akhauriyash/Code-Regression huggingface dataset:
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// class
// ------------------------------------------------
class Combi
{
  public:
    Combi();
    long long Combination(long long n, long long k);
  private:
    vector<vector<long long>> memo;
    long long n_num;
    long long k_num;
    void Resize(long long n, long long k);
};

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<long> vll;
// code
// ------------------------------------------------
int main() {

  ll a,b,c;
  cin >> a >> b >> c;

  ll right = c - a - b;
  ll left = 4 * a * b;

  if(left < right * right && right > 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Combi::Combi(){
  n_num = -1;
  k_num = -1;
};
ll Combi::Combination(ll n, ll k)
{
  Resize(n,k);

  ll ret;
  if(memo[n][k] != 0)
  {
    ret = memo[n][k];
  }
  else if(n == k || k == 0)
  {
    memo[n][k] = 1;
    ret = 1;
  }
  else
  {
    ret = Combination(n - 1, k - 1) + Combination(n - 1, k);
    memo[n][k] = ret;
  }
  return ret;
}

void Combi::Resize(ll n, ll k)
{
  if(n_num <= n || k_num <= k)
  {
    n_num = (n + 1) * 2;
    k_num = (k + 1) * 2;
    memo.resize(n_num);
    for(auto itr = memo.begin(); itr != memo.end(); ++itr)
    {
      itr->resize(k_num);
    }
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
public class ABC139B {
    public static void Main() {
        int A, B, ans = 0;
        string[] str = Console.ReadLine().Split(' ');
        A = int.Parse(str[0]);
        B = int.Parse(str[1]);
        ans = (B - 1) / (A - 1);
        if (B != 1 && (B - 1) % (A - 1) != 0) ans++;
        Console.WriteLine(ans);
    }
}


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

public class Main {
	static int cnt = 0;
	static int m = 0;
	static int[] G = new int[100];

	public static void insertionSort(int[] A, int n, int g) {
		int v = 0;
		for(int i = g; i < n; i++) {
			v = A[i];
			int j = i - g;

			while(j >= 0 && A[j] > v) {
				A[j + g] = A[j];
				j = j - g;
				cnt++;
			}
			A[j + g] = v;
		}
	}

	public static void shellSort(int[] A,int n) {
		cnt = 0;

		G[0] = 1;
		m = 0;
		for(int i = 1; i < 100; i++) {
			int tmp = G[i - 1] * 3 + 1;

			if(tmp > n) {
				m = i;
				break;
			}

			G[i] = tmp;
		}

		for(int i = m - 1; i >= 0; i--) {
			insertionSort(A, n, G[i]);
		}
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int inputNumOfTimes = Integer.parseInt(br.readLine());

		int[] sortNum = new int[inputNumOfTimes];

		for(int i = 0; i < inputNumOfTimes; i++) {
			sortNum[i] = Integer.parseInt(br.readLine());
		}

		shellSort(sortNum, inputNumOfTimes);

		System.out.println(m);

		for(int j = m - 1; j >= 0; j--) {
			System.out.print(G[j]);

			if (j == 0){
				break;
			}
			System.out.print(" ");
		}
		System.out.println();

		System.out.println(cnt);

		for(int i = 0; i < sortNum.length; i++) {
			System.out.println(sortNum[i]);
		}
	}
}

Measured memory_bytes: 106600
/// Code by Leonardo16
///   “It is not the strength of the body, but the strength of the spirit.”   —  J.R.R. Tolkien
#include<bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")

#define int long long
#define ll long long
#define sz size
#define ull unsigned long long
#define ld long double
#define ii pair<int,int>
#define fst first
#define scd second
#define vi vector<int>
#define vii vector<ii>
#define pb push_back
#define pf push_front
#define fl '\n'
#define el endl
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
/// Functions
#define db(x) cerr << #x << ": " << (x) << '\n';
#define random() __builtin_ia32_rdtsc()
#define lg2(x) 31-__builtin_clz(x)
#define lg2ll(x) 63-__builtin_clzll(x)
#define pi acos(-1)
#define YN(x) cout<<((x)?("YES"):("NO"))<<fl;
#define yn(x) cout<<((x)?("Yes"):("No"))<<fl;
#define des(x,s1,s2,end1,end2) cout<<((x)?(s1):(s2))<<fl;if(x){end1;}else{end2;}
#define precision(x) cout.setf(ios::fixed);cout.precision(x);
/// Red-Black Tree Template
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
//#define less_than(n) order_of_key(n)
//#define en_pos(n) find_by_order(n)
/// Prime numbers  173,179,311,331,737,1009,2011,2027,3079,4001,100003
///=====================================================================

main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s,t;
    cin>>s>>t;

    int ans=0;
    for(int i=0;i<s.sz();i++){
        if(s[i]!=t[i]){
            ans++;
        }
    }

    cout<<ans;
return 0;}







Measured memory_bytes: 3888
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>

#include <numeric>

#include <map>

#include <memory>

using namespace std;

typedef long long LL;

int n,m;

int s[1111], c[1111];

int getmin(int x) {
    if (x == 1) return 0;
    if (x == 2) return 10;
    if (x == 3) return 100;
}

int getmax(int x) {
    if (x == 1) return 10;
    if (x == 2) return 100;
    if (x == 3) return 1000;
}

int dig(int ss, int cc, int x) {
    if (n-ss < 0) return false;
    int cnt = 0; int a[20];
    memset(a,-1,sizeof a);
    a[cnt++] = x % 10;
    do {
        x/=10;
        a[cnt++]=x%10;
    } while(x);
    if (n-ss>=cnt) {
        return false;
    }
    return a[n-ss] == cc;
}

int check2(int x) {
    for (int i = 1; i <= m; ++i) {
        if (!dig(s[i], c[i], x)) return false;
    }
    return true;
}

int main() {

    cin >> n >> m;
    for (int i =1;i<=m;++i) {
        cin>>s[i]>>c[i];
    }

    bool ok = false;

    for (int i = getmin(n); i < getmax(n); ++i) {
        if (check2(i)) {
            cout << i;
            return 0;
        }
    }
    cout << -1;
    return 0;

}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

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

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

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll n;
  cin >> n;
  cout << "ABC" << n << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1e12;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

ll check(ll h, ll w)
{
	ll h1 = h / 2;
	ll h2 = h - h1;
	ll ans = 100000000000;

	for (ll i = 1;i < w;i++) {
		ll s1, s2, s3;
		s1 = h * i;	
		s2 = h1 * (w - i);
		s3 = h2 * (w - i);

		ll d = max(s1, max(s2, s3)) - min(s1, min(s2, s3));
		ans = min(ans, d);
	}

	return ans;
}

int main()
{
	ll h, w;
	cin >> h >> w;

	ll ans = 100000000000;

	if (h % 3 == 0 || w % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}

	ans = std::min(ans, w);
	ans = std::min(ans, h);

	ans = std::min(ans, check(w, h));
	ans = std::min(ans, check(h, w));

	cout << ans << endl;

	return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fore(i,a) for(auto i:a)
#define ll long long
using namespace std;

string s;
int main(){
    cin>>s;
    rep(i,0,s.size()){
        s[i]='x';
    }
    puts(s);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) (int i=a;i<n;i++)
#define per(i,a,n,s) (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define _GLIBCXX_DEBUG
// head

int main(){
    int r,g;
    cin >> r>>g;
    cout <<g*2-r<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define mod       1000000007
#define double    long double
#define ull       unsigned long long
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define rev       greater<int>()
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define ps(s)     for(auto i:s){cout<<i<<" ";}
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"This is test"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	ll n,m;cin>>n>>m;
	ll x=__gcd(n,m);
	cout<<(n*m)/x;
}
int32_t main(){
	kehsihba();
	//init();
	ll t=1;
	//cin>>t;
	for(int k=1;k<=t;k++){
		//cout<<"Case "<<k<<": ";
		solve();
		//e;
	}
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <set>
#include <string.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int n;
int p[100000];
int pos[100001];
set<int> s;

int main() {
    cin >> n;
    rep(i,n) {
        cin >> p[i];
        pos[p[i]] = i;
    }
    ll ans = 0;
    for (int i = n; i >= 1; i--) {
        if (i == n) {
            s.insert(pos[i]);
            continue;
        }
        auto x = s.lower_bound(pos[i]);
        if (x == s.end()) {
            x--;
            int l1 = (*x);
            int l2 = -1;
            if (x != s.begin()) {
                x--;
                l2 = (*x);
            }
            ans += (l1-l2) * (ll)(n-pos[i]) * (ll)i;
        } else if (x == s.begin()) {
            int r1 = (*x);
            int r2 = n;
            x++;
            if (x != s.end()) {
                r2 = (*x);
            }
            ans += (pos[i]+1) * (ll)(r2-r1) * (ll)i;
        } else {
            x--;
            int l1 = (*x);
            int l2 = -1;
            if (x != s.begin()) {
                x--;
                l2 = (*x);
            }
            x = s.lower_bound(pos[i]);

            int r1 = (*x);
            int r2 = n;
            x++;
            if (x != s.end()) {
                r2 = (*x);
            }

            ans += (r1-pos[i]) * (ll)(l1-l2) * (ll)i + (pos[i]-l1) * (ll)(r2-r1) * (ll)i;
        }
        s.insert(pos[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        ArrayList<String> strs = new ArrayList<String>(Arrays.asList("SUN","MON","TUE","WED","THU","FRI","SAT"));
        System.out.println(7-strs.indexOf(a));
    }
}



Measured memory_bytes: 21332
#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iomanip>
using namespace std;
int main(){
	int N;
	cin >> N;
	int a[N];
	for(int i=0;i<N;i++){
		cin >> a[i];
	}
	sort(a,a+N);
	cout << a[N-1]-a[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#define ALL(v) v.begin(), v.end()
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;


int main() {

	int n, k, q;
	cin >> n >> k >> q;

	vector<int> nP(n);

	//誰が何回正解したか
	for (int i = 0; i < q; i++)
	{
		int temp;
		cin >> temp;
		nP[temp-1]++;
	}



	int X = k - q;
	for (int i = 0; i < n; i++)
	{
		if (X + nP[i] > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;

		}

	}


}



Measured memory_bytes: 1024
#include<cstdio>
char s[200001];
int main(){
    long long sum=0,cnt=0;
    scanf("%s",s);
    for(int i=0;s[i]!='\0';i++){
        if(s[i]=='W'){
            sum+=i-cnt;
            cnt++;
        }
    }
    printf("%lld",sum);
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
main()
{
	string s;
	long long int i;
	cin >> s;
	for(i=0;i<s.size();i++)
	if(s[i] == '?')
	s[i] = 'D';
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3752
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int cal(int n) {
	int ans = 0;
	while (n != 0) {
		n = n / 10;
		ans++;
	}

	return ans;
}

int main() {
	
	ull n, ans = 11;
	cin >> n;

	

	ull keta = cal(n);
	keta = keta / 2 + keta % 2;
	ull s = 1;

	ll sub = n;
	ll extra = 0;

	if (n == 10000000000) {
		cout << 6 << endl;
		return 0;
	}


	while (sub > 10&&extra==0) {
		extra = sub % 10;
		sub = sub / 10;
	}

	if (extra==0&&sub==10) {
		cout << keta << endl;
		return 0;
	}

	rep(i, 0, keta) {
		s = s * 10;
	}

	
	mrep(i, s, 0) {
		if (n%i == 0) {
			ans = max(cal(n / i),cal(i));
			break;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];

		for (int i = 0; i < values.length ; i++ ) {
			values[i] = i + 1;
		}

		for (int i=0;i<n ;i++ ) {
			String line = sc.next();
			String[] ab = line.split(",");
			int a = Integer.parseInt(ab[0])-1;
			int b = Integer.parseInt(ab[1])-1;

			int temp;
			temp = values[a];
			values[a] = values[b];
			values[b] = temp;	
		}

		for (int i = 0;i<w ; i++) {
			System.out.println(values[i]);			
		}
	}
}

Measured memory_bytes: 26012
import heapq

n,m = map(int,input().split())
a_L = list(map(lambda x:int(x) * -1,input().split()))

heapq.heapify(a_L)
#a_L = list(sorted(a_L))
#max_num = a_L[0]
#a_L.append(max_num)

for val in range(0,m):
    a_min = heapq.heappop(a_L)
    a_min = (-1 * a_min)//2 * -1
    heapq.heappush(a_L,a_min)

print(-sum(a_L))



Measured memory_bytes: 72216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll n,k,m,t,ans,mod=998244353,a[305],b[305],dp[305][305][305];
char s[305];
int main(){
	scanf("%s%d",s+1,&k);
	ans=strlen(s)/100;
	for(int i=1;s[i];i++)
		m+=s[i]=='1';
	for(int i=1;s[i];i++)
		if(s[i]=='0')
			a[++n]=t,t=0;
		else t++;
	a[++n]=t;
	for(int i=1;i<=n;i++)
		b[i]=b[i-1]+a[i];
	k=min(k,m);
	dp[0][0][0]=1;
	for(int i=0;i<n;i++)
		for(int j=b[i];j<=b[n];j++)
			for(int h=0;h<=k;h++){
				if(!dp[i][j][h])continue;
				for(int f=max((ll)j,b[i+1]);f<=b[n];f++)
					if(h+f-j-a[i+1]<=k){
						if(i+1==n and f-j>a[i+1])
							break;
						int z=f-j<=a[i+1]?0:f-j-a[i+1];
						dp[i+1][f][h+z]=(dp[i+1][f][h+z]+dp[i][j][h])%mod;
					}
			}
	for(int i=0;i<=k;i++)
		ans=(ans+dp[n][m][i])%mod;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 31400
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private static final int INF = Integer.MAX_VALUE / 2;

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        int K = sc.nextInt();
        int ans = 0;
        for (int i = 0; i < N; ++i) {
            int x = sc.nextInt();
            ans += 2 * Math.min(x, K - x);
        }
        _out.println(ans);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21844
using System;   
    
class sample9{   
    static void Main(string[] args){   
        int x;
    
        for(int case_number = 1; case_number < 10001; case_number++){ 
                x = int.Parse(Console.ReadLine());
                
                if(x < 1 || x > 10000){
                    Console.WriteLine("xは1以上10000以下の数字で入力してください。");
                    Environment.Exit(0);   
                }
                
                if( x == 0){
                    break;
                }
                Console.WriteLine("Case {0}: {1}",case_number,x);   
        }  
    }   
}  


Measured memory_bytes: 17940
<?php
    $n = trim(fgets(STDIN));

    $ret = 0;
    for ($i=1; $i <= $n; $i++) { 
        for ($j = $i; $j <= $n; $j++) { 
            for ($k= $j; $k <= $n; $k++) { 
                //echo $i.$j.$k. PHP_EOL;
                if ($i != $j && $j != $k && $i != $k) {
                    //echo '6n'.PHP_EOL;
                    $ret = $ret + (gcd3($i, $j, $k) * 6);
                } else {
                    //echo '3n'.PHP_EOL;
                    $ret = $ret + (gcd3($i, $j, $k) * 3);
                }
            }            
        }            
    }

    //echo $ret.PHP_EOL;
    
    for ($l=1; $l <= $n; $l++) { 
        //echo $l.PHP_EOL;
        $ret = $ret - (gcd3($l, $l, $l) * 2);
    }

    echo $ret;
    return;

    function gcd3($a, $b, $c) {
        $ab = gcd($a, $b);
        return gcd($ab, $c);
    }

    function gcd($a, $b) {
        if ($b === 0) {
            return $a;
        }
        return gcd($b, $a % $b);
    }
?>


Measured memory_bytes: 16172
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

struct C{
	double r,x,y;
	C(double r,double x,double y) : r(r) , x(x) , y(y) {}
};

bool cmp_x(const C &a,const C &b){ return a.x == b.x ? a.y < b.y : a.x < b.x ; }
bool cmp_y(const C &a,const C &b){ return a.y == b.y ? a.x < b.x : a.y < b.y ; }

double dist(const C &a,const C &b){
	double x = a.x - b.x;
	double y = a.y - b.y;
	return sqrt( x * x + y * y );
}
int main(){
	int n;
	while(cin >> n && n){
		vector<C> a,b;
		for(int i = 0 ; i < n ; i++){
			double r,x,y;
			cin >> r >> x >> y;
			a.push_back(C(r,x,y));
			b.push_back(C(r,x,y));
		}
		double ans = 1e15;
		sort(a.begin(),a.end(),cmp_x);
		sort(b.begin(),b.end(),cmp_y);
		for(int i = 0 ; i < n ; i++){
			for(int j = i+1 ; j < min(i+12,n) ; j++){
				ans = min(ans,dist(a[i],a[j])-a[i].r-a[j].r);
			}
			for(int j = i+1 ; j < min(i+12,n) ; j++){
				ans = min(ans,dist(b[i],b[j])-b[i].r-b[j].r);
			}
		}
		printf("%.7f%c",ans,10);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

/* add vars here */

ll n,m,qq;

/* add your algorithm here */

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

  // 2次元累積和
  ll table[n+1][n+1];

  rep(i,n+1) {
    rep(j,n+1) {
      table[i][j] = 0;
    }
  }

  rep(i,m) {
    ll l,r;
    cin >> l >> r;
    table[l][r]++;
  }

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      table[i][j] += table[i][j-1];
    }
  }

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      table[i][j] += table[i-1][j];
    }
  }

  ll ans = 0;
  rep(i,qq) {
    ll p,q;
    cin >> p >> q;
    ans = table[q][q] - table[p-1][q] - table[q][p-1] + table[p-1][p-1];
    cout << ans << endl;
  }

}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int a,b,n;
    cin >> a >> b >> n;
    int l,r,ok = 0;
    for(int i = 0; i < n; i++){
        cin >> l >> r;
        if(l < a && a < r)ok = 1;
        if(l < b && b < r)ok = 1;
        if(l == a && r == b)ok = 1;
        if(l > a && r < b)ok = 1;
        if(l < a && r > b)ok = 1;
    }
    cout << ok << endl;
    return 0;
}   


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int K,X;
    cin >> K >> X;
    vector<int> ans;
    for (int i = max(-1000000LL, X-K+1); i <= min(1000000LL, X+K-1); i++) {
        ans.push_back(i);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
 int w,a,b;
  cin >> w >> a >>b;
 
  
  if(b>a+w) cout << b-(a+w) << endl;
  else if(a>b+w) cout << a-(b+w) << endl;
  else cout << 0 << endl;
}

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

using namespace std;


int N,K;
int p[1003];


int main(){
    cin >> N >> K;
    for(int i=0; i<N; i++) cin >> p[i];
    sort(p,p+N);

    int ans=0;
    for(int i=0; i<K; i++) ans+=p[i];

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

Measured memory_bytes: 3600
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, M;
    cin >> N >> M;

    char colors[N];
    string line;
    cin >> line;
    for (int i = 0; i < N; i++) colors[i] = line[i];

    vector<int> a_cnts(N, 0);
    vector<int> b_cnts(N, 0);
    vector<vector<int>> table(N);

    for (int i = 0; i < M; i++) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        table[s].push_back(t);
        table[t].push_back(s);

        if (colors[s] == 'A') a_cnts[t]++;
        else b_cnts[t]++;

        if (colors[t] == 'A') a_cnts[s]++;
        else b_cnts[s]++;
    }

    vector<bool> removed(N, false);

    stack<int> st;
    for (int i = 0; i < N; i++) {
        if (a_cnts[i] == 0 || b_cnts[i] == 0) {
            st.push(i);
            removed[i] = true;
        }
    }

    while (!st.empty()) {
        int node = st.top(); st.pop();
        for (int next : table[node]) {
            if (removed[next]) continue;

            if (colors[node] == 'A') a_cnts[next]--;
            else b_cnts[next]--;

            if (a_cnts[next] == 0 || b_cnts[next] == 0) {
                st.push(next);
                removed[next] = true;
            }
        }
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) if (removed[i]) cnt++;
    if (cnt == N) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 15620
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

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

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

void solve(){
     string s;
     cin >> s;
     int cnt = 1;int maxi = 1;
     int n = s.length();
     vector<int>a(n,1);
     for(int i = 0;i<n-1;i++){
        if(s[i]==s[i+1]&&s[i]=='R') {cnt++; a[i+1] += a[i];a[i] = 0;}
     }
     for(int i = n-1;i>=1;i--){
        if(s[i]==s[i-1]&&s[i]=='L'){a[i-1]+=a[i];a[i] = 0;}
     }

     for(int i = 0;i<n-1;i++){
        if(a[i]){
            int sum = a[i]+a[i+1];
            maxi = max(a[i],a[i+1]);
            if(sum%2){
                if(a[i]>a[i+1]){a[i] = sum/2+1;a[i+1] = sum/2;}
                else {a[i+1] = sum/2+1;a[i] = sum/2;}
                if(maxi%2==0) swap(a[i],a[i+1]);
            }
            else{
                a[i] = sum/2;a[i+1] = sum/2;
            }
            i++;
        }
     }

     for(int i = 0;i<n;i++) cout << a[i] <<' ';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 3884
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int count=0;
    string s,t;
    cin>>s>>t;
    for(int i=0;i<3;i++){
        if(s.at(i)==t.at(i)){
            count++;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
A, B = map(int,input().split())
A_factors=prime_factorize(A)
B_factors=prime_factorize(B)
B_factors = set(B_factors)
A_factors = set(A_factors)
C = A_factors & B_factors
ans = len(C) + 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;

int l;
int n;
int x, w;

int main(){
	int i;
	int mo = 0;
	
	cin >> l >> n;
	for( i = 0; i < n; i++ ){
		cin >> x >> w;
		mo += x * w;
	}
	if( mo == 0 ){ cout << 0 << endl; return 0; }
	
	cout << 1 << endl;
	int pos = (mo < 0) ? 1 : -1;
	cout << pos << " " << abs(mo) << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#define llint long long

using namespace std;

int n;
llint a[200005];
llint ans[200005];
vector<llint> vec;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	for(int i = n; i >= 1; i--){
		llint sum = 0;
		for(int j = 2*i; j <= n; j+=i) sum += ans[j];
		sum %= 2;
		ans[i] = (sum + a[i]) % 2;
		if(ans[i]) vec.push_back(i);
	}
	cout << vec.size() << endl;
	for(int i = 0; i < vec.size(); i++){
		cout << vec[i];
		if(i < (int)vec.size()-1) cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 5108
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PI 3.1415926535897932384626433832795
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct chash {
    int operator()(int x) const { return x ^ RANDOM; }
};
string toString(long long x)
{
stringstream ss;
ss << x;
string str = ss.str();
return str;
}
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}
int main()
{
    IO;
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i = 0;i < n;i++)
        cin >> arr[i];
    stack<int> ans;
    while(!arr.empty())
    {
        int curIdx = -1;
        int curEl = -1;
        for(int i = 0;i < arr.size();i++)
        {
            if(arr[i] == i+1)
            {
                if(arr[i] > curEl)
                {
                    curEl = arr[i];
                    curIdx = i;
                }
            }
        }
        if(curIdx == -1)
        {
            cout << "-1";
            return 0;
        }
        ans.push(curEl);
        arr.erase(arr.begin() + curIdx);
    }
    while(ans.size())
        cout << ans.top() << endl,ans.pop();
    return 0;
}


Measured memory_bytes: 256
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.numeric;

alias Pair = Tuple!(int, "to", int, "cost");

int n, q, k;
Pair[][] adj;

void main() {
    scan(n);
    adj = new Pair[][](n, 0);

    int ai, bi, ci;

    foreach (i ; 0 .. n - 1) {
        scan(ai, bi, ci);
        ai--; bi--;
        adj[ai] ~= Pair(bi, ci);
        adj[bi] ~= Pair(ai, ci);
    }

    scan(q, k);
    k--;

    auto d = new long[](n);

    void dfs(int u, int p, long c) {
        d[u] = c;

        foreach (v ; adj[u]) {
            if (v.to == p) continue;
            dfs(v.to, u, c + v.cost);
        }
    }

    dfs(k, -1, 0);

    int xi, yi;

    while (q--) {
        scan(xi, yi);
        xi--; yi--;

        long ans = d[xi] + d[yi];
        writeln(ans);
    }
}

long lcm(long a, long b) {
    return a / gcd(a, b) * b;
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 33660
import sys

sys.setrecursionlimit(10**9)

def dfs(now,prev,count):
    # 今いる頂点から行ける頂点を順に next に入れてループ
    count+=1
    for next in g[now]:
        if count<=2:
            if next != prev:
                if next== n-1:
                    if count==2:
                        print('POSSIBLE')
                        exit()
                    else:
                        break
                dfs(next,now,count)
 
n, m = map(int, input().split())
g = [[] * n for i in range(n)]
for i in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
dfs(0,-1,0)
print('IMPOSSIBLE')




    





Measured memory_bytes: 38320
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
vector<int> es[114514];

int Dfs(int v) {
  vector<int> vs;
  for (int u : es[v]) {
    vs.eb(Dfs(u));
  }
  sort(all(vs), greater<int>());

  int ad = 1;
  int ret = 0;
  for (int v : vs) {
    MX(ret, v+ad);
    ++ad;
  }
  //printf("%d: %d\n", v+1, ret);
  return ret;
}

int main() {
  scanf("%d", &N);
  reps(i, 1, N) {
    int a;
    scanf("%d", &a);
    --a;
    es[a].eb(i);
  }

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


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

int main() {
  int n;
  string input;

  while (cin >> n, n) {
    int prev_h = 0;
    int curr_l = 0, curr_r = 0;
    int ans = 0;

    rep (i, n) {
      cin >> input;

      // cout << input << endl;

      if (input == "lu") curr_l++;
      if (input == "ld") curr_l--;
      if (input == "ru") curr_r++;
      if (input == "rd") curr_r--;

      // cout << curr_l << "-" << curr_r << endl;

      if (curr_l == curr_r && curr_l != prev_h) {
        // cout << "count" << endl;
        ans++;
        prev_h = curr_l;
      }
    }

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

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

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define eps 1e-9
#define fast_cin ios_base::sync_with_stdio(false)

const int MOD = 1e9+7;

typedef long long ll;
typedef pair<int,int> pii;

int main()
{
	//freopen("Task.in","r",stdin);freopen("Task.out","w",stdout);
	fast_cin;
	ll a,b,c;
	cin >> a >> b >> c;
	ll fa=a,fb=b,fc=c;
	int cnt = 0;
	int flag = 0;
	{
		while((a%2==0)&&(b%2==0)&&(c%2==0)){
			a = fb/2 + fc/2 - fa;
			b = fc/2 + fa/2 - fb;
			c = fb/2 + fa/2 - fc;
			
			fa = a;
			fb = b;
			fc = c;

			cnt++;

			if(cnt > 1e5+7){
				flag = 1;
				break;
			}
		}

	}
	if(flag) cout << -1 << endl;
	else cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    A_ = []
    for a_ in A:
        A_ += [[a__, False] for a__ in a_]
    for b_ in b:
        for a__ in A_:
            if a__[0] == b_:
                a__[1] = True
    if (A_[0][1] and ((A_[1][1] and A_[2][1]) or \
                        (A_[3][1] and A_[6][1]) or \
                        (A_[4][1] and A_[8][1]))) or \
            (A_[1][1] and A_[4][1] and A_[7][1]) or \
            (A_[2][1] and A_[5][1] and A_[8][1]) or \
            (A_[3][1] and A_[4][1] and A_[5][1]) or \
            (A_[6][1] and A_[7][1] and A_[8][1]) or \
            (A_[2][1] and A_[4][1] and A_[6][1]):
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [[int(next(tokens)) for _ in range(3)] for _ in range(3)]  # type: "List[List[int]]"
    N = int(next(tokens))  # type: int
    b = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(A, N, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9260
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, A[int(2e5 + 5)];
int check[int(1e6 + 5)];

bool Solve(int num){
  if (num == 1){
    if (check[1] > 1) return true;
    else return false;
  }

  if (check[1] > 0) return true;
  if (check[num] > 1) return true;
  for (int i = 2; i * i <= num; i++){
    if (num % i != 0) continue;
    int now = num / i;
    if (check[i] || check[now]) return true;
  }
  return false;
}

int main(){
  scanf("%d", &N);
  for (int i = 0; i < N; i++){
    scanf("%d", A + i);
    check[A[i]]++;
  }

  int ans = N;
  for (int i = 0; i < N; i++){
    if (Solve(A[i])) ans--;
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 8196
#include <stdio.h>
#include <stdlib.h>

int Cmp(const void *a, const void *b){
  return *(int *)a - *(int *)b;
}

void Do(int n){
  int i, max, N;
  int a[n];
  double d, min;
  max = 0;
  for(i = 0;i < n;i++){
    scanf("%d", &a[i]);
    if(max < a[i]) max = a[i];
  }
  d = (double) max / 2;
  qsort(a, n, sizeof(int), Cmp);
  min = N = 1e9;
  for(i = 0;i < n;i++){
    if(max == a[i]) continue;
    if(min > abs(d - a[i])){
      min = abs(d - a[i]);
      N = i;
    }
  }
  printf("%d %d\n", max, a[N]);
}

int main(void){
  int n;
  scanf("%d", &n);
  Do(n);
  return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#pragma comment(linker, "/STACK: 20000000005")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

const ll N = 1e5 + 5, INF = 1e18;

ll ans = INF;
vector < ll > g[N];

ll n;
ll a[N];
ll s[N];
ll dp[N], DP[N];
ll ANS;

ll D[N];


void dfs (ll k, ll p){
    s[k] = a[k];
    ll sum = 0, ma = 0, t = 0;
    for (ll i = 0; i < (ll)g[k].size(); i++){
        ll u = g[k][i];
        if (u == p)
            continue;
        dfs (u, k);
    }
    for (ll i = 0; i < (ll)g[k].size(); i++){
        ll u = g[k][i];
        if (u == p)
            continue;
        s[k] += s[u];
        DP[k] += DP[u];
        ll x = s[u] + dp[u];
        ANS += s[u];
        D[k] += s[u] + D[u];
        if (x > ma){
            t = u;
            ma = x;
        }
        sum += x;
    }
    sum = 0;
    for (ll i = 0; i < (ll)g[k].size(); i++){
        ll u = g[k][i];
        if (u == p)
            continue;
        sum += s[u];
        if (u == t)
            sum += dp[u];
        else
            sum += D[u];
    }
    if (ma * 2 <= sum){
        dp[k] = sum % 2;
    }
    else {
        dp[k] = ma * 2 - sum;
    }
}



main()
{
    //freopen ("in.in", "r", stdin);freopen ("out.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin >> n;
    string S;
    cin >> S;
    for (ll i = 0; i < n; i++)
        a[i + 1] = S[i] - '0';
    for (ll i = 1; i < n; i++){
        ll u, v;
        cin >> u >> v;
        g[u].pb (v);
        g[v].pb (u);
    }
    for (ll i = 1; i <= n; i++){
        for (ll j = 1; j <= n; j++){
            s[j] = 0;
            dp[j] = 0;
            DP[j] = 0;
            D[j] = 0;
        }
        ANS = 0;
        dfs (i, 0);
        if (dp[i] == 0)
            ans = min (ans, ANS / 2);
    }
    if (ans == INF)
        ans = -1;
    cout << ans << endl;
    return 0;
}


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

int main()
{
  int64_t N, M, k, s, ans = 0;
  cin >> N >> M;
  vector<vector<int>> A(M);
  for (int i = 0; i < M; i++)
  {
    cin >> k;
    for (int j = 0; j < k; j++)
    {
      cin >> s;
      s--;
      A.at(i).push_back(s);
    }
  }
  vector<int> P(M);
  for (int i = 0; i < M; i++)
  {
    cin >> P.at(i);
  }
  for (int bit = 0; bit < (1 << N); bit++)
  {
    bool on = true;
    for (int i = 0; i < M; i++)
    {
      int cnt = 0;
      for (int j = 0; j < A.at(i).size(); j++)
      {
        if (bit & (1 << A.at(i).at(j)))
          cnt++;
      }
      if (cnt % 2 != P.at(i))
      {
        on = false;
        break;
      }
    }
    if (on)
      ans++;
  }
  cout << ans << endl;
}

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

using namespace std;

typedef pair<int,int> P;
typedef long long ll; 

#define int ll

const ll mod = 1e9 + 7;


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

	int ans = 0;
	for(int a=1;a<=k;a++){
		for(int b=1;b<=k;b++){
			for(int c=1;c<=k;c++){
				int g = __gcd(a,__gcd(b,c));
				ans += g;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

int main() {
	int a, b, c; cin >> a >> b >> c;
	if (a + b == c || b + c == a || a + c == b)cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

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

int main() {
  int a, b;
  char op;
  while(1){
    cin >> a >> op >> b;
    if(op == '+')
      cout << a + b;
    else if(op == '-')
      cout << a - b;
    else if(op == '*')
      cout << a * b;
    else if(op == '/')
      cout << a / b;
    else if(op == '?'){
      break;
    }
    cout <<  endl;
    }
    return 0;
  }


Measured memory_bytes: 3112
def f():
    N = int(input())
    if N == 0:
        return -1
    J = []
    for i in range(N):
        x, y = map(int, input().split())
        J.append((y, x))

    C = [[False for j in range(21)] for i in range(21)]
    C[10][10] = True
    y, x = 10, 10
    dic = {'N':(1, 0), 'W':(0, -1), 'S':(-1, 0), 'E':(0, 1)}

    M = int(input())
    for i in range(M):
        direct, value = input().split()
        value = int(value)
        dy, dx = dic[direct]
        for j in range(value):
            y += dy
            x += dx
            C[y][x] = True

    for j in J:
        if not C[j[0]][j[1]]:
            return 0

    return 1

def main():
    while True:
        ret = f()
        if ret == -1:
            return
        elif ret == 1:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()





Measured memory_bytes: 5632
import numpy

x,n = map(int,input().split())
try:
    p = list(map(int,input().split()))
except EOFError:
    p =[]

a = numpy.abs(list(map(lambda z: z-x,p))).tolist()
if 0 not in a:
    print(x)
else:
    i = 1
    while i <= n:
        if a.count(i) == 2:
            i += 1
            continue
        elif a.count(i) == 1:
            if x+i not in p:
                print(x+i)
                break
        if x > 0:
            print(x-i)
        else:
            print(x+i)
        break

Measured memory_bytes: 27136