akhauriyash/Code-Regression huggingface dataset:
void main(){
	int n = _scan();
	int[] a = _scanln();
	int allxor;
	foreach(elm; a){
		allxor = allxor^elm;
	}
	int[] ans;
	foreach(elm; a){
		ans ~= allxor^elm;
	}
	
	foreach(i, elm; ans){
		if(i == ans.length-1) writeln(elm);
		else writef("%d ", elm);
	}
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


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

const int N = 4005, M = 998244353;

int n, a[N], b[N], d[N][N];
char s[N];

int main(){
    scanf("%s", s + 1);
    n = strlen(s + 1);
    for(int i = 1; i <= n; i++){
        a[i] = a[i - 1] + s[i] - '0';
        b[i] = b[i - 1] + 2 - (s[i] - '0');
    }
    for(int i = n + 1; i <= 2 * n; i++){
        a[i] = a[i - 1];
        b[i] = b[i - 1];
    }
    d[0][0] = 1;
    for(int i = 0; i < 2 * n; i++){
        for(int j = 0; j <= a[i]; j++){
            int ta = a[i] - j, tb = b[i] - (i - j);
            if(ta < 0 || tb < 0) continue;
            d[i + 1][j + 1] = (d[i + 1][j + 1] + d[i][j]) % M;
            d[i + 1][j] = (d[i + 1][j] + d[i][j]) % M;
        }
    }
    printf("%d\n", d[2 * n][a[2 * n]]); 
}

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

int main()
{
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    for(int i=0;i<ty-sy;i++)
    cout<<"U";
    for(int i=0;i<tx-sx;i++)
    cout<<"R";
    for(int i=0;i<ty-sy;i++)
    cout<<"D";
    for(int i=0;i<tx-sx;i++)
    cout<<"L";
    cout<<"L";
    for(int i=0;i<ty-sy+1;i++)
    cout<<"U";
    for(int i=0;i<tx-sx+1;i++)
    cout<<"R";
    cout<<"DR";
    for(int i=0;i<ty-sy+1;i++)
    cout<<"D";
    for(int i=0;i<tx-sx+1;i++)
    cout<<"L";
    cout<<"U";
}


Measured memory_bytes: 256
s = int(input())
MOD = 10**9+7
len_inv = 2*(10**4) + 10
inv = [1]*(len_inv)
for i in range(2, len_inv):
    inv[i] = inv[MOD%i] * (MOD - MOD//i) % MOD

def comb(n, k, MOD):
    x = 1
    for i in range(k):
        x *= (n-i)
        x *= inv[i+1]
        x %= MOD
    return x

ans = 0
for i in range(1, s+1):
    if s < 3*i: break
    s2 = s - 3*i
    ans += comb(s2+i-1, i-1, MOD)
ans %= MOD
print(ans)


Measured memory_bytes: 9568
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
vector<ll>adj[1000005];
ll expo(ll b,ll n,ll m)
{
 ll r,p;
	p=1;
	 b=b%m;
	while(n>0)
	{ 
		r=n%2;
		if(r==1)
		   p=((p%m)*(b%m))%m;
		b=((b%m)*(b%m))%m; 
		n=n/2;		
	}
 return (p%m);
}
ll divide1(ll a,ll b,ll m)
	{ ll r,p,n;
			p=a%m;
				n=m-2;
				while(n>0){
						 r=n%2;
						if(r==1)
							p=((p%m)*(b%m))%m;
						b=((b%m)*(b%m))%m; 
						n=n/2;	
					}
	return (p%m); }
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	string s;
	cin>>s;
	string ans="Yes";
	for (int i = 0; i < s.length(); ++i)
	{
		if ((i==2 or i==4) and i+1<s.length() and s[i]!=s[i+1])
		{
			ans="No";
		}
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,string>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;


int main(){
    ll N;
    cin >> N;
    vector<ll> A(N+1,0);
    vector<ll> ch(N+1,0);
    for(ll i=2;i<=N;i++){
        cin>>A[i];
        ch[A[i]]++;
    ;}
    for(ll i=0;i<N;i++){
        cout<<ch[i+1]<<endl;
    ;}

return 0;
}


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

bool isPrime(int n) {
  for(int i = 2; i <= sqrt(n); ++i){
    if(n%i == 0) return false;
  }
  return true;
}

int main() {
  int N;
  cin >> N;
  int cnt = 0;
  while(N--){
    int a;
    cin >> a;
    cnt += isPrime(a);
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 824
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
#define ll  long long 
  vector<ll>to[1000005];
int main(){
  ll a,b=INT_MAX;cin>>a;
  vector<ll>c(a);
  rep(i,a)cin>>c[i];
  reverse(c.begin(),c.end());
  rep(i,a){
    if(b+1==c[i])c[i]=b;
    else if(b<c[i]){
      cout<<"No";
      return 0;
    }
    b=c[i];
  }
  cout<<"Yes";
  }


Measured memory_bytes: 24448
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<30;
const int mod = 1e9+7;


int main() {
  long long N, A, B; cin >> N >> A >> B;
  vector<long long> X(N);
  for(int i = 0; i < N; i++) {
    cin >> X[i];
  }
  long long ans = 0;
  for(int i = 1; i < N; i++) {
    ans += min((X[i] - X[i-1])*A, B);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] a = new int[3][n];
		for(int i=0;i<n;i++) {
			for(int j=0;j<3;j++) {
				a[j][i] = sc.nextInt();
			}
		}
		int[] score = new int[n];
		for(int k=0;k<3;k++) {
			for(int i=0;i<n;i++) {
				boolean flag = true;
				for(int j=0;j<n;j++) {
					if (i == j) {
						continue;
					}
					if (a[k][i] == a[k][j]) {
						flag = false;
						break;
					}
				}
				if (flag) {
					score[i] += a[k][i];
				}
			}
		}
		for(int i=0;i<n;i++) {
			System.out.println(score[i]);
		}
	}
}

Measured memory_bytes: 20812
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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() {
  long double r;
  cin >> r;
  r *= 2;
  long double ans = r*M_PI;
  printf("%.10Lf\n",ans);
}


Measured memory_bytes: 3264
#include<stdio.h>
#define max(a,b)  ((a)>(b)?(a):(b))

int dwdp[2002][2002],updp[2002][2002],lfdp[2002][2002],ridp[2002][2002];

int main(void){
    register int i,j,ri,rj;
    int h,w;
    scanf("%d %d",&h,&w);
    getchar();
    char grid[h][w];
    for(i = 0;i < h;i++,getchar())for(j = 0;j < w;j++)scanf("%c",&grid[i][j]);
    //down and up
    for(j = 1;j <= w;j++)for(i = 1;i <= h;i++){
        ri = h - i + 1;

        if(grid[i-1][j-1] != '#')updp[i][j] = updp[i-1][j] + 1;

        if(grid[ri-1][j-1] != '#')dwdp[ri][j] = dwdp[ri+1][j] + 1;
    }
    //left and right
    for(i = 1;i <= h;i++)for(j = 1;j <= w;j++){
        rj = w - j + 1;

        if(grid[i-1][j-1] != '#')lfdp[i][j] = lfdp[i][j-1] + 1;

        if(grid[i-1][rj-1] != '#')ridp[i][rj] = ridp[i][rj+1] + 1;
    }
    int ans = 0;
    for(i = 0;i < h;i++)for(j = 0;j < w;j++)ans = max(ans,dwdp[i+1][j+1]+updp[i+1][j+1]+lfdp[i+1][j+1]+ridp[i+1][j+1]-3/*overlap*/);
    printf("%d",max(ans,0));
    return 0;
}

Measured memory_bytes: 66688
#include <iostream>
using namespace std;
int main() {
	int a, b, k[15];
	cin >> a >> b;
	for (int i = 0; i < b; ++i) {
		cin >> k[i];
	}
	for (int i = a; i < 10 * a; ++i) {
		int mon = i, ch;
		bool check = true;
		while (mon) {
			ch = mon % 10;
			for (int j = 0; j < b; ++j) {
				if (k[j] == ch) {
					check = false;
					break;
				}
			}
			mon /= 10;
		}
      if (check) {
				cout << i << endl;
				return 0;
			}
	}
}

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

string S;
bool kaibun = true;

int main(){
  cin >> S;
  int N = S.size();

  for(int i = 0; i < N/2; i++){
    if(S[i] != S[N-1-i]){ kaibun = false; break; }
  }

  for(int i = 0; i < N/2-1; i++){
    if(S[i] != S[N/2-1-i]){ kaibun = false; break; }
  }

  for(int i = 0; i < N/2-1; i++){
    if(S[(N+1)/2+i] != S[N-1-i]){ kaibun = false; break; }
  }

  if(kaibun) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}






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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;
}


Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using static System.Math;
using System.Text.RegularExpressions;

namespace CsharpSpiral {
    partial class Program {
        static void Main(string[] args) {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }
        public void Solve(ConsoleInput cin) {
            var N = cin.ReadInt;
            var A = cin.ReadIntArray(N);
            var D = new int[N];
            for(int i = 0; i < N; i++) {
                D[A[i] - 1]++;
            }
            var All = D.Sum(a => (long)a * (a - 1) / 2);
            for(int i = 0; i < N; i++) {
                Console.WriteLine(All - (D[A[i] - 1] - 1));
            }
        }
    }

    static class ExtendClass {
        public static string Join<T>(this T[] X, string separator = " ") => string.Join(separator, X);
        public static S[] Clone<S>(this S[] src) where S : struct {
            var res = new S[src.Length];
            Array.Copy(src, res, src.Length);
            return res;
        }
    }

    class ConsoleInput {
        private readonly TextReader _stream;
        private readonly char _separator = ' ';
        private readonly Queue<string> inputStream;
        public ConsoleInput(TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read {
            get {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) {
            var ret = new string[N];
            for(long i = 0; i < N; ++i)
                ret[i] = Read;
            return ret;
        }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }
}


Measured memory_bytes: 37668
fun main(args:Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val count = (0 until m).map { 0 }.toMutableList()
    (1..n).forEach {
        readLine()!!.split(" ").map { it.toInt() - 1 }.drop(1).forEach { count[it]++ }
    }
    val ans = count.count { it == n }
    println(ans)
}

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

using namespace std;

int main()
{
    long long int x , i = 1 , p=100;
    cin>>x;
    while(true)
    {   
       p = 1.01*p;
       if(p>=x)
       {
           break;
       }
       i++;
    }
    cout<<i<<endl;
}

Measured memory_bytes: 3636
package main

import (
	"fmt"
	"sort"
)

type list []int

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

func main() {
	var n int
	fmt.Scanf("%d", &n)
	li := make(list, n)
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &li[i])
		sum += li[i]
	}
	sort.Sort(li)
	if sum%10 != 0 {
		fmt.Println(sum)
		return
	}
	for i := 0; i < n; i++ {
		if li[i]%10 != 0 {
			fmt.Println(sum - li[i])
			return
		}
	}
	fmt.Println(0)
}


Measured memory_bytes: 512
n, m = map(int, input().split())
ls = [[_ for _ in input().split()] for _ in range(m)]

ls_ac = [0] * n
ls_ng = [0] * n
ac = 0
ng = 0


for i in range(m):
    p = int(ls[i][0])
    if ls[i][1] == "AC":
        if ls_ac[p - 1] == 0:
            ac += 1
            ng += ls_ng[p - 1]
            ls_ac[p - 1] = 1
    elif ls[i][1] == "WA":
        if ls_ac[p - 1] == 0:
            ls_ng[p - 1] += 1

print(ac, ng)

Measured memory_bytes: 27508
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <list>
#define MAXN 1000010
using namespace std;

namespace S{
	list<int> ls;
	int delta;

	void add_all(int v){
		delta+=v;
	}

	int front(){
		return (*ls.begin())+delta;
	}

	void pop_front(){
		ls.pop_front();
	}

	int back(){
		return (*(--ls.end()))+delta;
	}

	void pop_back(){
		ls.pop_back();
	}

	void push_back(int x){
		ls.push_back(x-delta);
	}

	bool empty(){
		return ls.empty();
	}
}

int n;
int a[MAXN];

int main(){
#ifdef DEBUG
	freopen("E.in","r",stdin);
#endif
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	sort(a+1,a+n+1);
	S::push_back(a[1]);
	for(int i=2;i<=n;i++)
		if(a[i]>S::back()){
			if((a[i]-S::back())&1) S::pop_back();
			S::add_all(-1);
			while(!S::empty() && S::front()<0) S::pop_front();
			S::push_back(a[i]);
		}else{
			S::add_all(-1);
			while(!S::empty() && S::front()<0) S::pop_front();
		}
	if(S::front()&1) puts("Second");
	else puts("First");
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main () {
	int b, r, g, c, s, t;
	while (cin >> b >> r >> g >> c >> s >> t, b || r || g || c || s || t) {
		int bg = b * 5 + r * 3;
		t -= bg + s;
		int m = 100 - t * 3 + bg * 13 + b * 15 + r * 15 + g * 7 + c * 2;
		cout << m << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 100010;
VI e[N];
ll d1[N], d2[N], p1[N], p2[N];

void bfs(int s, ll d[], ll p[]){
    REP(i,N) d[i] = -1;
    d[s] = 0;
    queue<int> que;
    que.push(s);
    while (!que.empty()){
        int now = que.front();
        que.pop();
        p[d[now]]++;
        REP(i,e[now].size()){
            int next = e[now][i];
            if (d[next] >= 0) continue;
            d[next] = d[now] + 1;
            que.push(next);
        }
    }
}

int main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--;
    t--;
    REP(i,m){
        int x, y;
        scanf("%d %d", &x, &y);
        x--;
        y--;
        e[x].push_back(y);
        e[y].push_back(x);
    }
    bfs(s,d1,p1);
    bfs(t,d2,p2);
    int x = d1[t];

    ll ans = 0;
    REP(i,x-1){
        ans += p1[i] * p2[x-2-i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11024
#include <iostream>

using namespace std;

//global variances
int N;
int result = 0;

int main()
{
    cin >> N;
    
    for (int i = 1; i <= N; ++i)
    {
        for (int j = 1; j <= N; ++j)
        {
            for (int k = 1; k <= N; ++k )
            {
                result++;
            }
        }
    }
    
    cout << result;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int N;
    cin >> N;
    int p[N];
    REP(i, N) cin >> p[i];

    int s = 0;
    REP(i, N) s += p[i];

    int m = 0;
    REP(i, N) if (m < p[i]) m = p[i];

    cout << s - m + (m / 2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
	int N;

	cin >> N;

	int a[N + 1];

	for (int i = 1; i <= N; i++)
	{
		cin >> a[i];
	}

	int b[N + 1];
	int M = 0;
	/* bool done[N + 1]; */

	for (int i = N; i >= 1; i--)
	{
		int b_sum = 0;
		for (int j = 2 * i; j <= N; j += i)
		{
			b_sum += b[j];
		}

		int b_amari = b_sum % 2;

		if (((b_amari == 1) && (a[i] == 1)) || ((b_amari == 0) && (a[i] == 0)))
		{
			b[i] = 0;
		}
		else
		{
			b[i] = 1;
			M++;
		}
	}

	cout << M << endl;

	for (int i = 1; i <= N; i++)
	{
		if (b[i] == 1)
		{
			cout << i << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 2432
n = int(input().split()[0])
c = list(map(int,input().split()))
minimum = [ i for i in range(n+1) ]

for i in range(2,n+1):
    for j in c:
        if j <= i and minimum[i-j] + 1 < minimum[i]:
            minimum[i] = minimum[i-j]+1

print(minimum[n])

Measured memory_bytes: 9620
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF INT_MAX 
int main(){
    int N;
    cin >> N;
    int r=0,b=0;
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='R')r++;
        else b++;
    }
    if(r>b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int X = sc.nextInt();
			final int T = sc.nextInt();
			
			System.out.println((N + X - 1) / X * T);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


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

using namespace std;

int main()
{
    int A,a,B,b;
    cin >> A >> a >> B >> b;
    int C = 0;
    int c = 0;
    int D = 0;
    int d = 0;
    C = B-(b-a);
    c = b+(B-A);
    D = A-(b-a);
    d = a+(B-A);
    cout<<C<<' '<<c<<' '<<D<<' '<<d<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();

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

    int L, R, d; cin >> L >> R >> d;

    int ans = 0;

    for (int i=L;i<=R;i++) {
        if (i%d==0) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long R) { printf("%.10f\n", 2 * R * 3.1415926535); }

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


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

struct Unionfind{
  vector<long> par,par2;
  map<pair<int,int>,int> res;

  Unionfind(long n): par(n),par2(n){
    rep(i,n){
      par[i] = i;
      par2[i] = i;
    }
  }

  int root(int x){
    if(par[x] == x)return x;
    else return par[x] = root(par[x]);
  }
  int root2(int x){
    if(par2[x] == x)return x;
    else return par2[x] = root2(par2[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx != ry){
      par[rx] = ry;
    }
  }
  void unite2(int x, int y){
    int rx = root2(x);
    int ry = root2(y);
    if(rx != ry){
      par2[rx] = ry;
    }
  }

  void ans(int n){
    rep(i,n){
      int r1 = root(i);
      int r2 = root2(i);
      res[{r1,r2}]++;
    }
    rep(i,n){
      cout << res[{root(i),root2(i)}] << " ";
    }
  }

};

int main(){
  long n,k,l;
  cin >> n >> k >> l;
  Unionfind tree(n);
  rep(i,k){
    long p,q;
    cin >> p >> q;
    p--;q--;
    tree.unite(p,q);
  }
  rep(i,l){
    long r,s;
    cin >> r >> s;
    r--;s--;
    tree.unite2(r,s);
  }
  tree.ans(n);
  return 0;
}

Measured memory_bytes: 17720
//K-OS WITH THE OCDE

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <iostream>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

typedef long long int ll;
typedef long double db;


#define TEST ll t; cin>>t; while(t--)
#define vell vector<ll>
#define pl pair<ll,ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define dbg(x)  cerr << #x << ": "<< x <<endl
#define dbg2(x,y) cerr<< #x <<": "<< x <<" || "<< #y << ": " << y << endl

#define endl "\n"
#define MAX 1e18
#define MIN INT_MIN
#define mod 1000000007



void solve()
{
    ll n;
    cin >> n;
    ll mx = MIN;
    ll f = 0;

    for (ll i = 0 ; i < n ; ++i) {
        ll x;
        cin >> x;
        if (x < mx) {

            f += abs(mx - x);
        }
        else
            mx = max(mx , x);
    }

    cout << f;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    //TEST
    solve();
}



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

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    UnionFind Tree(n);
    while(q--){
        int t,x,y;
        cin >> t >> x >> y;
        if(t == 0) Tree.unite(x,y);
        else if(t == 1) {
            if(Tree.same(x,y)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
}



Measured memory_bytes: 3180
#include <iostream>

int main()
{
	int n, a[100010];
	std::cin >> n;
	
	for (int i = 0; i < n; ++i)
	{
		std::cin >> a[i];
		--a[i];
	}
	
	int cnt = 0;
	if (a[0] == 0)
	{
		int t = a[1];
		a[1] = a[0];
		a[0] = t;
		++cnt;
	}
	
	for (int i = 1; i < n - 1; ++i)
	{
		if (a[i] == i)
		{
			if (a[i + 1] != i)
			{
				int t = a[i + 1];
				a[i + 1] = a[i];
				a[i] = t;
				++cnt;
			}
			else
			{
				int t = a[i - 1];
				a[i - 1] = a[i];
				a[i] = t;
				++cnt;
			}
		}
	}
	if (a[n - 1] == n - 1)
	{
		int t = a[n - 1];
		a[n - 1] = a[n - 2];
		a[n - 2] = t;
		++cnt;
	}
	
	std::cout << cnt;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 2019;

ll modpow(ll a, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


int main(){
    string S; cin >> S;
    ll N = S.size();
    vector<ll> DP(N);
    DP[N-1] = S[N-1]-48;
    for(int i = N-2; i >= 0; i--){
        DP[i] =DP[i+1] + modpow(10, N-1-i) * (S[i]-48);
        DP[i] %= MOD;
    }
    ll ans = 0;
    map<ll, ll> M;
    rep(i, N) M[DP[i]]++;
    M[0]++;
    for(auto m : M) ans += (m.second*(m.second-1))/2;
    cout << ans << endl;



}

Measured memory_bytes: 5144
#include "bits/stdc++.h"
using namespace std;
#define MODULO 1000000007
#define PI 3.14159265359
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
     int x;
     cin>>x;
     if(x>=400 && x<600)
     cout<<"8"<<endl;
     if(x>=600 && x<800)
     cout<<"7"<<endl;
	 if(x>=800 && x<1000)
	 cout<<"6"<<endl;
	 if(x>=1000 && x<1200)
	 cout<<"5"<<endl;
	 if(x>=1200 && x<1400)
	 cout<<"4"<<endl;
	 if(x>=1400 && x<1600)
	 cout<<"3"<<endl;
	 if(x>=1600 && x<1800)
	 cout<<"2"<<endl;
	 if(x>=1800 && x<2000)
	 cout<<"1"<<endl;
    return 0;
}


Measured memory_bytes: 3684
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int r,g,b,x;
    cin >> r >> g >> b;
    x=r*100+g*10+b;
    if(x%4== 0){
        cout << "YES" << endl;
    }
    else if(x%4!= 0){
        cout << "NO" << endl;
    }
    }


Measured memory_bytes: 256
def powmod(b,r,mod)
  a = 1
  while r > 0
    if r%2 == 1
      a = a * b % mod
    end
    b = b * b % mod
    r /= 2
  end
  a
end
 
def invmod(f, mod)
  powmod(f, mod-2, mod)
end

n,a,b = `dd`.split.map &:to_i
Mod = 10**9+7
comb = [1]
(1..b).each{ |k|
  comb << comb[-1] * (n+1-k) * invmod(k, Mod) % Mod
}
p (powmod(2, n, Mod) - comb[a] - comb[b] - 1) % Mod

Measured memory_bytes: 4092
S = list(input())
T = list("AKIHABARA")
ans = "YES"
i = 0
while i < len(S) and i < 9:
    if S[i] != T[i]:
        if T[i] == "A":
            S.insert(i,"A")
    i += 1
if S[-1] != "A":
    S += "A"

if S == T:
    print("YES")
else:
    print("NO")


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換
int keta(ll n){int ans=0;while(n>0){n /= 10; ans++;}return ans;}
ll _pow(ll a,ll b){ll ans = 1;rep(i,b){ ans *= a;}return ans;}

int main() {
  string s;cin>>s;
  int S,E;
  rep(i,s.size()){
      if(s[i] == 'A') {S=i;break;}
  }
    for(int i = s.size()-1;i>=0;i--){
        if(s[i] == 'Z'){
            E = i;
            break;
        }
    }

    cout<<E-S+1<<endl;
    return 0;
}


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

const int INF = 1 << 25;
int to[100000];
int dist[100000];
int indeg[100000];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N, K;
	cin >> N >> K;
	for(int i = 0; i < N; i++){
		cin >> to[i];
		to[i]--;
		if(to[i] != -1) indeg[to[i]]++;
		dist[i] = INF;
	}

	queue<int> q;
	for(int i = 0; i < N; i++){
		if(indeg[i] == 0 && to[i] != -1){
			dist[i] = 0;
			q.push(i);
		}
	}

	while(q.size()){
		int v = q.front();
		q.pop();
		if(dist[v] == K - 1 || to[v] == -1) continue;
		if(dist[to[v]] == INF){
			dist[to[v]] = dist[v] + 1;
			q.push(to[v]);
		}
	}

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

Measured memory_bytes: 4464
from itertools import accumulate
from bisect import bisect

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

W = list(accumulate(W))

i = min(bisect(W, W[-1]/2), len(W)-1)
j = max(i-1, 0)
print(min(abs(W[-1]-2*W[i]), abs(W[-1]-2*W[j])))

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s

int di[] = { -1, 0, 0, 1 }; int dj[] = { 0, -1, 1, 0 };

int main()
{
	int w, h;
	typedef queue<pair<int, int>> que;

	while (cin >> w >> h, w)
	{
		int map[222][222];
		int way[222][222];
		REP(i, 222)REP(j, 222) way[i][j] = INF;
		REP(j, w) map[0][j] = 1;
		FOR(i, 1, 2 * h)
		{
			if (i % 2 == 1)
			{
				map[i][0] = 1;
				FOR(j, 1, w) cin >> map[i][j];
				map[i][w] = 1;
			}
			else
			{
				REP(j, w) cin >> map[i][j];
			}
		}
		REP(j, w) map[2 * h][j] = 1;
		que q;
		q.push(make_pair(0, 0));
		way[0][0] = 1;
		bool f = true;
		while (q.size())
		{
			int x = q.front().first; int y = q.front().second;
			q.pop();
			if (x == h - 1 && y == w - 1)
			{
				cout << way[x][y] << endl;
				f = false;
				break;
			}

			if (map[2 * x][y] == 0 && way[x - 1][y] == INF)
			{
				q.push(make_pair(x - 1, y));
				way[x - 1][y] = way[x][y] + 1;
			}
			if (map[2 * x + 2][y] == 0 && way[x + 1][y] == INF)
			{
				q.push(make_pair(x + 1, y));
				way[x + 1][y] = way[x][y] + 1;
			}
			if (map[2 * x + 1][y] == 0 && way[x][y - 1] == INF)
			{
				q.push(make_pair(x, y - 1));
				way[x][y - 1] = way[x][y] + 1;
			}
			if (map[2 * x + 1][y + 1] == 0 && way[x][y + 1] == INF)
			{
				q.push(make_pair(x, y + 1));
				way[x][y + 1] = way[x][y] + 1;
			}

		}
		if (f) cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 1460
N = int(input())
x = []
y = []
h = []
for _ in range(0, N):
	_x, _y, _h = map(int, input().split())
	x.append(_x)
	y.append(_y)
	h.append(_h)

nonzero = [i for i in range(0, N) if h[i] != 0]

for cx in range(0, 100+1):
	for cy in range(0, 100+1):
		H =  h[nonzero[0]] + abs(x[nonzero[0]] - cx) + abs(y[nonzero[0]] - cy)
		error = False
		for i in range(0, N):
			if h[i] != max([H - abs(x[i]-cx) - abs(y[i]-cy), 0]):
				error = True
				break
		if not error:
			print("{} {} {}".format(cx, cy, H))
			exit()

Measured memory_bytes: 3064
#include <iostream>
#include <string.h>
#include <map>

using namespace std;

int main() {
    char str[100000];
    cin >> str;

    // cout << str.length() << endl;

    map<char, int> mp;
    char i;
    for(i='a'; i<='z'; i++) {
        mp[i] = 0;
    }

    int j;
    
    for(j=0; j<strlen(str); j++) {
        mp[str[j]] += 1;
    }

    // cout << mp['a'] << endl;

    int flag=0;

    for(i='a'; i<='z'; i++) {
        if(mp[i]==0) {
            flag = 1;
            break;
        }
    }

    if(flag) cout << i << endl;
    else cout << "None" << endl;

    return 0;
    
}

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

#define ll long long int
ll mod=1e9+7;

int main()
{
    /* Faster input ouput */
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    /* To read input from a file and output to a file */
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    ll t = 1;
    // cin >> t;
    while(t--)
    {        
        ll n,i,j;
        cin >> n;
        ll arr[n];

        for(i=0;i<n;i++)
        {
            cin >> arr[i];
        }

        ll mtn = arr[0];
        ll stool = 0;
        for(i=1;i<n;i++)
        {
            if(arr[i] < mtn)
            {
                ll diff  = mtn-arr[i];
                stool += diff;
                arr[i] = mtn;
            }
            else
            {
                mtn = arr[i];
            }
        }
        cout << stool << '\n';
    }
    
    return 0;
}

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

using namespace std;

int main() {
	int n,m;
	cin>>n>>m;
	
	vector<int> v;
	int sum = 0;				
	for(int i = 0; i < m; i++) {
		int value;
		cin>>value;
		v.push_back(value);
		sum = sum + v[i];
	}
	if(n >= sum)
		cout<<n-sum;
	else
		cout<<-1;
	
		
	
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define all(v) v.begin(),v.end()
template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }

void solve() {
    ll X, K; cin >> X >> K;
    vector<ll> R(K + 1);
    R[0] = 0;
    rep(i, K) cin >> R[i + 1];

    auto clip = [&] (ll &a) {
        set_min(a, X);
        set_max(a, 0LL);
    };
    auto dir = [] (int k) { return k % 2 == 0 ? -1 : 1; };

    vector<ll> sum(K + 1);
    rep(k, K) sum[k + 1] = sum[k] + (k % 2 == 0 ? -1 : 1) * (R[k + 1] - R[k]);
    
    vector<ll> h(K + 1), l(K + 1); // 満杯状態でスタート
    vector<ll> ub(K + 1), lb(K + 1);
    // a <= ub[i] なら，R[i]までで上のパーツが満杯になる無駄な時間が生じない
    // a >  ub[i] なら，R[i]までのどこかで上のパーツが満杯になる
    //                  この時，a = X も必ず満杯になるのでR[i]以降では値がa = Xと一致しているはず
    h[0]  = X;  l[0] = 0;
    ub[0] = X; lb[0] = 0;
    rep(k, K) {
        ll d = (R[k + 1] - R[k]) * dir(k);
        
        h[k + 1] = h[k] + d;
        l[k + 1] = l[k] + d;
        if(dir(k) > 0) {
            ub[k + 1] = min(ub[k], ub[k] - (h[k] + d - X));
            lb[k + 1] = lb[k];
        } else {
            lb[k + 1] = max(lb[k], lb[k] + -(l[k] + d));
            ub[k + 1] = ub[k];
        }
        clip(h[k + 1]);  clip(l[k + 1]);
        clip(ub[k + 1]); clip(lb[k + 1]);
    }
    
    ll Q; cin >> Q;
    rep(q, Q) {
        ll t, a; cin >> t >> a;
        int k = upper_bound(all(R), t) - begin(R) - 1;
        assert(k >= 0);
        ll ans = 0;
        if(a >= ub[k])
            ans = h[k];
        else if(a <= lb[k])
            ans = l[k];
        else
            ans = a + sum[k];
        ans += (t - R[k]) * dir(k);
        clip(ans);
        cout << ans << endl;
    }
}

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


Measured memory_bytes: 5888
x, n = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
arr.append(n)
arr = set(arr)
a = 0
ans = 0
while True:
    if (x - a) not in arr:
        ans = x-a
        break
    if (x + a) not in arr:
        ans = x+a
        break
    a += 1
print(ans)


Measured memory_bytes: 9184
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }

double light[] = {35.5, 37.5, 40, 43, 50, 55, 70};
double heavy[] = {71, 77, 83, 89, 105, 116, 148};
string cls[] = {"AAA", "AA", "A", "B", "C", "D", "E"};


string comp(double a, double b)
{
	rep(i, 7)
		if(a < light[i] && b < heavy[i])
			return cls[i];
	
	return "NA";
}

int main()
{
    double a, b;
	while(cin >> a >> b)
		cout << comp(a, b) << endl;
}

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

const int N = 1E5 + 10;

int n, m;
int _pair[N], mod[N], a[N];

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    mod[a[i] % m]++;
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    int pt = i;
    while (a[pt] == a[i] && pt <= n) pt++;
    _pair[a[i] % m] += (pt - i) / 2;
    i = pt - 1;
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (i > m - i) break;
    int u = mod[i] - _pair[i] * 2, v = mod[m - i] - _pair[m - i] * 2;
    if (i == m - i || i == 0) {
      ans += _pair[i] + u / 2;
    } else {
      int mu = mod[i], mv = mod[m - i];
      if (u < v) swap(u, v), swap(mu, mv);
      ans += v + min(u - v, mv - v) + (mv - v - min(u - v, mv - v)) / 2 + (mu - u) / 2;
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1408
import java.io.*;
import java.util.*;
public class Main {
	
	static Node tree[];

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		int n=in.nextInt();
		tree=new Node[n]; for(int i=0;i<n;i++)tree[i]=new Node();
		
		for(int i=0;i<n;i++) {
			int id=Integer.parseInt(in.next()),l=Integer.parseInt(in.next()),r=Integer.parseInt(in.next());
			
			tree[id].left=l; tree[id].right=r;
			if(l!=-1)tree[l].parent=id;
			if(r!=-1)tree[r].parent=id;
		}
		
		PrintWriter out=new PrintWriter(System.out);
		for(int i=0;i<n;i++) {
			out.print("node "+i+": ");
			out.print("parent = "+tree[i].parent+", ");
			out.print("sibling = "+getSibling(i)+", ");
			out.print("degree = "+getDegree(i)+", ");
			out.print("depth = "+getDepth(i)+", ");
			out.print("height = "+getHeight(i,0)+", ");
			out.println(getType(i));
		}
		out.flush();
		
		
	}
	
	static int getSibling(int index) {
		int p=tree[index].parent;
		if(p==-1)return -1;
		else if(tree[p].left==index && tree[p].right!=-1)return tree[p].right;
		else if(tree[p].right==index && tree[p].left!=-1)return tree[p].left;
		else return -1;
	}
	
	static int getDegree(int index) {
		if(tree[index].left!=-1 && tree[index].right!=-1)return 2;
		else if(tree[index].left!=-1 || tree[index].right!=-1) return 1;
		else return 0;
	}
	
	static int getDepth(int index) {
		int d=0;
		while(tree[index].parent!=-1) {
			d++;
			index=tree[index].parent;
		}
		return d;
	}
	
	static int getHeight(int index,int h) {
		int h1=h,h2=h;
		if(tree[index].left!=-1)h1=getHeight(tree[index].left,h+1);
		if(tree[index].right!=-1)h2=getHeight(tree[index].right,h+1);
		return Math.max(h1, h2);
	}
	
	static String getType(int index) {
		if(tree[index].parent==-1)return "root";
		else if(tree[index].left==-1 && tree[index].right==-1)return "leaf";
		else return "internal node";
	}

}

class Node{
	int parent=-1,left=-1,right=-1;
}



Measured memory_bytes: 26488
n = int(input())
a = list(map(int,input().split()))

minus = []
plus = []

for i in a:
    if i < 0:
        minus.append(i)
    else:
        plus.append(i)
plus.sort()
minus.sort(reverse=True)

if len(plus)==0:
    if len(minus)%2==0:
        print(-sum(minus))
    else:
        print(-sum(minus)+2*minus[0])
    exit()

if len(minus)==0:
    print(sum(a))
    exit()

if len(minus) % 2==0:
    print(sum(plus) - sum(minus))
    exit()

if - minus[0] < plus[0]:
    print(sum(plus) - sum(minus) +2*minus[0])
else:
    print(sum(plus) - sum(minus) -2*plus[0])

Measured memory_bytes: 14412
#include <stdio.h>
#define N 100000
int partition(int *A,int p,int r){
    int x,i,j,t;
    x = A[r];
    i = p-1;
    for(j = p;j < r; j++){
        if(A[j] <= x){
            i++;
            t = A[i];
            A[i] = A[j];
            A[j] = t;
        }
    }
    t = A[i + 1];
    A[i + 1] = A[r];
    A[r] = t;
    return i + 1;
}

int main(){
    int i,q;
    int A[N],n;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    
    q = partition(A,0,n - 1);
    
    for(i=0;i<n;i++){
      if(i > 0) printf(" ");
      if(i == q) printf("[");
      printf("%d",A[i]);
      if(i == q) printf("]");
    }
    printf("\n");
  
  return 0;
}



Measured memory_bytes: 2172
/*
    Problem 66
    https://onlinejudge.u-aizu.ac.jp/problems/1127
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
/* class */
class DisjointSet {
public:
    vector<int> d;
    DisjointSet () {}
    DisjointSet (int len) { d.assign(len, -1); }

    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)];}
};
class Edge {
public:
    int u, v;
    double w;
    Edge () {}
    Edge (int u, int v, double w) : u(u), v(v), w(w) {}
    bool operator < (const Edge &e) const {
        return w < e.w;
    }
};
class Cube {
public:
    double x, y, z, r;
    Cube () {}
    Cube (double x, double y, double z, double r) :
    x(x), y(y), z(z), r(r) {}
};

/* global variables */
/* function */
void kruscal(DisjointSet ds, vector<Edge> edges) {
   // kruscal
    sort(edges.begin(), edges.end());
    double totalCost = 0.0;
    for (Edge e : edges)
        if (ds.unite(e.u, e.v))
            totalCost += e.w;
    cout << fixed << setprecision(3) << totalCost << '\n';
}
double dist(Cube c1, Cube c2) {
    double dx = c1.x - c2.x;
    double dy = c1.y - c2.y;
    double dz = c1.z - c2.z;
    return sqrt(dx * dx + dy * dy + dz * dz);
}
double calcDist(Cube c1, Cube c2) { return (dist(c1, c2) - (c1.r + c2.r)); }
void solve(int N) {
    vector<Cube> C(N, Cube());
    for (int i = 0; i < N; i++) {
        double x, y, z, r;
        cin >> x >> y >> z >> r;
        C[i] = Cube(x, y, z, r);
    }
    // if (球i, jが重なっている) 同じグループにいれる
    // else つなぐ可能性がある
    DisjointSet ds = DisjointSet(N);
    vector<Edge> edges;
    for (int i = 0; i < N - 1; i++) {
        for (int j = 0; j < N; j++) {
            double d = calcDist(C[i], C[j]);
            if (d <= 0) ds.unite(i, j);
            else edges.push_back(Edge(i, j, d));
        }
    }
    kruscal(ds, edges);
}
/* main */
int main(){
    while (1) {
        int N;
        cin >> N;
        if (N == 0) return 0;
        solve(N);
    }
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

// 3乗で通したお詫びにO(NlogN)で通します
// 参考 : https://twitter.com/SayakaAmemiya/status/1249515024541859842

template<int mod, int proot> struct NTT {
	int get_mod() { return mod; }
	int pow(int a, int b) {
	int res = 1;
		for (; b; b >>= 1) {
			if (b & 1) res = (int64_t) res * a % mod;
			a = (int64_t) a * a % mod;
		}
		return res;
	}
	int inv(int i) { return pow(i, mod - 2); }
	void ntt(std::vector<int> &a, bool inverse) {
		int n = a.size();
		assert((n & -n) == n);
		int h = pow(proot, (mod - 1) / n);
		if (inverse) h = inv(h);
		
		for (int i = 0, j = 1; j < n - 1; j++) {
			for (int k = n >> 1; k > (i ^= k); k >>= 1);
			if (j < i) std::swap(a[i], a[j]);
		}
		for (int i = 1; i < n; i <<= 1) {
			int base = pow(h, n / i / 2);
			int w = 1;
			
			std::vector<int> ws(i);
			for (int j = 0; j < i; j++) ws[j] = w, w = (int64_t) w * base % mod;
			
			for (int j = 0; j < n; j += i << 1) {
				for (int k = 0; k < i; k++) {
					int u = a[k + j];
					int d = (int64_t) a[k + j + i] * ws[k] % mod;
					a[k + j] = u + d >= mod ? u + d - mod : u + d;
					a[k + j + i] = d > u ? u + mod - d : u - d;
				}
			}
		}
		if (inverse) {
			int ninv = inv(a.size());
			for (auto &i : a) i = (int64_t) i * ninv % mod;
		}
	}
};

int main() {
	int n = ri();
	int back[3] = { 0 };
	int forward[3] = { 0 };
	std::vector<int> a(n);
	{
		char tmp[4096];
		scanf("%s", tmp);
		for (int i = 0; i < n; i++) {
			a[i] = tmp[i] == 'R' ? 0 : tmp[i] == 'G' ? 1 : 2;
			back[a[i]]++;
		}
	}
	
	int64_t res = 0;
	// j - i != k - jを無視したの
	for (int j = 0; j < n; j++) {
		back[a[j]]--;
		res += forward[(a[j] + 1) % 3] * back[(a[j] + 2) % 3];
		res += forward[(a[j] + 2) % 3] * back[(a[j] + 1) % 3];
		forward[a[j]]++;
	}
	// j - i == k - jで相異なるものを引く
	int n2 = 1;
	for (; n2 < n + n - 1; n2 <<= 1);
	NTT<40961, 3> ntt;
	std::vector<int> count[3];
	for (auto &i : count) i.resize(n2);
	for (int i = 0; i < n; i++) count[a[i]][i]++;
	for (auto &i : count) ntt.ntt(i, false);
	
	std::vector<int> conved[3]; // conved count[i], count[(i + 1) % 3]
	for (int i = 0; i < 3; i++) {
		auto &cur = conved[i];
		cur.resize(n2);
		for (int j = 0; j < n2; j++) cur[j] = (int64_t) count[i][j] * count[(i + 1) % 3][j] % 40961;
		ntt.ntt(cur, true);
	}
	for (int j = 0; j < n; j++) res -= conved[(a[j] + 1) % 3][j + j];
	
	printf("%" PRId64 "\n", res);
	
	return 0;
}


Measured memory_bytes: 3980