akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#define pi 3.14159265358979323846264338327950

int main() {
	int N; std::cin >> N;
	std::vector<int> P(N);
	std::vector<int> Q(N);
	std::vector<int> J(N);
	for (auto& r : P) std::cin >> r;
	for (auto& rr : Q) std::cin >> rr;
	for (int i = 0; i < N; ++i)
		J[i] = i + 1;

	std::sort(J.begin(), J.end());
	bool  flag_p = false;
	int i = 0;
	do {
		flag_p = false;
		++i;
		for (int j = 0; j < N; ++j)
			if (P[j] != J[j])
				flag_p = true;
		if (flag_p == false)break;
	} while (std::next_permutation(J.begin(), J.end()));

	std::sort(J.begin(), J.end());
	bool flag_q = false;
	int ii = 0;
	do {
		flag_q = false;
		++ii;
		for (int jj = 0; jj < N; ++jj)
			if (Q[jj] != J[jj])
				flag_q = true;
		if (flag_q == false)break;
	} while (std::next_permutation(J.begin(), J.end()));
	std::cout << std::abs(i - ii) << std::endl;

	return 0;
}

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

class Dice{
public:
  int f[6]; // face
  Dice(){} // instance
  void roll(int i,int j,int k,int l){
    int t = f[i];
    f[i] = f[j];
    f[j] = f[k];
    f[k] = f[l];
    f[l] = t;
  }
  void roll_y(){ roll(0, 2, 5, 3); } // to W
  void roll_x(){ roll(0, 1, 5, 4); } // to N
  void roll_z(){ roll(1, 2, 4, 3); }
};

int getRight( Dice d1, int f1, int f2 ){
  int i, j;
  for( i = 0; i < 6; i++ ){
    for( j = 0; j < 4; j++ ){
      if( d1.f[0] == f1 && d1.f[1] == f2 ) return d1.f[2];
      d1.roll_z();
    }
    if( i % 2 == 0 ) d1.roll_y();
    else d1.roll_x();
  }
  return -1;
}

int main(){
  Dice d;
  int f1, f2, i, q;

  for( i = 0; i < 6; i++ ) cin >> d.f[i];
  cin >> q;

  for( i = 0; i < q; i++ ){
    cin >> f1 >> f2;
    cout << getRight( d, f1, f2 ) << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll d;cin>>d;
    if(d==22){
        cout << "Christmas Eve Eve Eve" << endl;
    }else if(d==23){
        cout << "Christmas Eve Eve" << endl;
    }else if(d==24){
        cout << "Christmas Eve" << endl;
    }else{
        cout << "Christmas" << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
/**
 *    author:  tourist
 *    created: 08.10.2017 15:28:25       
**/
#include <bits/stdc++.h>

using namespace std;

template <typename T>
class graph {
  public:
  struct edge {
    int from;
    int to;
    T cost;
  };

  vector <edge> edges;
  vector < vector <int> > g;
  int n;

  graph(int n) : n(n) {
    g.resize(n);
  }

  virtual void add(int from, int to, T cost) = 0;
};

template <typename T>
class undigraph : public graph<T> {
  public:
  using graph<T>::edges;
  using graph<T>::g;
  using graph<T>::n;

  undigraph(int n) : graph<T>(n) {
  }

  void add(int from, int to, T cost = 1) {
    assert(0 <= from && from < n && 0 <= to && to < n);
    g[from].push_back(edges.size());
    g[to].push_back(edges.size());
    edges.push_back({from, to, cost});
  }
};

template <typename T>
vector <T> dijkstra(const graph<T> &g, int start) {
  assert(0 <= start && start < g.n);
  vector<T> dist(g.n, numeric_limits<T>::max());
  priority_queue<pair<T, int>, vector<pair<T, int> >, greater<pair<T, int> > > s;
  dist[start] = 0;
  s.emplace(dist[start], start);
  while (!s.empty()) {
    int expected = s.top().first;
    int i = s.top().second;
    s.pop();
    if (dist[i] != expected) {
      continue;
    }
    for (int id : g.g[i]) {
      auto &e = g.edges[id];
      int to = e.from ^ e.to ^ i;
      if (dist[i] + e.cost < dist[to]) {
        dist[to] = dist[i] + e.cost;
        s.emplace(dist[to], to);
      }
    }
  }
  return dist;
  // returns numeric_limits<T>::max() if there's no path
}

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  undigraph<int> g(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--; y--;
    g.add(x, y);
  }
  vector<int> d = dijkstra(g, 0);
  bool bi = true;
  for (auto &e : g.edges) {
    if (d[e.from] % 2 == d[e.to] % 2) {
      bi = false;
      break;
    }
  }
  if (bi) {
    int cnt1 = 0;
    for (int i = 0; i < n; i++) {
      cnt1 += (d[i] % 2);
    }
    int cnt0 = n - cnt1;
    cout << (long long) cnt0 * cnt1 - m << endl;
  } else {
    cout << (long long) n * (n - 1) / 2 - m << endl;
  }
  return 0;
}


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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = 998244353;
const int N = 305;

int n,m,k;
vector<int> v,u;
vector<vector<int>> ans;
int dp[N][N][N];

int rec(int id,int carry,int can)
{
    if(id == -1)
    {
        //if(!carry){ans.pb(u);}
        return (carry == 0);
    }
    if(dp[id][carry][can] != -1)return dp[id][carry][can];
    int has = v[id] + carry;
    int ans = 0;
    for(int give=0;give<=min(has,k);give++)
    {
        int left = has - give;
        //u[id] = left;
        int now = max(0LL,left-v[id]);
        if(now > can)break;
        ans += rec(id-1,give,can-now),ans %= M;
    }
    dp[id][carry][can] = ans;
    return ans;
}

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        for(int i=0;i<N;i++)for(int j=0;j<N;j++)for(int ii=0;ii<N;ii++)dp[i][j][ii]=-1;
        string s;
        cin>>s>>k;
        n = s.length();
        k = min(n,k);
        int curr = 0;
        for(int i=0;i<n;i++)
        {
            if(s[i] == '0')
            {
                v.pb(curr);
                curr = 0;
            }
            else curr++;
        }
        if(curr)v.pb(curr);
        m = v.size();
        //u = v;
        cout<<rec(m-1,0,k)<<endl;
        //sort(all(ans));
        //for(auto u:ans){for(auto i:u)cout<<i<<" ";cout<<endl;}
    }
    return 0;
}


Measured memory_bytes: 225324
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main()
{
    vector<int> vec(3);
    rep(i, 3) scanf("%d", &vec[i]);
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    int ans = vec[0] * 10 + vec[1] + vec[2];
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3768
#include <iostream>
#include <cstdlib>
#include<regex>
#include<vector>
using namespace std;

int main()
{
    int resultNum = 0;
    
    int peopleNumber, needHeight;
    cin >> peopleNumber >> needHeight;
    
    for(int i = 0; i < peopleNumber; i++)
    {
        int h;
        cin >> h;
        
        if(h >= needHeight) resultNum++;
    }
    
    cout << resultNum << endl;
    return 0;
}

Measured memory_bytes: 384
use proconio::input;
use proconio::marker::Chars;
use proconio::marker::Usize1;
use std::collections::VecDeque;

fn main() {
    input! {
        h: usize,
        w: usize,
        ch: Usize1,
        cw: Usize1,
        dh: Usize1,
        dw: Usize1,
        maze: [Chars; h],
    }

    let mut dist = vec![vec![std::usize::MAX / 2; w]; h];
    if let Some(num) = bfs01((ch, cw), (dh, dw), &maze, &mut dist) {
        println!("{}", num);
    } else {
        println!("{}", -1);
    }
}

fn bfs01(
    start: (usize, usize),
    goal: (usize, usize),
    maze: &Vec<Vec<char>>,
    dist: &mut Vec<Vec<usize>>,
) -> Option<usize> {
    let height = maze.len();
    let width = maze[0].len();

    let dx = vec![1, 0, -1, 0];
    let dy = vec![0, 1, 0, -1];

    let mut que = VecDeque::new();
    que.push_back(start);
    dist[start.0][start.1] = 0;

    while !que.is_empty() {
        let current_pos = que.pop_front().unwrap();
        let y = current_pos.0 as i32;
        let x = current_pos.1 as i32;
        let d = dist[y as usize][x as usize];

        for i in 0..4 {
            let next_y = y + dy[i];
            let next_x = x + dx[i];
            if next_y < 0 || next_y >= height as i32 || next_x < 0 || next_x >= width as i32 {
                continue;
            }
            if maze[next_y as usize][next_x as usize] == '#' {
                continue;
            }
            if dist[next_y as usize][next_x as usize] <= d {
                continue;
            }
            dist[next_y as usize][next_x as usize] = d;
            que.push_front((next_y as usize, next_x as usize));
        }

        for i in -2..3 {
            for j in -2..3 {
                let next_y = y + j;
                let next_x = x + i;
                if next_y < 0 || next_y >= height as i32 || next_x < 0 || next_x >= width as i32 {
                    continue;
                }
                if maze[next_y as usize][next_x as usize] == '#' {
                    continue;
                }
                if dist[next_y as usize][next_x as usize] <= d + 1 {
                    continue;
                }
                dist[next_y as usize][next_x as usize] = d + 1;
                que.push_back((next_y as usize, next_x as usize));
            }
        }
    }

    let ans = dist[goal.0][goal.1];
    if ans == std::usize::MAX / 2 {
        return None;
    } else {
        return Some(ans);
    }
}



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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;

struct eT
{
	void setd ( int _u, int _v, int _l )
	{
		u = _u, v = _v, last = _l;
	}

	int u, v, last;
}edge[MAXN*2];

int n;
int ke, la[MAXN];
int sg[MAXN];

void init ();
void input ();
void work ();

int dfs ( int now, int fa );



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	scanf ( "%d", &n );
	int u, v;
	ke = 0;
	INIT ( la, -1 );
	lp ( i, 1, n ){
		scanf ( "%d%d", &u, &v );
		edge[ke].setd ( u, v, la[u] );
		la[u] = ke++;
		edge[ke].setd ( v, u, la[v] );
		la[v] = ke++;
	}
}

void work ()
{
	// main work

	printf ( dfs ( 1, -1 ) ? "Alice\n" : "Bob\n" );
}



int dfs ( int now, int fa )
{
	sg[now] = 0;
	for ( int i = la[now]; ~i; i = edge[i].last ){
		if ( edge[i].v ^ fa ) sg[now] ^= ( dfs ( edge[i].v, now ) + 1 );
	}
	return sg[now];
}

Measured memory_bytes: 8064
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;
long long a, b, x;
int main() {
	cin >> a >> b >> x;
	long long D = (a + x - 1) / x;
	long long E = b / x;
	cout << E - D + 1 << endl;
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define sz(a) (int)a.size()
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define vii vector<pii>
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(){
    int n;cin>>n;
    string s;cin>>s;
    int dp[n+1][26];
    memset(dp,0,sizeof(dp));
    int ans=0;
    rep(1,n+1){
        repi(j,0,26) dp[i][j]=dp[i-1][j];
        dp[i][s[i-1]-'A']++;
    }
    rep(4,n+1){
        int n1=s[i-1]-'A';
        repi(j,2,i){
            // trace(d);
            int n2=s[j-1]-'A';
            if(n1==n2) continue;

            int d=j-(i-j);
            // trace(j,d,ans,n1,n2,dp[d][n1],dp[d][n2]);;
            if(d>=1){
                if(s[d-1]-'A'!=n1 && s[d-1]-'A'!=n2){
                    // ans-=dp[d][s[d-1]-'A'];
                    ans-=1;
                }
                // else if(s[d-1]-'A'==n2){
                //     ans-=dp[d][n2];
                // }
            }
            // trace()
            // if(d<1) continue;
            repi(k,0,26){
                if(k==n1||k==n2) continue;
                ans+=dp[j-1][k];
            }
        }
        // trace(i,ans);
    }
    cout<<ans;



    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4472
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL


struct node{
  struct node *parent;
  struct node *l;
  struct node *r;
  int key;
};

typedef struct node * Node;

void insert(Node,int);
void PrintInorder(Node );
void PrintPreorder(Node );
Node find(Node ,int);
Node rt,newnode;

main(){

  int n,i,k;
  char T[20];

  scanf("%d",&n);

  rt = malloc(sizeof(struct node));

  for( i=0 ; i<n ; i++ ){
    scanf("%s",T);

    if( T[0] == 'i'){
      scanf("%d",&k);

      if( i != 0)
    insert(rt, k);

      else
    rt->key = k;
    }
    else if(T[0] == 'p'){
      PrintInorder(rt);
      printf("\n");
      PrintPreorder(rt);
      printf("\n");
    }
    else{
      scanf("%d",&k);
      if(find(rt,k)==NIL)printf("no\n");
      else printf("yes\n");
    }
  }
  return 0;
}

void insert(Node T, int k){

  Node x,y,z;
  z = malloc(sizeof(struct node));
  z->key =k;
  z->l = z->r = NIL;

  y = NIL;
  x = T;
  while(1){
    y = x;
    if( z->key < x->key )
      x = x->l;
    else
      x = x->r;

    if( x == NIL )break;
  }
  z->parent =y;
    if( y == NIL )
      T = z;
    else if(z->key < y->key)
      y->l = z;
    else
      y->r = z;

}



void PrintPreorder(Node T){
  if(T != NIL){
    printf(" %d",T->key);

    PrintPreorder(T->l);
    PrintPreorder(T->r);

  }
  else return ;
}

Node find(Node T,int k){
  if(T == NIL || k == T->key)return T;
  if(k < T->key )return find(T->l,k);
  else return find(T->r,k);
}

void PrintInorder(Node T)
{
  if(T != NIL){
     PrintInorder(T->l);

  printf(" %d",T->key);

   PrintInorder(T->r);
  }
  else return;

}

Measured memory_bytes: 19364
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {
	ull val;
	cin>>val;
	if(val&1) {
		cout<<0;
		return;
	}
	ull now = 10;
	ull ans = 0;
	ull i = 1;
	ull upto = 1e18;
	for(;val/now>=1;now*=5){ans+=(val/now);}
	//ans-=val/5;
	//for(now=50;val/now>=1;now*=10)ans+=val/now;
	//i=1;
	//for(now = 50;now<=val;now*=100,i++)ans+=val/now;
	cout<<ans;
}//10 -1 100 - 

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3624
nm = gets.chomp.split
n = nm[0].to_i
m = nm[1].to_i

foods = Array.new(m+1, 0)

n.times do
    input = gets.chomp.split
    k = input[0].to_i
    k.times do |i|
        a = input[i+1].to_i
        foods[a] += 1
    end
end

puts foods.count(n)

Measured memory_bytes: 3836
<?php
	fscanf(STDIN,"%d%d%d",$a,$b,$c);
	$b_count = intdiv($b,$c);
	if($a==0){
      	echo  ($b_count+1)."\n";
      	exit;
    } 
	$a_count = intdiv(($a-1),$c);
	echo ($b_count-$a_count)."\n";
    

//echo intdiv(1000000000000000000,3);

Measured memory_bytes: 16164
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }



int main(){
  int n;
  cin >> n;
  vl a(n);
  int cnt = 0;
  long sum = 0;
  rep(i,n) {
    cin >> a.at(i);
    if(a[i] < 0) {
      cnt++;
      a[i] *= -1;
    }
    sum += a[i];
  }
  sort(all(a));
  
  if(cnt % 2 == 0){
    cout << sum << endl;
  }else{
    cout << sum - a[0]*2 << endl;
  }
}


Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e3 + 5;

int n, k;
int a[N], b[N];

int cnt(int x)
{
	int cnt = 0;
	for(int i = 1; i <= n; i++)
	{
		int cur = 0;
		for(int j = i; j <= n; j++)
		{
			cur += a[j];
			if((cur & x) == x)
				cnt++;
		}
	}
	return cnt >= k;
}

int32_t main()
{
	IOS;
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	int ans = 0, mask = 0;
	for(int i = 50; i >= 0; i--)
	{
		if(cnt(mask + (1LL << i)))
			mask += (1LL << i);
	}
	cout << mask;
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, k;
vector<i64> a;
array<array<i64, 2>, 52> dp;
int main() {
  cin >> n >> k;
  read_n(a, n);
  bool lz = true;
  for (int d = 50; d >= 0; --d) {
    i64 one = 0;
    for (i64 x : a) {
      one += (x >> d) & 1;
    }
    i64 zero = n - one;

    if (!lz) {
      dp[d][0] = (dp[d + 1][0] << 1) + max(zero, one);
    }
    if ((k >> d) & 1) {
      dp[d][0] = max(dp[d][0], (dp[d + 1][1] << 1) + one);
      lz = false;
    }
    dp[d][1] = (dp[d + 1][1] << 1) + ((k >> d) & 1 ? zero : one);
  }
  cout << max(dp[0][0], dp[0][1]) << endl;
  return 0;
}


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


int main(){
	while (true)
	{
		int n, a[5001] = {};
		long long int ans = -100000, sum;
		cin >> n;
		if (n == 0) { break; }
		for(int i = 0;i<n;i++){
			cin >> a[i];
		}
		for(int i = 0;i<n;i++){
			sum = 0;
			for(int j = i;j<n;j++){
				sum += a[j];
				if(sum > ans){
					ans = sum;
				}
			}
		}

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

Measured memory_bytes: 2976
n = int(input())
all_list = []
odd_list = []

for i  in range (1, n+1):
    if i % 2 == 0:
        all_list.append(i)
    else:
        odd_list.append(i)
        all_list.append(i)
        
print('{:.10f}'.format(len(odd_list)  / len(all_list)))

Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
    long long N,K;
    cin>>N>>K;

    long long M = (N - (N / K) * K);

    cout<< min(M, (long long)(abs(M-K)) )<<endl;

    return 0;

}


Measured memory_bytes: 256
//...Bismillahir Rahmanir Rahim...
// Code by    Asad Bin Saber

#include <bits/stdc++.h>

using namespace std;

// typedefs...
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

// constants...
const double PI = acos(-1);
const int Mod = 1e9+7; // 998244353;
const int MXS = 2e5+5;
const int MXI = 1e9+5;
const ll MXL = 1e15+5;
const int INF = 1e5+5;

// defines...
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

// chess moves...
// int dx[] = {+0, +0, -1, +1}; ///Up-down, Left-Right
// int dy[] = {+1, -1, +0, +0};
// int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
// int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1};
// int dx[] = {-2, -2, -1, -1,  1,  1,  2,  2}; ///Knight's Move
// int dy[] = {-1,  1, -2,  2, -2,  2, -1,  1};

// structs...
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

// functions...
ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll lcm(ll a, ll b)
{
    return (a/gcd(a, b)*b);
}
ll comb(ll a, ll b, ll M)
{
    ll x = max(a-b, b), ans=1;

    for(ll K=a, L=1; K>=x+1; K--, L++){
        ans *= K;
        ans /= L;
    }

    return ans % M;
}


void task()
{
    //code here...
    
    int a, b, c;
    
    cin >> a >> b >> c;
    
    if((a==5 && b==5 && c==7) || (a==7 && b==5 && c==5) || (a==5 && b==7 && c==5)) cout << "YES\n";
    else cout << "NO\n";
}


int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    task();

    return 0;
}



Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int) 1e9 + 23111992;
const ll LINF = (ll) 1e18 + 23111992;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int mrand() {return abs((int) mt());}
inline int mrand(int k) {return abs((int) mt()) % k;}
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
#define endln cerr << "\n";

void chemthan() {
    string s; cin >> s;
    cout << s.substr(0, 3) << "\n";
}

int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 3660
import math

N = input()
N = int(N)

gcds = []

for i in range(0,N):
  gcds.append([])
  for j in range(0,N):
    gcds[i].append(math.gcd(i+1,j+1))


sum = 0
for i in range(0,N):
    for j in range(0,N):
        for k in range(0,N):
            sum += gcds[ gcds[i][j] -1 ][k]

print(sum)

Measured memory_bytes: 9420
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    string S;
    cin >> S;
    if(S[0] == S[1] || S[1] == S[2] || S[3] == S[4] || S[2] == S[3]){
        cout << "Bad\n";
    }
    else{
        cout << "Good\n";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e1+10;
int a[4];
int main()
{
    int n,i;
    memset(a,0,sizeof a);
    cin>>n;
    for(i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        a[x%4]++;
    }
    int sum=a[1]+a[3]+(a[2]>0);
    if(sum<=a[0]+1)cout<<"Yes";
    else cout<<"No";
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MAX = 100000;
const int N = 100010;

const int MOD = 2019;

struct mint {
	ll x;
	mint(ll x=0):x((x%MOD+MOD)%MOD){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {if ((x+=a.x)>=MOD) x-=MOD; return *this;}
	mint& operator-=(const mint a) {if ((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
	mint& operator*=(const mint a) {(x*=a.x)%=MOD; return *this;}
	mint operator+(const mint a) const {mint res(*this); return res+=a;}
	mint operator-(const mint a) const {mint res(*this); return res-=a;}
	mint operator*(const mint a) const {mint res(*this); return res*=a;}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
 		return a;
	}

	// For prime mod.
	// Do not use if MOD is not prime number !!
	mint inv() const { return pow(MOD-2);}
	mint& operator/=(const mint a) { return (*this) *= a.inv();}
	mint operator/(const mint a) const {mint res(*this); return res/=a;}
};

int main() {
//	cout << fixed << setprecision(15);
	string s;
	cin >> s;
	reverse(s.begin(), s.end());
	vi c(MOD);
	c[0]++;
	mint coef(1);
	mint sum(0);
	ll ans = 0;
	rep(i, s.size()) {
		sum += mint(s[i] - '0') * coef;
		coef *= mint(10);
		ans += c[sum.x];
		c[sum.x]++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std; 
const int maxn = 100500;


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    long long n, ans = 0;
    cin >> n;
    for(long long i = 1 ; i * i <= n ; ++i)
        if(n % i == 0){
            int a = i - 1;
            long long b = (n / i) - 1;
            if(a && (n / a) == (n % a)) ans += a;
            if(b && (n / b) == (n % b)) ans += b;
        }
    cout << ans << '\n';
    return 0;

}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class A { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		int A = GetInt();
		int B = GetInt();
		WriteLine(Max(A + B, Max(2 * A - 1, 2 * B - 1)));
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 11220
n = int(input())
data = list(map(int, input().split()))
mx = max(data)
marked = [0]*(mx + 1)
for a in data:
    if marked[a] != 0:
        marked[a] += 1
    else:
        for x in range(a, mx+1, a):
            marked[x] += 1
ans = 0
for a in data:
    if marked[a] == 1:
        ans += 1
print(ans)


Measured memory_bytes: 32156
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(ll i=0;i<(ll)n;++i)
const ll INF = 999999999999999;
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) scanf("%lld",&a.at(i));
  if( n%2 == 0 ){
    for(ll i=n-1;i>=0;--i){
      if( (i+1)%2 == 0 ){
        printf("%lld ",a.at(i));
      }
    }
    for(ll i=0;i<n;++i){
      if( (i+1)%2 == 1 ){
        printf("%lld ",a.at(i));
      }
    }
  }else{
    for(ll i=n-1;i>=0;--i){
      if( (i+1)%2 == 1 ){
        printf("%lld ",a.at(i));
      }
    }
    for(ll i=0;i<n;++i){
      if( (i+1)%2 == 0 ){
        printf("%lld ",a.at(i));
      }
    }
  }
  printf("\n");
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  switch(n%10){
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout << "hon" << endl;
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
    case 3:
      cout << "bon" << endl;
      break;
  }
  
  return 0;
}


Measured memory_bytes: 3620
/* ?  ?        ????????????????         ? ? ?            ????????????????               ??     ??        ? ? ?           ???????        
		?             ??              ?       ?                 ??                      ??   ??        ?       ?        ??    ??     
   		 ?            ??             ?         ?                ??                      ?? ??         ?         ?      ??     ??         
  ?????????           ??             ?         ?                ??                      ??            ?         ?     ??      ??         
		 ?            ??             ?         ?                ??                      ?? ??         ?         ?   ??????????????                    
		?             ??              ?       ?                 ??                      ??   ??        ?       ?    ??          ??         
   ?  ?               ??                ? ? ?                   ??                      ??     ??        ? ? ?     ??           ??          
 
 
    ??     ?        ??    ?   ?   ?  ?   ??          ?  ?      ??     ?    ?    ????????  ?    ?                       
   ?      ? ?      ?  ?    ???    ????  ?  ?         ????     ?  ?    ?  ? ?       ??     ?  ? ?                       
   ?     ?   ?     ?  ?    ???    ?  ?  ?  ?         ?  ?    ??????   ? ?  ?       ??     ? ?  ?                 
    ??  ?     ?     ??    ?   ?   ?  ?   ??          ?  ?   ?      ?  ?    ?       ??     ?    ?                                      
                                                                                       
     ?      ?????    ??????    ?  ?    ???           ???????     ???     ????????    ???????       ?? ??      ?? ??     ??????????    ??                                                                               
    ? ?     ?        ??        ? ?   ?     ?         ??   ??   ?     ?      ??       ??            ??  ??    ??  ??         ??        ?? 
   ?   ?    ?????    ??        ??    ?     ?         ??   ??   ?     ?      ??       ???????       ?? ??      ?? ??         ??        ?? ??                                                           
  ?     ?   ?        ??        ? ?   ?     ?         ??   ??   ?     ?      ??       ??            ??        ??  ??         ??        ??  ?? 
 ?       ?  ?????    ??        ?  ?    ???           ??   ??     ???        ??       ????????      ??       ??   ??         ??        ?? ??                         
 
 
 
 
 
*/
 
#include <bits/stdc++.h>
 
using namespace std;
 
 
#define pb push_back
#define F first
#define S second
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end() 
 
int n,y,m = 1000000000,cnt;
vector <int> v;
int a[200005];
 
int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	if (n != 3 && m != 3){
		cout << 3;
	}
	else if (n != 2 && m != 2){
		cout << 2;
	} 
	else {
		cout << 1;
	}
	return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

vi d {0,1,2,3,4,5,6,7,8,9};
   
bool f(int n){
    int n2=n;
    while(n2){
        if(d[n2%10]==-1)
            return false;
        else
            n2/=10;
    }
    return true;
}

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

    int n,k;
    cin >> n >> k;
    
    for(int i=0; i<k; i++){
        int tmp; 
        cin >> tmp;
        d[tmp]=-1;
    }

    while(!f(n))
        n++;
    cout << n;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
using namespace std;
typedef long long LL;

#define _CRT_SECURE_NO_WARNINGS
int N;
float r, t;
int x[21], y[21];

float dp[21][21][10010] = {};
float Distance(int n, int m) {
	return sqrtf( (x[n] - x[m])*(x[n] - x[m])+(y[n] - y[m])*(y[n] - y[m]) );
}
bool TurnAble(int a, int b,int c) {
	float d = acosf( ((x[b] - x[a])*(x[c] - x[b]) + (y[b] - y[a])*(y[c] - y[b])) / (Distance(a, b)*Distance(b, c)) );
	return d < (t/180.0000 * 3.141592) ;
}
int main() {
	int ans = 0;
	scanf("%d", &N);
	scanf("%f %f", &r, &t);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k <= r;k++) {
				dp[i][j][k] = r + 1;
			}
		}
		
	}
	

	for (int i = 0; i < N;i++) {
		scanf("%d %d",x+i,y+i);
	}
	for (int i = 0; i < N; i++) {
		if (i != 0) {
			dp[0][i][1] = Distance(0, i);
			if (dp[0][i][1] <= r) {
				ans = 1;
			}
		}
	}
	if (ans == 0) {
		printf("0\n");
		return 0;
	}
	for (int k = 2; k <= r; k++) {
		for (int now = 0; now < N;now++) {
			for (int j = 0; j < N; j++) {
				if (j != now) {
					if (dp[j][now][k - 1] <= r) {
						for (int i = 0; i < N; i++) {
							if (i != now && i!=j) {
								if (TurnAble(j, now, i)) {
									dp[now][i][k] = min(dp[j][now][k - 1] + Distance(now, i), dp[now][i][k]);
									if (dp[now][i][k]<=r) {
										ans = max(ans, k);
									}
								}
							}
						}
					}
				}
			}
		}
	}

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


Measured memory_bytes: 18524
// Phoenix

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

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

const int maxn=2e5+10,mod=1e9+7;
const ll inf=1e18;

int a[maxn],n;
map<int,int>mp;// pos // dig

bool check(int num){
    mp.clear();
    int ln=0;
    for(int i=0;i<n;i++){
	if(ln<a[i]){
	    ln=a[i];
	}
	else{
	    if(!mp.empty()){
		int x=mp.rbegin()->F;
		while(x>=a[i]){
		    mp.erase(x);
		    if(mp.empty()) break;
		    x=mp.rbegin()->F;
		}
	    }
	    int pos=a[i]-1;
	    while((++mp[pos])==num){
		mp.erase(pos);
		if(pos==0) return 0;
		--pos;
	    }
	    ln=a[i];
	}
    }
    return 1;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
	cin>>a[i];
    bool yes=1;
    for(int i=0;i<n-1;i++)
	yes&=a[i]<a[i+1];
    if(yes)
	return cout<<1<<endl,0;
    int l=2,r=n,ans=n;
    while(l<=r){
	int mid=(l+r)/2;
	if(check(mid))
	    ans=mid,r=mid-1;
	else
	    l=mid+1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>
#include <sstream>
typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
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 = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}
/*
ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}*/
int main() {
	cin >> n >> m;
	vector<ll> a(n);
	ll sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	vector<ll> dp(n+1,0);

	dp[1] = a[0];
	for (ll i = 2; i < n+1; i++) {
		dp[i] = dp[i - 1] + a[i-1];
	}
	ll res = 0;
	map<ll, ll> mp;
	rep(i, n+1) {

		mp[dp[i]%m]++;
	}
	for (auto i = mp.begin(); i != mp.end(); i++) {
		if (i->second >= 2) {
			res += i->second*(i->second-1)/2;
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

double eps = 1e-5;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int A, B;
    cin >> A >> B;
    for(int i = 1; i <= 10000; i++){
        int a = (int)((double)i*0.08+eps);
        int b = (int)((double)i*0.1+eps);
        if(a == A && b == B){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    string s, t;
    cin >> s >> t;
    sort( ALL( s ) );
    sort( ALL( t ), greater<int>() );
    cout << ( s < t ? "Yes" : "No" ) << endl;
    return 0;
}

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

int n;
vector<int> G[N];

bool share[N];

int shcnt;

bool dfs(int x, int prev){
  
  if(x==n-1) return true;
  
  for(int i=0;i<G[x].size();i++){
    
    int nx=G[x][i];
    
    if(nx==prev) continue;

    if(dfs(nx,x)){
      
      if(x!=0) share[x]=true, shcnt++;
      
      return true;
    }
    
  }

  return false;  
}

int fcnt, scnt;

void dfsf(int x, int prev){
  
  if(x==n-1||share[x]) return;
  
  if(x!=0) fcnt++;

  for(int i=0;i<G[x].size();i++){
    
    int nx=G[x][i];
    
    if(nx==prev) continue;

    dfsf(nx,x);
  }

}

void dfss(int x, int prev){
  
  if(x==0||share[x]) return;
  
  if(x!=n-1) scnt++;

  for(int i=0;i<G[x].size();i++){
    
    int nx=G[x][i];
    
    if(nx==prev) continue;

    dfss(nx,x);
  }

}

void dfs2(int x,int prev){

  for(int i=0;i<G[x].size();i++){
    
    int nx=G[x][i];

    if(nx==prev||nx==0||nx==n-1||share[nx]) continue;

    share[nx]=true;
    
    dfs2(nx,x);
    
  }
  
}

typedef pair<int,int> P;

int d[N];
queue<P> q;

int main(){
  
  cin>>n;

  for(int i=0;i<n-1;i++){
    
    int a, b;
    cin>>a>>b;

    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
    
  }

  dfs(0,0);
  
  dfsf(0,0);

  dfss(n-1,n-1);
  
  for(int i=0;i<n;i++)
    if(share[i]) dfs2(i,i);

  memset(d,-1,sizeof(d));

  for(int i=0;i<G[0].size();i++)
    if(share[G[0][i]]) q.push(P(0,G[0][i]));
  
  for(int i=0;i<G[n-1].size();i++)
    if(share[G[n-1][i]]) q.push(P(1,G[n-1][i]));

  while(!q.empty()){

    P t=q.front(); q.pop();
    
    int color=t.first;
    int node=t.second;
    
    if(d[node]==-1) d[node]=color;
    else continue;

    for(int i=0;i<G[node].size();i++){
      
      int nx=G[node][i];
      if(nx==0||nx==n-1) continue;

      q.push(P(color,G[node][i]));
      
    }
    
  }

  for(int i=0;i<n;i++){
    if(d[i]==0) fcnt++;
    if(d[i]==1) scnt++;
  }

  if(fcnt>scnt) cout<<"Fennec"<<endl;
  else cout<<"Snuke"<<endl;
  
  return 0;
}


Measured memory_bytes: 12416
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	ll x;
	cin >> x;
	ll ans = x / 11 * 2;
	x %= 11;
	if (x > 6) ans += 2;
	else  if (x > 0 && x <= 6) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
#n=int(input())
n,x=map(int,input().split())
xl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

import fractions
#gcd=fractions.gcd(a,b)#最大公約数
#lcm=(a//fractions.gcd(a,b))*b #最小公倍数

res=0

for i in range(n):
    res=fractions.gcd(res,abs(x-xl[i]))

print(res)


Measured memory_bytes: 14252
#include <iostream>
using namespace std;
static int N_MAX = 100;

void p(int A[], int N) {
	for (int i = 0; i < N; ++i) {
		if (i > 0) {
			cout << " ";
		}
		cout << A[i];
	}
	cout << endl;
}

int bubbleSort(int A[], int N) {
	int count = 0;
	int flag = 1;
	while (flag) {
		flag = 0;
		for (int j = N - 1; j > 0; --j) {
			if (A[j] < A[j - 1]) {
				int a = A[j];
				A[j] = A[j - 1];
				A[j - 1] = a;
				flag = 1;
				++count;
			}
		}
	}
	return count;
}

int main() {
	int N;
	int A[N_MAX];
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}

	int count = bubbleSort(A, N);
	p(A, N);
	cout << count << endl;
}

Measured memory_bytes: 1160
n = gets.to_i
a = gets.split.map(&:to_i)

#\sum_i |a[i]-b| の最小値を求める問題に帰着
0.upto(n-1) do |i|
  a[i] = a[i] - i - 1
end

a.sort!

#b=(a[0],...,a[n-1]の中央値)のとき最小となる
b =
  if n%2 == 1
    a[(n-1)/2]
  else
    (a[n/2] + a[n/2 -1])/2
  end

sum = 0
0.upto(n-1) do |i|
  sum += (a[i]-b).abs
end

puts sum



Measured memory_bytes: 17536