akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

vvi g;
int D = 0;
vi dep;

void dfs(int v, int p) {
  dep[v] = 0;
  pii ma;
  for (int nv : g[v]) if (nv != p) {
    dfs(nv, v);
    int nd = dep[nv] + 1;
    dep[v] = max(dep[v], nd);
    if (nd > ma.first) {
      ma.second = ma.first;
      ma.first = nd;
    } else if (ma.second < nd) {
      ma.second = nd;
    }
  }
  D = max(D, ma.first + ma.second);
}

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n;
  cin >> n;
  g.resize(n);
  dep.assign(n, 0);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0, -1);
  vi f(200005);
  f[0] = 0;
  f[1] = 1;
  f[2] = 0;
  for (int i = 3; i < f.size(); ++i) {
    if (!f[i - 1] || !f[i - 2]) {
      f[i] = 1;
    } else {
      f[i] = 0;
    }
  }
  if (f[D + 1]) {
    cout << "First\n";
  } else {
    cout << "Second\n";
  }
  return 0;
}


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

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

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

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N; string S; cin >> S;
    if(N%2 == 1){
        cout << "No" << endstr;
    }
    else{
        bool ok = true;
        rep(i, N/2){
            if(S[i] != S[i+N/2]) ok = false;
        }
        cout << (ok ? "Yes" : "No") << endstr;
    }
    return 0;
}


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

m = []
for _ in range(N):
   m.append(int(input()))

remain = X - sum(m)

mmax = 0
for i in range(N):
  if remain/m[i] > mmax:
    mmax = remain/m[i]
print(int(len(m)+mmax))


Measured memory_bytes: 3060
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())

n = int(input())
s = input()
cnt = 0
q = s[0]
t = s[0]
for x in s[1:]:
    if x == q:
        cnt += 1
        if cnt < 3:
            t += x
    else:
        cnt = 0
        t += x
        q = x
ans = 0
for i in range(10):
    x = t.find(str(i)) + 1
    if not x: continue
    for j in range(10):
        y = t[x:].find(str(j)) + 1
        if not y: continue
        for k in range(10):
            z = t[x + y:].find(str(k)) + 1
            if not z: continue
            #print(i,j,k, ':', x,y,z)
            ans += 1
print(ans)


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

int main()
{
  char s[4];
  cin>>s;

  if(s[0]==s[1]&&s[1]==s[2])
  	cout<<"Yes"<<endl;
  else if(s[3]==s[2]&&s[1]==s[2])
  	cout<<"Yes"<<endl;
  else
  	cout<<"No"<<endl;


}


Measured memory_bytes: 256
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 S = sc.nextInt();

		if (S < 0 || S >= 86400) {
			System.out.println("0以上もしは、86400より小さい数を入力してください。");
		} else {

			int h = 0;
			int m = 0;
			int s = 0;

			h = (S / 3600);
			m = (S % 3600) / 60;
			s = (S % 3600) % 60;

			System.out.println(h + ":" + m + ":" + s);
		}

	}

}



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

using namespace std;

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

int N;
vector<double> p;

double dp[3100][3100];

int main() {
  cin >> N;
  p.resize(N);
  for (int i = 0; i < N; i++) cin >> p[i];

  dp[0][0] = 1.0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= i; j++) {
      dp[i + 1][j + 1] += dp[i][j] * p[i];
      dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
    }
  }

  double res = 0.0;
  for (int j = (N + 1) / 2; j <= N; j++) res += dp[N][j];
  printf("%.10f\n", res);

  return 0;
}

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

const long long MOD = 1000000007;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
typedef long long ll;

struct edge{
    int to, cost, attack;
    edge(int to, int cost, int attack): to(to), cost(cost), attack(attack){}
};

struct State{
    int v, l, a;
    State(int v, int l, int a): v(v), l(l), a(a){}
    bool operator<(const State& right ) const {
        return a == right.a ? l < right.l : a > right.a;
    }
};

int main(){
    while(1){
        int N, M, L;
        cin >> N >> M >> L;
        if(N == 0) break;

        vector<vector<edge>> E(N);
        for(int i=0;i<M;i++){
            int a, b, d, e;
            cin >> a >> b >> d >> e;
            a--; b--;
            E[a].emplace_back(b, d, e);
            E[b].emplace_back(a, d, e);
        }

        bool viewed[101][101];
        memset(viewed, 0, sizeof(viewed));

        priority_queue<State> que;
        que.emplace(0, L, 0);

        while(que.size()){
            State s = que.top(); que.pop();
            if(viewed[s.v][s.l]) continue;
            viewed[s.v][s.l] = true;
            if(s.v == N-1){
                cout << s.a << endl;
                break;
            }
            for(edge& e: E[s.v]){
                if(!viewed[e.to][s.l]){
                    que.emplace(e.to, s.l, s.a+e.attack);
                }
                int nl = s.l-e.cost;
                if(nl >= 0 && !viewed[e.to][nl]){
                    que.emplace(e.to, nl, s.a);
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>

using namespace std;

int main() {
  int N;
  cin>>N;
  int ans=0;

  int a;
  for(int i=1;i<=N;i++){
    int b=0;
    int n=i;
    while(n%2==0){
      n/=2;
      b++;
    }
    if(ans<=b){
      a=i;
      ans=b;
    }
    
  }
  
    cout<<a<<endl;
  
}

Measured memory_bytes: 256
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

import sys
input = sys.stdin.readline
n,m,r = map(int,input().split())
R = [int(i)-1 for i in input().split()]
d = [[10**9]*n for i in range(n)]
for i in range(m):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z
for i in range(n):
    d[i][i] = 0
    
chk = tuple(warshall_floyd(d))
ans = float('inf')

import itertools
for i in itertools.permutations(R, r):
  p = 0
  for j in range(r-1):
    p += d[i[j]][i[j+1]]
  ans = min(ans,p)
  
print(ans) 

Measured memory_bytes: 42588
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int n,a,b;
	cin>>n>>a>>b;
	if(a*n < b) cout<<a*n<<endl;
	else cout<<b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;
char s[100][100];
int H, W;
void dfs(int x, int y, char f) {
  if (x < 0 || y < 0 || x >= W || y >= H)
    return;
  if (s[y][x] == f) {
    s[y][x] = 'A';
  } else
    return;
  dfs(x + 1, y, f);
  dfs(x - 1, y, f);
  dfs(x, y + 1, f);
  dfs(x, y - 1, f);
}
int main() {
  while (cin >> H >> W) {
    if (H == 0 && W == 0)
      break;
    int ans = 0;
    rep(i, H) rep(j, W) cin >> s[i][j];
    rep(i, H) rep(j, W) {
      if (s[i][j] == 'A') {
      } else {
        ans++;
        dfs(j, i, s[i][j]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3380
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W; cin >> H >> W;
  string Q;
  for (int i=0;i<W+2;i++) cout << "#";
  cout << endl;
  for (int j=0;j<H;j++){
    cin >> Q;
    cout << "#" << Q << "#" << endl;
  }
  for (int i=0;i<W+2;i++) cout << "#";
  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int x,y,z;
  int K,S;
  int pattern;
  
  cin >> K >> S;
  
  for(x=0;x<=K;x++){
    for(y=0;y<=K;y++){
      z = S - x - y;
      if( (x+y+z) == S && z>=0 && z<=K) pattern++;
    }
  }
  
  cout << pattern << endl;
  
}

Measured memory_bytes: 256
fn main() {
    let mut s: String = read();
    s = s.replace("2017", "2018");
    println!("{}", s);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;

for(int i=1;i<=1000;i++)
{
	if(i*(i-1)==2*n)
	{
		ol("Yes\n");
		ol(i);on;
		int ed=0;
		vii v[1005];
		rep(ii,1,i)
		{
			rep(jj,ii+1,i)
			{
				ed++;
				v[ii].pb(ed);
				v[jj].pb(ed);
			}
		}
		rep(ii,1,i)
		{
			ol(v[ii].size());os;
			tr(v[ii],it)
			{
				ol(*it);os;
			}
			on;
		}
		return 0;
	}
}
ol("No\n");
return 0;
}



Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N;
    cin >> N;
    vector<int>As(N);

    for(int i=0; i<N; i++){
        cin >> As.at(i);
    }
    sort(all(As));
    cout << abs(As[0] - As[N-1]) << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;
const int MAXN = 15;
const int MAXM = 15;
typedef long long ll;
int ans = INT_MAX;

vector<int> costs(MAXN); 
vector<vector<int>> algos(MAXN, vector<int>(MAXM));

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, x; cin >> n >> m >> x;
    for (int i = 0; i < n; ++i) {
        cin >> costs[i];
        for (int j = 0; j < m; ++j) {
            cin >> algos[i][j];
        }
    }

    for (int i = 0; i < (1 << n); ++i) {
        int i_sum[m] = {}, csum = 0;
        for (int j = 0; j < n; ++j) {
            if (!(i & (1 << j))) continue;
            csum += costs[j];
            for(int k = 0;  k < m; ++k) i_sum[k] += algos[j][k];
        }

        bool ok = true;
        for (int k = 0; k < m; ++k) {
            if (i_sum[k] < x) ok = false;
        }

        if (ok) ans = min(ans, csum);
    }

    cout << (ans == INT_MAX ? -1 : ans) << '\n';
    return 0;
}



Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}


signed main(){
	int n, m;
	while(cin >> n >> m, n){
		vector<int> mini(n, 0), maxi(n, 0);
		rep(i,m){
			int s, k;
			cin >> s >> k;

			vector<int> c(k);
			cin >> c;

			if(k == 1){
				mini[c[0] - 1] += s;
			}
			for(auto i : c){
				maxi[i - 1] += s;
			}
		}

		//cout << maxi << endl;
		//cout << mini << endl;

		int ans = 0;
		rep(i,n){
			int m = 0;
			rep(j,n){
				if(i != j){
					m = max(m, maxi[j]);
				}
			}
			//cout << m << ' ' << mini[i] << endl;
			ans = max(ans, m - mini[i]);
		}
		cout << ans + 1 << endl;
	}
}



Measured memory_bytes: 3216
//あるごりずむ 1616
#include<iostream>
using namespace std;

int main(){
  while(true){
    int n,m;
    cin>>n>>m;
    if(n==0 && m==0)break;

    int a[1000];
    for(int i=0;i<n;i++){
      cin>>a[i];
    }
    int sum=-1;
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        int p=a[i]+a[j];
        if(p<=m && p>sum){
          sum=p;
        }
      }
    }
    if(sum!=-1){
      cout<<sum<<endl;
    }else{
      cout<<"NONE"<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+10;
int n,m,cnt,num1,num2,chk;
int head[N],vis[N],col[N],to[N<<1],nxt[N<<1],val[N<<1],stk[3];
ll ans;
inline void add(int u,int v,int w){
	to[++cnt]=v,nxt[cnt]=head[u],val[cnt]=w,head[u]=cnt;
}
inline int tp(int x){ x=(x%3+3)%3; return x; }
void dfs(int u,int c){
	vis[u]=1,col[u]=c,stk[col[u]]++,num1++;
	for(int i=head[u];i;i=nxt[i]){
		int v=to[i];
		num2+=(val[i]==1);
		if(!vis[v]) dfs(v,tp(col[u]+val[i]));
		else if(col[v]!=tp(col[u]+val[i])) chk=1;
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++) { int u,v; scanf("%d%d",&u,&v); add(u,v,1),add(v,u,-1); }
	for(int i=1;i<=n;i++){
		if(vis[i]) continue; 
		num1=0,num2=0,chk=0; stk[0]=stk[1]=stk[2]=0; 
		dfs(i,0);
		if(chk) ans+=1ll*num1*num1;
		else if(stk[0] && stk[1] && stk[2]) ans+=1ll*stk[0]*stk[1]+1ll*stk[1]*stk[2]+1ll*stk[2]*stk[0];
		else ans+=num2;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 13572
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int h,w;
    cin>>h>>w;
    vector<string>a(h);
    rep(i,h){
        cin>>a[i];
        a[i]="#"+a[i]+"#";
    }
    int al=a[0].length();
    string ans;
    rep(i,al){
        ans+="#";
    }
    cout<<ans<<endl;
    rep(i,h){
        cout<<a[i]<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int test[12345678];
signed main() {
	int n, cnt = 1, sum = 1, ans = 1; cin >> n;
	vector<vector<int>>aa(1000);
	for (int h = 1; h < 1000; h++) {
		test[h * (h + 1) / 2] = h;
	}
	if (test[n] == 0) { cout << "No" << endl; return 0; }
	cout << "Yes" << endl;
	cout << test[n] + 1 << endl;
	for (int h = 0; h <= test[n]; h++) {
		cout << test[n]; cnt = sum;
		for (int i = 0; i < aa[h].size(); i++) {
			cout << ' ' << aa[h][i];
		}
		for (int i = 0; i < test[n] - aa[h].size(); i++) {
			cout << ' ' << ans; aa[cnt].push_back(ans); cnt++; ans++;
		}
		cout << endl; sum++;
	}
	return 0;
}

Measured memory_bytes: 7288
fun main(arg: Array<String>) {
    val N = nextLong()
    var total = N * (N + 1) / 2
    for (n in 3 .. N)
        if (n % 3 == 0L || n % 5 == 0L) total -= n
    return println(total)
}


fun next() = readLine()!!
fun nextInt(offset: Int = 0) = Integer.parseInt(next()) + offset
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()


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

int main(void) {
  string s, t;
  cin >> s >> t;
  cout << t + s << endl;
  return 0;
}

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

using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	string t;
	cin>>s;
	cin>>t;
	long long int c=0;
	for(long long int i=0;i<s.size();i++){
		if(s[i]!=t[i]){
			c++;
		}
	}
	cout<<c;
	return 0;
}

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

int t[1002][1002];
int dp[1002][1002];

int main(void){
	int i,j,ti,tj;
	int w,h,n;
	int d,gx,gy;

	while(scanf("%d%d%d",&h,&w,&n) && (h||w||n)){
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				scanf("%d",&t[i][j]);
			}
		}

		memset(dp,0,sizeof(dp));
		dp[0][0] = n;
		gx = 0, gy = 0;

		for(tj=0;tj<w && gx<w && gy<h;tj++){
			for(i=0;i<h && 0<=tj-i && gx<w && gy<h;i++){
				d = 0;
				j = tj - i;

				if(dp[i][j] % 2 == 0){
					d = !t[i][j];
					dp[i][j+1] += dp[i][j] / 2;
					dp[i+1][j] += dp[i][j] / 2;
				}
				else{
					d = t[i][j];
					dp[i][j+1] += dp[i][j] / 2 + d;
					dp[i+1][j] += dp[i][j] / 2 + !d;
				}
				if(gx == j && gy == i){
					gx += d;
					gy += !d;
				}
			}
		}

		for(ti=1;ti<h && gx<w && gy<h;ti++){
			for(tj=0;tj<w && ti+tj<h && gx<w && gy<h;tj++){
				d = 0;
				i = ti + tj;
				j = w - tj - 1;

				if(dp[i][j] % 2 == 0){
					d = !t[i][j];
					dp[i][j+1] += dp[i][j] / 2;
					dp[i+1][j] += dp[i][j] / 2;
				}
				else{
					d = t[i][j];
					dp[i][j+1] += dp[i][j] / 2 + d;
					dp[i+1][j] += dp[i][j] / 2 + !d;
				}
				if(gx == j && gy == i){
					gx += d;
					gy += !d;
				}
			}
		}

		printf("%d %d\n",gy+1,gx+1);
	}

	return 0;
}

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

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int[] boxes = new int[n];
        final int[] answerChoice = new int[n];

        for (int i = 0; i < n; i++) {
            boxes[i] = scanner.nextInt();
        }

        for (int i = n - 1; i >= 0; i--) {
            if (i > n / 2) {
                answerChoice[i] = boxes[i];
                continue;
            }

            int sum = 0;
            for (int j = 2 * i + 1; j < n; j += i + 1) {
                sum += answerChoice[j];
            }

            if (sum % 2 == boxes[i]) {
                answerChoice[i] = 0;
            } else {
                answerChoice[i] = 1;
            }
        }

        final List<String> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (answerChoice[i] == 1) {
                list.add(Integer.toString(i + 1));
            }
        }

        System.out.println(list.size());
        if (list.size() != 0)
            System.out.println(String.join(" ", list));
    }
}


Measured memory_bytes: 88244
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]

X = I()

a = 100
y = 1

while True:
    a += a // 100
    if a >= X:
        print(y)
        break
    y += 1
    


Measured memory_bytes: 71780
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  int i;
  for(i=0;i<n;i++){
    cin >> p[i];
  }
  sort(p.begin(),p.end());
  int ans=0;
  for(i=0;i<n-1;i++){
    ans += p[i];
  }
  ans += p[n-1]/2;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    if(S=="SUN"){
        cout << 7 << endl;
    }
    else if(S=="MON"){
        cout << 6 << endl;
    }
    else if(S=="TUE"){
        cout << 5 << endl;
    }
    else if(S=="WED"){
        cout << 4 << endl;
    }
    else if(S=="THU"){
        cout << 3 << endl;
    }
    else if(S=="FRI"){
        cout << 2 << endl;
    }    
    else if(S=="SAT"){
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  long k,a,b;
  cin >> k >> a >> b;
  if(b-a <= 2){
    cout << 1+k << endl;
    return 0;
  }

  cout << (b-a)*((k-a+1L)/2L)+a+((k-a+1L)%2L) << endl;
  return 0;
}

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

template <class T, class... Args>
T& chmin(T& base, Args&&... args)
{
    base = std::min<T>({base, std::forward<Args>(args)...});
    return base;
}

template <class T, class... Args>
T& chmax(T& base, Args&&... args)
{
    base = std::max<T>({base, std::forward<Args>(args)...});
    return base;
}

int main()
{
    int N, K;
    std::cin >> N >> K;

    std::vector<int> h(N);

    for (int i = 0; i < N; ++i) {
        std::cin >> h[i];
    }

    std::vector<int> dp(N, std::numeric_limits<int>::max());
    dp[0] = 0;

    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K && i + j < N; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    std::cout << dp[N - 1] << std::endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
const int INF = 1001001001;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define re0 return 0

int npr(int n , int r){//nPr
    r = n - r;
    int sum = 1;
    int i;
    for (i=n;i>=r+1;i--)sum*=i;
    return sum;
}
int gcd(int a, int b) {//最大公約数
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {//最小公倍数
    return a * b / gcd(a, b);
}
int digsum(int n) {//桁和
    int res = 0;
    while(n > 0) {
        //res += n%10;
        //　↑をres++;にすれば桁数
         res++;
        n /= 10;
    }
    return res;
}
bool isPrime(int x){//素数
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
/*bit全探索
for (int bit = 0; bit < (1<<N); ++bit) {
}
if (bit & (1 << i)) {
}
*/


signed main(){ 
    ll n,T;
    cin >> n >> T;
    vector<int>t(n);
    rep(i,n)cin >> t[i];
    ll sum = n*T;
    rep(i,n-1){
        if(T+t[i]>=t[i+1]){
            sum-=T+t[i]-t[i+1];
        }
    }
    cout << sum <<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
	
int main(){
	string s;
	int n;
	cin>>n;
	cin >> s;
	int t=1;
	for(int i=0;i<n-1;i++){
		if(s[i]!=s[i+1]){
			t++;
		}
	}
	cout<<t;
	
} 

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

	if (A == 1) A = 14;
	if (B == 1) B = 14;

	if (A == B) {
		cout << "Draw" << endl;
	}
	else if (A > B) {
		cout << "Alice" << endl;
	}
	else {
		cout << "Bob" << endl;
	}

	return 0;
}

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

using namespace std;

int main()
{
  string s, t;
  int j, i;
  long long sol = LONG_LONG_MAX;
   cin>>s>>t;
   for(i=0; i <= (s.size()-t.size());i++)
   {
       long long csol = 0;
       for(j = 0; j < t.size();j++)
       {
           if(t[j] != s[i + j])
               csol++;
       }
       sol = min(sol, csol);
   }
   cout<<sol<<"\n";

}

Measured memory_bytes: 3636
n = int(input())
A = list(map(int,input().split()))
ans= []
B = [0]*n
for i in reversed(range(n)):
  if sum(B[i::i+1])%2!=A[i]:
    ans.append(i+1)
    B[i]+= 1
print(len(ans))   
print(*ans)
    

Measured memory_bytes: 76764
# ABC61 D - Score Attack  preference付

import sys
input=sys.stdin.readline  #危険！基本オフにしろ！

def BELLMANFORD(point,n,d):
    cost       = [-float("inf")]*(n+1)
    preference = [None         ]*(n+1)      #最適路のこと 
    cost[point]= 0
    for i in range(n-1):                                  #経路の長さは最大n-1であるため
        for nownode,nextnode,c in d:
            if cost[nextnode]<cost[nownode]+c:
                cost[nextnode]=cost[nownode]+c
                preference[nextnode]=nownode

    negative=[0]*(n+1)                                        #負閉路の長さは最大nであるため
    
    for i in range(n):                  #閉路判定
        for nownode,nextnode,c in d:
            if negative[nownode]:
                negative[nextnode]=1
            if cost[nextnode]<cost[nownode]+c:
                cost[nextnode]=cost[nownode]+c
                preference[nextnode]=nownode
                negative[nownode]=1
 
    return cost,negative


def main():
    n,m=map(int,input().split())
    
    d=[tuple(map(int,input().split()))for i in [0]*m]
    
    x,y=(BELLMANFORD(1,n,d))
    
    if y[n]:
        print("inf")
    else:
        print(x[n])


if __name__ == '__main__':
    main()


Measured memory_bytes: 42716
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

void solve() {
    int n; cin >> n;
    string s; cin >> s;
    s.resize(unique(all(s)) - s.begin());
    cout << s.size();
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3728
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    f = list(map(int, input().rstrip('\n').split()))
    a.sort()
    f.sort(reverse=True)
    left = -1
    right = 10 ** 13
    while right - left > 1:
        mid = (left + right) // 2
        count = 0
        for av, fv in zip(a, f):
            count += max(0, av - (mid // fv))
        if count <= k:
            right = mid
        else:
            left = mid
    print(right)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 113152
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int mod = 1e9 + 7;

inline int add(int a, int b) {
  return a+b >= mod ? a+b-mod : a+b;
}

inline int sub(int a, int b) {
  return a >= b ? a-b : a-b+mod;
}

inline int mul(int a, int b) {
  return llint(a)*b % mod;
}

const int MAX = 500050;

int f[MAX];
int P[MAX];

int L[MAX];

int sum(int x) {
  int r = 0;
  for (++x; x; x -= x&-x)
    r += L[x];
  return r;
}

void addv(int x, int v) {
  for (++x; x < MAX; x += x&-x)
    L[x] += v;
}

bool ima[MAX];
int ls[MAX];
int G[MAX];

int main(void) {
  int N;
  scanf("%d", &N);
  REP(i, N) scanf("%d", &P[i]);

  f[0] = 1;
  REP(i, N) f[i+1] = mul(f[i], i+1);

  int F = 0;
  REP(i, N) {
    F += P[i] == 0;
    ima[P[i]] = true;
  }

  ls[0] = 0;
  for (int i = 1; i <= N; ++i)
    ls[i] = ls[i-1] + !ima[i];
  
  int ans = f[F];
  int L = 0;

  int gg = 0;
  for (int i = N-1; i >= 0; --i) {
    if (P[i]) {
      gg = add(gg, F -  ls[P[i]]);
    } else {
      G[i] = gg;
    }
  }
  REP(i, N) {
    int total = 0;
    if (P[i]) {
      int FL = P[i]-1 - sum(P[i]) - ls[P[i]];
      total = add(total, mul(FL, f[F]));

      if (F > 0) {
        total = add(total, mul(mul(ls[P[i]], F-L), f[F-1]));
      }
      addv(P[i], 1);
    } else {
      L++;
      if (F > 1) {
        int pairs = ((llint(F) * (F - 1)) / 2) % mod;
        total = add(total, mul(pairs, mul(F-L, f[F-2])));
      }
      total = add(total, mul(G[i], f[F-1]));
    }

    ans = add(ans, mul(total, f[N-i-1]));
  }

  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 10624
#include <iostream>
#include<vector>
#include<string>
#include<bits/stdc++.h>
#include<algorithm>
#include<stdio.h>
#include<bits/stdc++.h>
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

using namespace std;

/*ll ma=998244353;
ll power(ll v,ll ti){
if(ti==1)
    return v;
ll x=power(v,ti/2);
x=(x*x)%ma;
if(ti%2==1)
    x=(x*v)%ma;
return x;

}
struct t{
int a,b;
};
vector<vector<t > >g;
vector<int> v;


ll n;


void dfs(int i,int sum){
v[i]=1;


for(int j=0;j<go[i].size();j++){
    int x=go[i][j].a;
    int y=go[i][j].b;
    if(v[x]==0){
        dfs(x,min(y,sum));

    }

}

}*/

ll dp[51][51][101];
 int main(){
int n,k;
cin>>n>>k;
ll a[n];
for(int i=0;i<n;i++)
    cin>>a[i];
for(int i=0;i<n;i++)
for(int j=i;j<n;j++){


    dp[i][j][1]=max(a[i],a[j]);


}
for(int t=2;t<=k;t++){
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
                ll q=0;
           if(i==j)
                dp[i][j][t]=max(q,a[i]);

           else{
            ll x=dp[i+1][j][t-1]+a[i];
            ll y=dp[i+1][j][t-2];
            ll z=dp[i][j-1][t-1]+a[j];
            ll w=dp[i][j-1][t-2];
            dp[i][j][t]=max(max(x,y),max(w,z));
           }

        }
    }


}
ll ans=0;
for(int i=1;i<=k;i++)
    ans=max(ans,dp[0][n-1][i]);
cout<<ans<<endl;

}




Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int q = scan.nextInt();
		for (int t = 0; t < q; t++) {
			char[] x = scan.next().toCharArray();
			char[] y = scan.next().toCharArray();

			int[][] dp = new int[x.length][y.length];

			dp[0][0] = x[0] == y[0] ? 1 : 0;
			for (int i = 1; i < x.length; i++)
				dp[i][0] = Math.max((x[i] == y[0]) ? 1 : 0, dp[i - 1][0]);
			for (int i = 1; i < y.length; i++)
				dp[0][i] = Math.max((x[0] == y[i]) ? 1 : 0, dp[0][i - 1]);
			
			for (int i = 1; i < x.length; i++) {
				for (int j = 1; j < y.length; j++) {
					dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
					if (x[i] == y[j])
						dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - 1] + 1);
				}
			}
			int ans = 0;
			for (int i = 0; i < y.length; i++)
				ans = Math.max(ans, dp[x.length - 1][i]);
			System.out.println(ans);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 65712
#ifndef ___Class_RangeTree
#define ___Class_RangeTree

// ------ Includes ------ //
#include <limits>
#include <vector>
#include <algorithm>

template<typename Type> class RangeTree {
private:
	int size_;
	std::vector<std::vector<Type> > dat;
	std::vector<std::vector<int> > vl;
	inline int query_(int a, int b, Type x, int k, int l, int r, int e) {
		// Find range [a, b) : value < x : Now k-th node and the range is [l, r) and e integers below x in the range
		if (r <= a || b <= l || e == 0) return 0;
		if (a <= l && r <= b) return e;
		int lc = query_(a, b, x, k << 1, l, (l + r) >> 1, vl[k][e - 1]);
		int rc = query_(a, b, x, k << 1 | 1, (l + r) >> 1, r, e - vl[k][e - 1]);
		return lc + rc;
	}
public:
	RangeTree() : size_(0), dat(std::vector<Type>()) {};
	template<class T>
	RangeTree(T begin_, T end_) {
		int n = (end_ - begin_);
		for (size_ = 1; size_ < n; size_ <<= 1);
		dat.resize(size_ << 1);
		vl.resize(size_);
		for (int i = 0; i < n; i++) dat[i + size_].push_back(*(begin_ + i));
		for (int i = size_ - 1; i > 0; i--) {
			dat[i].resize(dat[i << 1].size() + dat[i << 1 | 1].size());
			vl[i].resize(dat[i].size());
			int cl = 0;
			for (int j = 0; j < dat[i].size(); j++) {
				if (j - cl == dat[i << 1 | 1].size() || (cl != dat[i << 1].size() && dat[i << 1][cl] < dat[i << 1 | 1][j - cl])) dat[i][j] = dat[i << 1][cl++];
				else dat[i][j] = dat[i << 1 | 1][j - cl];
				vl[i][j] = cl;
			}
		}
	}
	inline int size() { return size_; }
	inline int query(int l, int r, Type x) {
		// Find range [a, b) : value < x
		int ptr = lower_bound(dat[1].begin(), dat[1].end(), x) - dat[1].begin();
		return query_(l, r, x, 1, 0, size_, ptr);
	}
};

#endif

#include <cstdio>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
int N, Q, xl, yl, xr, yr;
int main() {
	scanf("%d%d", &N, &Q);
	vector<pair<int, int> > p(N);
	for (int i = 0; i < N; i++) scanf("%d%d", &p[i].first, &p[i].second);
	sort(p.begin(), p.end());
	vector<int> z1(N), z2(N);
	for (int i = 0; i < N; i++) {
		z1[i] = p[i].first;
		z2[i] = p[i].second;
	}
	RangeTree<int> seg(z2.begin(), z2.end());
	while (Q--) {
		scanf("%d%d%d%d", &xl, &yl, &xr, &yr);
		int ptr1 = lower_bound(z1.begin(), z1.end(), xl) - z1.begin();
		int ptr2 = lower_bound(z1.begin(), z1.end(), xr + 1) - z1.begin();
		int res1 = seg.query(ptr1, ptr2, yl);
		int res2 = seg.query(ptr1, ptr2, yr + 1);
		printf("%d\n", res2 - res1);
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

typedef long long ll;

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin>>n;
  
  if(n>=64) {
    cout<<64;
    return 0;
  }else if(n>=32) {
    cout<<32;
    return 0;
  }else if(n>=16) {
    cout<<16;
    return 0;
  }else if(n>=8) {
    cout<<8;
    return 0;
  }else if(n>=4) {
    cout<<4;
    return 0;
  }else if(n>=2) {
    cout<<2;
    return 0;
  }else if(n>=1) {
    cout<<1;
    return 0;
  }

}

Measured memory_bytes: 256
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <bits/stdc++.h>

using namespace std;

int main()
{
#ifdef _MSC_VER
	freopen("d.in", "r", stdin);
#endif
	std::ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	int cx, cy;
	cin >> cx >> cy;
	--cx;
	--cy;
	int dx, dy;
	cin >> dx >> dy;
	--dx;
	--dy;
	vector<string> maze(n);
	for (int i = 0; i < n; i++) {
		cin >> maze[i];
	}
	vector<vector<int>> dist(n, vector<int>(m, -1));
	vector<vector<pair<int, int>>> que(n * m * 2);
	auto add = [&](int x, int y, int d) {
		if (x < 0 || x >= n || y < 0 || y >= m) return;
		if (maze[x][y] == '#') return;
		if (dist[x][y] >= 0 && d >= dist[x][y]) return;
		dist[x][y] = d;
		que[d].push_back(make_pair(x, y));
	};
	add(cx, cy, 0);
	for (int d = 0; d + 1 < que.size(); d++) {
		for (int close = 0; close < que[d].size(); ++close) {
			int x = que[d][close].first;
			int y = que[d][close].second;
			for (int dx = -2; dx <= 2; dx++) {
				for (int dy = -2; dy <= 2; dy++) {
					int new_x = x + dx;
					int new_y = y + dy;
					add(new_x, new_y, d + (abs(dx) + abs(dy) > 1 ? 1 : 0));
				}
			}
		}
	}
	cout << dist[dx][dy] << endl;
	return 0;
}


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

int gcd(int x,int y,int z){
  int a =__gcd(x,y);
  int b =__gcd(a,z);
  
  return b;
}
  
int main() {
  int p;
  cin >> p;
  long long sum=0;
  for(int i=1;i<=p;i++){
    for(int j=1;j<=p;j++){
      for(int k=1;k<=p;k++){
        sum+=gcd(i,j,k);
      }
    }
  }
  
  cout << sum <<endl;
}
        
        
  

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include <assert.h>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e9;
// typedef std::pair<int,int> P;
struct edge { int to, cost; };
#define VMAX 100000

int K;
ll N, ans = 0;
ll X[100010], Y[100010];
ll W_[3010][3010], B_[3010][3010];
auto W = W_ + 3, B = B_ + 3;
std::string C[100010];
//yxyx

ll imos(int a, int b, int c, int d, int mode) {
	int res = 0;
	if (a>c || b>d)return 0;
	if (mode == 0) {
		if ((0 <= c && c<2 * K) || (0 <= d && d<2 * K))res += W[c][d];
		if ((0 <= c && c<2 * K) || (0 <= b - 1 && b - 1<2 * K))res -= W[c][b - 1];
		if ((0 <= a - 1 && a - 1<2 * K) || (0 <= d && d<2 * K))res -= W[a - 1][d];
		if ((0 <= a - 1 && a - 1<2 * K) || (0 <= b - 1 && b - 1<2 * K))res += W[a - 1][b - 1];
	}
	else {
		if ((0 <= c && c<2 * K) || (0 <= d && d<2 * K))res += B[c][d];
		if ((0 <= c && c<2 * K) || (0 <= b - 1 && b - 1<2 * K))res -= B[c][b - 1];
		if ((0 <= a - 1 && a - 1<2 * K) || (0 <= d && d<2 * K))res -= B[a - 1][d];
		if ((0 <= a - 1 && a - 1<2 * K) || (0 <= b - 1 && b - 1<2 * K))res += B[a - 1][b - 1];
	}
	return res;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin >> N >> K;
	REP(i, N) {
		cin >> X[i] >> Y[i] >> C[i];
		X[i] %= 2 * K, Y[i] %= 2 * K;
		if (C[i] == "W")W[Y[i]][X[i]] += 1;
		else B[Y[i]][X[i]] += 1;
	}
	REP(i, 2 * K)REP(j, 2 * K) {
		W[i][j + 1] += W[i][j];
		B[i][j + 1] += B[i][j];
	}
	REP(i, 2 * K)REP(j, 2 * K) {
		W[i + 1][j] += W[i][j];
		B[i + 1][j] += B[i][j];
	}

	//for (size_t i = 0; i < 2 * K; i++)
	//{
	//	for (size_t j = 0; j < 2 * K; j++)
	//	{
	//		cout << W[i][j] << ' ';
	//	}
	//	cout << endl;
	//}

	REP(i, K)REP(j, K)REP(k, 2) {
		ll tans = 0;
		tans += imos(0, 0, i - 1, j - 1, (k == 0 ? 0 : 1));
		tans += imos(0, j, i - 1, j + K - 1, (k != 0 ? 0 : 1));
		tans += imos(0, j + K, i - 1, 2 * K - 1, (k == 0 ? 0 : 1));
		tans += imos(i, 0, i + K - 1, j - 1, (k != 0 ? 0 : 1));
		tans += imos(i, j, i + K - 1, j + K - 1, (k == 0 ? 0 : 1));
		tans += imos(i, j + K, i + K - 1, 2 * K - 1, (k != 0 ? 0 : 1));
		tans += imos(K + i, 0, 2 * K - 1, j - 1, (k == 0 ? 0 : 1));
		tans += imos(K + i, j, 2 * K - 1, j + K - 1, (k != 0 ? 0 : 1));
		tans += imos(K + i, j + K, 2 * K - 1, 2 * K - 1, (k == 0 ? 0 : 1));
		ans = max(tans, ans);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 102656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e1+1;
const ll p=1e9+7;
int main()
{
    ll n,a,b;
    cin>>n>>a>>b;
    cout<<max(0LL,(b-a)*(n-2)+1);
	return 0;
}


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

void mod_pow(ll &a, int x, int y, int mod) {
  for(int i = 0; i < y; i++) {
    a *= x;
    a %= mod;
  }
}

int main(){
  int mod = 998244353;
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i = 0; i < n; i++) cin >> d.at(i);
  //root自身への距離!=0
  if(d.at(0) != 0){
    cout << 0 << endl;
    return 0;
  }
  map<int, int> mp;
  ll ans = 1;
  for(int i = 0; i < n; i++) mp[d.at(i)]++;
  //距離0がroot以外に存在(mp[0]>1)
  if(mp[0] != 1){
    cout << 0 << endl;
    return 0;
  }
  for(int i = 0; i < mp.size()-1; i++) {
    mod_pow(ans, mp[i], mp[i+1], mod);
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 2019;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  ll L, R;
  cin >> L >> R;

  vll X(MOD);
  for (ll i=L; i<=R; i++) {
    ll t = i%MOD;
    if (X[t]) break;
    X[t] = 1;
  }

  ll ret = LINF;
  ll END = min({R, L+2*MOD});
  for (ll i=L; i<=END; i++) {
    for (ll j=i+1; j<=END; j++) {
      ret = min({ret, (i%MOD)*(j%MOD)%MOD});
    }
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256
import re
st_in = input()
tmp_in = re.split(" ",st_in)

a = int(tmp_in[0])
b = int(tmp_in[1])

i_sum = 1
for i in range(2,1000):
    i_sum += i
    if i_sum > b and i_sum - i > a:
        if i_sum - b == i_sum - i - a:
            print(i_sum-b)
            break

Measured memory_bytes: 3188
//Night's template
//orzakyrt
#include <bits/stdc++.h>
#define R register
#define LL long long
#ifdef __DEBUG__
	#define Debug (fprintf(stderr,"orzyrt\n"),fflush(stderr))
	#define debug(__a...) (fprintf(stderr,__a),fflush(stderr))
	#define setfile(__a) ('orzyrt')
	#define Compile(__a) system("g++ "__a".cpp -lm -o "__a)
#else
	#define Debug ('orzyrt')
	#define debug(__a...) ('orzyrt')
	#define setfile(__a) freopen(__a".in","r",stdin);freopen(__a".out","w",stdout)
	#define Compile(__a) ('orzyrt')
#endif
template<class TT>inline TT Max(R TT a,R TT b){return a<b?b:a;}
template<class TT>inline TT Min(R TT a,R TT b){return a<b?a:b;}
template<class TT>inline TT Abs(R TT a){return a<0?-a:a;}
template<class TT>inline TT cmin(R TT &a,R TT b){(b<a)&&(a=b);}
template<class TT>inline TT cmax(R TT &a,R TT b){(a<b)&&(a=b);}
using namespace std;
template<class TT>inline void read(R TT &x){
	x=0;R bool f=false;R char c=getchar();
	for(;c<48||c>57;c=getchar())f|=(c=='-');
	for(;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	(f)&&(x=-x);
}
//end template

namespace Night{
	const int maxn = 2e5+10;
	int n,m,lim;
	int mp[555][555];
	int vis[maxn];
	int main(){
		read(n);
		for(R int i=2;i<=448;++i){
			vis[i*(i-1)/2]=i;
			if((i*(i-1))/2==n)lim=i;
		}
		if(!lim){
			puts("No");return 0;
		}
		R int x1=1,x2=2,y1=1,y2=1;
		for(R int i=1;i<=n;++i){
			mp[x1][y1]=mp[x2][y2]=i;
			if(y1==y2 && x2==x1+1){
				x2++;y2=1;
				y1++;x1=1;
			}else{
				y2++;x1++;
			}
		}
		printf("Yes\n");
		printf("%d\n",lim);
		for(R int i=1;i<=lim;++i){
			printf("%d ",lim-1);
			for(R int j=1;j<lim;++j){
				printf("%d ",mp[i][j]);
			}
			puts("");
		}
		return 0;
	}
}
int main(){
	return Night::main();
}

Measured memory_bytes: 2816