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

using ll = long long;
static const ll MOD = 1e9 + 7;

// 組合せを素数で割った値を求める
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, k;
  cin >> n >> k;
  
  vector<ll> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  sort(a.begin(), a.end());
  
  COMinit();
  
  ll ans = 0;
  for(int i = k - 1; i < n; i++){
    ans += a.at(i) * COM(i, k - 1);
    ans %= MOD;
  }
  for(int i = 0; i <= n - k; i++){
    ans += MOD * 100000;
    ans -= a.at(i) * COM(n - i - 1, k - 1);
    ans %= MOD;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 13056
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();

        int zenhan = Integer.parseInt(S.substring(0,2));
        int kohan = Integer.parseInt(S.substring(2));

        if (zenhan >= 1 && zenhan <= 12 && kohan >= 1 && kohan <= 12) {
            System.out.println("AMBIGUOUS");
        }
        else if (zenhan >= 1 && zenhan <= 12 && kohan >= 0) {
            System.out.println("MMYY");
        }
        else if (zenhan >= 0  && kohan >= 1 && kohan <= 12) {
            System.out.println("YYMM");
        }
        else {
            System.out.println("NA");
        }

    }
}

Measured memory_bytes: 21716
D=int(input())
*c,=map(int,input().split())
s=[]
for i in range(D):
    *x,=map(int,input().split())
    s.append(x)

dt=[]
last=[-1]*26
v=0
for d in range(D):
    news=[s[d][i]+c[i]*(d-last[i])*(d-last[i]-1)//2 for i in range(26)]
    maxi=0
    tmp=-float('inf')
    for i in range(26):
        if tmp<news[i]:
            maxi=i
            tmp=news[i]
    last[maxi]=d
    v+=s[d][maxi]
    for i in range(26):
        v-=c[i]*(d-last[i])
    dt.append(maxi+1)

def score(T):
    last=[-1]*26
    v=0
    for d in range(D):
        v+=s[d][T[d]-1]
        last[T[d]-1]=d
        for i in range(26):
            v-=c[i]*(d-last[i])
    return v

v0=max(score(dt)+10**6,0)

import random

for _ in range(5):
    for d in range(1,D):
        y=-1
        newdt=dt+[]
        for i in range(26):
            if dt[d]!=i+1:
                newdt[d]=i+1
                v1=max(score(newdt)+10**6,0)
                if v0<v1:
                    y=i+1
                    v0=v1
        if y!=-1:
            if y%5!=random.randint(0,4):
                dt[d]=y

for i in dt:
    print(i)

Measured memory_bytes: 85568
#include<stdio.h>
int main(void){
	int n;
	int check[10000] = { 0 };
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		int roundA;
		int roundB;
		int roundC;
		roundA = i / 10;
		roundB = i / 100;
		roundC = i / 1000;
		if (i % 3 == 0)//3????????°
		{
			check[i] = 1;
		}
		if (i % 10 == 3)//1?????????3
		{
			check[i] = 1;
		}
		if (roundA%10==3)
		{
			check[i] = 1;
		}
		if (roundB % 10 == 3)
		{
			check[i] = 1;
		}
		if (roundC % 10 == 3)
		{
			check[i] = 1;
		}
	}
	for (int a = 1; a <= n; a++)
	{
		if (check[a] == 1)
		{
			printf(" %d", a);
		}
	}
	printf("\n");
}

Measured memory_bytes: 1880
# 2019/01/13
# KEYENCE Programming Contest 2019 - A
 
# Input
n = [0, 0, 0, 0]
val = [1, 9, 7, 4]
valflg = [0, 0, 0, 0]
 
n[0], n[1], n[2], n[3] = map(int,input().split())
 
for idx in range(4):
    for idx2 in range(4):
        if n[idx] == val[idx2]:
            valflg[idx2] = 1
 
if valflg[0] + valflg[1] + valflg[2] + valflg[3] == 4:
    ans = "YES"
else:
    ans = "NO"
    
# Output
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    ll ans=0;
    rep(i,n){
        if(a[i]==i+1){
            ans++;
            i++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
import math
def digit(X):
    d = 0
    while X:
        X //= 10
        d += 1
    return d

def F(A, B):
    return max(digit(A), digit(B))

N = int(input())

min_F = 20
max_div = round(math.sqrt(N)) + 10
for i in range(1, max_div):
    if N % i == 0:
        f = F(i, N/i)
        if f < min_F:
            min_F = f
print(min_F)



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

int n, m;
int par[100001];
vector<int> v;

int root(int x) {
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
}

bool same(int x, int y) {
    return root(x) == root(y);
}

void merge(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
    par[x] = y;
}

int main() {
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        v.push_back(--a);
        par[i] = i;
    }

    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        merge(--x, --y);
    }

    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(same(i, v[i])) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h> 
using namespace std;
int main() {
    int n; 
    cin >> n; 

    int sum = 0; 
    int x = n; 
    while (x) {
        sum += x % 10;
        x = x / 10; 
    }
    (n % sum) == 0 ? cout << "Yes\n" : cout << "No\n";
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		String str = sc.next();
		String[] S = str.split("");
		//System.out.println(S[0]);
		for(int i=0; i<S.length; i++){
			if(!(S[i].equals(S[S.length-1-i]))){
				System.out.println("No");
				return;
			}
			if(i<(S.length-1)/2-1-i){
				if(!(S[i].equals(S[(S.length-1)/2-1-i]))){
					System.out.println("No");
					return;
				}
			}
			if(i>=(S.length+3)/2-1&&i<((S.length+3)/2+S.length)/2){
				if(!(S[i].equals(S[S.length-1-i]))){
					System.out.println("No");
					return;
				}
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 35520
#include<stdio.h>
int dx[4]={-1,0,0,1};
int dy[4]={0,1,-1,0};
int dx2[8]={-1,-1,-1,0,1,1,1,0};
int dy2[8]={-1,0,1,1,1,0,-1,-1};
int dx3[12]={-1,-1,-1,0,1,1,1,0,-2,0,2,0};
int dy3[12]={-1,0,1,1,1,0,-1,-1,0,2,0,-2};
int main(){
	int t[14][14];
	int i,j;
	for(i=0;i<14;i++)for(j=0;j<14;j++)t[i][j]=0;
	int a,b,c;
	while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){
		t[a+2][b+2]++;
		if(c==1)for(i=0;i<4;i++)t[a+dx[i]+2][b+dy[i]+2]++;
		if(c==2)for(i=0;i<8;i++)t[a+dx2[i]+2][b+dy2[i]+2]++;
		if(c==3)for(i=0;i<12;i++)t[a+dx3[i]+2][b+dy3[i]+2]++;
	}
	int ans1=0;
	int ans2=0;
	for(i=2;i<12;i++){
		for(j=2;j<12;j++){
			if(t[i][j]>0)ans1++;
			if(ans2<t[i][j])ans2=t[i][j];
		}
	}
	printf("%d\n%d\n",100-ans1,ans2);
	return 0;
}

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

using namespace std;

int n, a;

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
    {
        scanf("%d", &a);
        if(a&1) return puts("first")&0;
    }
    puts("second");
    return 0;
}

Measured memory_bytes: 256
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        a: usize,
        b: usize
    }

    println!("{}", a * b);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 2188
#include <iostream>
#include <string>
#include <cmath>

using namespace std;


int main(){
  int a,b;
  cin >> a >> b;
  
  if(a != 1 && b != 1){
    cout << "1";
  }
  if(a != 2 && b != 2){
    cout << "2";
  }
  if(a != 3 && b != 3){
    cout << "3";
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n,i,p[10];scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&p[i]);
	int max=0,sum=0;
	for(i=0;i<n;i++){
		if(max<p[i])max=p[i];
		sum+=p[i];
	}
	printf("%d\n",sum-max+max/2);
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)

	inputs := make([]bool, 1000000000)
	var A int
	res := "YES"
	for i := 0; i < N; i++ {
		fmt.Scan(&A)
		if inputs[A] == true {
			res = "NO"
			break
		}
		inputs[A] = true
	}
	// fmt.Println(inputs)
	fmt.Println(res)
}


Measured memory_bytes: 1019776
#include <iostream>

using namespace std;

int main()
{
    string str;
    cin >> str;
 
    int count = 0;
    for (int i = 0; i < str.size(); i++) {
        if (str.at(i) == '1') {
        count++;
        }
    }
    
    cout << count << endl;

}

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

int main() {
   while (1) {
      string s;
      getline(cin, s);
      if (s == ".") break;

      stack<char> stk;
      int cnt = 0;
      bool ok = false;
      int n = s.size();
      for (int i = 0; i < n; i++) {
         if (s[i] == '(') stk.push(s[i]);
         if (s[i] == '[') stk.push(s[i]);
         if (s[i] == ')') {
            if (stk.empty() || stk.top() != '(') {
               ok = true;
               break;
            }
            stk.pop();
         }
         if (s[i] == ']') {
            if (stk.empty() || stk.top() != '[') {
               ok = true;
               break;
            }
            stk.pop();
         }
      }
      if (!ok && stk.empty()) {
         puts("yes");
      } else {
         puts("no");
      }
   }

   return 0;
}


Measured memory_bytes: 3196
import sys
n = int(input())
a_ls = list(map(int, input().split()))
hat_nperson = [0,0,1]
ans = 3
mod = 10**9+7

if a_ls[0] != 0 or (n != 1 and a_ls[1] == 2):
    print(0)
    sys.exit()

for i in range(1,n):
    n_same = a_ls[i]
    n_choices = 0
    choice_ind = -1
    for j,person in enumerate(hat_nperson):
        if person == n_same:
            n_choices += 1
            choice_ind = j
    if choice_ind == -1:
        print(0)
        sys.exit()
    hat_nperson[choice_ind] += 1
    ans *= n_choices
    ans %= mod
print(ans%mod)

Measured memory_bytes: 20708
///*
#include<iostream>
using namespace std;

int main() {

	int x[4], i;

	for (i = 0; i < 4; i++) {
		cin >> x[i];
	}

	x[0] * x[1] > x[2] * x[3] ? cout << x[0] * x[1] : cout << x[2] * x[3];

	return 0;
}
//*/

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

int main(){
    ll n,k,q;
    cin >> n >> k >> q;
    vector<ll> contestant(n,k-q);
    rep(i,q){
        ll answer=0;
        cin >> answer;
        contestant[answer-1] ++;
    }
    rep(i,n){
        if(contestant[i] > 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }

}



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

int main() {
	ll score[1<<16], n, a[16][16];
	cin >> n;
	memset(score, 0, sizeof(score));
	for (int i=0; i<n; i++) 
		for (int j=0; j<n; j++)
			cin >> a[i][j];
	for (int i=0; i<(1<<n); i++)
		for (int j=0; j<n; j++)
			for (int k=j+1; k<n; k++)
				if (i&(1<<j) && i&(1<<k))
					score[i] += a[j][k];
	for (int i=0; i<(1<<n); i++)
		for (int j=1; j<i; j++)
			if (j+(j^i)==i)
				score[i] = max(score[i], score[j]+score[j^i]);
	
	cout << score[(1<<n)-1] << "\n";
}

Measured memory_bytes: 896
S = list(input())

length = len(S)
cnt = 0
if length %2  == 0:
    for i in range(int(length/2)):
      if S[i] != S[-(i+1)]:
        cnt += 1
      else:
        continue
    print(cnt)
else:
    for i in range(int(length/2)+1):
      if S[i] != S[-(i+1)]:
        cnt += 1
      else:
        continue
    print(cnt)

Measured memory_bytes: 38484
import numpy as np

n, k = map(int, input().split())
mod = 10 ** 9 + 7

mx = 1
while (mx + 1) ** 2 <= n:
    mx += 1

dp_u = np.ones(mx, np.int64)
N = np.full(mx, n, np.int64)
L = N // np.arange(1, mx + 1)
R = np.maximum(N // np.arange(2, mx + 2), mx)
coef = L - R
dp_d = coef

for _ in range(2, k + 1):
    acc_u = np.cumsum(dp_u) % mod
    acc_d = np.cumsum(dp_d[::-1]) % mod
    dp_u = (dp_u.sum() + acc_d[::-1]) % mod
    dp_d = coef * acc_u % mod

ans = (dp_u.sum() + dp_d.sum()) % mod
print(ans)


Measured memory_bytes: 15824
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	vector<vector<lint>>A(3, vector<lint>(3));
	rep(i, 3) {
		rep(j, 3) {
			cin >> A[i][j];
		}
	}
	lint N;
	cin >> N;
	vector<lint>B(N);
	rep(i, N) {
		cin >> B[i];
	}
	vector<vector<bool>>V(3, vector<bool>(3));
	rep(i, 3) {
		rep(j, 3) {
			V[i][j] = false;
		}
	}
	rep(i, N) {
		rep(j, 3) {
			rep(k, 3) {
				if (B[i] == A[j][k]) {
					V[j][k] = true;
				}
			}
		}
	}
	bool ok = false;
	rep(i, 3) {
		if (V[i][0] && V[i][1] && V[i][2]) {
			ok = true;
		}
	}
	rep(i, 3) {
		if (V[0][i] && V[1][i] && V[2][i]) {
			ok = true;
		}
	}
	if (V[0][0] && V[1][1] && V[2][2]) {
		ok = true;
	}
	if (V[0][2] && V[1][1] && V[2][0]) {
		ok = true;
	}
	if (ok) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll N, M;
ll A[330][330];

signed main() {
  rep(i,330)
    rep(j, 330)
    A[i][j]=-1;
  cin >> N >> M;
  rep(i,N)
    rep(j,M) {
      cin>>A[i][j];
      A[i][j]--;
    }

  ll ans = N;
  rep(k,M) {
    // 最も参加者の多いスポーツ s を特定する
    vector<ll> n_player(M, 0);
    rep(i,N)
      rep(j,M)
        if (A[i][j] != -1) {
          n_player[A[i][j]]++;
          break;
        }
    //cout << "# of player: ";
    //rep(j,M){
    //  cout<< j << ":" << n_player[j] << " ";
    //}
    //cout << endl;
    ll s = 0;
    rep(j,M)
      if (n_player[j] > n_player[s])
        s = j;

    // スポーツ s の参加者は答えの候補
    // cout << "remove sport " << s << endl;
    ans = min(ans, n_player[s]);

    // スポーツ s を除外する
    rep(i,N)
      rep(j,M)
        if (A[i][j] == s)
          A[i][j]=-1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
MOD = int(1e9+7)
N = int(input())
S = input()
LR = [0]*(2*N)
LR[0] = 0
l, r = 1, 0
if S[0] == "W" or S[-1] == "W":
    print(0)
    exit()
for i in range(1, 2*N):
    if S[i-1] == S[i]:
        LR[i] = 0 if LR[i-1] == 1 else 1
    else:
        LR[i] = LR[i-1]
    if LR[i] == 0:
        l += 1
    else:
        r += 1
if l != r:
    print(0)
    exit()
L = 0
R = 0
count = 1
for w in LR:
    if w == 0:
        L += 1
    else:
        count *= L - R
        count %= MOD
        R += 1
for i in range(1, N+1):
    count = count * i % MOD
print(count)

Measured memory_bytes: 4968
import java.util.Scanner;

/**
 * Created by AMK on 8/27/2019.
 * Life is nice :)
 * Enjoy coding :D
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int arr[][] = new int[n][3];
        int dp[] = new int[3];
        for (int i = 0; i < n; i++) {
            arr[i][0] = scanner.nextInt();
            arr[i][1] = scanner.nextInt();
            arr[i][2] = scanner.nextInt();
            int xx[] = new int[3];
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    if (j != k) {
                        xx[j] = Math.max(xx[j], dp[k] + arr[i][k]);
                    }
                }
            }
            dp = xx;
        }
        System.out.println(Math.max(dp[0], Math.max(dp[1], dp[2])));
    }
}


Measured memory_bytes: 100276
use std::io::*;
use std::str::FromStr;
use  std::collections::BTreeSet;
use std::cmp::min;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let n: usize = read();
    let k: usize = read();
    let p: Vec<u64> = (0..n).into_iter().map(|_| read()).collect();
    let mut sum: Vec<f64> = Vec::with_capacity(n + 1);
    sum.push(0.0);
    for i in 0..n {
        let s = sum[i];
        sum.push(s + (p[i] as f64 + 1.0) / 2.0);
    }

    let mut ret: f64 = 0.0;
    for i in 0..(n - k + 1) {
        let tmp = sum[i + k] - sum[i];
        if ret < tmp {
            ret = tmp;
        }
    }
    println!("{:.6}", ret);
}


Measured memory_bytes: 8444
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(9);
  int count = 0;
  rep(i,n) cin >> a.at(i);
  rep(i,n){
    if(a.at(i)<=399) b.at(0)++;
    else if(a.at(i)<=799) b.at(1)++;
    else if(a.at(i)<=1199) b.at(2)++;
    else if(a.at(i)<=1599) b.at(3)++;
    else if(a.at(i)<=1999) b.at(4)++;
    else if(a.at(i)<=2399) b.at(5)++;
    else if(a.at(i)<=2799) b.at(6)++;
    else if(a.at(i)<=3199) b.at(7)++;
    else b.at(8)++;
  }
  rep(i,8){
    if(b.at(i)>=1)count++;
  }
//  cout << count << endl;
//  rep(i,9) cout << b.at(i) << " ";
//  cout << endl;
  
  //min
  if(count==0) cout << 1;
  else cout << count;
  
  //kuuhaku
  cout << " ";
  
  //max
  cout << count + b.at(8);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
int main()
{
  int n, t, a;
  cin >> n >> t >> a;
  vi h(n);
  re(i, n) cin >> h[i];

  vd v;
  re(i, n) {
    double ave = t - h[i] * 0.006;
    v.push_back(ave);
  }

  double tem = 100000;
  int p = 0;
  re(i, n) {
    if (abs(v[i] - a) < tem) {
      tem = abs(v[i] - a);
      p = i + 1;
    }
  }

  cout << p << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

// バブルソートで使うスワップ
// ループの中に書きたくなかったので関数化。
void swap(int& l, int &r) {
	int temp = l;
	l = r;
	r = temp;
}

int main() {
	int temp[5];
	for (int& a : temp) {
		cin >> a;
	}
	// 数が少ないのでバブルソートを実装してみる
	for (int i = 0; i < 4; ++i) {
		for (int j = 1; j < 5; ++j) {
			if (temp[j - 1] < temp[j]) {
				swap(temp[j - 1], temp[j]);
			}
		}
	}

	for (int i = 0; i < 5; ++i) {
		cout << temp[i];
		if (i != 4) {
			cout << " ";
		}
		else {
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1164
N = int(input())

dp = [N] * (N+1)

dp[0] = 0

for i in range(1,N+1):
    dp[i] = dp[i-1] + 1
    for k in range(1,10):
        if i < 6**k:
            break
        else:
            dp[i] = min(dp[i],dp[i-6**k]+1)
            
    for k in range(1,10):
        if i < 9**k:
            break
        else:
            dp[i] = min(dp[i],dp[i-9**k]+1)

print(dp[N])

Measured memory_bytes: 9460
#include <iostream>
#include <stack>
#include <cstring>

using namespace std;

struct R{
	int height;
	int pos;
};

int dp[505][505];

int calc_LARH (int n, int *hist )
{
	hist[n] = 0;
	stack<R> st;
	int res = 0;
	R curr;

	for (int i = 0; i <= n; i++ ){
		curr.height = hist[i];
		curr.pos = i;
		if (st.empty() ){
			st.push (curr );
			continue;
		} // end if

		if (st.top().height < hist[i] ){
			st.push (curr );
			continue;
		}else if (st.top().height == hist[i] ){
			continue;
		} // end if
		int last_pos = i;
		while (!st.empty() && st.top().height >= hist[i] ){
			R pre = st.top(); st.pop();
			int currs = pre.height*(i - pre.pos);
			res = max (res, currs );
			last_pos = pre.pos;
		} // end while
		curr.pos = last_pos;
		st.push (curr );
	} // end for

	return res;
}

int main()
{
	int h, w;

	while (cin >> h >> w && h && w ){
		memset (dp, 0, sizeof (dp ) );
		for (int i = 0; i < h; i++ ){
			for (int j = 0; j < w; j++ ){
				char b;
				cin >> b;
				if (b == '.' ){
					if (i == 0 ){
						dp[0][j] = 1;
					}else{
						dp[i][j] = dp[i-1][j] + 1;
					} // end if
				} // end if
			} // end for
		} // end for

		int res = 0;
		for (int i = 0;i < h; i++ ){
			int currs = calc_LARH (w, dp[i] );
			res = max (res, currs );
		} // end for
		cout << res << endl;	

	} // end loop

		
	return 0;
}

Measured memory_bytes: 0
//unsolved
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();
		long A[] = new long[N];	for(int i = 0; i < N; i++) {A[i] = sc.nextLong();}
		long F[] = new long[N];	for(int i = 0; i < N; i++) {F[i] = sc.nextLong();}
		Arrays.sort(A);
		Arrays.sort(F);
		long min = 0;
		long max = (long)Math.pow(10, 12);
		while(max > min) {
			long used = 0;
			long mid = (min + max)/2;
			for(int i = 0; i < N; i++) {
				if(mid/F[N-1-i] < A[i]) {
					used += A[i] - mid/F[N-1-i]; 
				}
			}
			if(used > K) {
				min = mid + 1;
			}else {
				max = mid;	
			}
		}
		System.out.println(min);
		sc.close();
	}
}

Measured memory_bytes: 98860
#include <iostream>
using namespace std;
const int mod = 1000000007;
int dp[55][1255][55];
int main() {
	int N, K;
	cin >> N >> K;
	if (K % 2 == 1) {
		cout << 0 << endl;
	}
	else {
		K >>= 1;
		dp[0][0][0] = 1;
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j <= K; ++j) {
				for (int k = 0; k <= i; ++k) {
					dp[i + 1][j + k][k + 1] = (dp[i + 1][j + k][k + 1] + dp[i][j][k]) % mod;
					dp[i + 1][j + k][k] = (dp[i + 1][j + k][k] + (2LL * k + 1LL) * dp[i][j][k]) % mod;
					if (k >= 1) {
						dp[i + 1][j + k][k - 1] = (dp[i + 1][j + k][k - 1] + 1LL * k * k * dp[i][j][k]) % mod;
					}
				}
			}
		}
		cout << dp[N][K][0] << endl;
	}
	return 0;
}

Measured memory_bytes: 17064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59


int main(){
    ll i,j,k;
    string s;
    cin>>s;
    ll l=s.size();
    ll dp[l+1][13];

    ll z[l];
    z[l-1]=1;
    for(i=l-2;i>=0;i--){
        z[i]=(z[i+1]*10)%13;
    }

    for(i=0;i<=l;i++){
        for(j=0;j<13;j++) dp[i][j]=0;
    }
    dp[l][0]=1;

    for(i=l-1;i>=0;i--){
        if(s[i]-'0'>=0&&s[i]-'0'<=9){
            for(j=0;j<13;j++){
                dp[i][(j+z[i]*(s[i]-'0'))%13]+=dp[i+1][j];
                dp[i][(j+z[i]*(s[i]-'0'))%13]%=Mod;
            }
        }
        else {
            for(k=0;k<10;k++){
                for(j=0;j<13;j++){
                    dp[i][(j+z[i]*k)%13]+=dp[i+1][j];
                    dp[i][(j+z[i]*k)%13]%=Mod;
                 }
            }
        }
    }

    cout<<dp[0][5]<<endl;

    
    return 0;
}

Measured memory_bytes: 11392
wood = input()

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

lis_1.sort()

guzai = 0

for i in range(int(wood)):
  max_gu = min(lis_1[2*i],lis_1[2*i+1])
  guzai += int(max_gu)
print(guzai)




Measured memory_bytes: 2940
input()
w=list(map(int,input().split()))
s=sorted(w)
x=s[0]
m={k:v for k,v in zip(s,w)if k!=v}
l=list(m.keys())
n=0
while l:
 a=l.pop();b=m[a];l.remove(b)
 if a==m[b]:n+=a+b
 else:
  t=[b]
  while 1:
   c=m[b];t+=[c]
   if c==a:p,q=len(t),min(t);n+=sum(t)+min((p-2)*q,q+(p+1)*x);break
   else:b=c;l.remove(c)
print(n)


Measured memory_bytes: 5720
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod =1e+9+7;

int main(){
    ll n; cin>>n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    ll stock=0;
    ll ans=1000;
    rep(i,n-1){
        if(a[i]<a[i+1]){
            stock=ans/a[i];
            ans+=(a[i+1]-a[i])*stock;
        }
    }
    cout<<ans<<endl;
}








































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

const int N = 1001;
const ll MAX = (1LL<<61);

ll dist[N];

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n, m; cin >> n >> m;

	for (int i = 0; i < n; i++) {
		dist[i] = MAX;
	}

	vector<pair<int,int>> edges(m);
	vector<ll> weights(m);
	for (int i = 0; i < m; i++) {
		ll u, v, w; cin >> u >> v >> w;
		u--; v--;
		edges[i] = {u,v};
		weights[i] = -w;
	}

	dist[0] = 0;

	for (int relax = 0; relax < n-1; relax++) {
		for (int i = 0; i < m; i++) {
			pair<int,int> e = edges[i];
			if (dist[e.first] == MAX) {
				continue;
			}
			if (dist[e.first] + weights[i] < dist[e.second]) {
				dist[e.second] = dist[e.first] + weights[i];
			}
		}
	}

	ll ans = dist[n-1];

	for (int i = 0; i < m; i++) {
		pair<int,int> e = edges[i];
		if (dist[e.first] == MAX) {
			continue;
		}
		if (dist[e.first] + weights[i] < dist[e.second]) {
			dist[e.second] = dist[e.first] + weights[i];
		}
	}

	if (ans > dist[n-1]) {
		cout << "inf" << endl;
	} else {
		cout << -dist[n-1] << endl;
	}
 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> ans(n);
  int k;
  rep(i,n) {
    cin >> k;
    k--;
    ans[k] = i;
  }
  rep(i,n-1) {
    cout << ans[i] + 1 << " ";
  }
  cout << ans[n-1] + 1 << endl;
  return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 			1000000007
#define tc(t) 			int t;cin >> t;while(t--)
#define for0(i , n)		for(int i=0;i<n;i++)
#define loop(i , a, b)	for(int i=a;i<=b;i++)
#define endl 			'\n'
#define inf 			1e18
#define fi 				first
#define se 				second

int XX[8] = { +1, +1, +1, 0, 0, -1, -1, -1};
int YY[8] = { +1, 0, -1, +1, -1, +1, 0, -1};
int dx[4] = { -1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int a[22][22];
int dp[22][1LL << 22];
int n;

int solve(int i, int x) {
	if (i == n) {
		if (x == 0) return 1;
		return 0;
	}

	if (dp[i][x] != -1) return dp[i][x];

	int ans = 0;

	for (int w = 0; w < n; w++) {
		bool available = (((1 << w)&x) == 0 ? 0 : 1);
		if (available && a[i][w]) {
			ans += solve(i + 1, x ^ (1 << w));
			if (ans >= mod) ans -= mod;
		}
	}

	return dp[i][x] = ans;
}

signed main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif

	cin >> n;

	for0(i, n) {
		for0(j, n) {
			cin >> a[i][j];
		}
	}

	memset(dp, -1, sizeof(dp));

	cout << solve(0, (1LL << n) - 1) << endl;

	return 0;
}

Measured memory_bytes: 724504
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

ll a, b, c, d;
const ll inf = 1LL<<60;
map<ll, ll> mp;

ll rec(ll now) {
    if (now == 0) return 0;
    if (now == 1) return d;
    if (mp.count(now)) {
        return mp[now];
    }
    ll res = inf;
    if (now <= inf / d) chmin(res, now * d);
    for (int x : vector<int>{2, 3, 5}) {
        ll cost;
        if (x == 2) cost = a;
        else if (x == 3) cost = b;
        else cost = c;
        ll k = now % x;
        if (k == 0) {
            chmin(res, rec(now/x) + cost);
        } else {
            chmin(res, rec(now/x) + d*k + cost);
            chmin(res, rec(now/x + 1) + (x-k)*d + cost);
        }
    }
    return mp[now] = res;
}

void solve() {
    ll n;
    cin >> n >> a >> b >> c >> d;
    cout << rec(n) << endl;
    mp.clear();
}

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

    int t;
    cin >> t;
    while (t--) solve();
}


Measured memory_bytes: 4344
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
ll solve(ll x){
    ll ans=0;
    for(int i=1;i<=10;i++){
        ll n=x*i;
        ans+=(x%10);
    }
    return ans;
}
int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll A[n+1];
    for(int i=0;i<n;i++)cin>>A[i];
    vector<ll>v(n,INT_MAX);
    v[0]=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<=i+k;j++){
            if(j<n){
                v[j]=min(v[j],v[i]+abs(A[j]-A[i]));
            }
        }
    }
    cout<<v[n-1];
    
    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define re return
#define pb push_back
#define po pop_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define si size
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pi 3.14159265359
#define er erase
#define in insert
#define em empty
#define ft front
#define fo(i,n) for(i = 0; i < n; i++)
#define ro(i,n) for(i = n - 1; i >= 0; i--)
#define fr(i,j,n) for(i = j; i < n; i++)
#define rf(i,j,n) for(i=n-1;i>=j;i--)
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::pair<int,int> ii;
typedef std::vector<ii> vii;
typedef std::vector<std::string> vs;
typedef double dl;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> vll;
#define filename ""
using namespace std;
    int a[26];
int main()
{
    /*
	freopen(filename".in","r",stdin);
	freopen(filename".out","w",stdout);
	*/
	/*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    */
    /*
    ios::sync_with_stdio(0);
    */
    string s,t;
    cin>>s;
    int i;
    if (s=="zyxwvutsrqponmlkjihgfedcba")
    {
        cout<<-1;
        re 0;
    }
    if (s.length()==26)
    {
        t=s;
        next_permutation(all(s));
        fo(i,s.length())
        {
            if (s[i]!=t[i])
            {
                cout<<s.substr(0,i+1);
                re 0;
            }
        }
    }
    fo(i,s.length())
    {
        a[s[i]-'a']++;
    }
    cout<<s;
    fo(i,26)
    {
        if (!a[i])
        {
            cout<<(char)(i+'a');
            re 0;
        }
    }
}


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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

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

    int N; cin >> N;
    unordered_map<string, int> counter;
    unordered_map<string, int> counter_raw;

    ll ans = 0;
    string s;
    rep(i, N) {
        cin >> s;
        if (++counter_raw[s] >= 2) {
            ans -= counter_raw[s] - 1;       
        }
        sort(all(s));
        if (++counter[s] >= 2) {
            ans += counter[s] - 1;       
        }
    }

    // for(auto it = counter.begin(); it != counter.end(); it++) {
    //     if (it->second >= 2)
    //         ans += it->second * (it->second - 1) / 2;
    // }
    // for(auto it = counter_raw.begin(); it != counter_raw.end(); it++) {
    //     if (it->second >= 2)
    //         ans -= it->second * (it->second - 1) / 2;
    // }
    cout << ans << endl;
}


Measured memory_bytes: 20936
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
int main(){
    ll a,b,n;
    cin >> a >> b >> n;
    ll k = min(b-1,n);
    ll ans = (a*k)/b - a*(k/b);
    cout << ans << endl;
}

Measured memory_bytes: 3604
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] numlist = new int[N];
    
    for(int i=0;i<N;i++){
      numlist[i]=sc.nextInt();
    }
    Arrays.sort(numlist);
    
    int diff=numlist[N-1]-numlist[0];
    
    System.out.println(diff);
  }
}

    

Measured memory_bytes: 23892
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int x = Integer.parseInt(str[0]);
    int y = Integer.parseInt(str[1]);
    boolean flg = false;
    for(int i=0; i<=x; i++) {
      if(2*i+4*(x-i)==y) {
        System.out.println("Yes");
        flg = true;
        break;
      }
    }
    System.out.println(flg==false?"No":"");
  }
}

Measured memory_bytes: 32736
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////


int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int N; cin >> N;
	vector<int> a(N);
	rep(i,N) cin >> a[i];

    set<int> dic;
	rep(i,N) dic.emplace(a[i]);

	cout << dic.size() << endl;
}



Measured memory_bytes: 7812
#include<stdio.h>
#include<string.h>
#include<math.h>
int gcd(int a,int b){
	if(b!=0)
		return gcd(b,a%b);
	return a;
}
int main(void)
{
	int n,i,x,a;
	x=0;
	int sum=0;
	scanf("%d",&n);
	scanf("%d",&a);
	sum=a;
	for(i=2;i<=n;i++)
	{
		scanf("%d",&a);
		sum=gcd(sum,a);
	}
	while(sum%2==0)
	{
		x++;;
		sum=sum/2;
	}
	printf("%d\n",x);
	return 0;
 } 

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

int frog(int n,int k,int a[],int dp[])
{
	//base case
	if(n==1)
		return 0;

	if(dp[n]!=INT_MAX)
		return dp[n];

	for (int i =1;i<=k;++i)
	{
		if((n-i)>=1)
			dp[n]=std::min(dp[n],abs(a[n]-a[n-i])+frog(n-i,k,a,dp));
	}
	return dp[n];
}
int main()
{

	int n;cin>>n;
	int k;cin>>k;

	int a[n+1];
	int dp[n+1];

	for (int i = 0; i < n+1; ++i)
	{
		dp[i]=INT_MAX;
	}

	for (int i = 1; i <=n; ++i)
	{
		cin>>a[i];
	}
	int ans=frog(n,k,a,dp);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10368
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll
#define INF INT_MAX/10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;


vector<int> Input(100100);

signed main() {
  int N;
  cin >> N;
  int sum = 0;
  for (int i = 1; i <= N; i++) {
    cin >> Input[i];
    if (i % 2 == 0) {
      sum -= Input[i];
    } else {
      sum += Input[i];
    }
  }

  int x = sum / 2;
  cout << 2 * x << " ";

  for (int i = 1; i <= N; i++) {
    x = Input[i] - x;
    if (i != N) {
      cout << 2 * x << " ";
    }
  }
  cout << endl;
  
  
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>

using namespace std;

int n, a[100], b[100], cnt;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main() {
   int x,y,z; cin >> x >> y >> z;
   swap(x,y);
   swap(x,z);
   cout << x << " " << y << " " << z << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] c = sc.next().toCharArray();
        boolean bl = true;
        Arrays.sort(c);
        for (int i=1; i<c.length; i++) {
            if (c[i-1] == c[i]) {
                bl = false;
                break;
            }
        }
        System.out.println(bl?"yes":"no");
    }
}

Measured memory_bytes: 22740
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] wei = new int[num];
        int[] ans = new int[num-1];
        int sum = 0;
        int t = 0;

        for(int i = 0;i < num;i++){
            wei[i] = sc.nextInt();
            sum += wei[i];
        }
        
        for(int i = 0;i < num-1;i++){
            int s1 = 0;
            for(int j = 0;j <= t;j++){
                s1 += wei[j];
            }
            ans[i] = Math.abs(sum-(2*s1));
            t++;
        }
        Arrays.sort(ans);
        System.out.println(ans[0]);
    }
}

Measured memory_bytes: 24020
;/**
        	C++14 (GCC 5.4.1)
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;

int main(){
    int A,B;

    cin >> A >> B;

    int m = (A - (B*2) ) > 0 ?  A - (B*2) : 0;
    cout << m << endl;
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

vector<int> a;

int main(){
  REP(i,3){
    int s;
    cin >> s;
    a.push_back(s);
  }
  int k;
  cin >> k;
  sort(a.begin(),a.end());
  REP(i,k){
    a[2] *= 2;
  }
  cout << a[0] + a[1] + a[2] << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 27;
const double EPS = 1e-10;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
#define repD(i, n) for(int i = n; i >= 0; i--)

ll v[100];
ll d[100];
ll ratio[100];

ll gcd(ll u, ll v){
	while(u > 0){
		if(v > u) swap(u, v);
		u %= v;
	}
	return v;
}

ll lcm(ll u, ll v){
	return u / gcd(u, v) * v;
}

int main(){
	int n;
	while(cin >> n && n){
		rep(i, n){
			cin >> d[i] >> v[i];
		}
		fill(ratio, ratio + 10, 1);
		rep(i, n){
			ll b = v[i] * d[0];
			ll a = v[0] * d[i];
			ll c = gcd(a, b);
			a /= c;
			b /= c;
			ll next = lcm(ratio[0], a);
			ll mul = next / ratio[0];
			rep(j, i) ratio[j] *= mul;
			ratio[i] = next / a * b;
		}
		rep(i, n) cout << ratio[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.IOException;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();

		int tp = 0;
		int hp = 0;

		for(int i=0;i<x;i++) {
			String t = sc.next();
			String h = sc.next();

			if(t.equals(h)) {
				tp += 1;
				hp += 1;
			}else if(t.compareTo(h) > 0) {
				tp += 3;
			}else {
				hp += 3;
			}
		}

		System.out.println(tp + " " + hp);

		sc.close();
	}
}


Measured memory_bytes: 29764
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()
import fractions
gcd=fractions.gcd
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0

n=I()
p=tuple(int(i) for i in input().split())
q=tuple(int(i) for i in input().split())

k=permutations(range(1,n+1))
for j,i in enumerate(k):
    if p==i:pn=j
    if q==i:qn=j
    
#ans=bisect.bisect(perm,p)-bisect.bisect(perm,q)

ans=abs(pn-qn)
print(ans)



Measured memory_bytes: 65772