akhauriyash/Code-Regression huggingface dataset:
def dot(c1, c2):
    return c1.real * c2.real + c1.imag * c2.imag

def cross(c1, c2):
    return c1.real * c2.imag - c1.imag * c2.real

def string_to_complex(s):
    x, y = map(int, s.split())
    return x + y * 1j

def contains(polygon, point):
    up = False
    down = False
    start_point = polygon[0]
    for p in polygon[::-1]:
        if start_point.imag > p.imag:
            up = True
            break
        elif start_point.imag < p.imag:
            down = True
            break
    flag = False
    for v1, v2 in zip(polygon[0:], polygon[1:]):
        a = v1 - point
        b = v2 - point
        if cross(a, b) == 0 and dot(a, b) <= 0:
            return 1
        if a.imag < b.imag:
            if a.imag < 0 or (a.imag == 0 and up):
                if b.imag > 0 and cross(a, b) > 0:
                    flag = not flag
            up = True
            down = False
        elif a.imag > b.imag:
            if a.imag > 0 or (a.imag == 0 and down):
                if b.imag < 0 and cross(a, b) < 0:
                    flag = not flag
            up = False
            down = True
    if flag:
        return 2
    else:
        return 0

import sys

file_input = sys.stdin

n = int(file_input.readline())

polygon = [string_to_complex(file_input.readline()) for i in range(n)]
polygon.append(polygon[0])

q = int(file_input.readline())

for line in file_input:
    t = string_to_complex(line)
    print(contains(polygon, t))

Measured memory_bytes: 7944
#include <bits/stdc++.h>
using namespace std;
int f(int n,int count)
{
	if(n%2==0)
	{
		n/=2;
		return f(n,count+1);
	}
	else
		return count;
}
int main()
{
	int n,a[10001],i,sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum+=f(a[i],0);
	}
	printf("%d",sum);
	return 0;
}

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

            #define rep(i,a,b) for(ll i =a; i<b;++i)
            #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
            #define endl "\n"
            #define pb push_back
            #define F first
            #define S second
            #define print(a)       for(auto x : a) cout << x << " "; cout << endl
            #define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
            #define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl
            #define mk(x,y)  make_pair(x,y)
            typedef  long long  int ll;
            const ll N = ( 2e3 + 5 );
            const ll mod = 1e18+7;
            ll n,m,a[N],s,b[N],c[N],d[N],u[N],v[N],dp[55][55*55],ans[N];
            vector < pair<ll, pair <ll,ll >> > g[N];
    ll pow_mod_m(ll a , ll n)
    {
        if(!n)
            return 1;
        ll pt =  pow_mod_m(a,n/2);
        pt *= pt ;
        if(n&1)
            pt *= a ;
        return pt;
    }

    void dfs(ll u)
    {

    }

/// dp_i_j min time taken to reach j from i

    int main()
    {
         IOS;
         int ts =1;
         //cin>>ts;
         while(ts--)
         {
             cin >> n >> m >> s;
             s = min(s,2500ll);
             rep(i,1,m+1)
             {
                 cin >> u[i] >> v[i] >> a[i] >> b[i];
                 g[u[i]].pb(mk(v[i],mk(a[i],b[i])));
                 g[v[i]].pb(mk(u[i],mk(a[i],b[i])));
             }
             rep(i,1,n+1)
             {
                 cin >> c[i] >> d[i];
             }
             memset(dp , -1 , sizeof(dp));
             using T = pair<ll, pair <ll,ll > >;
             priority_queue < T , vector <T> , greater<T> > pq; /// {time , { node, silver}}
             pq.push(mk(0,mk(1,s)));
             while(pq.empty() == false)
             {
                 T w = pq.top();
                 pq.pop();
                 ll node = w.S.F;
                 ll silver = w.S.S;
                 if(dp[node][silver] != -1) continue;
                 dp[node][silver] = w.F;
                 if(silver < 2500)
                 {
                     pq.push( mk (w.F + d[node] , mk( node , silver + c[node]) ) );
                 }
                 for(auto v : g[node])
                 {
                     if(v.S.F <= silver and dp[v.F][silver - v.S.F] == -1)
                     {
                         pq.push( mk ( w.F + v.S.S , mk( v.F , silver - v.S.F )));
                     }
                 }
             }
             rep(i,2,n+1)
             {
                 ans[i] = mod;
                 rep(j,0,2501)
                 {
                     ans[i] = min(ans[i],dp[i][j]);
                 }
                 cout << ans[i] << endl;
             }
         }
    }


Measured memory_bytes: 10908
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
    int n;
    scanf("%d",&n);
    if(n%10==3){
        printf("bon");
    }else if(n%10==0||n%10==1||n%10==6||n%10==8){
        printf("pon");
    }else{
        printf("hon");
    }
}


Measured memory_bytes: 3748
package main

import (
	"fmt"
)

func main() {
	var n, limitTime int
	fmt.Scan(&n, &limitTime)

	costs := make([]int, n)
	times := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&costs[i], &times[i])
	}

	minCost := 1001
	for i, time := range times {
		if limitTime < time {
			continue
		}

		if minCost > costs[i] {
			minCost = costs[i]
		}
	}

	if minCost == 1001 {
		fmt.Println("TLE")
	} else {
		fmt.Println(minCost)
	}
}


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

typedef long long LL;  //Attention!!
using namespace std;

#define fillchar(a, x) memset(a, x, sizeof(a))
#define MP make_pair
#define PB push_back
#define endl '\n'

const int M = 1000000007;

int main()
{
ios_base::sync_with_stdio(0); cout.precision(15);cout.setf(ios::fixed);
int a,b;

cin>>a>>b;
 

if(a>0)
	cout<<"Positive"<<endl;
else if(a<=0 && b>=0)
	cout<<"Zero"<<endl;
else if(b<0)
	{	
	if((b-a)%2==0)
		cout<<"Negative"<<endl;
	else
		cout<<"Positive"<<endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    if(a=="Sunny")
        cout<<"Cloudy"<<endl;
    else if(a=="Cloudy")
        cout<<"Rainy"<<endl;
    else if(a=="Rainy")
        cout<<"Sunny"<<endl;
    else
     return 0;
}


Measured memory_bytes: 3580
#include <stdio.h>
int main(void)
{
  int a, b, c, x;
  int cnt[100]={0};
  char *p ="NO";
  scanf("%d %d %d", &a, &b, &c);
  a%=b;
  for(x=a; cnt[x]<2; x=(x+a)%b){
    ++cnt[x];
    if(c==x){
      p="YES";
      break;
    }
  }
  printf("%s\n", p);
  return 0;
}


Measured memory_bytes: 128
n, q = [int(i) for i in input().split()]
process = []
for i in range(n):
    name, time = input().split()
    process.append([name, int(time)])

count = 0
while True:
    if len(process) == 0: break
    if process[0][1] <= q:
        count += process[0][1]
        print(process[0][0], count)
        process[0][1] = process[0][1] - q
        process.pop(0)
    else:
        count += q
        process[0][1] = process[0][1] - q
        process.append(process.pop(0))

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

int main()
{
  int N, T, A;
  cin >> N >> T >> A;
  
  double min = 1000000;
  int ans = 0;
  for(int i = 0; i < N; ++i)
  {
    int height;
    cin >> height;
    if(abs(A - (T - height * 0.006)) < min)
    {
      min = abs(A - (T - height * 0.006));
      ans = i + 1;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void disp(int x)
{
	cout << x<<endl;

}

int main()
{
	int a[3];
	vector<int>vect;
	cin >> a[0]>>a[1]>>a[2];
	for (int i = 0; i < 3; i++) {
		if(a[i]<1 || a[i]>10000)return 0;
	}
	for (int i = 0; i < 3; i++ )vect.push_back(a[i]);
	sort(vect.begin(), vect.end());
	for (int i = 0; i < 2; i++)cout << vect[i] << " "; 
	disp(vect[2]);
	return 0;

}

Measured memory_bytes: 3120
//	package Dynamic;
import java.io.*;
import java.util.*;
class Main
{
    static public void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
//        int t=Integer.parseInt(br.readLine());
//        while(t-->0)
//        {
        	int n=Integer.parseInt(br.readLine());
        	int ar[]=new int[n];
//        	StringTokenizer st=new StringTokenizer(br.readLine());
        	//TreeSet<Integer> tt=new TreeSet<>();
        	int i=0;
        	while(i<n)
        	{
        		ar[i]=Integer.parseInt(br.readLine());
        		i++;
        	}
        	//System.out.println(tt);
        	int max=Integer.MIN_VALUE;
        	int ind=-1;
        	for(int x=0;x<n;x++)
        	{
        		if(ar[x]>max)
        		{
        			max=ar[x];
        			ind =x;
        		}
        	}
        	int max2=Integer.MIN_VALUE;
        	int ff=0;
        	for(int x=0;x<ind;x++)
        	{
        		if(ar[x]>max2)
        		{
        			max2=ar[x];
        			if(max2==max)
        			{
        				ff++;
        			
        				break;
        			}
        		}
        	}
        	if(ff==0)
        	{
	        	for(int x=ind+1;x<n;x++)
	        	{
	        		if(ar[x]>max2)
	        		{
	        			max2=ar[x];
	        			if(max2==max)
	        			{ff++;
	        				break;
	        			}
	        		}
	        	}
        	}
        	if(max==max2)
        	{
        		for(int x=0;x<n;x++)
        			System.out.println(max);
        	}
        	else
        	{
        		for(int x=0;x<n;x++)
        		{
        			if(ar[x]==max)
        				System.out.println(max2);
        			else
        				System.out.println(max);
        		}
        	}
//        	int a=Integer.parseInt(st.nextToken());
//        	int b=Integer.parseInt(st.nextToken());
        	//int c=Integer.parseInt(st.nextToken());
//        	for(int x=0;x<n;x++)
//        	{
//        		ar[x]=Integer.parseInt(st.nextToken());
//        	}
//        	System.out.println((int)Math.ceil(a/((b*2.0)+1)));
        //}
    }
}

Measured memory_bytes: 68148
import sys
sys.setrecursionlimit(10**9)


def unite(par, i, j):
    j = get_par(par, j)
    par[j] = get_par(par, i)

def get_par(par, p):
    while par[p] != p:
        p = par[p]
    return par[p]

def resolve():
    n,m = map(int, input().split())
    cnt = [1 for _ in range(n+1)]
    par = [i for i in range(n+1)]

    for i in range(m):
        a,b = map(int, input().split())
        aa = get_par(par, a)
        bb = get_par(par, b)
        # unite
        if aa == bb:
            continue
        if cnt[aa] > cnt[bb]:
            par[bb] = aa
            cnt[aa] += cnt[bb]
        else:
            par[aa] = bb
            cnt[bb] += cnt[aa]
    #     print(a,b,cnt)

    # print(cnt)
    print(max(cnt))

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 18644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner sc = new Scanner(System.in);
		double p[] = new double[4];
		int i=0;
		double dx,dy;
		
		for(i = 0;i<4;i++){
			p[i]=sc.nextDouble();
		}
		
		dx = Math.pow((p[0]-p[2]), 2.0);
		dy = Math.pow((p[1]-p[3]), 2.0);
		
		System.out.printf("%.8f\n", Math.sqrt((dx+dy)));
	}

}



Measured memory_bytes: 28300
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define N_MAX 1000
#define ll long long int
using namespace std;

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

	if (B == 1) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 1; 1; i++) {
		if (A + (A - 1) * (i - 1) >= B) {
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <limits>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <array>
#include <tuple>
#include <utility>
#include <cctype>
#include <typeinfo>
using namespace std;

#define len(x)  (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b)    for (int a = 0; a < int(b); ++a)
#define ii(n)    ff(i, n)
#define kk(n)    ff(k, n)
#define xx(n)    ff(x, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define iii(a, b) fff(i, a, b)
#define kkk(a, b) fff(k, a, b)
#define mmm(a, b) fff(m, a, b)
#define uu first
#define vv second
#define bb begin()
#define ee end()
#define all(x)  (x).bb, (x).ee
#define ite(v)   decltype((v).bb)
#define fe(i, v) for(ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)    { fprintf(stderr, __VA_ARGS__); fflush(stderr); }

using LL = long long;
using pii = pair<int, int>;


const LL INF = 9223372036854775807LL;
//const int INF = 2147483647;
   


bool fillWith(vector<int> &rr, int &caret, int what, int how_many, int end_index) {
    for (; caret < end_index; ++caret) {
        if (rr[caret] != 0)
            continue;
        if (how_many == 0)
            break;
        rr[caret] = what;
        --how_many;
    }
    if (how_many)
        return false;
    return true;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout << '\n';
    
    int N;
    cin >> N;
    vector<pii> xs(N);
    ii (N) {
        cin >> xs[i].uu;
        --xs[i].uu;
        xs[i].vv = i+1;
    }

    sort(all(xs));

    vector<int> rr(N*N, 0);
    map<int, vector<pii> > waiting;
    int caret = 0;
    ii (len(xs)) {
        bool success = fillWith(rr, caret, xs[i].vv, xs[i].vv-1, xs[i].uu);
        if (!success || rr[xs[i].uu] != 0) {
            cout << "No\n";
            return 0;
        }
        rr[xs[i].uu] = xs[i].vv;
        waiting[xs[i].uu].append(pp(xs[i].vv, N-xs[i].vv));
    }

    queue<int> q;
    ii (len(rr)) {
        if (waiting.count(i)) {
            vector<pii> &waiting_here = waiting[i];
            kk (len(waiting_here)) {
                xx (waiting_here[k].vv)
                    q.push(waiting_here[k].uu);
            }
        }

        if (0 != rr[i])
            continue;
        if (q.empty()) {
            cout << "No\n";
            return 0;
        }
        rr[i] = q.front();
        q.pop();

    }

    cout << "Yes\n";
    ii (len(rr))
        cout << (i == 0 ? "" : " ") << rr[i];
    cout << "\n";






    return 0;
}



Measured memory_bytes: 2688
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
 
class Program
{
    static void Main()
    {
        string[] inputs = Console.ReadLine().Split(' ');
        long H = long.Parse(inputs[0]);
        long W = long.Parse(inputs[1]);
        long result = 0;
        if(!(H % 3 == 0 || W % 3 == 0))
        {
            if(H > W)
            {
                long tmp = H;
                H = W;
                W = tmp;
            }
            long separatePoint = W / 2;
            long[] areas = new long[3];
            long areaGap = long.MaxValue;
            int i = 1;
            while (separatePoint > 0)
            {
                areas[0] = H * separatePoint;
                long H2 = H / 2, W2 = W - separatePoint;
                areas[1] = H2 * W2;
                areas[2] = (H - H2) * W2;
                Console.Error.WriteLine("1-{6} - H1: {0}, W1: {1}, H2: {2}, W2: {3}, H3: {4}, W3: {5}", H, separatePoint, H2, W2, H - H2, W2, i++);
                long compareAreaGap = areas.Max() - areas.Min();
                Console.Error.WriteLine("area1: {0}, area2: {1}, area3: {2}, gap: {3}", areas[0], areas[1], areas[2], compareAreaGap);
                if(areaGap > compareAreaGap)
                {
                    areaGap = compareAreaGap;
                    separatePoint--;
                    continue;
                }
                else break;
            }
            long tmp2 = H;
            H = W;
            W = tmp2;
            separatePoint = W / 2;
            long areaGap2 = long.MaxValue;
            i = 1;
            while (separatePoint > 0)
            {
                areas[0] = H * separatePoint;
                long H2 = H / 2, W2 = W - separatePoint;
                areas[1] = H2 * W2;
                areas[2] = (H - H2) * W2;
                Console.Error.WriteLine("2-{6} - H1: {0}, W1: {1}, H2: {2}, W2: {3}, H3: {4}, W3: {5}", H, separatePoint, H2, W2, H - H2, W2, i++);
                long compareAreaGap = areas.Max() - areas.Min();
                Console.Error.WriteLine("area1: {0}, area2: {1}, area3: {2}, gap: {3}", areas[0], areas[1], areas[2], compareAreaGap);
                if(areaGap2 > compareAreaGap)
                {
                    areaGap2 = compareAreaGap;
                    separatePoint--;
                    continue;
                }
                else break;
            }
            result = Math.Min(areaGap, areaGap2);
            result = result > Math.Min(H, W) ? Math.Min(H, W) : result;
        }
        Console.WriteLine(result);
    }
}


Measured memory_bytes: 17468
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] array = new int[n];
    int sum = 0;
    for(int i = 0; i < n; i++){
      array[i] = sc.nextInt();
      sum = sum ^ array[i];
    }
    for(int i = 0; i < n; i++){
      System.out.print(sum ^ array[i]);
      System.out.print(" ");
    }
  }
}

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

int main(){
    ll X;
    cin >> X;

    ll ans = X/500;
    X -= ans*500;
    ans *= 1000;
    ans += (ll)(X/5) * 5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut d = read_vec::<i64>();
    d.sort();
    let l = d[n / 2 - 1];
    let u = d[n / 2];
    println!("{}", u - l);
}

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()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 22;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  string s; cin >> s;
  int n = s.size();
  map<char, int> m;
  REP(i, n) m[s[i]]++;
  for(char j = 'a'; j <= 'z'; j++) {
    if(m[j] == 0) {
      cout << s + j << endl;
      return 0;
    }
  }
  RREP(i, n-1) {
    for(char j = s[i]+1;j<='z';j++) {
      if(m[j] == 0) {
        cout << s.substr(0, i) + j << endl;
        return 0;
      }
    }
    m[s[i]]--;
  }
  cout << -1 << endl;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
maze = []
for _ in range(h):
  s = input()
  if s != '.'*w:
    maze.append(s)
h = len(maze)
skip = []
for j in range(w):
  for i in range(h):
    if maze[i][j] == '#':
      break
  else:
    skip.append(j)
 
for i in range(h):
  for j in range(w):
    if j not in skip:
      print(maze[i][j],end= '')
  print()

Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> data(M);
  int b, c;
  for(int i = 0; i < M; i++){
    cin >> data.at(i).first >> b;
    for(int j = 0; j < b; j++){
      cin >> c;
      data.at(i).second += pow(2, c - 1);
    }
  }
  int orn;
  vector<vector<int>> dp(M + 1, vector<int>((int)pow(2, N), 1000000000));
  dp.at(0).at(0) = 0;
  for(int i = 0; i < M; i++){
    for(int j = 0; j < pow(2, N); j++){
      if(dp.at(i).at(j) == 1000000000)continue;
      orn = j | data.at(i).second;
      dp.at(i + 1).at(orn) = min(dp.at(i + 1).at(orn), dp.at(i).at(j) + data.at(i).first);
      dp.at(i + 1).at(j) = min(dp.at(i + 1).at(j), dp.at(i).at(j));
      
    }
  }
  if(dp.at(M).at((int)pow(2, N) - 1) == 1000000000)cout << -1 << endl;
  else cout << dp.at(M).at((int)pow(2, N) - 1) << endl;
}

Measured memory_bytes: 16384
#include<bits/stdc++.h>
using namespace std;
int main()
{int n;
  cin>>n;
  string a;
  cin>>a;
  int a1=0;
  int a2=n-1;
  int minoperation=0;
  while(1){
  //cout<<a1<<" "<<a2<<endl;
  if(a2<=a1)
   break;
   if(a[a1]=='W' && a[a2]=='R')
   {
   	swap(a[a1],a[a2]);
   minoperation++;
} 
if(a[a1]=='R')
    a1++;
if(a[a2]=='W')    
    a2--;
  }//cout<<a<<endl;
  cout<<minoperation;
  
  
}


Measured memory_bytes: 3756
fun main() = ABC162C.main()

object ABC162C {
    fun log(message: Any?) {
        //println(message)// TODO: ←消す
    }

    fun main() {
        val K = readInt()
        var ans = 0
        (1..K).forEach { a ->
            (1..K).forEach { b ->
                (1..K).forEach { c ->
                    ans += Gcd.get(a, Gcd.get(b, c))
                }
            }
        }

        println(ans)
        log("calcCount=${Gcd.calcCount}")
    }


    /*####################################################################################*/
    object Gcd {
        var calcCount = 0
            private set
        private val cache = mutableMapOf<Pair<Int, Int>, Int>()

        fun get(a: Int, b: Int): Int {
            val (m, n) = if (a > b) listOf(a, b) else listOf(b, a)
            val cached = cache[m to n]
            return if (cached == null) {
                val gcd = calc(m, n)
                cache[m to n] = gcd
                gcd
            } else cached
        }

        private fun calc(m: Int, n: Int): Int { // m > n
            assert(m > n)
            var m = m
            var n = n
            while (n != 0) {
                val r = m % n
                m = n
                n = r
            }
            calcCount++
            return m
        }
    }

    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map { it.toInt() }
}

Measured memory_bytes: 63052
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <iostream>
#include <limits>
#include <algorithm>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <cmath>


using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
typedef stringstream ss;
const int mii = numeric_limits<int>::min();
const int mai = numeric_limits<int>::max();
const ll mil = numeric_limits<long long>::min();
const ll mal = numeric_limits<long long>::max();

#define REP(i, a, b) for(long long i=a; i<=b; ++i)
#define RREP(i, a, b) for(long long i=a; i>=b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

bool isPal(string  s) {
    /*REP(i, 0, (s.size()/2) - 1)
        if(s[i] != s[s.size() - 1 - i])
            return false;

        return true;*/
    
    string t(s.rbegin(), s.rend());
    return s==t;
}
bool isStrongPalindrome(string s) {

    if(!isPal(s))
        return false;

    int n = s.size();

    if(!isPal(s.substr(0, (n-1)/2)))
        return false;

    if(!isPal(s.substr(((n+3)/2) - 1)))
        return false;

    return true;
}

int main(int argc, char **argv) {
    string s;
    cin >> s;

    if(isStrongPalindrome(s))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[100000];
int i,j,n,m,ans=0;

int main()
{
	cin>>n;
	cin>>a[1]>>a[2];
	if(a[1]==1)ans++;
	if(a[2]==2)ans++;
	if((a[1]==1)&&(a[2]==2)) {swap(a[1],a[2]);ans--;}
	for(i=3;i<=n;i++)
	{
	cin>>a[i];
	if(a[i]==i)ans++;
	if((a[i-1]==i-1)&&(a[i-2]!=i-2)&&(a[i]==i)) {swap(a[i],a[i-1]);ans--;}
	}
	//if((a[n]==n)&&(a[n-1]==n-1)) ans--;
	cout<<ans;
	return 0;
}


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

#define rep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll MOD = 1e9+7;

int main(){

    int A,B,Q;
    cin >> A >> B >> Q;

    vector<ll> s(A+2,0);
    vector<ll> t(B+2,0);

    s[0] = -30000000001;
    t[0] = -30000000001;
    s[A+1] = 30000000000;
    t[B+1] = 30000000000;

    rep(i,0,A){
        cin >> s[i+1];
    }
    rep(i,0,B){
        cin >> t[i+1];
    }

    ll x;
    int si,ti;
    ll ls,lt,rs,rt;
    rep(loop,0,Q){

        cin >> x;
        si = distance(s.begin(),lower_bound(s.begin(),s.end(),x));
        ti = distance(t.begin(),lower_bound(t.begin(),t.end(),x));
        ls = x - s[si-1];
        lt = x - t[ti-1];
        rs = s[si]-x;
        rt = t[ti]-x;

        cout << min({ max(ls,lt) , max(rs,rt) , min(ls,rt) * 2 + max(ls,rt) , min(lt,rs) * 2 + max(lt,rs) }) << endl;
    }

}

Measured memory_bytes: 2944
using System;
using System.Collections.Generic;
using System.Linq;
 
class MainClass {
  public static void Main (string[] args) {
    //入力3
    var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var list = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var N = temp[0];
    var T = temp[1];
    
    if(N == 1){
      Console.WriteLine(T);
      return;
    }

    var sumtime = 0;
    var stoptime = 0;
    for(var i = 0; i < N; i++){
      if(i == N - 1){
        sumtime += stoptime - list[i-1];
        break;
      }
      if(list[i + 1] - list[i] < T){
        sumtime += list[i + 1] - list[i];
      }else{
        sumtime += T;
      }
      stoptime = list[i] + T;
    }
    Console.WriteLine(sumtime);
  }
}


Measured memory_bytes: 30432
while True:
    n = int(input())
    if not n:
        break
    #map???????????£????????£??¨????????????????°???????????????????????????????????????¨
    f = [[int(j) for j in input().split()] for i in range(n)]
    ans = max(min(f[i]) for i in range(n))
    tans = [max(f[i][j] for i in range(n)) for j in range(n)]
    for i in range(n):
        if tans[i] == ans:
            break
    else:
        ans = 0
    print(ans)

Measured memory_bytes: 7740
f=lambda:map(int,input().split())
n,k=f()
a=list(f())
lv=[-1]*n
lv[0]=0
p=0
for i in range(n):
  t=a[p]-1
  if lv[t]>=0:
    l,r=lv[t],i+1
    break
  lv[t]=i+1
  p=t
print(lv.index(l+(k-l)%(r-l) if k>l else k)+1)

Measured memory_bytes: 32260
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define ld long double
#define int long long
#define double long double
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pi 3.141592653589793238
const int MOD = 1e9+7;
const int INF = 1LL<<60;


const int N = 2e5+5;

// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif


void solve(){
    int x; cin>>x;
    For(i, 1, 361){
        int v = x*i;
        if(v%360 == 0){
            cout<<i;
            return;
        }
    }
}


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int t=1; 
    // cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, a[100001], dp[100001];
int main()
{
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	dp[1] = abs(a[0] - a[1]);
	for(int i = 2; i < n; i++){
    	dp[i] = min(abs(a[i] - a[i - 1]) + dp[i - 1], abs(a[i] - a[i - 2]) + dp[i - 2]);
	}
	cout << dp[n - 1];
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
#define MMAX 20
#define NMAX 50000
#define INFTY (1<<29)

int n, m;
int C[21];
int T[NMAX+1];
int getmin()
{
    for(int j=0; j<=n; j++)
        T[j] = INFTY;
    T[0] = 0;
    for(int i=0; i<=m; i++)
    {
        for(int j=C[i]; j<=n; j++)
            T[j] = min(T[j], T[j-C[i]]+1);
    }
    return T[n];
}
int main()
{
    cin >> n >> m;
    for(int i=1; i<=m; i++)
        cin >> C[i];
    cout << getmin() << endl;
    return 0;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(std::string S){
    cout << (S == "ABC" ? "ARC" : "ABC") << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
P arms[100010]; 
int main() {
	int n;
	cin >> n;

	int x, l;
	rep(i,n) {
		cin >> x >> l;
		arms[i] = {x+l,x-l};
	}
	sort(arms,arms+n);

	int ans = 0;
	int end = arms[0].second;
	rep(i,n) {
		if (arms[i].second >= end) {
			ans++;
			end = arms[i].first;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4388
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back

using namespace std;

const ll N=3e3+5;

int n;

double mem[N][N],p[N];

bool vis[N][N];

vector<int>adj[N];

char ch[N][N];

double dp(int pos,int cnt)
{
    if (pos==n)
    {
        if (cnt>n/2)return 1.0;
        else return 0.0;
    }
    if (vis[pos][cnt])return mem[pos][cnt];
    double ans=dp(pos+1,cnt+1)*p[pos];
    ans+=(1.0-p[pos])*dp(pos+1,cnt);
    vis[pos][cnt]=1;
    return mem[pos][cnt]=ans;
}

int main()
{
    memset(mem,-1,sizeof mem);
    cin >> n;
    for (int i=0;i<n;i++)
    {
        cin >> p[i];
    }
    cout << fixed << setprecision(9) << dp(0,0) << endl;
}


Measured memory_bytes: 80512
x,n =map(int,input().split())
 
if  n==0:
    print(x)
else:
    P =list(map(int,input().split()))
    for i in range(100):
        if  (x-i) not in P:
            print(x-i)
            break
        elif (x+i) not in P:
            print(x+i)
            break

Measured memory_bytes: 9180
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        int cost = 0;
        if (n > k) {
            cost = y * (n-k) + k * x;
        } else {
            cost = n * x;
        }

        System.out.println(cost);
    }
}


Measured memory_bytes: 23124
#include<cstdio>
#include<cstring>
const int N=190,M=17;
int n,m,f[N][N][N][M];char mp[N][N];
inline int imn(int x,int y){return x<y?x:y;}inline int imx(int x,int y){return x>y?x:y;}
int main()
{
	scanf("%d%d",&n,&m);for(int i=1;i<=n;++i)scanf("%s",mp[i]+1);
	for(int i=m;~i;--i)for(int j=1;j<=n;++j)f[j][j][i][0]=mp[j][i]==mp[j][i+1]?f[j][j][i+1][0]:i;
	for(int i=1;i<=m;++i)for(int j=1;j<=n;++j)for(int k=j+1;k<=n;++k)
		f[j][k][i][0]=mp[k][i]==mp[k-1][i]?imn(f[j][k-1][i][0],f[k][k][i][0]):0;
	for(int i=1;i<=16;++i)for(int j=1;j<=m;++j)for(int k=1;k<=n;++k)for(int l=k,x=k;l<=n;++l)
	{
		for(;x<l&&imn(f[k][x][j][i-1],f[x+1][l][j][i-1])<=imn(f[k][x+1][j][i-1],f[x+2][l][j][i-1]);++x);
		f[k][l][j][i]=imx(f[k][l][j][i-1],imx(f[k][l][f[k][l][j][i-1]+1][i-1],imn(f[k][x][j][i-1],f[x+1][l][j][i-1])));
	}
	for(int i=0;i<=16;++i)if(f[1][n][1][i]==m)return 0&printf("%d",i);
}

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

namespace AtCoderBeginnerContest
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ').Select(x=>long.Parse(x)).ToArray();
            var N = line[0];
            var A = line[1];
            var B = line[2];

            long max = A + B * (N-1);
            long min = A * (N - 1) + B;
            var rt = max - min + 1;
            if (rt < 0) rt = 0;
            Console.WriteLine(rt);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define each(i, n) for(auto&& i: n)

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

#ifdef local
	#include "debug/debug.h"
#endif


#ifndef local
	#define deb(x...) ;	
#endif

#define int long long  
#define ll long long
#define vi vector <int>
#define vii vector <pair<int,int> >
#define vvi vector <vi>
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define M_PI 3.14159265358979323846 

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
///*X.find_by_order("index")
///X.order_of_key("key")

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

int H, W, ch, cw, dh, dw;
string grid[1003];
bool vis[1003][1003];
int dist[1003][1003];

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

void solve()
{
	cin >> H >> W >> ch >> cw >> dh >> dw;
	ch--;cw--;dh--;dw--;
	rep(i,0,H) cin >> grid[i];
	
	rep(i,0,H)rep(j,0,W) dist[i][j] = MOD;
	dist[ch][cw] = 0;
	deque<pii> Q;
	Q.pb({ch, cw});
	
	while(!Q.empty())
	{
		auto te = Q.front();
		Q.pop_front();
		
		rep(i,0,4)
		{
			int nx = te.ff + dx[i], ny = te.ss + dy[i];
			if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
			if (grid[nx][ny] == '#') continue;
			
			if (dist[nx][ny] > dist[te.ff][te.ss])
			{
				dist[nx][ny] = dist[te.ff][te.ss];
				Q.push_front({nx, ny});
			}
		}
		rep(i,-2, 3) rep(j, -2, 3)
		{
			int nx = te.ff + i, ny = te.ss + j;
			if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
			if (grid[nx][ny] == '#') continue;
			
			if (dist[nx][ny] > dist[te.ff][te.ss])
			{
				dist[nx][ny] = dist[te.ff][te.ss] + 1;
				Q.push_back({nx, ny});
			}
		}
	}
	if (dist[dh][dw] == MOD) cout << "-1\n";
	else cout << dist[dh][dw] << "\n";
}

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	
	#ifdef local
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	clock_t TIMER = clock();
	#endif
	
	int t = 1;
	// cin >> t;
	rep(a,0,t)
	{
		//cout<<"Case #"<<a+1<<": ";
		solve();
		#ifdef local
		cout << "\n";
		#endif

	}
	
	#ifdef local
	{TIMER = clock() - TIMER;double time_taken = ((double)TIMER)/CLOCKS_PER_SEC;cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "<<time_taken<<" seconds\n";}
	#endif
}

Measured memory_bytes: 13784
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
struct pp{
  ll first;
  ll second;
};
pp dp[3010][3010];
int main(){
  int n;
  cin >> n;
  vector<ll> a(n,0);
  ll sum = (ll)0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    dp[i][i].first = a[i];
    dp[i][i].second = 0;
  }

  for(int len = 1;len<n;len++){
    for(int i=0;i<n-len;i++){
      int j=i+len;
      if(a[i]+dp[i+1][j].second>a[j]+dp[i][j-1].second){
        dp[i][j].first = a[i]+dp[i+1][j].second;
        dp[i][j].second = dp[i+1][j].first;
      }
      else{
        dp[i][j].first = a[j]+dp[i][j-1].second;
        dp[i][j].second = dp[i][j-1].first;
      }
    }
  }
  cout<<(dp[0][n-1].first-dp[0][n-1].second)<<endl;
}


Measured memory_bytes: 141568
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<string> vs;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

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

	ll N, M;  cin >> N >> M;

	ll cnt = min(N, M / 2);
	if (M - cnt * 2 > 3) {
		cnt += (M - cnt * 2) / 4;
	}

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


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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i =0; i < n; i++){
        cin >> a.at(i);
    }

    for (int i = n-1; i > -1; i--){
        cout << a.at(i) ;
        if(i != 0) cout << " "; 
    }
    cout << endl;

    return 0;
}



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

int main() {
    int l, r, d; cin >> l >> r >> d;
    int ans = 0;
    for (int i = l; i <= r; i++) {
        if (i% d == 0) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
import java.util.*;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}

	public Main() {
		new AOJ0202().doIt();
	}

	class AOJ0202{
		void doIt(){
			int N = 1000001;
			boolean prime[] = new boolean[N];
			Arrays.fill(prime, true);prime[0]=false;prime[1]=false;
			for(int i=2;i<N;i++)if(prime[i])for(int s=i+i;s<N;s+=i)prime[s] = false;
			while(true){
				int n = in.nextInt();//ryouri
				int x = in.nextInt();//kin
				if(n+x==0)break;
				int[] cook = new int[n];
				for(int i=0;i<n;i++)cook[i] = in.nextInt();
				Arrays.sort(cook);				
				boolean res[] = new boolean[x+1];
				res[0] = true;
				for(int i=0;i<n;i++){
					for(int s=cook[i];s<=x;s++)if(s-cook[i]>=0&&res[s-cook[i]])res[s] = true;
				}
				
				
//				for(int i=0;i<=x-10000;i++)System.out.println(i+" "+res[i]);
				
				int result = 0;
				for(int i=x;i>=0;i--)if(prime[i]&&res[i]){
					result = i;
					break;
				}
				System.out.println(result==0?"NA":result);
			}
		}
	}

}

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

int main()
{
    int a, b;
    char op;

 do {
    cin >> a >> op >> b;
    
        switch(op) {
            case '+':
                cout << a + b << endl;
                break;
            case '-':
                cout << a - b << endl;
                break;
            case '*':
                cout << a * b << endl;
                break;
            case '/':
                cout << a / b << endl;
            default:
                break;
        }
}while(op!='?');
    return 0;

}


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

    int N;
    cin>>N;
    vector<int>l(N);
    for(int i=0;i<N;i++)
        cin>>l[i];

    sort(l.begin(),l.end());

    long long ans=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            for(int k=j+1;k<N;k++){
                if(l[j]-l[i]<l[k]&&l[k]<l[i]+l[j])
                    ans++;
                else
                    break;
            }
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
 public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  int A = sc.nextInt();
  int B = sc.nextInt();
  int G = B-A+1;
  for(int i=0;i<2*A-1;i++){
   if(G<=1000000&&G>=-1000000){
    System.out.println(G);
   }
   G++;
  }
 }
}

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

using namespace std;

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

    int ans=0;
    for(int i=9;i<=n;i+=2){
        int cnt=0;
        for(int j=1;j<=i;j++){
            if(i%j==0) cnt++;
            if(cnt>8) break;
        }
        if(cnt==8) ans++;
        cnt=0;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
const int Maxn=1e5+5;
#define rep(i,n) for (int i=0;i<n;++i)
#define int long long
int n,mx;
std::vector <int> v[Maxn];
int dp[Maxn];
void dfs(int k,int p=-1)
{
	int s=0;
	int ss=0;
	std::vector <int> t;
	for (auto &x:v[k])
	{
		if (x==p)
		{
			continue;
		}
		ss++;
		t.push_back(x);
		dfs(x,k);
		if (dp[x])
		{
			s++;
		}
		dp[k]+=dp[x];
	}
	dp[k]+=std::max(ss-s-1,0ll);
}
signed main()
{
	std::cin>>n;
	for (int i=1;i<n;++i)
	{
		int x,y;
		std::cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	rep(i,n)
	{
		if (v[i].size()>v[mx].size())
		{
			mx=i;
		}
	}
	dfs(mx);
	std::cout<<std::max(1ll,dp[mx])<<std::endl;
	return 0;
}

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

int main() {

  int K, N;
  cin >> K >> N;

  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int mx = 0;

  vector<int> D(N+1);
  for (int i = 0; i < N; i++) {
    D[i] = A[i + 1] - A[i];
    if (i == N - 1) {
      D[i] = K - A[i] + A[0];
    }
    mx = max(D[i], mx);
  }

  cout << K - mx << endl;

  return 0;

}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    ll N, M;
    ll key[10004], cost[10004];
    ll dp[1024][10000];
    ll a, b, c;
    cin>>N>>M;
    ll goal=pow(2, N)-1;
    MEMSET(key, 0);
    MEMSET(cost, 0);
    rep(i, M){
        cin>>a>>b;
        cost[i]=a;
        rep(j, b){
            cin>>c;
            key[i]+=pow(2, c-1);
            
        }//cout<<key[i]<<endl;
    }
    rep(i, M+1) rep(j, goal+1) dp[i][j]=10000000001;
    dp[0][0]=0;
    rep(i, M) rep(j, goal+1){
        dp[i+1][j|key[i]]=min(dp[i+1][j|key[i]], dp[i][j]+cost[i]);
        dp[i+1][j]=min(dp[i][j], dp[i+1][j]);
        
        /*rep(k, M+1){
            rep(l, goal+1) cout<<dp[k][l]<<" ";
            cout<<endl;
        }
        cout<<endl;*/
    }
    cout<<((dp[M][goal]>10000000000) ?  (ll)-1 : dp[M][goal])<<endl;
    return 0;
}


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

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

    vector<int> a(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    sort(a.begin(), a.end());

    for (size_t i = 0; i < n - 1; i += 2)
    {
        if (a[i] < 0)
        {
            if (a[i + 1] < 0 || a[i + 1] < -a[i])
            {
                a[i] = -a[i];
                a[i + 1] = -a[i + 1
                ];
            }
        }
    }

    long long sum = 0;
    for (size_t i = 0; i < n; i++)
    {
        sum += a[i];
    }

    cout << sum << endl;
}


Measured memory_bytes: 640
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 1e5 + 20 ;
int n , l , a[N] ;
vector <int> vec ;

void solve (int x) {
	vec.push_back(x) ;
	for (int i = x + 1 ; i < n - 1 ; i ++) vec.push_back(i) ;
	for (int i = x - 1 ; i >= 0 ; i --) vec.push_back(i) ;

	cout << "Possible\n" ;
	while (vec.size()) {
		cout << vec.back() + 1 << '\n' ;
		vec.pop_back() ;
	}
}

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

	cin >> n >> l ;

	for (int i = 0 ; i < n ; i ++) cin >> a[i] ;

	for (int i = 0 ; i < n - 1 ; i ++) {
		if (a[i] + a[i + 1] >= l) {
			solve(i) ;
			return 0 ;
		}
	}

	cout << "Impossible\n" ;
}


Measured memory_bytes: 1784
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>

using namespace std;
typedef pair<short,short> pii;

short dp[2001][2001];
pii to[2001][2001];

string s;
string s2;
int n;

// sツづ2ツづ可づつつ「ツづ、ツ催妥・ツ閉板閉ェツ暗ェツ致ツ閉カツ篠堋療アツ陳キツづーツ仰づ淞づゥ
// ツつスツつセツつオツ、s_posツづ2_posツづーcrossツつウツつケツづづ債つ「ツつッツづ按つ「
int dfs(int a,int b){
	int b_rev=n-1-b;
	if(b_rev<a){
		to[a][b].first=-1;
		return 0;
	}
	else if(b_rev==a){
		to[a][b].first=-2;
		return 1;
	}
	if(dp[a][b]!=-1)return dp[a][b];
	int res=0;
	if(s[a]==s2[b]){
		int tmp=res;
		res=max(res,dfs(a+1,b+1)+2);
		if(tmp!=res){
			to[a][b]=pii(a+1,b+1);
		}
	}
	int tmp=res;
	res=max(res,dfs(a+1,b));
	if(tmp!=res){
		to[a][b]=pii(a+1,b);
	}
	tmp=res;
	res=max(res,dfs(a,b+1));
	if(tmp!=res){
		to[a][b]=pii(a,b+1);
	}
	return dp[a][b]=res;
}

int main(){

	while(cin>>s){
		n=s.size();
		memset(dp,-1,sizeof(dp));
		s2=s;
		reverse(s2.begin(),s2.end());
		int res=dfs(0,0);
		pii cur=pii(0,0);
		string ret;
		while(1){
			pii nxt=to[cur.first][cur.second];
			if(nxt.first==-1){
				string tmp=ret;
				reverse(tmp.begin(),tmp.end());
				ret=ret+tmp;
				break;
			}
			if(nxt.first==-2){
				string tmp=ret;
				reverse(tmp.begin(),tmp.end());
				ret=ret+s[cur.first]+tmp;
				break;
			}
			// diffツつェ1
			if(nxt.first-cur.first==1&&nxt.second-cur.second==1)
				ret+=s[cur.first];
			cur=nxt;
		}
		cout<<ret<<endl;
	}

	return 0;
}

Measured memory_bytes: 23000
n = int(input())
sticks = list(map(int, input().split()))
sticks.sort()
ans = 0
for i in range(n):
    for j in range(i+1,n):
        li = sticks[i]
        lj = sticks[j]
        if li < lj:
            for k in range(j+1, n):
                lk = sticks[k]
                if lj < lk:
                    if lk >= li +lj:
                        break
                    else:
                        ans += 1
print(ans)


Measured memory_bytes: 9184