akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define lli long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<lli> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

lli n, w;
lli W[102], V[102];
lli cache[101][N];

lli dp(lli idx, lli weight) {

    if(idx > n) {
        return 0;
    }

    lli &ans = cache[idx][weight];

    if(ans != -1) {
        return ans ;
    }

    if(weight >= W[idx])
        ans = max(V[idx] + dp(idx + 1, weight - W[idx]), dp(idx + 1, weight));
    else
        ans = dp(idx + 1, weight);

    return ans ;

}

void solve()
{

    cin>>n>>w;

    memset(cache, -1, sizeof cache);

    for(int i = 1; i <= n; i ++) {
        cin>>W[i]>>V[i];
    }

    lli ans = dp(1, w);

    cout<<ans;

    cout<<"\n";
    return ;
}

/*
*/

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

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


Measured memory_bytes: 237440
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int q;
    cin >> q;

    deque<char> deq;
    rep(i,n){
        deq.push_back(s[i]);
    }
    int flag = 0;
    rep(loop, q){
        int x;
        cin >> x;
        if(x == 1){
            flag++;
            flag %= 2;
        }else{
            int f;
            char c;
            cin >> f >> c;
            if((flag + f) % 2 == 0){
                deq.push_back(c);
            }else{
                deq.push_front(c);
            }
        }
    }

    if(flag){
        reverse(deq.begin(), deq.end());
    }

    for_each(deq.begin(), deq.end(), [](char c){
        cout << c;
    });
    cout << endl;
    return 0;
}
 
 


Measured memory_bytes: 896
#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;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int main()
{
    ll H, W, D, Q;
    cin >> H >> W >> D;
    vvll A(W + 1, vll(H + 1));
    vll dist(W * H + 1);
    vector<pair<ll, ll>> Ainv(W * H + 1);
    rep2(i, 1, H + 1)
    {
        rep2(j, 1, W + 1)
        {
            cin >> A[j][i];
            Ainv[A[j][i]] = {j, i};
        }
    }
    rep2(i, 1, W * H + 1)
    {
        if (i <= D)
        {
            dist[i] = 0;
        }
        else
            dist[i] = dist[i - D] + abs(Ainv[i].first - Ainv[i - D].first) + abs(Ainv[i].second - Ainv[i - D].second);
    }
    cin >> Q;
    vll L(Q), R(Q);
    rep(i, Q)
    {
        cin >> L[i] >> R[i];
    }
    rep(i, Q)
    {
        cout << dist[R[i]] - dist[L[i]] << endl;
    }
    return 0;
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const long long mod = 1e9 + 7;

int n, k;
long long arr[MAXN];
void solve(){
    int i = 0;
    int cnt = 0;
    while(cnt < k){
        vector<long long> hola(n + 1);
        int j = 0;
        for(j = 0; j < n; j++){
            hola[max(0LL, j - arr[j])]++;
            hola[min((long long)n - 1, j + arr[j]) + 1]--;
        }
        long long sum = 0;
        long long mn = MAXN * MAXN;
        for(j = 0; j < n; j++){
            sum += hola[j];
            arr[j] = sum;
            mn = min(mn, arr[j]);
        }
        if(mn == n)
            break;
        cnt++;
    }
    for(i = 0; i < n; i++)
        cout << arr[i] << " ";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    int i = 0;
    for(i = 0; i < n; i++)
        cin >> arr[i];
    solve();
    return 0;
}

Measured memory_bytes: 6776
#[allow(unused_imports)]
use std::cmp::max;
#[allow(unused_imports)]
use std::fmt;
#[allow(unused_imports)]
use std::fmt::Debug;
#[allow(unused_imports)]
use std::io;
#[allow(unused_imports)]
use std::str::FromStr;

fn main() {
    let n: usize = get_vec_input()[0];
    let count = (1..n + 1)
        .filter(|x| x % 2 != 0)
        .map(|x| count_div(x))
        .filter(|x| *x == 8)
        .collect::<Vec<_>>()
        .len();

    println!("{}", count);
}

#[allow(dead_code)]
fn count_div(value: usize) -> usize {
    let mut count = 0usize;
    for i in 1..200 + 1 {
        if value % i == 0 {
            count += 1;
        }
    }
    count
}

#[allow(dead_code)]
fn get_digit(value: i64) -> i64 {
    let mut digit = 0i64;
    let mut value = value;
    while value != 0 {
        value /= 10;
        digit += 1;
    }
    digit
}

#[allow(dead_code)]
fn sum_digit2(value: String) -> u32 {
    return value.chars().fold(0u32, |a, b| a + b.to_digit(10).unwrap());
}

#[allow(dead_code)]
fn sum_digit(value: i64) -> i64 {
    if value < 10 {
        return value;
    }
    return sum_digit(value / 10) + value % 10;
}

#[allow(dead_code)]
fn update_max<T>(left: &mut T, right: T)
where
    T: std::cmp::Ord + std::clone::Clone,
{
    if *left < right {
        *left = right.clone();
    }
}

#[allow(dead_code)]
fn update_min<T>(left: &mut T, right: T)
where
    T: std::cmp::Ord + std::clone::Clone,
{
    if *left > right {
        *left = right.clone();
    }
}

#[allow(dead_code)]
fn get_vec_input<T>() -> Vec<T>
where
    T: FromStr,
    T::Err: Debug,
{
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("Failed to read line");
    let vec: Vec<T> = input
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    vec
}

#[allow(dead_code)]
fn get_tuple_input() -> (u64, f32) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();
    let c: u64 = iter.next().unwrap().parse().unwrap();
    let n: f32 = iter.next().unwrap().parse().unwrap();
    (c, n)
}

#[allow(dead_code)]
fn get_string_input() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    s.trim().to_string()
}


Measured memory_bytes: 4352
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,5);
  var N = input[0];
  input.shift();
  input.push(0);
  if(input[0] != 0){
     myout(-1);
    return;
  }
  var output = 0;
  //いもす法いける
  var list = new Array(N+1).fill(0);
  for(var i = N-1; i >= 1; i--){
    var mae = input[i];
    var ato = input[i+1];
    if(ato - mae > 1){
       myout(-1);
      return;
    }
    if(mae - ato >= 0){
       list[i+1]--;
       list[i-(input[i]-1)]++;
    }else if(ato - mae == 1){
       continue;
    }
  }
  for(var i = 0; i < N; i++){
    list[i+1] += list[i];
  }
  for(var i = 0; i < N; i++){
    output += list[i];
  }
  myout(output);
}
Main(myin());

Measured memory_bytes: 35280
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <algorithm>
#define int long long
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 100010;
int n,ans;
string str[N];
signed main(){
	scanf("%lld",&n);
	for(int i=1; i<=n; i++){
		cin>>str[i];
		sort(str[i].begin(), str[i].end());
	}
	sort(str+1,str+1+n);
	string pre=str[1];
	int cnt=1;
	for(int i=2; i<=n; i++){
		if(str[i]==pre){
			cnt++;
		}
		else{
			ans+=cnt*(cnt-1)/2;
			cnt=1;
			pre=str[i];
		}
	}
	ans+=cnt*(cnt-1)/2;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 7296
package main
 
import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"sort"
)
 
type ByRune []rune

func (r ByRune) Len() int           { return len(r) }
func (r ByRune) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
func (r ByRune) Less(i, j int) bool { return r[i] < r[j] }

func run() {

	var N int64;
    N = nextInt();
    s := make([]string,N);
    for i := 0 ; i < int(N) ; i++ {
        s[i] = next();
    }
	solve(N, s);

}

func solve(N int64, s []string){	  
	for i, c := range s {
		s[i] = SortStringByCharacter(c)

	}
	
	m := map[string]int{}
	sum := 0

	for _, g := range s {
		v := m[g]
		m[g] = v+1
		sum += v
	}
	Println(sum)
	
}

func StringToRuneSlice(s string) []rune {
	var r []rune
	for _, runeValue := range s {
			r = append(r, runeValue)
	}
	return r
}

func SortStringByCharacter(s string) string {
	var r ByRune = StringToRuneSlice(s)
	sort.Sort(r)
	return string(r)
}
// --- template ---
// Thanks https://gist.github.com/halllllll/853ab587fd82ee3ffe6f7fb7fb499695
 
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
 
// Caution: You will get unexpected result if a single token is larger than this size.
const BufferSize = 64 * 1024 * 1024
 
func Print(a ...interface{}) (n int, err error) {
	return fmt.Fprint(out, a...)
}
 
func Printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, format, a...)
}
 
func Println(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(out, a...)
}
 
func next() string {
	sc.Scan()
	return sc.Text()
}
 
func nextInt() int64 {
	a, err := strconv.ParseInt(next(),10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}

func nextFloat() float64 {
	a, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}

 
func main() {
	sc.Buffer(make([]byte, 0, BufferSize), BufferSize)
	sc.Split(bufio.ScanWords)
	run()
	out.Flush()
}


Measured memory_bytes: 32896
#include <bits/stdc++.h>
using namespace std;
int dp[1001][1001];
int main(void)
{
	int w,n;
	int i,j;
	int cnt=0;
	int value,weight;
	int vsum,wsum;
	char ch;
	while(1){
		cnt++;
		cin>>w;
		if(w==0){
			break;
		}
		cin>>n;
		
		for(i=0;i<=n;i++){
			for(j=0;j<=w;j++){
				dp[i][j]=0;
			}
		}
		for(i=0;i<n;i++){
			cin>>value>>ch>>weight;
			for(j=0;j<=w;j++){
				if(dp[i+1][j]<dp[i][j]){
					dp[i+1][j]=dp[i][j];
				}
				if(j+weight<=w&&dp[i+1][j+weight]<dp[i][j]+value){
					dp[i+1][j+weight]=dp[i][j]+value;
				}
			}
		}
		vsum=-1;
		for(j=0;j<=w;j++){
			if(vsum<dp[n][j]){
				vsum=dp[n][j];
				wsum=j;
			}
		}
		cout<<"Case "<<cnt<<":"<<endl;
		cout<<vsum<<endl<<wsum<<endl;
	}
	return 0;
}


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

int bubbleSort(int A[], int N) {
int sw = 0;
bool flag = 1;
for ( int i = 0; flag; i++ ) {
flag = 0;
for ( int j = N - 1; j >= i + 1; j-- ) {
if ( A[j] < A[j - 1] ) {
swap(A[j], A[j - 1]);
flag = 1;
sw++;
}
}
} 
return sw;
}

int main() {
int A[100], N, sw;
cin >> N;
for ( int i = 0; i < N; i++ )
cin >> A[i];

sw = bubbleSort(A, N);

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

return 0;
}


Measured memory_bytes: 3096
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint K, T, A;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> K >> T;
	lint maxv = 0;
	REP(i, T) {
		cin >> A;
		chmax(maxv, A);
	}
	cout << max(0ll, maxv * 2 - K - 1) << endl;
}


Measured memory_bytes: 256
//1518
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<cstring>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;

int INF=1001001001;
int dx[4] = {0,-1,0,1};
int dy[4] = {1,0,-1,0};

int main(){
	int w,h;
	while(cin >> w >> h){
		if(w==0 && h==0) break;
		int i,j,k;
		int m[22][22];
		int a[15][15];
		pint d[14];
		char in;
		int n=1;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				cin >> in;
				if(in=='x') m[i][j]=-1000;
				else if(in=='.') m[i][j]=INF;
				else if(in=='o'){
					m[i][j]=INF;
					d[0]=pint(i,j);
				}
				else{
					m[i][j]=INF;
					d[n]=pint(i,j);
					n++;
				}
			}
		}
		for(i=0;i<n;i++) for(j=0;j<n;j++) a[i][j]=INF;
		
		queue<pair<pint,int> > q;
		for(k=0;k<n;k++){
			for(i=0;i<h;i++){
				for(j=0;j<w;j++){
					if(m[i][j]!=-1000) m[i][j]=INF;
				}
			}
			q.push(pair<pint,int>(d[k],0));
			m[d[k].first][d[k].second]=0;
			while(!q.empty()){
				pair<pint,int> tmp = q.front();
				q.pop();
				for(i=0;i<n;i++){
					if(tmp.first==d[i]){
						a[k][i] = tmp.second;
						a[i][k] = tmp.second;
					}
				}
				for(i=0;i<4;i++){
					if(tmp.first.first+dx[i]>=0 && tmp.first.first+dx[i]<h && tmp.first.second+dy[i]>=0 && tmp.first.second+dy[i]<w){
						if(m[tmp.first.first+dx[i]][tmp.first.second+dy[i]]==INF){
							m[tmp.first.first+dx[i]][tmp.first.second+dy[i]]=0;
							q.push(pair<pint,int>(pint(tmp.first.first+dx[i],tmp.first.second+dy[i]),tmp.second+1));
						}
					}
				}
			}
		}
		
		int f=0;
		for(i=0;i<n;i++) for(j=0;j<n;j++) if(a[i][j]==INF) f=1;
		
		if(f==1) cout << -1 << endl;
		else{
			int p[15];
			for(i=0;i<n-1;i++){
				p[i]=i+1;
			}
			int ans=INF;
			do{
				int tmp=a[0][p[0]];
				for(i=0;i<n-2;i++){
					tmp+=a[p[i]][p[i+1]];
				}
				ans=min(ans,tmp);
			}while(next_permutation(p,p+n-1));
			cout << ans << endl;
		}
	}
			
				
	return 0;
}
	

Measured memory_bytes: 912
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}
long long hindo[100005] = {0};
int a[100005];

int main(void){
    int n;
    int tmp;
    int *ifound;
    long long ans = 1;
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; i++){
        hindo[abs((n-(i+1))-i)] += 1;
    }
    for (int i = 0; i < n; i++){
        ans *= hindo[a[i]];
        ans %= 1000000007;
        hindo[a[i]]--;
    }

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


    return 0;
}


Measured memory_bytes: 1280
S = input()
K = int(input())
d=[[0 for _ in range(400)] for _ in range(4)]
ans = [0,0,0,0]
l = len(S)
odd_diff = 0
even_diff = 0
if l == 1:
    print(int(K//2))
if l > 1:
    for i in range(4):
        s = S * (i + 1)
        l = len(s)
        for j in range(l-1):
            
            if j == 0 and s[j] == s[j+1]:
                ans[i] += 1
                d[i][0] = 1
            if j > 0 and s[j] == s[j+1] and d[i][j-1] == 0:
                ans[i] += 1
                d[i][j] = 1
    if K <= 4:
        print(int(ans[K-1]))
    elif K > 4 and K % 2 == 0:
        even_diff = ans[3] - ans[1]
        print(int(ans[1]+(K/2-1)*even_diff))
    elif K > 4 and K % 2 == 1:
        odd_diff = ans[2] - ans[0]
        print(int(ans[0]+(K//2)*odd_diff))
    


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B){
    cout << ((A*B)%2 == 0 ? NO : YES) << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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


vector <int> kmp(string str) {
	vector <int> f(str.size(), 0);
	for(int i = 1; i < str.size(); i++) {
		int j = f[i - 1];
		while(j && str[j] != str[i]) {
			j = f[j - 1];
		}
		f[i] = j + (str[i] == str[j]);
	}
	return f;
}

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string str; cin >> str;
	int f = 0;
	for(auto ch: str) {
		f |= (1 << (ch - 'a'));
	}
	if(__builtin_popcount(f) == 1) {
		cout << str.size() << "\n" << 1 << endl;
		return 0;
	}
	vector <int> a = kmp(str);
	int len = str.size() - a.back(); 
	if((int)str.size() % len || !a.back()) {
		cout << 1 << "\n" << 1 << endl;
		return 0;
	}
	int ans = 2, cnt = 0;

	reverse(str.begin(), str.end());
	vector <int> b = kmp(str);
	int n = str.size();
	for(int i = 1; i < n; i++) {
		int len = i - a[i - 1];
		if(i > 1 && i % len == 0 && a[i - 1]) {
			continue;
		}
		
		int j = n - i; len = j - b[j - 1];
		if(j > 1 && j % len == 0 && b[j - 1]) {
			continue;
		}	
		
		++cnt;
	}

	cout << ans << "\n" << cnt << endl;
}

Measured memory_bytes: 8052
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  ll x; 
  cin >> x;
  ll ans = x/11 * 2;
  int rem = x % 11;
  if (rem > 0) {
    if (rem <= 6) ans++;
    else ans += 2;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	int n, k, r, s, p;
	cin >> n >> k >> r >> s >> p;
	string t;
	cin >> t;
	int ans = 0;
	rep(i, n){
		if(i >= k) if(t[i] == t[i-k]){
			t[i] = 'a';
			continue;
		}
		if(t[i] == 'r') ans += p;
		if(t[i] == 's') ans += r;
		if(t[i] == 'p') ans += s;
	}
	cout << ans << endl;
	return 0;
}

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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[n]; rep(i,n){ gets(x[i]);}
#define ll long long
typedef pair<int, int> P;

string maze[50];
int N, M, sx = 0, sy = 0, gx, gy, f = 1000, s = 1000;
int d[50][51]; //最短経路が入る
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; //移動のベクトル

int bfs() {
  queue<P> que;
  rep(i, N){
    rep(j, M){
      d[i][j] = 100000;
    }
  }
  que.push(P(sx, sy));
  d[sx][sy] = 0; // 初期地点を入れる
  while (true) {
    P p = que.front(); que.pop(); //先頭を取り出す
    if (f == p.first && s == p.second) {
      return -1;
    }else{
      f = p.first; s = p.second;
    }
    if (p.first == gx && p.second == gy) {
      break; //ゴールなら終わり
    }

    rep(i, 4){
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 >= nx && nx > N && 0 >= ny && ny > M) {
        cout << "oh" << endl;
      }
      if (0 <= nx && nx < N && 0 <= ny && ny < M && maze[nx][ny] != '#' && d[nx][ny] == 100000) {
        que.push(P(nx, ny));
        d[nx][ny] = d[p.first][p.second] +1;
      }
    }
  }
  return d[gx][gy];
}


int main(){
  int wall = 0;
  cin >> N >> M;
  gx = N-1, gy = M-1;
  rep(i, N){
    cin >> maze[i];
  }
  int shortest = bfs(); //最短経路
  if (shortest == -1) {
    cout << shortest << '\n';
    exit(0);
  }
  rep(i, N){
    rep(j, M){
      if (maze[i][j] == '#') {
        wall += 1;
      }
    }
  }
  int result = (N*M) - wall - (shortest+1);
  cout << result << '\n';
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
class node{
public:
	node* left;
	node* right;
	int num;//num==modなら葉
	node(void){num=mod;left=nullptr;right=nullptr;}
	void insert(int in){
		if(num==mod){num=in;left=new node();right=new node();}
		else if(in<num){left->insert(in);}
		else{right->insert(in);}
	}
	bool find(int in){
		if(num==mod){return false;}
		else if(num==in){return true;}
		else if(in<num){return left->find(in);}
		else{return right->find(in);}
	}
	void inprint(void){
		if(num==mod){return;}
		left->inprint();
		cout<<" "<<num;
		right->inprint();
	}
	void preprint(void){
		if(num==mod){return;}
		cout<<" "<<num;
		left->preprint();
		right->preprint();
	}
};
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin>>n;
	node ki;
	while(n--){
		string str;cin>>str;
		if(str=="insert"){
			int x;cin>>x;
			ki.insert(x);
		}else if(str=="find"){
			int x;cin>>x;
			cout<<(ki.find(x)?"yes":"no")<<endl;
		}else if(str=="print"){
			ki.inprint();cout<<endl;
			ki.preprint();cout<<endl;
		}
		
	}
	return 0;
}



Measured memory_bytes: 34344
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    int n,m,k;
    cin>>n>>m>>k;
    vector<vector<int>> G1(n),G2(n);
    UnionFind uf(n);

    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        G1[a].push_back(b);
        G1[b].push_back(a);
        uf.merge(a,b);
    }

    rep(i,k){
        int c,d;
        cin>>c>>d;
        c--,d--;
        if(uf.issame(c,d)){
            G2[c].push_back(d);
            G2[d].push_back(c);
        }
        
    }

    rep(i,n){
        int ans=uf.size(i);
        ans--;
        ans-=G1[i].size();
        ans-=G2[i].size();
        cout<<ans<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 14552
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let n: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let S: Vec<Vec<char>> = (0..n)
        .map(|_| {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().chars().collect()
        })
        .collect();

    let ascii_lowercase = "abcdefghijklmnopqrstuvwxyz".chars().collect::<Vec<_>>();
    let mut res = vec![];
    for &c in &ascii_lowercase {
        for _ in 0..S
            .iter()
            .map(|s| s.iter().filter(|&&x| x == c).count())
            .min()
            .unwrap()
        {
            res.push(c);
        }
    }
    let ans = res
        .iter()
        .map(|&c| c.to_string())
        .collect::<Vec<_>>()
        .join("");

    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
    
    static int dfs(int[] p, int a, int b, int i){
        if(i == p.length){
            return Math.abs(a - b);
        }else{
            int ans1 = dfs(p, a + p[i], b, i + 1);
            int ans2 = dfs(p, a, b + p[i], i + 1);
            return Math.min(ans1, ans2);
        }
    }
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            if(n == 0) break;
            int[] p = new int[n];
            for(int i = 0; i < n; i++){
                p[i] = sc.nextInt();
            }
            int ans = dfs(p, 0, 0, 0);
            System.out.println(ans);
        }
    }
}



Measured memory_bytes: 28352
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N, T = map(int, input().split())
    A = [int(i) for i in input().split()]
    min_v = float('inf')
    max_dif = 0
    ans = 0

    for a in A:
        if min_v > a:
            min_v = a
        else:
            max_dif = max(max_dif, a - min_v)

    # debug(max_dif, locals())

    min_v = float('inf')

    for a in A:
        if min_v > a:
            min_v = a
        else:
            if a - min_v == max_dif:
                ans += 1

    print(ans)

if __name__ == '__main__':
    solve()

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll gcd(ll a, ll b){
    if(b>a) return gcd(b,a);
    if(a%b == 0) return b;
    return gcd(b,a%b);
}

ll ctoi(char c){ return c-'0';}

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

    string s; cin >> s;

    bool f = true;
    if(s[s.size()-1] == ')') f = false;

    ll a,b;

    if(f){
        a = 1;
        b = ctoi(s[0]);
        bool d = false;
        for (int i = 1;i < s.size();i++){
            if(s[i] == '.'){ i++; d = true;}
            if(d) a *= 10;
            b = b*10+ctoi(s[i]);
        }
    }else{
        int t1 = 0;
        int t2 = 0;
        int ten = 1;
        int t3 = 1;
        bool d = false;
        t1 = t2 = ctoi(s[0]);
        for (int i = 1;i < s.size();i++){
            if(s[i] == '.') {i++; d = true;}
            if(s[i] == '('){
                i++;
                t2 = t1;
                for (;i < s.size()-1;i++){
                    t2 = t2*10+ctoi(s[i]);
                    ten *= 10;
                }
                break;
            }
            t1 = t1*10+ctoi(s[i]);
            if(d){
                t3 *= 10;
                ten *= 10;
            }
        }
        a = ten-t3;
        b = t2-t1;
    }

    ll a2 = a/gcd(a,b);
    ll b2 = b/gcd(a,b);

    cout << b2 << '/' << a2 << endl;
    

    return 0;

}


Measured memory_bytes: 3192
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	const a = parseInt(tmp[0], 10);
	const b = parseInt(tmp[1], 10);
  const c = parseInt(tmp[2], 10);
  const remain = c - (a - b);
	const result = remain < 0 ? 0 : remain;
	//出力
	console.log('%d',result);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

ll x,y;
int main(){
  cin >> x >> y;
  if(x%y == 0) cout << "-1" << endl;
  else cout << x << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	string ans;
	for(int i=0;i<n;i++)
	{
		ans += s[i];
		ans += t[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define psb push_back
#define ppb pop_back

const int INF = 1001001001;

const long double EPS = 0.000000001;

int main() {
    long double A, B;
    // string B;

    cin >> A >> B;

    ll ans = A*B+0.001;

    cout << ans << endl;

    // ll B100 = (B[0]-'0')*100 + (B[2]-'0')*10 + (B[3]-'0');
    // ll ans = A*B100/100;

    // cout << A*B100/100 << endl;
}


Measured memory_bytes: 3704
#include <iostream>
#include <vector>
#include <algorithm>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using namespace std;
int main() {
    int n, c, k; cin >> n >> c >> k;
    vector<int> t(n); repeat (i,n) cin >> t[i];
    whole(sort, t);
    int cnt = 0;
    int l = 0;
    while (l < n) {
        int r = l;
        while (r < n and r - l < c and t[r] <= t[l] + k) ++ r;
        ++ cnt;
        l = r;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

int n,m,x,y;

int main(){
    
    cin >> n>> m >> x >> y;
    int xx= -inf,yy = inf;

    rep(i,0,n){
        int a;
        cin >> a;
        xx = max(xx,a);
    }
    rep(i,0,m){
        int a;
        cin >> a;
        yy = min(yy,a);
    }

    if(x <= xx && xx < yy && yy <= y )P("No War");
    else P("War");
    
	return  0;
}

Measured memory_bytes: 256
N = gets.to_i
S = gets.chomp.chars.take(N)

s = S.drop_while { |ch| ch == '.' }.reverse
  .drop_while { |ch| ch == '#' }.reverse

list = []
white_count = 0
black_count = 0
s.each.with_index do |ch, i|
  if ch == '#'
    if white_count > 0
      list.push([black_count, white_count])
      black_count = 1
      white_count = 0
    else
      black_count += 1
    end
  else
    white_count += 1
    list.push([black_count, white_count]) if i == s.size - 1
  end
end
dp = Array.new(list.size + 10)
dp[0] = { 'white' => 0, 'black' => 0}
list.each.with_index do |(black_count, white_count), i|
  dp[i + 1] = {}
  dp[i + 1]['white'] = dp[i]['white'] + black_count
  dp[i + 1]['black'] = [
    dp[i]['white'] + white_count,
    dp[i]['black'] + white_count,
  ].min
end
ans = [dp[list.size]['white'], dp[list.size]['black']].min
puts ans


Measured memory_bytes: 51424
import copy

n = int(input())
t = [int(i) for i in input().split()]

m = int(input())
ans = []
for i in range(m):
   v = copy.deepcopy(t)
   p, x = map(int, input().split())
   v[p-1] = x
   ans.append(sum(v))

tmp = [print(i) for i in ans]


Measured memory_bytes: 3444
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; }
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; }
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; }
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
void print(void) { cout << endl; }
template <class Head> void print(Head&& head) { cout << head; print(); }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << " "; print(forward<Tail>(tail)...); }
template <class T> void chmax(T& a, const T b) { a = max<T>(a, b); }
template <class T> void chmin(T& a, const T b) { a = min<T>(a, b); }
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }

int main() {
	int N, M; cin >> N >> M;
	V<int> cnt(M,0),cnt2(100001,0),cnt3(M,0);
	for(int i = 0; i < N; ++i) {
		int X; cin >> X;
		cnt[X%M]++;
		cnt2[X]++;
	}
	for (int i = 1; i < 100001; ++i) cnt3[i%M] += cnt2[i] / 2;

	int ans = cnt[0]/2;
	cnt[0] %= 2;
	for(int i = M-1; 0 < i; --i){
		if (M - i > i) break;
		if(M-i>0){
			if(M-i==i){
				ans += cnt[M - i] / 2;
				cnt[M - i] %= 2;
				continue;
			}
			int a = cnt[i];
			int b = cnt[M - i];
			cnt[i] -= min(a, b);
			cnt[M-i] -= min(a, b);
			ans += min(a, b);
			ans += min(cnt[i]/2,cnt3[i]);
			ans += min(cnt[M-i]/2,cnt3[M-i]);
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1408
N, C, K = map(int, input().split())
Ts = [int(input()) for i in range(N)]
T = list(map(lambda x: (x, x+K), Ts))

T.sort(key = lambda x: x[1])
c = 0
bus = 0
limit = T[0][1]

for i, t in enumerate(T):
  if limit < t[0]:  # バスが出発していなければならない
    c = 1
    bus += 1
    limit = t[1]
  elif (c+1) > C:  # 自分が乗れずに出発して自分は次のバスに乗る
    c = 1
    bus += 1
    limit = t[1]
  else:  # いたバスで待つ
    c += 1

if c > 0:
  bus += 1
    
print(bus)

Measured memory_bytes: 19024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <array>
#include<unordered_map>
#include<unordered_set>

using namespace std;
#define IO                 \
	ios::sync_with_stdio(0); \
cin.tie(0);              \
cout.tie(0);
#define forn(i, n) for (int i = 0; i < n; i++)
#define forse(i, s, e) for (int i = s; i < e; i++)
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define mp make_pair
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define getcurrtime() \
	cerr << "Time = " << ((double)clock() / CLOCKS_PER_SEC) << endl

#define watch(x) cerr << (#x) << " is " << (x) << endl;

#ifndef LOCAL
#define cerr if(false)cerr
#endif
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll P=1e9+7;
double PI=3.141592653589793;
const int arrn = 2e5 + 1;


void solve(){
	int n,m;
	cin >> n >> m;
	if(n%2==0) n--;
	int mx=(n-1)/2;
	int t=0;
	for(int i=mx;i>=0;i-=2){
		if(i!=0&&m-->0) cout << t+1 << ' ' << t+i+1 << '\n';
		t++;	
	}
	t=(n+1)/2;
	for(int i=mx-1;i>=0;i-=2){
		if(i!=0&&m-->0) cout << t+1 << ' ' << t+i+1 << '\n';
		t++;	
	}
}

int main() {
	IO;
	int T=1;
//	cin >> T;
	forn(c,T){
		solve();
	}
}



Measured memory_bytes: 3656
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

H,W,K = map(int,readline().split())
grid = np.frombuffer(read(),'S1').reshape(H,-1)[:,:W]

X,Y = np.where(grid == b'#')

A = np.zeros((H,W),np.int32)
A[X,Y] = np.arange(1,K+1)

np.maximum.accumulate(A,axis = 1,out=A)

for w in range(W-2,-1,-1):
    A[:,w] += A[:,w+1] * (A[:,w] == 0)

for h in range(1,H):
    if A[h,-1] == 0:
        A[h] += A[h-1]
for h in range(H-1,-1,-1):
    if A[h,-1] == 0:
        A[h] += A[h+1]

print('\n'.join(' '.join(row) for row in A.astype(str)))

Measured memory_bytes: 20372
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string n;
    int k;
    cin >> k >> n;
    for(int i = 0; i < n.size() && i < k; i ++) {
        cout << n[i];
    }
    if(k < n.size()) {
        cout << "...";
    }

    return 0;
}




Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
            }
            

            var indexFromValueTable = a.Distinct()
                .OrderBy(v => v)
                .Select((value, index) => new { value, index })
                .ToDictionary(p => p.value, p => p.index);

            a = a.Select(v => indexFromValueTable[v]).ToArray();

            int ans = 0;

            for (int i = 0; i < n; i++)
            {
                if (i % 2 != a[i] % 2) ans++;
            }
            Console.WriteLine(ans/2);
        }
    }
}


Measured memory_bytes: 20056
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string s;
    cin >> s;
 
    if((s[0]==s[1]&&s[1]==s[2])||(s[1]==s[2]&&s[2]==s[3])){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
#define DEFAULT LL ans=solve();\
 	if(ans==NONE){\
 	}else{\
 		cout << ans << endl;\
 	}
#define YESNO three(solve(),(OUT(YES),1),(OUT(NO),0))
#define YesNo three(solve(),OUT(Yes),OUT(No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b-1);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<pr, Vpr > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 430;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p998 = 998244353;
const LL p107 = 1000000007;
const LL p = p107;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
const LL NONE=-2;
#define endl "\n"
ut N, M,K,  Q,  H, W;
VI edges[SIZE];
LL vals[SIZE], answer = zero;
LL A[SIZE],B[SIZE],C[SIZE];
LL D[SIZE];
LL P[SIZE];
LL solve(){
	LL h,m,h2,m2;
	cin >> h >>m >> h2 >> m2>>K;
	cout << abs(h*60+m-h2*60-m2)-K << endl;

	return NONE;
}
 signed main() {
 
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	LL T=1;

	REP(i,T){
		DEFAULT;

	}
	
//	YesNo;
//	YESNO;
//	three(solve(),OUT("First"),OUT("Second"));
	//cin >> N;
	return 0;
 
}


Measured memory_bytes: 15412