akhauriyash/Code-Regression huggingface dataset:
// https://arc098.contest.atcoder.jp/tasks/arc098_c
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#define NDEBUG
#include<cassert>
int main(){auto&O=std::cout;
#ifdef _GLIBCXX_DEBUG
std::stringstream I(R"(
11 7 5
24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784
)");
#else
auto&I=std::cin;std::ios::sync_with_stdio(0);I.tie(0);
#endif

int nNum,delRangeLen,nDel;
I>>nNum>>delRangeLen>>nDel;
std::vector<int> nums(nNum);for(int& x:nums)I>>x;

std::vector<int> uniqNums=nums;
std::sort(uniqNums.begin(),uniqNums.end());
uniqNums.erase(std::unique(uniqNums.begin(),uniqNums.end()),uniqNums.end());
int ans=1e9;
for(int lowestChosen:uniqNums){ // actually a lower bound of
	std::vector<int> pickableItems;pickableItems.reserve(nNum);
	int startIndex=0;
	for(int index=0;index<=nNum;++index)
	if(index==nNum||nums[index]<lowestChosen){
		// consider range [startIndex..index[
		int curRangeLen=index-startIndex;
		assert(O<<"lowestChosen="<<lowestChosen<<'\n');
		assert(O<<"range ["<<startIndex<<".."<<index<<"[\n");
		assert(std::all_of(nums.begin()+startIndex,nums.begin()+index,[&](int x){return x>=lowestChosen;}));
		if(curRangeLen>=delRangeLen){
			pickableItems.insert(pickableItems.end(),nums.begin()+startIndex,nums.begin()+index);
			std::nth_element(pickableItems.end()-curRangeLen,
				pickableItems.end()-delRangeLen,pickableItems.end()); // partition it
			pickableItems.resize(pickableItems.size()-(delRangeLen-1));
			// delRangeLen-1 last items can't be picked
		}
		startIndex=index+1;
	}
	// we need to pick nDel elements to delete, so the largest one being deleted is the one at [nDel-1]
	if((int)pickableItems.size()<nDel)
		break;
	std::nth_element(pickableItems.begin(),pickableItems.begin()+nDel-1,pickableItems.end());
	ans=std::min(ans,pickableItems[nDel-1]-lowestChosen);
}
O<<ans<<'\n';

}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
int A,B,C;

scanf("%d %d %d",&A,&B,&C);

if(A!=B && A==C)
{
    printf("Yes");
}

else if(A!=C && A==B)
{
    printf("Yes");
}

else if(A!=C && B==C)
{
    printf("Yes");
}

else
    printf("No");

}


Measured memory_bytes: 128
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();

		int ar[] = new int[N];

		for(int n=0;n<N;n++){
			ar[n] = sc.nextInt();
		}

		Arrays.sort(ar);

		int cnt = 0;

		for(int n=0;n<N;n++){

			if(n==N-1){
				if(X==ar[n]) cnt++;
				break;
			}
			if(X>=ar[n]){
				cnt++;
				X -= ar[n];
			}else break;
		}

		System.out.println(cnt);

	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second



using namespace __gnu_pbds;
using namespace std;
// const int mod=1e9+7;
 const int mod=998244353;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i; 


int pow(int a, int b)
{
    int prod=1;
    int mult=a%mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod*=mult;
            prod%=mod;
        }
        mult*=mult;
        mult%=mod;
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int mod)
{
    return pow(q, mod-2);
}



bool is_palindrome(string s)
{
    int n=s.size();
    for(int i=0;i<n;i++)
    {
        if(s[i]!=s[n-1-i])
            return false;
    }
    return true;
}

signed main()

{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
       cout.tie(NULL);
     #ifndef ONLINE_JUDGE
        if(fopen("INPUT.txt","r"))
        {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
        }
     #endif
    auto clk=clock(); 
    // -------------------------------------Code starts here---------------------------------------------------------------------     
    
    int n;
    cin>>n;
    readv(a, n);
    vector<int> cnt(n+1);
    int sum=0;
    for(auto i:a)
    {
        cnt[i]++;
        sum+=(cnt[i]-1);
    }
    for(auto i:a)
    {
        cnt[i]--;
        sum-=cnt[i];
        cout<<sum<<endl;
        cnt[i]++;
        sum+=cnt[i]-1;
    }

    // -------------------------------------Code ends here------------------------------------------------------------------

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


Measured memory_bytes: 5760
using System;
class devideproblem{
  public static void Main(){
    int n = int.Parse(Console.ReadLine());
    String[] str = Console.ReadLine().Split(' ');
    int[] num = new int[n];
    for(int i=0; i<n; i++){
      num[i] = int.Parse(str[i]);
    }
    Array.Sort(num);
    int middles = num[(n-1)/2];
    int middlel = num[n/2];
    Console.WriteLine(middlel-middles);
  }
}


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

#define f0(i,a,b) for(int i= a; i<= b; ++i)
#define f1(i,a,b) for(int i= a; i>= b; --i)
#define DEBUG(x) cerr << #x << " = " << x << endl
#define X first
#define Y second
using namespace std;
const long long base=1e9+7;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
const long long MAX_N = 3001;
double dp[MAX_N][MAX_N];
int Solves() {
    ll n;
    cin >> n;
    double p[n + 1];
    for(int i = 1; i <= n;i++) cin >> p[i];
    dp[1][0] = (double)1 - p[1];
    dp[1][1] = p[1];
    for(int i = 2; i <= n;i++) {
        for(int j = 0; j < i; j++) {
            dp[i][j + 1] += dp[i - 1][j]*p[i];
        }
        for(int j = 0; j < i;j++) {
            dp[i][j] += dp[i - 1][j]*(1 - p[i]);
        }
       // DEBUG(dp[i][i]);
    }
    double ans = 0;
    for(int i = n/2 + 1; i <= n;i++) {
        ans += dp[n][i];
    }
    cout << fixed << setprecision(10) << ans;
}

int main() {
    Solves();
}


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

int main()
{
	int A, B, C, X;
	cin >> A >> B >> C >> X;
	int ans = 0;
	for (int i = 0; i <= A; i++)
	{
		for (int j = 0; j <= B; j++)
		{
			for (int k = 0; k <= C; k++)
			{
				int SUM = 500 * i + 100 * j + 50 * k;
				if (SUM==X)
				{
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[][] a = new int[2][n];
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < n; j++) {
                    a[i][j] = in.nextInt();
                }
            }
            a[1][0] += a[0][0];
            for (int i = 1; i < n; i++) {
                a[0][i] += a[0][i - 1];
            }
            for (int i = 1; i < 2; i++) {
                for (int j = 1; j < n; j++) {
                    a[i][j] += Math.max(a[i - 1][j], a[i][j - 1]);
                }
            }
            out.println(a[1][n - 1]);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



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

m10 = y // 10000
m5 = 0
m1 = 0

if m10 > n:
    m10 = n

y0 = y - 10000 * m10

def calc(y, n, m10):
    for i in range(n + 1):
        j = n - m10 - i
        if j < 0:
            continue
#         print(m10, i, j)
        if y == (5000 * i + 1000 * j) \
            and n == m10 + i + j:
            return i, j
    return -1, -1
  
while m10 >= 0:
    m5, m1 = calc(y0, n, m10)
    if m5 == m1 == -1:
        m10 -= 1
        y0 += 10000
    else:
        break
print(m10, m5, m1)

Measured memory_bytes: 3064
import java.util.Scanner;

class Main {

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

        int h = sc.nextInt();
        int w = sc.nextInt();

        String[] c = new String[h];

        for (int i = 0; i < h; i++) {
            c[i] = sc.next();
        }

        boolean end = true;

        for (int i = 0; i < h; i++) {
            if (end == false) {
                i = i - 1;
            }
            System.out.println(c[i]);
            if (end == true) {
                end = false;
            } else {
                end = true;
            }
        }
        System.out.println(c[h - 1]);
    }
}


Measured memory_bytes: 24276
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(m<=1)return 0;
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=3e5+5;

bool prime(ll x){
  if(x==3)return true;
for(int i=2;i*i<=x;i++){
  if(x%i==0)return false;
}

  return true;

}

ll lcm(ll a,ll b){
  return (a*b)/(__gcd(a,b));
}



int main()
{ 

IOS;

ll n;cin>>n;
string s;cin>>s;

ll cnt=0;

ll pos=-1;

for(int i=0;i<n;i++){
  if(s[i]=='1')cnt++,pos=i;
}

if(!cnt){
  FOR(i,n)cout<<1<<endl;
  return 0;
}

if(cnt==1){
  for(int i=0;i<n;i++){
    if(s[i]=='0'){
     if(pos==n-1||i==n-1)cout<<2<<endl;
     else cout<<1<<endl;
    }
    else{
cout<<0<<endl;
    }
  }
  return 0;
}

ll s1=0,s2=0;

for(int i=0;i<n;i++){
  if(s[i]=='1'){
    (s1+=powM(2,n-i-1,cnt-1))%=(cnt-1);
(s2+=powM(2,n-i-1,cnt+1))%=(cnt+1);
  }
}

vl x(n);

vl ans(n,1);

for(int i=0;i<n;i++){
if(s[i]=='0'){
  x[i]=(s2+powM(2,n-i-1,cnt+1))%(cnt+1);

}
else {
  x[i]=(s1+(cnt-1)-powM(2,n-i-1,cnt-1))%(cnt-1);  
}
}

for(int i=0;i<n;i++){
  while(x[i]){
    ll cn=__builtin_popcount(x[i]);
    x[i]%=cn;
    ans[i]++;
  }
}

for(int i=0;i<n;i++)cout<<ans[i]<<endl;



return 0;
 
}


Measured memory_bytes: 6720
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d,e=0,f=0;
  string s,t;
  char i;
  cin >>s;
  t=s;
  for(int n=1;n<s.size();n++){
    if(s[n-1]==s[n]){
      if(s[n]=='0') s[n]='1';
      else s[n]='0';
      f++;
    }
  }
  for(int n=s.size()-1;n>=0;n--){
    if(t[n+1]==t[n]){
      if(t[n]=='0') t[n]='1';
      else t[n]='0';
      e++;
    }
  }
  cout <<min(e,f)<<'\n';
  return (0);
}


Measured memory_bytes: 512
n, m, l = map(int, input().split(" "))

A = []
for i in range(n):
    A.append(list())
    X = list(map(int, input().split(" ")))
    for j in range(m):
        A[i].append(list())
        A[i][j] = X[j]

B = []
for i in range(m):
    B.append(list())
    X = list(map(int, input().split(" ")))
    for j in range(l):
        B[i].append(list())
        B[i][j] = X[j]

C = []
for i in range(n):
    C.append(list())
    for j in range(l):
        C[i].append(list())
        C[i][j] = 0 
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]
    print(" ".join([str(x) for x in C[i]]))

Measured memory_bytes: 8884
#include <iostream>

using namespace std;

int main()
{

	int n;
	cin >> n;

	int d = 100000;

	for (int i = 0; i < n; ++i)
	{
		d = static_cast <int> (static_cast <double> (d) * 1.05);
		if (d % 1000 > 0)
		{
			d = d - (d % 1000) + 1000;
		}
	}

	cout << d << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair< int , int > P;
typedef tuple<int, int, int> T;
    


int main(){
    string s,t;
    ll ans=0;
    cin>>s>>t;

    rep(i,s.size()){
        if(s[i]!=t[i]) ans++;
    }
    cout<<ans;
}



Measured memory_bytes: 3916
#include "bits/stdc++.h"
using namespace std;
int main(){
 int n,i=0,a=0;cin>>n;string s;cin>>s;
 while(i<s.size()){
  a+=s[i]-'('?-1:1;if(a<0){
   s.insert(0,"(");++i;++n;++a;}++i;
 }for(int i=0;i<a;++i)s.push_back(')');cout<<s;}

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

using namespace std;
#define rep2(x,from,to) for(int x=from;x<to;x++)
#define rep(x,to) rep2(x,0,to)
int main()
{
    int n;
    cin>>n;
    if(n%2==0)cout<<(int)(n/2)-1<<endl;
    else cout<<(int)(n/2)<<endl;
    return 0;
}

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

using namespace std;

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pi acos(-1.0)
#define scan(a) scanf("%d",&a)
#define scanll(a) scanf("%lld",&a)
#define print(a) printf("%d\n",a)
#define printll(a) printf("%lld\n",a)
#define stll(a) stoll(a,nullptr,10)
#define PII pair<ll,ll>
#define mp(a,b) make_pair(a,b)

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll n;
    string str;
    cin>>n>>str;
    if(n>=3200)
        cout<<str;
    else cout<<"red";
    cout<<endl;


}






Measured memory_bytes: 256
# include <stdio.h>
int main()
{
    char s[4]; 
    int a=0;
    scanf("%s", &s);
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == '1')
        {
            a++;
        }
    }
    printf("%d", a);
    return 0;
}

Measured memory_bytes: 128
import sys
x0,y0=map(float,raw_input()[:-1].split(","))
x1,y1=map(float,raw_input()[:-1].split(","))
x1,y1=x1-x0,y1-y0
s=0
for e in sys.stdin:
    ex,ey=map(float,e[:-1].split(","))
    x2,y2=ex-x0,ey-y0
    s+=abs(x1*y2-x2*y1)
    x1,y1=x2,y2
print s/2

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int n, a, b;
    cin >> n >> a >> b;
    b ^= a;

    int pc = __builtin_popcount(b);
    if(pc%2 == 0){
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;

    int gc[1<<17];
    for(int i=0;i<(1<<n);i++) gc[i] = i^(i>>1);
    
    deque<int> ans;
    bool flg_f = true;
    for(int i=0;i<(1<<n);i++){
        if(__builtin_popcount(gc[i]+1) == 1 && __builtin_popcount(gc[i]) <= pc-1 && __builtin_popcount(gc[i])%2 == 1) flg_f = true;
        if(flg_f) ans.push_front(gc[i]);
        else      ans.push_back(gc[i]);
        if(__builtin_popcount(gc[i]+1) == 1 && __builtin_popcount(gc[i]) <= pc-1 && __builtin_popcount(gc[i])%2 == 0) flg_f = false;
    }

    vector<int> bits[2];
    for(int i=0;i<n;i++) bits[b>>i & 1].push_back(i);
    
    map<int, int> bits_ans2output;
    for(int i=0;i<bits[1].size()-1;i++) bits_ans2output[i] = bits[1][i];
    bits_ans2output[n-1] = *bits[1].rbegin();
    for(int i=0;i<bits[0].size();i++) bits_ans2output[bits[1].size()+i-1] = bits[0][i];

    int beg;
    for(int x:ans){
        int output = 0;
        for(int i=0;i<n;i++){
            output += (x>>i & 1) << bits_ans2output[i];
        }
        if(x==*ans.begin()) beg = output;
        cout << (output^beg^a) << " \n"[x==*ans.rbegin()];
    }
    return 0;
}

Measured memory_bytes: 2048
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

a,b = map(int, input().split())

# 0からnまでのXOR和
def xor_sum(n):
    ans = 0
    # XORで1になる組数を求める
    if n % 2:
        # 奇数の時は切り上げて偶奇判定
        ans = ((n + 1) // 2) % 2
    else:
        # 偶数の時はnとのXORを返す
        ans = (n // 2) % 2
        ans ^= n
    return ans

print(xor_sum(b) ^ xor_sum(a - 1))


Measured memory_bytes: 9144
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint unsigned long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++)
#define DUMP(ar) for(auto itd=begin(ar); itd != end(ar); itd++) cout << "["s << itd - begin(ar) << "]:"s << *itd << endl
#define DUMPL(ar) for(auto itd=begin(ar); itd != end(ar); itd++) { cout << *itd; if(end(ar)-itd > 1) cout << ' '; } cout << endl
#define COUT(x) cout << (x) << endl
#define ALL(ar) ar.begin(), ar.end()
#define LOOPD(i) cout << "ループ["s << i << "]回目---------------"s << endl
using namespace std;

int factorion(int x){
    int res = 1;
    for(int i=2; i<=x; i++){
        res *= i;
    }
    return res;
}

int count_order(vector<int> &a, int n){
    int a_cnt = 0;
    vector<int> tmp(n);
    for(int i=0; i<n; i++) tmp[i] = i+1;
    for(int i=0; i<n; i++){
        int idx=0;
        for(int j=0; j<(int)tmp.size(); j++){
            if(a[i] == tmp[j]){
                idx = j;
                break;
            }
        }
        tmp.erase(tmp.begin() + idx);
        a_cnt += factorion(n-i-1) * idx;
    }

    return a_cnt;
}

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

    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=0; i<n; i++){
        cin >> b[i];
    }
    
    int a_cnt = count_order(a, n) + 1;
    int b_cnt = count_order(b, n) + 1;

    COUT(abs(a_cnt - b_cnt));

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
const int N=100000;
int a[N],i,n,j,c;
bool ok=1;
void generator()
{	while(true)
	{
		for(i=1;i<=n;i++)
		{
			if(a[i]%2==0)
			{
				a[i]/=2;
			}
			else
			{
				return ;
			}
					
		}
		c++;
	}
	
}
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin >> a[i];
	}
	generator();
	cout<< c;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
#include <cstdint>

typedef long long int llint;

void solve(){

  int n;
  std::cin >> n;
  std::map<int, int> aa;
  for(int i=0; i<n; i++){
    int tmp;
    std::cin >> tmp;
    if(aa.find(tmp) == aa.end()) aa[tmp] = 0;
    aa[tmp]++;
  }

  std::set<int> a;
  std::set<int> taboo;
  for(const auto& elem: aa){
    if(elem.second>1) taboo.insert(elem.first);
    a.insert(elem.first);
  }

  std::vector<int> res;
  while(!a.empty()){
    int largest = *(a.rbegin());
    res.push_back( *(a.begin()) );
    //std::cout << a.size() << " " << res.size() << " " << res[res.size()-1] << " " << largest << std::endl;
    for(int j=res[res.size()-1]; j<=largest; j+=res[res.size()-1]){
      if(a.find(j)!=a.end()) a.erase(j);
    }
  }

  int count = 0;
  for(const auto& elem: res){
    if(taboo.find(elem) == taboo.end()) count++;
  }
  std::cout << count << std::endl;
  
  return;
  
}

int main(void){

  solve();
  
  return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int k; cin >> k;
	if (k%7==0) k /= 7;
	int ret = -1;
	ll prev = 1;
	for (int i=1; i<k+3; i++) {
		ll now;
		now = (10 * prev)%(9 * k);
		if (now==1) {
			ret = i;
			break;
		} else {
			prev = now;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;if(n==0) return -1;return logtwo(n/2)+1;}
ll dig(ll n)
{
	ll c=0;
	while(n>0)
	{
		n=n/10;
		c++;
	}
	return c-1;
}
int main()
{
    fastio();
    
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=2;i*i<=n;i++)
    {
    	if(n%i==0)
    	{
    		ll c=0;
    		while(n%i==0)
    		{
    			n=n/i;
    			c++;
    		}
    		int j=1;
    		while(c>0)
    		{
    			c=c-j;
    			if(c<0)
    				break;
    			j++;
    		}
    		//cout<<i<<" "<<n<<" "<<j-1<<endl;
    		ans+=j-1;
    	}
    }
    if(n>1)
    {
    	ans+=1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    #define double long double
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    void chmax(int &x,const ll y) {x=(x>y?x:y);}
    void chmin(int &x,const ll y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):0;}
    const int INF=0x3f3f3f3f;
    const int MOD=998244353;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    inline ll qpower(ll x,ll e)
    {
        ll ans=1;
        while(e)
        {
            if(e&1) ans=ans*x%MOD;
            x=x*x%MOD;e>>=1;
        }
        return ans;
    }
    inline int invm(int x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    int a[N],b[N];
    priority_queue<pr> q;
    void main()
    {
        int n=qread();for(int i=0;i<n;i++) a[i]=qread();
        for(int i=0;i<n;i++) b[i]=qread(),q.push(MP(b[i],i));
        ll ans=0;
        while(q.size())
        {
            int x=q.top().SE;q.pop();
            int l=(x-1+n)%n,r=(x+1)%n,ss=b[l]+b[r];
            if(ss>b[x] or b[x]==a[x]) continue;
            // printf("x=%d ss=%d bx=%d\n",x,ss,b[x]);
            int go=max(b[x]%ss,a[x]),ned=b[x]-go;if(ned%ss or ned<0) {puts("-1");return;}
            ans+=ned/ss;q.push(MP(b[x]=go,x));
        }
        for(int i=0;i<n;i++) if(a[i]!=b[i]) {puts("-1");return;}
        write(ans);
    }
};
int main()
{
    srand(time(0));
    mine::main();
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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

const ll MRINF = 5000000000000000;

int main() {

    ll N;
    cin >> N;
    string S;
    cin >> S;
    vector<ll> left(N, 0), right(N, 0);

    if(S[0]=='W'){
        left[0] = 1;
    }else{
        left[0] = 0;
    }
    REP1(i, N){
        if(S[i]=='W'){
            left[i] = left[i-1]+1;
        }else{
            left[i] = left[i-1];
        }
    }

    if(S[N-1]=='E'){
        right[N-1] = 1;
    }else{
        right[N-1] = 0;
    }
    for(ll i = N-2; i>=0; i--){
        if(S[i]=='E'){
            right[i] = right[i+1]+1;
        }else{
            right[i] = right[i+1];
        }
    }

    // REP(i, N){
    //     cout << left[i] << " " << right[i] << endl;
    // }
    vector<ll> ans(N);
    ans[0] = right[1];
    ans[N-1] = left[N-2];
    REP1(i, N-1){
        ll l = left[i-1];
        ll r = right[i+1];
        ans[i] = l+r;
    }
    sort(ans.begin(), ans.end());
    cout << ans[0] << endl;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 10560
A = []

for _ in range(3):
  A.append(list(map(int, input().strip().split())))


N = int(input())
nums = set()
for _ in range(N):
  n = int(input())
  nums.add(n)

for row in A:
  if len(set(row).difference(nums)) == 0:
    print('Yes')
    exit()
for col in range(len(A[0])):
  nums_in_col = set()
  for row in range(len(A)):
    nums_in_col.add(A[row][col])
  if len(nums_in_col.difference(nums)) == 0:
    print('Yes')
    exit()

nums_ = set()
for i in range(len(A)):
  nums_.add(A[i][i])
if len(nums_.difference(nums)) == 0:
  print('Yes')
  exit()

nums_ = set()
for i, j in zip(range(len(A)-1, -1, -1), range(len(A))):
  nums_.add(A[i][j])

if len(nums_.difference(nums)) == 0:
  print('Yes')
  exit()

print('No')
  
  

Measured memory_bytes: 3188
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

bool dp[100005][4][4][4];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, a, b, c;
	cin >> n >> a >> b >> c;
	vector<string> s(n + 1);
	repn(i, 1, n + 1) cin >> s[i];
	a = min(a, 2);
	b = min(b, 2);
	c = min(c, 2);
	dp[0][a][b][c] = 1;
	repn(i, 1, n + 1) rep(j, 4) rep(k, 4) rep(l, 4){
		if(s[i] == "AB"){
			if(j > 0 && k < 3) dp[i][j - 1][k + 1][l] |= dp[i - 1][j][k][l];
			if(j < 3 && k > 0) dp[i][j + 1][k - 1][l] |= dp[i - 1][j][k][l];
		}
		else if(s[i] == "BC"){
			if(k > 0 && l < 3) dp[i][j][k - 1][l + 1] |= dp[i - 1][j][k][l];
			if(k < 3 && l > 0) dp[i][j][k + 1][l - 1] |= dp[i - 1][j][k][l];
		}
		else{
			if(j > 0 && l < 3) dp[i][j - 1][k][l + 1] |= dp[i - 1][j][k][l];
			if(j < 3 && l > 0) dp[i][j + 1][k][l - 1] |= dp[i - 1][j][k][l];
		}
	}
	int pos = 0;
	pair<pi, int> st;
	rep(i, 4) rep(j, 4) rep(k, 4){
		if(dp[n][i][j][k]) st = mp(mp(i, j), k);
		pos |= dp[n][i][j][k];
	}
	if(pos){
		string ans = "";
		int j = st.fi.fi, k = st.fi.se, l = st.se;
		for(int i = n - 1; i >= 0; i--){
			if(s[i + 1] == "AB"){
				if(j > 0 && k < 3 && dp[i][j - 1][k + 1][l]) ans += 'A', j--, k++;
				else if(j < 3 && k > 0 && dp[i][j + 1][k - 1][l]) ans += 'B', j++, k--;
			}
			else if(s[i + 1] == "BC"){
				if(k > 0 && l < 3 && dp[i][j][k - 1][l + 1]) ans += 'B', k--, l++;
				else if(k < 3 && l > 0 && dp[i][j][k + 1][l - 1]) ans += 'C', k++, l--;
			}
			else{
				if(j > 0 && l < 3 && dp[i][j - 1][k][l + 1]) ans += 'A', l++, j--;
				else if(j < 3 && l > 0 && dp[i][j + 1][k][l - 1]) ans += 'C', j++, l--;
			}
		}
		cout << "Yes" << endl;
		reverse(all(ans));
		rep(i, ans.size()) cout << ans[i] << endl;
	}
	else cout << "No" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/




Measured memory_bytes: 12968
n,m = map(int,input().split())
k = [list(map(int,input().split())) for i in range(m)]
p = list(map(int,input().split()))
ans = 0
switch_st = 0
cnt = 0

while switch_st != 2**n:
    switch_on = { i+1 for i in range(n) if switch_st>>i & 1 == 1}
    for i in range(m):
        switch_cnt = len(switch_on & set(k[i][1:]))
        if switch_cnt %2 == p[i]:
            cnt += 1
    else:
        if cnt == m:
            ans += 1
    cnt = 0
    switch_st += 1

print(ans)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main() {
	int		a[4][14], n, i, k, j, x;
	char	t;
	for (k = 1; k <= 13; k++) {
		a[0][k] = 0;
		a[1][k] = 0;
		a[2][k] = 0;
		a[3][k] = 0;
	}
	cin >> n;
	for (i = 1; i <= n; i++) {
		cin >> t >> x;
		if (t == 'S') {
			a[0][x]=1;
		}
		else if (t == 'H') {
			a[1][x]=1;
		}
		else if (t == 'C') {
			a[2][x]=1;
		}
		else if (t == 'D') {
			a[3][x]=1;
		}
		
	}
	for (j = 1; j <= 13; j++) {
		if (a[0][j] == false) {
			cout << "S" <<" "<< j << endl;
		}
	}
	for (j = 1; j <= 13; j++) {
		if (a[1][j] == false) {
			cout << "H" <<" "<< j << endl;
		}
	}
	for (j = 1; j <= 13; j++) {
		if (a[2][j] == false) {
			cout << "C" <<" "<< j << endl;
		}
	}
	for (j = 1; j <= 13; j++) {
		if (a[3][j] == false) {
			cout << "D" <<" "<< j << endl;
		}		
		
	}
	return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int mod=1e9+7,N=2e6+9;
int fac[N],ifac[N];

int pw(int a,int t=mod-2){
    int x=1;
    while(t>0){
        if(t&1)x=x*a%mod;
        a=a*a%mod,t>>=1;
    }
    return x;
}
int C(int n,int r){
    if(r<0 or r>n)return 0;
    return fac[n]*ifac[r]%mod*ifac[n-r]%mod;
}
int P(int n,int r){
    if(r<0 or r>n or n<0)return 0;
    return fac[n]*ifac[n-r]%mod;
}
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    fac[0]=ifac[0]=1;
    for(int i=1;i<N;i++){
        fac[i]=i*fac[i-1]%mod;
        ifac[i]=pw(fac[i]);
    }
    int n,m;
    cin >> n >> m;
    int sum=0,s=1;
    for(int i=0;i<=n;i++){
        sum=(sum+s*P(m-i,n-i)*C(n,i)%mod+mod)%mod;
        s*=-1;
    }
    cout << sum*P(m,n)%mod ;
}


Measured memory_bytes: 34888
h,w = map(int,input().split())
table = [["."]*(w+2) for _ in range(h+2)]
for i in range(1,h+1):
    s = input()
    for j in range(1,w+1):
        if s[j-1] == '#':
            table[i][j] = "#"
for i in range(1,h+1):
    for j in range(1,w+1):
        if table[i][j] != "#":
            ctr = table[i-1][j-1:j+2].count("#")
            ctr += table[i][j-1:j+2].count("#")
            ctr += table[i+1][j-1:j+2].count("#")
            table[i][j] = str(ctr)
for i in range(1,h+1):
    print("".join(table[i][1:w+1]))


Measured memory_bytes: 3188
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

typedef int weight;

struct edge {
	int to;
	weight cap;
	int rev;
	bool is_rev;
	edge(int to_, weight cap_, int rev_, bool is_rev_):to(to_), cap(cap_), rev(rev_), is_rev(is_rev_){}
};

constexpr weight INF = (1 << 29);

vector<vector<edge> > G;
vector<int> level;
vector<int> iter;

void init(int V) {
	G.assign(V, vector<edge>());
	level.resize(V);
	iter.resize(V);
}

void add_edge(int from, int to, weight cap) {
	G[from].emplace_back(to, cap, G[to].size(), false);
	G[to].emplace_back(from, 0, G[from].size() - 1, true);
}

void bfs(int s) {
	fill(level.begin(), level.end(), -1);
	queue<int> que;
	level[s] = 0;
	que.push(s);

	while(!que.empty()) {
		const int v = que.front();
		que.pop();

		for(const auto &e : G[v]) {
			if(e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

weight dfs(int v, int t, weight f) {
	if(v == t) return f;

	for(int &i = iter[v]; i < static_cast<int>(G[v].size()); ++i) {
		edge &e = G[v][i];
		if(e.cap > 0 && level[v] < level[e.to]) {
			const weight d = dfs(e.to, t, min(f, e.cap));
			if(d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}

	return 0;
}

weight max_flow(int s, int t) {
	weight flow = 0;

	for(;;) {
		bfs(s);
		if(level[t] < 0) return flow;

		fill(iter.begin(), iter.end(), 0);
		for(weight f; (f = dfs(s, t, INF)) > 0; flow += f);
	}
}

vector<bool> calc_reach(int s, int ok) {
	const int n = G.size();

	queue<int> que;
	vector<bool> visited(n, false);

	que.push(s);
	visited[s] = true;

	while(!que.empty()) {
		const int v = que.front();
		que.pop();

		for(const auto &e : G[v]) {
			if(e.cap == ok && !visited[e.to]) {
				que.push(e.to);
				visited[e.to] = true;
			}
		}
	}
	
	return visited;
}

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

	for(int n, m, s, t; cin >> n >> m >> s >> t && n;) {
		--s; --t;
		init(n);
		for(int i = 0; i < m; ++i) {
			int a, b;
			cin >> a >> b;
			--a; --b;
			add_edge(a, b, 1);
		}

		const int f = max_flow(s, t);
		const auto reach_s = calc_reach(s, 1);
		const auto reach_t = calc_reach(t, 0);

		int num = 0;
		for(int v = 0; v < n; ++v) {
			if(!reach_t[v]) continue;

			for(const auto &e : G[v]) {
				if(e.cap == 1 && !e.is_rev && reach_s[e.to]) ++num;
			}
		}

		cout << (num ? f + 1 : f) << ' ' << num << endl;
	}


	return EXIT_SUCCESS;
}

Measured memory_bytes: 1904
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n,k,x,y;

	cin>>n>>k>>x>>y;

	if(n<=k){
		cout<<x*n<<endl;
	}else{
		cout<<k*x+(n-k)*y<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()

res = 0
for j in B:
    i = bisect.bisect_left(A, j)
    k = bisect.bisect_right(C, j)
    k = len(C) - k
    res += i * k

print(res)


Measured memory_bytes: 23360
let () = Scanf.scanf "%d\n" @@ fun n ->
  let es = Array.make n [] in
  for i = 0 to n - 2 do
    Scanf.scanf "%d %d\n" @@ fun a b ->
      es.(a - 1) <- (b - 1, i) :: es.(a - 1);
      es.(b - 1) <- (a - 1, i) :: es.(b - 1)
  done;
  let colours = Array.make (n - 1) 0 in
  let visited = Array.make n false in
  let rec solve s v =
    visited.(v) <- true;
    ignore
      (List.fold_left (fun colour (u, i) ->
        let rec skip colour =
          if List.mem colour s then skip (colour + 1) else colour in
        let colour = skip colour in
        if visited.(u)
        then colour
        else begin
          colours.(i) <- colour;
          solve [colour] u;
          colour + 1
        end) 1 es.(v)) in
  solve [] 0;
  Printf.printf "%d\n" (Array.fold_left max min_int colours);
  Array.iter (Printf.printf "%d\n") colours



Measured memory_bytes: 19328
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int maxn=max(a,b);
	maxn=max(maxn,c);
	int max1=maxn*10+a+b+c-maxn;
	cout<<max1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
int main(void){
    string a,b,c;
    cin>>a>>b>>c;
    if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


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

int main(){
    string S;
    cin >> S;
    
    int days = 3;
    int count = 0;
    int max_count = 0;

    for(int i = 0; i < days; i++){
        if(S[i] == 'R'){
            count++;
        }else{
            if(max_count < count){
                max_count = count;
            }
            count = 0;
        }
    }

    if(max_count < count){
        max_count = count;
    }

    cout << max_count << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<int,int> P;
struct edge{ int to,cost; };
#define VMAX 100000
//bool cmp(P a,P b){ return a.second < b.second;}

ll N,M,K,ans=0;
ll A[100010],S[100010];
unordered_map<ll,ll> Q;
int main(){
	std::ios_base::sync_with_stdio(false);
	cin>>N>>M;
	REP(i,N){cin>>A[i];S[i]=A[i];}
	REP(i,N)S[i+1]+=S[i];
	REP(i,N)DEB(S[i]%M)END
	REP(i,N){
		Q[S[i]%M]++;
	}
	for(auto x:Q){
			ans+=x.second*(x.second-1)/2;
			if(x.first==0)ans+=x.second;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
// #define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

ll N, K;
ll a[100010];
ll sum;
ll up[100010];
ll down[100010];
int main(void){
	cin >> N >> K;
	reps(i, 1, N + 1) cin >> a[i];
	reps(i, 1, N + 1)if(a[i] > 0)sum += a[i];
	reps(i, 1, N + 1) if(a[i] > 0) up[i] = a[i];
	reps(i, 1, N) up[i + 1] += up[i];
	reps(i, 1, N + 1) if(a[i] < 0) down[i] = a[i];
	reps(i, 1, N) down[i + 1] += down[i];

	// printf("sum %ld\n", sum);
	ll ans = 0;
	reps(i, 1, N - K + 2){
		ll black = down[i + K - 1] - down[i - 1];
		chmax(ans, sum + black);
		ll white = up[i + K - 1] - up[i - 1];
		chmax(ans, sum - white);
		// printf("%lld %lld\n", black, white);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2560
fn main() {
    let s = {
        let mut s = String::new(); 
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_string()
    };

    let tokens = s.split(" ")
        .map(|num| num.parse().unwrap())
        .collect::<Vec<i32>>();

    let s = tokens[0];
    let limit = tokens[1] + 1;
    let num = tokens[2];

    let mut cnt = 0;
    for i in s..limit {
        if num % i == 0 {
            cnt += 1;
        }
    }

    println!("{}", cnt);

}



Measured memory_bytes: 5032
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cstdio>
#include <cstring>
#include <climits>
#include <sstream>
#include <cmath>
#include <complex>
using namespace std;

typedef complex<double> point;
#define EPS (1e-9)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define DEB 0
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)

double cross(point a, point b){
  return ( a.real()*b.imag() - a.imag()*b.real() );
}
bool is_intersection_ls(point a1, point a2, point b1, point b2){
  return ( cross(a2-a1,b1-a1)*cross(a2-a1,b2-a1)<EPS &&
           cross(b2-b1,a1-b1)*cross(b2-b1,a2-b1)<EPS );
}
point intersection_ls(point a1, point a2, point b1, point b2){
  point b = b2 - b1;
  double d1 = abs(cross(b, a1-b1));
  double d2 = abs(cross(b, a2-b1));
  double t = d1 / (d1+d2);
  return a1 + (a2-a1)*t;
}

class sen{
public:
  point p;
  int o,l;
  sen(point _p, int _o, int _l){
    p = _p;
    o = _o;
    l = _l;
  }
  bool operator<(const sen& a)const{
    if( abs(p.real()-a.p.real())>EPS ) return p.imag() < a.p.imag();
    return p.real() < a.p.real();
  }
};

point s,e;
point ds[110], de[110];
int O[110], L[110];
int n;


int main(){
  int T;
  cin>>T;
  while(T--){
    cin >> s.real() >> s.imag() >> e.real() >> e.imag();
    cin>>n;
    rep(i,n){
      cin >> ds[i].real() >> ds[i].imag();
      cin >> de[i].real() >> de[i].imag();
      cin >> O[i] >> L[i];
    }
#if DEB
    rep(i,n){
      cout << ds[i] << " : " << de[i] << " ," << O[i] << " " << L[i] << endl;
    }
#endif

    vector<sen> v;
    rep(i,n){
      if( abs(cross(e-s,de[i]-ds[i]))<EPS )continue;
      if( is_intersection_ls(s,e,ds[i],de[i]) ){
        point p = intersection_ls(s,e,ds[i],de[i]);
        v.push_back(sen(p,O[i],L[i]));
      }
    }

    // o ª1Èç©Ð
    // l ª
    int nl;
    int cnt = 0;
    sort(all(v));

    if( v.size()>0 ){
      nl = (v[0].o==1 ? v[0].l : !v[0].l);
    }

    
    REP(i,1,v.size()){
      if( (v[i].o==1 && v[i].l!=nl) ||
          (v[i].o==0 && v[i].l==nl) ){
        nl = !nl;
        cnt++;
      }
      /*
      if( v[i].o==1 ){
        if( v[i].l!=nl ){
          nl = v[i].l;
          cnt++;
        }
      }else{
        if( v[i].l==nl ){
          nl = (v[i].l==1 ? 0 : 1);
          cnt++;
        }
      }
      */
    }
    cout << cnt << endl;
  }
  return 0;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main()
{
	int a, b;
	cin >> a >> b;
	
	if(a >= 13) cout << b << endl;
	else if(a >= 6) cout << b/2 << endl;
	else cout << 0 << endl;

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define DEBUG
#ifdef DEBUG
    #define IFD(...) __VA_ARGS__
    #define IFN(...)
    #define L cout<<__LINE__<<"\n";
    #define PRINT(...) __VA_ARGS__ cout<<__LINE__<" : "<<#__VA_ARGS__<<"\n"
    #define PRT(x) cout<<__LINE__<<" : "<<#x<<" = "<<x<<"\n"
#else // DEBUG
    #define IFD(...)
    #define IFN(...) __VA_ARGS__
    #define L
    #define PRINT(...) __VA_ARGS__
    #define PRT(x)
#endif // DEBUG

#define it iterator
#define rit reverse_iterator
#define mp make_pair
#define mems(a,b) memset(a,b,sizeof(a))
#define mem0(a) mems(a,0)
#define mem1(a) mems(a,1)
#define mem255(a) mems(a,255)
#define halt exit(0)
#define all(c) (c).begin() , (c).end()
#define sz(c) ((long long)((c).size()))
#define phb push_back
#define ppb pop_back
#define phf push_front
#define ppf pop_front
#define fort0(i,a,b) for(ll i=a,i##_TO=b;i<i##_TO;i++)
#define for0(i,n) fort0(i,0,n)
#define fort1(i,a,b) for(ll i=a,i##_TO=b;i<=i##_TO;i++)
#define for1(i,n) fort1(i,1,n)
#define ford(i,a,b) for(ll i=a,i##_TO=b;i>=i##_TO;i--)

using namespace __gnu_pbds;
using namespace std;

#define int ll

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template
<
    class key,
    class val=null_type,
    class comp=less<key>
>
using ord_set=tree
<
    key,
    val,
    comp,
    rb_tree_tag,
    tree_order_statistics_node_update
>;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b;
    cin>>a>>b;
    cout<<(a<=b?a:a-1);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> as(n);
  for(int i=0;i<n;i++) cin>>as[i];

  for(int a:as)
    if(a%2==0)
      if(!(a%3==0||a%5==0)) drop("DENIED");

  drop("APPROVED");
  return 0;
}


Measured memory_bytes: 256
# your code goes here
def max(a, b):
	if a > b:
		return a
	else:
		return b



n,a,b = map(int, input().split())
l = a + b + (n - 2) * a;
h = a + b + (n - 2) * b;
print(max(h - l + 1, 0))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; i++)
#define int long long
signed main(signed argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    set<int> st;
    cin>>n;
    rep(i,n){
        int in;
        cin>>in;
        st.insert(in);
    }
    cout<<st.size()<<endl;
}



Measured memory_bytes: 7816
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

int main() {
	int k, a, b;
	cin >> k >> a >> b;

	int x = b / k * k;
	cout << (x >= a ? "OK" : "NG") <<endl;
	return 0;
}


Measured memory_bytes: 3136