akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;cin>>n;
	set<ll> st;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			ll t=n;
			while(t%i==0){
				if(t/i%i==1) st.insert(i);
				t/=i;
			}
		}
	}
	for(ll i=1;i*i<=n-1;i++){
		if((n-1)%i==0){
			st.insert(i);
			st.insert((n-1)/i);
		} 
	}
	st.erase(1);
  	st.insert(n);
	cout<<st.size()<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

void solve(ll n, ll m, vector<ll> a) {
  for (ll &i: a) --i;
  vector<int> from(n-1), to(n-1), diff(n-1);
  vector<vector<int>> pos_from(m);
  vector<vector<int>> pos_to(m);
  REP(i,n-1) {
    from[i] = a[i];
    to[i] = a[i + 1];
    diff[i] = to[i] - from[i];
    if (diff[i] < 0) diff[i] += m;
    pos_from[a[i]].push_back(i);
    pos_to[a[i + 1]].push_back(i);
  }
  ll sum = 0;
  int cnt = 0;
  REP(i,n-1) {
    if (from[i] <= to[i]) sum += to[i] - from[i];
    else { sum += to[i]; ++cnt; }
  }
  ll res = sum + cnt;

  REP(i,m-1) {
    for (int j: pos_to[i]) {
      --cnt;
      sum += diff[j];
    }
    for (int j: pos_from[i]) {
      ++cnt;
    }
    sum -= cnt;
    chmin(res, sum + cnt);
  }
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll n;
	ll m;
	scanf("%lld", &n);
	vector<ll> a(n-1+1);
	scanf("%lld", &m);
	for (int i = 0 ; i <= n-1 ; i++) {
	  scanf("%lld", &a[i]);
	}
	solve(n, m, a);
	return 0;
}


Measured memory_bytes: 12416
n = int(input())
a = []
b = []
 
for i in range(n):
    s = int(input())
    a.append(s)
    b.append(s)
    
b.sort()
b.reverse()
 
if b[0] == b[1]:
    for i in range(n):
        print(b[0])
else:
    for i in range(n):
        if a[i] == b[0]:
            print(b[1])
        else:
            print(b[0])

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define int long long

typedef pair<int, int> ii;

const int N = 2e5 + 5;

int n, dp[105][N], w[N], v[N], W;

signed main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n >> W;
    for(int i = 1; i <= n; i++)
        cin >> w[i] >> v[i];
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= W; j++)
            dp[i][j] = -LLONG_MAX;
    }
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= W; j++) {
            if(j - w[i] >= 0)
                dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i][j]);
            dp[i][j] = max(dp[i - 1][j], dp[i][j]);
        }
    }
    int mx = 0;
    for(int j = 0; j <= W; j++)
        mx = max(mx, dp[n][j]);
    cout << mx;
}


Measured memory_bytes: 160000
package main

import "fmt"
// import "math"

func main(){
	var A, B int

	fmt.Scan(&A, &B)
	flag := 0
	for i := 1 ; i <= 1009 ; i++ {
		if  int(float64(i)*0.08) == A && int(float64(i)*0.1) == B {
			fmt.Println(i)
			flag = 1
			break
		}
	}
	if flag == 0 {
		fmt.Println(-1)
	}
}

Measured memory_bytes: 512
from sys import stdin
import math

n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]

d = {}
for aa in a:
    if aa in d.keys():
        d[aa] += 1
    else:
        d[aa] = 1

result = 'YES'
for key, value in d.items():
    if value > 1:
        result = 'NO'

print(result)

Measured memory_bytes: 33616
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a * b, c * d) << endl;
}



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author GYSHGX868
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    OutputWriter out = new OutputWriter(outputStream);
    TaskA solver = new TaskA();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskA {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
      String s = in.nextString();
      for (int i = 0; i < s.length(); i++) {
        if (s.charAt(i) == ',') {
          out.print(' ');
        } else {
          out.print(s.charAt(i));
        }
      }
      out.printLine();
    }

  }

  static class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
      writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void printLine() {
      writer.println();
    }

    public void print(char i) {
      writer.print(i);
    }

    public void close() {
      writer.close();
    }

  }

  static class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int read() {
      if (numChars == -1) {
        throw new InputMismatchException();
      }
      if (curChar >= numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (numChars <= 0) {
          return -1;
        }
      }
      return buf[curChar++];
    }

    public String nextString() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      StringBuilder res = new StringBuilder();
      do {
        if (Character.isValidCodePoint(c)) {
          res.appendCodePoint(c);
        }
        c = read();
      } while (!isSpaceChar(c));
      return res.toString();
    }

    public boolean isSpaceChar(int c) {
      if (filter != null) {
        return filter.isSpaceChar(c);
      }
      return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
      boolean isSpaceChar(int ch);

    }

  }
}



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

int main() {
    int n, m;
    while(cin >> n >> m, n) {
        vector <int> a(n), b(m);
        rep (i, n) cin >> a[i];
        rep (i, m) cin >> b[i];
        int now = 1;
        rep (i, m) {
            now += b[i];
            if (now >= n) goto va;
            now += a[now - 1];
            if (now >= n) goto va;
            if (false) {
                va:
                cout << i + 1 << endl;
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3132
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			//Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int n = vs[0];
			int k = vs[1];
			int ans = 1;
			int x = n / k;
			while (x > 0) {
				ans++;
				x /= k;
			}
			Console.WriteLine(ans);


			//Console.Out.Flush();
		}
	}
}


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

using namespace std;

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

    int dp[N][3] = { 0 };
    cin >> dp[0][0] >> dp[0][1] >> dp[0][2];

    int input;
    for (int row = 1; row < N; row++)
    {
        for (int column = 0; column < 3; column++)
        {
            cin >> input;
            if (column == 0)
            {
                dp[row][column] = input + max(dp[row - 1][1], dp[row - 1][2]);
            } else if (column == 1)
            {
                dp[row][column] = input + max(dp[row - 1][0], dp[row - 1][2]);
            } else {
                dp[row][column] = input + max(dp[row - 1][0], dp[row - 1][1]);
            }
        }
    }

    cout << max(max(dp[N - 1][0], dp[N - 1][1]), dp[N - 1][2]);
}


Measured memory_bytes: 1408
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
j=n
for i in range(n):
    if a[i]>=0:
        j=i
        break
a=list(map(abs,a))
a.sort()
if j%2==0:
    print(sum(a))
else:
    print(sum(a)-2*a[0])


Measured memory_bytes: 14284
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        
        String strStdIn = in.readLine();
        int n = Integer.parseInt(strStdIn);
        
        strStdIn = in.readLine();
        
        ArrayList<String[]> list = new ArrayList<String[]>();
        
        while(strStdIn!=null){ 
            String[] data = strStdIn.split(" ");
            list.add(data);

            strStdIn = in.readLine();
        }
        
        int sum = 0;
        int pre = -10;
        for(int i = 0; i < n; i++) {
            int eat = Integer.parseInt(list.get(0)[i]);
            if (eat-1 == pre) {
                sum += Integer.parseInt(list.get(2)[pre-1]);
            }
            pre = eat;
            sum += Integer.parseInt(list.get(1)[eat-1]);
        }
        
        System.out.println(sum);
    }
}

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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    bool ok=true;
    if(n%2==0){
        for(int i=0;i<s.size()/2;i++){
            if(s[i]!=s[s.size()/2+i])ok=false;
        }
        if(ok){cout << "Yes" << endl;}
        else{cout << "No" << endl;}
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 main()
{
    int n;
    bool ok  = true;
    cin>>n;
    for(int i =0; i<n; i++){
        int x;
        cin>>x;
        if(x % 2 == 0) {
            if(x % 5 == 0)continue;
            if(x % 3 == 0)  continue;
            ok = false;
        }
    }
    if(ok)cout<<"APPROVED\n";
    else cout<<"DENIED\n";

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	cin >> a;
	if (a == 3 || a == 5 || a == 7)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

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

int main(){

    int h,w;
    cin >>h>>w;

    vector<string> s(h);

    rep(i,h) cin >> s[i];


    rep(i,h){
        rep(j,w){
            cout << s[i][j];
        }
        cout << endl;
        rep(j,w){
            cout << s[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;

int main() {
	int N;
	cin >> N;
	
	for (int n = 1; n <= N; n++) {
      int cnt = 0;
		for (int x = 1; x < 100; x++) {
			if (x * x > n) break;
			for (int y = 1; y < 100; y++) {
				if (x * x + y * y > n) break;
				for (int z = 1; z < 100; z++) {
					if (x * x + y * y + z * z + x * y + y * z + z * x > n) break;
					if (x * x + y * y + z * z + x * y + y * z + z * x == n) cnt++;
				}
			}
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 3568
#include <iostream>
using namespace std;
 
#define MAX_W 100
#define MAX_H 100
char farm[MAX_W][MAX_H];
int W, H;
const int direction[4][2] = {
	{ -1, 0 },
	{ 1, 0 },
	{ 0, -1 },
	{ 0, 1 },
};
 
void dfs(const int& x, const int& y, const char tree)
{
	farm[x][y] = 'x';
	for (int i = 0; i < 4; ++i)
	{
		int nx = x + direction[i][0];
		int ny = y + direction[i][1];
		if (nx >= 0 && nx < W && ny >= 0 && ny < H && farm[nx][ny] == tree)
		{
			dfs(nx, ny, tree);
		}
	}
}

int main()
{
 
	while (cin >> H >> W&&W > 0)
	{
		int res = 0;
		int x, y;
		for (y = 0; y < H; ++y)
		{
			for (x = 0; x < W; ++x)
			{
				cin >> farm[x][y];
			}
		}
 
		for (y = 0; y < H; ++y)
		{
			for (x = 0; x < W; ++x)
			{
				if (farm[x][y] != 'x')
				{
					dfs(x, y, farm[x][y]);
					++res;
				}
			}
		}
		cout << res << endl;
	}
 
	return 0;
}



Measured memory_bytes: 3872
#include <iostream>
#include <stack>
#include <string>

using namespace std;

int main() {

	stack<int> S;
	string s;
	while (cin >> s) {
		if (s[0] == '+') {
			int a = S.top();
			S.pop();
			int b = S.top();
			S.pop();
			S.push(a + b);
		}
		else if (s[0] == '-') {
			int a = S.top();
			S.pop();
			int b = S.top();
			S.pop();
			S.push(b - a);
		}
		else if (s[0] == '*') {
			int a = S.top();
			S.pop();
			int b = S.top();
			S.pop();
			S.push(a * b);
		}
		else {
			S.push(stoi(s));
		}
	}
	cout << S.top() << endl;
}


Measured memory_bytes: 3172
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  int n, i, j;
  int C[VMAX+1];
 unsigned short *A,*B;
  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

for(i=0;i<=VMAX;i++) {
  C[i]=0;
}
  for (i = 0; i < n; i++) {
    scanf("%hd",&A[i+1]);
    C[A[i+1]]++;
  }

  for(i=1;i<=VMAX;i++) C[i]=C[i]+C[i-1];

  for(j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n;i++){
    if(i==n)  printf("%d\n",B[i]);
    else printf("%d ",B[i]);
  }
  return 0;
}


Measured memory_bytes: 9564
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
 
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000001;
 
using namespace std;
 
 
 
int main(void) {
	int n, m;
	int p = 1;
	cin >> n;
	vector<int>d(n + 1);
	FOR(i, 1, n) {
		cin >> d[i];
	}
	cin >> m;
	vector<int>t(m + 1);
	FOR(i, 1, m) {
		cin >> t[i];
	}
	sort(d.begin(), d.end());
	sort(t.begin(), t.end());
	FOR(i, 1, m) {
		FOR(u, p, n) {
			if (t[i] == d[u]) {
				p = u + 1;
				if (i == m) {
					cout << "YES" << endl;
					goto warp;
				}
				break;
			}
			if (u == n) {
				cout << "NO" << endl;
				goto warp;
			}
		}
	}
	warp:
	return 0;
}


Measured memory_bytes: 1792
A,B=gets.split.map(&:to_i)
#A,B=10**12, 10**12-100

g = A.gcd(B)
ans = 1
(2..(g**0.5).to_i).each do |i|
  if g%i == 0
    ans += 1
  end
  
  while g%i == 0
    g /= i
  end
end
if g != 1
  ans += 1
end
puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<complex>
#include<cstdio>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef complex<double> P;

int main(){
	int n;
	while(cin>>n,n){
		P p[n],dir=P(0,1);
		rep(i,n)cin>>p[i].real()>>p[i].imag();
		
		int nuse=0,used[n]; rep(i,n)used[i]=0;
		double ans=0; P now=P(0,0);
		
		while(nuse<n){
			double ang=1e9,tang; int mini;
			rep(i,n)if(!used[i]){
				tang=arg(dir/(p[i]-now));
				if(tang<0)tang+=atan(1)*8;
				if(ang>tang||abs(ang-tang)<1e-8&&abs(p[mini]-now)>abs(p[i]-now))mini=i,ang=tang;
			}
			dir=p[mini]-now;
			ans+=abs(dir);
			now=p[mini];
			used[mini]=1;nuse++;
		}
		printf("%.1f\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
#!python3

import sys
sys.setrecursionlimit(10 ** 6)

import numpy as np


INF = 10 ** 10

# input
N = int(input())
A = list(map(int, input().split()))
uv = [list(map(int, input().split())) for _ in range(N - 1)]

# link
link = [[] for _ in range(N + 1)]
for u, v in uv:
    link[u].append(v)
    link[v].append(u)


def dfs(l, dp, pre, v):
    # LIS
    idx = np.searchsorted(dp, A[v - 1])
    l[v] = max(idx, l[pre])
    bef = dp[idx]
    dp[idx] = A[v - 1]
    
    for x in link[v]:
        if x != pre:
            dfs(l, dp, v, x)

    dp[idx] = bef


def main():
    l = [0] * (N + 1)
    dp = np.full(N + 1, INF)
    dp[0] = 0
    dfs(l, dp, 0, 1)
    for ans in l[1:]:
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 269244
N, X = map(int,input().split())
L = list(map(int,input().split()))
i = 1
D = [0]
while i <= N and D[i-1] <= X:
  D += [D[i-1] + L[i-1]]
  i += 1
if D[i-1] > X:
  i -= 1
print(i)

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

int main()
{
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	map<ll,ll> s;
	ll a[n];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		s[a[i]]++;
	}
	sort(a,a+n);
		ll mx=a[n-1];
		for(ll i=0;i<n;i++)
		{
			if(s[a[i]]!=0)
			{
				if(s[a[i]]>1)
				s[a[i]]=0;
				for(ll j=2;a[i]*j<=mx;j++)
				{
					if(s.find(a[i]*j)!=s.end())
					s[a[i]*j]=0;
				}
			}
		}
		int ans=0;
		map<ll,ll>::iterator it;
		for(it=s.begin();it!=s.end();it++)
		{
			if(it->second==1)
			ans++;
		}
		cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 17660
//  Created by conan1024hao on 2019/11/26.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ！llか？？
    cin.tie(0);
    ios::sync_with_stdio(false);
    //------------------------------
    ll n,m;cin>>n>>m;
    //cout<<314*1592<<endl;
    //cout<<314*2+1592*2<<" "<<3808<<endl;
    ll ans=n*m;
    
    if(n==1&&m==1)
        ans=1;
    else if(n==1){
        ans-=2;
        //ans-=(n+m);
    }
    else if(m==1){
        ans-=2;
        //ans-=(n+m);
    }
    else{
        ans+=4;
        ans-=2*(n+m);
    }
        
    cout<<ans<<endl;
        
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------



Measured memory_bytes: 256
n, y = map(int, input().split())

# print(n, y)

for i in range(n+1):
    for j in range(n - i + 1):
        k = n - j - i
        total = i * 10000 + j * 5000 + k * 1000
        if total == y:
            print(i, j, k)
            exit()

print(-1, -1, -1)

Measured memory_bytes: 3060
n = int(input())
s = input()
q = int(input())
import sys
input = sys.stdin.readline
Q = [list(input().split()) for i in range(q)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
  
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
  
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

import string
DD = [chr(i) for i in range(ord("a"), ord("z")+1)]
D = {}
for i in range(len(DD)):
    D[DD[i]] = i
S = []
for i in range(n):
    S.append(D[s[i]])
B = [Bit(n) for i in range(26)]
for i in range(26):
    for j in range(n):
        if S[j] == i:
            B[i].add(j+1, 1)  # 合計n回

for i in range(q):
    qu = int(Q[i][0])
    if qu == 2:
        l = int(Q[i][1])
        r = int(Q[i][2])
        ans = 0
        for j in range(26):
            p = min(1, B[j].sum(r) - B[j].sum(l-1))
            # print(j,p)
            ans += p
        print(ans)
    elif qu == 1:
        iq = int(Q[i][1])-1
        c = D[Q[i][2]]
        pc = S[iq]
        B[pc].add(iq+1, -1)
        B[c].add(iq+1, 1)
        S[iq] = c


Measured memory_bytes: 152276
#include <string>
#include<queue>
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<map>
#include<tuple>

using namespace std;

typedef pair<int,int> pii;
typedef tuple<int,int,int> t3;
typedef tuple<int,int,int,int> t4;

const int MX = 1<<18;

struct Tree{
	pii t[MX*2];
	pii find(int s, int e){
		s += MX, e += MX;
		pii r = pii(1e9, -1);
		while(s <= e){
			if( s&1 ) r = min(r, t[s++]);
			if(~e&1 ) r = min(r, t[e--]);
			s /= 2, e /= 2;
		}
		return r;
	}
	void update(int x, int v){
		x += MX; t[x] = pii(v, x-MX);
		while(x > 1) x /= 2, t[x] = min(t[x*2], t[x*2+1]);
	}
} t[2];

int D[MX];

int main()
{
	int N, s = 1;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) t[0].update(i, 1e9), t[1].update(i, 1e9);
	for(int i = 1; i <= N; i++){
		scanf("%d", D+i);
		t[i%2].update(i, D[i]);
	}
	set<t4> X;
	pii p = t[1].find(1, N);
	X.insert(t4(p.first, p.second, 1, N));
	for(int i = 1; i*2 <= N; i++){
		int a, b, c, d; tie(a, b, c, d) = *X.begin();
		X.erase(X.begin());
		printf("%d ", a);
		pii p = t[~b&1].find(b+1, d);
		printf("%d ", p.first);
		auto ins = [&](int s, int e){
			if( s > e ) return;
			pii p = t[s&1].find(s, e);
			X.insert(t4(p.first, p.second, s, e));
		};
		ins(c, b-1);
		ins(b+1, p.second-1);
		ins(p.second+1, d);
	}
}


Measured memory_bytes: 12288
#include <stdio.h>


int i_dp[1000000];
int o_dp[1000000];
char str[1000001];

int main(void)
{
	int n, m;
	int ans;
	
	while (1){
		scanf("%d", &n);
		if (n == 0) break;
		scanf("%d", &m);
		scanf("%s", str);
		
		if (str[0] == 'I'){
			i_dp[0] = 1;
		}
		else {
			i_dp[0] = 0;
		}
		if (str[1] == 'I'){
			i_dp[1] = 1;
		}
		else {
			i_dp[1] = 0;
		}
		for (int i = 2; i < m; i++){
			if (str[i] == 'I'){
				i_dp[i] = i_dp[i - 2] + 1;
			}
			else {
				i_dp[i] = 0;
			}
		}
		
		o_dp[0] = str[0] == 'O' ? 1 : 0;
		o_dp[1] = str[1] == 'O' ? 1 : 0;
		for (int i = 2; i < m; i++){
			o_dp[i] = str[i] == 'O' ? o_dp[i - 2] + 1 : 0;
		}
		
		ans = 0;
		for (int i = 2; i < m; i++){
			if (i_dp[i] >= n + 1 && o_dp[i - 1] >= n){
				ans++;
			}
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

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

int main() {
  string t;
  cin>>t;
  rep(i,t.size()){
    if(t[i]=='?')t[i]='D';
  }
  cout<<t<<endl;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  
  if ( (a+b)%2 == 0){
    cout << (a+b)/2 << endl;
  }
  else{
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int start, finish;
    int num;
    int i, j;
    
    scanf("%d", &num);
    for (i = 0; i < num; i++) {
        scanf("%d %d", &start, &finish);
        if (start < finish) {
            for (j = start; j <= finish; j++) {
                printf("%d", j);
                if (j != finish) printf(" ");
                else printf("\n");
            }
        }
        else if (start <= 5 && finish <= 5){
            for (j = start; j >= finish; j--) {
                printf("%d", j);
                if (j != finish) printf(" ");
                else printf("\n");
            }
        }
        else if (6 <= start && finish <= 5){
            for (j = start; j <= 9; j++) {
                printf("%d ", j);
            }
            for (j = 5; j >= finish; j--) {
                printf("%d", j);
                if (j != finish) printf(" ");
                else printf("\n");
            }
        }
        else if (5 <= start && 5 <= finish){
            for (j = start; j <= 9; j++) {
                printf("%d ", j);
            }
            for (j = 5; j >= 0; j--) {
                printf("%d ", j);
            }
            for (j = 1; j <= finish; j++) {
                printf("%d", j);
                if (j != finish) printf(" ");
                else printf("\n");
            }
        }
        else break;
    }
    return 0;
}

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

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define pb push_back
#define pii pair <int, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ld long double
#define int long long

void SOLVE(){
    int x;
    cin >> x;
    int ans = 0;
    int pr = 1;
    while (x){
        ans += pr;
        x /= 2;
        pr *= 2;
    }
    cout << ans << '\n';
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int Q = 1;
    //cin >> Q;
    while (Q--){
        SOLVE();
    }

    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);

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

  VI col(8,-1);
  REP(i,k){
    int r, c;
    cin>> r >> c;
    col[c] = r;
  }

  VI a = {0,1,2,3,4,5,6,7};
  VI ans;
  do {
    bool ok=true;
    set<int> st;
    REP(i,8){
      if(col[i] != -1 && col[i] != a[i])ok=false;
    }
    if(!ok)continue;

    ok=true;

    REP(i,8){
      FOR(j,i+1,8){
        if(abs(i - j) == abs(a[i] - a[j]))ok=false;
      }
    }

    if(ok){
      ans = a;
      break;
    }

  }while(next_permutation(ALL(a)));

  REP(i,8){
    REP(j,8){
      if(ans[j]==i)cout << "Q";
      else cout << ".";
    }
    cout << endl;
  }
}



Measured memory_bytes: 3124
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static List<Edge>[] G;
	static boolean[] used;


	static class TaskX {
		@SuppressWarnings("unchecked")
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int V = in.nextInt(), E = in.nextInt();
			G = Stream.generate(ArrayList::new).limit(V).toArray(List[]::new);
			for (int i = 0; i < E; i++) {
				int u = in.nextInt();
				int v = in.nextInt();
				int c = in.nextInt();
				G[u].add(new Edge(v, c, G[v].size()));
				G[v].add(new Edge(u, 0, G[u].size() - 1));
			}

			int flow = 0;
			while (true) {
				used = new boolean[V];
				int f = dfs(0, V - 1, INF);
				if (f == 0) break;
				flow += f;
			}
			out.println(flow);

		}

		static int dfs(int u, int v, int f) {
			if (u == v) return f;
			used[u] = true;
			for (int i = 0; i < G[u].size(); i++) {
				Edge e = G[u].get(i);
				if (!used[e.to] && e.cap > 0) {
					int d = dfs(e.to, v, Math.min(f, e.cap));
					if (d > 0) {
						e.cap -= d;
						G[e.to].get(e.rev).cap += d;
						return d;
					}
				}
			}
			return 0;
		}

	}
	static class Edge {
		int to, cap, rev;
		public Edge(int to, int cap, int rev) {
			this.to = to;
			this.cap = cap;
			this.rev = rev;
		}
	}


	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}



Measured memory_bytes: 32004
h, w = map(int, input().split())
a = []
delcol = {i: True for i in range(w)}
for _ in range(h):
    _a = input()
    if _a == "."*w:
        continue

    for _w in range(w):
        delcol[_w] &= ("." == _a[_w])

    a.append(_a)

for _a in  a:
    for _w in range(w):
        if not delcol[_w]:
            print(_a[_w], end="")

    print()


Measured memory_bytes: 4468
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 62;
const int INF = 1 << 30;
const double PI = acos(-1);
int main()
{
    int n, m;
    int ans = 0;
    int sum = 0;
    cin >> n >> m;
    V a(n);
    rep(i, n)
    {
        cin >> a[i];
        sum += a[i];
    }
    int border = (sum+4*m-1) / (4 * m);
    rep(i, n)
    {
        if (a[i] >= border)
        {
            ans++;
        }
    }
    cout << solve(ans >= m) << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main {
  public static void main(String[] args) throws IOException{
    BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(buf.readLine());
    for (int i = 0; i < N; i++) {
      String[] tmp = buf.readLine().split(" ");
      int array[] = new int[3];
      for (int j = 0; j < 3; j++) {
        array[j] = Integer.parseInt(tmp[j]);
      }
      Arrays.sort(array);
      if (array[2] * array[2] == (array[1] * array[1]) + (array[0] * array[0])) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    }
  }
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a) {if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(int a) {if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
void AorB(int a,string b,string c) {if(a){cout<<b<<endl;}else{cout<<c<<endl;}}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    int h,w,count=0;
    cin>>h>>w;
    Vs s(h);
    REP(i,0,h){
        cin>>s[i];
        REP(j,0,w) if(s[i][j]=='#') count++;
    }
    AorB(count==h+w-1,"Possible","Impossible");
    
    return 0;
}


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

int main(){
  char a, b;
  cin >> a >> b;
  if(a == 'D'){
    if(b == 'D') b = 'H';
    else b = 'D';
  }
  cout << b << endl;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

int n,a,b,c,l[10],ans=INF;

void dfs(int d, int x, int y, int z, int p){
	if(d<n){
		dfs(d+1,x,y,z,p);
		dfs(d+1,x+l[d],y,z,p+1);
		dfs(d+1,x,y+l[d],z,p+1);
		dfs(d+1,x,y,z+l[d],p+1);
	}else if(x&&y&&z){
		ans = min(ans,abs(x-a)+abs(y-b)+abs(z-c)+10*(p-3));
	}
}

int main(void){
	int i;
	cin >> n;
	cin >> a >> b >> c;
	for(i=0; i<n; ++i){
		cin >> l[i];
	}
	dfs(0,0,0,0,0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*
import kotlin.comparisons.compareBy
import kotlin.comparisons.compareByDescending
import kotlin.comparisons.compareValues
import kotlin.comparisons.thenByDescending

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val m = scanner.nextInt()
    val ab = Array(n) { AB(scanner.nextInt(), scanner.nextLong()) }

    val comp = compareByDescending<Pair<Long, Long>> { it.second }
        .thenByDescending { it.first }

    val dayasc = ab.sortedWith(compareBy { it.a })
    val pq = PriorityQueue<AB>()

    var ret = 0L
    var di = 0
    (0..m).forEach { day ->
        while (di < dayasc.size && dayasc[di].a == day) {
            pq.add(dayasc[di])
            di++
        }

        if (pq.isEmpty()) return@forEach

        val w = pq.poll()
        ret += w.b

    }

    println(ret)
}

data class AB(val a: Int, val b: Long) : Comparable<AB> {
    override fun compareTo(other: AB): Int {
        return compareValues(other.b, b)
    }
}

Measured memory_bytes: 115448
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;


ll i,j,k;


int main(){
    ll N;
    cin>>N;
    cout<<2*N*M_PI<<endl;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()
using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;

int GCD(int x,int y){
	return x? GCD(y % x , x):y;
}

int main(void){
	int A,B,C; cin>>A>>B>>C;
	cout<<(C % GCD(B,A) == 0? "YES": "NO");
}


Measured memory_bytes: 256
from fractions import*

n = int(input())
a = list(map(int, input().split()))
a_r = list(reversed(a))

l = [a[0]]
r = [a_r[0]]

for i in range(1, n-1):
#    print(i)
    l.append(gcd(l[i-1], a[i]))
    r.append(gcd(r[i-1], a_r[i]))

l = [0] + l
r = r[::-1] + [0]

print(max(gcd(s, t) for s, t in zip(l, r)))

Measured memory_bytes: 16132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int a[101010],b[101010];

int main(){
  int A,B,M; cin>>A>>B>>M;
  rep(i,A) cin>>a[i];
  rep(i,B) cin>>b[i];
  int ans=0,mi=1e9;
  rep(i,A) mi=min(mi,a[i]);
  ans+=mi;
  mi=1e9;
  rep(i,B) mi=min(mi,b[i]);
  ans+=mi;
  rep(i,M){
    int x,y,z; cin>>x>>y>>z; x--,y--;
    int tmp=a[x]+b[y]-z;
    ans=min(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <string>
#include <list>
#include <bitset>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

const LL mod=1e9+7;
const double PI=acos(-1);
const double EPS=1e-6;
const int INF=0x3f3f3f3f;
inline int readint(){int sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;}
inline LL readLL(){LL sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;}

vector<int> E[100005];

int dfs(int pos,int fa){
    int ans=0;
    for(int i=0;i<E[pos].size();i++){
        if(E[pos][i]==fa) continue;
        ans^=(dfs(E[pos][i],pos)+1);
    }
    return ans;
}

int main(){//ios_base::sync_with_stdio(0);cin.tie(0);
    int n=readint();
    for(int i=1;i<n;i++){
        int u=readint(),v=readint();
        E[u].push_back(v);
        E[v].push_back(u);
    }
    if(dfs(1,0)) printf("Alice\n");
    else printf("Bob\n");
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


Measured memory_bytes: 11904
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int C[4];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  rep(i, 3) {
    int a, b;
    cin >> a >> b;
    a--,b--;
    C[a]++,C[b]++;
  }
  rep(i, 4) if (C[i] > 2) {
    cout << "NO\n";
    return 0;
  }
  cout << "YES\n";
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import static java.lang.Integer.parseInt;

/**
 * Illumination
 * --------------------
 * JOI 12th, Fin.1
 */
public class Main {

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

		int N = parseInt(br.readLine());

		List<Integer> list = new ArrayList<>();

		line = br.readLine();

		//sum up
		list.add(0);

		char prev = line.charAt(0);
		int sum = 1;
		int max = 1;

		for (int i = 2; i < line.length(); i += 2) {
			char next = line.charAt(i);
			if (prev != next) {
				sum++;
			} else {
				list.add(sum);
				sum = 1;
			}
			prev = next;
		}

		list.add(sum);
		list.add(0);

		//solve
		for (int i = 1; i < list.size() - 1; i++) {
			max = Math.max(max, list.get(i - 1) + list.get(i) + list.get(i + 1));
		}

		System.out.println(max);
	}
}

Measured memory_bytes: 29836
import Control.Monad
import qualified Data.Map as M
main = do
  n <- readLn
  ss <- replicateM n getLine
  putStrLn 
    $concatMap (uncurry (flip replicate))
    $ M.toList $ foldl1 (M.intersectionWith min) 
    $ map (M.fromListWith (+) . flip zip (repeat 1)) ss

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

using namespace std;

typedef long long ll;

int main () {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) cin >> h[i];
  ll ans = 0, count = 0;
  for (int i = n - 1; i > 0; --i) {
	  if (h[i] <= h[i-1]) {
		  count++;
	  }
	  else {
		  ans = max(count, ans);
		  count = 0;
	  }
	  if (count == n - 1) {
		  cout << count;
		  return 0;
	  }
  }
  cout << ans;
}


Measured memory_bytes: 640
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i,n) for(long long i=0;i<n;i++)
int a[114514];
int b[334334];
int main() {
	int n;
	cin >> n;
	int k;
	cin >> k;
	rep(i, n) { cin >> a[i]; }
	sort(a, a + n);
	rep(i, (n - k+1)) { b[i] = min(abs(a[i])+abs(a[i+k-1]-a[i]), abs(a[i+k-1]) + abs(a[i+k-1]-a[i] )); }
	sort(b, b + (n - k+1));
	cout << b[0] << endl;
}

Measured memory_bytes: 896
/*input
3 2
5 3
31415 9265
35897 932
*/
#include <bits/stdc++.h>
using namespace std;
#define MAX 200010

int a[MAX];

int main() {
    int n, k;
    while (cin >> n >> k) {
        long long ans = 0;
        memset(a, 0, sizeof(a));

        for (int i = 1; i <= n; i++) a[i % k]++;
        
        ans += (long long) a[0] * a[0] * a[0];
        for (int i = 1; i < k; i++) {
            if ((k - i + k - i) % k != 0) continue;

            ans += (long long) a[i] * a[k - i] * a[k - i];
        }

        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 1024
import math
X = int(input())

sq = int(math.sqrt(X))
m = 1
for b in range(2, sq+1):  # ここで2が1になると1のp乗となり永遠にループが回り続ける
    p = 2
    tmp = b ** p
    while tmp <= X:
        m = max(tmp, m)
        p += 1
        tmp = b ** p
print(m)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e2 + 5;
bool used[MAX_N], match[MAX_N][MAX_N];
int girl[MAX_N];
bool fnd(int x, int n) {
    for (int j = 1; j <= n; j++) {
        if (match[x][j] && !used[j]) {
            used[j] = true;
            if (girl[j] == 0 || fnd(girl[j], n)) {
                girl[j] = x;
                return true;
            }
        }
    }
    return false;
}
int solve(int m, int n) {
    int ans = 0;
    for (int i = 1; i <= m; i++) {
        memset(used, false, sizeof(used));
        if (fnd(i, n)) ans++;
    }
    return ans;
}
int main() {
    int n, a, b, x[105], y[105];
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &x[i], &y[i]);
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &a, &b);
        for (int j = 1; j <= n; j++) {
            if (x[j] < a && y[j] < b) match[j][i] = true;
        }
    }
    printf("%d\n", solve(n, n));
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<long long> A(N), B(N);
  for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];

  vector<long long> C(N+1, 0); // C[N] = 0 を番兵としておく
  for (int i = N-1; i >= 0; --i) {
      A[i] += C[i+1]; // とりあえず前回分を足しておく
      long long amari = A[i] % B[i];
      long long need = 0;
      if (amari != 0) need = B[i] - amari; // 追加で必要な分
      C[i] = C[i+1] + need;
  }
  cout << C[0] << endl;
}


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

int64_t lucas(vector<int64_t> &lucaslog, int N);

int main() {
  int N;
  cin >> N;
  vector<int64_t> lucaslog(N+1, 0);
  lucaslog.at(0) = 2;
  lucaslog.at(1) = 1;
  cout << lucas(lucaslog, N) << endl;
}


int64_t lucas(vector<int64_t> &lucaslog, int N){
  int lucas_number;
  if(lucaslog.at(N) != 0){ 
    return lucaslog.at(N); 
  } else { 
    lucaslog.at(N) = lucas(lucaslog,N-2) + lucas(lucaslog,N-1); 
    return lucaslog.at(N); 
  }
}

Measured memory_bytes: 256