akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long
#define EPS 1e-8

// ???????°???°???????????????
inline double add(double a, double b){
  if(abs(a+b) < EPS*(abs(a) + abs(b))) return 0;
  return a+b;
}

struct Point{
  double x,y;
  Point() {}
  Point(double nx, double ny) : x(nx), y(ny) {}
  inline Point operator + (const Point & p){ return Point(add(x, p.x), add(y, p.y)); }
  inline Point operator - (const Point & p){ return Point(add(x,-p.x), add(y,-p.y)); }
  inline Point operator * (double d){ return Point(x*d, y*d); }
  inline double dot(const Point & p){ return add(x * p.x, y*p.y); }  //??????
  inline double det(const Point & p){ return add(x * p.y, -y*p.x); } //??????
  inline double dist(const Point & p){ return sqrt((x-p.x)*(x-p.x) + (y-p.y)*(y-p.y)); }
  inline bool operator < (const Point & p) const {
    if(x != p.x) return x < p.x;
    else return y < p.y;
  }
  inline bool operator == (const Point & p) const {
    return (add(x, -p.x)==0) && (add(y, -p.y)==0);
  }
  friend ostream& operator<<(ostream& os, const Point& p) {
    os << "[" << p.x << "," << p.y << "]";
    return os;
  }
};

pair<Point, Point> calcCenter(Point &p1, Point &p2){
  if(add(p1.x, -p2.x)==0){
    double y = (p1.y + p2.y)/2;
    double dx = sqrt(1 - (p1.y - y)*(p1.y - y));
    return mp(Point(p1.x+dx, y), Point(p1.x-dx,y));
  }
  // 2???????????´???????????? Ax + By + C = 0 , A != 0
  double A = 2*(p1.x - p2.x);
  double B = 2*(p1.y - p2.y);
  double C = - p1.x*p1.x + p2.x*p2.x - p1.y*p1.y + p2.y*p2.y;
  // x = py+q
  double p = -B/A; double q = -C/A;

  // p1, p2 ??¨????????¢???1?????? ay^2 + 2by + c = 0
  double a = 1 + p*p;
  double b = p*q - p1.x*p - p1.y;
  double c = q*q - 2*p1.x*q + p1.x*p1.x + p1.y*p1.y - 1;

  double rt = sqrt(b*b-a*c);
  double y1 = (-b+rt)/a;
  double y2 = (-b-rt)/a;

  return mp(Point(p*y1+q, y1), Point(p*y2+q, y2));
}

Point vec[300];

int main(){
  int n;
  while(scanf("%d", &n), n){
    rep(i,n){
      scanf("%lf %lf", &vec[i].x, &vec[i].y);
    }

    int res=1;
    rep(i,n) repl(j,i+1,n) if(vec[i].dist(vec[j]) <= 2+EPS){
      pair<Point, Point> pr = calcCenter(vec[i], vec[j]);
      int cnt=0;
      rep(k,n) if(pr.fi.dist(vec[k]) <= 1+EPS) cnt++;
      res = max(res, cnt);
      cnt=0;
      rep(k,n) if(pr.se.dist(vec[k]) <= 1+EPS) cnt++;
      res = max(res, cnt);
    }

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

Measured memory_bytes: 3248
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 
int main(){
string S,T;
bool yes=false;
cin >> S >> T;
 
for(int i=0;i<S.size();i++){
rotate(S.begin(),S.end()-1,S.end());
if(S==T)yes = true;
}
if(yes)cout << "Yes";else cout << "No";
}



Measured memory_bytes: 256
use std::collections::VecDeque;
fn main() {
    let input = read_as_vec::<u32>();
    let n = *input.get(0).unwrap();
    let q = *input.get(1).unwrap();
    let mut que: VecDeque<Proc> = (0..n)
        .fold(VecDeque::new(), |mut que, _| {
            let input: Vec<String> = read_as_vec();
            let name = input[0].clone();
            let time = input[1].parse::<u32>().ok().unwrap();
            que.push_back(Proc::new(name, time));
            que
        });
    let mut total = 0;
    while let Some(mut p) = que.pop_front() {
        if p.time > q {
            total += q;
            p.time = p.time - q;
            que.push_back(p);
        } else {
            total += p.time;
            println!("{} {}", p.name, total);
        }
    }
}


struct Proc {
    name: String,
    time: u32,
}

impl Proc {
    fn new(name: String, time: u32) -> Self {
        Proc { name, time }
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().parse::<T>().ok().unwrap()
}

fn read_as_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| { e.parse::<T>().ok().unwrap() })
        .collect()
}


Measured memory_bytes: 7056
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,t,u;
  cin >> s >> t >> u;
  char a,b,c,d;
  a = s.at(s.length()-1);
  b = t.at(0);
  c = t.at(t.length()-1);
  d = u.at(0);
  if (a == b && c == d) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	Main m = new Main();
	m.answer();
    }

    private Scanner scan = new Scanner(System.in);
    private final int N;
    private final int A;

    public Main() {
	N = Integer.parseInt(scan.next());
	A = Integer.parseInt(scan.next());

	scan.close();
    }

    public final void answer() {
	System.out.println(N*N-A);
    }
}


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

int main()
{
  int a, b;
  cin >> a >> b;
  int ans = max(a + b, max(a - b, a * b));
  cout << ans << endl;
  return 0;
}

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

#define TRACE
#ifdef TRACE
#define TR(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define TR(...)
#endif

typedef long long                LL;
typedef vector < int >           VI;
typedef pair < int,int >         II;
typedef vector < II >            VII;

#define MOD                      1000000007
#define EPS                      1e-12
#define N                        200100
#define PB                       push_back
#define MP                       make_pair
#define F                        first 
#define S                        second
#define ALL(v)                   v.begin(),v.end()
#define SZ(a)                    (int)a.size()
#define FILL(a,b)                memset(a,b,sizeof(a))
#define SI(n)                    scanf("%d",&n)
#define SLL(n)                   scanf("%lld",&n)
#define PLLN(n)                  printf("%lld\n",n)
#define PIN(n)                   printf("%d\n",n)
#define REP(i,j,n)               for(LL i=j;i<n;i++)
#define PER(i,j,n)               for(LL i=n-1;i>=j;i--)
#define endl                     '\n'
#define fast_io                  ios_base::sync_with_stdio(false);cin.tie(NULL)

LL rec(LL a , LL b) {
  if(a < b) swap(a , b);
  if(b == 0) return -a;
  TR(a , b);
  LL ret = (a / b) * b * 2LL;
  a -= (a / b) * b;
  ret += rec(a , b);
  TR(ret);
  return ret;
}

int main() {
  LL n,x;
  cin >> n >> x;
  cout << n + rec(n - x , x) << endl;
  return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut sum = 0;
    let mut max = 0;
    for _ in 0..5 {
        let x: u32 = read();
        let ceil = ((x + 9) / 10) * 10;
        sum += ceil;
        let rem = ceil - x;
        if max < rem { max = rem; }
    }
    println!("{}", sum - max);
}


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

vector<pair<int,int> >v;

int main()
{
    int n;
    scanf("%d",&n);
    if(n<3 || __builtin_popcount(n)==1)
        puts("No");
    else
    {
        puts("Yes");
        v.push_back({1,2});
        v.push_back({2,3});
        v.push_back({3,n+1});
        v.push_back({n+1,n+2});
        v.push_back({n+2,n+3});

        for(int i=4;i<n;i+=2)
        v.push_back({n+1,i}),v.push_back({i,i+1});

        for(int i=n+5;i<=2*n;i+=2)
        v.push_back({n+1,i}),v.push_back({i,i-1});


        if(n%2==0)
        {
            int x,y;
            for(int i=0;;i++)
            {
                if(1<<i&n)
                {
                    x=1<<i;break;
                }
            }
            y=n^x^1;
           v.push_back({x==2?n+2:x,n});
           v.push_back({n+y,2*n});
        }
        for(auto i :v)
            printf("%d %d\n",i.first,i.second);

    }

    return 0;
}


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

vector<vector<int>> neibor=
{
    {0,1,2,4,6,7,9},
    {1,3,4,6,8,9,11},
    {2,4,5,7,9,10,12},
    {4,6,7,9,11,12,14},
    {6,8,9,11,13,14,16},
    {7,9,10,12,14,15,17},
    {9,11,12,14,16,17,18}
};
vector<int> pos=
{
    {4,6,7,9,11,12,14}
};
bool solve(vector<int> f){
    for(int bit=0;bit<(1<<19);bit++){
        bitset<19> mask=bit;
        for(int i=0;i<7;i++){
            int tmp=0;
            for(int j=0;j<7;j++){
                tmp|=(((bit>>neibor[i][j])&1)<<j);
            }          
            mask[pos[i]]=f[tmp];
        }
        int bef=mask[9];
        int i=3;
        int tmp=0;
        for(int j=0;j<7;j++){
            tmp|=(((mask>>neibor[i][j])[0])<<j);
        }          
        mask[pos[i]]=f[tmp];
        int aft=mask[9];
        if(bef!=aft) return false;
    }
    return true;
}
int main(){
    string str;
    while(cin>>str,str!="#"){
        vector<int> f(128);
        for(int i=0;i<128;i++) f[i]=str[i]-'0';
        cout<<(solve(f) ? "yes" : "no")<<endl;
    }
    return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <string>
#include <vector>
int n, m, sum[200010], vis[200010];
std::vector<int> p[26];
inline int lowbit(int x) { return x & -x; }
inline void add(int x, int y) {
    for (; x <= n; x += lowbit(x)) sum[x] += y;
}
inline int qry(int x) {
    register int ret = 0;
    while (x) {
        ret += sum[x];
        x -= lowbit(x);
    }
    return ret;
}
long long ans = 0;
int main() {
    std::string s;
    std::cin >> s;
    n = s.length();
    for (int i = 0; i < n; i++) p[s[i] - 'a'].push_back(i + 1);
    for (int i = 0; i < 26; i++) m += p[i].size() & 1;
    if (m > 1) {
        puts("-1");
        return 0;
    }
    for (int i = 1; i <= n; i++) add(i, 1);
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            const int c = s[i - 1] - 'a';
            int j = p[c][p[c].size() - 1];
            if (i == j)
                ans += (qry(n) - qry(j)) >> 1;
            else
                ans += qry(n) - qry(j);
            vis[i] = vis[j] = 1;
            add(i, -1);
            add(j, -1);
            p[c].pop_back();
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 3076
a = int(input())
b = list(map(int, input().split()))
c = {}
for i in b:
    if i not in c:
        c[i] = 1
    else:
        c[i] += 1
    if i+1 not in c:
        c[i+1] = 1
    else:
        c[i+1] += 1
    if i-1 not in c:
        c[i-1] = 1
    else:
        c[i-1] += 1
c = sorted(c.items(), key=lambda x: x[1], reverse=True)
print(c[0][1])

Measured memory_bytes: 23208
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 2000000000
#define MOD 998244353
#define N 100005
#define MAX 5000000
#define LOG 100
#define KOK 333
using namespace std;

int a[N];
int x,y,n;
vector<int> v[N];

void print(bool ver) {

	printf(ver?"YES":"NO");

	exit(0);

}

ll obtain(vector<ll>&chs) {

	if(!sz(chs)) return 0;

	ll mt=0,re=chs[0];

	for(int i=1;i<sz(chs);i++) {

		ll nm=min(chs[i],re);

		chs[i]-=nm;
		re-=nm;

		ll cm=min(chs[i]/2,mt);

		chs[i]-=cm*2;
		re+=chs[i];
		mt+=cm+nm;

	}

	return mt*2;

}

ll dfs(int node,int ata) {

	if(sz(v[node])==1) return a[node];

	ll sum=0;

	vector<ll> chs;

	for(int i:v[node]) {

		if(i==ata) continue ;

		ll add=dfs(i,node);

		sum+=add;

		chs.pb(add);

	}

	ll del=(sum-a[node])*2;

	if(del<0 || obtain(chs)<del) print(false);

	return sum-del;

}

int main() {

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

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d",a+i);

	if(n==2) print(a[1]==a[2]);

	for(int i=1;i<n;i++) {

		scanf("%d %d",&x,&y);

		v[x].pb(y);
		v[y].pb(x);

	}

	int root=1;

	for(int i=1;i<=n;i++) if(sz(v[i])>1) root=i;

	print((dfs(root,0)==0));
 
}

Measured memory_bytes: 16128
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int x,int y){
	return x>y;
}
int a[55];
int main(){
	int n,s,i,num=0;
	cin>>n>>s;
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+n,cmp);
	for(i=1;i<=s;i++){
		num=num+a[i];
	}
	cout<<num<<"\n";
	return 0;
}

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

mod = (10**9 + 7)
ans = 0

import numpy
alistsum = numpy.cumsum(alist)
asum = sum(alist)

for i in range(n-1):
    ans += alist[i]*(asum - alist[i])
    asum -= alist[i]
    ans = ans%mod
print(ans)

Measured memory_bytes: 37532
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = map(int,input().split())

uf = UnionFind(N)

for _ in range(M):
    x,y,z = map(int,input().split())
    x -= 1
    y -= 1
    uf.union(x,y)


print(uf.group_count())



Measured memory_bytes: 76952
#include<stdio.h>

int main(){
  long long i,j,k,N;
  scanf("%lld",&N);
  
  long long A[N+1],B[N+1],ans=0;
  
  for(i=0;i<N+1;i++){
    scanf("%lld ",&A[i]);
  }
  for(i=0;i<N;i++){
    scanf("%lld ",&B[i]);
  }
  B[N]=0;
  if(A[0] > B[0]){
    ans+=B[0];
    B[0]=0;
  }
  else{
    ans+=A[0];
    B[0]-=A[0];
  }
  for(i=1;i<N+1;i++){
    if(B[i-1]>0){
      if(B[i-1] > A[i]){
        ans+=A[i];
        A[i]=0;
        B[i-1]=0;
      }
      else{
        ans+=B[i-1];
        A[i]-=B[i-1];
        B[i-1]=0;
      }
    }
    if(A[i] < B[i]){
      ans+=A[i];
      B[i]-=A[i];
    }
    else{
      ans+=B[i];
      A[i]-=B[i];
      B[i]=0;
    }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 1664
n = int(input())
a = [int(i) for i in input().split()]
if len(a)%2==0:
	for i in range(len(a)-1,-1,-2):
		print(a[i],end=" ")
	for j in range(0,len(a),2):
		if j == len(a)-2: print(a[j])
		else: print(a[j],end=" ")
else:
	for i in range(len(a)-1,-2,-2):
		print(a[i],end=" ")
	for j in range(1,len(a),2):
		if j == len(a)-2: print(a[j])
		else: print(a[j],end=" ")

Measured memory_bytes: 26020
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

#define SIZE 30
#define MAX_OPE 8

int ans[SIZE] = {1,1,1,1,1,1,1,1,1,2,2,2,4,4,4,6,6,6,5,5,5,3,3,3,3,3,3,3,3,3};
bool check(vector<int> &cube) {
  for(int i=0;i<SIZE;i++) {
    if(cube[i] != ans[i]) {
      return false;
    }
  }
  return true;
}

void operate_cube(vector<int> &cube,int order) {
  if(order == 0) {
    swap(cube[0],cube[23]); swap(cube[3],cube[26]); swap(cube[6],cube[29]);
    swap(cube[15],cube[17]); swap(cube[9],cube[20]);
  }
  else if(order == 1) {
    swap(cube[6],cube[21]); swap(cube[7],cube[22]); swap(cube[8],cube[23]);
    swap(cube[9],cube[11]); swap(cube[12],cube[17]);
  }
  else if(order == 2) {
    swap(cube[2],cube[21]); swap(cube[5],cube[24]); swap(cube[8],cube[27]);
    swap(cube[12],cube[14]); swap(cube[11],cube[18]);
  }
  else if(order == 3) {
    swap(cube[0],cube[27]); swap(cube[1],cube[28]); swap(cube[2],cube[29]);
    swap(cube[18],cube[20]); swap(cube[14],cube[15]);
  }
  else {
    // no order
    return;
  }
}

int search(vector<int> &cube) {
  queue<vector<int> > que;
  queue<vector<int> > next_que;
  que.push(cube);
  int cnt = 0;
  while(!que.empty()) {
    vector<int> state = que.front(); que.pop();
    if(check(state)) {
      return cnt;
    }
    for(int i=0;i<4;i++) {
      vector<int> tmp = state;
      operate_cube(tmp,i);
      next_que.push(tmp);
    }
    if(que.empty()) {
      que = next_que;
      while(!next_que.empty()) next_que.pop();
      cnt++;
      continue;
    }
    if(cnt == 8) {
      return cnt;
    }
  }
  return cnt;
}

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

  int n; cin >> n;
  while(n--) {
    vector<int> cube(SIZE);
    int s;
    for(int i=0;i<SIZE;i++) {
      cin >> s;
      cube[i] = s;
    }
    cout << search(cube) << endl;
  }
}

Measured memory_bytes: 20624
#include <iostream>
using namespace std;
int main() {
  int A, B;
  cin >> A;
  cin >> B;
  bool a[3] = {false, false, false};
  a[A - 1] = true;
  a[B - 1] = true;
  for (int i = 0; i < 3; i++) {
    if (!a[i]) {
      cout << i + 1;
    }
  }
  return 0;
}

Measured memory_bytes: 256
while True:
    n = input()
    if n == 0: break
    P = [(map(int, raw_input().split())) for i in range(n)]
    S = set(map(tuple, P))
    ans = 0
    for i in range(n - 1):
        xi, yi = P[i]
        for j in range(i + 1, n):
            xj, yj = P[j]
            q = (xj - yj + yi, yj + xj - xi)
            r = (xi - yj + yi, yi + xj - xi)
            if q in S and r in S:
                ans = max(ans, (xi - xj) ** 2 + (yi - yj) ** 2)
    print ans

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

int n;
double dp[305][305][305] = {0};

double solve(int i, int j, int k) {

    if (dp[i][j][k] >= 0) return dp[i][j][k];
    if (i==0 && j==0 && k==0) return dp[i][j][k] = 0.0;

    double tmp = 0.0;
    if(i>0) tmp += solve(i-1, j, k) * i;
    if(j>0) tmp += solve(i+1, j-1, k) * j;
    if(k>0) tmp += solve(i, j+1, k-1) * k;
    tmp += n;
    tmp /= (i+j+k);
    return dp[i][j][k] = tmp;
}

int main() 
{
    cin >> n;    

    int a[4] = {0};
    rep(i,n) {
        int x; cin >> x;
        a[x]++;
    }

    rep(i,305)rep(j,305)rep(k,305) dp[i][j][k] = -1;
    printf("%.10f\n", solve(a[1], a[2], a[3]));

    return 0;
}


Measured memory_bytes: 221952
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
#include<cstdlib>
#include <queue>
#include <cmath>
#include <iomanip>
#include<list>
#include <utility>
#include <functional>
#include<map>
#include<stack>
#define T long long


int main(){
	T a,b,c,k;
	std::cin>>a>>b>>c>>k;
	if(k<=a){
		std::cout << k <<std::endl;
	}else if(k<=(a+b)){
		std::cout << a <<std::endl;
	}else{
		std::cout << (a-(k-a-b)) <<std::endl;
	}
}


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



int main(){
    ll n,ans=0;
    cin>>n;
    vector<ll> p(n);
    map<ll,vector<ll>> mp;
    map<ll,ll> ansmap;
    rep(i,n){
        cin>>p[i];
        mp[p[i]].push_back(i);
    }
    for(auto&a: mp){
        ll m;
        m=a.second.size();
        ansmap[a.first]=m*(m-1)/2;
        ans+=m*(m-1)/2;
    }
    rep(i,n){
        ll nowans=ans;
        nowans-=ansmap[p[i]];
        ll m;
        m=mp[p[i]].size();
        nowans+=(m-1)*(m-2)/2;
        cout<<nowans<<endl;
    }
    return 0;
}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    int k;
    cin>>k;
    string s;
    cin>>s;
    string ans="";
    int i;
    for(i = 0; i < k && i < s.size(); i++){
        ans += s[i];
    }
    if(s.size() > k) cout<<ans+"...";
    else cout<<ans;
    return 0;
}

Measured memory_bytes: 3600
using System;

namespace ABC0613
{
    class Program
    {
        static void Main(string[] args)
        {
            string name=Console.ReadLine();
            int length = name.Length;

            Random r = new Random();
            int index = r.Next() %(length - 2);

            string nick = name.Substring(index, 3);
            Console.WriteLine(nick);
        }
    }
}


Measured memory_bytes: 25880
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>
#define ll long long
int main()
{
    int N ;
    scanf("%d",&N);
    int L[N];
    int max = 0;
    int idx = 0;
    for (int i = 0; i<N; i++)
    {
        scanf("%d",&L[i]);
        if (max<L[i])
        {
            max=L[i];
            idx = i;
        }
    }
    int sum =0;
    L[idx]=0;
    for (int i = 0; i<N; i++)
    {
        sum+=L[i];
    }

    if (max<sum)
        printf("Yes");
    else
        printf("No");




    return 0;

}


Measured memory_bytes: 128
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<int>;


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

	vector<int> X(N);
	vector<int> Y(N);
	
	map<pair<int, int>, int> mp;

	for (int i = 0; i < N; ++i)
	{
		cin >> X[i] >> Y[i];
	}

	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			if (i == j)continue;
			int p = X[i] - X[j];
			int q = Y[i] - Y[j];

			if (mp.count(pair<int,int>( p,q )))
			{
				mp[pair<int, int>(p, q)]++;
			}
			else
			{
				mp[pair<int, int>(p, q)] = 1;
			}
		}
	}

	int ans = 0;
	for(auto itr : mp)
	{
		ans = max(ans, itr.second);
	}
	cout << N - ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int A, B, C, D; cin >> A >> B >> C >> D;
	cout << max(A*B, C*D) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
int main(void)
{
    int a;
    cin >> a;
    cout << "ABC" << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    ll n;cin>>n;
    vi v(n);rep(i,n)cin>>v[i];
    P ma=P(1000,0),mi=P(0,1000);
    rep(i,n){
        P tma=ma,tmi=mi;
        chmax(tma,P(mi.se+mi.fi*v[i],0));
        chmax(tmi,P((ma.fi/v[i])+ma.se,ma.fi%v[i]));
        ma=tma;mi=tmi;
    }
    out(ma.fi);
}

Measured memory_bytes: 3608
import sys

from collections import deque
# q = deque(); q.append(x); q.appendleft(x); q.pop() -> x; q.popleft() -> x
from collections import defaultdict
# d = defaultdict(lambda: []); d[key] -> []
import heapq
# hq = []; heapq.heappush(hq, x); heapq.heappop(hq) -> x; heapq.heappushpop(hq, x) -> x
import bisect
# i = bisect.bisect_left([1,2,3,4], 1.5); i = bisect.bisect_right([4,3,2,1], 1.5)

#import numpy as np
#from scipy.misc import comb

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def getBitsL(n, L):
    bits = [0] * L
    for i in range(L):
        bits[i] = (n & 1) == 1
        n >>= 1
    return bits

def main():
    H, W, K = i2nn()
    if W == 1:
        print(1)
        return
    # パターン数
    P = [[0] * W for _ in range(W)]
    for i in range(int(2**(W-1))):
        bits = getBitsL(i, W-1)
        ng = False
        for j in range(1, len(bits)):
            if bits[j-1] and bits[j]:
                ng = True
                break
        if ng:
            continue
        for j in range(W):
            if j == 0:
                if bits[j]:
                    P[j][j+1] += 1
                else:
                    P[j][j] += 1
            elif j == W-1:
                if bits[j-1]:
                    P[j][j-1] += 1
                else:
                    P[j][j] += 1
            else:
                if bits[j]:
                    P[j][j+1] += 1
                elif bits[j-1]:
                    P[j][j-1] += 1
                else:
                    P[j][j] += 1

    # 漸化式
    # A[縦][横] = パターン数
    A = [[0] * W for i in range(H+1)]
    A[0][0] = 1
    MOD = int(1e+9) + 7
    for h in range(H):
        for w1 in range(W):
            for w2 in range(W):
                A[h+1][w2] = (A[h+1][w2] + A[h][w1] * P[w1][w2]) % MOD
    print(A[H][K-1])
    #import numpy as np
    #print(np.array(P))
    #print(np.array(A))

main()


Measured memory_bytes: 39536
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
)

func main() {
	defer writer.Flush()
	var n, x int
	min := 1000
	fmt.Fscanf(reader, "%d %d\n", &n, &x)
	var m int
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d\n", &m)
		x -= m
		if m < min {
			min = m
		}
	}
	fmt.Fprintln(writer, n+x/min)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
int main(void){
   int N;
   cin >> N;
   
   int nums[N];
   for(int i = 0;i < N;i++){
       cin >> nums[i];
   }
   
   int ans = 0;
   for(int i = 2;i < N;i++){
       if(
           (nums[i - 2] < nums[i - 1] && nums[i - 1] < nums[i]) ||
           (nums[i - 2] > nums[i - 1] && nums[i - 1] > nums[i])
           ){
               ans++;
           }
   }
   cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <time.h>
#define mp(a,b) make_pair(a,b)
#define ll long long
#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define ss(s) scanf("%s",&s)
#define pi(n) printf("%d\n",n)
#define pl(n) printf("%lld\n",n)
#define newline cout << endl;
using namespace std;

long double findMedian(ll a[], ll n)
{
    // First we sort the array
    sort(a, a+n);

    // check for even case
    if (n % 2 != 0)
       return (long double)a[n/2];

    return (long double)(a[(n-1)/2] + a[n/2])/2.0;
}

int main(){
  clock_t tStart = clock();
    ll n; sl(n);
    ll cnt = 1;
    ll arr1[n],arr2[n];
    for(ll i=0;i<n;i++){
      sl(arr1[i]);
      arr1[i]-=cnt;
      arr2[i]=arr1[i];
      cnt++;
    }
    long double b = findMedian(arr2,n);
    ll k1 = floor(b);
    ll mini = 1e17;
    ll t1 = 0;
    for(int i=0;i<n;i++){
      t1+=abs(arr1[i]-k1);
    }
    mini =  min(mini,t1);
    t1 = 0;
    for(int i=0;i<n;i++){
      t1+=abs(arr1[i]-k1-1);
    }
    mini =  min(mini,t1);
    t1 = 0;
    for(int i=0;i<n;i++){
      t1+=abs(arr1[i]-k1+1);
    }
    mini =  min(mini,t1);
    t1 = 0;
    for(int i=0;i<n;i++){
      t1+=abs(arr1[i]-k1-2);
    }
    mini =  min(mini,t1);
    t1 = 0;
    for(int i=0;i<n;i++){
      t1+=abs(arr1[i]-k1+2);
    }
    mini =  min(mini,t1);
    t1 = 0;
    for(int i=0;i<n;i++){
      t1+=abs(arr1[i]-k1+3);
    }
    mini =  min(mini,t1);
    t1 = 0;
    for(int i=0;i<n;i++){
      t1+=abs(arr1[i]-k1-3);
    }
    mini =  min(mini,t1);
    pl(mini);
  //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
  return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#include<stack>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;
//set<int>::iterator it;

int main(void){
   int N;
   cin>>N;
   pair<pair<string,int>,int> p[110];

   for(int i=0;i<N;i++){
       string name;
       int score;
       cin>>name>>score;
       p[i] = make_pair(make_pair(name,-score),i);
   }
   std::sort(p,p+N);
   for(int i=0;i<N;i++){
       cout<<p[i].second+1<<endl;
   }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;
ll n, s, b, x;
bool exist=false;
vector<ll> candid;

ll sum(ll u, ll base)
{
	if(u<base)
	{
		return u;
	}
	else
	{
		return sum(u/base,base)+u%base;
	}
}

bool work(ll base)
{
	if(sum(n,base)==s)
	{
		return true;
	}
	return false;
}
void check(void)
{
	ll i;
	for(i=2 ; i<=x ; i++)
	{
		if(work(i))
		{
			cout<<i;
			exit(0);
		}
	}
}

void getcandid(void)
{
	for(ll i=1 ; i*i<=(n-s) ; i++)
	{
		if((n-s)%i==0)
		{
			candid.push_back(i+1);
			if(i*i!=(n-s))
			{
				candid.push_back((n-s)/i+1);
			}
		}
	}
	sort(candid.begin(),candid.end());
}

void perf(void)
{
	int i;
	for(i=0 ; i<candid.size() ; i++)
	{
		if(sum(n,candid[i])==s)
		{
			cout<<candid[i];
			exit(0);
		}
	}
}
int main(void)
{
	cin>>n>>s;
	if(n==s)
	{
		cout<<n+1;
		return 0;
	}
	if(n<s)
	{
		cout<<-1;
		return 0;
	}
	x=(ll)sqrt(n);
	check();
	getcandid();
	perf();
	cout<<-1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000009
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  vector<vector<ll>> A(3, vector<ll>(3, 0));
  rep(i, 3){
    rep(j, 3){
      cin >> A.at(i).at(j);
    }
  }
  ll N;
  cin >> N;
  vector<ll> b(N);
   set<ll> S;
  rep(i, N){
    cin >> b.at(i);
    S.insert(b.at(i));
  }
  bool bingo = false;
  bool out = false;
  rep(i, 3){
    rep(j, 3){
      if(!S.count(A.at(i).at(j))){
        break;
      }
      if(j == 2){
        bingo = true;
        break;
      }
    }
    if(bingo){
      break;
    }
  }
  rep(i, 3){
    rep(j, 3){
      if(!S.count(A.at(j).at(i))){
        break;
      }
      if(j == 2){
        bingo = true;
        break;
      }
    }
    if(bingo){
      break;
    }
  }
  rep(i, 3){
    if(!S.count(A.at(i).at(i))){
      break;
    }
    if(i == 2){
      bingo = true;
      break;
    }
  }
  rep(i, 3){
    if(!S.count(A.at(i).at(2-i))){
      break;
    }
    if(i == 2){
      bingo = true;
      break;
    }
  }
  if(bingo){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N; cin >> N;
	vector<ll> a(N);
	ll ans = 0;
	for (int i = 0; i < N;i++) cin >> a[i];
	a.erase(unique(a.begin(), a.end()), a.end());

	if (a.size() == 1) {
		cout << 1 << endl; return 0;
	}

	bool inc = false;
	if (a[0] < a[1])inc = true;
	ll l = 2;

	for (int i = 2; i < a.size();i++) {
		if (a[i - 1] < a[i]) {
			if (inc) {
				l++;
			}
			else {
				ans = max(ans, l);
				inc = true;
				l = 2;
			}
		}
		else {
			if (!inc) {
				l++;
			}
			else {
				ans = max(ans, l);
				inc = false;
				l = 2;
			}
		}
	}
	ans = max(ans, l);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

const int MAX = 1000001;

int main(){
    int N;
    cin >> N;
    vector<bool> isOK(MAX, true);
    vector<bool> same(MAX, false);
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    sort(all(a));
    //おんなじ物を取り除く
    int fnum = -1;
    rep(i, N){
        if(fnum == a[i]) same[a[i]] = true;
        fnum = a[i];
    }
    rep(i, N){
        //a[i]についてエラトステネスの篩
        if(isOK[a[i]] == true){
            int j = 2;
            while(j * a[i] < MAX){
                isOK[j * a[i]] = false;
                j++;
            }
            if(same[a[i]] == true) isOK[a[i]] = false;
        }
    }
    
    int ans = 0;
    rep(i, N) ans += isOK[a[i]];
    cout << ans << endl;
}

Measured memory_bytes: 4236
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e8;
const ll infl = 1LL << 60;
///////
const ll mod = 1e9+7;
int main(){
  int s,w;cin >> s >> w;
  if(s <= w) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(abs(b-c)-a>0){
		cout<<abs(b-c)-a<<endl;
	}
	else{
		cout<<0<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int main() {
    int a, b;
    scanf("%d %d", &a, &b);

    if (a % 2 == 0 || b % 2 == 0) {
        printf("Even\n");
    } else {
        printf("Odd\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
//fflush(stdin);
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    ve <ll> a(n),b(n),c(n);
    rep (i,0,n)
    {
        cin>>a[i];
    }
    rep (i,0,n)
    {
        cin>>b[i];
    }
    rep (i,0,n-1)
    {
        cin>>c[i];
    }
    c[n-1]=0;
    ll ans=0;
    ans+=b[a[0]-1];
    //cout<<"b0.. "<<b[a[0]-1]<<"\n";
    ll pre=a[0];
    rep (i,1,n)
    {
        ans+=b[a[i]-1];
        //cout<<"b.. "<<b[a[i]-1]<<"\n";
        if (pre+1==a[i])
        {
            ans+=c[pre-1];
        }
        pre=a[i];
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int,read().split())

d = {}
for i in a:
    if i in d: d[i] += 1
    else: d[i] = 1

M = 10**6+1
sieve = [0]*(M)
for k,v in d.items():
    for i in range(k,M,k):
        sieve[i] += v


ans = 0
for ai in a:
    if sieve[ai] == 1:
        ans += 1

print(ans)

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

string s;

int main() {
    cin>>s;
    map<string, int> mp;
    mp["SUN"]=7; mp["MON"]=1; mp["TUE"]=2; mp["WED"]=3; 
    mp["THU"]=4; mp["FRI"]=5; mp["SAT"]=6;
    cout<<(7-mp[s]==0 ? 7:7-mp[s])<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Triangle | diff Triangle.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Triangle.cpp && ./a.out

/*
 
 7/21/2019
 
 5:00-6:06 give up
 6:50-7:08 RE
 7:45-
 
 */

LL S;

LL isqrt(LL x) {
  assert(x>0);
  LL y=(LL)(sqrtl((long double) x)+0.5);
//  while(y*y<x) ++y;
//  while(y*y>x) --y;
  return y;
}

void pr(LL a, LL b, LL c, LL d) {
  assert(a<=1e9&&b<=1e9&&c<=1e9&&d<=1e9);
  assert(a*d-b*c==S);
  println("%lld %lld %lld %lld %lld %lld", 0LL,0LL,a,b,c,d);
}
void solve() {
  LL a=isqrt(S);
  dump(a,a*a,S);
  LL d=a;
  while(a*d<S) ++d;
  if(a*d==S) {
    pr(a,0,0,d);
    return;
  }
  dump(a,d,a*d,S);
  LL bc=a*d-S;
  pr(a,bc,1,d);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>S;
  solve();
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

		int n = scanner.nextInt();
		int m = scanner.nextInt();
		
		List<List<Integer>> v = new ArrayList<>(n);
		int g_[] = new int[n];
		for (int i = 0; i < n; i ++) {
			v.add(new LinkedList<Integer>());
			g_[i] = -1;
		}
		
		for (int i = 0; i < m; i ++) {
			int s = scanner.nextInt();
			int t = scanner.nextInt();
			
			v.get(s).add(t);
			v.get(t).add(s);
		}
		
		Queue<Integer> queue = new ArrayDeque<>(n);
		
		for (int i = 0; i < n; i ++) {
			if(g_[i] != -1) continue;
			g_[i] = i;
			
			queue.add(i);
			while(!queue.isEmpty()) {
				int u = queue.remove();
				
				for (int j: v.get(u)) {
					if (g_[j] == -1) {
						g_[j] = i;
						queue.add(j);
					}
				}
			}
		}
		
		int q = scanner.nextInt();
		
		for (int i = 0; i < q; i ++) {
			if (g_[scanner.nextInt()] == g_[scanner.nextInt()]) {
				System.out.println("yes");
			} else {
				System.out.println("no");
			}
		}
		
		scanner.close();
	}
} 



Measured memory_bytes: 118828
import copy
import math

# a = get_int()
def get_int():
    return int(input())

# a = get_string()
def get_string():
    return input()

# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]

# a_list = get_string_list():
def get_string_list():
    return input().split()

# a, b = get_int_multi()
def get_int_multi():  # a, b = get_int_multi()
    return map(int, input().split())

# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))

# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    ret = 0
    n, d = get_int_multi()

    for _ in range(0, n):
        x, y = get_int_multi()

        if math.sqrt(x * x + y * y) <= d:
            ret += 1

    print(ret)

if __name__ == '__main__':
    main()




Measured memory_bytes: 9356
#include<bits/stdc++.h>
using namespace std;
int main()
{

int i,j,ami=0,tmi=0;
string s;
char ch;
cin>>s;

for(ch='A';ch<+'Z';ch++) {
        ami=0;
    for(i=0;i<s.size();i++) {
        if(ch==s[i])
            ami++;
    }
    if(ami>0)
    tmi++;
}
if(tmi==2)
    cout<<"Yes"<<endl;
else
    cout<<"No"<<endl;


    return 0;
}


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

using namespace std;

#define ll long long

int n;
int a[100005][3];
int s[100005][3];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    for (int j = 0; j < 3; j++) {
        s[0][j] = a[0][j];
    }
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            s[i][j] = max(s[i - 1][(j + 1) % 3], s[i - 1][(j + 2) % 3]) + a[i][j];
        }
    }
    cout << max(max(s[n - 1][0], s[n - 1][1]), s[n - 1][2]) << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cmath>
#include <limits>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;



long long xxor2(long long N, long long K, long long a[]) {
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) {
      A[i] = a[i];
    }
        
    long long res = 0;
    for (int d = 60; d >= -1; --d) { // d = -1 は X = K の場合
        if (d != -1 && !(K & (1LL<<d))) continue;
	// go if k = 1
        
        long long tmp = 0;
        for (int e = 60; e >= 0; --e) {
            long long mask = 1LL<<e;
            long long num = 0;
            for (int i = 0; i < N; ++i) if (A[i] & mask) ++num;
            
            if (e > d) {
                if (K & mask) tmp += mask * (N - num);
                else tmp += mask * num;
            }
            else if (e == d) {
                tmp += mask * num;
            }
            else {
                tmp += mask * max(num,  N - num);
            }
        }
        res = max(res, tmp);
    }
    return res;
}

int max_bit(long long k) {
  int counter = 0;
  while(k !=0) {
    k = k >> 1;
    counter++;
  }
  return counter;
}

long long xxor(long long n, long long k, long long a[]) {
  int k_bit_peek = max_bit(k);

  int begin = k_bit_peek;
  for(long long i=0;i<n;i++) {
    begin = max(begin, max_bit(a[i]));
  }
  // all zero
  if(begin ==0) {
    return 0;
  }
  //cout << "max_bit: " << begin << endl;
  
  long long res = 0;
  for(int i=begin; i!=-1; i--) {
    if(i != 0 && ( (k & (1LL << (i-1))) == 0)) {
      continue;
    }
    long long temp_ans = 0;
    for(int j=begin; j!=0; j--) {
      long long num_of_one = 0;
      long long flag = 1LL << (j-1);
      for(long long k = 0;k<n;k++) {
	if (a[k] & flag) {
	  num_of_one++;
	}
      }
      if(j>i) {
	if(k & flag) {
	  temp_ans += flag * (n - num_of_one);
	} else {
	  temp_ans += flag * num_of_one;
	}
      } else if (j==i) {
	//cout << "j==i " << flag * num_of_one << endl;
	temp_ans += flag * num_of_one;
      } else {
	//cout << "j<i " << flag * max(num_of_one, n-num_of_one) << endl;
	temp_ans += flag * max(num_of_one, n-num_of_one);
      }
    }
    // cout << "best: " << res << " current: " << temp_ans << " at " << i << endl;
    res = max(res, temp_ans);
  }
  return res;
}

int main() {
  long long n, k;
  cin >> n;
  cin >> k;
  long long a[n];
  for(long long i=0;i<n;i++) {
    cin >> a[i]; 
  }
  cout << xxor(n, k, a);
}

Measured memory_bytes: 4380