akhauriyash/Code-Regression huggingface dataset:
from sys import stdin
from copy import deepcopy
from functools import reduce
from fractions import gcd
import math
import itertools
from collections import Counter
from itertools import chain  ##list(chain.from_iterable(l)) ##flatten
from heapq import heappush, heappop
import bisect


"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) ## 横一列
A = [int(input()) for _ in range(N)] ## 縦一列
lst = [list(map(int,input().split())) for i in range(M)] ## 二次元
"""


N = int(input())
A = list(map(int,input().split()))
A.sort()

## 例外処理
if N == 1:
  print(1)
  exit()
elif N > 1 and A[0] == 1:
  if A[1] == 1:
    print(0)
    exit()
  else:
    print(1)
    exit()
elif A[0] == A[-1]:
  print(0)
  exit()


MAXINT = int(1e6)
#MAXINT = int(10)
lst = [False for _ in range(MAXINT+1)]
for i in range(N):
  lst[A[i]] = True

pre = 0
for i in range(N):
  #print(i, lst, pre)
  if lst[A[i]]:
    if A[i] == pre:
      lst[A[i]] = False
      continue
    else:
      pre = A[i]
      j = 2 * A[i]
      while j <= MAXINT:
        lst[j] = False
        j += A[i]
    #print(i, lst)

solver = [i for i in range(MAXINT+1) if lst[i]]
ans = len(solver)
print(ans)
#print(lst)

Measured memory_bytes: 170248
use proconio::input;
use proconio::marker::Usize1;

fn adjacency_list(n: usize, ab: &Vec<(usize, usize)>) -> Vec<Vec<usize>> {
    let mut e = vec![vec![]; n];
    for &(a, b) in ab.iter() {
        e[a].push(b);
        e[b].push(a);
    }
    e
}

fn shortest_path_spanning_tree(e: &Vec<Vec<usize>>, s: usize) -> Vec<usize> {
    let n = e.len();
    let inf = n;
    let mut d = vec![inf; n];
    let mut t = vec![n; n];
    let mut pq = std::collections::BinaryHeap::new();
    d[s] = 0;
    t[s] = s;
    pq.push(std::cmp::Reverse((0, s)));
    while let Some(std::cmp::Reverse((c_u, u))) = pq.pop() {
        for &v in e[u].iter() {
            let c_v = c_u + 1;
            if c_v < d[v] {
                d[v] = c_v;
                t[v] = u;
                pq.push(std::cmp::Reverse((c_v, v)));
            }
        }
    }
    t
}

fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(Usize1, Usize1); m],
    };

    let e = adjacency_list(n, &ab);
    let t = shortest_path_spanning_tree(&e, 0);

    println!("Yes");
    for &t_i in t.iter().skip(1) {
        let ans = t_i + 1;
        println!("{}", ans);
    }
}


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

const double EPS = 1e-8;

using namespace std;
struct Point{
    double x, y, z;
    Point () {}
    Point (double x, double y, double z) :
        x(x), y(y), z(z) {}
};
Point operator - (Point a, Point b){
    return Point(a.x - b.x, a.y - b.y, a.z - b.z);
}
Point operator * (double a, Point b){
    return Point(a * b.x, a * b.y, a * b.z);
}

double dot(Point a, Point b){
    return a.x * b.x + a.y * b.y + a.z * b.z;
}

double abs(Point a){
    return sqrt(dot(a, a));
}


bool is_cross(Point p, Point c, double r){
    bool in_target = (abs(c) < r + EPS);
    bool in_self = (abs(c - p) < r + EPS);
    if(in_self && in_target) return false;
    if(!in_self && in_target) return true;
    if(in_self && !in_target) return true;

    double k = dot(c, p) / dot(p, p);
    if(k < 0 || 1 < k) return false;

    return abs(c - k * p) < r + EPS;
}

int main(){
    int N, M, R;
    while(cin >> N >> M >> R && N){
        vector<Point> sp(N);
        vector<double> sr(N);
        vector<Point> tp(M);
        vector<double> tb(M);
        double ex, ey, ez;
        REP(i, N) cin >> sp[i].x >> sp[i].y >> sp[i].z >> sr[i];
        REP(i, M) cin >> tp[i].x >> tp[i].y >> tp[i].z >> tb[i];
        cin >> ex >> ey >> ez;
        REP(i, N){
            sp[i].x -= ex;
            sp[i].y -= ey;
            sp[i].z -= ez;
        }
        REP(i, M){
            tp[i].x -= ex;
            tp[i].y -= ey;
            tp[i].z -= ez;
        }

        vector<double> score(M);
        for(int i = 0; i < M; i++){
            score[i] = tb[i] / dot(tp[i], tp[i]);
        }

        vector<int> cross(N);
        for(int i = 0; i < N; i++){
            for(int j = 0; j < M; j++){
                if(is_cross(tp[j], sp[i], sr[i])){
                    cross[i] |= 1 << j;
                }
            }
        }

        double ans = 0;
        for(int s = (1 << M) - 1; s >= 0; s--){
            double score_sum = 0;
            for(int i = 0; i < M; i++)
                if(s >> i & 1)
                    score_sum += score[i];

            if(score_sum < ans) continue;

            int cost = 0;
            for(int i = 0; i < N; i++){
                if(cross[i] & s) cost++;
                if(cost > R) break;
            }

            if(cost <= R){
                ans = score_sum;
            }
        }
        
        printf("%.15f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1312
N = int(input())
A = list(map(int,input().split()))
ans = sum(map(abs,A))
flag = False
sign = 0
mi = 10 ** 9
for a in A:
    if a == 0:
        flag = True
        break
    if a < 0:
        sign += 1
    if abs(a) < mi: mi = abs(a)
if flag:
    print(ans)
else:
    if sign % 2 == 0:
        print(ans)
    else:
        print(ans-2*mi)

Measured memory_bytes: 14332
import sys
input = sys.stdin.readline
N, M, K = map(int, input().split())
mod = 998244353
class Factorial:
  def __init__(self, n, mod):
    self.f = [1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod

f = Factorial(N + M, mod)

dp = [0] * (N + 1)
dp[1] = M
for i in range(1, N):
  dp[i + 1] = dp[i] * (M - 1)
  dp[i + 1] %= mod
#print(dp)
res = 0
for i in range(K + 1):
  res += dp[N - i] * f.combi(N - 1, i) % mod
  res %= mod
print(res)

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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

int Q;
int a, b;

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(Q);
    while(Q--) {
        read(a), read(b);
        if(a > b) std::swap(a, b);

        if(a == 1 && b == 1) {
            puts("0");
            continue;
        }

        ll ans = 0;
        ll s = (ll) a * b - 1, r = std::max(0ll, (ll)sqrt(s) - 5);

        while((r + 1) * (r + 1) <= s) ++ r;

        ll t = s / r;
        ans = 2 * r - (t == r);

        printf("%lld\n", ans - (a <= r));
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>    // std::copy
#include <iterator>     // std::back_inserter
#include <set>
using namespace std;
 
int main(){
    int N ,Q;
    long long K;
    cin >> N >> K >> Q;

    vector<long long> A(N);
    for(int i = 0; i < Q ; i++){
        int ans;
        cin >> ans;
        ans--;
        A[ans]++;
    }

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

}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define inf std::numeric_limits<int>().max()

int main() {
	int n, k;
	cin >> n >> k;
	cout << (n/k) + (n % k > 0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

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

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

	double max_value = values[0];
	for (int i = 1; i < n; ++i) {
		max_value = (max_value + values[i]) / 2;
	}

	cout << setprecision(10) << max_value << "\n";

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int H,W;
    while (H!=0 || W!=0){
    cin >> H >> W;
    for (int i=0; i<H; i++){
        for (int j=0; j<W; j++){
            cout << '#' ;
        }
        cout << endl;
    }
    if (H!=0 || W!=0){
         cout << endl;
    }
    }
    return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
          
using namespace std;
          
#define ll long long
#define vi vector<int> 
#define pb push_back
#define sz(s) (int)s.size() 
#define all(v) v.begin(), v.end()
#define show(a) cerr << #a <<" -> "<< a <<"\n"
 
ll mn = 1000000, mx = -1000000000; 
ll cnt, cnt2, sum, x, y;
const int N = 1e5 + 5;
int n;
string s;
			             
int main (){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    cin >> s;
    if (sz(s) > n) {	
		for (int i = 0; i < n; i++) {
    		cout << s[i];
		}
		cout << "...";
	}
	else {
		cout << s;
	}
}

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

int main(){
    int N, A, B, C, D;
    string S;
    cin >> N >> A >> B >> C >> D;
    cin >> S;

    for(int i=min(A, B)-1; i<max(C, D)-2; i++){
        if(S[i] == '#' && S[i+1] == '#'){
            cout << "No" << endl;
            return 0;
        }
    }

    if((D > C && B > A) || (C > D && A > B)){
        cout << "Yes" << endl;
        return 0;
    }

    int r = max(A, B);
    int dest;
    if(r == B)
        dest = D;
    else
        dest = C;    
        
    bool flag = true;
    for(int i=r-1; i<dest; i++){
        if(S[i] == '#')
            continue;
        if(S[i-1] == '.' && S[i+1] == '.'){
            flag = false;
        }
    }

    if(flag){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 640
package main

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

func main() {
	sc := NewScanner()
	A, B := sc.NextInt(), sc.NextInt()

	ans := 0
	for i := 0; i < 2; i++ {
		if A < B {
			ans += B
			B--
		} else {
			ans += A
			A--
		}
	}
	fmt.Println(ans)
}
func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if ( A + B == C + D ) {
		cout << "Balanced" << endl;
	} else if ( A + B > C + D ) {
		cout << "Left" << endl;
	} else {
		cout << "Right" << endl;
	}
	return ( 0 );
}


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

int main(){
    long long N, K;
    cin >> N >> K;
    vector<pair<long long,long long> > a(N);
    for (int i=0; i<N; i++) {
        cin >> a.at(i).first >> a.at(i).second;
        //cout << a.at(i).first << " " << a.at(i).second << endl;
    }
    sort(a.begin(),a.end());
    long long sum=0;
    for (int i=0; i<N; i++) {
        sum+=a.at(i).second;
        if (sum>=K) {
            cout << a.at(i).first << endl;
            return 0;
        }
    }
} 

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

class Main{
    public static void main(String[] args){
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	Deque<Integer> stack = new ArrayDeque<Integer>();
	Deque<A> s_e_stack = new ArrayDeque<A>();
	
	int sum=0;
	
	try{
	    char[] line = br.readLine().toCharArray();
	    for(int i=0;i<line.length;i++){
		if(line[i] == '\\'){
		    stack.push(i);
		}else if(line[i] == '/'){
		    if(stack.isEmpty()){
			continue;
		    }
		    int st = stack.pop();
		    int en = i;
		    int ar = en-st;
		    sum+=ar;
		    
		    while(!s_e_stack.isEmpty() && s_e_stack.peek().start > st && s_e_stack.peek().end < en){
			A a;
			a = s_e_stack.pop();
			ar += a.area;
		    }
		    s_e_stack.push(new A(st,en,ar));
		}
	    }
	    
	    System.out.println(sum);
	    System.out.print(s_e_stack.size());
	    int n = s_e_stack.size();
	    for(int i=0;i<n;i++){
		System.out.print(" "+s_e_stack.getLast().area);
		s_e_stack.removeLast();
	    }
	    System.out.println();
	}catch(Exception e){
	    e.printStackTrace();
	}
    }
}

class A{
    int start;
    int end;
    int area;

    public A(int a, int b, int c){
	start = a;
	end = b;
	area = c;
    }
}



Measured memory_bytes: 26420
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define sz(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()

void solve (string s)
{
    int cnt = 0;
    int total = sz(s);
    for (char ch : s)
    {
        if (ch == 'S')
            cnt++;
        if (ch == 'T' && cnt > 0)
        {
            total -= 2;
            cnt--;
        }
    }

    cout << total << endl;
}

int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "w", stdout);
    #endif

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

    string n;
    while (cin >> n)
        solve(n);
}


Measured memory_bytes: 788
input = raw_input
a, b, c, k = map(int, input().split(" "))

ak = min(a, k)
out1 = ak
k = k-ak
bk = min(b, k)
out2 = 0
k = k-bk
ck = min(c, k)
out3 = -ck

out = out1 + out2 + out3
print(out)

Measured memory_bytes: 64208
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner (System.in);
		int a=in.nextInt();
		int b=in.nextInt();
                int c=in.nextInt();
                if(a+b==c || a+c==b || c+b==a){
                    System.out.println("Yes");
                }else{
                    System.out.println("No");
                }  
	}
}

Measured memory_bytes: 26984
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n,a;
    cin>>n;
    map<ll,ll> mp;
    rep(i,n){
        cin>>a;
        mp[a]++;
    }
    ll cnt=0;
    for(auto x:mp){
        if(x.second>=x.first) cnt+=x.second-x.first;
        else cnt+=x.second;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define all(v) v.begin(),v.end_()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define strep(it,v) for(it=v.begin();it!=v.end_();++it)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a);  a = (a * a);  b/=2;  }  return res; }
#define rs resize
long long readLI(){  register char c;  for(c = getchar(); !(c>='0' && c<='9'); c = getchar());  register long long a=c-'0';
    for(c = getchar(); c>='0' && c<='9'; c = getchar())
        a = (a<<3)+(a<<1)+c-'0';
    return a;
}
const ll N = 100011;
string a,b="";
int i;
int main()
{
   std::ios_base::sync_with_stdio(false); cin.tie(NULL);
   cin>>a;
   for(i = 0;i<a.length();i+=2)
    b = b + a[i];
   cout<<b;
   return 0;
}


Measured memory_bytes: 656
using System;
namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            string first, second;
            while((first = Console.ReadLine()) != null) {
                int hit = 0, blow = 0;
                first = string.Join("", first.Split());
                second = string.Join("", Console.ReadLine().Split());
                for(int i=0; i < first.Length; ++i) {
                    hit += first[i] == second[i] ? 1 : 0;
                    blow += first.Contains(second[i].ToString()) ? 1 : 0;
                }
                blow -= hit;
                Console.WriteLine("{0} {1}", hit, blow);
            }
        }
    }
}

Measured memory_bytes: 6232
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	vector<int> m,M,z;
	bool fm = false,fM = false,fz = false;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i] > 0){
			fM = true;
			M.push_back(a[i]);
		}
		if(a[i] < 0){
			fm = true;
			m.push_back(a[i]);
		}
		if(a[i]==0){
			fz = true;
			z.push_back(0);
		}
	}
	sort(a.begin(),a.end());
	vector<mp> b(n-1);
	if(fz){
	    	int  i = 0;
		for(i = 0;i<z.size()-1;i++){
			b[i] = mp(0,0); 
		}
		if(fM&&fm){
			for(int j = 0;j<M.size();j++){
				b[i] = mp(m[0],M[j]);
				i++;
				m[0]-=M[j];
			}
			int sum =0;
			for(int j=0;j<m.size();j++){
				b[i] = mp(sum,m[j]);
				i++;
				sum-=m[j];
			}
		}else if(fm){
		    	int sum = 0;
			for(int j=0;j<m.size();j++){
				b[i] = mp(sum,m[j]);
				i++;
				sum-=m[j];
			}
		}else if(fM){
			int sum = 0;
			for(int j=0;j<M.size()-1;j++){
				b[i] = mp(sum,M[j] );
				sum -= M[j];
				i++;
			}
			b[n-2] = mp(M[M.size()-1],sum);
		}

		cout<<b[n-2].first-b[n-2].second<<endl;
		for(int i=0;i<n-1;i++){
			cout<<b[i].first<<' '<<b[i].second<<endl;
		}
	    return 0;
	}
	//cout<<"ok"<<endl;
	if(fM&&fm){
		int i=0;
		//cout<<m.size()<<' '<<M.size()<<endl;
		for(int j=0;j<M.size()-1;j++){
		   // 	cout<<j<<endl;
			b[i] = mp(m[0],M[j]);
			//cout<<j<<endl;
			i++;
			m[0]-=M[j];
			//cout<<i<<endl;
		}
		for(int j=0;j<m.size();j++){
			b[i] = mp(M[M.size()-1],m[j]);
			i++;
			//cout<<i<<endl;
			M[M.size()-1]-=m[j];
		}

	}else if(fM){
		int i=0;
		sort(M.begin(),M.end());
		for(int j=1;j<M.size()-1;j++){
			b[i] = mp(M[0],M[j]);
			M[0]-=M[j];
			i++;
		}
		b[i] = mp(M[M.size()-1],M[0]);
	}else if(fm){
		sort(m.begin(),m.end());
		int i=0;
		for(int j=0;j<m.size()-1;j++){
			b[i] = mp(m[m.size()-1],m[j]);
			i++;
			//cout<<i<<endl;
			m[m.size()-1] -=m[j];
		}
	}
	//cout<<"ok"<<endl;
	cout<<b[n-2].first-b[n-2].second<<endl;
	for(int i=0;i<n-1;i++){
		cout<<b[i].first<<' '<<b[i].second<<endl;
	}

	return 0;
}


Measured memory_bytes: 4344
#include<stdio.h>

int c=1;
int vi[100000]={0};
int list[100000][1000];
int ll[100000]={0};
int ty=-1,tty[100000],tc=1000;
int tanff(int v){
	int i,f=0;
	vi[v]=c;
	if(v==ty){
		for(i=0;i<tc;i++){
			if(vi[tty[i]]==0){
				tanff(tty[i]);
			}
		}
	}else{
	for(i=0;i<ll[v];i++){
		if(vi[list[v][i]]==0){
			tanff(list[v][i]);
		}
	}}
	return 1;
}

int main(){
	int n,m,i,j;
	int xyz[3];
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d%d%d",&xyz[0],&xyz[1],&xyz[2]);
		xyz[0]--;
		xyz[1]--;
		if(ll[xyz[0]]==1000){
			for(j=0;j<1000;j++){
		tty[j]=list[xyz[0]][j];
			}
			ty=xyz[0];
			ll[xyz[0]]=0;
		}
		if(ty==xyz[0]){
			tty[tc++]=xyz[1];
		}else list[xyz[0]][ll[xyz[0]]++]=xyz[1];
		if(ty==xyz[1]){
			tty[tc++]=xyz[0];
		}else list[xyz[1]][ll[xyz[1]]++]=xyz[0];
	}
	int tmp=0;
		for(i=0;i<n;i++){
			if(vi[i]==0){
				tanff(i);
				c++;
			}
		}
	printf("%d\n",c-1);
	return 0;
}

Measured memory_bytes: 394624
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var line1 = ReadLine();
            var line2 = ReadLine();

            bool flag = true;
            for (int i = 0; i < line1.Length; i++)
            {
                if (line1[i] != line2[2 - i]) flag = false;
            }
            WriteLine(flag ? "YES" : "NO");
        }
    }
}



Measured memory_bytes: 11092
#include<stdio.h>

int main(){
	unsigned long long int a,b,tempa,tempb,divi=1;
	unsigned long long int grecomdivi = 0,leacommul = 0;
	
	while(scanf("%lld %lld",&a,&b) != EOF){
		tempa=a;
		tempb=b;
		divi=1;
		
		while(divi != 0){
			divi = tempa%tempb;
			if(divi == 0)break;
			tempa = tempb;
			tempb=divi;
		}
		grecomdivi = tempb;
		leacommul = (a*b/grecomdivi);
			
		printf("%lld %lld\n",grecomdivi,leacommul);
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int H, W;
char g[128][128];
int dy[] = {-1,0,1,0}, dx[] = {0,-1,0,1};

void dfs(int y, int x, char f){
  g[y][x] = '.';
  rep(d, 4){
    int ny = y+dy[d], nx = x+dx[d];
    if(ny < 0 || ny >= H || nx < 0 || nx >= W || g[ny][nx] != f) continue;
    dfs(ny, nx, f);
  }
  return;
}

int main(){
  while(scanf("%d%d", &H, &W) && H+W){
    rep(i, H) scanf("%s", g[i]);
    
    int res = 0;
    rep(i, H) rep(j, W){
      if(g[i][j] == '.') continue;
      dfs(i, j, g[i][j]);
      res++;
    }
    
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 1672
import Data.Bool
import qualified Data.ByteString.Char8 as C

main = sol . C.reverse <$> C.getLine >>= putStrLn . (bool "NO" "YES")

sol s
  | C.null s                = True
  | ts!!0 `C.isPrefixOf` s  = sol $ C.drop (C.length (ts!!0)) s
  | ts!!1 `C.isPrefixOf` s  = sol $ C.drop (C.length (ts!!1)) s 
  | ts!!2 `C.isPrefixOf` s  = sol $ C.drop (C.length (ts!!2)) s
  | ts!!3 `C.isPrefixOf` s  = sol $ C.drop (C.length (ts!!3)) s
  | otherwise               = False

ts = (C.reverse . C.pack) <$> ["dream","dreamer","erase","eraser"]

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

int main(void) {
  ll X, Y;
  cin >> X >> Y;

  if(X % Y == 0) cout << -1 << endl;
  else cout << X * (Y - 1) << endl;
}


Measured memory_bytes: 256
n=int(input())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
dp=[]
for i in range(n):
    dp.append([0]*3)
    
dp[n-1][0]=l[n-1][0]
dp[n-1][1]=l[n-1][1]
dp[n-1][2]=l[n-1][2]
for i in range(n-2,-1,-1):

    dp[i][0]=l[i][0]+max(dp[i+1][1],dp[i+1][2])
    dp[i][1]=l[i][1]+max(dp[i+1][0],dp[i+1][2])
    dp[i][2]=l[i][2]+max(dp[i+1][1],dp[i+1][0])
print(max(max(dp[0][0],dp[0][1]),dp[0][2]))
    


Measured memory_bytes: 47384
require 'complex'

n, d = gets.chomp.split(' ').map{|v| v.to_i}

points = []
n.times {
    points.push(gets.chomp.split(' ').map{|v| v.to_i})
}

count = 0

(n-1).times {|i|
    first_points = points[i]
    ((i+1)...n).each {|j|
        second_points = points[j]
        #p '---------'
        #p first_points
        #p second_points

        sum = 0
        d.times {|k|
            sum += (first_points[k] - second_points[k]) ** 2
        }

        #    p Math.sqrt(sum)
        count += 1 if Math.sqrt(sum).to_s =~ /^[0-9]+(.0+)?$/
    }
}

puts count


Measured memory_bytes: 1916
n = int(input())
ln = list(str(n))
from collections import Counter
nc = dict(Counter(ln))
s = 0
if n != 0:
    for i in range(1, 10):
        if str(i) in nc:
            s += i * nc[str(i)]
if s % 9 == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 80388
#include <iostream>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int result = 0;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        while (x % 2 == 0) {
            x /= 2;
            result++;
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a;
    scanf("%d", &a);
    a = a % 10;
    if (a == 2 || a == 4 || a == 5 || a == 7 || a == 9)
    {
      printf("hon\n");
    }
    else if (a == 0 || a == 1 || a == 6 || a == 8)
    {
      printf("pon\n");
    }
    else 
    {
      printf("bon\n");
    }
    return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <cstdio>
using namespace std;
int n, k, dp[1 << 21][21], f0[1 << 21], f1[1 << 21];
int main() {
	// freopen("input", "r", stdin);
	scanf("%d%d", &n, &k);
	for(int i = 0; i <= n; i ++) {
		static char s[1 << 21]; scanf("%s", s);
		for(int j = 0; j < (1 << i); j ++) if(s[j] == '1') dp[j | (1 << i)][i] = 1;
	}
	for(int i = 1; i < (1 << (n + 1)); i ++) {
		bool t = 0; f0[i] = f1[i] = -1;
		for(int j = n; j >= 0; j --) {
			bool c = i >> j & 1;
			if(!t) t |= c;
			else {
				if(c && -1 == f1[i]) f1[i] = j;
				if(!c && -1 == f0[i]) f0[i] = j; 
			}
		}
	}
	int ans = 0, len = -1;
	for(int i = (1 << (n + 1)) - 1; i >= 1; i --) {
		int l = 0;
		for(int j = n; j >= 0; j --) if(i >> j & 1) { l = j; break ; }
		for(int j = l; j >= 0; j --) if(dp[i][j]) {
			int t = i & ((1 << j) - 1), s = (i ^ (1 << l)) >> j;
			if(j) dp[s | (1 << (l - j))][0] += dp[i][j];
			int p0 = f0[t | (1 << j)], p1 = f1[t | (1 << j)];
			if(~ p0) dp[(s << (p0 + 1)) | (t & ((1 << p0) - 1)) | (1 << (l - j + p0 + 1))][p0] += dp[i][j];
			if(~ p1) dp[(s << (p1 + 1)) | (1 << p1) | (t & ((1 << p1) - 1)) | (1 << (l - j + p1 + 1))][p1] += dp[i][j];
		}
		if(dp[i][0] >= k && (l > len || (l == len && ans > i))) ans = i, len = l;
	}
	for(int i = n; i >= 0; i --) if(ans >> i & 1) {
		for(int j = i - 1; j >= 0; j --) {
			putchar('0' + (ans >> j & 1));
		}
		break ;
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 190720
S = input()
cnt = []
c = S[0]
tmp = 0
for i in range(len(S)):
	if S[i] == c:
		tmp += 1
	else:
		cnt.append(tmp)
		c = S[i]
		tmp = 1
cnt.append(tmp)

cnt_S, cnt_T = 0,0
delete = 0
if S[0] != 'S':
	cnt.pop(0)
cnt_S = cnt[0]
for i in range(1,len(cnt),2):
	if cnt_S >= cnt[i]:
		cnt_S -= cnt[i]
		delete += cnt[i]*2
	else:
		delete += cnt_S*2
		cnt_S = 0

	if i+1 >= len(cnt):
		break

	cnt_S += cnt[i+1]

print(len(S)-delete)


Measured memory_bytes: 4328
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    string S;
    cin >> S;
    int ans = 0;
    char pre = S[0];
    FOR (i, 1, S.size()) {
        if (S[i] != pre) {
            pre = S[i];
            ans++;
        }
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  
  const int nmmax = 50;
  
  char A[nmmax][nmmax],B[nmmax][nmmax];
  
  for(int y=0;y<n;y++){
    for(int x=0;x<n;x++){
      cin >> A[y][x];
    }
  }
  
  for(int y=0;y<m;++y){
    for(int x=0;x<m;++x){
      cin >> B[y][x];
    }
  }
  
  bool exist = false;
  
  for(int ly=0;ly<n;ly++){
    for(int lx=0;lx<n;++lx){
      if(ly+m-1>=n || lx+m-1>=n) continue;
      
      bool match = true;
      for(int y=0;y<m;y++){
        for(int x=0;x<m;++x){
          if(A[ly+y][lx+x]!=B[y][x]) {
            match = false;
            break;
          }
        }
      if(match == false)break;
      }
      
      if(match) exist = true;
    }
  }
  
  if(exist)cout << "Yes" << endl;
  else cout << "No" << endl;
  
}


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

const ll MOD = 1e9+7;
const int INF = (int)1e9+7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

ll dp[101][100001];

int main(){
    ll N,W;
    cin >> N >> W;
    ll w,v;
    rep(i,N){
        rep(j,100001){
            dp[i][j] = INF;
        }
    }
    cin >> w >> v;
    dp[0][v] = w;

    cout << endl;
    for(int i=1; i<N; i++){
        cin >> w >> v;
        dp[i][v] = w;
        rep(j,100001){
            if(j-v>=0) dp[i][j] = min({dp[i][j], dp[i-1][j], dp[i-1][j-v]+w});
            else dp[i][j] = min(dp[i][j], dp[i-1][j]);
        }
    }

    ll ans = 0;
    for(ll j=0; j<100001; j++){
        if(dp[N-1][j]<=W){
            ans = max(ans, j);
        }
    }
    cout << ans;
    
    
    return 0;
}


Measured memory_bytes: 78336
//
// Created by 李青坪 on 2018/11/6.
//

#include <cstdio>
#include <algorithm>
#include <set>
#define MAXN 100
#define INFINITY 1<<20
#define NIL -1
using namespace std;

int n;
int sum;
int graph[MAXN][MAXN];
int d[MAXN];
int parent[MAXN];
set<int> T;
set<int> V_T;

void init(){
    fill(d, d+n, INFINITY);
    fill(parent, parent+n, NIL);
    T.insert(0);
    for (int i = 1; i < n; ++i) {
        V_T.insert(i);
    }
    for (int j = 0; j < n; ++j) {
        d[j] = graph[0][j];
    }
}

void updateMinWeight(){

}

pair<int, pair<int, int> > findMinEdge(){
    int min = INFINITY;
    pair<int, int> r;
    set<int >::iterator itr;
    for (itr = T.begin(); itr != T.end(); itr++){
        for (set<int>::iterator itr1 = V_T.begin(); itr1 != V_T.end(); itr1++){
            if (graph[*itr][*itr1] < min){
                min = graph[*itr][*itr1];
                r = make_pair(*itr, *itr1);
            }
        }
    }
    return make_pair(min, r);
}

void findMinSpanTree(){
    while (!V_T.empty()){
        pair<int, pair<int, int> > v = findMinEdge();
        sum += v.first;
        parent[v.second.second] = v.second.first;
        T.insert(v.second.second);
        V_T.erase(V_T.find(v.second.second));
    }
}

int main(){
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int w;
        for (int j = 0; j < n; ++j) {
            scanf("%d", &w);
            if (w == -1) graph[i][j] = INFINITY;
            else graph[i][j] = w;
        }
    }
    init();
    findMinSpanTree();
    printf("%d\n", sum);
}
/*
5
 -1 2 3 1 -1
 2 -1 -1 4 -1
 3 -1 -1 1 1
 1 4 1 -1 3
 -1 -1 1 3 -1
 */


Measured memory_bytes: 2844
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

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

	int x = n % 10;
	if (x == 3)
		cout << "bon" << endl;
	else if (x == 0 || x == 1 || x == 6 || x == 8)
		cout << "pon" << endl;
	else
		cout << "hon" << endl;
}



Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int h[200000],dp[200000];
int min_cost(int x)
{
	if(x==1)
		return 0;
	if(x==2)
		return abs(h[2]-h[1]);
	if(dp[x]==-1)
	{
		dp[x] = min(min_cost(x-1)+abs(h[x]-h[x-1]) , min_cost(x-2)+abs(h[x]-h[x-2]));
	}
	return dp[x];
}

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

	for (int i = 1; i <= n; ++i)
	{
		dp[i] = -1;
		cin>>h[i];
	}
	cout<<min_cost(n)<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
map<int,int>m;
void primeFactors(int n)
{
    // Print the number of 2s that divide n
    while (n % 2 == 0)
    {
        m[2]++;
        n = n/2;
    }

    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            m[i]++;
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        m[n]++;
}

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   primeFactors(n);
   int ans=0;
   for(auto it=m.begin();it!=m.end();it++)
   {
       int x=it->S;
       int c=1;int cnt=0;
       while(x >= c)
       {
           x-=c;
           cnt++;
           c++;
       }
       ans+=cnt;

   }
   cout<<ans<<endl;
}


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

int main() {
  int a, b; cin>>a>>b;
  if (a>=b) rep(i, a) cout<<b;
  else rep(i, b) cout<<a;
  cout<<endl;
}

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

typedef struct{
	int no;
	int score;
	int rank;
}team;

int main(){
	team t[100];
	int a=0;
	while(1){
		scanf(" %d,%d", &t[a].no, &t[a].score);
		if(t[a].no==0 && t[a].score==0) break;
		a++;
	}
	
	for(int i=0; i<a; ++i){
		for(int j=i; j<a; ++j){
			if(t[i].score < t[j].score) swap(t[i], t[j]);		
		}
	}

	
	int now=1, sc=t[0].score;
	t[0].rank=now;
	for(int i=1 ;i<a; ++i){
		if(t[i].score==sc) t[i].rank=now;
		else{
			++now;
			t[i].rank=now;
			sc=t[i].score;
		}
	}

	//for(int i=0; i<a; ++i) printf("%d: %d, rank=%d\n", t[i].no, t[i].score, t[i].rank);
	
	int x;
	while(cin >> x){
		for(int i=0; i<a; ++i){	
			if(x == t[i].no){
				printf("%d\n", t[i].rank);
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d;cin>>a>>b>>c>>d;
    while(true){
        c-=b;
        if(c<=0){
            cout<<"Yes"<<endl;
            break;
        }
        a-=d;
        if(a<=0){
            cout<<"No"<<endl;
            break;
        }
    }
}


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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n,i;
	cin>>n;
	long long int a[n],b[n];

	long long int x=0;
	for(i=0;i<n;i++)
		{cin>>a[i];x=x^a[i];}

	for(i=0;i<n;i++)
	{
		b[i]=a[i]^x;
	}	

	for(i=0;i<n;i++)
		cout<<b[i]<<" ";
	
	

	return 0;
}


Measured memory_bytes: 6772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
inline int read(){
	int x=0,w=1;
	char ch=0;
	while (ch<'0' || ch>'9'){
		ch=getchar();
		if (ch=='-') w=-1;	
	}
	while (ch<='9' && ch>='0'){
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	return x*w;
}
int a,b,c,ans=0;
int main(){
	a=read(),b=read(),c=read();
	ans=b+min(a+b,c);
	if (c>a+b) ++ans;
	printf("%d\n",ans);
	return 0;
}

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

int main(){
	int n,m;
	cin>>n>>m;
	int arr[10];
	memset(arr,-1,sizeof(arr));
	int mx = 0;
	for(int i=0; i<m; i++){
		int a,b;
		cin>>a>>b;
		if(arr[a]!=-1 && arr[a]!=b){
			cout<<-1;
			return 0;
		}
		arr[a] = b;
		mx = max(mx,a);
	}
	bool exist = false;
	for(int i=1; i<=n; i++){
		if(arr[i]>0) exist = true;
	}
	if(mx>n) cout<<-1;
	if(arr[1]==0){
		if(exist || n>1) cout<<-1;
		else cout<<0;
		return 0;
	}
	else{
		
		if(arr[1]==-1){
			if(n==1) arr[1] = 0;
			else arr[1] = 1;
		}
		for(int i=1; i<=n; i++){
			if(arr[i]==-1) cout<<0;
			else cout<<arr[i];
		}
	}
}

Measured memory_bytes: 3632
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <tuple>
#include <list>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cstring>
#include <cstdlib>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

#define xx first
#define yy second
#define $1 first
#define $2 second

void solveCase() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	ll x; cin >> x;
	cout << (x / 500) * 1000 + ((x % 500) / 5) * 5;
}

int main() {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	solveCase();
}

Measured memory_bytes: 256
#include<stdio.h>



main()
{
	int sum;
	int i;
	char buf[1001];
	
	do{
		i=0;
		sum=0;
		
		scanf("%s",buf);
		
		if(buf[0]=='0'){
			break;
		}
		
		while(buf[i]!='\0'){
			if('0' <= buf[i] && buf[i]<='9'){
				sum += (buf[i] - '0');
			}
			i++;
		}
		printf("%ld\n",sum);
	}while(1);
	
	return 0;
}

Measured memory_bytes: 536
#include <algorithm>
#include <cstdio>

using namespace std ;

typedef long long LL ;
const int N=1e6+10 ;

LL a[N] , b[N] ;
int n ;

int main ()
{
	int i ;
	scanf("%d",&n);
	for ( i=1 ; i<=n ; i++ ) 
		scanf("%lld",a+i);
	for ( i=1 ; i<=n ; i++ ) 
		scanf("%lld",b+i);
	LL A=0 , B=0 ;
	for ( i=1 ; i<=n ; i++ )
		if ( a[i]>b[i] ) A+=a[i]-b[i];
		else B+=(b[i]-a[i])>>1;
	if ( A<=B ) puts("Yes");
	else puts("No");
	return 0 ;
}

Measured memory_bytes: 2304
#define M 99999
T[M+1],t[M/2];main(i,j,m,a,b,p,q){
for(i=2;i<=M;i++)if(!T[i])for(j=i*2;j<=M;j+=i)T[j]=1;
for(i=2,j=0;i<=M;i++)if(!T[i])t[j++]=i;
for(;scanf("%d%d%d",&m,&a,&b),m;printf("%d %d\n",p,q)){
	for(;;m--)for(i=0;t[i]*t[i]<=m;i++){
			p=t[i],q=m/t[i];
			if(p*q!=m||T[q])continue;
			if(/*p<=q&&*/a*q<=b*p)goto E;
	}
E:;}
exit(0);}

Measured memory_bytes: 1028
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
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
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	m := scanInt()
	g := make([][]int, n)
	for i := 0; i < m; i++ {
		a, b := scanInt()-1, scanInt()-1
		g[a] = append(g[a], b)
	}

	var dfs func(u, v int, arr []int)
	t := 0
	ts := make([]int, n)
	var ans []int
	dfs = func(u, v int, arr []int) {
		if len(arr) != 0 && u == v {
			ans = make([]int, len(arr))
			copy(ans, arr)
			return
		}
		for _, to := range g[u] {
			if ts[to] == t {
				continue
			}
			ts[to] = t
			dfs(to, v, append(arr, to))
		}
	}

	for i := 0; i < n; i++ {
		t++
		dfs(i, i, []int{})
	}

	if len(ans) == 0 {
		fmt.Fprintln(wr, -1)
		return
	}

	for {
		f := make([]bool, n)
		idx := map[int]int{}
		for i := 0; i < len(ans); i++ {
			f[ans[i]] = true
			idx[ans[i]] = i
		}
		a, b := -1, -1
	L:
		for i := 0; i < len(ans); i++ {
			for _, v := range g[ans[i]] {
				if f[v] && v != ans[(i+1)%len(ans)] {
					a, b = i, idx[v]
					break L
				}
			}
		}
		if b == -1 {
			fmt.Fprintln(wr, len(ans))
			for i := 0; i < len(ans); i++ {
				fmt.Fprintln(wr, ans[i]+1)
			}
			return
		}
		if a > b {
			ans = ans[b : a+1]
		} else {
			ans = append(ans[:a+1], ans[b:]...)
		}
	}
}


Measured memory_bytes: 5504
S = input()
s = []
for i in range(4):
    s.append(int(S[i]))
op0 = '+'
op1 = '-'
if s[0] + s[1] + s[2] + s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op0, s[1], op0, s[2], op0, s[3]))
elif s[0] + s[1] + s[2] - s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op0, s[1], op0, s[2], op1, s[3]))
elif s[0] + s[1] - s[2] + s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op0, s[1], op1, s[2], op0, s[3]))
elif s[0] + s[1] - s[2] - s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op0, s[1], op1, s[2], op1, s[3]))
elif s[0] - s[1] + s[2] + s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op1, s[1], op0, s[2], op0, s[3]))
elif s[0] - s[1] + s[2] - s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op1, s[1], op0, s[2], op1, s[3]))
elif s[0] - s[1] - s[2] + s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op1, s[1], op1, s[2], op0, s[3]))
elif s[0] - s[1] - s[2] - s[3] == 7:
    print('{}{}{}{}{}{}{}=7'.format(s[0], op1, s[1], op1, s[2], op1, s[3]))


Measured memory_bytes: 38384
N, M, Q = map(int, input().split())
ptn = []
for i in range(Q):
    a,b,c,d = map(int, input().split())
    ptn.append([a-1,b-1,c,d])
mx = 0
def calc(arr):
    if len(arr) == N:
        global mx
        tot = 0
        #print(arr)
        #print(ptn)
        for i in range(Q):
            if arr[ptn[i][1]] - arr[ptn[i][0]] == ptn[i][2]:
                tot += ptn[i][3]
        mx = max(mx, tot)
        return
    for i in range(1,M+1):
        if i < arr[-1]: continue
        calc(arr+[i])
for i in range(1,M+1):
    calc([i])
print(mx)


Measured memory_bytes: 74272
#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)
int main(){
  int a,b,e;cin>>a>>b;
  vector<long long int>c(a+1,0);
  vector<bool>d(a,true);
  rep(i,b){
    cin>>e;
    d[e]=false;
  }
  c[0]=1;
  c[1]=1;
  for(int i=2;i<a+1;i++){
    if(d[i-1])c[i]+=c[i-1];
    if(d[i-2])c[i]+=c[i-2];
    c[i]%=1000000007;
  }
  cout<<c[a];
  }


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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &v : a) cin >> v;
    sort(a.begin(), a.end());
    cout << unique(a.begin(), a.end()) - a.begin() << endl;
}

Measured memory_bytes: 256
n, a, b, c, d = map(int, input().split())

s = input()

if c < d:
    for i in range(b, d):
        if s[i:i+2] == "##":
            print(('No'))
            exit()
    for i in range(a, c):
        if s[i:i+2] == "##":
            print(('No'))
            exit()
    print('Yes')
else:
    for i in range(b, d):
        if s[i:i+2] == "##":
            print(('No'))
            exit()
    for i in range(a, c):
        if s[i:i+2] == "##":
            print(('No'))
            exit()
    for i in range(b-2, d-1):
        if s[i:i+3] == "...":
            print(('Yes'))
            exit()
    print('No')


Measured memory_bytes: 3572