akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n)for(ll i=0;i<n;i++)
using namespace std;
typedef long long ll;

int a[101];

int main() {
	int n;
	while (cin >> n)a[n]++;
	int Max = *max_element(a, a + 101);
	rep(i, 101) {
		if (a[i] == Max)cout << i << endl;
	}
	return 0;
}

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

#define ll long long
#define mii make_pair<int, int>
#define mll make_pair<ll, ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define all(v) (v).begin(), (v).end()


bool BFS(vvi &adj, vl &d)
{
    int n = adj.size();
    vb vis(n, 0);
    
    vis[0] = 1;
    queue<int> q;
    q.push(0);
    while (!q.empty())
    {
        int t = q.front();
        q.pop();
        for (int i : adj[t])
            if (!vis[i])
            {
                q.push(i);
                d[i] = t+1;
                vis[i] = 1;
            }
    }
    for (bool b : vis)
        if (!b)
            return 0;
    return 1;
}

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

    int n, m;
    cin >> n >> m;
    vl d(n, 0);
    vvi adj(n);
    for (int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    if (BFS(adj, d))
    {
        cout << "Yes\n";
        for (int i = 1; i < d.size(); ++i)
            cout << d[i] << '\n';
    }
    else
        cout << "No\n";
}

Measured memory_bytes: 10700
#include<stdio.h>
int main(){
  int n,i;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=n-1;i>0;i--){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[0]);
  return 0;
}
  

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define eb emplace_back
#define precision(n) cout << fixed << setprecision(n);
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{
    fast;
    int n,k;
    cin>>n>>k;
    int a[n];
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];

    }
    sort(a,a+n);
    for(int i=0;i<k;i++)
    {
        sum+=a[i];
    }
  cout<<sum<<endl;
    return 0;
}




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


int main(){
  int n,m,tmp;
  int* a; //動的確保する配列
  int i,sum=0;
  int count=0;
  double border=0;

  scanf("%d" ,&n);
  /*
  if(n<1 || n>100){
    fprintf(stderr,"error: ill-formed fraction.\n");
    exit(1);
  }
  */

  scanf("%d" ,&m);
  /*
  if(m<1 || m>100){
    fprintf(stderr,"error: ill-formed fraction.\n");
    exit(1);
  }
  */

  if(n<m){
    fprintf(stderr,"error: ill-formed fraction.\n");
    exit(1);
  }

  //配列を動的に確保して投票数を入力
  a = (int*)malloc(sizeof(int) * n);
  for(i=0;i<n;i++){

    tmp = scanf("%d",a+i);
    if(tmp<1 || tmp>1000){
      fprintf(stderr,"error: ill-formed fraction.\n");
      exit(1);
    }else{
    sum += a[i];
  }

  }


  border = (double)sum / (4*m);

  //商品a[i]が条件を満たすか判断する
  for(i=0;i<n;i++){
    if((double)a[i]>=border) count++;

    if(count == m){
      printf("Yes\n");
      break;
    }
  }

  if(count != m){
    printf("No\n");
  }


  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

class card{
public:
	char suit;
	int val;
	card() {}
	card(char s,int v) {
		suit = s;
		val = v;
	}
	bool operator<=(card& e) {
			return this->val <= e.val;
		}
	bool operator<(card& e) {
		return this->val < e.val;
	}
	card& operator=(card& e) {
		this->suit = e.suit;
		this->val = e.val;
		return *this;
	}
};

int pt(vector<card>& a,int p,int r) {
	card x = a[r];
	int i = p-1;
	for(int j = p;j < r;j++) {
		if(a[j] <= x) {
			i++;
			auto l = a[i];
			a[i] = a[j];
			a[j] = l;
		}
	}
	auto l = a[r];
	a[r] = a[i+1];
	a[i+1] = l;
	return i+1;
}

void qs(vector<card>& a,int p,int r) {
	if (p < r) {
		int q = pt(a,p,r);
		qs(a,p,q-1);
		qs(a,q+1,r);
	}
}

vector<card> s;

void merge(int l,int m,int r) {
    card* ll = new card[m-l+1];
    card* rr = new card[r-m+1];
    ll[m-l].val = 0x7fffffff;
    rr[r-m].val = 0x7fffffff;
    for(int i = l;i < m;i++)ll[i-l]=s[i];
    for(int i = m;i < r;i++)rr[i-m]=s[i];
    int i = 0,j = 0,c = 0;
    while(c != r-l) {
        if(ll[i] <= rr[j]) {
            s[l+c] = ll[i];
            i++;
        }else {
            s[l+c] = rr[j];
            j++;
        }
        c++;
    }
}

void sort(int l,int r) {
    if(r <= l + 1) return;
    int m = (l + r) / 2;
    sort(l,m);
    sort(m,r);
    merge(l,m,r);
}

int main(void) {
	int n,t;
	string st;
	cin >> n;
	vector<card> a;
	for(int i = 0;i < n;i++){
		cin >> st >> t;
		a.push_back(card(st[0],t));
		s.push_back(card(st[0],t));
	}
	sort(0,n);
	qs(a,0,n-1);
	bool stable = true;
	for(int i = 0;i < n;i++) {
		if(s[i].suit != a[i].suit || s[i].val != a[i].val)
			stable = false;
	}
	if(stable) cout << "Stable" << endl;
	else cout << "Not stable" << endl;
	for(int i = 0;i < n;i++) {
		cout << a[i].suit << " " << a[i].val << endl;

	}
}



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

int main() {
    int n;
    cin >> n;
    vector<int> ds(n);
    for (int &d : ds) {
        cin >> d;
    }
    
    int sum = 0;
    for (int i = 0; i < ds.size()-1; i++) {
        for (int j = i+1; j < ds.size(); j++) {
            sum += ds.at(i) * ds.at(j);
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
int main()
{
    ft
    ll t,i,j,n,m,l=0,r;
    cin>>n;
    ll a[n+2];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=1;i<n-1;i++)
    {
        ll b[3]={a[i],a[i-1],a[i+1]};
        sort(b,b+3);
        if(b[1]==a[i])
        {
            l++;
        }
    }
    cout<<l<<"\n";
    return 0;
}



Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=1e5+1;
bool f(long long x, long long y)
{
    while(x%y==0)
    {
        x/=y;
    }
    return x%y==1;
}
int main()
{
    FASTINOUT;
    ll x,ans=0;
    cin>>x;
    if (x==2){
        cout<<1<<endl;
        return 0;
    }
    for (ll i=2;i<=sqrtl(x);i++){
        if (x%i==0){
            bool b=f(x,i),k=0;
            if (i*i!=x)
                k=f(x,x/i);
            ans=ans+(b)+(k);
        }
    }
    for (ll i=2;i<=sqrtl(x-1);i++){
        if ((x-1)%i==0){
            bool b=f(x,i),k=0;
            if (i*i!=(x-1))
                k=f(x,(x-1)/i);
            ans=ans+(b)+(k);
        }
    }
    cout<<ans+2<<endl;
    return 0;
}


Measured memory_bytes: 256
M,D = map(int,input().split())
import sys
counter = 0
if D<10:
    print(0)
    sys.exit()
for m in range(1,M+1):
    for d in range(10,D+1):
        d10 = int(str(d)[0])
        d1 = int(str(d)[1])
        if d10>=2 and d1>=2 and d1*d10==m:
            counter += 1

print(counter)

Measured memory_bytes: 3060
//In the name of God
//SMani24
#include<bits/stdc++.h>
using namespace std;

char a, b;
string s, t, ans[2];
int main() {
	cin >> a >> b;
	for (int i = 0; i < a - '0'; i++)
		s += b;
	for (int i = 0; i < b - '0'; i++)
		t += a;
	ans[1] = s;
	ans[0] = t;
	sort(ans, ans + 2);
	cout << ans[0] << endl;
}


Measured memory_bytes: 256
s = gets.chomp
s = s[0..-3] if s.size.even?
s = s[0..-2] if s.size.odd?
(0...s.size/2).each do |i|
  if s[0...s.size/2] == s[s.size/2...s.size]
    p s.size
    return
  else
    s = s[0..-3]
  end
end

Measured memory_bytes: 14312
#include <cstdio>
#include <algorithm>
 
using namespace std;
 
int main(void) {
    int n, k, x, y;
    scanf("%d %d %d %d", &n, &k, &x, &y);
 
    printf("%d\n", min(k, n)*x + max(0, n-k)*y);
    return 0;
}


Measured memory_bytes: 128
# coding: utf-8

#約数列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

#main
X = int(input())
F = make_divisors(X)
#intのみのlistは、直接.join()できない
S = [int(x) for x in F]

for i in range(len(S)):
    tmp = S[i]
    for A in range(-1000, 1001):
        B = A - tmp
        if A**5 - B**5 == X:
            print(str(A) + ' ' + str(B))
            break
    else:
        continue
    break

Measured memory_bytes: 65796
/* author   : mpily :-()
title : Competing.cpp
time :Mon Sep  9 20:28:15 2019

*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin>>N;
	vector<int>arrA(N);
	vector<int>arrB(N-1);
	int ans = 0;
	for(int i =0; i < N-1; i++){
		cin>>arrB[i];
	}
	arrA[0] = arrB[0];
	ans+=arrA[0];
	for(int i = 1; i < N-1; i++){
		arrA[i] = min(arrB[i],arrB[i-1]);
		//cout<<arrA[i]<<":: \n";
		ans+=arrA[i];
	}
	ans+=arrB[N-2];
	cout<<ans<<"\n";
	return 0;
}


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

int n;
long long d, x, y, ans;

int main() {
    cin >> n >> d;
    d *= d;
    for (int i = 0; i < n; i++){
        cin >> x >> y;
        if (x*x + y*y <= d) ans++;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int max, index = 0;
    for (int i = 0; i <= n; i++) {
        if (i == pow(2, index)) {
            max = i;
            index++;
        }
    }
    cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
vi lun(1,0);


void dfs(intl now, intl depth){
  lun.push_back(now);
  if(depth >= 10) return;
  intl first = now % 10;
  Rep(i,3){
    if(first+ dy.at(i) <= 9 &&first+ dy.at(i) >= 0) dfs(now*10 +first + dy.at(i) , depth +1);
  }
  return;
}

int main(){
  int N;
  cin >> N;
  Rep(i,9) dfs(i+1,1);
  SortA(lun);
  cout << lun.at(N);
}

Measured memory_bytes: 5428
import math
N = int(input())

A = []

for i in range(N):
    tmpx, tmpy = map(int, input().split())
    A.append([tmpx,tmpy])

d = []

for i in range(0,N-1):
    for j in range(i+1,N):
        tmpd = math.sqrt((A[i][0] - A[j][0])**2 + (A[i][1] - A[j][1])**2)
        d.append(tmpd)

com = 1
for i in range(1,N):
    com *= i

com *= 2

ans = 0
for i in range(len(d)):
    ans += d[i]*com

M = 1
for i in range(1,N+1):
    M *= i

print(ans/M)





Measured memory_bytes: 3064
s = input()

for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        print(*[i + 1, i + 2])
        exit()
for i in range(len(s) - 2):
    if s[i] == s[i + 2]:
        print(*[i + 1, i + 3])
        exit()
print(*[-1, -1])

Measured memory_bytes: 3188
#include<iostream>
#include<vector>

using namespace std;

int main() {

	int n;
	vector<int> vt;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int data;

		cin >> data;
		vt.push_back(data);
	}

	for (int j = n-1; j > 0; j--) {
		cout << vt[j] << " ";
	}
	cout << vt[0] << endl;
	
	return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<int> s(N);
    rep(i,N)cin >> s[i];
    int ans = 0;
    rep(i,N)ans += s[i];
    map<int,int> L;
    rep(i,N){
        int tmp = s[i] % 10;
        L[s[i]] = tmp;
    }
    if(ans % 10 != 0)cout << ans << endl;
    else{
        int t = 0;
        for(auto itr = L.begin();itr != L.end();itr++){
            if(itr -> S % 10 != 0){
                t = itr -> F;
                break;
            }
        }
        if(t == 0)cout << 0 << endl;
        else cout << ans - t << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
//  #ifndef ONLINE_JUDGE
//     freopen ("INPUT.txt" , "r" , stdin);
//     freopen ("OUTPUT.txt" , "w" , stdout);
//  #endif

// -------------------------------------Code starts here---------------------------------------------------------------------     

   int h;
   cin>>h;
   int ans=0;
   int x=1;
   while(h!=0)
   {
      h/=2;
      ans+=x;
      x*=2;
   }
   cout<<ans;

// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll INFl = 1e18;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int x; cin >> x;
	for (int i = -150; i <= 150; i ++) {
		for (int j = -150; j <= 150; j ++) {
			if (pow(i, 5) - pow(j, 5) == x) {
				cout << i << ' ' << j << '\n';
				return 0;
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 4060
#!/usr/bin/env python3
# ITP2_10_C: Bitset 1 - Bit Flag


class BitFlag:
    def __init__(self, size):
        self.size = size
        self.mask = ~(1 << self.size)
        self.data = 0 & (1 << self.size)

    def set(self, i):
        self.data |= (1 << i) & self.mask

    def test(self, i):
        return self.data & (1 << i) > 0

    def clear(self, i):
        self.data &= ~(1 << i) & self.mask

    def flip(self, i):
        self.data ^= (1 << i) & self.mask

    def all(self):
        return self.data == 2**self.size - 1

    def any(self):
        return not self.data == 0

    def none(self):
        return self.data == 0

    def count(self):
        return sum(1 for i in range(self.size) if self.test(i))

    def val(self):
        return self.data


def run():
    flg = BitFlag(64)
    q = int(input())
    for _ in range(q):
        cmd = input().split()

        if cmd[0] == '0':
            if flg.test(int(cmd[1])):
                print(1)
            else:
                print(0)
        elif cmd[0] == '1':
            flg.set(int(cmd[1]))
        elif cmd[0] == '2':
            flg.clear(int(cmd[1]))
        elif cmd[0] == '3':
            flg.flip(int(cmd[1]))
        elif cmd[0] == '4':
            if flg.all():
                print(1)
            else:
                print(0)
        elif cmd[0] == '5':
            if flg.any():
                print(1)
            else:
                print(0)
        elif cmd[0] == '6':
            if flg.none():
                print(1)
            else:
                print(0)
        elif cmd[0] == '7':
            print(flg.count())
        elif cmd[0] == '8':
            print(flg.val())


if __name__ == '__main__':
    run()



Measured memory_bytes: 5652
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int a, b, x; cin >> a >> b >> x;
	int res = x - a;
	
	if (0 <= res && res <= b) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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

using namespace std;

int main(){
    int ans=-1;
    int a, b;
    cin>>a>>b;
    for(int i=1;i<=10000;++i){
        if(((int)(i*0.08)==a)&&((int)(i*0.1)==b)){
            ans=i;
            break;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll K,A,B;
    cin >> K >> A >> B;
    string out = "NG";
    for(ll i=A;i<=B;i++){
        if(i%K==0) out = "OK";
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "
int main(){
    int n,m,x;cin>>n>>m>>x;
    int before=0,after=0;
    rep(i,m){
        int tmp;cin>>tmp;tmp<x?before++:after++;
    }
    co(min(before, after));
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

const ll mod = 1000000007;

int main() {
  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;

  vll ps(a);
  vll qs(b);
  vll rs(c);

  rep(i, a) cin >> ps[i];
  rep(i, b) cin >> qs[i];
  rep(i, c) cin >> rs[i];

  priority_queue<ll> pq;

  Sort(ps);
  Reverse(ps);
  Sort(qs);
  Reverse(qs);

  rep(i, x) pq.push(ps[i]);
  rep(i, y) pq.push(qs[i]);
  rep(i, c) pq.push(rs[i]);

  ll ans = 0;
  rep(i, x + y) {
    ans += pq.top();
    pq.pop();
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8560
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

template<class T> inline void cal(T &ans, T n) {
    REP(i, n) {
        ans *= (i + 1);
        ans %= mod;
    }
}

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

    ll n, m;
    cin >> n >> m;

    ll ans = 1;
    ll diff = abs(n - m);
    if (diff > 1) ans = 0;
    else {
        if (diff == 0) {
            cal(ans, n);
            cal(ans, m);
            ans *= 2;
            ans %= mod;
        }
        if (diff == 1) {
            cal(ans, n);
            cal(ans, m);
        }
    }

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


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

long long gcdTest(long long x, long long y) {
  if (y > x) swap(x, y);
  if (y == 0) return x;
  return gcdTest(y, x % y);
}

int main() {
  long long A, B; cin >> A >> B;
  long long gcd_AB = gcdTest(A, B);
  long long dev_A = A / gcd_AB;
  long long dev_B = B / gcd_AB;
  long long ans = gcd_AB * dev_A * dev_B;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int s[] = {-1,1};
int main(){
  int n,m; cin >> n >> m;;
  vector<long long int> a(n),b(n),c(n);
  for(int i=0;i<n;i++) cin >> a[i] >> b[i] >> c[i];
  long long int ans = -1000000000;
  vector<long long int> v(n);
  for(int i=0;i<2;i++)
    for(int j=0;j<2;j++)
      for(int k=0;k<2;k++){
      	for(int l=0;l<n;l++) v[l] = s[i]*a[l] + s[j]*b[l] + s[k]*c[l];
        sort(v.begin(),v.end());
        long long int sum = 0;
        for(int l=0;l<m;l++) sum += v[n-l-1];
        ans = max(ans,sum);
   }
  cout << ans << endl;
  return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include<vector>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    std::vector<int> vec(n) ;
    for(int i=0;i<n;i++){
        cin>>vec[i];
    }
    
    int ans=-1, count=0;
    for(int i=1;i<n;i++){
        if(vec[i]<=vec[i-1]){
            count++;
        }
            
        else{
            ans= max(ans, count);
            count=0;
        }
    }
        ans= max(ans, count);
cout<<ans;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
  string s;
  cin>>s;
  bool SS=false;bool NN=false;bool WW=false;bool EE=false;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='S'){SS=true;}
    if(s.at(i)=='N'){NN=true;}
    if(s.at(i)=='W'){WW=true;}
    if(s.at(i)=='E'){EE=true;}
  }
   
   if(SS==true&&NN==false){cout<<"No";}
   else if(NN==true&&SS==false){cout<<"No";}
   else if(WW==true&&EE==false){cout<<"No";}
   else if(EE==true&&WW==false){cout<<"No";}
   else{cout<<"Yes";}
   cout<<endl;

  return 0;
}

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

using namespace std;

int main()
{
	int n;
	vector<int> w;

	cin >> n;

	w.resize(n);

	int sum = 0;
	for(int i = 0; i < n; ++i)
	{
		cin >> w[i];
		sum += w[i];
	}

	int ans = 1 << 30;
	int now = 0;
	for(int t = 0; t < n - 1; ++t)
	{
		now += w[t];
		ans = min(ans, abs(now - (sum - now)));
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
#print(A)
ans=0
i=0
while(i<len(A)-1):
    ar=[]
    try:
        ar=A[i:i+k]
    except:
        ar=A[i:len(A)]
    i=i+k-1
    ans=ans+1
print(ans)


Measured memory_bytes: 52780
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map>
#include <map>
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
using namespace std;
typedef long long LL;

/*
cout<< = printf()
cin>> = scanf()

char = string
*/
int main(){
  int a,b;
  std::cin >> a >> b;
  if((a*b)%2 == 0){
    std::cout << "Even";
  }else{
    std::cout << "Odd";
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

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

	int ans = 0;
	for (int f = 0, l = s.length() - 1; f < l;)
	{
		char F = s[f], L = s[l];
		if (F == L)
		{
			f++, l--;
			continue;
		}

		if (F == 'x')
		{
			f++;
			ans++;
			continue;
		}
		if (L == 'x')
		{
			l--;
			ans++;
			continue;
		}

		cout << -1 << endl;
		return 0;
	}

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

Measured memory_bytes: 512
import numpy as np
N, M, X = map(int, input().split(' '))
matrix = np.array([list(map(int, input().split(' ')))  for i in range(N)])
price = []
for i in range(2**N):
    res = np.zeros(M+1)
    for j in range(N):
        if ((i >> j) & 1):
            res += matrix[j]
        if res[1:].min() >=X:
            price.append(res[0])
price = np.array(price)
if len(price) > 0:
    print(int(price.min()))
else:
    print('-1')

Measured memory_bytes: 28632
n,k=gets.split.map &:to_i;s=gets.chop.chars.map &:ord;l=0;((s[l]+l)%2>0&&(s[l]^=3;0==k-=1)&&break;l+=1;k-=1)while k>0&&l<n;s=s.rotate l%n;l%2>0&&s=s.map{|e|e^3};s[0]^=(n*k)%2*3;$><<s.map(&:chr)*''

Measured memory_bytes: 24416
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var hwd = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int[][] field = new int[hwd[0]][];
            for (int i = 0; i < hwd[0]; i++)
            {
                field[i] = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            }
            var map = new Dictionary<int, int>();
            for (int i = 0; i < hwd[0]; i++)
            {
                for (int j = 0; j < hwd[1]; j++)
                {
                    map[field[i][j]] = 1000 * i + j;
                }
            }
            map = map.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
            int[] warp = map.Values.ToArray();
            int[] ans = new int[warp.Count()];
            int q = int.Parse(Console.ReadLine());
            for (int i = ans.Count() - 1; i >= 0; i--)
            {
                if (i >= ans.Count() - hwd[2]) ans[i] = 0;
                else
                {
                    ans[i] = ans[i + hwd[2]] + Math.Abs(warp[i] % 1000 - warp[i + hwd[2]] % 1000) + Math.Abs(warp[i] / 1000 - warp[i + hwd[2]] / 1000);
                }
            }
            for (int i = 0; i < q; i++)
            {
                var lr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                Console.WriteLine(ans[lr[0] - 1] - ans[lr[1] - 1]);
            }
        }
    }
}

Measured memory_bytes: 32012
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <cmath>
#include <cassert>

#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 1e5 + 5, MOD = 1e9 + 7;

int N, W;
ll dp[MN];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> N >> W;
    memset(dp, 0x3f, sizeof(dp));
    dp[0] = 0;
    for (int i = 0, w, v; i < N; i++) {
        cin >> w >> v;
        for (int j = 100000; j >= v; j--) dp[j] = min(dp[j], dp[j - v] + w);
    }
    for (int i = 100000; i >= 0; i--) {
        if (dp[i] <= W) {
            cout << i << '\n';
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
X = int(input())
b = 1
ans = 0
while(1):
    b += 1
    p = 1
    if (b**2) > X:
        break
    while(1):
        p += 1
        if X < (b**(p+1)) and (b**p) <= X:
            ans = max(ans,b**p)
            break
if X==1:
    print(1)
    exit()
if X==2 or X == 3:
    print(1)
    exit()

print(ans)

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

#define MAX 100000

struct Node{int key,parent,left,right;};

int parent(int i){return i/2;}
int left(int i){return 2 * i;}
int right(int i){return 2 * i + 1;}

int main(){
    long long n;
    int i;
    long long A[MAX+1];
    cin >> n;
    for(long long i = 0; i < n; i++){
        cin >> A[i+1];
    }
    for(long long i = 0; i < n; i++){
        cout << "node " << i+1 << ": key = " << A[i+1] << ", ";
        if(parent(i+1) > 0) cout << "parent key = " << A[parent(i+1)] << ", ";
        if(left(i+1) <= n) cout << "left key = " << A[left(i+1)] << ", ";
        if(right(i+1) <= n) cout << "right key = " << A[right(i+1)] << ", "; 
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3124
import itertools


def count_ones(n):
  res = []
  length = n.bit_length()
  power = 1
  while len(res) < length:
    d, m = divmod(n, 2**power)
    num_ones = 2**(power-1) * d + max(0, m + 1 - 2**(power-1))
    res.append(num_ones)
    power += 1
  return res

A, B = map(int, input().split())
if B == 0:
  print(0)
else:
  ones_A = count_ones(A)
  ones_B = count_ones(B)

  ones = [nb - na for nb, na in itertools.zip_longest(ones_B, ones_A, fillvalue=0)]

  change = [x % 2 for x in ones[::-1]]
  change = int(''.join(map(str, change)), 2)
  print(A ^ change)

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


int main(){
    int m,f,r;
    while(true){
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r==-1){
            break;
        }
        if(m==-1 || f==-1){
            cout << 'F' << endl;
        }
        else if((m+f)>=80){
            cout << 'A' << endl;
        }
        else if((m+f)>=65){
            cout << 'B' << endl;
        }
        else if((m+f)>=50){
            cout << 'C' << endl;
        }
        else if((m+f)>=30){
            if(r>=50){
                cout << 'C' << endl;
            }
            else{
                cout << 'D' << endl;
            }
        }
        else{
            cout << 'F' << endl;
        }

    }


}


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

const int N = 100010;
int a[N], b[N], c[N], d[N];

struct Node {
    int l, r;
} w[N];

inline bool cmp(Node a, Node b)
{
    if (a.l == b.l) return a.r < b.r;
    return a.l < b.l;
}

int main()
{
    register int n, ans = 0;
    scanf("%d", &n);
    for (register int i = 1; i <= n; ++i) {
        scanf("%d %d", &w[i].l, &w[i].r);
    }
    sort(w + 1, w + n + 1, cmp);
    a[1] = w[1].l, b[1] = w[1].r;
    for (register int i = 2; i <= n; ++i) {
        a[i] = max(a[i - 1], w[i].l);
        b[i] = min(b[i - 1], w[i].r);
    }
    c[n] = w[n].l, d[n] = w[n].r;
    for (register int i = n - 1; i >= 1; --i) {
        c[i] = max(c[i + 1], w[i].l);
        d[i] = min(d[i + 1], w[i].r);
    }
    for (register int i = 1; i < n; ++i) {
        ans = max(ans, max(0, b[i] - a[i] + 1) + max(0, d[i + 1] - c[i + 1] + 1));
    }
    for (register int i = 1; i <= n; ++i) {
        ans = max(ans, w[i].r - w[i].l + 1 + max(0, min(b[i], d[i]) - max(a[i], c[i]) + 1));
    }
    printf("%d\n", ans);
    return 0;
}

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

int main(void){
    while(true){
        int n, m, taro[110], hana[110], tsum=0, hsum=0, sa=0, min=100000, ans1=0, ans2=0;
        cin >> n >> m;
        if(n==0 && m==0) break;
        for(int i=0;i<n;++i) {cin >> taro[i]; tsum += taro[i];}
        for(int j=0;j<m;++j) {cin >> hana[j]; hsum += hana[j];}
        sa = hsum - tsum;
        if(sa%2!=0){cout << "-1" << endl; continue;}
        sa /= 2;
        for(int i=0;i<n;++i){
            int tar = 0;
            tar = taro[i] + sa;
            if(tar < 0) continue;
            for(int j=0;j<m;++j){
                if(hana[j]==tar){
                    if(min > (taro[i]+hana[j])){
                        min = (taro[i]+hana[j]);
                        ans1 = taro[i];
                        ans2 = hana[j];
                    }
                }
            }
        }
        if(min==100000) cout << "-1" <<endl;
        else cout << ans1 << " " << ans2 << endl;
    }
}


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

int trace(vector<pair<int, char>> a, int n)
{
    for(int i=0; i<n; i++){
        if(i == a.size()-1){
            cout << a[i].second << a[i].first << endl;;
        }
        else{
            cout << a[i].second << a[i].first << " ";
        }
    }
}

void BubbleSort(vector<pair<int, char>> &a, int n)
{
    bool flag = true;
    while(flag){
        flag = false;
        for(int i=n-1; i>0; i--){
            if(a[i].first < a[i-1].first){
                swap(a[i].first, a[i-1].first);
                swap(a[i].second, a[i-1].second);
                flag = true;
            }
        }
    }
}

void SelectionSort(vector<pair<int, char>> &a, int n)
{
    for(int i=0; i<n-1; i++){
        int minj = i;
        for (int j=minj; j<n; j++){
            if (a[minj].first > a[j].first) minj = j;
        }
        swap(a[i].first, a[minj].first);
        swap(a[i].second, a[minj].second);
    }
}

bool CheckStable(vector<pair<int, char>> a, vector<pair<int, char>> b, int n)
{
    for(int i=0; i<n; i++){
        if (a[i].second != b[i].second) return false;
    }
    return true;
}

int main()
{
    int n;
    cin >> n;
    vector<pair<int, char>> a(n);
    vector<pair<int, char>> ba(n);
    vector<pair<int, char>> sa(n);

    rep(i,n){
        string s; cin >> s;
        char type = s[0];
        int num = s[1] - '0';
        a[i] = make_pair(num, type);
    }
    copy(a.begin(), a.end(), ba.begin());
    copy(a.begin(), a.end(), sa.begin());

    BubbleSort(ba, n); trace(ba, n);
    cout << "Stable" << endl;

    SelectionSort(sa, n); trace(sa, n);
    if (CheckStable(ba, sa, n) == true) cout << "Stable" << endl;
    else cout << "Not stable" << endl;

    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
map<ll,int> cnt;
void input(){
    fast_io();
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        ll a; cin >> a;
        cnt[a]++;
    }
    
}

int solve(){
    ll ans = 1;
    int chk = 0;
    for(auto p=(--cnt.cend()); p!=--cnt.cbegin(); p--){
        DBG(p.first)
        if(chk>=2) break;
        if(p->second<2) continue;
        else if(p->second>=4) {
            if(chk==1) {ans *= p->first; chk++; }
            else {ans *= (p->first*p->first); chk+=2;}
            }
        else {
            ans *= p->first;
            chk++;
            }
    }
    if(chk<2) ans = 0;
    cout << ans << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

using B = bitset<1000>;

tuple<B, B> f(vector<B> a, vector<B> b, vector<int> msb, B x) {
    int N = a.size();
    B y;
    rep(i, N) if (x[msb[i]]) {
        x ^= a[i];
        y ^= b[i];
    }
    return make_tuple(x, y);
}

int main() {
    int N, M;
    cin >> M >> N;
    vector<B> v(N);
    rep(j, M) {
        string s; cin >> s;
        rep(i, N) v[i].set(j, s[i] - '0');
    }
    vector<B> a, b;
    vector<int> msb;
    vector<bool> cocircuit(N, true);
    rep(i, N) {
        B x, y;
        tie(x, y) = f(a, b, msb, v[i]);
        if (x.any()) {
            int j;
            for (j = 0; !x[j]; j++);
            int k = lower_bound(all(msb), j) - msb.begin();
            a.insert(a.begin() + k, x);
            y.set(i, 1);
            b.insert(b.begin() + k, y);
            msb.insert(msb.begin() + k, j);
        }
        else {
            y.set(i, 1);
            rep(i, N) if (y[i]) cocircuit[i] = false;
        }
    }
    vector<string> ans(M, string(N, ' '));
    rep(j, M) {
        B e;
        e.set(j, 1);
        B x, y;
        tie(x, y) = f(a, b, msb, e);
        rep(i, N) {
            if (cocircuit[i]) ans[j][i] = (x.none() && y[i]) ? '-' : '0';
            else ans[j][i] = x.any() ? '+' : '0';
        }
    }
    rep(j, M) cout << ans[j] << endl;
}



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


int main(){
	int N,T;
	cin>>N>>T;
	int c[N],t[N];
	int min_cost = 999999;
	for(int i=0;i<N;i++){
		cin>>c[i]>>t[i];
		if(t[i]<=T&&min_cost>c[i]){
			min_cost=c[i];
		}
	}
	
	if(min_cost==999999){
		cout<<"TLE"<<endl;
	}
	else{
		cout<<min_cost<<endl;
	}
	return 0;
}

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

using namespace std;

int main(){
    int K;
    string S;
    cin>>K;
    cin>>S;

    for(int i= 0; i < S.length(); i++){
        if(i>=K){
            cout<<"...";
            break;
        }else{
            cout<<S[i];
        }

    }
}


Measured memory_bytes: 3560
import sys
input = sys.stdin.readline
import heapq as hq
n,m = map(int,input().split())
s,t = map(int,input().split())
abd = [list(map(int,input().split())) for i in range(m)]
mod = 10**9+7
graph = [[] for i in range(n+1)]
for a,b,d in abd:
  graph[a].append((b,d))
  graph[b].append((a,d))
dists = [[10**18,0] for i in range(n+1)]
distt = [[10**18,0] for i in range(n+1)]
for start,dist in (s,dists),(t,distt):
  dist[start] = [0,1]
  q = [(0,start)]
  hq.heapify(q)
  while q:
    dx,x = hq.heappop(q)
    k = dist[x][1]
    for y,d in graph[x]:
      if dist[y][0] > dx+d:
        dist[y][0] = dx+d
        dist[y][1] = k
        hq.heappush(q,(dist[y][0],y))
      elif dist[y][0] == dx+d:
        dist[y][1] = (dist[y][1]+k)%mod
dst = dists[t][0]
ansls = []
for u,v,d in abd:
  for a,b in (u,v),(v,u):
    if dists[a][0] < distt[a][0]:
      if dists[a][0]*2 < dst and distt[b][0]*2 < dst:
        if dists[a][0]+distt[b][0]+d == dst:
          ansls.append(dists[a][1]*distt[b][1]%mod)
for v in range(1,n+1):
  if dists[v][0]*2 == distt[v][0]*2 == dst:
    ansls.append(dists[v][1]*distt[v][1]%mod)
sm = sum(ansls)%mod
ans = sm**2%mod
for i in ansls:
  ans = (ans-i**2)%mod
print(ans)

Measured memory_bytes: 128988
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
b = Counter(a)
ans = 0
X = 0
for i in b.keys():
    if X < b[i-1] + b[i] + b[i+1]:
        X = b[i-1] + b[i] + b[i+1]
print(X)

Measured memory_bytes: 14564
#!/usr/bin/env python3
#ABC139 A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
t = input()

cnt = 0
for i in range(3):
    if s[i] == t[i]:
        cnt += 1
print(cnt)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n, k , temp;
    cin>>n>>k;

    temp=n%k;
    n=temp;
    if(abs(n-k)<temp)
        temp=abs(n-k);
    cout<<temp<<endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
tmp_list = list(map(int, input().split()))
counter = 0
max_num = 0
for i in range(n):
    if tmp_list[i] == 0:
        max_num = max(max_num, counter)
        counter = 0
    else:
        counter += 1
        
max_num = max(max_num, counter)

print(max_num + 1)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int JC(int k)
{  int m=sqrt(k);
   for(int i=2;i<=m;i++)
   {
     if(k%i==0)  return 0;
   } 
   return 1;
}
int main()
{  int n,k=11;
   cin>>n;
   while(n!=0)
   {
     if(JC(k)==1)
	 {
	   cout<<k<<' ';
	   n--;  
	 }  
	 k+=10;
   }
   return 0;
}


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

using namespace std;

int f(int n) {
  int ret = n;
  
  for(int i=2; i*i<=n; i++) {
    if(n % i == 0) {
      ret -= ret / i;
      while(n % i == 0) n /= i;
    }
  }
  if(n != 1)
    ret -= ret / n;
  
  return ret;
}

int main() {
  int tc, n;
  long long dp[1000001];
  
  dp[1] = 2;
  for(int i=1; i<1000000; i++)
    dp[i+1] = dp[i] + f(i+1);
  
  cin >> tc;
  while(tc--) {
    cin >> n;
    cout << dp[n] << endl;
  }
  return 0;
}

Measured memory_bytes: 8964
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, 1, 1,  1,  0, -1,-1,-1};
char charnum[9] = {'0', '1', '2', '3', '4', '5', '6', '7', '8'};

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> board(h);
    rep(y, h) {
        string s;
        cin >> s;
        board[y] = s;
    }

    rep(y, h) {
        rep(x, w) {

            if(board[y][x] == '#') {
                continue;
            }

            int bomb = 0;
            rep(i, 8) {
                int nx = x + dx[i];
                int ny = y + dy[i];
                
                if(nx < 0 || w <= nx || ny < 0 || h <= ny) {
                    continue;
                } 

                if(board[ny][nx] == '#') {
                    bomb++;
                }
            }

            board[y][x] = charnum[bomb];
        }
    }

    rep(y, h) {
        rep(x, w) {
            cout << board[y][x];
        }
        cout << "\n";
    }

    return 0;
}

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

using namespace std;

#define ll long long
#define forn(i, n) for (ll i = 0; i < (ll) n; ++i)
#define sz(a) static_cast<int>(a.size())

char buff[(int) 2e6+ 17];
const ll inf = (ll) 1e9 + 7ll;

const int maxn = (int) 1e5 + 17;

int n, m;
int a[maxn];
vector<int> g[maxn];
bool used[maxn];
multiset<int> kek[maxn];

bool read() {
    if (scanf("%d %d", &n, &m) != 2)
        return false;

    forn (i, n)
        scanf("%d", a + i);

    forn (i, m) {
        int u, v;
        scanf("%d %d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }

    return true;
}

void dfs(int v, int p) {
    used[v] = true;
    kek[p].insert(a[v]);

    for (auto to : g[v])
        if (!used[to])
            dfs(to, p);
}

void solve() {
    forn (i, n)
        if (!used[i])
            dfs(i, i);

    multiset<int> lol;
    int c = 0;
    ll ans = 0;

    forn (i, n)
        if (!kek[i].empty()) {
            ++c;
            ans += *kek[i].begin();
            kek[i].erase(kek[i].begin());

            while (!kek[i].empty()) {
                lol.insert(*kek[i].begin());
                kek[i].erase(kek[i].begin());
            }
        }

    if (c == 1) {
        printf("0\n");
        return ;
    }

    int need = c - 2;

    if (sz(lol) < need) {
        printf("Impossible\n");
        return ;
    }

    while (need > 0) {
        ans += *lol.begin();
        lol.erase(lol.begin());
        --need;
    }

    printf("%lld\n", ans);
}

int main() {
#if SEREZHKA
    freopen("file.in", "r", stdin);
#endif

    while (read())
        solve();

    return 0;
}


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

int main() {
    long long int r = 0, a = 0;
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'W'){
            r += i-a;
            a++;
        }
    }
    cout << r << '\n';
}

Measured memory_bytes: 640
/**
 *   @FileName	e.cpp
 *   @Author	kanpurin
 *   @Created	2020.09.19 21:36:51
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    ll n,x,m;cin >> n >> x >> m;
    vector<ll> a;
    a.push_back(x);
    vector<int> b(m,-1);
    vector<ll> sum(m+1,0);
    int start,end; 
    sum[0] = x;
    for (int i = 0; i <= m; i++) {
        a.push_back(a[i] * a[i] % m);
        sum[i+1] = sum[i] + a[i+1];
        if (b[a[i+1]] != -1) {
            start = b[a[i+1]];
            end = i+1;
            break;
        }
        b[a[i+1]] = i+1;
    }
    if (n-1 <= end) {
        cout << sum[n-1] << endl;
        return 0;
    }
    ll k = sum[end] - sum[start];
    ll t = (n-1-end);
    
    cout << sum[end] + t/(end-start)*k+sum[t%(end-start)+start]-sum[start] << endl;
    return 0;
}

Measured memory_bytes: 4928
#include <iostream>
#include <string>

using namespace std;

bool check(int iI, int iA, int iB, int iC, int iD) {

	if ((iI & 0x01) == 0x01)
		iA += iB;
	else
		iA -= iB;

	if ((iI & 0x02) == 0x02)
		iA += iC;
	else
		iA -= iC;

	if ((iI & 0x04) == 0x04)
		iA += iD;
	else
		iA -= iD;

	return (iA == 7);

}

int main(void) {

	string strLine;
	int iA, iB, iC, iD;
	int iI;

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> strLine;

	iA = strLine[0] - '0';
	iB = strLine[1] - '0';
	iC = strLine[2] - '0';
	iD = strLine[3] - '0';

	for (iI = 0; iI < 8; iI++)
		if (check(iI, iA, iB, iC, iD) == true)
			break;

	cout << iA;
	((iI & 0x01) == 0x01) ? cout << "+" : cout << "-";
	cout << iB;
	((iI & 0x02) == 0x02) ? cout << "+" : cout << "-";
	cout << iC;
	((iI & 0x04) == 0x04) ? cout << "+" : cout << "-";
	cout << iD << "=7\n";

	return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner stdIn = new Scanner(System.in);
		
		while(stdIn.hasNext()) {
			int a = stdIn.nextInt();
			int b = stdIn.nextInt();
			
			System.out.println(a + b);
		}
	}

}

Measured memory_bytes: 20392
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=1e9+7;
const ll ms=1e6+5;
const ll inf=-1e17;

int ar[ms];
ll ss[ms];
ll bb[ms];

int main()
{
    idfc;


    priority_queue<int> q;


    int n;
    cin>>n;
    int i;
    ll a=0;
    for(i=1;i<=n*3;i++)
    {
        cin>>ar[i];
        q.push(-ar[i]);
        a+=ar[i];
        if(q.size()>n)
        {
            a+=q.top();
            q.pop();
        }
        ss[i]=a;
    }
    while(!q.empty())q.pop();
    a=0;
    for(i=n*3;i>=1;i--)
    {
        a+=ar[i];
        q.push(ar[i]);
        if(q.size()>n)
        {
            a-=q.top();
            q.pop();
        }
        bb[i]=a;
    }
    ll ans=LONG_LONG_MIN;
    for(i=n;i<=2*n;i++)
    {
        ans=max(ans,ss[i]-bb[i+1]);
        //cout<<ss[i]<<" "<<bb[i+1]<<"\n";
    }
    cout<<ans;


    return 0;
}

Measured memory_bytes: 9624
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回
// double pi = M_PI or acos(-1)
// printf("%.10f\n", ans);

const int MAX = 1000000001;

int main() {
    int n;
    cin >> n;
    map<ll, int> mp;
    string ans = "YES";
    rep(i, n) {
        ll tmp;
        cin >> tmp;
        if(mp.count(tmp) == 0) {
            mp[tmp] = 1;
        } else {
            ans = "NO";
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 16096