akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int dp[1 << 18][51];
int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int n;
  cin >> n;
  int a[n], b[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  int m = (1 << n);
  // dp[mask][val] = use all elements in mask s.t. sequence ends in val and no. of swaps is least
  for (int i = 0; i < m; i++)
    for (int j = 0; j <= 50; j++)
      dp[i][j] = INT_MAX;
  dp[0][0] = 0;
  for (int mask = 0; mask < m; mask++) {
    for (int last = 0; last <= 50; last++) {
      // already mask elements are taken and their last element is last.
      int taken = 0;
      for (int pos = 0; pos < n; pos++) {
        if (mask & (1 << pos)) // this pos already taken so can't take it again
          taken++;
        else {
          int newmask = (mask | 1 << pos), nextpos = __builtin_popcount(mask), curr;
          if ((pos & 1) == (nextpos & 1)) // same parity, so when pos will come on nextpos, a will be present in a[nextpos]
            curr = a[pos];
          else
            curr = b[pos];
          if (curr >= last && dp[mask][last] != INT_MAX) // the last state was reachable and curr element is greater than last element of the sequence
            dp[newmask][curr] = min(dp[newmask][curr], dp[mask][last] + pos - taken);
        }
      }
    }
  }
  int ans = INT_MAX;
  for (int i = 0; i <= 50; i++)
    ans = min(ans, dp[m - 1][i]);
  if (ans == INT_MAX)
    ans = -1;
  cout << ans;
  return 0;
}

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

if n <= 111:
    print(111)
elif n <= 222:
    print(222)
elif n <= 333:
    print(333)
elif n <= 444:
    print(444)
elif n <= 555:
    print(555)
elif n <= 666:
    print(666)
elif n <= 777:
    print(777)
elif n <= 888:
    print(888)
elif n <= 999:
    print(999)

Measured memory_bytes: 61748
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 998244353//1000000007
#define inf 1000000007
#define ll long long
#define ull unsigned long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 200010
#define _DEBUG
template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}
inline int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}
int pow(int a,int b,int c){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%c;
        a=1LL*a*a%c;b>>=1;
    }
    return ans;
}

int main(){
    //srand(time(NULL)+clock());
    int ca=0,T,k,i,j,m=0,n;
    double start=clock();
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    k=min(a,c);
    int ans=k;
    a-=k,c-=k;
    if(c){
        k=min(c,b);
        ans+=2*k;
        c-=k,b-=k;
    }
    if(b)ans+=b;
    ans+=min(c,1);
    printf("%d\n",ans);
    cerr<<(1.*clock()-start)/CLOCKS_PER_SEC<<"\n";
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String s[] = new String[N];
		
		boolean bl = false;
		for(int i=0; i<N; i++){
			s[i] = sc.next();
			if(s[i].equals("Y"))bl=true;
		}
		System.out.println(bl==true?"Four":"Three");
	}
}

Measured memory_bytes: 21972
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

for i in range(N):
	if A[i]%2 == 1:
		continue
	else:
		if A[i]%3 == 0:
			continue
		if A[i]%5 == 0:
			continue
		print("DENIED")
		exit()
print("APPROVED")

Measured memory_bytes: 61164
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main() { (new Solver()).Run(); }
}

class Solver
{
    public void Run()
    {
        var N = int.Parse(Console.ReadLine());
        var dict = new Dictionary<string, int>();

        for (var i = 0; i < N; i++)
        {
            var t = Console.ReadLine();
            if (dict.ContainsKey(t))
                dict[t]++;
            else
                dict[t] = 1;
        }

        var max = dict.Max(z => z.Value);
        foreach (var d in dict.Where(x => x.Value == max).OrderBy(z => z.Key, StringComparer.OrdinalIgnoreCase))
        {
            Console.WriteLine(d.Key);
        }
    }
}


Measured memory_bytes: 46320
#include <iostream>

using namespace std;

const int N = 10, D = 10, X = 10e5;

int price[D][N] = { 0 };
int dp[X] = { 0 };

int main(){
	int n, d, x, diff, v;
	cin >> n >> d >> x;
	for(int i = 0;i < d;++i) {
		for(int j = 0;j < n;++j){
			cin >> price[i][j];
		}
	}
	for(int i = 0;i < d - 1;++i){
		v = 0;
		for(int j = 0;j <= x;++j){
			dp[j] = 0;
		}
		for(int j = 1;j <= x;++j){
			for(int k = 0;k < N;++k){
				diff = price[i + 1][k] - price[i][k];
				if(j - price[i][k] >= 0){
					dp[j] = max(dp[j], diff + dp[j - price[i][k]]);
				}
				v = max(v, dp[j]);
			}
		}
		x += v;
	}
	cout << x << endl;
	return 0;
}



Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int n;
  	cin >> n;
 	long long res = 0;
  	for(int i=0;i<n;i++){
    	int a = i+1;
      	if(a % 3 == 0 || a % 5 == 0) continue;
      	else res += a;
    }
  	cout << res << endl;
}

Measured memory_bytes: 3536
k=int(input())
d=dict()
for i in range(k):
    x=input()
    d[x]=d.get(x,0)+1
q=list()
for k,v in d.items():
    q.append( (v,k) )
bigV=0
for (v,k) in sorted(q,reverse=True):
    if(v>bigV):
        bigV=v
for (v,k) in sorted(q):
    if(v==bigV):
        print(k)


Measured memory_bytes: 48176
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> C[i];
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  ll res = 0;
  for (int i = 0; i < N; i++) {
    res += distance(A.begin(), lower_bound(A.begin(), A.end(), B[i])) *
           distance(upper_bound(C.begin(), C.end(), B[i]), C.end());
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 1408
n, q = map(int, input().split())
S = input().strip()
*LR, = (map(int, input().split()) for _ in range(q))

A = [0] * n
for i in range(1, n):
    A[i] = A[i-1] + (S[i-1] == 'A' and S[i] == 'C')
for l, r in LR:
    print(A[r-1]-A[l-1])

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
typedef vector<pi> vp;

#define pb push_back
#define mp make_pair
#define fora(i, a, n) for(int i = a; i < n; i++)
#define forb(i, a, n) for (int i = a; i >= (n); --i)
#define PI 3.1415926535897932384626433832795
#define INF 1e9

int main(){ 
ios::sync_with_stdio(false);
cin.tie(NULL);
//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

int a, b, c; 
cin >> a >> b >> c;
cout << c << " " << a << " " << b << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
using namespace std;
int n;
int a[200010];
int ind[200010];
vector<int>ans;
set<int>st;
set<int>bar;
int mnum;
struct segment_tree{
	int mn[1<<20],N,sz;
	void init()
	{
		N=1;
		while(N<n)N*=2;
		for(int i=0;i<N*2-1;i++)mn[i]=1e9;
	}
	void pushup(int x)
	{
		while(x>0)
		{
			x=(x-1)>>1;
			mn[x]=min(mn[(x<<1)+1],mn[(x<<1)+2]);
		}
	}
	void ins(int x)
	{
		int pos=(sz++)+N-1;
		mn[pos]=x;
		pushup(pos);
	}
	int query(int a,int b,int k,int l,int r)
	{
		if(a>=r || b<=l)return 1e9;
		if(a<=l && b>=r)return mn[k];
		return min(query(a,b,(k<<1)+1,l,(l+r)>>1),query(a,b,(k<<1)+2,(l+r)>>1,r));
	}
}s[2];
int main()
{
	scanf("%d",&n);
	s[0].init();
	s[1].init();
	for(int i=1;i<=n;i++)
	{
		scanf("%d",a+i);
		ind[a[i]]=i;
	}
	for(int i=1;i<=n;i++)
	{
		s[i&1].ins(a[i]);
		s[(i&1)^1].ins(1e9);
	}
	st.insert(s[1].query(0,n-1,0,0,s[1].N));
	bar.insert(0);
	bar.insert(n+1);
	int l=0; 
	while(l<n)
	{
		mnum=*st.begin();
		ans.push_back(mnum);
		int w=ind[mnum];
		int mnn=1e9;
		set<int>::iterator it1=bar.lower_bound(w);
		set<int>::iterator it2=it1;
		it1--;
		mnn=min(mnn,s[(w&1)^1].query(w,(*it2)-1,0,0,s[(w&1)^1].N));
		ans.push_back(mnn);
		st.erase(st.begin());
		int tt=s[w&1].query((*it1),w-1,0,0,s[w&1].N);
		if(tt!=1e9)st.insert(tt);
		tt=s[(w&1)^1].query(w,ind[mnn]-1,0,0,s[(w&1)^1].N);
		if(tt!=1e9)st.insert(tt);
		tt=s[w&1].query(ind[mnn],(*it2)-1,0,0,s[w&1].N);
		if(tt!=1e9)st.insert(tt);
		bar.insert(w);
		bar.insert(ind[mnn]);
		l+=2;
	}
	for(int i=0;i<n;i++)printf("%d ",ans[i]);
	return 0;
}

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

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define mod 1000000007
#define ull unsigned long long
#define mst(ss,b) memset(ss,b,sizeof(ss));
#define pl(x) cout << #x << "= " << x << endl;
const double eps = 1e-12;
const int inf = 0x3f3f3f3f;

ll a[55][55];
int N, A, B;
map<ll, int>mp;
set<ll>st;

//杨辉三角模板
void comb_table(int n){
    for(int i=0;i<=n;++i){
        for(int j=0;j<=i;++j){
            if(j==0 or j==i){
                a[i][j]=1LL;
            }else{
                a[i][j]=(a[i-1][j-1]+a[i-1][j]);
            }
        }
    }
}

int  main(){
    comb_table(50);
    scanf("%d%d%d", &N, &A, &B);
    for(int i=1; i<=N; i++){
        ll x;
        scanf("%lld", &x);
        mp[x]++;
        st.insert(x);
    }
    double mx = 0.0;
    ll ans = 0;
    int tmp = A, num = 0;
    auto it=st.rbegin();
    for(; it!=st.rend(); it++){
        if(tmp >= mp[*it])mx += mp[*it]*(*it), tmp -= mp[*it];
        else mx += tmp*(*it), num = tmp, tmp = 0;
        if(tmp == 0)break;
    }
    mx /= A;
    if(it != st.rbegin()){
        printf("%.6f\n", mx);
        ans = a[mp[*it]][num];
        printf("%lld\n", ans);
    }
    else{
        printf("%.6f\n", mx);
        for(int i=A; i<=B; i++)ans += a[mp[*it]][i];
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		int N,K;
		Scanner sc = new Scanner(System.in);
		N=sc.nextInt();//何日間の予定を考えるか
		K=sc.nextInt();//何日間の予定が決まっているか
		int pasta[][]=new int[6][N+1];
		int pastaplan[]=new int[N+1];
		for(int i=0;i<K;i++){
			int day=sc.nextInt();//何日の予定が決まっているか
			pastaplan[day]=sc.nextInt();//その日のパスタは何か
		}
		if(pastaplan[1]==0){//もし１日目の予定が決まっていなければ
			pasta[1][1]=1;pasta[3][1]=1;pasta[5][1]=1;
			
		}else if(pastaplan[1]==1){
			pasta[1][1]=1;
		}else if(pastaplan[1]==2){
			pasta[3][1]=1;
		}else if(pastaplan[1]==3){
			pasta[5][1]=1;
		}
		for(int j=2;j<=N;j++){
			if(pastaplan[j]==0){//j日の予定がきまってなければ
				pasta[0][j]=pasta[1][j-1];//２日連続の時には前日の１日目の値がそのままくる。
				pasta[2][j]=pasta[3][j-1];
				pasta[4][j]=pasta[5][j-1];
				pasta[1][j]=pasta[2][j-1]%10000+pasta[3][j-1]%10000+pasta[4][j-1]%10000+pasta[5][j-1]%10000;
				pasta[3][j]=pasta[0][j-1]%10000+pasta[1][j-1]%10000+pasta[4][j-1]%10000+pasta[5][j-1]%10000;
				pasta[5][j]=pasta[0][j-1]%10000+pasta[1][j-1]%10000+pasta[2][j-1]%10000+pasta[3][j-1]%10000;
			}else if(pastaplan[j]==1){//j日の予定がトマトだったら
				pasta[0][j]=pasta[1][j-1];//２日連続の時には前日の１日目の値がそのままくる。
				pasta[1][j]=pasta[2][j-1]+pasta[3][j-1]+pasta[4][j-1]+pasta[5][j-1];
			}else if(pastaplan[j]==2){
				pasta[2][j]=pasta[3][j-1];
				pasta[3][j]=pasta[0][j-1]+pasta[1][j-1]+pasta[4][j-1]+pasta[5][j-1];
			}else{
				pasta[4][j]=pasta[5][j-1];
				pasta[5][j]=pasta[0][j-1]+pasta[1][j-1]+pasta[2][j-1]+pasta[3][j-1];
			}
		}
		int sum=pasta[0][N]%10000+pasta[1][N]%10000+pasta[2][N]%10000+pasta[3][N]%10000+pasta[4][N]%10000+pasta[5][N]%10000;
		System.out.println(sum%10000);
	}
}

Measured memory_bytes: 19688
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

void Check(map<char, int> m) {
	string ans = "Yes";
	FOR_ITR(m) {
		if (itr->second % 2 != 0) {
			ans = "No";
			break;
		}
	}
	cout << ans << endl;
}

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	string w;
	map<char, int> m;
	
	cin >> w;
	FOR(i, 0, w.length()) {
		if (m.count(w[i])==0) {
			m.insert(MP(w[i], 1));
		}
		else {
			m.insert(MP(w[i], ++m[w[i]]));
		}
	}

	Check(m);
	
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int count = 0;
  for (int i=0; i<N; i++) {
    vector<int> l(N),r(N);
    cin >> l.at(i) >> r.at(i);
    count += (r.at(i)-l.at(i)+1) ;
  }
  
  cout << count << endl;
  
}

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

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

int a[200010];
double sum[400010];

int main(void) {
	int N,K;
	double ans = 0;
	vector <double> v;
	cin >> N >> K;
	REP(i,N) cin >> a[i];
	sum[0] = 0;
	REP(i,N) sum[i+1] = sum[i]+((double)a[i]+1.0)/2.0;
	REP(i,N) ans = max(ans, sum[i+K]-sum[i]);
	printf("%.12lf\n",ans);
	return 0; 
}


Measured memory_bytes: 2560
import java.util.*;
import java.util.stream.*;

class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int[] cities_andX = new int[N+1];
    for(int i=0;i<N+1;i++){
      cities_andX[i] = scan.nextInt();
    }
    scan.close();
    
    Arrays.sort(cities_andX);
    
    int[] distances = new int[N];
    for(int i=0;i<N;i++){
      distances[i] = Math.abs(cities_andX[i]-cities_andX[i+1]);
    }
    
    int result = Arrays.stream(distances).distinct().sorted().reduce((a,b)->{
      int tmp;
      while((tmp=b%a)!=0){b=a;a=tmp;}
      return a;
    }).getAsInt();
    System.out.println(result);
      
  }//main
}//Main

Measured memory_bytes: 53928
#include <cmath>
#include <iostream>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;

int main() {
  int n, t, a, h;
  cin >> n >> t >> a;
  double diff = 10000.0;
  int idx = -1;
  for (int i = 0; i < n; ++i) {
    cin >> h;
    double x = t - h * 0.006;
    double b = abs(a - x);
    if (b < diff) {
      idx = i + 1;
      diff = b;
    }
  }
  cout << idx << endl;
  return 0;
}


Measured memory_bytes: 3172
#include<iostream>
#include<cstdio>
#define sc(n) scanf("%d",&n)
#define sc2(x,y) scanf("%d %d",&x,&y)
#define fornt(i,n) for(i=0; i<n; ++i)
using namespace std;


int main ()
{
   int a,sum=0;
   sc(a);
   sum = (a) + (a*a) + (a*a*a);
   printf("%d\n",sum);
}


Measured memory_bytes: 3228
N = int(input())
if N>=400 and N<600:
  print(8)
elif N>=600 and N<800:
  print(7)
elif N>=800 and N<1000:
  print(6)
elif N>=1000 and N<1200:
  print(5)
elif N>=1200 and N<1400:
  print(4)
elif N>=1400 and N<1600:
  print(3)
elif N>=1600 and N<1800:
  print(2)
else:
  print(1)

Measured memory_bytes: 9072
#include<iostream>
using namespace std;
int main() {
	int n, x, min,sum=0;
	int v[100];
	cin >> n >> x;
	min = x;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		sum += v[i];
		if (min > v[i])min = v[i];
	}
	cout << (x - sum) / min + n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define ll long long
using namespace std;
 
int main() {
  int p, q, r;
  cin >> p >> q >> r;
  cout << min(p + q, min(q + r, r + p));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int cnt1[5000000]={},cnt2[5000000]={};
int main()
{
    int n,maxx1=0,maxx2=0,index1=0,index2=0,maxx11=0,maxx22=0,ans=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i+=2){
        cnt1[a[i]]++;
        if(cnt1[a[i]]>maxx1) maxx1=cnt1[a[i]],index1=a[i];
    }
    for(int i=1;i<n;i+=2){
        cnt2[a[i]]++;
        if(cnt2[a[i]]>maxx2) maxx2=cnt2[a[i]],index2=a[i];
    }
    for(int i=0;i<n;i+=2){
        if(cnt1[a[i]]>maxx11 && a[i]!=index1) maxx11=cnt1[a[i]];
    }
    for(int i=1;i<n;i+=2){
        if(cnt2[a[i]]>maxx22 && a[i]!=index2) maxx22=cnt2[a[i]];
    }
    if(index1==index2){
        ans=max((maxx1+maxx22),(maxx11+maxx2));
    }
    else ans=maxx1+maxx2;
    cout<<n-ans;
}


Measured memory_bytes: 4812
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int K, Q;
	cin >> K >> Q;
	vector<ll> D(K), N(Q), X(Q), M(Q);
	for(int i=0; i<K; i++) cin >> D[i];
	for(int i=0; i<Q; i++){
		cin >> N[i] >> X[i] >> M[i];
	}

	vector<ll> Dm(K);
	for(int i=0; i<Q; i++){
		for(int j=0; j<K; j++) Dm[j] = D[j]%M[i];

		ll sum = 0;
		ll eq = 0;
		for(int j=0; j<K; j++) sum += Dm[j];
		for(int j=0; j<K; j++){
			if(Dm[j]==0) eq++;
		}
		eq *= (N[i]-1) / K;
		ll total = X[i]%M[i] + sum * ((N[i]-1) / K);
		for(int j=0; j<(N[i]-1)%K; j++){
			total += Dm[j];
			if(Dm[j]==0) eq++;
		}
		ll cnt = total / M[i];
		ll rem = total % M[i];
		debug(sum, total, cnt, rem, eq);

		cout << N[i]-1-cnt-eq << endl;
	}

	return 0;
}


Measured memory_bytes: 512
N = int(input())
s = []

for i in range(N):
  s.append(int(input()))
  
S = sum(s)

if S%10 != 0:
  print(S)
else:
  b = True
  for j in range(N):
    if  s[j]%10 == 0:
      continue
    else:
      b = False
  if b:
    print(0)
  else:
    s.sort()
    for k in range(N):
      if s[k]%10 != 0:
        print(S-s[k])
        break

Measured memory_bytes: 9020
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
	
	int N, a, b[200], price_a, price_b;
	
	cin >> N;
	
	cin >> price_a >> price_b;
	
	cin >> a;
	
	for(int i = 0; i < N; i++){
		cin >> b[i];
	}
	
	sort(b, b + N);
	
	int c_sum, p_sum;
	
	c_sum = a;
	p_sum = price_a;
	
	for(int i = N - 1; i >= 0; i--){
		if((c_sum + b[i]) / (p_sum + price_b) >= c_sum / p_sum){
			c_sum += b[i];
			p_sum += price_b;
		}else{
			break;
		}
	}
	
	printf("%d\n", c_sum / p_sum);
	
	return 0;
}

Measured memory_bytes: 1164
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
//作者:中国江苏南京丁天行
using namespace std;
int n,a[200005];
ll ans;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d",a+i);
    if(a[1]){
        puts("-1");
        return 0;
    }
    for(int i=2;i<=n;++i){
        if(a[i-1]<a[i]-1){
            puts("-1");
            return 0;
        }
    }
    for(int i=2;i<=n;++i){
        if(!a[i]) continue;
        if(a[i-1]+1>a[i])ans+=a[i]*1ll;
        else ans+=1ll;
    }
    printf("%lld\n",ans);
	//system("pause");
	return 0;
}


Measured memory_bytes: 1024
#include <cstdlib>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <stack>
#include <utility>
#include <unordered_set>
#include <unordered_map>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/multi_array.hpp>

using namespace std;

#if 0
// memo
abs()

start_with(str, "hoge");
ends_with(str, "hoge");

std::sort(d.begin(), d.end());
d.erase(std::unique(d.begin(), d.end()), d.end());
#endif

using namespace boost;
using namespace boost::algorithm;

/**

   @retuen msb pos + 1,
   @retval 0 not found
 */
template<size_t SZ>
size_t msb(const std::bitset<SZ>& s) {
    for (size_t i = SZ; i != 0; --i) {
        if (s[i-1]) {
            return i;
        }
    }
    return 0;
}


static inline bool isOdd(int v)
{
    return v & 0x01;
}

int main()
{
    string S;
    cin >> S;

    const auto L = S.size();
    uint64_t allsum = 0;

    for (uint64_t patterns = 0; patterns < 1<<(L-1); ++patterns) {
        uint64_t result = 0;
        uint64_t work = 0;
        for (size_t i = 0; i < L - 1; ++i) {
            work += lexical_cast<uint64_t>(S[i]);
            if ((patterns>>i) & 1) {
                result += work;
                work = 0;
            }
            else {
                work *= 10;
            }
        }
        work += lexical_cast<uint64_t>(S[L-1]);
        result += work;

        allsum += result;
    }

    std::cout << allsum << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    vector<int> vc(4,0);
    int abcd;
    cin >> abcd;
    for(int i=0; i<4; i++){
        int keta = abcd%10;
        abcd /= 10;
        vc[3-i] = keta;
    }

    for(int bit=0; bit<(1<<3); bit++){
        vector<bool> plusminus(3, false);
        int tmp_num = vc[0];
        for(int i=0; i<3; i++){
            if(bit & 1<<i) plusminus[i] = true;
        }
        for(int i=0; i<3; i++){
            if(plusminus[i]) tmp_num += vc[i+1];
            else tmp_num -= vc[i+1];
        }
        if(tmp_num == 7){
           cout << vc[0];
           for(int i=0; i<3; i++){
               if(plusminus[i]) cout << '+';
               else cout << '-';
               cout << vc[i+1];
           }
           cout << '=' << 7 << endl;
           break;
        }
    }

    return 0;
}


Measured memory_bytes: 3644
n,m=map(int,input().split())
a=[]
mod=1000000007
for _ in range(m):
    a.append(int(input()))
a=set(a)
ans=[1]+[0]*(n)
for i in range(1,n+1):
    if i in a:
        ans[i]=0
    else:
        ans[i]=(ans[i-1]+ans[i-2])%mod
print(ans[n])

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll n,m;
string s;
//Write From this Line

const int mod = 1e9+7;
int main()
{
	int k ;
	cin >> n >> k;
	vector<ll> num(k,0);
	for(int i = 1 ; i <= n ; i ++) num[i%k] ++ ;//num[x] = k で割ってx余る数が１以上N以下に何個あるか
	ll res = 0 ;
	rep(a,k){
		int b = ( k - a ) % k ;
		int c = ( k - a ) % k ;
		if( ( b + c ) % k != 0) continue;
		res += num[a] * num[b] * num[c] ;
	}
	cout << res << endl;
	//けんちょんさんの写経

}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;



int main(){
    int n,m;
    cin >> n >> m;
    vector<int> h(n);
    vector<bool> flag(n);
    vector<vector<int>> r(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
        flag[i] = true;
    }    
    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        r[a].push_back(b);
        r[b].push_back(a);
    }
    for(int i = 0; i < n; i++){
        if(!flag[i]) continue;
        for(auto p:r[i]){
            if(h[i] < h[p]){
                flag[i] = false;
            }
            else if(h[p] < h[i]){
                flag[p] = false;
            }
            else{
                flag[i] = false;
                flag[p] = false;
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(flag[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8808
#include <stdio.h>
int main(void){
  
  int n;
  scanf("%d",&n);
  int a[n];
  int i;

  for (i = 0; i < n; i++)
    {
      scanf("%d",&a[i]);
    }
  
  printf("%d",a[i-1]);
  for(i = i-2;i>-1;i--)
    {
      printf(" %d",a[i]);
    }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <math.h>

typedef struct {
  double x,y;
}Point;

void koch (int n,Point a,Point b) {
  if (n == 0) return;
  Point s,t,u;
  double th = M_PI*60.0 / 180.0;

  s.x = (2.0 * a.x + 1.0 *b.x)/3.0;
  s.y = (2.0 * a.y + 1.0 * b.y)/3.0;
  t.x = (1.0 * a.x + 2.0 * b.x)/3.0;
  t.y = (1.0 * a.y + 2.0 * b.y)/3.0;
  u.x = (t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y = (t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
  
  koch (n-1 , a, s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);
}

int main () {
  Point a,b;
  int n;

  scanf("%d",&n);
  a.x = 0;
  a.y = 0;
  b.x = 100.0;
  b.y = 0;
  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);
  return 0;
}



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

int main() {
  long N, D;
  cin >> N >> D;

  vector<long> X(N);
  vector<long> Y(N);

  for(int i = 0; i < N; ++i){
    cin >> X.at(i) >> Y.at(i);
    X.at(i) = abs(X.at(i));
    Y.at(i) = abs(Y.at(i));
  }
  long ans = 0;
  long MAX = D*D;
    
  for(int i = 0; i < N; ++i){
    if(X.at(i) > D || Y.at(i) > D) continue;
    long num = X.at(i)*X.at(i) + (Y.at(i)*Y.at(i));
    if(num <= MAX) ++ans;
  }

  cout << ans << endl;
}


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

int main() {
    string S;
    cin >> S;
    int N = S.size();

    vector<ll> dp(2019);

    ll cur = 0, now = 1;
    dp[cur]++;
    rep(i, N) {
        cur = (cur + now * (S[N - i - 1] - '0') % 2019) % 2019;
        now = now * 10 % 2019;
        dp[cur]++;
    }

    ll ans = 0;
    rep(i, 2019)
        ans += dp[i] * (dp[i] - 1) / 2;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3748
n, m = map(int, input().split())
t = {}
W = [0 for i in range(0, n+1)]
A = [0 for i in range(0, n+1)]
w = 0
a = 0
for i in range(m):
    p, s = input().split()
    p = int(p)
    if A[p] == 0 and s == "WA":
        W[p] += 1
    elif A[p] == 0 and s == "AC":
        a += 1
        A[p] = 1
        w += W[p]
print(a, w)

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

using namespace std;

int main() {
	long long a, b, c, k;
	long long  t;
	cin >> a >> b >> c >> k;
	t = k - a - b;
	if (k < a)
		cout << k;
	else if (t <= 0)
		cout << a;
	else
		cout << a - t;
}

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

import math

s=int(math.sqrt(n))
#print(s)
for i in range(s):
  if n%(s-i)==0:
    k1=s-i
    break

  else:
    k=0

#print(k1)
k2=int(n/k1)

print(k1+k2-2)


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



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

    REP(i, n-1){
        FOR(j, i+1, n){
            int bit = 0;
            while(true){
                if(((i^j) >> bit) & 1) break;
                bit++;
            }
            cout << bit + 1 << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>

typedef long long ll;

int max(int a,int b){
    if(a>b) return a;
    else return b;
}

int min(int a,int b){
    if(a<b) return a;
    else return b;
}

/*qsort(array,num_of_index,sizeof(int),compare_int); */
 int compare_int(const void *a,const void *b){
     return *(int*) a - *(int *) b; 
 } 
 
int b_search(int* array,int left,int right,int key){
    int mid = left + (right - left)/2;
     if( right - left == 1){
         if(array[mid]==key)
             return mid;
          else
               return -1;
     }
     if(array[mid]==key)
         return mid;
     else if(array[mid]>key)
         b_search(array,left,mid,key);
     else if(array[mid]<key)
         b_search(array,mid,right,key);
}

/*lower_bound(key以上のイテレータを返す)*/
 /*例えば,2,2,5,5,9でkey=2なら(2),2,5,5,9を返す*/
 int lower_bound(int  *array,int left,int right,int key){
     if(right-left==1)
         return left;
     int mid = left + (right - left)/2;
     if(array[mid]<key)
         return lower_bound(array,mid,right,key);
     else
         return lower_bound(array,left,mid,key);
 }

int main(){
    int N;
    int ans=0;
    scanf("%d",&N);
    int L[102];
    for(int i=0;i<N;i++)
        scanf("%d",L+i);
    qsort(L,N,sizeof(int),compare_int);
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(L[i] == L[j]) continue;
            for(int k=j+1;k<N;k++){
                if(L[j]==L[k]) continue;
                if(L[i] + L[j] > L[k]) ans++;
            }
        }
    }
    printf("%d",ans);

}


Measured memory_bytes: 1732
import java.util.Scanner; 
 public class Main{  
     public static void main(String[] args) {     
	 Scanner sc = new Scanner(System.in);   
	 while(true){
	 int n = sc.nextInt();
	 if (n==0){break;}    
	 int[] score;
	 score=new int[n];
	 int max=0,min=1500;
	 for(int i=0;i<n;i++){
	      score[i]=sc.nextInt();
	     if(max<score[i]){max=score[i];}
	     if(min>score[i]){min=score[i];}
	 }
	 int sum=0;
	 for(int i=0;i<n;i++){
	      sum=score[i]+sum;
	 }

	 int average=(sum-min-max)/(n-2);
	 System.out.printf("%d\n",average);
	 }


     } 
 } 

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

int main(){
  int d,n,ans=0;
  cin >> d >> n;

  if(n==100)  n++;
  if(d==0) ans=n;
  else if(d==1)  ans=100*n;
  else  ans= 10000*n;

  cout << ans << endl;
}

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

int main()
{
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(q);
    rep(i, q) cin >> a[i];
    vector<int> point(n);
    rep(i, q)
        point[a[i] - 1]++;
    for (auto p : point)
    {
        if (p - q + k > 0)
            cout << "Yes" << endl;
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    ll r, g, b, n, ans = 0;
    cin >> r >> g >> b >> n;
    for(int i = 0; i <= 3000; i++){
        if(r * i > n) break;
        for(int j = 0; j <= 3000; j++){
            if(r * i + g * j > n) break;
            if((n - (r * i + g * j)) % b == 0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int n,x;
	cin >> n >> x;
	int m[n];
	for(int i=0; i<n; i++)
		cin >> m[i];

	int max = m[0],total=0;
	for(int i=0; i<n; i++){
		total += m[i];
		if(max > m[i])
			max = m[i];
	}

	int result = n + (x - total) / max;
	cout << result << endl;
}

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

int main(){
    int n;
    cin >> n;
    rep(i, 9){
        if(n % i == 0){
            int x = n / i;
            if(x < 10){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int i;
  int len,b;
  char aa[100],bb[100],cc[100];
  int ia,ib,ic;
  scanf("%s %s",&aa,&bb);
//    printf("aa:%s bb:%s\n",aa,bb);
  scanf("%d %d",&ia,&ib);
  scanf("%s",&cc);
//    printf("ia:%d ib:%d ic:%s\n",ia,ib,cc);
	if(strcmp(aa,cc)==0){
		ia--;
    }
  	else{
		ib--;
    }
    printf("%d %d \n",ia,ib);

  return 0;

}

Measured memory_bytes: 128
n = gets.chomp.to_i
a = gets.chomp.split().map(&:to_i)
aa = []
i = 0
while true
    aa.push(a[i])
    i += 2
    if i >= a.size
        break
    end
end
aa.delete_if {|v| v %2 == 0}
print aa.size

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

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

needsearch=[]

for i in range(n):
    a[i]-=(i+1)
    needsearch.append(-2*(i+1)-a[i])

counter=[0]*(2*(10**6))

for i in range(n):
    if 0<a[i]+10**6<2*(10**6):
        counter[a[i]+10**6]+=1

ans = 0
for i in range(len(needsearch)):
    if 0<needsearch[i]+10**6<2*(10**6):
        ans += counter[needsearch[i]+10**6]
    if 0<a[i]+10**6<2*(10**6):
        counter[a[i]+10**6]-=1


print(ans)


Measured memory_bytes: 122276
from functools import reduce

INF = 10**9+1

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

def GCD(a,b):
    if a < b:
        a,b = b,a
    if b == 0:
        return a
    else:
        return GCD(b,a%b)

def LCM(a,b):
    return a*b//GCD(a,b)

def LCM_list(L):
    return reduce(LCM,L)

B = [A[i]//2 for i in range(N)]
flag = False
for i in range(N-1):
    count,count_,b,b_ = 0,0,B[i],B[i+1]
    while b % 2 == 0:
        b //= 2
        count += 1
    while b_ % 2 == 0:
        b_ //= 2
        count_ += 1
    if count != count_:
        flag = True
        print(0)
        exit()

hlcm = LCM_list(B)
if hlcm <= M:
    lb,ub = 1,INF
    while lb < ub:
        mid = (lb + ub) // 2
        if hlcm * mid <= M and hlcm * (mid+1) > M:
            break
        elif hlcm * mid > M:
            ub = mid
        else:
            lb = mid
    ans = (mid+1)//2
    print(ans)
else:
    print(0)


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

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

    int sum = 0;
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= k; j++) {
        for (int s = 1; s <= k; s++) {
          sum += gcd(i, j, s);
        }
      }
    }
    
    System.out.print(sum);
  }
  
  private static int gcd(int i, int j, int s) {
  	return gcdTwo(gcdTwo(i, j), s);
  }
  
  private static int gcdTwo(int i, int j) {
  	if (j == 0) {
      return i;
    }
    int r = i % j;
    return gcdTwo(j, r);
  }
}


Measured memory_bytes: 32740
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
for i in range(n):
  a = list(map(int,input().split()))
  product = 0
  for j in range(m):
    product += a[j]*b[j]
  if product + c > 0:
    count += 1
print(count)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int n;
  cin>>n;
  vector<int> h(n);
  for(auto&& e: h) 
  {
    cin>>e;
  }
  vector<int> cost(n);
  cost[0]=0;
  cost[1]=abs(h[1]-h[0]);
  for (int i = 2; i < n; ++i)
  {
    cost[i]=
    min(cost[i-1]+abs(h[i]-h[i-1]),
      cost[i-2]+abs(h[i]-h[i-2]));
  }
  cout<<cost.back()<<endl;
}

Measured memory_bytes: 4052
#include<stdio.h>
#include<bitset>
#include<algorithm>
const int N=16;
int main()
{
	int T,gx,gy,x1,y1,x2,y2,n;
	for(scanf("%d",&T);T--;)
	{
		scanf("%d%d",&gx,&gy);
		std::bitset<N*N>u,r;
		for(scanf("%d",&n);n--;)
		{
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			if(x1==x2)u[std::min(y1,y2)*N+x1]=1;
			else r[y1*N+std::min(x1,x2)]=1;
		}
		int a[N][N]={1},i,j;
		for(j=0;j<gx;++j)if(!r[j])a[0][j+1]=a[0][j];
		for(i=0;i<gy;++i)if(!u[i*N])a[i+1][0]=a[i][0];
		for(i=1;i<=gy;++i)for(j=1;j<=gx;++j)
		{
			if(!u[(i-1)*N+j])a[i][j]+=a[i-1][j];
			if(!r[i*N+j-1])a[i][j]+=a[i][j-1];
		}
		if(a[gy][gx])printf("%d\n",a[gy][gx]);
		else puts("Miserable Hokusai!");
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

#define MAXN 100000

typedef struct ABC {
	int a,b,c;
} PLAN;

PLAN DP[MAXN+1];
PLAN A[MAXN+1];

int vac(int n)
{
	int i, tmpa, tmpb, tmpc,max;

	DP[0].a = DP[0].b = DP[0].c = 0;

	for ( i = 1; i <= n; i++ ) {
		tmpa = DP[i-1].a, tmpb = DP[i-1].b, tmpc = DP[i-1].c;

		if ( tmpb > tmpc ) DP[i].a = tmpb+A[i].a;
		else DP[i].a = tmpc+A[i].a;
		if ( tmpa > tmpc ) DP[i].b = tmpa+A[i].b;
		else DP[i].b = tmpc+A[i].b;
		if ( tmpa > tmpb ) DP[i].c = tmpa+A[i].c;
		else DP[i].c = tmpb+A[i].c;

	}

	max = DP[n].a;
	if ( max < DP[n].b ) max = DP[n].b;
	if ( max < DP[n].c ) max = DP[n].c;

	return max;
}


int main(void)
{
	int n,i;

	scanf("%d", &n);
	for ( i = 1; i <= n; i++ ) scanf("%d%d%d", &(A[i].a), &(A[i].b), &(A[i].c));


	printf("%d\n", vac(n));

	return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<map>
using namespace std;
using std::map;
int main() {
	map<string, int> a;
	int N = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		a[s]++;
	}
	int max = 0;
	for (const auto& x : a) {
		int v = x.second;
		if (v > max) {
			max = v;
		}
	}
	for (auto it = a.begin(); it != a.end(); it++) {
		if (it->second == max) {
			cout << it->first << endl;
		}
	}

}

Measured memory_bytes: 25216
#include <stdio.h>

int max(int a,int b)
{
    return a>b?a:b;
}

int main()
{
    int a[3];
    scanf("%d %d %d",&a[0],&a[1],&a[2]);
    printf("%d\n",max(a[0],max(a[1],a[2]))*10+a[0]+a[1]+a[2]-max(a[0],max(a[1],a[2])));
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
 
int main(){
    string W;
    string T;
    int NumberOfW = 0;
 
    cin >> W;
 
    while(1){
        cin >> T;
        if(T=="END_OF_TEXT")break;
        for(int i=0; i<T.size(); i++){
            if(T[i] >= 'A' && T[i] <= 'Z'){
                T[i] += 'a' - 'A';
            }
        }
        if(T==W)NumberOfW++;
    }
 
    cout << NumberOfW << endl;
    return 0;
}

Measured memory_bytes: 1192
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
#define N 10000

bool isPrime(int n){
  int i;

  if(n == 2) return true;

  if(n < 2 || n%2 == 0) return false;

  i = 3;
  while(i <= sqrt(n)){
    if(n%i == 0) return false;
    i = i+2;
  }

  return true;
}

int main(){
  int num[N];
  int i,n,p=0;

  scanf("%d",&n);

  for(i = 0; i < n; i++) scanf("%d",&num[i]);

  for(i = 0; i < n; i++){
    if(isPrime(num[i]) == true) p++;
    else continue;
  }

  printf("%d\n",p);

  return 0;
}




Measured memory_bytes: 2708
n = int(input())
s = [list(input()) for _ in range(n)]

ss = [10**3]*28

for i in range(n):
    sl = [0]*28
    for j in range(len(s[i])):
        sl[ord(s[i][j]) - 97] += 1
    for k in range(28):
        ss[k] = min(ss[k], sl[k])

ans = []
for i in range(28):
    ans.append(chr(i + 97) * ss[i])

print("".join(ans))

Measured memory_bytes: 64984
/*
ID: thanhvq1
LANG: C++14
PROB: namenum
*/

#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;

// defines
#define int long long
typedef long long ll;
#define double long double
#define vec vector
#define vi vector<int>
#define vvi vector<vector<int>>
#define FZ(n) memset((n),0,sizeof())
#define FMO(n) memset((n),-1,sizeof(n))
#define unset unordered_set
#define ii pair<int, int>
#define vii vector<ii>
#define F first;
#define S second
#define mp make_pair
#define PB push_back
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)(x).size())
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define BUG(x) cerr << #x << " = " << (x) << endl
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c) min(a, b) < min(b, c) ? min(a, b) : min(b, c)

//permanent constants
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 998244353; //1e9 + 7;  const ll MOD2 = (ll)MOD * (ll)MOD;
const double PI = 2.0*acos(0.0); //acos(-1.0L);
const double EPS = static_cast<double>(1e-10);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0};
//const ll INF = (ll)(1e18 + 239);
const int BIG = (int)(1e9 + 239);

//random
mt19937 rnd(239); //(chrono::high_resolution_clock::now().time_since_epoch().count());

void FILEIO() {  freopen("in.txt", "r", stdin);  freopen("out.txt", "w", stdout); }
//void FILEIO() {  freopen("namenum.in", "r", stdin);  freopen("namenum.out", "w", stdout); }
void input() {   }

void solve() {
	int n, d; cin >> n >> d;
	int rem = n%(2*d+1), ans;
	if(rem == 0) ans = n/(2*d+1); else ans = n/(2*d+1)+1;
	cout << ans << endl;
}

signed main() {
  ios_base::sync_with_stdio(false); cin.tie();
//  FILEIO();
//auto beginProgram = chrono::steady_clock::now();

//  int test = 0;
//  string s; getline(cin, s); int t = stoi(s);
//  while(t--)
  {
//	  cout << "Case " << ++test << ": ";
	  solve();
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
inline long long read();
using namespace std;
int main()
{
	string s;cin>>s;
	int ans=0;
	for(int i=0;i<s.length();i++)
	{
		ans+=s[i]-'0';
	}
	ans=max(ans,(int)(s.length()-1)*9+s[0]-'1');
	cout<<ans;
}

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

void dfs(int root, int went, vector<vector<pair<int, int>>> &T, vector<int> &ans){
  for (auto t: T[root]){
    if (t.first != went){
      if (t.second % 2 == 0) ans[t.first] = ans[root];
      else ans[t.first] = 1 ^ ans[root];
      dfs(t.first, root, T, ans);
    }
  }
}

int main(){
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> T(n);
  for (int i=0; i<n-1; i++){
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    T[u].push_back(make_pair(v, w));
    T[v].push_back(make_pair(u, w));
  }

  vector<int> ans(n, -1);
  ans[0] = 0;
  dfs(0, -1, T , ans);
  for (int i=0; i<n; i++) cout << ans[i] << endl;

  return 0;
}

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

int gcd(ll a, ll b) {
    if(a % b == 0) return b;
    else return(gcd(b, a % b));
}

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    ll l = c / gcd(c, d) * d;
    cout << (b - b / c - b / d + b / l) - (a - a / c - a / d + a / l) << endl;
    return 0;
}


Measured memory_bytes: 3564
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = [list(map(int, input().split())) for i in range(M)]

ans = min(a) + min(b)

for i in range(M):
  ans = min(ans, a[m[i][0]-1] + b[m[i][1]-1] - m[i][2])
  
print(ans)

Measured memory_bytes: 38488
#include<stdio.h>

int main() {
	int a, b[200000], k,count=0;
	scanf("%d", &a);
	for (int i = 0; i < a; i++) {
		scanf("%d", &b[i]);
	}
	k = 1;
	for (int j = 0; j < a; j++) {
		if (b[j] == k) {
			k++;
		}
		else count++;
	}
	if (count == a) {
		printf("-1");
	}
	else {
		printf("%d", count);
	}
	return 0;
}

Measured memory_bytes: 896