akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    ll cnt4 = 0, cntodd = 0;
    rep(i, 0, n) {
        ll a;
        cin >> a;
        if (a % 4 == 0) cnt4++;
        if (a % 2 == 1) cntodd++;
    }
    if (cnt4 >= cntodd) cout << "Yes" << endl;
    else if (n % 2 == 1 && cnt4 == cntodd-1 && cnt4+cntodd == n) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

/*--------構造体定義-------*/
typedef struct wordcard{
 int num;
 struct wordcard *left;
 struct wordcard *right;
}word;
/*--------------------------*/

/*-------文字列を数字へ-------*/
int henkan(char str[]){
int i=0;

while(str[i]!='\0'){
 switch(str[i]){
  case 'A':str[i]='1';
           break;
  case 'C':str[i]='2';
           break;
  case 'G':str[i]='3';
           break;
  case 'T':str[i]='4';
           break;
 }
 i++;
}

return atoi(str);
}
/*--------------------------*/

/*-------単語カード作成----------*/
word* makecell(char str[]){
word *new=malloc(sizeof(word));

new->num=henkan(str);
new->left=NULL;
new->right=NULL;

return new;
}
/*--------------------------------*/


/*------------heap作成--------------------------*/
void insert(word **p,word *q){

if((*p)==NULL)(*p)=q;
else{
 if((*p)->num < q->num)insert(&((*p)->right),q);
 else insert(&((*p)->left),q);
}

return;
}
/*---------------------------------------------*/


/*--------------------find関数-------------------*/
void find(word *p,int x){

while(p!=NULL){
 if(p->num == x){printf("yes\n");return;}
 else if(p->num >x){find(p->left,x);return;}
 else {find(p->right,x);return;}
}

if(p==NULL)printf("no\n");

return;
}

/*---------------------------------------------*/



int main(){
int n,i,j;
char com[7];
word *new;
word *root;
char temp[13];
int z;

root=NULL;

scanf("%d",&n);

for(j=0;j<n;j++){

 scanf("%s",com);

 if(com[0]=='i'){
                 scanf("%s",temp);
                 new=makecell(temp);
                 insert(&root,new);
                }

  else if(com[0]=='f'){
                      scanf("%s",temp);
                      z=henkan(temp);
                      find(root,z);
                      }

}


return 0;
}


Measured memory_bytes: 19548
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree < int,  null_type,  less<int>,  rb_tree_tag,  tree_order_statistics_node_update > ordered_set;
typedef long long ll;
#define pb push_back
#define pi (acos(-1))
#define ull  unsigned long long
#define ld long double
#define all(v) v.begin(), v.end()
///freopen("input.txt","r",stdin);
///freopen("output.txt","w",stdout);
ll LCM(ll a, ll b)
{
    ll g = __gcd(a,b);
    return (a/g)*b ;
}
string numtostr(ll n)
{
    ostringstream str1 ;
    str1 << n ;
    return str1.str();
}
ll strtonum(string s)
{
    ll x ;
    stringstream str1(s);
    str1 >> x ;
    return x ;
}
int a[5],i;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  for(i=0;i<5;++i)
    cin>>a[i];
  for(i=0;i<5;++i)
  {
      if(a[i]==0)
      {
          cout<<i+1;
          return 0;
      }
  }
    return 0;
}


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

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

int N, K;
bool flag;

signed main()
{
    cin >> N;

    for(int i = 1; i * (i - 1) / 2 <= N; i++)
    {
        if(i * (i - 1) / 2 == N)
        {
            flag = true;
            K = i;
        }
    }

    if(flag)
    {
        cout << "Yes" << endl;
        set<int> S[K];
        int cnt = 1;
        for(int i = 0; i < K; i++)for(int j = i + 1; j < K; j++)
        {
            S[i].insert(cnt);
            S[j].insert(cnt++);
        }

        cout << K << endl;
        rep(i, K)
        {
            cout << S[i].size();
            if(S[i].size())cout << " ";
            for(auto ite = S[i].begin(); ite != S[i].end(); ite++)
            {
                if(ite != S[i].begin())cout << " ";
                cout << *ite;
            }
            cout << endl;
        }
    }
    else
        cout << "No" << endl;
    

    return 0;
}

Measured memory_bytes: 12868
#include<stdio.h>
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<=5){printf("0\n");}
	else if(a>=6&&a<=12){
		printf("%d\n",b/2);
	}
	else{
		printf("%d\n",b);
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,ans=0;
  cin>>n;
  for(ll i=2;i<=sqrt(n);i++){
    if(n%i==0){
      ll c=0,cur=1;
      while(n%i==0){
        c++;
        n/=i;
      }
      while(cur<=c){
        ans++;
        c-=cur;
        cur++;
      }
    }
  }
  cout<<ans+(n>1);
  return 0;
}

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

using namespace std;

bool normal(int a, int b, string s) {
 	for (int i = 0; i <= a + b; ++i) {
	 	if (i == a) {
	 	 	if (s[a] != '-')
				return false;
	 	} else {
	 	 	if (!(s[i] >= '0' && s[i] <= '9'))
	 	 	  return false;
	 	}
  }
  return true;
}
                                            
int main() {
	int a, b;
	string s;
	cin >> a >> b >> s;
	if (normal(a, b, s))
		cout << "Yes" << endl;
	else
		cout << "No" << endl; 	
}


Measured memory_bytes: 256
a,b=map(int,input().split())
c,d=map(int,input().split())
e,f=map(int,input().split())
if (c>e and d>f) or (c<e and d<f):
    print(0)
else:
    if c<e:
        c,d,e,f=e,f,c,d
    s=(c-e)*a
    t=(f-d)*b
    if s>t:
        print(0)
    elif s==t:
        print("infinity")
    else:
        print(int(s/(t-s))+int(t/(t-s))-(1 if s%(t-s)==0 else 0))

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

int main(){
  int x1,x2,y1,y2;
  cin>>x1>>y1>>x2>>y2;
  cout<<x2+y1-y2<<" "<<y2+x2-x1<<" "<<x1+y1-y2<<" "<<y1+x2-x1<<endl;
}

Measured memory_bytes: 384
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


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

cnt_0 = sum([a % 2 == 0 for a in A])
cnt_1 = sum([a % 2 != 0 for a in A])

ans = 0
# 0枚食べる時
if P == 0:
    ans += 1
for k in range(1, N + 1):
    for i in range(0, k + 1):
        j = k - i
        if i > cnt_0 or j > cnt_1:
            continue
        if P == 0 and j % 2 == 0:
            ans += cmb(cnt_0, i) * cmb(cnt_1, j)
        elif P == 1 and j % 2 == 1:
            ans += cmb(cnt_0, i) * cmb(cnt_1, j)

print(ans)


Measured memory_bytes: 39280
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

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


// vector<ll> getPrimes(ll n) {
//     vector<long long> primes;
//     primes.clear();
//     if (n < 2){
//         return primes;
//     }
//     primes.push_back(2);
//     if (n == 2){
//         return primes;
//     }
//     primes.push_back(3);
//     if (n == 3){
//         return primes;
//     }
//     for(ll i = 5; i <= n; i += 2){
//         bool isPrime = true;
//         for(int p = 0; p < (int)primes.size(); ++p){
//             if (i % primes[p] == 0){
//                 isPrime = false;
//                 break;
//             }
//         }
//         if (isPrime) {
//             primes.push_back(i);
//         }
//     }
//     return primes;
// }


vector<ll> getPrimesFast(ll n){
    vector<ll> primes;
    if (n < 10000){
        primes.clear();
        if (n < 2){
            return primes;
        }
        primes.push_back(2);
        if (n == 2){
            return primes;
        }
        primes.push_back(3);
        if (n == 3){
            return primes;
        }
        for(ll i = 5; i <= n; i += 2){
            bool isPrime = true;
            for(int p = 0; p < (int)primes.size(); ++p){
                if (i % primes[p] == 0){
                    isPrime = false;
                    break;
                }
            }
            if (isPrime) {
                primes.push_back(i);
            }
        }
        return primes;
    }
    else{
        vector<ll> sieve = getPrimesFast(sqrt(n));

        vector<short> isPrime(n+1, 1);
        for(int i = 0; i < (int)sieve.size(); ++i){
            for(int j = sieve[i] * 2; j <= n; j += sieve[i]){
                isPrime[j] = 0;
            }
        }

        for(int i = 2; i <= n; ++i){
            if (isPrime[i]){
                primes.push_back(i);
            }
        }
        return primes;
    }
}

int main(void)
{
    cin.sync_with_stdio(false);
    int Q;
    cin >> Q;

    auto primes_vec = getPrimesFast(100000);
    set<ll> primes(ALL(primes_vec));

    vector<int> sum(100010);
    for(int i = 3; i < 100001; i += 2) {
        sum[i] = sum[i-2]
               + primes.count(i) * primes.count((i + 1) / 2);
        sum[i+1] = sum[i];
    }

    REP(q, Q) {
        int l, r;
      	cin >> l >> r;
      	cout << sum[r] - sum[l - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 1596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
int main(void){
    int n;
    string s[2];
    cin>>n>>s[0]>>s[1];
    ll ans;
    int i=1;
    bool tate=true;
    if(s[0][0]==s[1][0]) ans=3;
    else{
        ans=6;
        i=2;
        tate=false;
    }
    for(;i<n;){
        if(tate){
            if(s[0][i]==s[1][i]){
                ans=(ans*2)%mod;
                tate=true;
                i++;
            }
            else{
                ans=(ans*2)%mod;
                tate=false;
                i+=2;
            }
        }
        else{
            if(s[0][i]==s[1][i]){
                tate=true;
                i++;
            }
            else{
                ans=(ans*3)%mod;
                i+=2;
            }
        }
    }
    cout<<ans<<endl;
}

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

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

void prime_factorize(ll N,map<ll,ll> &res) {
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res[a]=ex;
    }

    // 最後に残った数について
    if (N != 1) res[N]=1;
}

int main(){
    ll a,b; cin >> a >> b;
    ll d = gcd(a,b);
    map<ll,ll> mp;
    prime_factorize(d,mp);
    cout << 1+mp.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stack>
#include <deque>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define pii pair<pi,int>
#define sqr(x) ((x)*(x))
#define FOR for(int i=0;i<n;i++)for(int j=0;j<m;j++)
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main()
{
	int x;
	cin>>x;
	if(x<1200){puts("ABC");return 0;}
	else if(x<2800){puts("ARC");return 0;}
	else puts("AGC");
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char s[200005];
int len;
bool f[200005];
int main()
{
	scanf("%s",s+1);
	len=strlen(s+1);
	int ans=0;
	for(int i=1;i<=len;i++)
	{
		if(!f[i-1]&&s[i]==s[i-1])
		{
			f[++i]=1;
			if(i>len)
				ans--;
		}
		ans++;
	}
	if(len>=4&&!f[len-4]&&s[len]==s[len-1]==s[len-2]==s[len-3])
		ans--;
	printf("%d",ans);
}

Measured memory_bytes: 512
package main

import (
	"fmt"
)

type SegTree struct {
	n int
	d []int
}

func NewSegTree(n int) *SegTree {
	s := SegTree{}
	s.n = n
	s.d = make([]int, 2*n)
	return &s
}

func (s *SegTree) Modify(i, x int) {
	i += s.n
	s.d[i] = x
	for ; i > 0; i >>= 1 {
		s.d[i>>1] = s.d[i] + s.d[i^1]
	}
}

func (s *SegTree) Query(l, r int) int {
	res := 0
	l += s.n
	r += s.n
	for l < r {
		if l&1 == 1 {
			res += s.d[l]
			l++
		}
		if r&1 == 1 {
			r--
			res += s.d[r]
		}
		l >>= 1
		r >>= 1
	}
	return res
}

func main() {
	var n, q int
	var str string
	fmt.Scan(&n, &str, &q)

	s := []byte(str)
	abc := [26]*SegTree{}

	for i := 0; i < 26; i++ {
		abc[i] = NewSegTree(n)
	}

	for i := 0; i < n; i++ {
		c := s[i] - 'a'
		abc[c].Modify(i, 1)
	}

	for k := 0; k < q; k++ {
		var t int
		fmt.Scan(&t)

		if t == 1 {
			var i int
			var a string
			fmt.Scan(&i, &a)
			i--

			abc[s[i]-'a'].Modify(i, 0)
			s[i] = a[0]
			abc[s[i]-'a'].Modify(i, 1)
		} else {
			var l, r int
			fmt.Scan(&l, &r)
			l--

			res := 0
			for i := 0; i < 26; i++ {
				if abc[i].Query(l, r) > 0 {
					res++
				}
			}
			fmt.Println(res)
		}

	}
}


Measured memory_bytes: 216832
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long int n;
    cin >> n;
    long long int cnt = 0;
    long long int a,b,c;
    for (long long int a = 1; a < n; a++) {
        for (long long int b = 1; a*b < n; b++) {
cnt++;

        }
    }
cout << cnt << endl;
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  long long ans = pow(3, n);
  long long cnt_odd = 1;
  for (int i=0; i<n; i++) {
    if (a[i] % 2 == 0) {
      cnt_odd *= 2;
    }
  }
  cout<<ans-cnt_odd<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, K;
  std::cin >> N >> K;
  string S;
  std::cin >> S;
  ll ans = 0;
  char now = '0';
  int count = 0;
  for(int i=0;i<N;i++){
    if(now==S[i]) ans++;
    else now = S[i], count++;
  }
  if(K*2<count) ans += 2*K, K=0;
  else ans = N-1;
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

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

int main(void)
{
    cin.sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if (a <= c && c <= b) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
p = list(map(int, input().split()))
Y = 0
for i in range(2,N):
  if p[i-1] > p[i-2] and p[i-1] < p[i]:
    Y = Y + 1
    
  if p[i-1] < p[i-2] and p[i-1] > p[i]:
    Y = Y + 1
    
print(Y)

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

using namespace std;
typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n), c(n);
  for (int i = 0; i < n; ++i)
    cin >> p[i];
  for (int i = 0; i < n; ++i)
    cin >> c[i];
  ll ans = LLONG_MIN;
  for (int i = 0; i < n; ++i) {
    vector<bool> vis(n);
    int idx = i;
    vector<ll> sum = {0}, hi = {LLONG_MIN};
    while (!vis[p[idx] - 1]) {
      idx = p[idx] - 1;
      vis[idx] = true;
      sum.emplace_back(sum.back() + c[idx]);
      hi.emplace_back(max(hi.back(), sum.back()));
    }
    int m = sum.size() - 1;
    int f = k / m, rem = k % m;
    ll result;
    if (f > 0)
      result = max(hi[m], max(sum[m] * f + (rem == 0 ? 0 : hi[rem]),
                              sum[m] * (f - 1) + hi[m]));
    else
      result = hi[rem];
    ans = max(ans, result);
  }
  cout << ans;
}


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

typedef long long ll;

using tpl = tuple<int, int, int>;
typedef pair<ll,ll> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N, M;
int A[100010];
int B[100010];
vector<int> ins[100010];
bool ok_e[100010];
int in[100010];
int out[100010];
vector<int> outs[100010];
int ans[100010];

int main(){
    fastStream();
    cin >> N >> M;
    for(int i = 0; i < N + M; i++){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
        ins[B[i]].push_back(i);
        outs[A[i]].push_back(i);
        out[A[i]]++;
        in[B[i]]++;
        ok_e[i] = true;
    }

    queue<int> q;
    for(int i = 0; i < N; i++){
        if(in[i] == 0){
            q.push(i);
        }
    }
    while(q.size()){
        int pos = q.front(); q.pop();
        for(int i = 0; i < (int)outs[pos].size(); i++){
            int e_id = outs[pos][i];
            int cld = B[e_id];
            in[cld]--;
            if(in[cld] == 0){
                q.push(cld);
            }
            else{
                ok_e[e_id] = false;
            }
        }
    }

    memset(ans, -1, sizeof(ans));
    for(int i = 0; i < N + M; i++){
        if(ok_e[i]){
            ans[B[i]] = A[i];
        }
    }

    for(int i = 0; i < N; i++){
        cout << ans[i] + 1 << endl;
    }
    
    

    return 0;
}


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

int main(void){
    int n, m;
    cin >> n >> m;
    vector<int> x(m),d(m-1);
    rep(i,m) cin >> x[i];
    sort(all(x));
    rep(i,m-1){
        d[i] = x[i+1] - x[i];
    }
    sort(all(d));
    ll sum = 0;
    rep(i, max(m-n,0)){
        sum += d[i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
ll n,k,v[55];
ll solve(ll l,ll r){
  vector<ll> t;
  for(int i=0;i<=l;i++)t.push_back(v[i]);
  for(int i=r;i<n;i++)t.push_back(v[i]);
  sort(t.begin(),t.end());
  ll lim=k-t.size(); if(lim<0)return 0;
  ll sum=0;
  for(int i=0;i<t.size();i++){
    if(t[i]<0&&lim>0){
      lim--;
    }
    else sum+=t[i];
  }
  //cout<<l<<" "<<r<<" "<<sum<<endl;
  return sum;
}
int main(){
  cin>>n>>k;
  for(int i=0;i<n;i++)cin>>v[i];
  ll ans=0;
  for(int i=-1;i<n;i++)for(int j=i+1;j<=n;j++){
    ans=max(ans,solve(i,j));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/arc069/tasks/arc069_b
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
const int MAXN = 1e5 + 4;
char s[MAXN];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    cin >> s;
    s[n] = s[0], s[n + 1] = s[1];
    bitset<100005> a;
    REP(i, 4) {
        a[0] = i & 1, a[1] = (i >> 1) & 1;
        FOR(j, 2, n + 2) a[j] = (s[j - 1] == 'x') ^ a[j - 1] ^ a[j - 2];
        if (a[0] == a[n] && a[1] == a[n + 1]) {
            REP(j, n) { cout << (a[j] ? "W" : "S"); }
            cout << "\n";
            return 0;
        }
    }
    cout << "-1\n";
    return 0;
}


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

using namespace std;

typedef long long ll;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"

const int N = 100;
string grid[1 + N];
int dp[1 + N][1 + N];

void _ (int &a, int b) {
    if (a > b)
        a = b;
}

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

    int h, w;
    cin >> h >> w;
    for (int i = 1; i <= h; i++) {
        cin >> grid[i];
        grid[i] = " " + grid[i];
    }

    for (int i = 0; i <= h; i++)
        for (int j = 0; j <= w; j++)
            dp[i][j] = h * w;

    dp[1][1] = (grid[1][1] == '#');
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (i < h)
                _ (dp[i + 1][j], dp[i][j] + (grid[i][j] != '#' && grid[i + 1][j] == '#'));
            if (j < w)
                _ (dp[i][j + 1], dp[i][j] + (grid[i][j] != '#' && grid[i][j + 1] == '#'));
        }
    }

    cout << dp[h][w] << "\n";

    return 0;
}


Measured memory_bytes: 384
N = int(input())
A = sorted(list(map(int,input().split())))
B = (10**6+1)*[0]

for a in A:
  B[a]+=1
  if B[a]==1:
    for n in range(2*a,10**6+1,a):
      B[n]+=2

print(B.count(1))

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

using namespace std;
using ll = long long;

int main() {
  char b;
  cin >> b;
  switch(b){
    case 'A':
      cout << 'T' << endl;
      break;
    case 'T':
      cout << 'A' << endl;
      break;
    case 'C':
      cout << 'G' << endl;
      break;
    case 'G':
      cout << 'C' << endl;
      break;
  }
}


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

using namespace std;

int main() {

    double r;
    double e, m;
    cin >> r;
    
    e = (r + r) * M_PI;
    m = (r * r) * M_PI;
    
    cout << setprecision(6);
    cout << fixed << m << " " << e << endl;
    
    return 0;
}

Measured memory_bytes: 1288
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

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

func main() {
	n := nextInt()
	p := make([]int, n)

	for i := 0; i < n; i++ {
		p[i] = nextInt()
	}

	total := 1
	min := p[0]
	for i := 1; i < n; i++ {
		if p[i] <= min {
			total++
			min = p[i]
		}
	}

	fmt.Printf("%d", total)
}


Measured memory_bytes: 3584
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int N, kazu, K;
int A[18], B[18], onaji[18], MAB[18];
unsigned char dp[36][1 << 18];
int keisan(int b, bool n, int k) {
	if (dp[k][b] != 255) return dp[k][b];
	if (b == (1 << N) - 1) return 0;

	int saishou = 254;
	int num2 = 0;
	int used = 0;
	int m = 40;
	auto a = n ? B : A;

	rep(i, N) {
		if (!(b >> i & 1)) {
			if (MAB[i] < k) return dp[k][b] = 254;
			if (!(used >> onaji[i] & 1) && a[i] >= k && a[i] <= m) {
				chmin(saishou, keisan(b ^ (1 << i), !n, a[i]) + num2);
				used ^= 1 << onaji[i];
			}
			chmin(m, MAB[i]);
			num2++;
		}
	}
	return dp[k][b] = saishou;
}

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


	scanf("%d", &N);
	rep(i, N) {
		if (i & 1) scanf("%d", B + i);
		else scanf("%d", A + i);
	}
	rep(i, N) {
		if (i & 1) scanf("%d", A + i);
		else scanf("%d", B + i);
	}
	rep(i, N) MAB[i] = max(A[i], B[i]);

	rep(i, N) {
		int atta = -1;
		rep(j, i) {
			if (A[i] == A[j] && B[i] == B[j]) {
				atta = j;
				break;
			}
		}
		if (atta != -1) onaji[i] = onaji[atta];
		else onaji[i] = kazu++;
	}

	pair<int, int> kari[36];
	rep(i, N) kari[i] = mp(A[i], i);
	rep(i, N) kari[i + N] = mp(B[i], i + N);
	sort(kari, kari + N * 2);
	int mae = kari[0].first;
	rep(i, N * 2) {
		if (mae != kari[i].first) K++;
		mae = kari[i].first;
		if (kari[i].second < N) A[kari[i].second] = K;
		else B[kari[i].second - N] = K;
	}
	memset(dp[0], 255, (K + 1) * (1 << 18));

	int kotae = keisan(0, 0, 0);
	if (kotae == 254) printf("-1\n");
	else printf("%d\n", kotae);

	Would you please return 0;
}

Measured memory_bytes: 8320
from collections import defaultdict

N = int(input())
As = sorted(map(int, input().split()), reverse=True)

prev = None
pair = []
for A in As:
    if prev == A:
        prev = None
        pair.append(A)
        if len(pair) == 2:
            break
    else:
        prev = A

if len(pair) == 2:
    print(pair[0] * pair[1])
else:
    print(0)

Measured memory_bytes: 14636
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
 
#define CASES int t;cin>>t;while(t--)
#define REP(i, val, b) for (int i = val; i < b; ++i)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
 
int main() {
    fastio
    int n;
    cin >> n;
    vector<int> A(n);
    REP(i,0,n) cin >> A[i];
    vector<int> B(n);
    B[0] = 0;
    B[1] = abs(A[1] - A[0]);
    REP(i,2,n) {
        B[i] = min(B[i-1] + abs(A[i] - A[i-1]), B[i-2] + abs(A[i] - A[i-2]));
    }
    cout << B[n-1];
    return 0;
}

Measured memory_bytes: 1024
#
# abc177 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
1 2 3"""
        output = """11"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
141421356 17320508 22360679 244949"""
        output = """437235829"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    S = sum(A)
    ans = 0
    for a in A:
        S -= a
        ans += a * S

    print(ans % (10**9+7))


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 39392
#include<stdio.h>
#include<string.h>

int main(void) {
	char text[1227], c1, c2;
	int ct1 = 0, ct2 = 0;

	scanf("%s", text);

	c1 = text[1];

	for (int i = 0; i < strlen(text); i++) {
		if (text[i] != c1){
        	c2=text[i];
          	break;
        }
	}

	for (int j = 0; j < strlen(text); j++) {
		if (text[j] == c1)ct1++;
		else if (text[j] == c2)ct2++;
	}

	if (ct1 == ct2 && ct1 == 2) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a==b){
		printf("a == b\n");
	}
	else if(a<b){
		printf("a < b\n");
	}
	else if(a>b){
		printf("a > b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,m;

int main(){
	cin >> n >> m;
	
	cout << (1900*m+(n-m)*100)*(1<<m) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,X,sum=0,L[1000],cnt=1;
	cin>>N>>X;
	for(int i=0;i<N;i++)
	{
		cin>>L[i];
		sum+=L[i];
		if(sum<=X)
		cnt++;
		else 
		cnt+=0;
	}
	cout<<cnt<<endl;
	return 0;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b,c;
    cin>>a>>b>>c;
    char ch='a';
    bool loop=true;
    while(loop){
        switch(ch){
        case 'a':if(a.empty()){
        cout<<'A';
        loop=false;
        break;
        }
        ch=a[0];
        a.erase(0,1);
        break;

        case 'b':if(b.empty()){
        cout<<'B';
        loop=false;
        break;
        }
        ch=b[0];
        b.erase(0,1);
        break;

        case 'c':if(c.empty()){
        cout<<'C';
        loop=false;
        break;
        }
         ch=c[0];
         c.erase(0,1);
         break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

ll solve(){
    ll k,a,b;
    cin >>k >>a >>b;

    if(b <= a) return k+1;

    // b-a > 0

    ll ans = k+1;

    ll rem = k-(a-1);
    if(rem>0){
        ll num = rem/2;

        ll t = num*(b-a);
        if(rem%2==1) ++t;
        // dbg(t);
        ans = max(ans, t+a);
    }
    return ans;
}

int main(){
    cout << solve() << endl;
    return 0;
}


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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s; cin >> s;
    if(s.back() == 's') s += "es";
    else s += "s";
    cout << s;
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
#define rep(n) for( int i = 0 ; i < n ; i++ )
#define REP(n) for( int i = 1 ; i <= n ; i++ )
#define repll(n) for( ll i = 0 ; i < n ; i++ )
#define REPll(n) for( ll i = 1 ; i <= n ; i++ )
#define rep2(n) for( int j = 0 ; j < n ; j++ )
#define REP2(n) for( int j = 1 ; j <= n ; j++ )
#define repll2(n) for( ll j = 0 ; j < n ; j++ )
#define REPll2(n) for( ll j = 1 ; j <= n ; j++ )

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a , b;
  	cin >> a >> b;
  	cout << a - b + 1;
}


Measured memory_bytes: 3652
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		int n = sc.nextInt();
		for( int i=0; i<n; i++) {
		    String str = sc.next();
		    Integer count = map.get(str);
		    if (count == null) {
		        map.put(str,1);
		    } else {
                map.remove(str);
		        map.put(str,count+1);
		    }
		}
		List list = new ArrayList();
		int max_count = 0;
		for (String key : map.keySet()) {
		    int c = map.get(key);
		    if (max_count <= c) max_count = c;
		}
		for (String key : map.keySet()) {
		    int c = map.get(key);
		    if (max_count == c) list.add(key);
		}
		Collections.sort(list);
		for (int i=0; i<list.size(); i++) {
		    System.out.println(list.get(i));
		}
	}
}


Measured memory_bytes: 83584
#include <stdio.h>
#include <algorithm>
#define rep(i,r) for (int i = 0; i < r; i++)

using namespace std;

int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  int H[N];
  rep(i,N) scanf("%d", &H[i]);
  sort(H, H + N);
  long D = 0;
  rep(i,N - K) D += H[i];
  printf("%ld", D);
  return 0;
}


Measured memory_bytes: 896
int a[200],b[200],c[1000],d[1000],n,m,i,j,k,t=0,w,q;main(){for(;;){scanf("%d",&n);if(n==0)break;for(i=0;i<n;i++){scanf("%d %d",&a[i],&b[i]);}scanf("%d",&m);for(i=0;i<m;i++){scanf("%d %d",&c[i],&d[i]);}for(i=0;i<m;i++){w=c[i]-a[0];q=d[i]-b[0];for(j=1;j<n;j++){for(k=0;k<m;k++){if(a[j]+w==c[k]){if(b[j]+q==d[k]){t++;break;}}}}if(t==n-1){printf("%d %d\n",w,q);t=0;break;}t=0;}}return 0;} 

Measured memory_bytes: 608
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  const int M = 15;
  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  vector<vector<ll>> dpr(n, vector<ll>(M + 1));
  REP(j, M + 1) dpr[n - 1][j] = j;
  for (int i = n - 2; i >= 0; --i) {
    if (a[i] <= a[i + 1]) {
      int cnt = 0;
      ll tmp = a[i];
      while (tmp * 4 <= a[i + 1]) {
        ++cnt;
        tmp *= 4;
      }
      REP(j, cnt + 1) dpr[i][j] = j + dpr[i + 1][0];
      FOR(j, cnt + 1, M + 1) dpr[i][j] = j + dpr[i + 1][j - cnt];
    } else {
      int cnt = 0;
      ll tmp = a[i + 1];
      while (a[i] > tmp) {
        ++cnt;
        tmp *= 4;
      }
      REP(j, M + 1) dpr[i][j] = j + (j + cnt > M ? dpr[i + 1][M] + (j + cnt - M) * (n - 1 - i) : dpr[i + 1][j + cnt]);
    }
    // REP(i, n) REP(j, M + 1) cout << dpr[i][j] << " \n"[j == M];
    // cout << '\n';
  }
  for (int &e : a) e *= -2;
  vector<vector<ll>> dpl(n, vector<ll>(M + 1));
  REP(j, M + 1) dpl[0][j] = j;
  FOR(i, 1, n) {
    if (a[i - 1] <= a[i]) {
      int cnt = 0;
      ll tmp = a[i];
      while (a[i - 1] <= tmp * 4) {
        ++cnt;
        tmp *= 4;
      }
      REP(j, cnt + 1) dpl[i][j] = j + dpl[i - 1][0];
      FOR(j, cnt + 1, M + 1) dpl[i][j] = j + dpl[i - 1][j - cnt];
    } else {
      int cnt = 0;
      ll tmp = a[i - 1];
      while (tmp > a[i]) {
        ++cnt;
        tmp *= 4;
      }
      REP(j, M + 1) dpl[i][j] = j + (j + cnt > M ? dpl[i - 1][M] + (j + cnt - M) * i : dpl[i - 1][j + cnt]);
    }
    // REP(i, n) REP(j, M + 1) cout << dpl[i][j] << " \n"[j == M];
    // cout << '\n';
  }
  // REP(i, n) REP(j, M + 1) cout << dpr[i][j] << " \n"[j == M];
  // cout << '\n';
  // REP(i, n) REP(j, M + 1) cout << dpl[i][j] << " \n"[j == M];
  ll ans = dpr[0][0] * 2;
  REP(i, n) chmin(ans, dpl[i][0] * 2 + i + 1 + (i + 1 == n ? 0 : dpr[i + 1][0]) * 2);
  cout << ans << '\n';
  return 0;
}


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

int main(){
    int n,m,ans=0;
    ll pena=0;
    cin >> n >> m;
    vector<int> a(n,0);
    vector<int> b(n,0);
    for(int i=0;i<m;i++){
        int num;
        string s;
        cin >> num >> s;
        if(a[num-1]==0){
            if(s=="AC"){
                a[num-1]=1;
            }else{
                pena++;
                b[num-1]++;
            }
        }
    }
    
    rep(i,n){
        if(a[i]) ans++;
        else pena-=b[i];
    }
    
    printf("%d %d\n",ans,pena);

    return 0;
}






Measured memory_bytes: 1024
#include<stdio.h>

struct data{
	int start;
	int finish;
};

struct data arr[100005];
struct data temp[100005];
void mergesort(struct data *arr, int left, int right)
{
	if(left==right)
	{
		return;
	}
	
	int mid=(left+right)/2;
	mergesort(arr,left,mid);
	mergesort(arr,mid+1,right);
	
	int l=left;
	int tl=mid;
	int r=mid+1;
	int tr=right;
	int idx=left;
	
	while(l<=tl && r<=tr)
	{
		if(arr[l].finish<arr[r].finish)
		{
			temp[idx]=arr[l++];
		}
		else
		{
			temp[idx]=arr[r++];
		}
		idx++;
	}
	
	while(l<=tl)
	{
		temp[idx++]=arr[l++];
	}
	
	while(r<=tr)
	{
		temp[idx++]=arr[r++];
	}
	
	for(int i=left;i<=right;i++)
	{
		arr[i]=temp[i];
	}
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d %d",&arr[i].start,&arr[i].finish);		
	}
	
	int count=1;
	int idx=0;
	mergesort(arr,0,n-1);
	
	for(int i=1;i<n;i++)
	{
		if(arr[idx].finish<arr[i].start)
		{
			count++;
			idx=i;
		}
	}
	printf("%d\n",count);
	
}


Measured memory_bytes: 3348
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>


using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, std::vector<long long> A){
  sort(A.begin(), A.end());
  ll x = A[0];
  ll num = 1;
  ll eve = 0;
  ll y = 1;
  for(ll i=1; i<N; i++) {
    if(A[i] == x)
      num++;
    else {
      if(num%2 == 0)
	eve++;
      num=1;
      y++;
    }
    x = A[i];
  }
  if(num%2==0)
    eve++;

  if(eve%2==0)
    std::cout << y << std::endl;
  else
    std::cout << y-1 << std::endl;
    
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, std::move(A));
  return 0;
}



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

int main() {
    vector<int> v(3);
    rep(i,3){
        int a; cin >> a;
        v[i]=a;
    }
    sort(v.begin(),v.end());
    cout << v[0] << " " << v[1] << " " << v[2] << endl;
    


    return 0;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}



int main()
{
	IOS;
	ll n,m;
	cin>>n>>m;
	ll ans=(n*m)/(__gcd(n,m));
	cout<<ans;
}



Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

struct edge {ll to, cost;};

int main(){
    ll N; cin >> N;
    vl D(N); REP(i, N) cin >> D[i];
    vl fix, sel; map<ll, ll> cnt;
    REP(i, N){
        cnt[D[i]]++;
        if(cnt[D[i]] >= 3 || D[i] == 0){
            cout << 0 << endl; return 0;
        }
    }
    FORMAP(it, cnt){
        if(it->ss == 2){
            fix.pb(it->ff); fix.pb(24-it->ff);
        }
        else if(it->ss == 1){
            sel.pb(it->ff);
        }
    }
    
    ll M = sel.size(); ll ans = 0;
    REP(i, 1ll << M){
        vl cand;
        REP(j, M){
            if(i >> j & 1) cand.pb(sel[j]);
            else cand.pb(24-sel[j]);
        }
        vl tmp = fix;
        tmp.pb(0);
        REP(j, M) tmp.pb(cand[j]);
        
        ll an = LINF;
        REP(j, tmp.size()){
            FOR(k, j+1, tmp.size()){
                ll mnt = min(tmp[j], tmp[k]);
                ll mxt = max(tmp[j], tmp[k]);
                ll t = mxt - mnt;
                an = min(an, min(t, 24-t));
            }
        }
        
        ans = max(ans, an);
    }
    cout << ans << endl;
    return 0;
}


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

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

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

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

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

    // 素数である
    return 1;
}

 lint  dp[13][100005];
int main(){
   string s;
   cin>>s;
   reverse(s.begin(),s.end());
   dp[0][0]=1;
   lint mul=1;
   rep(i,s.size()){
       lint x;
       if(s[i]!='?'){
           x=s[i]-'0';
         rep(j,13){
             dp[(j+x*mul)%13][i+1]+=dp[j][i];
         }
       }else{
           rep(k,10){
           rep(j,13){
                   dp[(j+k*mul)%13][i+1]+=dp[j][i];
           }
           }
       }
       mul*=10;
       mul%=13;
       rep(m,13){
            dp[m][i+1]%=MOD;
       }
   }
   cout<<dp[5][s.size()];
}


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

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


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int node;

typedef struct Trees{
    char *word;
    int node_id;    //number of node in this line
    int left;
    int right;
    int father;
    int degree;
    int sibling;
    int height;
    int depth;
}Tree;

void CreateBiTree(Tree*,int,int,int);
void find_father(Tree*,int);
void find_degree(Tree*,int);
void find_sibling(Tree*,int);
void attribute_judgement(Tree *);
void depth(int,int,Tree*);
int height(int,int*,Tree*);

int max(int a,int b)
{
    if(a>b)return a;
    else return b;
}
int main()
{
    int i,a,b,c;
    scanf("%d",&node);
    Tree tree[node];
    
    int root=-1,h[node];
    //CreateBiTree(&Tree);
    for(i=0;i<node;i++)
    {
        scanf("%d %d %d",&a,&b,&c);
        CreateBiTree(&tree[a],a,b,c);
    }
    find_father(tree,node);
    
    if(node>1) find_sibling(tree,node);
    find_degree(tree,node);
    //depth(node,tree,0,dep);
    for(i=0;i<node;i++) if(tree[i].father==-1)root=i;
    depth(root,0,tree);
    height(root,h,tree);
    
    
    
    attribute_judgement(tree);
    for(i=0;i<node;i++)
    {
        
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n", tree[i].node_id, tree[i].father, tree[i].sibling, tree[i].degree, tree[i].depth, h[i], tree[i].word);
        
    }
    return 0;
}

void CreateBiTree(Tree *t,int a,int left,int right)
{
    t->node_id=a;
    t->left=left;
    t->right=right;
    t->father=-1;
    t->sibling=-1;
    t->degree=0;
}
void find_father(Tree *tree,int node)
{
    int i,j;
    for(i=0;i<node;i++)
    {
        for(j=0;j<node;j++)
        {
            if(tree[i].node_id==tree[j].left)
                tree[i].father=tree[j].node_id;
            else if(tree[i].node_id==tree[j].right)
                tree[i].father=tree[j].node_id;
        }
    }
}
void find_degree(Tree *tree,int node)
{
    int i;
    for(i=0;i<node;i++)
    {
        if(tree[i].left>=0)
            tree[i].degree++;
        if(tree[i].right>=0)
            tree[i].degree++;
    }
}
void find_sibling(Tree *tree,int node)
{
    int i;
    for(i=0;i<node;i++)
    {
 if ( tree[i].father == -1 ) continue;
        if(tree[i].node_id==tree[tree[i].father].left)
            tree[i].sibling=tree[tree[i].father].right;
        else if(tree[i].node_id==tree[tree[i].father].right)
            tree[i].sibling=tree[tree[i].father].left;
    }
}
void attribute_judgement(Tree *tree)
{
    int i;
    for(i=0;i<node;i++)
    {
        if(tree[i].father==-1) tree[i].word="root";
        else if(tree[i].left==-1 && tree[i].right==-1) tree[i].word="leaf";
        else tree[i].word="internal node";
    }
}


void depth(int u,int d,Tree *tree)
{
    if(u==-1)return;
    tree[u].depth=d;
    depth(tree[u].left,d+1,tree);
    depth(tree[u].right,d+1,tree);
}

int height(int u,int h[],Tree*tree)
{
    int left=0,right=0;
    if(tree[u].left!=-1){
        left=height(tree[u].left,h,tree)+1;
    }
    if(tree[u].right!=-1){
        right=height(tree[u].right,h,tree)+1;
    }
    return h[u]=max(left,right);
}



Measured memory_bytes: 2736
#include <algorithm>
#include <chrono>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>

#define llong long long

using namespace std;
const int IINF = 2147483647;
const llong LLINF = 9223372036854775807;

//素因数分解
map<long, int> FIP(long n) {
  map<long, int> ret;
  long n0 = n;
  for (long i = 2; i * i <= n0; i++) {
    while (n % i == 0) {
      n /= i;
      ret[i]++;
    }
  }
  if (n > 1) ret[n]++;
  return ret;
}

//gcd
long gcd(long a, long b){
  if(a<b)return gcd(b, a);
  else if(b==0)return a;
  else return gcd(b, a%b);
}

int main(){
  long a, b;
  cin >> a >> b;
  long g=gcd(a, b);
  map<long, int>fg=FIP(g);
  int cnt=0;
  for(pair<long, int>p: fg){
    if(p.second>0)cnt++;
  }
  cout << cnt+1;
  return 0;
}

Measured memory_bytes: 256