akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
constexpr ll INF = LLONG_MAX;
constexpr double DINF = DBL_MAX;
constexpr ll mod = 1e9+7;
constexpr double PI = M_PI;

template<typename T>
vector<T> make_v(size_t a){
  return vector<T>(a);
}
 
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

int main(){
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
 
  long long n, m, a;
  cin >> n >> m;
  for(int i = 0; i < m; i++){
    cin >> a;
    n -= a;
  }
  cout << max(-1ll, n) << endl;
  return 0;
}


Measured memory_bytes: 3656
a = []
for i in range(6):
    a.append(input())
maxn = 0
minn = 128
for i in range(5):
	if(maxn < a[i]):
		maxn = a[i]
	if(minn > a[i]):
		minn = a[i]
if(maxn - minn > a[5]):
	print(":(")
else:
	print("Yay!")

Measured memory_bytes: 2568
var
	N,i,j:Longint;
	A:Array[1..100,1..99]of Longint;
begin
	read(N);
	if N=2 then begin
		writeln(-1);
		exit;
	end;
	if N mod 2=1 then begin
		for i:=1 to N-1 do A[N,i]:=i;
		i:=1;
		while i<=N-1 do begin
			for j:=1 to i-1 do begin
				A[i,j]:=j;
				A[i+1,j]:=j;
			end;
			A[i,i]:=i+1;
			A[i+1,i+1]:=i;
			A[i,i+1]:=i+2;
			A[i+1,i]:=i+2;
			for j:=i+2 to N-1 do begin
				A[i,j]:=j+1;
				A[i+1,j]:=j+1;
			end;
			inc(i,2);
		end;
	end else begin
		i:=1;
		while i<=N-2 do begin
			for j:=1 to i-1 do begin
				A[i,j]:=j;
				A[i+1,j]:=j;
			end;
			A[i,i]:=i+1;
			A[i+1,i+1]:=i;
			A[i,i+1]:=i+2;
			A[i+1,i]:=i+2;
			for j:=i+2 to N-1 do begin
				A[i,j]:=j+1;
				A[i+1,j]:=j+1;
			end;
			inc(i,2);
		end;
		for j:=1 to N-3 do begin
			A[N-1,j]:=j;
			A[N,j]:=j;
		end;
		A[N-1,N-2]:=N;
		A[N,N-1]:=N-1;
		A[N-1,N-1]:=N-2;
		A[N,N-2]:=N-2;
	end;
	for i:=1 to N do begin
		for j:=1 to N-1 do begin
			write(A[i,j]);
			write(' ');
		end;
		writeln;
	end;
end.


Measured memory_bytes: 128
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{

  ll n,a,b;
  cin >> n >> a >> b;

  ll ans1,ans2,ans3;

  ans1 = LLONG_MAX;
  ans2 = LLONG_MAX;
  ans3 = LLONG_MAX;
  
  if((b - a) % 2 == 0)
  {
    ans1 = (b - a) / 2;
  }

  ans2 = (n - a + n - b + 1) / 2;
  ans3 = (a + b - 1) / 2;

  cout << min(ans1,min(ans2,ans3)) << endl;


  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 120
int ir,ic,grid[N][N];
bool vis[N][N];

int main() {
    scanf("%d%d" , &ir , &ic);
    int n; scanf("%d" , &n);
    vector<int> colour(n + 1); colour[0] = -1;
    for (int i = 1 ; i <= n ; i++)
        scanf("%d" , &colour[i]);
    int r = 0, c = 0, colourIn = 0;
    bool entered = false;
    for (int colourIn = 1 ; colourIn <= n ; colourIn++) {
        while (colour[colourIn]--) {
            if (!entered) {
                if (c == ic - 1) {
                    grid[r][c] = colourIn;
                    r++;
                    entered = true;
                    continue;
                }
                grid[r][c] = colourIn;
                c++;
            } else {
                if (c == 0) {
                    grid[r][c] = colourIn;
                    r++;
                    entered = false;
                    continue;
                }
                grid[r][c] = colourIn;
                c--;
            }
        }
    }
    for (int r = 0 ; r < ir ; r++) {
        for (int c = 0 ; c < ic ; c++) {
            printf("%d" , grid[r][c]);
            printf(c == ic - 1 ? "\n" : " ");
        }
    }
}

Measured memory_bytes: 384
import java.io.InputStream;
import java.io.IOException;
import java.util.NoSuchElementException;
import static java.lang.System.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    }else{
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
    if (!hasNext()) throw new NoSuchElementException();
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while(isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }
  public long nextLong() {
    if (!hasNext()) throw new NoSuchElementException();
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while(true){
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      }else if(b == -1 || !isPrintableChar(b)){
        return minus ? -n : n;
      }else{
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }
  public int nextInt() {
    long nl = nextLong();
    if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
    return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

public class Main {
  public static void main(String[] args) {
    FastScanner fs = new FastScanner();

    int a = fs.nextInt();
    int b = fs.nextInt();
    String s = fs.next();

    String[] list = s.split("-", 0);
    if (list.length == 2 && list[0].length() == a && list[1].length() == b)
      out.println("Yes");
    else
      out.println("No");
  }
}


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

int n, m;
std::pair<long long, int> a[100005];
int main()
{
	std::cin >> n >> m;
	for (int i = 0; i < n; ++i)
		std::cin >> a[i].first >> a[i].second;

	std::sort(a, a + n);

	long long ans = 0;
	int res = 0;
	for (int i = 0; i < n; ++i) {
		if (res >= m)
			break;
		ans += a[i].first*std::min(m - res, a[i].second);
		res += std::min(m - res, a[i].second);
	}

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


Measured memory_bytes: 1792
#include <stdio.h>
int fine(int A[], int n, int key){
    int i = 0;
    A[n] = key;
    while(A[i] != key) i++;
    return i != n;
}

int main(){
    int i, n, A[10000+1], q, key, sum = 0;

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

    scanf("%d", &q);
    for(i=0; i<q; i++){
        scanf("%d", &key);
        if(fine(A, n, key) ) sum++;
    }
    printf("%d\n", sum );
    return 0;
}


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

int main(){
  
  string s;
  cin >> s;
  
  int start = 0;
  int end = s.size()-1;
  
  while(true){
    if(s[start] == 'A') break;
    start++;
  }
  
  while(true){
    if(s[end] == 'Z') break;
    end--;
  }
  
  
    
  
  cout << end - start +1  << endl;
}

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

string str , ans[6003]; int L;

string solve(int id){
	if(id == 2 * L) return string();
	if(ans[id].size()) return ans[id];
	if(str[id] == 'a'){
		int sum = 0 , pos = id;
		while(pos < 2 * L && sum <= 0) sum += str[pos++] == 'a' ? -1 : 1;
		if(pos == 2 * L){
			queue < int > stk; int r = -1;
			for(int i = id ; i < 2 * L ; ++i)
				if(str[i] == 'a') stk.push(i);
				else{if(stk.front() > r){r = i; ans[id] += "ab";} stk.pop();}
		}
		else ans[id] = solve(pos - 1);
	}
	else{
		int sum = 1 , pos = id + 1;
		while(pos < 2 * L && sum > 0) sum += str[pos++] == 'a' ? -1 : 1;
		string temp = solve(pos); int num = (pos - id) / 2;
		for(int i = 0 ; i <= num ; ++i){
			int cnta = 0 , cntb = 0; string now;
			for(int j = id ; j < pos ; ++j)
				if(str[j] == 'a' && ++cnta > i) now += 'a';
				else if(str[j] == 'b' && ++cntb > i) now += 'b';
			now += temp; if(ans[id] < now) ans[id] = now;
		}
	}
	return ans[id];
}

int main(){cin >> L >> str; solve(0); cout << ans[0]; return 0;}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll n, a[401], bd[400][400];

int main() {
	cin >> n;
	a[0] = 0;
	for (int i=1; i<=n; i++) {
		cin >> a[i];
		a[i] += a[i-1];
	}
	for (int i=0; i<n; i++)
		bd[i][i] = 0;
	for (int i=1; i<n; i++) {
		for (int j=0; j+i<n; j++) {
			bd[j][j+i] = bd[j][j] + bd[j+1][j+i];
			for (int k=1; k<i; k++) 
				bd[j][j+i] = min(bd[j][j+i], bd[j][j+k]+bd[j+k+1][j+i]);
			bd[j][j+i] += a[j+i+1]-a[j];
		}
	}
	cout << bd[0][n-1] << "\n";
}

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

//#define DBG
//#define DBG2

using namespace std;

using ll = long long;

static bool t [10][10][10];

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

  string s;
  cin >> s;
  cin.ignore();

  vector <int> v[10];
  int i_tmp;
  for (int i = 0; i < n; i++){
    i_tmp = (int) (s[i] - '0');
    v[i_tmp].push_back(i);
  }

  int cnt = 0; // こたえ
  int first = 0, second = 0, third = 0;

  vector <int>::iterator itr, itr2, itr3;

#ifdef DBG2
  for (int i = 0; i <= 9; i++){ //最初
    for(itr = v[i].begin(); itr != v[i].end(); itr++){
      cout << *itr << " " << flush;
    }
    cout << endl;
  }
#endif

  
  for (int i = 0; i <= 9; i++){ //最初
    if(v[i].empty() == true){
      continue;
    }

    itr = v[i].begin();
    first = *itr;
#ifdef DBG
    cout << "i = " << i << endl;
    cout << "first = " << first << endl;
#endif

    for(int j = 0; j <= 9; j++){
      if(v[j].empty() == true){
        continue;
      }
      if(i == j){
        if(v[j].size() <= 1){
          continue;
        }
      }

      itr2 = v[j].begin();
      if(i == j){
        ++itr2;
      }

      for(; itr2 != v[j].end(); itr2++){
        second = *itr2;
#ifdef DBG
        cout << "j = " << j << endl;
        cout << "second = " << second << endl;
#endif
        if(second > first){
          // 3つめの検索
          for(int k = 0; k <= 9; k++){
            if(v[k].empty() == true){
#ifdef DBG
              cout << "K EMP" << endl;
#endif
              
              continue;
            }
            if((i == k) || (j == k)){
              if(v[k].size() <= 1){
#ifdef DBG
                cout << "K SIZE less 1" << endl;
#endif
                continue;
              }
            }
            if((i == k) && (j == k)){
              if(v[k].size() <= 2){
#ifdef DBG
                cout << "K SIZE less 2" << endl;
#endif
                continue;
              }
            }
            itr3 = v[k].begin();
            if((i == k) || (j == k)){
              ++itr3;
              if((i == k) && (j == k)){
                ++itr3;
              }
            }

            for(; itr3 != v[k].end(); itr3++){
              third = *itr3;
#ifdef DBG
              cout << "k = " << k << endl;
              cout << "third = " << third << endl;
#endif
              if(third > second){
#ifdef DBG2
                cout << "i = " << i << " " << flush;
                cout << "j = " << j << " " << flush;
                cout << "k = " << k << " " << flush;
                cout << endl;
#endif
                ++cnt;
                break;
              }
            }
          }
          break;
        }
      }
    }
  }

  cout << cnt << endl;
        
    

  return 0;
}
  


Measured memory_bytes: 512
from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
import string

def get_int():
    return int(stdin.readline().strip())


def get_tuple():
    return map(int, stdin.readline().split())


def get_list():
    return list(map(int, stdin.readline().split()))

n,k = get_tuple()
ls = get_list()
j = 0
i = k
while i<n:
    if ls[j]>=ls[i]:
        print("No")
    else:
        print("Yes")
    i += 1
    j += 1



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

for i in range(n+1):
  amount = y - i*10000
  for j in range(n-i+1):
    if not (amount - (j*5000 + (n-i-j)*1000)):
      print(i,j,(n-i-j))
      exit(0)
else:
  print('-1 -1 -1')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    if(s[s.size()-1]=='s'){
        cout << s << "es" << endl;
    }
    else{
        cout << s << 's' << endl;
    }
}

Measured memory_bytes: 3648
#include <queue>
#include <iostream>
#include <atcoder/all>
using namespace std;


int main() {
    int n, m; cin >> n >> m;
    string s[n]; for (int i = 0; i < n; i++) cin >> s[i];
    const int M = 200;
    atcoder::mcf_graph<int, int> G(m * n + 102);
    const int S = m * n, T = m * n + 1;
    int idx = m * n + 2;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (s[i][j] == '#') continue;
            G.add_edge(i * m + j, T, 1, 0);
            if (s[i][j] == 'o') {
                G.add_edge(S, idx, 1, 0);
                int dist[n][m];
                for (int i = 0; i < n; i++)
                    for (int j = 0; j < m; j++) dist[i][j] = -1;
                queue<pair<int, int> > q;
                q.push({i, j});
                dist[i][j] = 0;
                while (!q.empty()) {
                    auto [x, y] = q.front();
                    const int d = dist[x][y];
                    q.pop();
                    G.add_edge(idx, x * m + y, 1, M - d);
                    const int dx[] = {0, 1}, dy[] = {1, 0};
                    for (int k = 0; k < 2; k++) {
                        const int x1 = x + dx[k], y1 = y + dy[k];
                        if (0 <= x1 && x1 < n && 0 <= y1 && y1 < m
                            && s[x1][y1] != '#' && dist[x1][y1] == -1) {
                            dist[x1][y1] = d + 1;
                            q.push({x1, y1});
                        }
                    }
                }
                idx++;
            }
        }
    auto [cap, cost] = G.flow(S, T);
    cout << M * cap - cost << endl;
}


Measured memory_bytes: 6796
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] A = IntStream.range(0,N).map(i->scan.nextInt()).toArray();

        int sumA = 0;
        for(int i=0;i<N;++i)sumA+=A[i];
        boolean dp[] = new boolean[100001];
        int minvalue = Integer.MAX_VALUE;

        dp[0]=true;
        for(int i=0;i<N;++i){
            boolean newdp[] = new boolean[100001];
            for(int j=0;j<=100000;++j){
                if(!dp[j])continue;
                newdp[Math.abs(j-A[i])]=true;
                if(j+A[i]<=100000)newdp[j+A[i]]=true;
            }
            dp = newdp;
        }
        for(int i=0;i<100000;++i){
            if(dp[i]){
                minvalue = Math.min(minvalue, i);
                break;
            }
        }


        System.out.println((sumA+minvalue)/2);


    }
}

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

int main(){
	int n;
	cin >> n;
	int now(1),a;
	rep(i,n){
		cin >> a;
		if(a == now) now++;
	}
	if(now == 1) cout << -1 << endl;
	else cout << n - (now-1) << endl;
	return 0;
}

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

#define all(x) (x).begin(),(x).end()
#define fastio ios_base::sync_with_stdio(false)

typedef double db;
typedef long long ll;
typedef unsigned long long ull;

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

int main() {
	fastio;
	ll a, b, k; cin >> a >> b >> k;
	if(k <= a)
		cout << a - k << " " << b << endl;
	else {
			cout << 0 << " " << max(0ll, b - (k - a)) << endl;
		}
	return 0;
}

Measured memory_bytes: 256
from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
input=lambda :sys.stdin.readline().rstrip()

N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]
data=[[] for i in range(N+1)]
for a,b in AB:
    data[a].append(b)
    data[b].append(a)
a=1
b=data[a][0]

visited={a,b}
lst=[]
for z in [a,b]:
    stack=[z]
    while 1:
        a=stack[-1]
        for p in data[a]:
            if not p in visited:
                stack.append(p)
                visited.add(p)
                break
        else:
            break
    lst.append(stack)

lst[0].reverse()
lst[0]+=lst[1]
print(len(lst[0]))
print(" ".join([str(i) for i in lst[0]]))


Measured memory_bytes: 49148
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
#define ll long long
#define rep(i,n) for (i = 0; i < n; ++i) 
#define REP(i,k,n) for (i = k; i <= n; ++i) 
#define REPR(i,k,n) for (i = k; i >= n; --i)
using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
  ll n;
  cin>>n;
  ll arr[n],sum=0;
  for(int i = 0;i<n;i++)
  {
      cin>>arr[i];
      sum = sum + arr[i];
  }
  ll ans = sum,su=0;
  for(int i=0;i<n-1;i++)
  {
   su=su+arr[i];
   sum=sum-arr[i];
   if(abs(sum - su)<ans)
   {
       ans = abs(sum-su);
   }
   
  }
cout<< ans;
	return 0;
}

Measured memory_bytes: 3520
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<(int)N;i++)
#define p(S) cout<<(S)<<endl
#define ck(n,a,b) (a<=(n)&&(n)<=b)
#define F first
#define S second
using namespace std;
const int inf=1e9;

struct RF{
	int id,from,to;
};
int main(){
	int N;
	while(cin>>N,N){
		vector<RF> seg;
		seg.push_back({-1,0,inf});
		REP(i,0,N){
			char c;
			int id,num;
			cin>>c;
			if(c=='W'){
				cin>>id>>num;
				int i=0;
				while(num>0){
					if(seg[i].id==-1){
						int from=seg[i].from,to=seg[i].to;
						if(to-from+1<=num){
							seg[i].id=id;
							num-=to-from+1;
						}else{
							seg[i]={id,from,from+num-1};
							seg.insert(seg.begin()+i+1,{-1,from+num,to});
							num=0;
						}
					}
					i++;
				}
				//for(auto v:seg){
					//cout<<v.id<<" "<<v.from<<" "<<v.to<<endl;
				//}
			}else if(c=='D'){
				cin>>id;
				REP(i,0,seg.size()){
					if(seg[i].id==id) seg[i].id=-1;
				}
			}else if(c=='R'){
				cin>>num;
				for(auto v:seg){
					if(ck(num,v.from,v.to)){
						p(v.id);
						break;
					}
				}
			}
		}
		p("");
	}

	return 0;
}

Measured memory_bytes: 3268
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n;
	cin >>n;
	int t[n], total=0;
	for(int i=0; i<n; i++){
		cin >> t[i];
		total += t[i];
	}

	int m;
	cin >> m;
	for(int i=0; i<m; i++){
		int p, x;
		cin >> p >> x;
		cout << total + x - t[p-1] << endl;
	}

	return 0;
}

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define VEC vector

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				Vint;
typedef vector<Vint>			VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		100010

const ll LINF = (ll)9e18+7;		//
const int INF = 100100100;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//

// int DP[MAX];

int main(){
	int n,m;cin >> n >> m;
	Vint H(n);
	v(Vint) A(n);
	REP(i,n)cin>>H[i];
	REP(i,m){
		int a,b;cin>>a>>b;
		A[a-1].push_back(b-1);
		A[b-1].push_back(a-1);
	}

	Vint High(n,0);

	REP(i,n){
		if(High[i])continue;
		for(auto j : A[i]){
			High[i] += (H[i]<=H[j]);
			High[j] += (H[i]>=H[j]);
		}
	}
	int cnt = 0;
	REP(i,n)if(High[i]==0)cnt++;
	// cout << High << endl;
	cout << cnt << endl;

	return 0;
}
 



Measured memory_bytes: 9076
S = input()
if 0 < int(S[:2]) < 13:
    if 0 < int(S[2:]) < 13:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 0 < int(S[2:]) < 13:
        print('YYMM')
    else:
        print('NA')


Measured memory_bytes: 2940
N, M = map(int, input().split())
A = [-1*int(i) for i in input().split()]

import heapq
# print(A)
heapq.heapify(A)
# print(A)
for _ in range(M):
    a = heapq.heappop(A)
#     print( "aaa",a)
    heapq.heappush(A,-1*((-1*a)//2))
#     print("AAA",A)
    
# print("list",A)

print(-1*sum(A))


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

int main(){
  int n, k; cin >> n >> k;
  int h[n];
  for(int i=0; i<n; i++){
    cin >> h[i];
  }
  int count;
  for(int i=0; i<n; i++){
    if(h[i]>=k)	count++;
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 640
n=int(input())
A=list(map(int,input().split()))
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

C=Counter(A[::2])
CC=Counter(A[1::2])
A=[[i,j] for i,j in C.items()]+[[None,0]]
AA=[[i,j] for i,j in CC.items()]+[[None,0]]
A=sorted(A, key=lambda x:x[1])
AA=sorted(AA, key=lambda x:x[1])
if A[-1][0]==AA[-1][0]:
    print(min(  sum(C.values())-A[-2][1]+sum(CC.values())-AA[-1][1] , sum(C.values())-A[-1][1]+sum(CC.values())-AA[-2][1]  ))
    exit()
print(sum(C.values())-max(C.values())+ sum(CC.values()) - max(CC.values()))


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

int mod = 998244353;

int expo(int num, int p) {
    if(num == 0) return 0;
    num = num % mod;
    int ret = 1;
    while(p) {
        if(p & 1) ret = (ret * num) % mod;
        num = (num * num) % mod;
        p /= 2;
    }
    return ret;
}

signed main() {
    IOS;
    int fact[200005], inv[200005];
    fact[0] = 1;
    for(int i = 1; i < 200005; ++i) fact[i] = (fact[i - 1] * i) % mod;
    for(int i = 0; i < 200005; ++i) inv[i] = expo(fact[i], mod - 2);
    int n, m, k;
    cin >> n >> m >> k;
    int ans = 0;
    if(m == 1) {
        if(k == n - 1) cout << 1;
        else cout << 0;
        return 0;
    }
    for(int i = 0; i <= k; ++i) {
        int cur = (m * expo(m - 1, n - i - 1)) % mod;
        cur = (cur * fact[n - 1]) % mod;
        cur = (cur * inv[i]) % mod;
        cur = (cur * inv[n - i - 1]) % mod;
        ans = (ans + cur) % mod;
    }
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 6796
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int BAN=1<<25;
typedef struct P{int p,t,f;bool operator <(const P &a)const{ return t==a.t?p<a.p:t>a.t;};}P;
int N,M[100010],f[100010],np;
int main()
{
	memset(f,0x77,sizeof(f));
	f[0]=0;
	scanf("%d",&N);
	for(int i=0;i<N;i++)scanf("%d",&M[i]);
	priority_queue<P>Q;
	P t={0,0,0};Q.push(t);
	for(;!Q.empty();)
	{
		t=Q.top();Q.pop();
		if(t.p>=N-1)break;
		if(t.t>f[t.p])continue;
		if(!t.f)
			for(int i=1;i<=6;i++)
			{
				np=t.p+i;
				if(f[np]>t.t+1)
				{
					f[np]=t.t+1;
					P ins={np,t.t+1,M[np]?1:0};
					Q.push(ins);
				}
			}
		else
		{
			np=t.p+M[t.p];
			if(f[np]>t.t)
			{
				f[np]=t.t;
				P ins={np,t.t,M[np]?1:0};
				Q.push(ins);
			}
		}
	}
	printf("%d\n",t.t);
	return 0;
}

Measured memory_bytes: 1860
#include<iostream>
using namespace std;
int main() {
  int X,Y;
  cin >> X >> Y;
  if(Y%2 == 1)cout << "No" << endl;
  else if(Y<2*X)cout << "No" << endl;
  else if(Y>4*X)cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/*Atcoder用
 * 		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int a = Integer.parseInt(tmp[0]);
		int b = Integer.parseInt(tmp[1]);
		int c = Integer.parseInt(tmp[2]);


		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String get = br.readLine();
		char[] s = get.toCharArray();
		for(char c:s)System.out.println(c);

		List<Integer> ls = new ArrayList<Integer>();
		String[] tmp = br.readLine().split(" ");
		for (int n = 0; n < N; n++) {
			ls.add(Integer.parseInt(tmp[n]));
		}
 */

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");

		List<Integer> ls = new ArrayList<Integer>();
		int a = Integer.parseInt(tmp[0]);
		int b = Integer.parseInt(tmp[1]);
		int c = Integer.parseInt(tmp[2]);

		ls.add(a);
		ls.add(b);
		ls.add(c);

		ls.sort(null);
		int sum = 0;
		for(int i = 0;i<2;i++){
			sum += Math.abs(ls.get(i) - ls.get(i+1));
		}
		System.out.println(sum);




	}
}


Measured memory_bytes: 22612
N = int(input())
result = N

for i in range(1, N//2+1):
    a = str(i)
    b = str(N - i)
    wa_a = sum([int(t) for t in a])
    wa_b = sum([int(t) for t in b])
    if result > wa_a + wa_b:
        result = wa_a + wa_b
print(result)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;

ll INF = LLONG_MAX;

#define ARRAY_MAX 15

void build(ll first,ll last,vector<ll>& value,vector<ll>& weight,vector<LLP> &arr,ll weight_maxi){

    ll times = last - first;
    for(int i = 0;i < (1<<times);i++){

        ll va = 0,we = 0;
        for(int j = 0;j < times;j++){
            
            if((i>>j)&1){
                //選ぶ
                va += value[first + j];
                we += weight[first + j];
            }
        }
        if(we > weight_maxi){
            continue;
        }
        arr.push_back({we,va});
    }
    VSORT(arr);

    ll v_max = 0;
    REP(i,arr.size()){
        v_max = max(v_max,arr[i].second);
        arr[i].second = v_max;
    }
}




int main(){

    ll n,weight_maxi;
    cin >> n >> weight_maxi;
    vector<ll> value(n),weight(n);
    REP(i,n){
        cin >> value[i] >> weight[i];
    }

    vector<LLP> s1,s2;

    build(0,n/2,value,weight,s1,weight_maxi);//前半部分
    build(n/2,n,value,weight,s2,weight_maxi);//後半部分
    ll ans = -1;

    REP(i,s1.size()){
        ll w1 = s1[i].first,v1 = s1[i].second,v2;
        v2 = (lower_bound(s2.begin(),s2.end(),LLP(weight_maxi-w1,INF))-1)->second;
        ans = max(ans,v1+v2);
    }
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 43712
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int sum = 700;
  string S;
  cin >> S;

  for (int i = 0; i < 3; ++i)
  {
    if (S.at(i) == 'o')
    {
      sum += 100;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
 int n,a,b,count=0,sum,num;
 cin >> n >> a >> b;
 for(int k=1;k<=n;k++){
  sum =0; num =k;
  for(int i=0;i<10;i++){
  sum += num%10;
  num = num/10;

  }
  if(sum>=a&&sum<=b)
   count += k;
 }
  cout << count << endl;
  
 return 0;
} 

Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

ll A, B, K;

signed main(){
    cin >> A >> B >> K;
    if(A >= K){
        cout << A-K << " " << B << endl;
    }
    else{
        cout << 0 << " " << max(0LL, B+A-K) << endl;
    }
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const int INF=1e9;


int main(){
  char a;
  cin >>a;

  if(isupper(a)){
    cout<<"A"<<endl;
  }else{
    cout<<"a"<<endl;
  }

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
//Int mod = 998244353;
Int INF = 1e18;
double EPS = 0.00000001;

int main() {
    Int n, k;
    string s;
    cin >> n >> k >> s;
    string t = s;
    reverse(t.begin(), t.end());
    string u = s;
    reverse(u.begin(), u.end());
    s = s + t;
    for (Int i = 0; i < n + 1; i++) {
        string tmp = s.substr(i, n);
        //dump(tmp);
        reverse(tmp.begin(), tmp.end());
        u = min(u, tmp);
    }        
    //dump(u);
    Int cnt = 0;
    char a = u[0];
    string pre = "";
    for (Int i = 0; a == u[i]; i++) {
        cnt++;
        pre.push_back(u[i]);
    }
    Int i = 0;
    while (cnt <= n && i < k - 1) {
        cnt <<= 1LL;
        i++;
    }
    if (cnt > n) {
        //assert(true);
        for (Int i = 0; i < n; i++) {
            cout << a;
        }
        cout << endl;
        return 0;
    }
    else {
        for (Int i = 0; i < cnt; i++) {
            cout << a;
        }
        Int i = 0;
        while (a == u[i]) i++;
        while (i < n - (cnt - (Int)pre.size())) {
            cout << u[i];
            i++;
        }
        cout << endl;
        return 0;
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000000 + 7
#define PI 3.14159265359

const long long INF = 100000;
typedef pair<int,int> P;
typedef long long ll;

using Graph = vector<vector<ll>>;

vector<int> num(100000 + 5); //num[i]は点iが含まれる連結領域の自信を含まない要素数
vector<int> numb(100000 + 5); //連結領域にいる、自身とブロック関係にある人の数

vector<bool> seen(100000 + 5, false);

//まず各点が含まれる連結領域の要素数を求める

int iCount = 0; //連結領域の自信を含まない要素数
vector<int> connect; //連結領域の要素を格納
vector<int> connect2; //連結領域の要素を格納

void dfs(const Graph &G, int v) {
	if (seen[v]) return;

	seen[v] = true;//vを訪問済みにする
	connect.push_back(v);//vを追加

	for (auto next_v : G[v]) {//vと隣接する要素を見る

		if (seen[next_v]) continue;//訪問済みならスルー
		dfs(G, next_v);//再帰的に探索
	}

}

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

	Graph Friend(N + 1);//友達関係のグラフ
	Graph Block(N + 1);//ブロック関係のグラフ

	for (int i = 0; i < M ;i++) {
		int A, B;
		cin >> A >> B;
		Friend[A].push_back(B);
		Friend[B].push_back(A);
	}

	for (int i = 0; i < K; i++) {
		int C, D;
		cin >> C >> D;
		Block[C].push_back(D);
		Block[D].push_back(C);
	}

	for (int v = 1; v <= N; v++) {
		dfs(Friend, v);

		for (int i = 0; i < connect.size(); i++) {

			//connect.size() - 1は自身を含まない連結領域の要素数
			num[connect[i]] = connect.size() - 1;
		}

		set<int> S;//connectの各要素 = 各点が含まれる連結領域の要素を格納
		int count = 0;

		for (int i = 0; i < connect.size(); i++) {
			S.insert(connect[i]);
		}

		//connectの各点について調べる
		for (int i = 0; i < connect.size(); i++) {
			int v2 = connect[i];
			for (auto k : Block[v2]) { //v2とブロック関係のある要素で、connectに含まれているものを数える
				if (S.count(k)) count++;
			}
			numb[v2] = count;

			count = 0;
		}

		connect = connect2;
	}

	vector<int> ans;

	for (int v = 1; v <= N; v++) {
		int ff = 0;//vの友達候補の数

		ff = num[v] - Friend[v].size() - numb[v];
		ans.push_back(ff);
	}

	for (int i = 0; i < ans.size(); i++) {
		if (i == ans.size() - 1) cout << ans[i];
		else cout << ans[i] << " ";
	}
	cout << endl;

}

Measured memory_bytes: 18296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
int main(){
  ll N; cin >> N;
  ll dist[310][310]; bool to[310][310];
  for(int i = 0; i < 310; i++){for(int j = 0; j < 310; j++){ if( i!= j){to[i][j] = true;}else{to[i][j] = false;}}}
  //必要な道をtrueとする(全ての異なる２点間同士に最初に道をひく)
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){ cin >> dist[i][j];}}
  //まず先に全点の間を最短距離で直接結び、Warshall-Floydの要領で余計な道を刈り取っていく
  
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        
        if( dist[i][j] > dist[i][k] + dist[k][j]){cout << -1 << endl; return 0;}
        else if( dist[i][j] == dist[i][k] + dist[k][j] && i != k && j != k && i != j){
          //i,j間を直接むすぶ最短路と同じ、迂回路が存在↪︎この道いらない
          to[i][j] = false; to[j][i] = false;
        }
       
      }
    }
  }

  ll ans = 0;
  for(int i = 0; i < N-1; i++){
    for(int j = i+1; j < N; j++){ 
      if( to[i][j]){  ans += dist[i][j];}}}
  
  cout << ans << endl; return 0;}
                                  
          
          

Measured memory_bytes: 1024
#prag\
ma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long
using namespace std;

vector<int> v;
map<char,int> m;
char ch[5]={'M','A', 'R', 'C','H'};

int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		string s;
		cin>>s;
		m[s[0]]++;
	}
	ll ans=0;
	for(int i=0;i<=2;i++)
		for(int j=i+1;j<=3;j++)
			for(int k=j+1;k<=4;k++)
			{
				ans+=(ll)m[ch[i]]*(ll)m[ch[j]]*(ll)m[ch[k]];
			}
	cout<<ans<<endl;
}

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

template <size_t N, typename T, typename U = T, std::enable_if_t<
  N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz, T t) {
  return std::vector<U>(sz, t);
}
template <size_t N, typename T, std::enable_if_t<
  N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz) {
  return std::vector<T>(sz);
}
template <size_t N, typename T, typename... Args, std::enable_if_t<
  N != 1, std::nullptr_t> = nullptr>
auto make_vector(size_t a, Args... args) {
  return make_vector<1>(a, make_vector<N - 1, T>(args...));
}
template <typename T, typename Size_t>
auto& at(T& t, Size_t i) {
  return t.at(i);
}
template <typename T, typename Size_t, typename... Args>
auto& at(T& t, Size_t i, Args... args) {
  return at(t.at(i), args...);
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; long long k; std::cin >> n >> k;
  std::vector<int> a(n);
  for (auto& x : a) {std::cin >> x; x--;}
  constexpr int max = 2e5;
  auto m = make_vector<2, int>(max, 0);
  for (int i = 0; i < n; i++) {
    m.at(a.at(i)).push_back(i);
  }
  auto add = std::vector<int>(n);
  for (auto& v : m) {
    if (v.empty()) continue;
    int sz = v.size();
    v.push_back(n + v.front());
    for (int i = 0; i < sz; i++) {
      auto crr = v.at(i), nxt = v.at(i + 1);
      assert(0 <= crr && crr < n && crr < nxt);
      add.at(crr) = nxt - crr + 1;
    }
  }
  auto moved = [&] (auto x) {
    return x + add.at(x % n);
  };
  k %= [&] {
    long long ret = 0;
    for (int i = 0; i < n; i++) {
      ret = moved(ret);
      if (ret % n == 0) break;
    }
    assert(ret % n == 0);
    return ret / n;
  }();
  long long crr = 0, goal = n * k;
  std::vector<int> ans;
  while (crr < goal) {
    auto nxt = moved(crr);
    if (nxt <= goal) {
      crr = nxt;
      continue;
    }
    ans.push_back(a.at((crr++ % n)));
  }
  int sz = ans.size();
  for (int i = 0; i < sz; i++) {
    std::cout << (i > 0 ? " " : "") << ans.at(i) + 1;
  }
  std::cout << std::endl;
  return 0;
}

Measured memory_bytes: 14968
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

int main(){
    int a, b;
    cin >> a >> b;
    if(a%2 != b%2) cout << "IMPOSSIBLE" << endl;
    else cout << (a + b) / 2 << endl;
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] b = Console.ReadLine().Split();
            int A = int.Parse(b[0]); int B = int.Parse(b[1]);
            int an;
            if (A % B == 0) { an = 0; }
            else { an = 1; }
            Console.Write(an);
        }
    }
}

Measured memory_bytes: 13140
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n, m; cin>>n>>m;
    vector<vector<int>> modM(m);
    for(int i=0; i<n; i++){
        int x; cin>>x;
        modM[x%m].emplace_back(x);
    }

    for(int i=0; i<m; i++){
        sort(modM[i].begin(), modM[i].end());
    }

    int half = m / 2;
    int ans = modM[0].size() / 2;
    for(int i=1; i<=half; i++){
        int small = i, big = m - i;
        int smallsz = modM[small].size(), bigsz = modM[big].size();

        if(smallsz == bigsz){
            if(small == big) ans += smallsz / 2;
            else ans += smallsz;
            continue;
        }

        if(smallsz > bigsz){
            int maxmatch = 0;
            for(int j=0; j<smallsz; j++){
                int cnt = 1, cur = modM[small][j];
                while(j + 1 < smallsz && cur == modM[small][j+1]){
                    j++;
                    cnt++;
                }
                maxmatch += cnt / 2;
            }

            ans += bigsz;

            int rest = smallsz - bigsz;
            ans += min(rest / 2, maxmatch);
        }
        else{
            int maxmatch = 0;
            for(int j=0; j<bigsz; j++){
                int cnt = 1, cur = modM[big][j];
                while(j + 1 < bigsz && cur == modM[big][j+1]){
                    j++;
                    cnt++;
                }
                maxmatch += cnt / 2;
            }

            ans += smallsz;

            int rest = bigsz - smallsz;
            ans += min(rest / 2, maxmatch);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5760
#! /usr/bin/python 
# -*- coding: utf-8 -*- 
#===============================================================================
# Date created  : 2019-03-26T14:51:38+09:00
# Date modified : 2019-03-26T15:03:21+09:00
# Author        : awk
# Description   : unanswered
#===============================================================================
N = int(input())
MOD = 7 + 10**9
L = list(map(int,input().split()))
if N % 2 == 0:
    correct = []
    for i in range(N // 2):
        correct.append(i*2 + 1)
        correct.append(i*2 + 1)

    if sorted(L) == sorted(correct):
        print(2 ** (N // 2)% MOD)
    else:
        print(0)
else:
    correct = [0]
    for i in range(N // 2):
        correct.append((i+1)*2)
        correct.append((i+1)*2)
    if sorted(L) == sorted(correct):
        print(2 ** (N // 2) % MOD)
    else:
        print(0)


Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
vector <bool>  primes(1000000,1) ;
void Eratosthenes(int n){
    for(int i = 2; i <= sqrt(n); i++){
		if(primes[i]){
			for(int j = 0; i * (j + 2) <= n; j++){
				primes[i *(j + 2)] = 0;
			}
		}
	}
	primes[0] = 0; primes[1] = 0;

	
}
signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    Eratosthenes(200000);
    int n; cin>>n;
    while(1){
        if(primes[n]) {cout<<n<<endl; return 0;}
        n++;
    }
}

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

using namespace std;

void abc_170a();
void abc_171a();
void abc_172a();
void abc_173a();
void abc_174a();
void abc_175a();

void abc_170b();
void abc_171b();


int main()
{
  //abc_170a();
  //abc_171a();
  //abc_172a();
  //abc_173a();
  //abc_174a();
  //abc_175a();

  //abc_170b();
  abc_171b();

}

void abc_170a()
{
  vector<int> x(5);
  for (int i = 0; i < 5; ++i) cin >> x[i];

  for (int i = 0; i < 5; ++i)
  {
    if (x[i] == 0)
    {
      cout << i + 1 << "\n";
      return;
    }
  }
}

void abc_171a()
{
  char c;
  cin >> c;

  if (c == tolower(c)) cout << "a\n";
  else cout << "A\n";
}

void abc_172a()
{
  int a;
  cin >> a;

  cout << a + a * a + a * a * a << "\n";
}

void abc_173a()
{
  int N;
  cin >> N;

  if (N % 1000) cout << 1000 - N % 1000 << "\n";
  else cout << "0\n";
}

void abc_174a()
{
  int x;
  cin >> x;

  if (x >= 30) cout << "Yes\n";
  else cout << "No\n";
}

void abc_175a()
{
  string s;
  cin >> s;

  int cnt = 0, tmp = 0;
  for (int i = 0; i < s.size(); ++i)
  {
    if (s[i] == 'S')
    {
      tmp = 0;
    }
    else
    {
      ++tmp;
      cnt = tmp;
    }
  }

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


void abc_170b()
{
  int x, y;
  cin >> x >> y;

  for (int i = 0; i <= x; ++i)
  {
    int n_c = i, n_t = x - i;
    if (n_c * 2 + n_t * 4 == y)
    {
      cout << "Yes\n";
      return;
    }
  }
  cout << "No\n";
}

void abc_171b()
{
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i < N; ++i) cin >> p[i];

  sort(p.begin(), p.end());

  int price = 0;
  for (int i = 0; i < K; ++i)
  {
    price += p[i];
  }
  cout << price << "\n";
}


Measured memory_bytes: 3612