akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

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

	  int N = sc.nextInt();


	  int test = 1;
	  int total = 0;
	  while (test <= N) {
		  int count = 0;
		  for (int i = 1; i <= test ; i++) {
			  if(test % i == 0) {
				  count++;
			  }
			  if (count > 8) {
				  break;
			  }
		  }
		  if (count == 8) {
			  total++;
		  }
		  test = test + 2;
	  }
	  System.out.println(total);


  }
}


Measured memory_bytes: 22740
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
static long factMax = 200000;//nCkにおけるnの最大値
static long[] factorials = new long[factMax+1];//i!(mod p)をO(n)で先にメモ。
static long[] factorialRs = new long[factMax+1];//i!^-1(mod p), pは素数でO(n)。

	static void Main()
	{
    long mod = 1000000007;
    factorials[0] = 1;
    factorialRs[factMax] = DivideModFactorial(factMax,mod);
    for(long i = 1; i <= factMax; i++)
    {
      factorials[i] = (factorials[i-1]*i)%mod;//i!(mod p)
      factorialRs[factMax-i] = (factorialRs[factMax+1-i]*(factMax+1-i))%mod;//逆元も先にメモ
    }
    //ここからCombを使える

		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int k = int.Parse(input[1]);
    long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long answer = 0;

    Array.Sort(nums);
    for(int i = 0; i < n; i++)
    {
      answer += nums[n-1-i] *Comb(n-1-i,k-1,mod);
      answer %= mod;
    }
    for(int i = 0; i < n; i++)
    {
      answer -= nums[i] *Comb(n-1-i,k-1,mod);
      answer %= mod;
      if(answer < 0) answer += mod;
    }

		Console.WriteLine(answer);
	}

  static long MathPow(long x, long a)//戻り値はx^a。O(loga)
  {
    long num = 2;
    long answer = 1;
    long check = a;
    long memo = x;
  
    while(check > 0)
    {
      if(check % num == num / 2)
      {
        check -= num / 2;
        answer *= memo;
      }
    memo *= memo;
    num *= 2;
    }
    return answer;
  }

  static long DivideMod(long x, long a, long p)//戻り値はx^a(mod p)。O(loga)
  {
    long num = 2;
    long answer = 1;
    long check = a;
    long memo = x%p;
    
    while(check > 0)
    {
      if(check % num == num / 2)
      {
        check -= num / 2;
        answer *= memo;
        answer %= p;
      }
    memo *= memo;
    memo %= p;
    num *= 2;
    }
    return answer;
  }

  static long DivideModReverse(long x, long p)//戻り値はx^-1(mod p), pは素数。O(logp)
  {
    long answer = DivideMod(x, p-2, p);
    return answer;
  }

  static long ModFactorial(long x, long p)//戻り値はx!(mod p)
  {
    long answer = 1;
    for(int i = 2; i <= x; i++)
    {
      answer *= i;
      answer %= p;
    }
    return answer;
  }

  static long DivideModFactorial(long x, long p)//戻り値はx!^-1(mod p), pは素数
  {
    long answer = 1;
    for(long i = x; i >= 2; i--)
    {
      answer *= DivideModReverse(i, p);
      answer %= p;
    }
    return answer;
  }

  static long Comb(long a, long b, long p)//組み合わせC(a,b)(mod p)をO(1)で返す
  {
    if(a-b < 0) return 0;//引数a-bが負なら0を返す
    long answer = 1;
    answer *= factorials[a];
    answer %= p;
    answer *= factorialRs[a-b];
    answer %= p;
    answer *= factorialRs[b];
    answer %= p;
    return answer;
  }

  
}

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

int main() {
	int N, M;
	long x[1010][3];
	cin >> N >> M;
	for(int i=0; i<N; ++i) cin >> x[i][0] >> x[i][1] >> x[i][2];
	long ans=0;
	for(int t=0; t<8; ++t){
	    priority_queue<long> pq;
	    for(int i=0; i<N; ++i){
	        long ire=0;
	        for(int g=0; g<3; ++g){
	            if(t&(1<<g)) ire += x[i][g];
	            else ire -= x[i][g];
	        }
	        pq.push(ire);
	    }
	    long now=0;
	    for(int i=0; i<M; ++i){
	        now += pq.top();
	        pq.pop();
	    }
	    ans=max(ans, now);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.buffer.readline

N, M = map(int, input().split())
nextcity = [[] for _ in range(N)]
sgn = [0 for _ in range(N)]
while M:
	M -= 1
	A, B = map(int, input().split())
	A -= 1
	B -= 1
	nextcity[A].append(B)
	nextcity[B].append(A)

def dfs(cnt, city):
	for item in nextcity[city]:
		if sgn[item] == 0:
			sgn[item] = cnt
			dfs(cnt, item)
	return None

cnt = 0
for k in range(N):
	if sgn[k] == 0:
		cnt += 1
		sgn[k] = cnt
		dfs(cnt, k)
print(cnt -1)


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

int main(){
  int N;
  cin>>N;
  map<char,int> A;
  for(int i=0;i<N;i++){
    char c;
    cin>>c;
    A[c]++;
  }
  int64_t k=1;
  for(pair<char,int> i:A){
    k*=(i.second+1);
    k=(k-1)%1000000007+1;
  }
  cout<<k-1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 //Compiler version g++ 6.3.0
 struct drink{
 	ll v;
 	ll h;
 	drink(ll inputted_v, ll inputted_h)
    {
        v = inputted_v;
        h = inputted_h;
    }
 	bool operator<(const drink &another) const
    {
        return v < another.v;
    };
 };
 int main()
 {
 	ll n,m,ans=0;
 	cin >> n>>m;
 	vector <drink> a;
 	for (int i = 0; i < n; i++){
 		ll x,y;
 		cin >> x>>y;
 		drink z={x,y};
 		a.push_back(z);
 	}
 	sort(a.begin(),a.end());
 	for (auto itr : a){
 		if(itr.h<m){
 			m-=itr.h;
 			ans+=itr.v*itr.h;
 		}else{
 			ans+=itr.v*m;
 			cout << ans << endl;
 			return 0;
 		}
 	}
 }

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

int n, m;
int W[1500], H[1500];
vector<int> hh;
vector<int> ww;

void solve(int N, int M) {
    hh.clear();
    ww.clear();
    for(int i = 0; i < N; i++) {
        cin >> W[i];
    }
    for(int i = 0; i < M; i++) {
        cin >> H[i];
    }

    for(int i = 0; i < N; i++) {
        int now = 0;
        for(int j = i + 1; j <= N; j++) {
            now += W[j - 1];
            ww.push_back(now);
        }
    }

    for(int i = 0; i < M; i++) {
        int now = 0;
        for(int j = i + 1; j <= M; j++) {
            now += H[j - 1];
            hh.push_back(now);
        }
    }

    sort(ww.begin(), ww.end());
    sort(hh.begin(), hh.end());

    int ans = 0;
    for(int wi = 0, hi = 0; wi < ww.size() && hi < hh.size(); wi++, hi++) {
        while(wi < ww.size() && hi < hh.size() && ww[wi] != hh[hi]) {
            if(hh[hi] < ww[wi])
                hi++;
            else
                wi++;
        }

        if(wi < ww.size() && hi < hh.size() && ww[wi] == hh[hi]) {
            int wc = 1, hc = 1;
            int v = ww[wi];
            while(wi < ww.size() - 1 && ww[wi + 1] == v) {
                wi++;
                wc++;
            }
            while(hi < hh.size() - 1 && hh[hi + 1] == v) {
                hi++;
                hc++;
            }
            ans += wc * hc;
        }
    }
    cout << ans << endl;
}

int main() {
    while(true) {
        cin >> n >> m;
        if(n == m && n == 0)
            break;
        solve(n, m);
    }
}


Measured memory_bytes: 15748
n = gets.chomp
s = n.size
count = 0
st = 3
while true
    if n.to_i >= 357
        ["3","5","7"].repeated_permutation (st) do |i|
            if i.count("7") >= 1 && i.count("5") >= 1&& i.count("3") >= 1
                ii = i.join("").to_i
                if ii <= n.to_i
                    count += 1
                end
            end
        end
    else
        count = 0
        break
    end
    if st == s
        break
    end
st += 1
end

puts count

Measured memory_bytes: 14264
#include <bits/stdc++.h>
#define MAXTIME 200005
using namespace std;
typedef long long ll;

int main(){
    int N, C;
    cin >> N >> C;
    vector<vector<int> > channel(30, vector<int>(MAXTIME));
    for(int i=0;i<N;i++){
        int s, t, c;
        cin >> s >> t >> c;
        channel[c-1][2*s-1] = 1;
        channel[c-1][2*t] = -1;
    }
    vector<int> arr(MAXTIME,0);
    for(int i=0;i<MAXTIME-1;i++){
        for(int j=0;j<C;j++){
            if(channel[j][i]==1 && channel[j][i+1]==-1){channel[j][i]=0;channel[j][i+1]=0;}
            else{arr[i] += channel[j][i];}
        }
    }
    int ans = 0;
    for(int i=1;i<MAXTIME;i++){
        arr[i] += arr[i-1];
        ans = max(ans,arr[i]);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 24576
import numpy as np
import sys
A=a=int(input())
count=2
samenumcount=0
y=[]
 
if A==1:
    print(0)
    sys.exit()
 
while A!=1 and count<np.sqrt(a):
    if A%count==0:
        samenumcount+=1
        y.append(count**samenumcount)
        A=A/count
    else:
        count+=1
        samenumcount=0
if A!=1:
    y.append(A)
y.sort()
count2=0
for i in y:
    if a==1:
      break
    if a%i==0:
        a=a/i
        count2+=1
 
if count2==0:
    count2+=1

print(count2)

Measured memory_bytes: 27120
#include<stdio.h>
#include<string.h>
#pragma warning(disable:4996)
int main()
{
	int N;
	int a[100][10];
	int b[100][11];
	int n = 10;
	scanf("%d", &N);
	getchar();
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			scanf("%d", a[i] + j);
		}
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < 11; j++)
		{
			scanf("%d", &b[i][j]);
		}
	} 
	//此乃二进制枚举也
	long long bb = 0, dd, ii;
	int h[10];
	for (long long i = 1; i < (1 << n); i++)
	{
		//这些个数列（十位，二进制）
		for (int j = 0; j < 10; j++)
		{
			if (i&(1 << j))
			{
				h[9 - j] = 1;
			}
			else
			{
				h[9 - j] = 0;
			}
		}
		//生成一个数列
		for (int g = 0; g < N; g++)
			//N个店
		{
			bb = 0;
			for (int p = 0; p < 10; p++)
			{
				if (h[p] & a[g][p])
				{
					bb++;
				}
			}
			//这个数列和原始数列同为1的个数
			if (g == 0)
			{
				dd = b[g][bb];
			}
			else
			{
				dd += b[g][bb];
			}
		}
		if (i == 1)
		{
			ii = dd;
		}
		else if (ii < dd)
		{
			ii = dd;
		}
	}
	printf("%d\n",ii);
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 128
s = input()

# patarn of 010101...
a1 = 0
for i, item in enumerate(s):
    # i is even, s[i] should 0
    if i % 2 == 0 and item != "0":
        a1 += 1

    if i % 2 == 1 and item != "1":
        a1 += 1

# patarn of 101010...
a2 = 0
for i, item in enumerate(s):
    # i is even, s[i] should 0
    if i % 2 == 0 and item != "1":
        a2 += 1

    if i % 2 == 1 and item != "0":
        a2 += 1
print(min(a1, a2))



Measured memory_bytes: 41328
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

// Created by White Knife on 15/04/20.
// doot diddly donger cuckerino Hahahahahah

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

// @formatter:off
#define F               first
#define S               second
#define all(x)          (x).begin(), (x).end()
#define sz(x)           (long long) (x).size()
#define sim             template<typename T
#define ris             return *this
#define dor             > debug & operator <<
#define eni(x)          sim > typename enable_if<sizeof dud<T>(0) x 1, debug&>::type operator<<(T i)
sim> struct rge { T b, e; };
sim> rge<T> rang(T i, T j) { return rge<T>{i, j}; }
sim> auto dud(T *x) -> decltype(cerr << *x, 0);
sim> char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) { cerr << boolalpha << i; ris; }
  eni(==) { ris << rang(all(i)); }
  sim, typename U dor(pair<U, T> d) { ris << "(" << d.first << ", " << d.second << ")"; }
  sim dor(rge<T> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
  sim dor(const T&) { ris; }
#endif
};
#define pr(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ull = unsigned long long;
using ld = long double;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vb = vector<bool>;

using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ld PI = acos(-1);

template<typename T> inline T mini(T& x, T y) { return x = min(x, y); }
template<typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
template <typename T> T rand(T x, T y) { return rand() % (y - x + 1) + x; }
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

// @formatter:on


class DAlterAltar {
public:
  
  void solve(std::istream& cin, std::ostream& cout) {
    int n;
    string s;
    cin >> n >> s;
    int i = 0, j = n - 1;
    int ans = 0;
    while (i < j) {
      while (i < j and s[i] != 'W') i++;
      while (j > i and s[j] != 'R') j--;
      if (i >= j) break;
      swap(s[i], s[j]);
      debug() << pr(i) pr(j) pr(s[i]) pr(s[j]);
      i++;
      j--;
      ++ans;
    }
    cout << ans << '\n';
  }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
	DAlterAltar solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

using pll = pair<long long, long long>;

int main() {
    int N, M; cin >> N >> M;
    vector<pll> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i].first >> A[i].second;
    sort(A.begin(), A.end());
    long long res = 0;
    for (int i = 0; i < N; ++i) {
        if (M >= A[i].second) {
            res += A[i].first * A[i].second;
            M -= A[i].second;
        }
        else {
            res += A[i].first * M;
            break;
        }
    }
    cout << res << endl;
}













Measured memory_bytes: 1792
#include<stdio.h>

int main(){

	int a,b,c,d;

	scanf("%d", &a);

	b = a / 3600;
	c = (a-b*3600)/60;
	d = (a - b * 3600)-c * 60;

	printf("%d:%d:%d\n", b,c,d);

	return 0;
}

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

int main() {
    int n,T;
    cin >> n >> T;
    vector<int> c(n);
    vector<int> t(n);
    for(int i=0;i<n;i++){
        cin >> c.at(i) >> t.at(i);
        if(t.at(i)>T){
            c.at(i)=1001;
        }
    }
    sort(c.begin(),c.end());
    if(c.at(0)==1001) cout << "TLE" << endl;
    else cout << c.at(0) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
//ll arr[1000002];
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
string s;
ll i,a,b,c,d,k,r,n,ans=0;
cin>>s;
n=s.size();
if(s.size()<3)
{
    cout<<0<<endl;
    return 0;
}
i=0,c=0,d=0;
while(i<n)
{
    if(s[i]=='A')
    {
        while(i<n && s[i]=='A')
        {
            c++;
            i++;
        }
        continue;
    }
    if(c!=0 && s[i]=='B' && i+1<n && s[i+1]=='C')
    {
        while(i<n && s[i]=='B' && i+1<n && s[i+1]=='C' )
        {
            d++;
            i=i+2;
        }
        ans=ans+c*d;
        d=0;
        if(i<n && s[i]!='A')
            c=0;
        continue;
    }
    else if(c!=0)
    {
        c=0;
        i++;
        continue;
    }
    i++;
}
cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;

int main()
{
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
        sum+=i;
    }


    cout<<sum<<endl;




    return 0;
}


Measured memory_bytes: 3636
import java.util.*;
public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int a =Integer.parseInt(scan.next());
		int b =Integer.parseInt(scan.next());

		int c=Integer.parseInt(scan.next());
		int d=Integer.parseInt(scan.next());

		while(true){
			c-=b;
			if (c <=0){
				System.out.print("Yes");
				break;
			}
			a-=d;
			if (a <=0){
				System.out.print("No");
				break;
			}
		}

	}
}
//end


Measured memory_bytes: 35704
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int n, a, b, c, d;

bool dfs(ll sum = 0, int cur = 0) {
    if (cur == n-1) {
        if (sum == b-a) return true;
        else return false;
    }
    bool res = false;
    for (int x = c; x <= d; x++) {
        if (dfs(sum+x,cur+1)) res = true;
        if (dfs(sum-x,cur+1)) res = true;
    }
    return res;
}

int main() {
    cin >> n >> a >> b >> c >> d;
    n--;
    bool ok = false;
    for (int x = 0; x <= n; x++) {
        ll lb = (ll)x*(c+d)-(ll)n*d;
        ll ub = (ll)x*(c+d)-(ll)n*c;
        if (lb <= b-a && b-a <= ub) ok = true;
    }
    if (ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    cout << ((S[0]!=S[1] || S[1]!=S[2])? "Yes":"No") << "\n";
}

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

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n), b(n), c(m), d(m);
    rep(i,n) cin >> a[i] >> b[i];
    rep(i,m) cin >> c[i] >> d[i];
    rep(i,n) {
        ll mn = 1e18;
        int ans;
        rep(j,m) {
            ll dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if(mn > dist) {
                mn = dist;
                ans = j+1;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
 
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
 
int main() {
  int n, q;
  cin >> n >> q;
  vector<vector<int>> graph(n, vector<int>{});
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    graph[b - 1].push_back(a - 1);
    graph[a - 1].push_back(b - 1);
  }
  vector<long long> point(n);
 
  rep(i, q) {
    int p, x;
    cin >> p >> x;
    point[p - 1] += x;
  }
 
  vector<bool> seen(n, false);
  queue<int> que;
  que.push(0);
  seen[0] = true;
 
  while (!que.empty()) {
    int curr = que.front();
    que.pop();
    long long curr_point = point[curr];
    for (auto &next : graph[curr]) {
      if (!seen[next]) {
        point[next] += curr_point;
        que.push(next);
        seen[next] = true;
      }
    }
  }
  print(point);
}

Measured memory_bytes: 16372
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;

ll mod = 1e9 + 7;

ll power(ll x, ll y)
{
    ll res = 1;
    while (y) {
        if (y&1)
            res = (res*x) % mod;
        y >>= 1;
        x = (x*x)%mod;
    }
    return res;
}

void solve()
{
    ll n;
    cin >> n;
    if (n==1) {
        cout << "0\n";
        return;
    }
    ll ans = (power(10,n) + power(8,n))%mod;
    ans = ans - ((2*power(9,n))%mod);
    while (ans < 0) ans += mod;
    cout << ans << '\n';
}

int main()
{
    fastIO;
    int t=1;
    // cin >> t;
    while (t--) {
        solve();
    }   
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

const int MAX_N = 100005;

class segTree{
    public:
        int n, dat[4 * MAX_N];
        virtual int query(int, int, int, int, int) = 0;
        void init(int n_){}
        void init(int a[MAX_N], int n_){
            n = 1;
            while(n <= n_) n *= 2;
            for(int i = n; i < n * n; i++){
                dat[i] = a[i - n];
            }
            for(int i = n - 1; i >= 1; i--){
                dat[i] = min(dat[i * 2], dat[i * 2 + 1]);
            }
        }
};

class rangeAddQuery : public segTree{
    private:
        int dat_add[4 * MAX_N];
        int query(int a, int b, int k, int l, int r){
            if(b <= l || r <= a) return 0;
            else if(a <= l && r <= b) return dat[k] * (r - l) + dat_add[k];
            else{
                int res = (min(b, r) - max(a, l)) * dat[k];
                res += query(a, b, k * 2, l, (l + r) / 2);
                res += query(a, b, k * 2 + 1, (l + r) / 2, r);
                return res;
            }
        }
        void add(int a, int b, int k, int l, int r, int x){
            if(a <= l && r <= b){
                dat[k] += x;
            }else if(l < b && a < r){
                dat_add[k] += (min(b, r) - max(a, l)) * x;
                add(a, b, k * 2, l, (l + r) / 2, x);
                add(a, b, k * 2 + 1, (l + r) / 2, r, x);
            }
        }
    public:
        void init(int n_){
            n = 1;
            while(n <= n_) n *= 2;
            rep(i,2 * n) dat[i] = dat_add[i] = 0;
        }

        void update(int i, int x){
            add(i, i + 1, 1, 0, n, x);
        }
        int query(int a, int b){
            return query(a,b,1,0,n);
        }
        void add(int s, int t, int x){
            add(s, t, 1, 0, n, x);
        }
        int get(int a){ return query(a, a + 1); }
};

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

    vector<pair<int, int>> v[100005]; //v[区間の長さ] = (l, r)
    rep(i,n){
        int l, r;
        cin >> l >> r;
        v[r - l + 1].emplace_back(make_pair(l, r));
    }

    rangeAddQuery seg;
    seg.init(m);

    int segment_num = n;
    range(i,1,m + 1){
        int ret = 0;
        for(int j = i; j <= m; j+=i) ret += seg.get(j);
        //show(i)
        //show(ret)
        //show(seg.get(3))
        for(auto e : v[i]){
            //show(i)
            //cout << e.first << ' ' << e.second << endl;
            seg.add(e.first, e.second + 1, 1);
        }
        cout << segment_num + ret << endl;
        segment_num -= v[i].size();
    }
}


Measured memory_bytes: 10240
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,m,sum=0;
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        cin>>m;
        sum+=m;
    }
    cout<<sum-n<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(input())
    T = [0] * (N+1)
    XY = [[0,0] for _ in range(N+1)]
    ans = 'Yes'
    for i in range(1,N+1):
        T[i],XY[i][0],XY[i][1] = map(int, input().split())
    for i in range(N):
        t = T[i+1] - T[i]
        d = abs(XY[i+1][0]-XY[i][0]) + abs(XY[i+1][1]-XY[i][1])
        if t<d or (t-d)%2==1:
            ans = 'No'

    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 20372
N = int(input())
A = list(map(int,input().split()))
count = 0
flag = True
while(flag):
    for i in range(N):
        if A[i] % 2 == 0:
            A[i] = A[i]/2
        else:
            flag = False
            break
    if flag == True:
        count+=1
print(count)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  while(true){
    if(a+1<b)a++;
    else{
      puts("Borys");return 0;
    }
    if(a<b-1)b--;
    else{
      puts("Alice");return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int x, y, a;
	while(1){
		scanf("%d%d", &x, &y);
		if(x==0 && y==0) break;
		if(x > y){
			a=x; x=y; y=a;
		}
		printf("%d %d\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
double a[200005];
int main(){
    string s;
    cin>>s;
    ll k;
    cin>>k;
    ll n=s.length();
    if(k==1){
        cout<<(s[0]-'0')+(n-1)*9<<endl;
    }
    if(k==2){
        ll num=n-k;
        num=(num*(num+1))/2;
        num*=(ll)81;
        ll pos=1;
        while(pos<n&&s[pos]=='0') pos++;
        if(pos!=n){
            num+=(ll)(s[pos]-'0');
            num+=(n-pos-1)*(ll)9;
        }
        for(ll i=1;i<(ll)(s[0]-'0');i++){
            num+=(n-1)*(ll)9;
        }
        cout<<num<<endl;
    }
    if(k==3){
        ll num=0;
        for(ll i=2;i<n-1;i++){
            num+=(i*(i-1))/2;
        }
        num*=(ll)729;
        ll cnt=0;
        for(ll i=1;i<n;i++){
            if(cnt==2) break;
            if(s[i]!='0'){
                cnt++;
                if(cnt==1){
                    num+=((n-i-1)*(n-i-2))/2*81;
                    num+=((s[i]-'0')-1)*(n-i-1)*9;
                }
                if(cnt==2){
                    num+=s[i]-'0'+(n-i-1)*9;
                }
            }
        }
        for(ll i=1;i<(ll)(s[0]-'0');i++){
            num+=((n-1)*(n-2))/2*(ll)81;
        }
        cout<<num<<endl;
    }
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
S = input()
c = Counter(S)
ans = c['R'] * c['G'] * c['B']

for s in range(N-2):
    for d in range(1, (N-1-s)//2+1):
        t = s + d
        u = t + d
        if S[s] != S[t] and S[t] != S[u] and S[u] != S[s]:
            ans -= 1
print(ans)


Measured memory_bytes: 74160
a = []
for i in iter(input, '-1 -1 -1'):
    a.append(list(map(int, i.split())))
for i in range(len(a)):
    if (a[i][0] == -1) | (a[i][1] == -1):
        print('F')
    elif a[i][0]+a[i][1] >= 80:
        print('A')
    elif 65 <= a[i][0]+a[i][1] < 80:
        print('B')
    elif (50 <= a[i][0]+a[i][1] < 65) | ((30 <= a[i][0]+a[i][1] < 50) & (a[i][2] >= 50)):
        print('C')
    elif 30 <= a[i][0]+a[i][1] < 50:
        print('D')
    else:
        print('F')


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

int main() {
	// freopen("input.txt", "r", stdin);

	int N, K;
	scanf("%d %d", &N, &K);

	string S;
	cin >> S;
	S[K - 1] = tolower(S[K - 1]);
	puts(S.c_str());
	return 0;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d", $n);
$input = trim(fgets(STDIN));
$a_arr = explode(' ', $input);

$multi = 1;
foreach ($a_arr as $a) {
    $multi *= $a;
}

$child = 0;
foreach ($a_arr as $a) {
    $child += $multi / $a;
}

echo $multi / $child;


Measured memory_bytes: 4604
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import sys

N = int(input())
A = [int(x) for x in input().split()]

if len(A) != N:
  print("[ERROR] Number of Input integer is invalid")
  sys.exit()

for i in range(N):
  v = A[i]
  j = i - 1
  while j >= 0 and A[j] > v:
    A[j + 1] = A[j]
    j -= 1
  A[j + 1] = v

  print(' '.join(map(str, A)))



Measured memory_bytes: 5612
import sys
import bisect
input = sys.stdin.readline

N = int(input())
A = sorted([int(x) for x in input().strip().split()])
B = sorted([int(x) for x in input().strip().split()])
C = sorted([int(x) for x in input().strip().split()])

ans = 0
for b in B:
    a_ind = bisect.bisect_left(A, b)
    c_ind = bisect.bisect_right(C, b)
    ans += a_ind * (N - c_ind)

print(ans)



Measured memory_bytes: 22720
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<initializer_list>
#include<map>
#include<set>
#include<utility>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define llong long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()

int dfs(vector<int>fixed, vector<int>free) {
	vector<int>lf(fixed);
	if (free.size() == 0) {
		int m = 1000;
		if (free.size() != 1) {
			sort(all(fixed));
			int n = fixed.size();
			rep(i, n - 1) {
				for (int j = i + 1; j < n; j++) {
					int d = fixed[j] - fixed[i];
					m = min(m, min(d, 24 - d));
				}
			}
		}
		else m = free.front();

		return min(m, 24 - m);
	}
	else {
		vector<int>c1(fixed);
		vector<int>c2(fixed);
		c1.push_back(free.front());
		c2.push_back(24 - free.front());
		free = vector<int>(free.begin() + 1, free.end());
		return max(dfs(c1, free), dfs(c2, free));

	}

}
int main() {
	// wa torenai
	int n;
	cin >> n;
	vector<int>d(n);
	rep(i, n)cin >> d[i];
	vector<int>c(13, 0);
	rep(i, n) c[d[i]]++;
	int m = c.size();
	if (c[0] >= 1 || c[12] >= 2 || *max_element(all(c)) >= 3) {
		cout << 0 << endl;
		return 0;
	}

	vector<int> free;
	vector<int> fixed;
	fixed.push_back(0);//this is takahashi
	if (c[12] != 0)fixed.push_back(12);
	for (int i = 1; i < m - 1; i++) {
		if (c[i] == 1) {
			free.push_back(i);
		}
		else if (c[i] == 2) {
			fixed.push_back(i);
			fixed.push_back(24 - i);
		}
	}
	cout << dfs(fixed, free) << endl;
	return 0;
}





Measured memory_bytes: 256
/*input
6
30 10 60 10 60 50
*/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits>

using namespace std; 

int GCD(int x,int y){return y?GCD(y,x%y):x;}
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,a,b) for(int i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define rept(v) for(auto it=v.begin();it<v.end();it++)
#define all(v) v.begin(),v.end()
const int INF = 1<<30;
typedef long long ll;
typedef pair<int,int> pii;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	int n;
	cin >> n;
	int a[n+1];
	rep(i, n) cin >> a[i+1];
	int dp[n+1];
	dp[0]=0;a[0]=a[1];
	repl(i, 1, n+1) {
		dp[i]=INF;
		if(i-1>=0) dp[i]=min(dp[i], dp[i-1]+abs(a[i-1]-a[i]));
		if(i-2>=0) dp[i]=min(dp[i], dp[i-2]+abs(a[i-2]-a[i]));
	}
	cout << dp[n];
	return 0;
}

Measured memory_bytes: 4392
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;


template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "{";
    for (int i = 0; i < v.size(); ++i) {
        if(i) os << ", ";
        os << v[i];
    }
    return os << "}";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "{" << p.first << ", " << p.second << "}";
}


int main() {
    int a, b;
    while(cin >> a >> b){
        string ans;
        map<int, int> m;
        int cur = 0;
        while(!m.count(a) && a){
            m[a] = cur++;
            a *= 10;
            ans += a/b+'0';
            a %= b;
        }
        cout << ans << "\n";
        if(a){
            for (int i = 0; i < ans.size(); ++i) {
                if(i < m[a]) putchar(' ');
                else putchar('^');
            }
            puts("");
        }
    }
    return 0;
}


Measured memory_bytes: 3040
a=[11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381];print(*a[:int(input())], sep=' ')

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

using namespace std;

int n;
int f[110][10];
int p[110][11];

int main(void) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> f[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }

  int ans = -1e9;
  for (int i = 1; i < 1 << 10; i++) {
    int g[10] = {};
    for (int j = 0; j < 10; j++) {
      if (i >> j & 1) g[j] = 1;
    }

    int cnt[110] = {};
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < 10; k++) {
        cnt[j] += (g[k] == 1 && f[j][k] == 1);
      }
    }

    int sum = 0;
    for (int j = 0; j < n; j++) {
      sum += p[j][cnt[j]];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <cstring>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define DEB 1
#define all(x) x.begin(), x.end()

const int dx[] = {0,1,0,-1};
const int dy[] = {-1,0,1,0};
int w,h,sx,sy,gx,gy;
int field[10][10];
int memo[7][10][10];

class State{
public:
  int x,y,life;
  State(int _x, int _y, int _l){
    x=_x; y=_y; life=_l;
  }
};

int main(){

  while(scanf("%d%d",&w,&h),w|h){
    rep(k,7)rep(i,10)rep(j,10)memo[k][i][j]=INT_MAX;
    rep(i,h){
      rep(j,w){
	scanf("%d",&field[i][j]);
	if( field[i][j]==2 ){
	  sx=j; sy=i;
	}else if( field[i][j]==3 ){
	  gx=j; gy=i;
	}
      }
    }
    
    int ans = INT_MAX;
    queue<State> q;
    q.push(State(sx,sy,6));
    memo[6][sy][sx] = 0;
    while( !q.empty() ){
      int x = q.front().x;
      int y = q.front().y;
      int life = q.front().life;
      int c = memo[life][y][x];
      q.pop();
      if( life==1 )continue;

      rep(k,4){
	int tx = x + dx[k];	
	int ty = y + dy[k];
	if( tx<0 || ty<0 || tx>=w || ty>h || field[ty][tx]==0 )continue;
	if( field[ty][tx]==1 ){
	  if( memo[life-1][ty][tx] > c+1 ){
	    memo[life-1][ty][tx] = c+1;
	    q.push(State(tx,ty,life-1));
	  }
	}else if( field[ty][tx]==4 ){
	  if( memo[6][ty][tx] > c+1 ){
	    memo[6][ty][tx] = c+1;
	    q.push(State(tx,ty,6));
	  }
	}else if( field[ty][tx]==3 ){
	  ans = min(ans,c+1);
	  break;
	}else if( field[ty][tx]==2 ){
	  if( memo[life-1][ty][tx] > c+1 ){
	    memo[life-1][ty][tx] = c+1;
	    q.push(State(tx,ty,life-1));
	  }
	}
      }
    }
    printf("%d\n",ans==INT_MAX?-1:ans);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  ll n;
  cin >> n;

  vector<bool> plus(24);
  vector<bool> minus(24);
  vector<ll> pos(24);
  vector<ll> neg(24);
  pos[0] = 1;
  neg[0] = 2;
  for (int i = 1; i < 24; i++) {
    pos[i] = pos[i-1] * 4;
    neg[i] = neg[i-1] * 4;
  }

  ll a = 0;
  for (int i = 0; i < 24; i++) {
    a -= neg[i];
    minus[i] = true;
  }
  for (int i = 23; i >= 0; i--) {
    if (a + neg[i] <= n) {
      a += neg[i];
      minus[i] = false;
    }
    if (a + pos[i] <= n) {
      a += pos[i];
      plus[i] = true;
    }
  }

  vector<int> ans;
  for (int i = 23; i >= 0; i--) {
    if (minus[i]) ans.push_back(1);
    else if (ans.size() > 0) ans.push_back(0);
    if (plus[i]) ans.push_back(1);
    else if (ans.size() > 0) ans.push_back(0);
  }
  if (ans.size() == 0) ans.push_back(0);

  for (auto &x: ans) cout << x;
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int N;
	
	int count=0;
	cin >> N;
	int* A = new int[N];
	for (int i = 0;i < N;i++) {
		cin >> A[i];
		if (A[i] % 2 == 1)
			count++;
	}
	if (count % 2 == 0) cout << "YES";
	else cout << "NO";
	

}

Measured memory_bytes: 4036
N,M = list(map(int, input().split()))
AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))
AB = sorted(AB)

n = 0
result = 0

while M > 0:
    if AB[n][1] <= M:
        result += AB[n][0] * AB[n][1]
        M -= AB[n][1]
        n += 1
    else:
        result += AB[n][0] * M
        break

print(result)

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

int main(){
  int n;
  cin >> n;
  vector<int> an(n), bn(n), cn(n);
  for(int i=0; i<n; ++i) cin >> an[i];
  for(int i=0; i<n; ++i) cin >> bn[i];
  for(int i=0; i<n; ++i) cin >> cn[i];
  sort(an.begin(),an.end());
  sort(bn.begin(),bn.end());
  sort(cn.begin(),cn.end());
  vector<ll> btot(n);
  for(int i=0; i<n; ++i){
    int x = bn[i];
    auto it = lower_bound(an.begin(),an.end(),x);
    btot[i] = it - an.begin();
    if(i>0) btot[i] += btot[i-1];
  }
  ll ans = 0;
  for(int i=0; i<n; ++i){
    int x = cn[i];
    auto it = lower_bound(bn.begin(),bn.end(),x);
    if(it - bn.begin() > 0) ans += btot[it - bn.begin() -1];
  }
  cout << ans << endl;
}

Measured memory_bytes: 5108
#include<iostream>
#include<algorithm>
using namespace std;
long long a[10];
int main() {
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < 3; i++) {
		if (a[i] % 2 == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	sort(a, a + 3);
	cout << a[0] * a[1] << endl;
}

	

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const int MAX_N=pow(2,18)+2;


long used[(int)1e6+3];
long mp[(int)1e6+3];
int main(){
    int N;
    cin>>N;
    CLR(used);CLR(mp);
    vector<long>A(N);
    set<long>st1;
    REP(i,N){
        cin>>A[i];used[A[i]]++;
    }
    REP(i,N){
        for(long tt=1;tt*tt<=A[i];tt++){
            if(A[i]%tt==0){
                if(tt*tt==A[i]){
                    if(used[tt])mp[A[i]]++;
                }else{
                    if(used[A[i]/tt])mp[A[i]]++;
                    if(used[tt])mp[A[i]]++;
                }
            }
        }
    }
    int res=0;
    REP(i,N){
        if(mp[A[i]]<=1){
            res++;
        }
    }
    cout<<res<<endl;
    return 0;
}


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

#define ll long long
#define db double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 4003;
int n, p[3][N];
int ch[256];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	ch['R'] = 0;
	ch['G'] = 1;
	ch['B'] = 2;
	string s;
	cin >> n >> s;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 3; j++) {
			p[j][i] = p[j][i - 1];
		}
		p[ch[s[i - 1]]][i]++;
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int k = i + 2; k <= n; k++) {
			if (s[i - 1] == s[k - 1]) {
				continue;
			}
			int lf = 3 - (ch[s[i - 1]] + ch[s[k - 1]]);
			int res = p[lf][k - 1] - p[lf][i - 1];
			if ((i + k) % 2 == 0) {
				int j = (i + k) / 2;
				if (ch[s[j - 1]] == lf) {
					res--;
				}
			}
			ans += res;
		}
	}
	cout << ans;
}


Measured memory_bytes: 3704
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

vector<bool> isp(101, true);
vector<vector<int>> yaku;

void sieve() {
  isp[0] = false;
  isp[1] = false;
  for (int i=2; pow(i,2)<=100; i++) {
    if (isp[i]) for(int j=2; i*j<=100; j++) isp[i*j] = false;
  }
}

int num(int n) {
  int result = 0;
  for (auto x: yaku) if (x[1]>=n-1) result++;
  return result;
}

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

  sieve();
  rep(i, 101) if (isp[i]) yaku.push_back({i,0});
  rep(i, yaku.size()) {
    int tmp = N;
    while (tmp!=0) {
      yaku[i][1] += tmp/yaku[i][0];
      tmp /= yaku[i][0];
    }
  }

  int result = 0;
  result += num(75);
  result += num(25) * (num(3)-1);
  result += num(15) * (num(5)-1);
  result += num(5) * (num(5)-1) * (num(3)-2) / 2;
  cout << result << endl;
  return 0;
}

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

int main()
{
  ll x, y, a, b, c; cin >> x >> y >> a >> b >> c;
  vector<int> aa(a);
  vector<int> bb(b);
  vector<int> cc(c);
  rep(i, a) cin >> aa[i];
  rep(i, b) cin >> bb[i];
  rep(i, c) cin >> cc[i];
  sort(aa.rbegin(),aa.rend());
  sort(bb.rbegin(),bb.rend());
  sort(cc.rbegin(),cc.rend());
  vector<int> v;
  rep(i, x) v.push_back(aa[i]);
  rep(i, y) v.push_back(bb[i]);
  rep(i, c) v.push_back(cc[i]);
  sort(v.rbegin(),v.rend());
  ll ans = 0;
  rep(i, x+y) ans+=v[i];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3572
x, y = [int(x) for x in input().split()]
a = b = 0
flag = False
for i in range(x + 1 // 2):
    a = x - i
    b = x - a
    if 4 * a + 2 * b == y or 4 * b + 2 * a == y:
        flag = True
        break
print("Yes" if flag else "No")


Measured memory_bytes: 9204
from sys import stdin

def main():

    input = stdin.readline

    S = input()[:-1]
    Q = int(input())
    
    query = [0] * Q
    ans_list = []

    reverse_flag = False

    mae = []
    ushiro = []

    for i in range(Q):
        query = input().split()
        if(query[0] == '1'):
            reverse_flag = not reverse_flag
        else:
            if reverse_flag is True:
                if(query[1] == '1'):
                    ushiro.append(query[2])
                else:
                    mae.append(query[2])                
            else:
                if(query[1] == '1'):
                    mae.append(query[2])
                else:
                    ushiro.append(query[2])
    
    ans_list = "".join(mae[::-1]) + S + "".join(ushiro)
    
    if(reverse_flag is not True):
        print(''.join(ans_list))
    else:
        print(''.join(ans_list[::-1]))


if __name__ == "__main__":
    main()

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

double eps = 1e-10;

class Point {
public:
	double x, y;
	
	Point(double x = 0, double y = 0) : x(x), y(y) {}
	
	Point operator + (const Point& p) {
		return Point(x + p.x, y + p.y);
	}
	Point operator - (const Point& p) {
		return Point(x - p.x, y - p.y);
	}
	Point operator * (const double& a) {
		return Point(x * a, y * a);
	}
	Point operator / (const double& a) {
		return Point(x / a, y / a);
	}
	
	bool operator < (const Point& p) const {
		return x != p.x ? x < p.x : y < p.y;
	}
	bool operator == (const Point& p) const {
		return fabs(x - p.x) < eps && fabs(y - p.y) < eps;
	}
	
	double abs() {
		return sqrt(norm());
	}
	double norm() {
		return x * x + y * y;
	}
	
};

typedef Point Vector;

// ????????????
bool equals(const double& a, const double& b) {
	return fabs(a - b) < eps;
}

// ??????
double dot(const Vector& a, const Vector& b){
	return a.x * b.x + a.y * b.y;	
}

// ??????
double cross(const Vector& a, const Vector& b){
	return a.x * b.y - a.y * b.x;
}

// ????????????(????????????)
bool isParallel(const Vector& a, const Vector& b){
	return equals(cross(a, b), 0.0);
}

// ????????????(???4???)
bool isParallel(Point a1, Point a2, Point b1, Point b2){
	return isParallel(a1 - a2, b1 - b2);
}

int main() {
	int n;
	double x1, x2, x3, x4, y1, y2, y3, y4;
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		if(isParallel(Point(x1, y1), Point(x2, y2), Point(x3, y3), Point(x4, y4)))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include <iostream>

using namespace std;

int main(void) {
    int a, b, c, d;
    int res;
    cin >> a >> b >> c >> d;
    if (a < b) {
        res = a;
    } else {
        res = b;
    }
    if (c < d) {
        res += c;
    } else {
        res += d;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define _GLIBCXX_DEBUG
const int INF=1e15;

signed main(){
    int N;
    cin>>N;
    cout<<N*(N-1)/2<<endl;
}

Measured memory_bytes: 256
import math
def combinatorial(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

N, K = (int(x) for x in input().split())
for i in range(1, K+1):
    if N-K+1 >= i:
        ans = combinatorial(K-1, i-1)*combinatorial(N-K+1, i)%(10**9+7)
    else:
        ans = 0
    print(ans)


Measured memory_bytes: 3316