akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

int N, W;
int w[100005];
long long int v[100005];
long long int dp[105][100005];

int main(void) {
	cin >> N >> W;
	for (int i = 1; i <= N; i++) {
		cin >> w[i] >> v[i];
	}

	for (int i = 1; i <= N; i++) {
		dp[i][w[i]] = max(dp[i][w[i]],v[i]);
		for (int j = 1; j <= W; j++) {
			if (dp[i - 1][j] != 0) {
				dp[i][j] = max(dp[i][j], dp[i - 1][j]);
				if (j + w[i] <= W) { dp[i][j + w[i]] = max(dp[i][j + w[i]], dp[i - 1][j] + v[i]); }
			}
		}
	}

	long long int ans = 0;

	for (int j = 1; j <= W; j++) {
		ans = max(ans, dp[N][j]);
	}

	cout << ans << endl;

	/*for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= W; j++) {
			cout << "dp[" << i << "][" << j << "]= " << dp[i][j] << endl;
		}
	}*/

	//system("pause");
	return 0;
}

Measured memory_bytes: 78080
M,D = map(int,input().split(' '))

ans = 0
for m in range(1,M+1):
	for d1 in range(2,10):
		for d10 in range(2,10):
			if 10*d10 + d1 <= D:
				if m == d10 * d1:
					ans += 1

print(ans)




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

int main() {
  int h1,m1,h2,m2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  
  int wake = (h2 * 60 + m2) - (h1 * 60 + m1);
  
  if(wake > k){
    cout << wake - k << endl;
  } else {
    cout << 0 << endl;
  }
}


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

int main(){
  int t,n;
  ll k,l,r,b;
  pair<ll,ll> a;
  cin>>t;
  for(int i=0;i<t;i++){
    cin>>n;
    ll ans=0;
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> lq;
    priority_queue<pair<ll,ll>> rq;
    for(int j=0;j<n;j++){
      cin>>k>>l>>r;
      ans+=min(l,r);
      if(l>=r)lq.push({k,l-r});
      else rq.push({k,r-l});
    }
    priority_queue<ll,vector<ll>,greater<ll>> la,ra;
    ll lac=0,rac=0;
    for(int j=1;j<=n;j++){
      if(lq.empty())break;
      a=lq.top();
      while(a.first==j){
        lq.pop();
        la.push(a.second);
        lac++;
        ans+=a.second;
        if(lq.empty())break;
        else a=lq.top();
      }
      while(lac>j){
        b=la.top();
        la.pop();
        ans-=b;
        lac--;
      }
    }
    for(int j=n;j>=1;j--){
      if(rq.empty())break;
      a=rq.top();
      while(a.first==j){
        rq.pop();
        ra.push(a.second);
        rac++;
        ans+=a.second;
        if(rq.empty())break;
        else a=rq.top();
      }
      while(rac>n-j){
        b=ra.top();
        ra.pop();
        ans-=b;
        rac--;
      }
    }
    cout<<ans<<endl;
  }
}


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

class Main{
    public static void main(String[] args)throws IOException {
    	InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);
        String hw[]=br.readLine().split(" ");
        for(int i=0;i<Integer.parseInt(hw[0]);i++){     
        	char []cl=br.readLine().toCharArray();
        	int flag=-1;
        	for(int j=0;j<Integer.parseInt(hw[1]);j++){
        		if(flag>-1)flag++;
        		if(cl[j]=='c')flag=0;
        		if(j==0){
        			System.out.print(flag);
        		}else System.out.print(" "+flag);
        	}
        	System.out.println();
        }        
        br.close();
    }
}

Measured memory_bytes: 29744
h,w = map(int,input().split())
n = int(input())
l = []
a = list(map(int,input().split()))
for i in range(n):
  for j in range(a[i]):
    l.append(i+1)
for i in range(h):
  if i % 2 == 0:
    print(' '.join(map(str,l[i*w:(i+1)*w])))
  else:
    b = l[i*w:(i+1)*w]
    b.reverse()
    print(' '.join(map(str,b)))

Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#define N 600
int f(int x){
    return x*x;
}


int main(void){
        int d,i;
        int sum;    
    while(std::cin>>d){
        sum=0;
        for(int i=d;i<N;i+=d){
            sum+=f(i)*d;
        }
        std::cout<<sum<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 3096
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

long a[3];

int main(){
    for(int i = 0; i < 3; i++){
        scanf("%ld", a+i);
    }
    for(int i = 0 ;i < 3; i++){
        if(a[i] == a[(i+1)%3] + a[(i+2)%3]){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


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

int toInt(char c){
  return (int)(c - '0');
}

bool isMonth(int m){
  return m >= 1 && m <= 12;
}

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

  int a = toInt(s[0])*10 + toInt(s[1]);
  int b = toInt(s[2])*10 + toInt(s[3]);

  if(isMonth(a) && isMonth(b)) cout<<"AMBIGUOUS"<<endl;
  else{
    if(isMonth(a)) cout<<"MMYY"<<endl;
    else{
      if(isMonth(b)) cout<<"YYMM"<<endl;
      else cout<<"NA"<<endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256
program main
	implicit none
	integer(8) :: Q, H, S, D, N
	
	read(*, *) Q, H, S, D
	read(*, *) N
	
	if(mod(N,2) == 0) then
		Q = 8*Q
		H = 4*H
		S = 2*S
		write(*, *) N/2 * min(Q,H,S,D)
	else
		Q = min(2*H,4*Q,S)
		write(*, *) min(N*Q,N/2 * D+Q)
	end if
end program main

Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;
using namespace std;

// xが素数か判定する
bool isprime(long long x)
{
    if (x == 2)
        return true;

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

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

// エラトステネスの篩
// 配列に素数ならtrueを入れる
bool prime[100000001];
void eratos(long long n)
{
    for (long long i = 0; i < n; i++)
        prime[i] = true;
    prime[0] = prime[1] = false;
    for (long long i = 2; i <= sqrt(n); i++)
    {
        if (prime[i])
        {
            long long j = i + i;
            while (j <= n)
            {
                prime[j] = false;
                j += i;
            }
        }
    }
}

int main(void)
{
    //cout << isprime(101) << endl;
    //cout << isprime(4) << endl;

    // eratos(100000001);
    int n;
    cin >> n;
    int ans = 0;
    REP(i, n)
    {
        int a;
        cin >> a;
        if (isprime(a))
        {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define ll long long
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD ll(1000000007)

int main()
{ FAST
    int a, b, c; cin >> a >> b >> c;
    if((a == b && a != c) || (a == c && a != b) || (b == c && c!= a)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#素因数分解、計算量はO(√N)
from collections import defaultdict
def factorize(n):
  b = 2
  dic = defaultdict(lambda: 0)
  while b * b <= n:
    while n % b == 0:
      n //= b
      dic[b] += 1
    b = b + 1
  if n > 1:
    dic[n] += 1
  return dic

def extgcd(a, b):
  if b:
    d, y, x = extgcd(b, a%b)
    y -= (a//b)*x
    return d, x, y
  else:
    return a, 1, 0
N = int(input())
fct = factorize(2*N)
lis = []
for k,v in fct.items():
  lis.append(pow(k,v))
ans = 10**18
from itertools import groupby, accumulate, product, permutations, combinations
for pro in product([0,1],repeat=len(lis)):
  prod1 = 1
  for i,p in enumerate(pro):
    if p==1:
      prod1 *= lis[i]
  prod2 = (N*2)//prod1
  if min(prod1,prod2)>ans:
    continue
  if min(prod1,prod2)==1:
    ans = min(ans, max(prod1,prod2)-1)
  else:
    d,a1,a2 = extgcd(prod1,prod2)
    ans = min(ans, min(abs(a1*prod1),abs(a2*prod2)))
print(ans)



Measured memory_bytes: 71020
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;

int main() {
	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
	
	mp::cpp_int A, B; std::cin >> A >> B;

	if (A == B) {
		std::cout << "EQUAL";
	}
	else if (A > B) {
		std::cout << "GREATER";
	}
	else {
		std::cout << "LESS";
	}
	return 0;
}

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

int main(){
  string S, T;
  cin >> S >> T;
  int size;
  size = (int)S.size();
  
  int ans = 0;
  for(int i=0; i<size; i++){
    if(S.at(i) != T.at(i))ans++;
  }
  cout << ans <<endl;
}

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


int main() {
  int N; cin >> N;
  vector<vector<int>> F(N, vector<int>(10));
  vector<vector<int>> P(N, vector<int>(11));
  for(int i=0; i<N; i++) for(int j=0; j<10; j++) cin >> F[i][j];
  for(int i=0; i<N; i++) for(int j=0; j<11; j++) cin >> P[i][j];

  vector<int> cnt(N);
  int ans = -1145141919;
  int profit;

  for(int i=1; i<(1<<10); i++){
    profit = 0;
    for(int& c:cnt) c = 0;

    for(int j=0; j<10; j++){
      for(int k=0; k<N; k++){
        if((i>>j)&F[k][j] == 1){
          cnt[k]++;
        }
      }
    }

    for(int j=0; j<N; j++)  profit += P[j][cnt[j]];
    ans = max(ans, profit);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

vector<ll> lun;

void dfs(int d, ll  now){
    lun.push_back(now);

    if(d == 10) return;

    for(int i = -1; i <= 1; i++){
        int add = now%10 + i;
        if(add >= 0 && add <= 9) dfs(d+1, now*10 + add);
    }
}

int main() {
    int k;
    cin >> k;
    rep(i,9) dfs(1,i+1);
    sort(all(lun));
    dunk(lun[k-1]);
    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define ii pair<int, int>
#define fi first
#define se second

int n, m;
char G[30][30];
int dist[30][30];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int solve(ii s, ii e)
{
    if(G[s.fi][s.se] == '#' or G[e.fi][e.se] == '#') return -1;
    queue<ii> q;
    memset(dist, -1, sizeof(dist));
    dist[s.fi][s.se] = 0;
    q.push(s);
    while(!q.empty())
    {
        ii c = q.front();
        q.pop();
        for(int i = 0; i < 4; i++)
        {
            int x = c.fi + dx[i], y = c.se + dy[i];
            if(x >= 0 and x < n and y >= 0 and y < m and dist[x][y] == -1 and G[x][y] == '.')
            {
                dist[x][y] = dist[c.fi][c.se] + 1;
                q.push({x, y});
            }   
        }
    }
    return dist[e.fi][e.se];
}

int32_t main()
{
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            cin >> G[i][j];
    
    int ans = 0;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            for(int a = 0; a < n; a++)
                for(int b = 0; b < m; b++)
                    ans = max(ans, solve({i, j}, {a, b}));
    cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
s=input()
n=len(s)-1
ans=int(s)
for i in range(1,2**n):
    cut=[0]
    for j in range(n):
        if (i>>j)&1:
            cut.append(j+1)
    tmp=0
    for j in range(1,len(cut)):
        tmp+=int(s[cut[j-1]:cut[j]])
    tmp+=int(s[cut[j]:])
    ans+=tmp

print(ans)

Measured memory_bytes: 69352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("abc160/abc160_c.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int K, N;
  cin >> K >> N;
  
  vector<int> c(N);
  rep(i, N) { cin >> c[i]; }

  int diff = K - c[N - 1] + c[0];
  rep(i, N - 1) { diff = max(diff, c[i + 1] - c[i]); }

  cout << K - diff << endl;
}

Measured memory_bytes: 1024
def main():
    n,m = map(int, input().split())
    a = sorted(list(map(int, input().split())),reverse = True)
    all = sum(a)
    cnt = 0
    for i in(a):
        if(i * 4 * m >= all and cnt < m):
            cnt += 1
    if cnt >= m:
        print('Yes')
    else:
        print('No')
main()

Measured memory_bytes: 9100
def main():
  a, b, c = map(int, input().split())
  k = int(input())
  for i in range(k):
    if a >= b:
      b*=2
    elif b >= c:
      c*=2
  if a < b and b < c:
    print("Yes")
  else:
    print("No")
    
if __name__ == "__main__":
  main()

Measured memory_bytes: 9092
package main

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

var (
	rdr   = bufio.NewReaderSize(os.Stdin, 1000000)
	reply string
)

func main() {
	in := nextSlice()
	solve(in)
}

func solve(buf []string) {
	var x, _ = strconv.Atoi(buf[0])
loop:
	for i := x; ; i++ {
		for j := 2; j < i; j++ {
			if i%j == 0 {
				continue loop
			}
		}
		reply = strconv.Itoa(i)
		break
	}
	fmt.Println(reply)
}

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func nextSlice() []string {
	return strings.Split(readLine(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func scanSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func scanFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

// ---------------------------------------------------

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func min(a ...int) int {
	min := a[0]
	for i := 1; i < len(a); i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	return min
}

func max(a ...int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}

// ---------------------------------------------------

func yesOrNo(b bool) {
	if b {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func yesorNO(b bool) {
	if b {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
 
 
int main(void) {
 
 
	int n,a,i,s;
	char b[100];
 
	scanf("%d",&n);
	scanf("%s",b);
 
	a = n/2;
 
	s = a;
	i=0;
	while(b[i]==b[s]&&i<a){
		i++;
		s++;
	}
 
	if(n%2 !=0 ){
		i++;
	}
	if(i == a){
		printf("Yes");
	}else{
		printf("No");
	}
 
 
	return 0;
}

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

int main() {
  int64_t a, b, c;
  cin >> a >> b >> c;

  if (a + b > c) {
    cout << "No" << endl;
    return 0;
  }

  cout << (4 * a * b < (c - a - b) * (c - a - b) ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a,b,c;
	int tmp;
	scanf("%d %d %d",&a,&b,&c);
	if(a>=b){
		tmp=a;
		a=b;
		b=tmp;
	}
	if(b>=c){
		tmp=b;
		b=c;
		c=tmp;
	}
	if(a>=b){
		tmp=a;
		a=b;
		b=tmp;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N, Y;
    cin >> N >> Y;
    int res[] = {-1,-1,-1};
    for(int i = 0; i <= N; ++i) {
        for(int j = 0; j <= N; ++j) {
            int c = N - i - j;
            int total = 10000*i + 5000*j + 1000*c;
            if(Y == total && N == i + j + c && c >= 0) {
                res[0] = i;
                res[1] = j;
                res[2] = c;
            }
            // for(int k = 0; k < N; k++) {
            //     if(N == (i + j + k)
            //     && Y == (i * 10000) + (j * 5000) + (k * 1000)) {
            //         res[0] = i;
            //         res[1] = j;
            //         res[2] = k;
            //     }
            // }
       }
    }
    cout << res[0] << " " << res[1] << " " << res[2] << endl;
    return 0;
}

Measured memory_bytes: 256
'use strict'
function main(input) {
    const tmp = Array.from(input.split('\n'));
    const N = parseInt(tmp[0], 10);
    const A = tmp[1].split(' ').map((elem) => parseInt(elem, 10));

    let X = [];
    const S = A.reduce((sum, elem) => sum + elem);
    const A2 = A.filter((elem, i) => i % 2 !== 0).reduce((sum, elem) => sum + elem);
    X[0] = S - 2 * A2;

    for (let i = 1; i < N; i++) {
        X[i] = 2 * A[i - 1] - X[i - 1];
    }
    console.log(X.join(' '));

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

bool p[10000001];
vector<int> plist,p4;

void prime(){
	p[0] = true;
	p[1] = true;
	for(int i = 4;i < 10000001;i += 2){
		p[i] = true;
	}
	for(int i = 3;i < sqrt(10000001) + 1;i++){
		for(int j = i * 2;j < 10000001;j += i){
			p[j] = true;
		}
	}
	for(int i = 0;i < 10000001;i++){
		if(!p[i]) {
			plist.push_back(i);
		}
	}
	for(int i = 0;i < plist.size() - 3;i++){
		if(plist[i + 3] - plist[i] == 8 && plist[i + 2] - plist[i] == 6 && plist[i + 1] - plist[i] == 2) p4.push_back(plist[i + 3]);
	}
}

int main(){
	int n;
	prime();
	while(cin >> n,n){
		bool flag = false;
		for(int i = 0;i < p4.size();i++) {
			if(p4[i] > n){
				cout << p4[i - 1] << endl;
				flag = true;
				break;
			}
		}
		if(!flag) cout << p4[p4.size() - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 15348
//#ifdef JUDGE
//#include <fstream>
//std::ifstream cin("input.txt");
//std::ofstream cout("output.txt");
//#else
#include <iostream>
#include <bits/stdc++.h>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stdio.h>
using namespace std;
#define ll long long
ll sd(ll n)
{
    ll a=0;
    while (n>0)
    {
        a+=n%10;
        n/=10;
    }
    return a;
}
void solve()
{
   string s;
   cin>>s;
   int l=s.length();
   cout<<s[0]<<l-2<<s[l-1];
}
int main()
{
    ll t=1;
    //cin >>t;
    while(t--)
        solve();

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1e9+7;
using namespace std;
#define ll long long
#define ar array

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

	int N,K;
	cin >> N >> K;
	int ans = 0;

	for (int i = 0; i < N; i++) {
		int h;
		cin >> h;
		if (h>=K) ans++;
	}
	cout << ans << endl;
	return 0;
}


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


double ans = 0;
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  int64_t dp[N];
  dp[0] = 0;
  dp[1] = abs(A[1] - A[0]);
  for(int i=2;i<N;i++){
    dp[i] = min(dp[i-2] + abs(A[i]-A[i-2]), dp[i-1] + abs(A[i]- A[i-1]));
  }
  cout << dp[N-1] << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;

    vector<int> v(N, 0);
    vector<vector<int>> start(N, vector<int>());
    vector<vector<int>> end(N+1, vector<int>());
    for(int i = 0; i < M; i++) {
        int l, r;
        cin >> l >> r;
        l -= 1; r-=1;
        start[l].push_back(i);
        end[r+1].push_back(i);
    }

    int enable = 0;
    int count = 0;
    for(int i = 0; i < N; i++) {
        enable += start[i].size() - end[i].size();
        if(enable == M) count++;
    }
    // sort(v.begin(), v.end(), greater<int>());
    // int count = 0;
    // for(int i = 0; i < N; i++) {
    //     if(v[i] == M) count++;
    //     else {
    //         break;
    //     }
    //}
    cout << count << endl;
    return 0;
}

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

using namespace std;

const uint64_t MOD = 1e+9 + 7;

int main()
{
  uint64_t N, M;
  cin >> N >> M;
  
  vector<uint64_t> S(N), T(M);
  for (uint64_t n = 0; n < N; ++n) { cin >> S[n]; }
  for (uint64_t m = 0; m < M; ++m) { cin >> T[m]; }
  
  vector< vector<uint64_t> > dp(N + 1), sum(N + 1);
  for (uint64_t n = 0; n <= N; ++n) {
    dp[n] = vector<uint64_t>(M + 1, 0);
    sum[n] = vector<uint64_t>(M + 1, 0);
  }
  
  for (uint64_t n = 1; n <= N; ++n) {
    for (uint64_t m = 1; m <= M; ++m) {
      if (S[n - 1] == T[m - 1]) {
        dp[n][m] = (sum[n - 1][m - 1] + 1) % MOD;
      } else {
        dp[n][m] = 0;
      }
      sum[n][m] = (sum[n - 1][m] + sum[n][m - 1]) % MOD;
      sum[n][m] = (sum[n][m] + MOD - sum[n - 1][m - 1]) % MOD;
      sum[n][m] = (sum[n][m] + dp[n][m]) % MOD;
    }
  }
  
  cout << ((sum[N][M] + 1) % MOD) << endl;
  
  return 0;
}

Measured memory_bytes: 62976
N=int(input())
S=input()
S_sp=list(S)

if len(S_sp)%2==1:
    print("No")
elif len(S_sp)%2==0:
    for i in range(int(N/2)):
        if not S_sp[i]==S_sp[int(N/2)+i]:
            print("No")
            break
        if i==int(N/2)-1 and S_sp[int(N/2)-1]==S_sp[N-1]:
            print("Yes")

Measured memory_bytes: 3060
S=input()
T=len(S)
a=0
d=1
mod=[0]*2019
mod[0]+=1
for i in range(T):
 a+=(int(S[T-i-1])*(d))%2019
 b=a%2019
 mod[b]+=1
 d*=10
 d%=2019
c=0
for i in range(2019):
 if mod[i]>=2:
  c+= mod[i]*(mod[i]-1)/2
print(int(c))

Measured memory_bytes: 68560
K=gets.strip.to_i

a=(K+50-1)/50 + 49
b=50-K%50
puts 50

if b==50
	(1..50).each do |i|
		print a-50+b
		print ' ' if i<50
	end	
	puts ''
else
	(1..b).each do |i|
		print a-50+b-1
		print ' '
	end
	(1..50-b).each do |i|
		print a+b
		print ' ' if i<50-b
	end
	puts ''
end

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main(){
  int n;
  string foot;
  int left = 0;
  int right = 0;
  int status = 0;
  int count = 0;
  while(1){
    count = 0;
    int left = 0;
    int right = 0;
    int status = 0;
    cin >> n;
    if(n == 0){
      break;
    }

    for(int i = 0;i < n;i++){
      cin >> foot;
      if(foot == "lu"){
        left = 1;
      }else if(foot == "ru"){
        right = 1;
      }else if(foot == "ld"){
        left = 0;
      }else{
        right = 0;
      }
      

      if(left == 1 && right == 1 && status == 0){
        count++;
        status = 1;
      }

      if(left == 0 && right == 0 && status == 1){
        count++;
        status = 0;
      }
    }
    cout << count << endl;
  }
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())

using namespace std;
typedef pair<int,int> P;

// 最大公約数
int64_t gcd(int64_t a, int64_t b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
int64_t lcm(int64_t a, int64_t b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  int64_t h,w;
  cin >> h >> w;
  vector<string> vec(h);
  REP(i,h){
    cin >> vec.at(i);
  }
  queue<P> q;
  int reached[1100][1100];
  REP(i,1100){
    REP(j,1100){
      reached[i][j] = INT_MAX;
    }
  }
  REP(i,h){
    REP(j,w){
      if (vec.at(i).at(j) == '#'){
        q.push(P(i,j));
        reached[i][j] = 0;
      }
    }
  }
  int t=0;
  while (q.size()){
    int x,y;
    P p = q.front();q.pop();
    y = p.first;
    x = p.second;
    if (y < 0 || y >= h || x < 0 || x >= w){
      continue;
    }
    if (vec.at(y).at(x) == '.'){
      vec.at(y).at(x) = '#';
      t = reached[y][x];
    }
    if (reached[y+1][x] == INT_MAX){
      reached[y+1][x] = reached[y][x] + 1;
      q.push(P(y+1,x));
    }
    if (reached[y-1][x] == INT_MAX){
      reached[y-1][x] = reached[y][x] + 1;
      q.push(P(y-1,x));
    }
    if (reached[y][x+1] == INT_MAX){
      reached[y][x+1] = reached[y][x] + 1;
      q.push(P(y,x+1));
    }
    if (reached[y][x-1] == INT_MAX){
      reached[y][x-1] = reached[y][x] + 1;
      q.push(P(y,x-1));
    }
  }
  cout << t << endl;
  return 0;
}



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

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int h, w;
    vector<P> data;

    while(true) {
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        data.push_back(P(h, w));

    }
    for(auto d : data){
        for(int i = 0; i < d.first; i++){
            for(int k = 0; k < d.second; k++){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3184
#include <iostream>

using namespace std;

int main(){

	ios::sync_with_stdio(false);

	int a, b;
	cin >> a >> b;

	bool maior = a >= 13;
	bool menor = a >= 6 and a < 13;

	if(maior)
		cout << b << endl;
	else if(menor)
		cout << b/2 << endl;
	else
		cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<queue>
#include<math.h>
#include<time.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<map>
#include<stack>
#define LL long long
#define mem(a,b) memset(a,b,sizeof(a))
#define lowbit(a) a&(-a)
#define PI acos(-1)
#define shortime(a)  std::ios::sync_with_stdio(a);
using  namespace std;
const LL mod=1e9+7;
//long long cmp(node a,node b){ if(a.x==b.x) return a.r>b.r;return a.x>b.x;}
//LL  quick(LL x,LL n){ LL ans=1,temp=x; while(n){if(n%2==1){ ans=(ans*temp)%mod;} n/=2;temp=temp*temp%mod;}return ans;}
int maxn (int a,int b,int c){return max(max(a,b),max(b,c));}
LL min(LL a,LL b) {return a<b?a:b;}
int gcd (int a,int b){return b==0?a:gcd(b,a%b);}
vector<int>a[100040];
queue<int>Q;
int main()
{
    int n,x,y;
    int vis[200005];
    mem(vis,0);
    scanf("%d",&n);
    for(int i=0;i<n-1;i++)
    {
        scanf("%d%d",&x,&y);
        a[x].push_back(y);
        a[y].push_back(x);
    }
    int num1=0,num2=0,flag=1;
    vis[1]=1,vis[n]=2;
    Q.push(1);
    Q.push(n);
    while(!Q.empty())
    {
        int temp;
        temp=Q.front();
        Q.pop();
        for(int i=0;i<a[temp].size();i++)
        {
            if(vis[a[temp][i]]==0)
            {
                Q.push(a[temp][i]);
                vis[a[temp][i]]=vis[temp];
                if(vis[temp]==1) num1++;
                else num2++;
            }
        }
    }
    if(num1>num2)
         printf("Fennec\n");
    else printf("Snuke\n");
    return 0;
}


Measured memory_bytes: 6656
/*　　　　　　　{:i:i:|i:i:/l/l--　 　 　--l/li:i:i|i:i:i:i}
　　　　　　 　 {:rx|:i:i ィi芥ミ 　 　 .ィi芥ミｉ:ｉ|ﾍ:i:i:}
.　　　 　 　 　 ｛ﾏ|ｉ:  {::’:} 　 　 　{:‘::} :ｉ:i:|〉｝:/
　　 　 　 　 　 乂|:i:| ｀¨¨¨¨´ 　 　　｀¨¨¨´  :i:ｉ:|ｼ/
　 　 　 　 　 　 ﾉ:|:i|　　　　　　′　　　 　   |:i:i:|ﾂ
　　　　　　　　/:/|:i:| ､　　　 　_ _ 　　　　  |:i:i:|
　 　 　　 　 /:/ .|:i:|/ ＼　　　 　 　     ｨ〔|:i:/
　　 　 　  　 〈;/ く刈＿ 个 　   -   　＜}　./|/_〉
　　     　　 r-っ'~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ~ﾞ|___
　　 　     /／ニつ　　　　　　 ､　　　　　　　ノﾆﾆ　＼
.　　　     |　　ニ⊃ 　./　/　 ──   /　/　　..⊆ﾆﾆ　　:|
.　　　     |　　丁´　 /|￣|￣  ─‐ /|￣|￣ 　 .￣|丁 　|
.　　　     |　　ﾉ.  　 |￣|￣  ─‐  |￣|￣ 　 　.|八 　|
.　　　     |　　||. 　 |￣|￣ |￣| |￣|￣ 　   .|　|
.　 　 　   |  　||   　￣￣￣　￣ 　￣￣￣　　  .|　|  |
.　 　 　  　    ||＿＿＿＿＿＿＿＿＿＿＿＿______|__　　 ',
　 　      ,′　 | ７ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ}  ,′
.　　     {　　　|/　}ﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆﾆ{/ 　 　
*///讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐讐。
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>

using namespace std;

#define rep(a) _rep(0,int(a))
#define repj(a) for(int j=0;j<int(a);j++)
#define _rep(a,b) for(int i=int(a);i<int(b);i++)
#define ll long long
#define fst first
#define snd second
#define pf(b) printf("%.12f\n",(double)b)
#define _GLIBCXX_DEBUG
const double pai = 3.1415926535897;
#define _cos(n) cos(n*pai/180)

//factorial(練習)　階乗
int fact(int n) {
	int a = 1;
	for (int i = 1;i <= n;i++) a *= i;
	return a;
}
int sa(int n, int m) {      //差！
	if (n < m)return m - n;
	else return n - m;
}

string s;
signed main() {
	cin >> s;
	int a = s.size();
	rep(a) {
		if (s[i] == '1')s[i] = '9';
		else if (s[i] == '9')s[i] = '1';
		cout << s[i];
	}cout << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn uc(a : i32, b : i32) -> i32{
    fn ucc(la : i32, sm : i32) -> i32 {
        let ans = la % sm;
        if ans == 0 {
            return sm;
        }
        ucc(sm, ans)
    }
    if a > b {ucc(a, b)} else {ucc(b, a)}
}

fn divisor_list(num : i32) -> Vec<i32> {
    let mut ans : Vec<i32> = vec![num];
        for i in (0..(num / 2)).rev() {
            if num % (i + 1) == 0 {
                ans.push(i + 1);
            }
        }
    ans
}

fn main() {
    input! {
        a : i32,
        b : i32,
        k : usize
    }
    println!("{:?}", divisor_list(uc(a, b))[k - 1]);
}


Measured memory_bytes: 4352
import java.util.*;

public class Main{
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int N=sc.nextInt(), count=0, a;
    
    for(int i=0; i<N; i++) {
      a = sc.nextInt();
      while(a % 2 == 0) {
        count++;
        a /= 2;
      }
    }

    System.out.println(count);   
  }
}


Measured memory_bytes: 34908
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18 
 
using namespace std;


signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int n,i;
    cin>>n;
    int ans=0;
    for(i=1;i<=n;i++)
    {
        ans+=i*(n-i+1);
    }
    // cout<<ans;
    for(i=0;i<n-1;i++)
    {
        int u,v;
        cin>>u>>v;
        if(u>v) swap(u,v);
        ans-=u*(n-v+1);
    }
    cout<<ans;
}


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

int main() {
    vector<int> times;
    
    int N; cin >> N;
    
    for (int i=0; i<N; i++) {
        int h, m; cin >> h >> m;
        times.push_back(1000*h+m);
    }
    
    int M; cin >> M;
    
    for (int i=0; i<M; i++) {
        int h, m; cin >> h >> m;
        times.push_back(1000*h+m);
    }
    
    sort(times.begin(), times.end());
    times.erase(unique(times.begin(), times.end()), times.end());
    
    for (int i=0; i<times.size(); i++) {
        int h=times[i]/1000, m=times[i]%1000;
        string h2=to_string(h), m2=to_string(m);
        
        if (m2.size()==1) {
            m2 = '0'+m2;
        }
        
        string res = h2+':'+m2;
        
        if (i<times.size()-1) {
            res += ' ';
        }
        
        cout << res;
    }
    
    cout << endl;
}


Measured memory_bytes: 3296
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n;
    cin >> n;
    unordered_map<int, int> m;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        m[a] += 1;
    }

    long sum = 0;
    for (auto [i, k] : m) sum += i * k;

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int b, c;
        cin >> b >> c;
        int k = m[b];
        m[b] = 0;
        m[c] += k;
        sum = sum + (c - b) * k;
        cout << sum << endl;
    }
}


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

using namespace std;
const int N = 1e5 + 9 ;
bool vis[N];
vector < int > adj[N];
int n , m, x , y;
int mem[N];
int dfs(int s){
    if(adj[s].empty()){

        return 0;
    }
    vis[s] = 1;
    int &ret = mem[s];
    if(~ret)
        return ret;
    for(int i = 0 ; i < adj[s].size() ; ++i){
              int to = adj[s][i];
              ret = max(ret , 1 + dfs(to));

    }
    return ret;


}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(mem , -1 , sizeof mem);
    cin >> n >> m;
    for(int i = 0 ; i < m ; ++i){
        cin >> x >> y;
        adj[x].push_back(y);
    }
    int ans = 0;
    for(int i = 1 ;i<=n;++i){
        if(!vis[i]){
            ans = max(ans , dfs(i));
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 11528
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
  int N, P = 0, D, num, count, ans = 0 ;
  cin >> N ;
  char X[N] ;
  cin >> X ;
  for(int i=0;i<N;i++){
    if(X[i] == '1') P++ ;
  }
  int Func[P+1] ;
  Func[0] = 0 ;
  for(int i=1;i<P+1;i++){
    count = 0 ;
    num = i ;
    while(num){
      if((num % 2) == 1) count++ ;
      num /= 2 ;
    }
    Func[i] = 1 + Func[(i % count)] ;
  }
  int Pplus[N], Pminus[N], digplus = 1, digminus = 1 ;
  if(P == 2){
    Pplus[N-1] = 1 ;
    Pminus[N-1] = 0 ;
  }
  else if(P == 1){
    Pplus[N-1] = 1 ;
    Pminus[N-1] = 0 ;
  }  
  else if(P == 0){
    Pplus[N-1] = 0 ;
    Pminus[N-1] = 0 ;
  }
  else{
    Pplus[N-1] = 1 ;
    Pminus[N-1] = 1 ;
  }
  
  int Xplus = 0, Xminus = 0;
  if(P <= 1){
    for(int i=N-2;i>=0;i--){
      digplus = (digplus * 2) % (P+1) ;
      Pplus[i] = digplus ;
    }
    for(int i=0;i<N;i++){
      if(X[i] == '1'){
        Xplus = (Xplus + Pplus[i]) % (P+1) ;
      }
    }
  }
  else{
    for(int i=N-2;i>=0;i--){
      digplus = (digplus * 2) % (P+1) ;
      Pplus[i] = digplus ;
      digminus = (digminus * 2) % (P-1) ;
      Pminus[i] = digminus ;
    }
    for(int i=0;i<N;i++){
      if(X[i] == '1'){
        Xplus = (Xplus + Pplus[i]) % (P+1) ;
        Xminus = (Xminus + Pminus[i]) % (P-1) ;
      }  
    }
  }
  if(P <= 1){
    for(int i=0;i<N;i++){
      if(X[i] == '1'){
        cout << 0 << endl ;
        continue ;
      }
      else{
        num = (Xplus + Pplus[i]) % (P+1) ; 
        cout << 1 + Func[num] << endl ;
      }
    }
  }
  else{
    for(int i=0;i<N;i++){
      if(X[i] == '1'){
        num = (Xminus - Pminus[i] + (P-1) ) % (P-1) ;
        cout << 1 + Func[num] << endl ;
      }
      else{
        num = (Xplus + Pplus[i] ) % (P+1) ; 
        cout << 1 + Func[num] << endl ;
      }
    }
  }
  return 0 ;
}  

Measured memory_bytes: 5780
#include <bits/stdc++.h>
using namespace std ;
int main(){
    string A,B;
    cin >> A >> B;
    int Ak = A.size();
    int Bk = B.size();
    int Ans=-1;
    if(Ak>Bk)Ans=0;
    else if(Ak<Bk)Ans =1;
    else{
        for(int i=0;i<A.size();i++){
            if(A[i]>B[i]){
                Ans =0;
                break;
            }else if(A[i]<B[i]){
                Ans =1;
                break;
            }
        }
    }
    if(Ans==0)cout << "GREATER" << endl;
    else if(Ans ==1)cout << "LESS" << endl;
    else cout << "EQUAL" << endl;
    
 }

Measured memory_bytes: 3632
/*
                            ---| APOORVA MITTAL |---
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl "\n"
#define nl   "\n"

#define speed                     \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)


// ====== Useful functions end ======

//--------------------------------------------------------------------------------------------------------------------------------
void solve()
{
   int K; cin>>K;
   int sum=0;
   for(int i=1;i<=K;i++)
   {
       for(int j=1;j<=K;j++)
       {
           for(int k=1;k<=K;k++)
           {
               int g = __gcd(i,j);
               g = __gcd(g,k);
               sum+=g;
           }
       }
   }
   cout<<sum<<endl;

}
signed main()
{	
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

	speed;
	int t=1;
	// cin>>t;
	
	for(int tt=1;tt<=t;tt++)
	{
		// cout<<"Case #"<<tt<<": ";
		solve();
	}
}


Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    C = list(map(int, input().split()))
    C.append(INF) # 1-indexed
    C.sort(reverse = 1)

    res = 0
    for i in range(1, n + 1):
        res += (i + 1) * C[i]
        res %= MOD

    res *= pow(4, n - 1, MOD)
    res %= MOD
    print(res)
resolve()

Measured memory_bytes: 80232
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

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

    cout << (n+1)/2 << endl;
}

Measured memory_bytes: 888
<?php                                                                           
$sLen = intval(trim(fgets(STDIN)));                                             
$s = explode(' ', trim(fgets(STDIN)));                                          
$tLen = intval(trim(fgets(STDIN)));                                             
$t = explode(' ', trim(fgets(STDIN)));                                          
$count = 0;                                                                     
                                                                                
for ($j = 0; $j < $tLen; $j++) {                                                
    $i = 0;                                                                     
    $s[$sLen] = $t[$j];                                                         
                                                                                
    while ($s[$i] !== $t[$j]) {                                                 
        $i++;                                                                   
    }                                                                           
    if ($i !== $sLen) {                                                         
        $count++;                                                               
    }                                                                           
}                                                                               
                                                                                
echo $count . "\n"; 


Measured memory_bytes: 11076
#include <iostream>

int main() {
  int a, b, c;
  std::cin >> a >> b >> c;
  if (b < a) {
    int tmp = b;
    b = a;
    a = tmp;
  }
  if (c < a) {
    int tmp = c;
    c = b;
    b = a;
    a = tmp;
  }
  if (c < b) {
    int tmp = c;
    c = b;
    b = tmp;
  }
  std::cout << a << " " << b << " " << c << "\n";
  return 0;
}


Measured memory_bytes: 3096
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main(){
    int A, B;
    cin >> A >> B;
    cout << max(A - 2 * B, 0) << endl;
}


Measured memory_bytes: 3580
#include <stdio.h> 

int main(void)
{
	int n, i, j, rank;
	int card[4][13]={0};
	char mark;
	

	for(i = 0; i < 4; i++)
	{
		for(j = 0; j < 13; j++)
		{
			card[i][j] = 0;
		}
	}

	scanf("%d",&n);

	for(i = 0; i < n*2; i++)
	{
		scanf("%c %d", &mark, &rank);

		if(mark == 'S')
		{
			card[0][rank-1] = 1;
		}
		if(mark == 'H')
		{
			card[1][rank-1] = 1;
		}
		if(mark == 'C')
		{
			card[2][rank-1] = 1;
		}
		if(mark == 'D')
		{
			card[3][rank-1] = 1;
		}
	}

	for(i = 0; i < 4; i++)
	{
		for(j = 0; j < 13; j++)
		{
			if(card[i][j] != 1)
			{
				if(i == 0)
				{
					printf("S %d\n",j+1);
				}
				if(i == 1)
				{
					printf("H %d\n",j+1);
				}
				if(i == 2)
				{
					printf("C %d\n",j+1);
				}
				if(i == 3)
				{
					printf("D %d\n",j+1);
				}
			}
		}
	}



	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

template<class T>bool chmax(T &a, const 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 true; } return false; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll h,n;
    cin>>h>>n;
    VV dp(n+1,Vec(h+1,INF));

    Vec a(n);
    Vec b(n);
    rep(i,n){
        cin>>a[i]>>b[i];
    }

    a.insert(a.begin(),0);
    b.insert(b.begin(),0);
    ll ans=0;

//    dbg(a);
//    dbg(b);
    dp[0][h] = 0;
    //i番目までで、HPをhにするときの魔力の消費
    REP(i,1,n+1){
        per(j,h){
            dp[i][j] = dp[i-1][j];
        }
        per(j,h){
            dp[i][ max(j-a[i],0LL)] =  min(dp[i][max(j-a[i],0LL)],dp[i][j]+b[i]);
        }
    }
   // dbg(dp);
    cout<<dp[n][0]<<endl;
    return  0;
}


Measured memory_bytes: 78720
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n>>k;

	cout<<(n-k+1);
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
using namespace std;

int main()
{
    int c[3][3];
    int i, j;
    
    for(i = 0; i < 3; i++) {
        for(j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }
    
    int j1 = c[0][0]-c[0][1], j2 = c[1][0]-c[1][1], j3 = c[2][0]-c[2][1];
    int j4 = c[0][1]-c[0][2], j5 = c[1][1]-c[1][2], j6 = c[2][1]-c[2][2];
    int j7 = c[0][0]-c[1][0], j8= c[0][1]-c[1][1], j9 = c[0][2]-c[1][2];
    int j10 = c[1][0]-c[2][0], j11 = c[1][1]-c[2][1], j12 = c[1][2]-c[2][2];
    
    if(((j1==j2)&&(j2==j3))&&((j4==j5)&&(j5==j6))&&((j7==j8)&&(j8==j9))&&((j10==j11)&&(j11==j12))) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
main()
{
    int n,i,j,cnt=0,cnt_ans=0;
    scanf("%d",&n);
    if(n<105){printf("0\n");}
    else {
    for(i=105;i<=n;i=i+2)
    {  cnt=0;
        for(j=1;j<=i;j++)
        {
            if(i%j==0){cnt++;}
        }
        if(cnt==8){cnt_ans++;}
    }
    printf("%d\n",cnt_ans);}

    return 0;

}


Measured memory_bytes: 256