akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

const int N = 2e5 + 10;
typedef long long ll;
ll n, m, Q, fa[N], A[N], B[N], tot, num;

int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }

int main() {
    cin >> n >> m >> Q;
    rep(i, 0, n - 1) fa[i] = i;
    num = n;  // 连通块个数
    rep(i, 1, Q) {
        int a, b, c; scanf("%d%d%d", &a, &b, &c);
        int x = getfa(a), y = getfa(b);
        if (!c && x != y) fa[y] = x, num--;
        if (c) A[++tot] = a, B[tot] = b;
    }
    rep(i, 1, tot) if (getfa(A[i]) == getfa(B[i])) { puts("No"); return 0; }
    if ((1ll * num * (num - 1) / 2 < m + num - n) || ((num == 2 || m < n) && tot)) puts("No");
    else puts("Yes");
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> alpha = vector<int>(26, 0);
  string s; cin >> s;
  for (int i = 0; i < s.size(); i++) {
    int idx = s[i] - 'a';
    alpha[idx]++;
  }
  long long int sum = 0;
  for (int i = 0; i < s.size(); i++) {
    int idx = s[i] - 'a';
    for (int j = 0; j < 26; j++) {
      if (j == idx) continue;
      sum += alpha[j];
    }
  }
  cout << sum / 2LL + 1LL << endl;
  return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int dp[50];

int fib(int n) {
	if (n == 0 || n == 1)return dp[n] = 1;
	if (dp[n] != -1)return dp[n];
	return dp[n] = fib(n - 1) + fib(n - 2);
}

int main() {
	int n, i;
	for (i = 0; i < 50; i++)dp[i] = -1;

	scanf("%d", &n);
	printf("%d\n", fib(n));
	return 0;
}

Measured memory_bytes: 1756
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

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

  multiset<double> s;
  int num;
  rep(i,n){
     cin>>num;
     s.insert(num);
  }
  double val1,val2,sum;
  while(s.size()!=1){
   auto itr=s.begin();
   val1=*itr;
   val2=*(++itr);
   sum=val1+val2;

   s.erase(s.begin());
   s.erase(s.begin());
   s.insert(sum/2);
  }
  cout<<*(s.begin())<<endl;

}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a;
  int i, sum=0;
  for(i=0; i<4; i++){
    scanf("%d",&a);
    sum += a;
    }
  int x, y;
  x=sum/60;
  y=sum-x*60;
  printf("%d\n%d\n",x, y);
  return 0;
}

Measured memory_bytes: 596
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <bitset>
using namespace std;

const int MAX_N = 501;
const int MAX_M = 200001;
const int MAX_Q = 100001;

int p[MAX_Q];
int q[MAX_Q];

int a[MAX_N][MAX_N];
int s[MAX_N][MAX_N];

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

  int N, M, Q;
  cin >> N >> M >> Q;
  
  int L, R;
    
  for (int i = 0; i < M; i++) {
    cin >> L >> R;
    L--; R--;
    a[L][R]++;
  }
  
  for (int i = 0; i < Q; i++) {
    cin >> p[i] >> q[i];
    p[i]--;
    q[i]--;
  }
  
  for (int i = 0; i < N; i++) 
    for (int j = 0; j < N; j++) 
      s[i + 1][j + 1] = s[i][j + 1] + s[i + 1][j] - s[i][j] + a[i][j];

  int ans;
  int l, r;
  for (int i = 0; i < Q; i++) {
    l = p[i];
    r = q[i];
    ans = s[r+1][r+1] - s[r+1][l] - s[l][r+1] + s[l][l];
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 5816
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
signed main(){
	int n;
	string s;
	stack<char>st;
	cin>>n>>s;
	int le=0,ri=0;
	rep(i,n){
		if(st.empty())st.push(s[i]);
		else if(st.top()=='('&&s[i]==')')st.pop();
		else st.push(s[i]);
	}
	while(st.size()){
		if(st.top()=='(')le++;
		else ri++;
		st.pop();
	}
	rep(i,ri)cout<<"(";
	cout<<s;
	rep(i,le)cout<<")";
	cout<<endl;
}


Measured memory_bytes: 256
n = int(input())

a = []

for i in range(2):
    a.append(list(map(int, input().split())))

tempSum = sum(a[1]) + a[0][0]
sumMax = tempSum
for i in range(1, n):
    tempSum += a[0][i] - a[1][i - 1]
    if tempSum > sumMax:
        sumMax = tempSum

print(sumMax)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit
#include <cstdio>	// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define DEBUG 0

using namespace std;

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

int main()
{
	int n, k;
	while (scanf ("%d %d", &n, &k ) && n && k ){
		vector<int> card (n, 0 );

		rep (i, n ){
			cin >> card[i];
		} // end rep

		int res = 0;
		for (int i = 0; i <= n-k; i++ ){
			int curr = 1;
			for (int j = i; j < i+k; j++ ){
				curr *= card[j];
			} // end for
			res = max (curr, res );
		} // end for

		int ans = 0;
		for (int i = 0; i < n; i++ ){
			for (int j = i+1; j < n; j++ ){
				swap (card[i], card[j] );
				for (int m = 0; m <= n-k; m++ ){
					int curr = 1;
					for (int l = m; l < m+k; l++ ){
						curr *= card[l];
					} // end for
					if (ans < curr ){
						ans = curr;
					} // end if
				} // end for
				swap (card[i], card[j] );
			} // end for
		} // end for
		if (res > ans ){
			cout << "NO GAME" << endl;
		}else{
			cout << ans - res << endl;
		} // end if
	} // end while			
		
	return 0;
}

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

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

    set<int> numbers;
    int target_number;
    for (int i = 0; i < n; ++i) {
        cin >> target_number;
        if (numbers.find(target_number) != numbers.end()) {
            numbers.erase(target_number);
            continue;
        }
        numbers.insert(target_number);
    }

    cout << numbers.size() << endl;

    return 0;
}

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

int it;
string s;

char add(char a)
{
  if(a=='Z')
    return 'A';
  else if(a=='?')
    return a;
  else
    return a+1;
}

char sub(char a)
{
  if(a=='A')
    return 'Z';
  else if(a=='?')
    return a;
  else
  return a-1;
}

char letter()
{
  if(s[it]=='+')
    {
      it++;
      return add(letter());
    }
  else if(s[it]=='-')
    {
      it++;
      return sub(letter());
    }
  else
    {
      it++;
      return s[it-1];
    }
}

string smake()
{
  string a;
  while(it<s.size() && s[it]!=']')
    {
      if(s[it]=='[')
	{
	  string tmp;
	  it++;
	  while(s[it]!=']')
	    {
	      tmp+=smake();
	    }
	  it++;
	  for(int x=tmp.size()-1;x>=0;x--)
	a+=tmp[x];
	}
      else
	a+=letter();
    }
  return a;
}

string parse()
{
  string a;
  while(it<s.size())
    {
      a+= smake();
    }
  return a;
}





int main()
{
  for(;cin>>s,s!=".";)
    {
      it=0;
      string ans = parse();
      //      cout<<ans<<endl;
      for(int i=0;i<ans.size();i++)
	{
	  if(ans[i]=='?')
	    cout<<'A';
	  else
	    cout<<ans[i];
	}
      cout<<endl;
    }

}

Measured memory_bytes: 1192
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ_Volume11_1193
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var H = int.Parse(Console.ReadLine());
                if (H == 0) break;

                //読み込み
                int[,] map = new int[H, 5];
                for (int i = 0; i < H; i++)
                {
                    var input = ReadInt();
                    for (int j = 0; j < 5; j++)
                    {
                        map[H - 1 - i, j] = input[j];
                    }
                }

                int ans = 0;

                //消える
                while (true)
                {
                    bool banish = false;

                    for (int i = 0; i < H; i++)
                    {
                        for (int k = 0; k < 3; k++)//スタート
                        {
                            if (map[i, k] == 0) continue;
                            int count = 1;
                            for (int j = k + 1; j < 5; j++)//連続
                            {
                                if (map[i, j] == map[i, k])
                                {
                                    count++; continue;
                                }
                                else break;
                            }
                            if (count >= 3)//削除の処理
                            {
                                for (int j = k; j < k + count; j++)
                                {
                                    ans += map[i, j];
                                    map[i, j] = 0;
                                }
                                banish = true;
                                break;
                            }
                        }
                    }

                    if (!banish) break;

                    // 下に詰める
                    int[,] nextMap = new int[H, 5];
                    for (int i = 0; i < 5; i++)
                    {
                        int index = 0;
                        for (int j = 0; j < H; j++)
                        {
                            if (map[j, i] == 0) continue;
                            nextMap[index, i] = map[j, i];
                            index++;
                        }
                    }
                    map = nextMap;
                }

                Console.WriteLine(ans);
            }

            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}



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


int main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; 2 * i - 1 <= N; ++i) {
        int num = 2 * i - 1;
        int cnt = 0;
        for (int j = 1; j <= num; ++j) {
            if (num % j == 0) ++cnt;
        }
        if (cnt == 8) ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3512
N=int(input())
X=[input().split() for i in range(N)]
SP=[[str(X[j][0]),-1*int(X[j][1]),j+1] for j in range(N)]
X=sorted(SP,key=lambda x:(x[0],x[1]))
for k in range(N):
	print(X[k][2])

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cctype>
#include <stdlib.h>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <iterator>

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb(x) push_back(x)
#define sz(x) x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-9

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define ss(ch) scanf("%s",ch)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define ps(ch) printf("%s",ch)
#define NL printf("\n")
#define debug(x) printf("wow %d !!\n",x)

typedef long long LL;

using namespace std;

bool array[1000010];
int ans[1000010];
int main()
{
    int i,j;
    array[1]=1;
    for(i=2; i*i<=1000005; i++)
    {

        if(!array[i])for(j=i*i; j<=1000005; j=j+i)array[j]=1;
    }
    int cnt=0;
    rep(i,1000005)
    {
        if(array[i]==0)cnt++;
        ans[i]=cnt;
    }
    int n;
    while(si(n) !=EOF)
    {
        pi(ans[n]);
        NL;
    }
    return 0;
}

Measured memory_bytes: 6072
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define itr(macro_v,i) macro_v.begin()+i
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    bool can = false;
    for(int i=1; i<=9; i++){
        for(int j=1; j<=9; j++){
            if(i*j==n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

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

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



int N, Q;
long long K;

int main() {
    while (cin >> N >> K >> Q) {
        vector<long long> num(N, 0);
        for (int i = 0; i < Q; ++i) {
            int a; cin >> a; --a;
            num[a]++;
        }

        for (int i = 0; i < N; ++i) {
            if (K - (Q - num[i]) <= 0) cout << "No" << endl;
            else cout << "Yes" << endl;
        }
    }
}













Measured memory_bytes: 1408
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;



int main(void)
{
	//変数の宣言
	int n,m;
	int h,w;
	char c[310][310];
	static int d[110][110];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int temp3=0;
	static int vec[100010];
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;
	static char stemp[100010];
	
	//データの読み込み


	scanf("%d %d",&h,&w);
//	scanf_s("%d %d",&h,&w);


//	scanf("%s",&s);
//	scanf_s("%s",&s,100010);


/*	for(i=0;i<10;i++){
		for(j=0;j<10;j++){
//			scanf("%d",c[i][j]);
			scanf_s("%d",&c[i][j]);
		}
	}*/

	for(i=0;i<h;i++){
		scanf("%s",&c[i][j]);
//		scanf_s("%s",&c[i],310);
	}


/*	for(i=0;i<3;i++){
//		scanf("%s",&s);
		scanf_s("%s",&s[i],100010);
	}*/


	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

//	clock_t start=clock();


	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
				d[i][j]=INFINT;
		}
	}

	if(c[0][0]=='.'){
		d[0][0]=0;
	}else{
		d[0][0]=1;
	}

	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(j>0){
				if(c[i][j]==c[i][j-1]){
					d[i][j]=min(d[i][j],d[i][j-1]);
				}else{
					d[i][j]=min(d[i][j],d[i][j-1]+1);
				}
			}
			if(i>0){
				if(c[i][j]==c[i-1][j]){
					d[i][j]=min(d[i][j],d[i-1][j]);
				}else{
					d[i][j]=min(d[i][j],d[i-1][j]+1);
				}
			}
		}
	}

/*	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			printf("d[%d][%d]=%d\n",i,j,d[i][j]);
		}
	}*/

//	clock_t end=clock();

	//	printf("計算部分終了\n");

	//出力
	
	printf("%d",(d[i-1][j-1]+1)/2);

//	printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC);
	//	printf("結果の出力終了\n");

	return 0;
}



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

int main()
{
    string s;  cin >> s;
    int a, z, ans = 0;

    rep(i, 200000) {
        if (s[i] == 'A') {
            a = i;
            break;
        }
    }
    for (int i = s.length(); i > 0; i--) {
        if (s[i] == 'Z') {
            z = i;
            break;
        }
    }

    ans = z - a + 1;
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e5)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;


int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;

	// Write your code here


	int t = 1;
	// cin >> t;
	while (t--) {
		ll n;
		cin >> n;
		ll i = 1;
		while (i * n % 360) i++;
		cout << i << "\n";
	}


	return 0;
}

Measured memory_bytes: 3616
#include<stdio.h>
#include<iostream>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

ll gcd(ll p, ll q){
    if(p < q)std::swap(p,q);
    if(p % q == 0) return q;
    else return gcd(q, p%q);
}

ll lcm(ll p, ll q){
    return p*q/gcd(p,q);
}

int main(){
    int n;
    int a[11];
    cin >> n;
    REP(i,n)cin >> a[i];
    ll ans=a[0];
    REP(i,n-1){
        ans = lcm(ans, a[i+1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  int n=s.size();

  int ans=1e6;
  
  for(int i=0;i<26;i++){
    char c=char('a'+i);
    int left=0,right=0;
    int cnt=0,tmp=0,before=0;
    for(int j=0;j<n;j++){
      if(s[j]==c){
        left=j-before;
        right=n-j-1;
        cnt=max(left,right);
        cnt=max(cnt,tmp);
        tmp=max(tmp,left);
        ans=min(ans,cnt);
        before=j+1;
     
      }
    }
  }
  cout<<ans;
  
    
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <climits>
#include <string>
#include <vector>

using namespace std;

int main () {
    int n = 0, k = 0;
    cin >> n >> k;
    if (k == 1) cout << 0 << endl;
    else cout << n - k << endl;
    return 0;
}


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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int X,N;
    cin>>X>>N;
    vec_int p(N);
    rep(i,N)cin>>p.at(i);

    int min_dist = 200;
    /*
    rep(i,N){
        if(X==p.at(i))continue;
        if(abs(X-p.at(i)<min_dist)){
            min_dist = abs(X-p.at(i));
        }
    }
    */
   int ans=10000;
   for(int i=0;i<300;i++){
       int flag=0;
       for(int j=0;j<N;j++){
           if(i==p.at(j)){
               flag=1;
           }
       }
       if(flag==1)continue;
        if(abs(X-i)<min_dist){
            min_dist = abs(X-i);
            ans=i;
        }


   }
    cout<<ans<<endl;


    return 0;
}

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

#define ll long long;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n, a, res = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a;
    if (i % 2 == 1 && a % 2 == 1)
      res++;
  }
  cout << res << "\n";

  return 0;
}

Measured memory_bytes: 3644
import math
N, M = map(int, input().split())

if N == M:
  ans = math.factorial(N) % (10**9+7)
  ans = (ans**2) % (10**9+7)
  ans = (ans*2) % (10**9+7)
elif N - M == 1:
  ans = math.factorial(M) % (10**9+7)
  ans = (ans**2) % (10**9+7)
  ans = (ans*N) % (10**9+7)
elif M - N == 1:
  ans = math.factorial(N) % (10**9+7)
  ans = (ans**2) % (10**9+7)
  ans = (ans*M) % (10**9+7)
else:
  ans = 0
  
print(ans)

Measured memory_bytes: 10056
#include<iostream>
#include<string>
#include<map>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++ )
#define MAX 1000
#define INFTY (1<<21)

class Deal{
    public:
    string name, type;
    char item;
    int value;

    Deal(string n="", string t="", char i=' ', int v=0): name(n), type(t), item(i), value(v){}
};

Deal D[MAX];
int n;
map<string, pair<int, int> > P;

void compute(){
    int maxd[26], mind[26], totald[26], cnt[26], maxv, minv, mi;
    rep(i, 26) { 
	maxd[i] = -1;
	mind[i] = INFTY;
	totald[i] = 0;
	cnt[i] = 0;
    }

    bool used[MAX];
    rep(i, n) used[i] = false;

    for ( int cur = 0; cur < n; cur++ ){
	maxv = mi = -1;
	minv = INFTY;
	for ( int i = 0; i < cur; i++ ){
	    if ( used[i] ) continue;
	    if ( D[cur].item != D[i].item ) continue;
	    if ( D[cur].name == D[i].name ) continue;
	    if ( D[cur].type == "SELL" && D[i].type == "BUY"){
		if ( D[cur].value <= D[i].value && maxv < D[i].value ){
		    maxv = D[i].value;
		    mi = i;
		}
	    } else if ( D[cur].type == "BUY" && D[i].type == "SELL" ){
		if ( D[cur].value >= D[i].value && minv > D[i].value ){
		    minv = D[i].value;
		    mi = i;
		}
	    }
	}

	if ( mi == -1 ) continue;
	if ( D[cur].type == "SELL"){
	    int d = (maxv + D[cur].value)/2;
	    totald[D[cur].item - 'A'] += d;
	    maxd[D[cur].item - 'A'] = max( d,  maxd[D[cur].item - 'A']);
	    mind[D[cur].item - 'A'] = min( d,  mind[D[cur].item - 'A']);
	    cnt[D[cur].item - 'A']++;
	    P[D[cur].name].second += d;
	    P[D[mi].name].first += d;
	} else {
	    int d = (minv + D[cur].value)/2;
	    totald[D[cur].item - 'A'] += d;
	    maxd[D[cur].item - 'A'] = max( d,  maxd[D[cur].item - 'A']);
	    mind[D[cur].item - 'A'] = min( d,  mind[D[cur].item - 'A']);
	    cnt[D[cur].item - 'A']++;
	    P[D[cur].name].first += d;
	    P[D[mi].name].second += d;
	}
	used[mi] = used[cur] = true;
    }

    for ( int i = 0; i < 26; i++ ){
	if ( totald[i] == 0 ) continue;
	cout << (char)('A' + i) << " " <<  mind[i] << " " << totald[i]/cnt[i] << " " << maxd[i] <<endl;
    }
    cout << "--" << endl;
    for ( map<string, pair<int, int> >::iterator it = P.begin(); it != P.end(); it++ ){
	string name = (*it).first;
	pair<int, int> p = (*it).second;
	cout << name << " " << p.first << " " << p.second << endl;
    }
    cout << "----------" << endl;
}


main(){
    while( cin >> n && n ){
    P = map<string, pair<int, int> >();
	rep(i, n){
	    cin >> D[i].name >> D[i].type >> D[i].item >> D[i].value;
	    P[D[i].name] = make_pair(0, 0);
	}
	compute();
    }
}

Measured memory_bytes: 0
#!/usr/bin/env python3

def main():
    X,Y = map(int,input().split())
    for i in range(101):
        for j in range(101):
            if i + j ==X and i*2+j*4 == Y:
                print("Yes")
                exit()
    print("No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
#define int ll
using pii = pair <int, int>;
#define INF 0x7f7f7f7f7f7f7f7f
const bool debug = 0;
const int mod = 1000000007;
ll modpow(ll x, ll y, ll p = mod)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int n;
map<pii, int> mp;
vector <int> G[202020];
int child[202020];
int res[202020];
int inv[202020];
int dfs(int r, int p)
{
    int u = 1;
    if (G[r].size() == 1 && G[r][0] == p)
    {
        mp[{p, r}] = 1;
        mp[{r, p}] = n-1;
        return child[r] = 1;
    }
    for (auto it:G[r])
    {
        if (child[it]==-1 && it != p)
        {
            int k = dfs(it, r);
            mp[{r, it}] = k;
            mp[{it, r}] = n-k;
            u += k;
        }
    }
    return child[r] = u;
}

inline int mul(int a, int b)
{
    return (a*b)%mod;
}
inline int moddiv(int a, int b)
{
    return (a*inv[b])%mod;
}
void calc(int r, int p, int bef)
{
    int down = mp[{p, r}];
    int up = mp[{r, p}];
    int comp = mul(bef, down);
    comp = moddiv(comp, up);
    //printf("%lld : reverse (%lld, %lld). Multiply %lld, Divide %lld = %lld\n",r,p,r,up,down,comp);
    res[r] = comp;
    for (auto it:G[r])
        if (it!=p)
            calc(it, r, res[r]);
}
int32_t main()
{
    usecppio
    memset(child, -1, sizeof(child));
    cin >> n;
    for (int i = 1; i<=200000; i++)
        inv[i] = modpow(i, mod-2);
    for (int i = 1; i<n; i++)
    {
        int u, v; cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1, 0);
    int ans = 1;
    for (int i = 1; i<=n; i++)
        ans = mul(ans, i);
    for (int i = 1; i<=n; i++)
        ans = moddiv(ans, child[i]);
    res[1] = ans;
    for (auto it:G[1])
        calc(it, 1, ans);
    for (int i = 1; i<=n; i++)
        cout << res[i] << '\n';
}

Measured memory_bytes: 44528
def resolve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    ans = 1 << 60
    for bit in range(1 << N):
        bills = A[:]
        # K個の建物が必要
        if bin(bit).count("1") != K:
            continue
        sum_H = 0
        cmb = []  # 建物の組み合わせ
        for i in range(N):
            if bit >> i & 1:
                cmb.append(i)
        for b in cmb:
            if b == 0:
                continue
            m = max(bills[:b])
            if m < bills[b]: # 後ろの建物が高かい場合、伸ばす必要なし
                pass
            else:
                sum_H += m + 1 - bills[b] # 伸ばすコスト
                bills[b] = m + 1 # 伸ばした高さに修正
        ans = min(ans, sum_H)

    return print(ans)

if __name__ == "__main__":
    resolve()

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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int m, k, ans = 0;
    cin >> m >> k;
    ll n;
    if(k == 0){
        n = (1 << m + 1);
        cout << 0;
        for(int i = 1; i < n; i++){
            cout << " " << i / 2;
        }
        cout << endl;
    }else{
        n = (1 << m);
        if(m >= 2 && k < (1 << m)){
            cout << k;
            for(int i = 0; i < n; i++){
                if(i == k) continue;
                cout << " " << i;
            }
            cout << " " << k;
            for(int i = n - 1; i >= 0; i--){
                if(i == k) continue;
                cout << " " << i;
            }
            cout << endl;
        }else{
            cout << -1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1792
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Queue;
import java.util.Scanner;
import java.lang.Math;

public class Main {
    public static int factorial(int n) {
        int fact = 1;
        for (int i = 2; i <= n; i++) {
            fact = fact *  i;
        }
        return fact;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        double[][] inp = new double[N][2];
        for(int i = 0; i < N ;i++){
            inp[i][0] = Double.parseDouble(sc.next());
            inp[i][1] = Double.parseDouble(sc.next());
        }
        double total = 0d;
        for(int i = 0; i < N - 1 ; i++){
            for(int j = i+1; j < N ;j++){
                total += Math.sqrt(
                Math.pow(inp[i][0]-inp[j][0],2)+
                Math.pow(inp[i][1]-inp[j][1],2)
                );
            }
        }
        System.out.println(total*2/N);
        //Caluclate mean
    }
}

Measured memory_bytes: 21844
int main(void){
	int N;
  	int K;
  	scanf("%d %d", &N, &K);
  	
  	double result_point = 0.0;
  	for(int init_point = 1; init_point <= N; init_point++){
	  	double temp = 1.0;
      	int num = init_point;
      	while(num < K){
          temp = temp / 2.0;
          num = num * 2;
        }
      	result_point += temp;
    }
  	
  	printf("%.16f", result_point/N);
}

Measured memory_bytes: 128
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  std::vector<ll> v(n),l;
  rep(i,n) cin>>v[i];
  ll p = -1;
  ll cnt = 1;
  rep(i,n){
    // cout<<cnt<<endl;
    if(p==v[i]) {
      cnt++;
    } else {
      p = v[i];
      l.pb(cnt);
      cnt = 1;
    }
  }
  l.pb(cnt);
  ll ans = 0;
  rep(i,l.size()){
    // cout<<l[i]<<endl;
    ans += (l[i]/2);
  }
  cout<<ans<<endl;

}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char s[100001];
	int i,x,y;
	for(;~scanf("%s",&s);printf("%d\n%d\n",x,y))
	for(i=x=y=0;i<strlen(s)-2;i++)
	{
		if(s[i+1]=='O'&&s[i+2]=='I')
			s[i]=='J'?x++:s[i]=='I'?y++:0;
	}
	return 0;
}

Measured memory_bytes: 556
#include<stdio.h>
#define N 20
#define MAX 2000

int solve( int , int );

int n,X[MAX],Y[MAX];
 
main(){
  
  int i,j,q;

  scanf("%d",&n);
  for( i = 0 ; i < n ; i++ ){
    scanf("%d",&X[i]);
  }

  scanf("%d",&q);
  for( i = 0 ; i < q ; i++ ){
    scanf("%d",&Y[i]);
  }

  for( i=0 ; i < q ; i++ ){
    if( solve( 0,Y[i] ) )
      printf("yes\n");
    else printf("no\n");
  }
  
  return 0;

}

int solve( int a , int b ){
 
  if(X[a] == b)return 1;
 
  if(a+1  == n)return 0;
 
  if( solve(a+1,b-X[a]) || solve(a+1,b) )
    return 1;
  
  return 0;
 
}

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

#define mod 1000000007

#define rep(i, n) for(int i=0; i<n; ++i)

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	long double A, B;
    cin >> A >> B;

	cout << (ll)(A * B) << endl;

	return 0;
}

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

int main(){
  int H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  int T1, T2;
  T1 = H1*60 + M1;
  T2 = H2*60 + M2;
  int ans = T2 - K - T1;
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using ll = long long;

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

    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    Bint sum = 1;
    REP(i, n) {
        sum *= a[i];
        if (sum > 1000000000000000000) {
            sum = -1;
            break ;
        }
    }

    cout << sum << '\n';
    return 0;
}


Measured memory_bytes: 4016
fn main() {
    use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Write};
    let stdin = stdin();
    let stdin = BufReader::new(stdin.lock());
    let stdout = stdout();
    let mut stdout = BufWriter::new(stdout.lock());
    let mut lines = stdin.lines();
    let a: Vec<u32> = lines.next().unwrap().unwrap().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let total: u32 = lines.next().unwrap().unwrap().split_whitespace().map(|s| s.parse::<u32>().unwrap()).sum();

    let ans = if total >= a[0] { "Yes" } else { "No" };
    writeln!(stdout, "{}", ans).unwrap();
}

Measured memory_bytes: 4352
// abc179_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
  string S;
  cin>>S;
  int size = S.size();
  if (S[size - 1] == 's') cout << S << "es";
  else cout << S << "s";
  cout << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define MN 150
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,K,mod,KK,F[MN+5],f[MN+5],g[MN+5][MN+5],pw[MN+5],ans;
inline void Re(int&x,int y){(x+=y)>=mod?x-=mod:0;}
int Solve1(int n)
{
    f[0]=1;
    for(int i=1;i<=n;++i)
    {
        F[i]=i<=K;
        for(int j=max(1,i-K);j<i;++j) Re(F[i],f[j-1]);
        f[i]=(f[i-1]+F[i])%mod;
    }
    return f[n];
}
inline int Odd(int x){return (x&1)?x:x-1;}
inline int Even(int x){return (x&1)?x-1:x;}
int main()
{
    n=read();K=read();mod=read();KK=K+1>>1;
    if(~K&1) return K>>=1,printf("%d\n",1LL*Solve1(n/2)*Solve1(n+1>>1)%mod),0;//number of ways that only contain intervals no longer than K/2
	pw[0]=1;for(int i=1;i<=n;++i) pw[i]=2*pw[i-1]%mod;
    if(K>=n) return 0*printf("%d\n",pw[n]);
    for(int i=1;i<=KK;++i) g[0][i*2-1]=pw[max(0,i-2)];
    g[0][0]=pw[KK-1];
    for(int i=2;i+K<=n;i+=2)
    {
        for(int j=1;j<i+K;j+=2) Re(g[i][j],g[i-2][j]),Re(g[i][0],g[i-2][j]);
        Re(g[i][i+K],g[i-2][0]);Re(g[i][0],g[i-2][0]);
        for(int j=i;j<=n;j+=2) //new interval for even numbers: i->j
        {
            for(int k=0;k<i+K;k+=2-(k==0)) if(g[i-2][k])
            {
                int L=max(i+K,j-K+2),R=min(Odd(n),j+K+2);
                if(k>0&&k+K<=j) L=max(L,i+K+2);
                for(int l=L;l<=R;l+=2) 
                {
                    if(l==i+K&&k) continue;
                    int num=1LL*g[i-2][k]*pw[max(0,(l-L)/2-1)]%mod;
                    Re(g[j+2][l],num);
                }
                if(L==i+K&&k) Re(g[j+2][k],g[i-2][k]);
                int num0=1LL*g[i-2][k]*pw[max(0,(R-L)/2)]%mod;
                Re(g[j+2][0],num0);
            }
        }
    }
    for(int i=0;i<=n+2;i+=2) if(i+K+2>n) 
        for(int j=0;j<=n;++j) Re(ans,1LL*g[i][j]*pw[max(0,Even(n)-i)/2]%mod);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 384
import sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def ns(i_s, i_d, other_s, other_d):
	#i_sの方が小さいとしておく。
	if i_s > other_s:
		i_s, i_d, other_s, other_d = other_s, other_d, i_s, i_d
	
	r = i_s
	other_s -= i_s
	if other_s >= i_d:
		r += i_d
		r += other_d // 2
	else:
		r += other_s
		i_d -= other_s
		r += i_d // 2
		r += other_d // 2
	#print(r)
	return r

def nss(aa, ab):
	r = (aa+ab) // 2
	#pa(r)
	return r

def main():
	#a = int(input())
	n,m = tin()
	#s = input()
	al=lin()
	dd=[0]*m
	ni=[0]*m
	cc = collections.Counter(al)
	for k in cc:
		#pa((k,cc[k]))
		nv = cc[k]
		dd[k%m] += nv%2
		ni[k%m] += nv-(nv%2)
	#pa(dd)
	#pa(ni)
	ret = 0
	for i in range(m):
		other = (m-i) % m
		if other < i:
			continue
		#pa((i,other))
		if i == other:
			ret += nss(dd[i], ni[i])
		else:
			ret += ns(dd[i], ni[i], dd[other], ni[other])
	print(ret)
	
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 92204
#include <stdio.h>
#define MAX 1000000
#define INFTY 1000000000
void mergesort(int *,int,int);
void merge(int *,int,int,int);
int cnt=0;

int main(){
  int n,i,S[MAX];

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&S[i]);

  mergesort(S,0,n);

  for(i=0;i<n;i++)
    if(i!=n-1)
      printf("%d ",S[i]);
    else
      printf("%d\n%d\n",S[i],cnt);
  
  return 0;
}

void mergesort(int *S,int left,int right){
  int mid;

  if(left+1<right){
    mid=(left+right)/2;
    mergesort(S,left,mid);
    mergesort(S,mid,right);
    merge(S,left,mid,right);
  }
}

void merge(int *S,int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  int i,j,k;
  int L[n1+1],R[n2+1];

  for(i=0;i<n1;i++)
    L[i]=S[left+i];
  for(i=0;i<n2;i++)
    R[i]=S[mid+i];
  L[n1]=INFTY;
  R[n2]=INFTY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j]){
      S[k]=L[i];
      i=i+1;
    }
    else{
      S[k]=R[j];
      j=j+1;
    }
  }
}

Measured memory_bytes: 4704
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k,l;
  int n;
  cin>>n;
  string s;
  getline(cin,s);
  string c[12]={"ld","mb","mp","nc","nd","ng","nt","nw","ps","qu","cw","ts"};
  int a[38][38];
  memset(a,0,sizeof(a));
  for(i=0;i<n;i++){
    getline(cin,s);
    s+=' ';
    int ln=s.length();
    for(j=0;j<ln;){
      if(s[j]!=' '){
	for(k=0;k<12;k++){
	  if(c[k]==s.substr(j,2))
	    break;
	}
	if(k==12){
	  if(s[j+1]!=' '){
	    for(l=0;l<12;l++){
	      if(c[l]==s.substr(j+1,2))
		break;
	    }
	    if(l==12){
	      a[s[j]-'a'][s[j+1]-'a']++;
	      j+=1;
	    }else{
	      a[s[j]-'a'][26+l]++;
	      j+=1;
	    }
	  }else{
	    j++;
	  }
	}else{
	  if(s[j+2]!=' '){
	    for(l=0;l<12;l++){
	      if(c[l]==s.substr(j+2,2))
		break;
	    }
	    if(l==12){
	      a[26+k][s[j+2]-'a']++;
	      j+=2;
	    }else{
	      a[26+k][26+l]++;
	      j+=2;
	    }
	  }else{
	    j+=2;
	  }
	}
      }else{
	j++;
      }
    }
  }
  for(i=0;i<38;i++){
    int mx=0;
    for(j=1;j<38;j++){
      if(a[i][mx]<a[i][j])
	mx=j;
    }
    if(i<26)
      cout<<(char)(i+'a')<<" ";
    else
      cout<<c[i-26]<<" ";
    if(mx<26)
      cout<<(char)(mx+'a')<<" ";
    else
      cout<<c[mx-26]<<" ";
    cout<<a[i][mx]<<endl;
  }
  return 0;
}

Measured memory_bytes: 904
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
using namespace std;

int N, M;
const int N_MAX = 100001;
const int M_MAX = 100001;
struct Data {
	int first;
	int second;
	int third;
};
Data D[M_MAX];
int P[N_MAX] = {};

bool comp1(const Data &a, const Data &b) {
	return a.first < b.first;
}
bool comp3(const Data &a, const Data &b) {
	return a.third < b.third;
}


int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> D[i].second >> D[i].first;
		D[i].third = i;
	}
	sort(D, D + M, comp1);

	for (int i = 0; i < M; i++) {
		P[D[i].second]++;
		D[i].first = P[D[i].second];
	}
	sort(D,D+M, comp3);

	for (int i = 0; i < M; i++) {
		cout << setfill('0') << setw(6) << D[i].second;
		cout << setfill('0') << setw(6) << D[i].first << endl;
	}
	return 0;

}

Measured memory_bytes: 3072
import java.io.*;
import java.util.StringTokenizer;

class Main {
  public static void main(String args[]) {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String buf;
    try {
      while ((buf = br.readLine())!=null) {
        double x[] = new double[4];
        double y[] = new double[4];
        StringTokenizer st = new StringTokenizer(buf);
        for (int i=0;i<4;i++) {
          x[i] = Double.parseDouble(st.nextToken());
          y[i] = Double.parseDouble(st.nextToken());
        }
        double vx[] = new double[2];
        double vy[] = new double[2];
        vx[0] = x[1]-x[0];
        vy[0] = y[1]-y[0];
        vx[1] = x[3]-x[2];
        vy[1] = y[3]-y[2];
        double  dif = vx[0]*vx[1]+vy[0]*vy[1];
        if (Math.abs(Math.round(dif*Math.pow(100000,2)))==0) System.out.println("YES");
        else System.out.println("NO");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

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

struct Point {
    long long x, y;
};

int main()
{
    int N, K;
    cin >> N >> K;
    vector<Point> points1(N), points2(N);
    for (int i = 0; i < N; ++i) {
        long long x, y;
        cin >> x >> y;
        points1[i].x = x;
        points1[i].y = y;
        points2[i].x = x;
        points2[i].y = y;
    }
    sort(points1.begin(), points1.end(), [&](const Point& lhs, const Point& rhs) {
        return lhs.x < rhs.x;
    });
    sort(points2.begin(), points2.end(), [&](const Point& lhs, const Point& rhs) {
        return lhs.y < rhs.y;
    });

    //for (int i = 0; i < N; ++i) {
    //    printf("points1[%d].x = %lld, y = %lld\n", i, points1[i].x, points1[i].y);
    //}
    //for (int i = 0; i < N; ++i) {
    //    printf("points2[%d].x = %lld, y = %lld\n", i, points2[i].x, points2[i].y);
    //}

    auto isOK = [&](int i, int j, int k, int l) {
        int num = 0;
        for (int m = 0; m < N; ++m) {
            if (points1[i].x <= points1[m].x 
                    && points1[m].x <= points1[j].x
                    && points2[k].y <= points1[m].y 
                    && points1[m].y <= points2[l].y) {
                num++;
            }
        }
        return num >= K;
    };

    long long ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            for (int k = 0; k < N; ++k) {
                for (int l = k + 1; l < N; ++l) {
                    if (isOK(i, j, k, l)) {
                        if (ans == 0) {
                            ans = (points1[j].x - points1[i].x) * (points2[l].y - points2[k].y);
                        } else {
                            ans = min(ans, (points1[j].x - points1[i].x) * (points2[l].y - points2[k].y));
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256