akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 900010

ll inv[N], fact[N], ifact[N];
 
void init_fact(ll n = N){
    inv[1] = 1;
    for(int i = 2; i < n; i++) inv[i] = inv[mod%i] * (mod - mod/i) % mod;
	fact[0] = ifact[0] = 1;
	for(int i = 1; i < n; i++){
		fact[i] = (fact[i-1]*i)%mod;
		ifact[i]=(ifact[i-1]*inv[i])%mod;
	}
}

ll comb(ll a, ll b){
	return fact[a+b]*ifact[a]%mod*ifact[b]%mod;
}

ll comb_nk(ll n, ll k){
	return comb(n-k, k);
}

ll lcm(ll a, ll b){
    return a/__gcd(a, b)*b;
}

ll lambda(ll m){
    ll res = 1;
    if(m%8==0) m /= 2;
    for(ll i = 2; i*i <= m; i++){
        if(!(m%i)){
            ll r = i-1;
            m /= i;
            while(!(m%i)){
                m /= i;
                r *= i;
            }
            res = lcm(res, r);
        }
    }
    if(m>1) res = lcm(res, m-1);
    return res;
}

ll tot(ll m){
	ll res = 1;
	for(ll i = 2; i*i <= m; i++){
		if(!(m%i)){
			res *= i-1;
			m /= i;
			while(!m%i){
				m /= i;
				res *= i;
			}
		}
	}
	if(m>1) res *= m-1;
	return res;
}

ll pow_mod(ll a, ll r, ll m){
	ll x = 1;
	while(r){
		if(r&1) (x*=a)%=m;
		(a*=a)%=m;
		r>>=1;
	}
	return x;
}

int main(){
	ll n, m, k;
	cin>>n>>m>>k;
	n--;
	init_fact();
	ll res = 0, s = 1;
	rep(i, m+k+1){
		ll r = comb(n, i);
		(r*=pow_mod(3, m+k-i, mod))%=mod;
		(res+=r*s)%=mod;
		(s*=2)%=mod;
		if(i>=m)	s -= comb(m, i-m);
		if(i>=k) s -= comb(i-k, k);
	}
	(res+=mod)%=mod;
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 21376
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func mmin(a []int) int {
	r := int(1e10)
	for i := range a {
		r = min(r, a[i])
	}
	return r
}
func mmax(a []int) int {
	r := -int(1e10)
	for i := range a {
		r = max(r, a[i])
	}
	return r
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	a := make([]int, n)
	for i := range a {
		a[i] = nextInt(sc)
	}
	// sort.Ints(a)
	q := nextInt(sc)
	ans := make([]int, q)
	for i := 0; i < q; i++ {
		c := nextInt(sc)
		b := nextInt(sc)
		e := nextInt(sc)
		if c == 0 {
			ans[i] = mmin(a[b:e])
		} else {
			ans[i] = mmax(a[b:e])
		}
	}
	wtr := bufio.NewWriter(os.Stdout)
	for i := range ans {
		fmt.Fprintf(wtr, "%d\n", ans[i])
	}
	wtr.Flush()
}



Measured memory_bytes: 1148
/*input
1
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}

void solve(){
	ll i,j,k;
	ll n;
	cin>>n;
	ll ans=0;
	rep(i,2,sqrt(n)+1){
		if(!(n%i)){
			j=i;
			while(!(n%j)){
				n/=j;
				ans++;
				j*=i;
			}
			while(!(n%i))n/=i;
		}
	}
	if(n>1)ans++;
	cout<<ans<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}




Measured memory_bytes: 3688
r, c = gets.chomp.split(/\s/).map(&:to_i)
array = []

r.times do
  tmp = gets.chomp.split(/\s/).map(&:to_i)
  tmp << tmp.inject(:+)
  array << tmp
end

array.each do |row|
  puts row.join("\s")
end

puts array.transpose.map{ |column| column.inject(:+) }.join("\s")

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

using namespace std;

int main() {
  string s;
  cin >> s;

  int ans = 0, a = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'R')
      a++;
    else
      a = 0;
    ans = max(ans, a);
  }
  cout << ans << '\n';
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;

void run_case()
{
    int a;
    string s;
    cin >> a;
    cin >> s;
    if (a >= 3200)
        cout << s << "\n";
    else
        cout << "red\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3640
H, W = map(int, input().split())
S = ['.' * (W + 2)] + ['.' + input() + '.' for _ in range(H)] + ['.' * (W + 2)]

N = [(0, 1), (1, 0), (1, 1), (0, -1), (-1, 0), (1, -1), (-1, 1), (-1, -1)]
ans = [[] for _ in range(H)]
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if S[h][w] == '.':
            ans[h - 1].append(sum([S[h + n[0]][w + n[1]] == '#' for n in N]))
        else:
            ans[h - 1].append('#')

for h in range(H):
    print(''.join(map(str, ans[h])))


Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int A1, A2, A3;

  std::cin >> A1 >> A2 >> A3;

  std::cout << (A1 + A2 + A3 >= 22 ? "bust" : "win") << std::endl;
    
  return 0;
}


Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
const int N=1005;
char mp[N][N],s[N][N];int n,m;
int main(){
	scanf("%d%d",&n,&m);
	fp(i,1,n)scanf("%s",mp[i]+1);
	fp(i,1,n)fp(j,1,m)s[i][j]=mp[i][j];
	fp(i,1,n)s[i][1]='#';for(R int i=1;i<=n;i+=2)fp(j,1,m-1)s[i][j]='#';
	fp(i,1,n){
		fp(j,1,m)putchar(s[i][j]);
		putchar('\n');
	}
	putchar('\n');
	fp(i,1,n)fp(j,1,m)s[i][j]=mp[i][j];
	fp(i,1,n)s[i][m]='#';for(R int i=2;i<=n;i+=2)fp(j,2,m)s[i][j]='#';
	fp(i,1,n){
		fp(j,1,m)putchar(s[i][j]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
using namespace std;
int main() {
  int h,n;
  cin>>h>>n;
  int sum=0;
  for(int i=0;i<n;i++) {
    int a;
    cin>>a;
    sum=sum+a;
  }
  if(sum>=h){
    cout<<"Yes";}
  else {cout<<"No";}
} 

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

int div_cnt(int a){
    int cnt=0;
    do {
        a/=2;
        ++cnt;
    } while (a!=0 && a%2==0);
    return cnt;
}

int main(){
    int n,ans=0,c=0,d=0;
    cin >> n;
    if(n==1){
        cout << 1 << endl;
        return 0;
    }
    for(int i=1;i<=n;++i){
        if(i%2==0){
        c=div_cnt(i);
            if(c>=d) {
                d=c;
                ans=i;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//	-*- mode: C++ -*-
// Counting Sort
//	Counting sort can be used for sorting elements in an array which each of the n input elements is an integer in the range 0 to k. The idea of counting sort is to determine, for each input element x, the number of elements less than x as C[x]. This information can be used to place element x directly into its position in the output array B. This scheme must be modified to handle the situation in which several elements have the same value. Please see the following pseudocode for the detail:
//
//	Counting-Sort(A, B, k)
//	1    for i = 0 to k
//	2        do C[i] = 0
//	3    for j = 1 to length[A]
//	4        do C[A[j]] = C[A[j]]+1
//	5    /* C[i] now contains the number of elements equal to i */
//	6    for i = 1 to k
//	7    do C[i] = C[i] + C[i-1]
//	8    /* C[i] now contains the number of elements less than or equal to i */
//	9    for j = length[A] downto 1
//	10       do B[C[A[j]]] = A[j]
//	11          C[A[j]] = C[A[j]]-1
//	Write a program which sorts elements of given array ascending order based on the counting sort.
//
// Input
//	The first line of the input includes an integer n, the number of elements in the sequence.
//
//	In the second line, n elements of the sequence are given separated by spaces characters.
//
// Output
//	Print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character.
//
// Constraints
//	1 ≤ n ≤ 2,000,000
//	0 ≤ A[i] ≤ 10,000
// Sample Input 1
//	7
//	2 5 1 3 2 3 0
// Sample Output 1
//	0 1 2 2 3 3 5

#include <iostream>
#include <vector>

class CA
{
public:
	CA(){}
	~CA(){}
	void	Sort();

private:
	const unsigned int	maxValue	{10000};
	unsigned int	n	{0};
	std::vector<unsigned int>	A;
	std::vector<unsigned int>	C;

	void	CountingSort();
};

void	CA::Sort()
{
	std::cin >> n;

	for(unsigned int i = 0; i < n; i++){
		unsigned int	Ai	{0};
		std::cin >> Ai;
		A.push_back(Ai);
	}

	CountingSort();
}

void	CA::CountingSort()
{
	for(unsigned int i = 0; i < maxValue + 1; i++){
		C.push_back(0);
	}

	for(unsigned int j = 0; j < n; j++){
		C[A[j]]++;
	}

	for(unsigned int i = 0; i < maxValue; i++){
		C[i + 1]	+= C[i];
	}

	std::vector<unsigned int>	B(n + 1);

	for(int j = n - 1; j >= 0; j--){
		B[C[A[j]]]	= A[j];
		C[A[j]]--;
	
	}
	#if 1
	for(unsigned int i = 1; i < n + 1; i++){
		std::cout << B[i];
		if(i < n){
			std::cout << ' ';
		}
	}

	std::cout << std::endl;
	#endif
}

int	main()
{
	CA	ca;

	ca.Sort();
}



Measured memory_bytes: 18584
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int x,n;
  cin>>x>>n;
  vector<int> p(n);
  rep(i,n)
    cin>>p.at(i);
  sort(all(p));
  int mini=101;
  int ans=0;
  
  for(int i=-1;i<=201;i++){
    if(find(all(p),i) != p.end()) continue;
    int a=max(i-x,x-i);
    if(a<mini){
      mini=a;
      ans=i;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3552
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double


#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define int ll
const ll mod =1e9+7;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll maxn = 400000+10;


int32_t main()
{

   IOS
   int n,k;
   cin>>n>>k;
   int ans = n;
   if(n>=k){
     n = n%k;
     ans = min(ans,abs(k-n));
   }
   else{
     n = (abs(n-k));
     ans = min(n,ans);
     n = n%k;
     ans= min(n,ans);
   }
   cout<<min(n,ans)<<endl;
}

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

int main(){
  int a, b;

  cin >> a >> b;

  int ans = 0;
  for (int i = a; i <= b; i++) {
    string s = to_string(i);
    string t = to_string(i);
    reverse(t.begin(), t.end());
    if (s == t) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main() {
	long long n, k, total = 0;
	cin >> n >> k;
	
	vector<long long> h(n);
	
	for (long long i = 0; i < n; i++) cin >> h[i];
	sort(h.begin(), h.end());
	
	for (long long i = 0; i < n - k; i++) {
		total += h[i];
	}
	
	cout << total;
	
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        System.out.println((a * b) + " " + (a * 2 + b * 2));
    }
}

Measured memory_bytes: 17156
n,k=map(int,input().split())
A=[int(input()) for i in range(n)]

def track_num(n):
    cnt,track=0,1
    for i in A:
        if cnt+i>n:
            track +=1
            cnt=i
        else:
            cnt +=i
    return track

def Binaryserch():
    left,right=max(A),sum(A)+1
    ans=0
    while left<right:
        mid=(left+right)//2
        track=track_num(mid)
        if track<=k:
            ans=mid
            right=mid
        elif track>k:
            left=mid+1
    return ans

print(Binaryserch())



Measured memory_bytes: 9576
def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

a, b, c = l_in()

if a == b and b == c:
    print("No")
elif a == b or a == c or b == c:
    print("Yes")
else:
    print("No")


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

#define F(i, a, b) for(int i=a; i<b; i++)
#define mem(arr, val) memset(arr, val, sizeof(arr))
#define rev(a) reverse(a.begin(), a.end())
#define UPPER(a) transform(a.begin(), a.end(), a.begin(), ::toupper)
#define LOWER(a) transform(a.begin(), a.end(), a.begin(), ::tolower)
#define INF 1000000000000001
#define epsilon 1e-15

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

ll p = 1000000007;
const int MAX = 500001;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    int N, X, T;
    cin >> N >> X >> T;
    cout << ((N+X-1)/X) * T;

    return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String weather = sc.next();

        switch(weather){
            case "Sunny":
                System.out.println("Cloudy");
                break;
            case "Cloudy":
                System.out.println("Rainy");
                break;
            case "Rainy":
                System.out.println("Sunny");
                break;
        }
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, k; cin >> n >> k;
    vll a(n); rep(i, n) cin >> a[i];
    sort(all(a));

    ll l = -inf, r = inf;
    while (l + 1 < r) {
        ll cnt = 0;
        ll M = (l + r) / 2;

        rep(i, n) {
            ll l = i, r = n;
            while (l + 1 < r) {
                ll m = (l + r) / 2;
                if (a[i] * a[m] <= M) {
                    a[i] > 0 ? l = m : r = m;
                } else {
                    a[i] > 0 ? r = m : l = m;
                }
            }
            if (a[i] > 0) cnt += l - i;
            else cnt += n - r;
        }

        (cnt < k) ? l = M : r = M;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 1792
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  V<ll> pac(100010,0);

  ll sum=0;
  rep(i,0,n){
    ll x;cin>>x;
    pac[x]++;
    sum+=x;
  }

  int qq;cin>>qq;
  while(qq--){
    ll b,c;cin>>b>>c;
    sum+=pac[b]*(c-b);
    pac[c]+=pac[b];
    pac[b]=0;
    cout<<sum<<ENDL;
  }


}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

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

int main(){
string S;
  cin>>S;
  
  int ans=999;
  for(int i=0; i<S.size()-2; i++){
   int num=(S[i]-'0')*100+(S[i+1]-'0')*10+(S[i+2]-'0'); // S[i]から文字'0'を引いてint型に
   ans=min(ans, abs(num-753));                          // 入れることで数字にできる
  }
  
  cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
#define PI 3.14159265358979323846264338327950L
typedef unsigned long long uint64;
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<int>d(n);
  int ans = 0;
  rep(i,n){
    cin >> d[i];
  }
  for(int i = 0; i<n;i++){
    for(int j= i+1; j<n;j++){
      ans += d[i]*d[j];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
import java.util.*;

public class Main {
	int cnt, min;
	int[][] cost;
	
	void check(int[] perm){
		int sum = 0;
		for(int i=0;i<cnt-1;i++) sum += cost[perm[i]][perm[i+1]];
		min = Math.min(min, sum);
	}
	
	void makeperm(int k, int[] perm, boolean[] flag){
		if(k==cnt){
			check(perm);
		}else{
			for(int i=1;i<cnt;i++){
				if(flag[i]==true) continue;
				perm[k] = i;
				flag[i] = true;
				makeperm(k+1, perm, flag);
				flag[i] = false;
			}
		}
	}
	
	void solve(){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int w = sc.nextInt();
			int h = sc.nextInt();
			if(w==0 && h==0) break;
			
			char[][] map = new char[h][w];
			int[] x = new int[11];
			int[] y = new int[11];
			cnt = 1;
			for(int i=0;i<h;i++){
				String s = sc.next();
				for(int j=0;j<w;j++){
					char t = s.charAt(j);
					if(t=='o'){
						x[0] = j;
						y[0] = i;
					}else if(t=='*'){
						x[cnt] = j;
						y[cnt] = i;
						cnt++;
					}
					map[i][j] = t;
				}
			}
			
			cost = new int[cnt][cnt];
			int[] xx = new int[]{0,0,1,-1};
			int[] yy = new int[]{1,-1,0,0};
			boolean f = false;
			for(int i=0;i<cnt;i++){
				for(int j=i+1;j<cnt;j++){
					ArrayDeque<Integer> p = new ArrayDeque<Integer>();
					ArrayDeque<Integer> q = new ArrayDeque<Integer>();
					int[][] c = new int[h][w];
					for(int s=0;s<h;s++){
						for(int t=0;t<w;t++) c[s][t] = Integer.MAX_VALUE;
					}
					
					p.offer(x[i]);
					q.offer(y[i]);
					c[y[i]][x[i]] = 0;
					while(p.size()!=0){
						int u = p.poll();
						int v = q.poll();
						if(u==x[j] && v==y[j]) break;
						
						for(int s=0;s<4;s++){
							if(0<=u+xx[s] && u+xx[s]<w && 0<=v+yy[s] && v+yy[s]<h){
								if(map[v+yy[s]][u+xx[s]]!='x' && c[v][u]+1<c[v+yy[s]][u+xx[s]]){
									p.offer(u+xx[s]);
									q.offer(v+yy[s]);
									c[v+yy[s]][u+xx[s]] = c[v][u]+1;
								}
							}
						}
					}
					
					if(c[y[j]][x[j]]==Integer.MAX_VALUE){
						f = true;
						break;
					}
					cost[i][j] = cost[j][i] = c[y[j]][x[j]];
				}
				if(f==true) break;
			}
			
			if(f==false){
				min = Integer.MAX_VALUE;
				makeperm(1, new int[cnt], new boolean[cnt]);
				System.out.println(min);
			}else{
				System.out.println(-1);
			}
		}	
	}
		
	
	public static void main(String[] args) {
		new Main().solve();
	}	
}

Measured memory_bytes: 41976
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long LLINF = 1LL<<60;
const int INF = 1e9;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

class UnionFind {
public:
    ll S;
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
    // Constructor
    UnionFind(ll n){
    	rep(i,n){
    		par.push_back(i); // 初期では親は自分自身
    		siz.push_back(1);
    	}
        S = n;
    }
 
    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }
 
    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
        S--;
        return true;
    }
 
    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }
 
    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
	ll allsize() {return S;}
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,m; cin >> n >> m;
    UnionFind tree(n);
    vector<pair<ll,ll>> v(m);
    rep(i,m) {
        ll a, b;cin >>a >> b;
        a--; b--;
        v[i] = {a,b};
    }
    reverse(ALL(v));
    ll cnt = n*(n-1)/2;
    vector<ll> ans = {cnt};

    rep(i,m) {
        if(tree.issame(v[i].first,v[i].second)) ans.push_back(cnt);
        else {
            cnt = cnt - tree.size(v[i].first)*tree.size(v[i].second);
            ans.push_back(cnt);
        }
        tree.merge(v[i].first,v[i].second);
    }
    reverse(ALL(ans));
    REP(i,1,m+1) cout << ans[i] << endl;



    return 0;
}

Measured memory_bytes: 5356
/******************************************
* AUTHOR : SOMU KUMAR *
* INSTITUTION : IIT BHUBANESWAR *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
int dp[10*N];
void solve(){
	for(int i=1;i<=10*N;i++){
		for(int j=1;j*i<=10*N;j++){
			dp[j*i]++;
		}
	}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//code here...............//
int n;
cin>>n;
solve();
int ans=0;
for(int i=1;i<=n-1;i++){
	ans+=dp[i];
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 7552
from collections import defaultdict
n = int(input())
counter = defaultdict(int)

for i in range(1, n+1):
    t = str(i)
    counter[(t[0], t[-1])] += 1

ans = 0
for i in range(1, n+1):
    t = str(i)
    ans += counter[(t[-1], t[0])]
print(ans)




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

// Dinic
struct MaxFlow {
	struct edge { int v, r; long long c; };

	vector<vector<edge>> g;
	vector<int> d, it;

	MaxFlow(int n) : g(n), d(n), it(n) {}

	void add(int u, int v, long long c) {
		int i = g[u].size(), j = g[v].size();
		g[u].push_back({ v, j, c });
		g[v].push_back({ u, i, 0 });
	}

	long long max_flow(int s, int t) {
		long long res = 0;
		while (bfs(s, t)) {
			long long f;
			while ((f = dfs(s, t, 1e18)) > 0) res += f;
		}
		return res;
	}

	bool bfs(int s, int t) {
		fill(it.begin(), it.end(), 0);
		fill(d.begin(), d.end(), -1);
		d[s] = 0;
		queue<int> q({ s });
		while (!q.empty()) {
			int v = q.front(); q.pop();
			for (edge e : g[v]) if (e.c > 0 && d[e.v] == -1) {
				d[e.v] = d[v] + 1;
				q.push(e.v);
			}
		}
		return d[t] >= 0;
	}

	long long dfs(int v, int t, long long f) {
		if (v == t) return f;
		while (it[v] < g[v].size()) {
			edge &e = g[v][it[v]++];
			if (e.c > 0 && d[v] < d[e.v]) {
				long long ff = dfs(e.v, t, min(f, e.c));
				if (ff > 0) {
					e.c -= ff;
					g[e.v][e.r].c += ff;
					return ff;
				}
			}
		}
		return 0;
	}
};

char g[111][111];

int main() {
	int h, w;
	cin >> h >> w;

	for (int i = 0; i < h; i++) {
		scanf("%s", &g[i + 1][1]);
	}
	h += 2;
	w += 2;

	MaxFlow mf(h * w * 2 + 2);
	int s = h * w * 2;
	int t = s + 1;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int in = i * w + j;
			int out = i * w + j + h * w;
			if (g[i][j] == 0) {
				mf.add(out, t, 1e9);
				mf.add(in, out, 1e9);
			} else if (g[i][j] == 'X') {
				mf.add(s, in, 1e9);
				mf.add(in, out, 1e9);
			} else {
				mf.add(in, out, 1);
			}

			for (int k = 0; k < 4; k++) {
				int ny = i + (k - 2) % 2;
				int nx = j + (k - 1) % 2;
				if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
				mf.add(out, ny * w + nx, 1e9);
			}
		}
	}

	int ans = mf.max_flow(s, t);
	if (ans >= 1e8) ans = -1;
	cout << ans << endl;
}

Measured memory_bytes: 3964
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

static const int MAX = 1000000;

int func(int n){
    if( n % 2 == 0 ) return n/2;
    else return 3 * n + 1;
    return 0;
}

int main(){
    int t;
    vector<int> v;
    cin >> t;
    v.push_back(t);
    while(1){
        t = func(t);
        if(*lower_bound(v.begin(), v.end(), t) == t ){
            break;
        }
        v.push_back(t);
        sort(v.begin(), v.end());
    }
    cout << v.size() + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
	int n; cin>>n;
  	set<int> s;
  	
    rep(i,n){
    	int t; cin >> t;
      	s.insert(t);
    }
  	
  	if((n-s.size())%2){
    	cout << s.size()-1;
    }else{
    	cout << s.size();
    } 
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int a,b;
  cin>>a>>b;
  cout<<a*b/__gcd(a,b)<<endl;


}

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

int main(){
    int n;
    cin >> n;
    vector<int> b(n+1,1e9);
    for(int i=1;i<n;i++)cin >> b[i];
    int ans=0;
    for(int i=0;i<n;i++){
        ans+=min(b[i],b[i+1]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll r, d, x2000;
    cin >> r >> d >> x2000;
    ll x = x2000;
    REP(i, 10)
    {
        x = r * x - d;
        cout << x << endl;
    }
    return 0;
}


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

using namespace std;

int main(){

	int x, y, a, b, c;
	vector<int> p, q, r, v;
	long long int ps=0, qs=0, ans = 0;

	cin>> x >> y >> a >> b >> c;
	p.resize(a);
	q.resize(b);
	r.resize(c);
	for (int i = 0;i<a;i++) cin >> p[i];
	for (int i = 0;i<b;i++) cin >> q[i];
	for (int i = 0;i<c;i++) cin >> r[i];

	sort(p.begin(), p.end(), greater<int>());
	sort(q.begin(), q.end(), greater<int>());
	sort(r.begin(), r.end(), greater<int>());

	for (int i = 0;i < x;i++) v.emplace_back(p[i]);
	for (int i = 0;i < y;i++) v.emplace_back(q[i]);
	for (int i = 0;i < min(c, x + y);i++) v.emplace_back(r[i]);

	sort(v.begin(), v.end(), greater<int>());

	for (int i = 0;i < x+y;i++) ans+=v[i];

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3572
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import static java.util.Collections.sort;

/**
 */
class Main {
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);

		List<Integer> ints = new ArrayList<Integer>();
		for(int i=0;i<5;i++) ints.add(in.nextInt());

		sort(ints);
		for(int i=ints.size()-1;i>=0;i--) {
			System.out.print(ints.get(i));
			if(i!=0) System.out.print(" ");
		}
		System.out.println("");
	}

}

Measured memory_bytes: 26076
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

    set<int> d;
    for (auto i = 0; i < n; i++) {
        int tmp; cin >> tmp;
        d.insert(tmp);
    }

    cout << d.size() << endl;
    return 0;
}

Measured memory_bytes: 3576
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;sc.hasNext();) {
			int n = sc.nextInt();
			long sp[] = new long[n+1];
			sp[0] = 1;
			for(int i=1;i<=n;i++) {
				sp[i] = sp[i-1]+i;
			}
			System.out.println(sp[n]);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
#include <stdio.h>

int main(void){
 
    int w,h,x,y,r;
    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
    
    if (x >= r && y >= r && x<= (w-r) && y<=(h-r)) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 2112
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#define ll long long
using namespace std;
int a[100050];
int n,x,y;
bool judge(ll mid)
{
    ll cot=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]-y*mid>0)
        {
            int k=a[i]-y*mid;
            if(k%(x-y)==0) cot+=k/(x-y);
            else cot+=k/(x-y)+1;
        }
    }
    if(cot<=mid) return true;
    else return false;
}
int main()
{

    scanf("%d%d%d",&n,&x,&y);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    ll l=0,r=1000000000;
    while(l<r)
    {
        ll mid=(l+r)/2;
        if(judge(mid))
        {
            r=mid;
        }
        else l=mid+1;
    }
    printf("%lld\n",r);
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
map<int,int>cnt;
int main(){
    //~ freopen("file.in", "r", stdin);
    int n;
    scanf("%d",&n);
    while(n--){
		int x;
		scanf("%d",&x);
		cnt[x]++;
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int x;
		scanf("%d",&x);
		if(!cnt[x])
			return puts("NO")*0;
		cnt[x]--;	
	}puts("YES");
	return 0;
}


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

int main(void) {
  int k;
  string s;
  cin >> k;
  cin >> s;
  if ((int)s.size() > k) {
    cout << s.substr(0,k) << "..." << endl;
  } else {
    cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
import math
import random # ランダムな配列の生成用

cnt  = 0

def quick_sort(arr):
    """ クイックソート 
    """
    global cnt

    if len(arr) < 2:
        # 1. 走査する配列長が0か１の場合戻る。
        return arr

    # 2. 走査する範囲の中央の要素をピボットとして選ぶ。
    pivot = math.floor(len(arr)/2)
    pivot_height = arr[pivot]
    left, right = 0, len(arr) - 1

    while(left < right):
        # 3. ピボットと比べ、大きい要素は左へ小さい要素は右へ交換する。
        while(arr[left] < pivot_height):
            # 左側の基準値より大きい位置まで移動
            left += 1
        while(arr[right] > pivot_height):
            # 右側の基準値より小さい位置まで移動
            right -= 1

        if (left < right):
            # leftがrightを超えていない場合、leftとrightを交換
            cnt += 1
            arr[left], arr[right] = arr[right], arr[left]
        else:
            break
    # 4. 左右２つに配列を分割してこの関数を再帰的に繰り返す。
    arr[:left] = quick_sort(arr[:left])      # ピボットの左側をクイックソート
    arr[left+1:] = quick_sort(arr[left+1:])  # ピボットの右側をクイックソート
    return arr


if __name__ == "__main__":
    s=input()	
    li = list(map(int,input().split()))	
    # 長さ10のランダムな配列

    dst = quick_sort(li)
    
    if cnt < 2:
      print("YES")
    else:
      print("NO")

Measured memory_bytes: 4208
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

ll g[114514]   = {};
ll cnt[114514] = {};
int main() {
	IOS();
	ll n, m;
	cin >> n >> m;
	vector<ll> a(n);
	map<ll, ll> mp;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		g[a[i] % m]++;
		mp[a[i]]++;
	}
	for (auto it = mp.begin(); it != mp.end(); it++) {
		cnt[it->first % m] += it->second / 2;
	}
	ll ans = g[0] / 2;
	for (int i = 1; i * 2 < m; i++) {
		ll tmp = min(g[i], g[m - i]);
		ans += tmp;
		if (g[i] >= g[m - i]) {
			ans += min(cnt[i], (g[i] - tmp) / 2);
		} else {
			ans += min(cnt[m - i], (g[m - i] - tmp) / 2);
		}
	}
	if (m % 2 == 0) ans += g[m / 2] / 2;
	dump(ans);
	return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
int a[200100];
int main(){
  int n,x,y;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x>>y;
    a[x+y]++;
  }
  for(int i=0;i<200100;i++)
    if(a[i]>1){
      a[i+1]+=a[i]/2;
      a[i]=a[i]%2?1:0;
    }
  for(int i=0;i<200100;i++)
    if(a[i])cout<<i<<' '<<0<<endl;
}

Measured memory_bytes: 3724
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		
		Scanner sc = new Scanner(System.in);
		int intX = -1;
		int i = 0;

		while(intX != 0){
			intX = sc.nextInt();

			if(intX == 0 ){
				break;
			}

			i++;

			System.out.println("Case " + i + ": " + intX);
		}
	}
}

Measured memory_bytes: 42092
import math
posx = 0
posy = 0
s = math.radians(90)

while True:
    lst = list(map(int, input().split(",")))
    if lst == [0, 0]:
        break
    
    n = lst[0]
    movex = n* math.cos(s)
    movey = n* math.sin(s)

    posx = posx + movex
    posy = posy + movey

    s = s - math.radians(lst[1])

print(int(posx))
print(int(posy))


Measured memory_bytes: 5720
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(long long i = a; i < (b); ++i)
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<int>P(N);
    rep(i,0, N){
        cin >> P[i];
    }
    ll ans = 0;
    rep(i, 0, N-1){
        if(P[i] == i+1){
            swap(P[i], P[i+1]);
            ans++;
        }
    }
    if(P[N-1] == N){
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define debug(x) cout << #x << ": " << x << endl
using ll = long long;

#define int ll

//**********

signed main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    int ans = 0;
    
    if(k==0) ans = n*n;
    else{
    FOR(i,k+1,n+1){
        ans += int(n/i) * (i-k);
        if (n%i - k + 1 > 0) ans += n%i - k + 1;
    }
    }
    printf("%lld\n",ans);
    
    return 0;
    
}







Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;


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

	cin >> N >> M >> K;
	while (N) {
		int box = 0;
		N -= M;
		while (box<K) {
			N += M;
			if (N == 1) {
				continue;
			}
			bool flag = true;
			for (int i = 2; i*i <= N; i++) {
				if (N%i == 0) {
					flag = false;
					break;
				}
			}
			if (flag) {
				box++;
			}
		}
		cout << N << endl;
		cin >> N >> M >> K;
	}
	return 0;
}

Measured memory_bytes: 3016
_n = gets.to_i
slimes = gets.split.map(&:to_i)
need_to_change = 0
previous = slimes.shift
slimes.each do |current|
  if previous == current
    need_to_change += 1
    current = slimes.max + 1
  end
  previous = current
end
puts need_to_change


Measured memory_bytes: 1788
#include <bits/stdc++.h>
//#include <boost/array.hpp>
//#include <boost/range/numeric.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/multiprecision/cpp_int.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
//using namespace boost::multiprecision;

constexpr long long INF = LLONG_MAX;
constexpr long long MOD = 1000000007;
constexpr long double PI = M_PI;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define CALL(x) x.cbegin(),x.cend()
#define RALL(x) x.rbegin(),x.rend()
#define CRALL(x) x.crbegin(),x.crend()

#define cout cout << fixed << setprecision(12)
#define dbglf cerr << '\n'

#define ACCM(arr) accumulate(ALL(arr),0LL)
#define Yes(ex) cout << ((ex) ? "Yes" : "No") << endl
#define YES(ex) cout << ((ex) ? "YES" : "NO") << endl

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void veccin(vector<T>& v) {
    for (auto && e : v) { cin >> e; }
}

template < typename T >
inline void dbg(T a) { cerr << a << ' '; }

ll n, m, k;
ll ans = 0, sum = 0, cnt = 0;
//ld d;
string s/*1, s2, s3*/;
char c/*1, c2, c3*/;
bool flag = false;

/*--------------------template--------------------*/

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

    cin >> n >> m >> k;
	ans = floor(n*(m-1)/m)-n*floor((m-1)/m);
	sum = floor(n*k/m)-n*floor(k/m);
    cout << (m>k?sum:ans) << endl;
}


Measured memory_bytes: 3652
a,b,c=[int(i) for i in input().split()]
def ans(m):
    print((m-a)//2+(m-b)//2+(m-c)//2+((m-a)%2+(m-b)%2+(m-c)%2)//2)
ans(max(a,b,c) if sum([a,b,c])%2==max(a,b,c)*3%2 else max(a,b,c)+1)

Measured memory_bytes: 38384
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    let n = read_i64() as usize;
    let s = read_line();
    let mut xs = vec![0; n];
    let mut ys = vec![0; n];
    let mut t = 0;
    for (i,c) in s.bytes().enumerate() {
        if c == 'W' as u8 {
            t += 1;
        }
        xs[i] = t;
    }
    t = 0;
    for (i,c) in s.bytes().enumerate().rev() {
        if c == 'E' as u8 {
            t += 1;
        }
        ys[i] = t;
    }
    let mut res = n;
    for i in 0..n {
        let mut u = 0;
        if 1 <= i {
            u += xs[i-1];
        }
        if i < n-1 {
            u += ys[i+1];
        }
        res = min(res, u);
    }
    println!("{}", res);
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec_i64<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


Measured memory_bytes: 12540
#include <iostream>
using namespace std;
int main(void){
  char str[4];
  for(int i = 0; 4 > i; i++) cin >> str[i];
  if(str[2] == str[1]){
    if(str[2] == str[3] || str[2] == str[0]){
      cout << "Yes" << endl;
    } else { 
      cout << "No" << endl;
    }
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(),a.end());
    int ans = (a[2]-a[1])/2 + (a[2]-a[0])/2;
    if((a[2]-a[1])&1 && (a[2]-a[0])&1){ans += 1;}
    else if((a[2]-a[1])&1 || (a[2]-a[0])&1){ans += 2;}
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 256