akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;

#define A first
#define B second

const ll MAXN = 2e5+5;

ll ans = 0, tot = 0;

ll n, y[MAXN];
vector<ll> g[MAXN];
pii a[MAXN][2];
string s;
map<pii, ll> m;
map<pii, ll> z;

void dfsdown(ll v, ll f = -1) {
	y[v] = s[v];

	a[v][0] = pii(0, v);
	for (ll u : g[v]) {
		if (u == f)
			continue;
		dfsdown(u, v);

		y[v] += y[u];
		z[pii(v, u)] = y[u];
		z[pii(u, v)] = tot - y[u];

		pii t = a[u][0];
		t.B = u;
		t.A++;
		m[pii(v, u)] = t.A;

		if (t > a[v][0]) {
			a[v][1] = a[v][0];
			a[v][0] = t;
		} else if (t > a[v][1])
			a[v][1] = t;
	}
}

void dfsup(ll v, ll f = -1) {
	for (ll u : g[v]) {
		if (u == f)
			continue;

		pii t;
		if (a[v][0].B == u)
			t = a[v][1];
		else
			t = a[v][0];
		t.A++;
		t.B = v;
		m[pii(u, v)] = t.A;

		if (t > a[u][0]) {
			a[u][1] = a[u][0];
			a[u][0] = t;
		} else if (t > a[u][1])
			a[u][1] = t;

		dfsup(u, v);
	}
}

int main() {
	cin >> n;
	for (ll i = 0; i < n-1; ++i) {
		ll a, b;
		cin >> a >> b;
		a--; b--;

		g[a].push_back(b);
		g[b].push_back(a);
	}

	cin >> s;
	for (ll i = 0; i < n; ++i) {
		s[i] -= '0';
		tot += s[i];
	}

	dfsdown(0, -1);
	dfsup(0, -1);

	for (ll i = 0; i < n; ++i) {
		if (s[i] == 1) {
			ans += a[i][1].A+1;
			continue;
		}

		ll mini = MAXN;
		for (ll u : g[i])
			if (z[pii(i, u)] >= 1)
				mini = min(mini, m[pii(i, u)]);
		ans += max(0LL, a[i][1].A+1-mini);
	}

	for (ll i = 0; i < n; ++i) {
		for (ll u : g[i]) {
			if (u > i)
				continue;
			ll vu = m[pii(u, i)];
			ll vi = m[pii(i, u)];

			if (vi < vu) {
				ans += (z[pii(i, u)] >= 1);
			} else if (vi > vu) {
				ans += (z[pii(u, i)] >= 1);
			} else {
				ans++;
			}
		}
	}

	cout << ans << endl;
}

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


abcde = [int(input()) for _ in range(5)]

first_digit = []
for i in range(len(abcde)):
    if abcde[i] % 10 == 0:
        first_digit.append(10)
    else:
        first_digit.append(abcde[i] % 10)


ans = sum([((i-1)//10+1)*10 for i in abcde])

ans = ans-10+min(first_digit)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846

ll power(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}

int pow(int a,int b){
	if(b == 0)return 1;
	int res = pow(a,b/2);
	res = res*res;
	if(b&1)res *= a;
	return res;
}



int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
 //    int t;
 //     cin >> t;

 //     while(t--){

     
 // }

int n,k;
cin >> n >> k;
vi total(n+1);
fo(i,1,n+1){
	total[i] += i+total[i-1]; 
}
vi totalm(n+1);
totalm[n] = n;
for(int i = n-1;i >= 0;i--){
	totalm[i] += totalm[i+1] + i;
}
int res = 0;
reverse(all(totalm));
fo(i,k-1,n+1){
	res = (res + abs(totalm[i] - total[i])+1)%mod;
}
cout << res << endl;


return 0;
	
	}




Measured memory_bytes: 6336
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
  }

#[fastout]
fn main() {
    input!{
        n: usize,
    }

    let mut tmp = n;
    let mut sum = 0;
    while tmp!=0 {
        sum += tmp%10;
        tmp /= 10;
        debug!(sum);
    }

    if n%sum==0 {
        println!("Yes");
    } else {
        println!("No");
    }

}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
int x,y;
cin>>x>>y;
int ans=0;
if(x==1&&y==1)ans+=400000;
ans+=max(0LL,400000-x*100000);
ans+=max(0LL,400000-y*100000);cout<<ans;
 


return 0;
}


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

int selectionsort(int n, int a[])
{
    int cnt = 0;
    for (int i = 0;i < n;i++)
    {
        int mini = i;
        for (int j = i;j < n;j++)
        {
            if (a[j] < a[mini])
            {
                mini = j;
            }
        }
        if (mini != i)
        {
            int temp = a[i];
            a[i] = a[mini];
            a[mini] = temp;
            cnt++;
        }
    }
    return cnt;
}

int main ()
{
    int n, cnt;
    cin >> n;
    int a[n];
    for (int i = 0;i < n;i++) cin >> a[i];
    
    cnt = selectionsort(n, a);
    
    for (int i = 0;i < n;i++)
    {
        cout << a[i];
        if (i < n-1) cout << " ";
    }
    cout << endl << cnt << endl;
    return 0;
}


Measured memory_bytes: 3080
package main

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

type Job struct {
	A int
	B int
}

type Jobs []Job

func (j Jobs) Len() int {
	return len(j)
}

func (j Jobs) Swap(x, y int) {
	j[x], j[y] = j[y], j[x]
}

func (j Jobs) Less(x, y int) bool {
	return j[x].B < j[y].B
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var n, a, b int
	fmt.Scan(&n)

	sc.Split(bufio.ScanWords)
	var jobs Jobs = []Job{}
	for i := 0; i < n; i++ {
		a = nextInt()
		b = nextInt()
		jobs = append(jobs, Job{a, b})
	}

	sort.Sort(jobs)

	time := 0
	for i := 0; i < n; i++ {
		time += jobs[i].A
		if time > jobs[i].B {
			fmt.Println("No")
			os.Exit(0)
		}
	}
	fmt.Println("Yes")
}

Measured memory_bytes: 12544
class Node
  def initialize(prev_node, next_node, value)
    @value = value
    @prev = prev_node
    @next = next_node
  end
  attr_accessor :next_node, :prev_node, :value
end

class LinkedList
  def initialize
    @first_node = Node.new(nil, nil, nil)
    @last_node = Node.new(nil, nil, nil)
    first_node.next_node = last_node
    last_node.prev_node = first_node
  end
  attr_accessor :first_node, :last_node

  def insert(x)
    new_node = Node.new(first_node, nil, x)
    tmp = first_node.next_node
    connect_node new_node, tmp
    connect_node first_node, new_node
  end

  def delete(x)
    current = first_node.next_node
    until current.next_node.nil?
      if current.value == x
        connect_node current.prev_node, current.next_node
        break
      end
      current = current.next_node
    end
  end

  def deleteFirst
    connect_node first_node, first_node.next_node.next_node
  end

  def deleteLast
    connect_node last_node.prev_node.prev_node, last_node
  end

  def print_all
    current = first_node
    array = []
    until current.next_node.next_node.nil?
      array << current.next_node.value
      current = current.next_node
    end
    puts array.join ' '
  end

  def connect_node(first, second)
    first.next_node = second
    second.prev_node = first
  end
end

list = LinkedList.new
gets.to_i.times do
  input = gets.split(' ')
  case input[0]
  when 'insert'
    list.insert input[1].to_i
  when 'delete'
    list.delete input[1].to_i
  when 'deleteFirst'
    list.deleteFirst
  when 'deleteLast'
    list.deleteLast
  end
end
list.print_all



Measured memory_bytes: 107668
#include<stdio.h>
int main(){
    int p,q,r,x;
    scanf("%d %d %d",&p,&q,&r);
    x=p+q;
    if(x>q+r){
        x=q+r;
    }
    if(x>p+r){
        x=p+r;
    }
    printf("%d\n",x);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
using namespace std;

int main(){
  long int a,ans=0,cnt=0;
  string s;
  cin>>s;
  int b;
  b=s.size();
  for(int i=0;i<b;i++){
    if(s[i]=='W'){
      cnt++;
      ans+=i;
    }
  }
  if(cnt>1){
    for(int i=1;i<cnt;i++){
      ans-=i;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 640
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int start = (A > C) ? A : C;
		int end = (B < D) ? B : D;
		
		System.out.println((end - start >= 0) ? end - start : 0);
	}
}

Measured memory_bytes: 23252
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
//#include <intrin.h>  //AtCoder (gcc) 上ではこれがあると動かない。__popcnt用のincludeファイル。
using namespace std;
using Graph = vector<vector<int>>;

typedef long long ll;
typedef long double ld;


#define int long long
#define rep(i, n) for(long long i = 0; i < (n); i++)
#define sqrt(d) pow((long double) (d), 0.50)

const int INF = 2e9;
const ll large_P = 1e9 + 7;



//繰り返し2乗法
//N^aの、Mで割った余りを求める。
ll my_pow(ll N, ll a, ll M) {
	ll tempo;
	if (a == 0) {
		return 1;
	}
	else {
		if (a % 2 == 0) {
			tempo = my_pow(N, a / 2, M);
			return (tempo * tempo) % M;
		}
		else {
			tempo = my_pow(N, a - 1, M);
			return (tempo * N) % M;
		}
	}
}



//N_C_a を M で割った余り
ll my_combination(ll N, ll a, ll M) {
	ll answer = 1;

	rep(i, a) {
		answer *= (N - i);
		answer %= M;
	}

	rep(i, a) {
		answer *= my_pow(i + 1, M - 2, M);
		answer %= M;
	}

	return answer;
}



ll my_gcd(ll& a, ll& b) {
	if (b == 0) return a;
	ll temp = a % b;
	return my_gcd(b, temp);
}



// long long型 n を、base 進法での、i 桁目の数が入った vector にする。
void ll_to_vector(ll base, ll n, vector<ll>& v) {
	ll tempo = n;

	ll n_digit = floor(log10(n) / log10(base)) + 1;
	v.assign(n_digit, 0);

	//ll n_digit = v.size();

	for (ll i = 0; i < n_digit; i++) {
		v.at(i) = tempo / pow(base, n_digit - 1 - i);
		tempo -= v.at(i) * pow(base, n_digit - 1 - i);
	}
}



int char_to_int(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4;
	case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9;
	default: return 0;
	}
}


//エラトステネスの篩で、prime で ないところに false を入れる。
//true で初期化された vector を代入する必要がある。
void prime_judge(vector<bool>& prime_or_not) {

	prime_or_not.at(0) = false;
	prime_or_not.at(1) = false;

	ll n = prime_or_not.size() - 1;
	ll region = sqrt(n) + 1;

	for (ll i = 2; i <= n / 2; i++) {
		prime_or_not.at(2 * i) = false;
	}


	for (ll i2 = 1; i2 < n / 2; i2++) {
		ll i = 2 * i2 + 1;  //ここからは奇数のみ探索
		if (i < region && prime_or_not.at(i)) {
			ll j = i * i;
			while (j < n + 1) {
				prime_or_not.at(j) = false;
				j += 2 * i;
			}
		}
	}
};



map<int, int> divide_to_prime(int target) {
	map<int, int> res;

	//sqrt(target) まで調べる。
	int upper_lim = ceil(sqrt(target));
	vector<bool> prime_or_not(upper_lim + 1, true);

	if (upper_lim < 20) prime_or_not.assign(25, true);
	prime_judge(prime_or_not);

	int tempo = target;
	rep(i, upper_lim + 1) {
		if (prime_or_not.at(i)) {
			while (tempo % i == 0) {
				tempo /= i;
				res[i]++;
			}
		}
	}

	if (tempo != 1) res[tempo]++; //sqrt(target) より大きな素因数は高々1つしかない。



	return res;
}





signed main() {
	string S;
	cin >> S;

	string res;

	if (S == "Sunny") res = "Cloudy";
	else if(S == "Cloudy") res = "Rainy";
	else res = "Sunny";


	cout << res << endl;
}

Measured memory_bytes: 256
import collections
import itertools

n = int(input())
s = collections.defaultdict(int)
for i in range(n):
    s[input()[0]] += 1

seq = list(itertools.combinations(['M', 'A', 'R', 'C', 'H'], 3))
ans = 0
for l in seq:
    ans += s[l[0]] * s[l[1]] * s[l[2]]
print(ans)


Measured memory_bytes: 3316
#include <stdio.h>

int main()
{
    int i,j,n;
    char buf[10];
    fgets(buf,sizeof(buf),stdin);
    sscanf(buf,"%d",&n);
    int min,maxprofit;
    maxprofit = -1e10;
    for (i=0;i<n;i++){
        scanf("%d",&j);
        if (i==0) min = j;
        else{
            if (maxprofit < (j-min)) maxprofit = (j-min);
            if (j<min) min = j;
        }
    }
    printf("%d\n",maxprofit);

    return 0;
}


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

using namespace std;

typedef long long ll;


map<char, int> mRGB;

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

	int n;
	cin >> n;

	string s;
	cin >> s;

	string sRGB = "RGB";
	map<char, int> mRGB;
	mRGB['R'] = 0;
	mRGB['G'] = 1;
	mRGB['B'] = 2;

	vector<vector<ll>> a(3, vector<ll>(n, 0));
	rep(i, 3){
		a[i][n-1] = (s[n-1] == sRGB[i] ? 1 : 0);
		for(int j = n - 2; j >= 0; j--){
			a[i][j] = a[i][j+1] +  (s[j] == sRGB[i] ? 1 : 0);
		}
	}

	ll ans = 0;
	for(int i = 0; i <= n - 3; i++){
		for(int j = i + 1; j <= n - 2; j++){
			if(s[i] == s[j]) continue;
			int idx = 3 - mRGB[s[i]] - mRGB[s[j]];

			ans += a[idx][j + 1];
		}
	} 

	for(int i = 0; i < n - 1; i++){
		for(int j = 1; i + 2 * j < n; j++){
			if(s[i] != s[i + j] && s[i] != s[i + 2 * j] && s[i + j] != s[i + 2 * j]){
				ans--;
			}
		}
	}

	cout << ans << endl;
}


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

int main() {
	int l, r, d;
	int cnt = 0;
	cin >> l >> r >> d;
	for (int i = l; i <= r; i++) {
		if (i%d == 0) cnt++;
	}
	cout << cnt << endl;
} 

Measured memory_bytes: 3620
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    C = collections.Counter(A)

    for i in C.keys():
        if C[i] >= 2:
            print("NO")
            break
    else:
        print("YES")


if __name__ == '__main__':
    main()



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

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N;
vector<long long> A;

int main() {
    while (cin >> N) {
        A.resize(N);
        for (int i = 0; i < N; ++i) cin >> A[i];
        sort(A.begin(), A.end(), greater<long long>());
        
        long long a[10] = {0};
        int iter = 0;
        for (int i = 0; i < N;) {
            if (A[i] == A[i+1]) {
                a[iter++] = A[i];
                i += 2;
            }
            else {
                ++i;
            }
            
            if (iter >= 2) break;
        }
        
        cout << a[0] * a[1] << endl;
        
    }
}















Measured memory_bytes: 1152
import java.util.*;

// 区間スケジュール問題 貪欲法
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());

        int[][] arr = new int[M][2];
        for (int i = 0; i < M; i++) {
            arr[i][0] = Integer.parseInt(scanner.next());
            arr[i][1] = Integer.parseInt(scanner.next());
        }

        scanner.close();

        // 終点の昇順
        Arrays.sort(arr, Comparator.comparingInt(a -> a[1]));

        int count = 0;
        int last = 0;
        for (int[] a : arr) {
            if (last <= a[0]) {
                last = a[1];
                count++;
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 63912
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue> //C++
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
#include<map> //C++
using namespace std; //C++
#define rep(i, a, n) for (i = (a); i < (n); i++)
#define  max(x,y) ((x)>(y)?(x):(y))
#define  min(x,y) ((x)>(y)?(y):(x))






int main()
{

	int i;
	string s;
	cin >> s;

	for (i = 0; i < s.size() ; i++) {
		if (s[i] == 'C') {
			for (int j = i; j < s.size() ; j++) {
				if (s[j] == 'F') {
					cout << "Yes";
					return 0;
				}
			}
		}
	}

	cout << "No";



	return 0;
}
	







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fo for(int i=0;i<n;i++)
#define clear cin.clear();cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define loopSolve int t; cin>>t; while(t--){solve();}
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

//INT_MAX         2,147,483,647                       <10^10
//U_INT_MAX       4,294,967,295                       <10^10
//LONG_LONG_MAX   9,223,372,036,854,775,807           <10^18
//U_LONG_LONG_MAX 18,446,744,073,709,551,615          <10^18
//ll power(int a, int b){
//    return (ll)(pow(a,b)+0.5);
//}

vector<int> gV(int n){
    vector<int> v(n);
    fo { cin>>v[i];  }
    return v;
}

int* gA(int n){
    int* arr = new int[n];
    fo cin>>arr[i];
    return arr;
}


void solve(){
    int n; cin>>n;
    string s; cin>>s;
    string temp=s;
    sort(temp.begin(),temp.end());
    int count=0;
    for(int i=0;i<n;i++){
        if(s[i]^temp[i])
            count++;
    }

    cout<<(count+1)/2<<endl;
}


int main() {
	ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    solve();
    //loopSolve;

	return 0;
}


Measured memory_bytes: 3856
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] data = new int[3];
        for (int i = 0; i < data.length; i++) {
            data[i] = Integer.parseInt(sc.next());
        }

        int ans = 1000;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (i == j) {
                    continue;
                }
                ans = Math.min(ans, data[i] + data[j]);
            }
        }
        System.out.print(ans);
    }

}

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

int main(){
    int n; cin >> n;
    vector<int> l(n); rep(i,n) cin >> l[i];

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

    if(l[l.size()-1] < accumulate(l.begin(),l.end()-1,0)){
        put("Yes");
    }else{
        put("No");
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

typedef uint64_t ull;
typedef  int64_t sll;

static const ull MOD = 1000000007LL;

int n;
int k;
int q;

ull a[200019];

ull umin (ull a, ull b) {
	return (a < b) ? a : b;
}
ull umax (ull a, ull b) {
	return (a > b) ? a : b;
}

ull solve () {
	sll i, j, ki;
	ull res = 0;

	ull allxor = 0;
	for (i = 0; i < n; i++) {
		allxor ^= a[i];
	}
	for (i = 0; i < n; i++) {
		a[i] &= ~allxor;
	}

	ull rank = 0;
	for (i = 59; i >= 0; i--) {
		for (j = rank; j < n; j++) {
			if (a[j] & (1LL << i)) break;
		}
		if (j == n) {
			continue;
		}

		if (j > rank) a[rank] ^= a[j];
		for (j = rank + 1; j < n; j++) {
			a[j] = umin(a[j], a[j] ^ a[rank]);
		}

		rank++;
	}
	ull x = 0;
	for (i = 0; i < n; i++) {
		x = umax(x, x ^ a[i]);
	}

	res = (x * 2) + allxor;

	return res;
}

int main(void){

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

	printf("%lld\n", solve());

	return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

int h, w;
vector<string>m;
int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };

int main() {
	cin >> h >> w;
	m.resize(h);
	vector<pair<int, int>>start;
	for (int i = 0; i < h; i++) {
		cin >> m[i];
		for (int j = 0; j < w; j++) {
			if (m[i][j] == '#')start.push_back({ i,j });
		}
	}
	vector<vector<int>>d(h, vector<int>(w, 0));
	queue<pair<int, int>>q;
	for (auto&& x : start) {
		q.push(x);
	}

	while (!q.empty()) {
		int x = q.front().first, y = q.front().second;
		q.pop();
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i], ny = y + dy[i];
			if (nx < 0 || nx >= h || ny < 0 || ny >= w)continue;
			if (m[nx][ny] == '#' || d[nx][ny])continue;
			d[nx][ny] = d[x][y] + 1;
			q.push({ nx,ny });
		}
	}
	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (ans < d[i][j])ans = d[i][j];
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 25056
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for _ in range(d)]
last=[-1 for i in range(26)]
x=0
for day in range(d):
  type=int(input())
  last[type-1]=day
  x+=s[day][type-1]
  for j in range(1,27):
    x-=(day-last[j-1])*c[j-1]
  print(x)

Measured memory_bytes: 9396
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <functional>

using namespace std;

bool cmp(pair<int,string> a , pair<int,string> b){  
	return a.first > b.first; 
} 

int main(void){
	bool b=false;
	while(1){
		int a,n;
		string s;
		vector< pair<int,string> > P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		if(b==true)cout << endl;
		b=true;
		for(a=0;a<n;a++){
			 cin >> s >> w >> l >> d; 
			P.push_back(make_pair(w*3+d,s));
		}
		stable_sort(P.begin(),P.end(),cmp);
		for(a=0;a<n;a++){
			cout << P[a].second << "," << P[a].first << endl; 
		}
	}
	return 0;
}

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


int main() {
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r",stdin);
	freopen("output.txt", "w",stdout);
#endif*/
	int n;
	cin>>n;
	int a[n+1][2];
	for(int i=0;i<n;i++)
	{
		cin>>a[i][0]>>a[i][1];
	}
	int f=0;
	for(int i=0;i<n-2;i++)
	{
		if(a[i][0]==a[i][1] && a[i+1][0]==a[i+1][1] && a[i+2][0]==a[i+2][1])
		{
			cout<<"Yes\n";
			f=1;
			break;
		}
	}
	if(f==0)
		cout<<"No\n";
    return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

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

// B

void solve() {

}

int main() {
  int n;
  cin >> n;
  map<string,int> mp;
  rep(i,n) {
    string s;
    cin >> s;
    mp[s]++;
  }
  cout << "AC x "  << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;




  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

ll gcd (ll x, ll y) { return y ? gcd(y,x%y) : x; }

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  ll ans;
  cin >> ans;
  rep(i,n-1) {
    ll x;
    cin >> x;
    ans = gcd(ans, x);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
program main
  implicit none
  integer :: n, i, res
  integer, allocatable :: h(:)
  read(*, *) n
  allocate(h(0:n))
  h(0) = 0
  read(*, *) h(1:)

  res = 0
  do i = 1, n
    res = res + max(0, h(i) - h(i - 1))
  end do

  write (*, "(i0)") res
end program main


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    static String z;
    static long sum=0;


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        HashSet<Integer>hs = new HashSet<>();
        for(int i=0;i<=2;i++)hs.add(s.nextInt());
        System.out.println(hs.size());

    }



}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25396
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    ll n, x, m;
    cin >> n >> x >> m;
    vector<int> id(m,-1);
    vector<int> a;
    int len = 0;
    ll tot = 0;
    while (id[x] == -1) {
        a.push_back(x);
        id[x] = len;
        len++;
        tot += x;
        x = (x*x)%m;
    }

    int c = len-id[x];
    ll s = 0;
    for (int i = id[x]; i < len; i++) s += a[i];

    ll ans = 0;
    if (n <= len) {
        rep(i,n) ans += a[i];
    } else {
        ans += tot;
        n -= len;
        ans += s*(n/c);
        n %= c;
        rep(i,n) ans += a[id[x]+i];
    }
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
constexpr int M = 1e9 + 7;
constexpr int INF = 1e9;

int N, Z, W;

// 直前の相手の手: top, turn: 今の手番
int solve(int top, int turn, vector<vector<int>>& dp, vector<int> const& a) {
    int& res = dp[top][turn];
    if(dp[top][turn] != -1) {
        return dp[top][turn];
    }
    if(top == 0) {
        res = abs(W - a.back()); // 最後まで引く
    } else {
        res = abs(a[top] - a.back()); // 最後まで引く
    }
    if(turn == 0) { // 途中まで引く
        for(int nex = top + 1; nex < N; ++nex) {
            res = max(res, solve(nex, turn^1, dp, a));
        }
    } else {
        for(int nex = top + 1; nex < N; ++nex) {
            res = min(res, solve(nex, turn^1, dp, a));
        }
    }
    return res;
}

int main() {
    cin >> N >> Z >> W;
    vector<int> a(N + 1);
    for(int i = 0; i < N; ++i) {
        cin >> a[i + 1];
    }

    vector<vector<int>> dp(N + 1, vector<int>(2, -1));
    cout << solve(0, 0, dp, a) << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int abs(int a)
{
	return a < 0 ? -a : a;
}

int gcd(int a, int b)
{
	return b ? gcd(b,a%b) : a;
}

int main()
{
	int a,b,c,d;
	scanf ("%d %d %d %d",&a,&b,&c,&d);

	int ans = abs(a-c) + abs(b-d) - gcd(abs(a-c),abs(b-d));

	printf ("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
class Main {
	public static void main(String[] args) {
		Scanner kb = new Scanner( System.in);	
		int a,b;

		a=kb.nextInt();
		b=kb.nextInt();

		System.out.printf( "%d %d %f\n", a/b, a%b, (double)a/b );	
	}
}

Measured memory_bytes: 17196
#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;
struct CompareBySecond {
  constexpr bool operator()(pair<P_ll, ll> const& a,
                            pair<P_ll, ll> const& b) const noexcept {
    return a.second > b.second;
  }
};

int main() {
  int H, W;
  int C_h, C_w;
  int D_h, D_w;
  cin >> H >> W;
  cin >> C_h >> C_w;
  cin >> D_h >> D_w;
  C_h--;
  C_w--;
  D_h--;
  D_w--;
  vector<vector<char>> S(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  ll ans = -1;
  // cout << ans << endl;
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  vector<vector<P_ll>> d(H, vector<P_ll>(W, P_ll(INF_ll, INF_ll)));
  priority_queue<pair<P_ll, ll>, vector<pair<P_ll, ll>>, CompareBySecond> que;
  pair<P_ll, ll> s;
  s.first = P_ll(C_h, C_w);
  s.second = 0;
  que.push(s);
  d[C_h][C_w].first = 0;
  d[C_h][C_w].second = 0;

  while (que.size()) {
    pair<P_ll, ll> p = que.top();
    que.pop();
    if (p.first.first == D_h && p.first.second == D_w) {
      ans = p.second;
      break;
    }
    for (int i = 0; i < 4; i++) {
      int nx = p.first.first + dx[i];
      int ny = p.first.second + dy[i];
      if (nx >= 0 && nx < H && ny >= 0 && ny < W) {
        if (S[nx][ny] == '#') {
          continue;
        } else {
          if (p.second < d[nx][ny].second) {
            pair<P_ll, ll> n_p;
            n_p.first = P_ll(nx, ny);
            n_p.second = p.second;
            que.push(n_p);
            d[nx][ny].second = p.second;
          }
        }
      }
    }
    for (int x_w = -2; x_w <= 2; x_w++) {
      for (int y_w = -2; y_w <= 2; y_w++) {
        int nx = p.first.first + x_w;
        int ny = p.first.second + y_w;
        if (nx >= 0 && nx < H && ny >= 0 && ny < W) {
          if (S[nx][ny] == '#') {
            continue;
          }
          if (p.second + 1 < d[nx][ny].second) {
            pair<P_ll, ll> n_p;
            n_p.first = P_ll(nx, ny);
            n_p.second = p.second + 1;
            que.push(n_p);
            d[nx][ny].second = p.second + 1;
          }
        }
      }
    }
  }
  // for (int i = 0; i < H; i++) {
  //   for (int j = 0; j < W; j++) {
  //     cout << d[i][j].second << " ";
  //   }
  //   cout << endl;
  // }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 20448
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;


ll root = -1;
vector<set<ll>> G(100001);
vll c(100001, -1);

vll init(ll now, ll from){//頂点、白頂点
  if(G[now].size()==1) return vll{1, 0};
  vll ret{1, (G[now].size()%2!=c[now])};
  for(auto to:G[now]){
    if(to==from) continue;
    vll tmp = init(to, now);
    ret[0] += tmp[0];
    ret[1] += tmp[1];
  }
  return ret;
}

ll tmp = -100000000;

ll dfs(ll now, ll from){
  if(G[now].size()==1) {
    tmp = max(tmp, 1LL);
    return 1LL;
  }

  vll cost;
  for(auto to:G[now]){
    if(to==from) continue;
    cost.push_back(dfs(to, now));
  }
  sort(all(cost));
  reverse(all(cost));
  if(cost.size()>1){
    ll l = cost[0], r = cost[1];
    tmp = max(tmp, l+r+(G[now].size()%2!=c[now]?1:-1));
  }
  return cost[0] + 1 + (G[now].size()%2!=c[now]?1:-1);
}

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  for(int i=0;i<n-1;i++){
    ll a, b;std::cin >> a >> b;
    G[a].insert(b);
    G[b].insert(a);
  }

  ll w_cnt = 0;
  for(int i=1;i<=n;i++){
    char cr;std::cin >> cr;
    c[i] = (cr=='W');
    w_cnt += c[i];
  }
  if(w_cnt==0){
    std::cout << 0 << '\n';
    return 0;
  }
  if(w_cnt==1){
    std::cout << 1 << '\n';
    return 0;
  }

  vector<ll> ji(n+1, 0);
  for(int i=1;i<=n;i++) ji[i] = G[i].size();
  //次数1かつ黒のものを消していく

  queue<ll> q;
  for(int i=1;i<=n;i++) if(ji[i]==1) q.push(i);

  vector<ll> use(n+1, 1);
  use[0] = 0;

  while(!q.empty()){
    ll top = q.front();
    q.pop();
    if(c[top]) continue;//白はスルー
    use[top] = 0;
    ll otonari = (*G[top].begin());
    G[top].erase(otonari);
    G[otonari].erase(top);
    if(G[otonari].size()==1) q.push(otonari);
  }

  ll node = 0;
  for(int i=1;i<=n;i++) if(use[i]) node++;
  if(node==2) {
    std::cout << 2 << '\n';
    return 0;
  }

  //部分木を構成
  for(int i=1;i<=n;i++){
    if(G[i].size()>1&&use[i]){
      root = i;
      break;
    }
  }
  vll t = init(root, -1);
  ll ans = 2*(t[0]-1) + t[1];
  dfs(root, -1);

  //木dp
  std::cout << ans - tmp + 1 << '\n';
  return 0;
}


Measured memory_bytes: 32036
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;


	void doIt() {
		double w = sc.nextInt();
		double h = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		System.out.println(w * h / 2.0 + " " 
		+ ((w / 2 == x && h / 2 == y)?1:0));
	}


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


Measured memory_bytes: 21844
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define lld long long int

int main(){
    int n;
    scanf("%d", &n);
    char s[51];
    int a[26] = {0}, b[26] = {0};
    scanf("%s", s);
    int x = 0;
    while(s[x] != '\0'){
        a[s[x] - 'a']++;
        x++;
    }
    rep(i, 1, n){
        scanf("%s", s);
        x = 0;
        rep(i, 0, 26){
            b[i] = 0;
        }
        while(s[x] != '\0'){
            b[s[x] - 'a']++;
            x++;
        }
        rep(i, 0, 26){
            if(a[i] > b[i]){
                a[i] = b[i];
            }
        }
    }
    rep(i, 0, 26){
        rep(j, 0, a[i]){
            printf("%c", 'a'+i);
        }
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long N;
    cin >> N;
    vector<long long>A(5);
    for (int i = 0; i < 5; i++) {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    long long time = (N+A.at(0)-1)/A.at(0) + 4;
    cout << time << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define int long long
char c[500][500];
bool b[500][500];
typedef pair<int, int>p;
p f1(p a, p b) { return make_pair(a.first + b.first, a.second + b.second); }
p f(int i, int j) {
	p r = make_pair(0, 0);
	if (b[i][j])return r;
	b[i][j] = 1;
	char ch = (c[i][j] == '.' ? '#' : '.');
	if (c[i][j] == '.')r.first++; else r.second++;
	if (c[i - 1][j] == ch && !b[i - 1][j])r = f1(r, f(i - 1, j));
	if (c[i + 1][j] == ch && !b[i + 1][j])r = f1(r, f(i + 1, j));
	if (c[i][j - 1] == ch && !b[i][j - 1])r = f1(r, f(i, j - 1));
	if (c[i][j + 1] == ch && !b[i][j + 1])r = f1(r, f(i, j + 1));
	return r;
}
signed main() {
	int h, w; cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> c[i][j];
		}
	}
	int ans = 0;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (!b[i][j]) {
				p p1 = f(i, j);
				ans += p1.first * p1.second;
			}
		}
	}
	cout << ans << endl;
	cin >> c[0][0];
}

Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std; 
using lint =                            long long int;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<63)-1
#define MOD 1000000007
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
#define                                 debug(x) cerr << #x << " " << (x) << endl
struct fast_ios                         { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T>                    bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T>                    bool mmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }


/* -------
         |
    **   |
   -------      
   |
   ---------------------------------------------------------------------------------------------------------------------------------*/

void solve(){  
  lint A;
  cin>>A;
  lint B;
  cin>>B;

  cout<< (A*B)/__gcd(A,B) <<endl;;
}

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


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

int w,q,id,t;
char r;
int wall[100];
int i,j,k;

int main(){
  for(;;){
    cin >> w >> q;
    if(!w && !q)break;

    for(i=0;i<w;i++)wall[i] = -1;

    for(i=0;i<q;i++){
      cin >> r;
      if(r=='s'){
	cin >> id >> t;
	for(j=0;j+t-1<w;j++){
	  bool f=true;
	  for(k=0;k<t;k++){
	    if(wall[j+k]>=0){
	      f=false;
	      break;
	    }
	  }
	  if(f){
	    cout << j << endl;
	    for(k=0;k<t;k++)wall[j+k]=id;
	    break;
	  }
	}
	if(j+t-1==w)cout << "impossible\n";
      }else{
	cin >> id;
	for(int j=0;j<w;j++)
	  if(wall[j]==id)wall[j] = -1;
      }
    }
    cout << "END\n";
  }
}

Measured memory_bytes: 0
n = int(input())
m = {}
a = [int(i) for i in input().split()]
for x in a:
    m[x] = 0

for x in a:
    m[x] += 1

s = sum(a)
for i in range(int(input())):
    b, c=  map(int, input().split())
    if b in m:
        s -= m[b]*b
        s += m[b]*c
        if c in m:
            m[c] += m[b]
        else:
            m[c] = m[b]
        m[b] = 0
    print(s)


Measured memory_bytes: 84248
n=int(input())
t1=0
x1=0
y1=0
for _ in range(n):
    t2,x2,y2=map(int,input().split())
    t=t2-t1
    d=abs(x1-x2)+abs(y1-y2)
    if d>t or t%2!=d%2:
        print('No')
        break
    t1,x1,y1=t2,x2,y2
else:
    print('Yes')

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

int N, Q;
vector<vector<int>> G;
vector<lint> X;

void dfs(int cur, int pre = -1) {
    for(auto to : G[cur]) {
        if(to == pre) continue;
        X[to] += X[cur];
        dfs(to, cur);
    }
}

int main() {
    cin >> N >> Q;
    G.resize(N);
    X.resize(N);
    rep(i, 0, N - 1) {
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].push_back(b); G[b].push_back(a);
    }
    rep(i, 0, Q) {
        int p, x;
        cin >> p >> x;
        p--;
        X[p] += x;
    }
    dfs(0);
    for(auto a : X) cout << a << " ";
    return 0;
}


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

int main()
{
	int N;
	string S;
	cin >> N >> S;

	int cnt = 0;
	int ma = 0;
	for( int i = 0; i < N; i++ ) {
		if( S[i] == ')' ) cnt++;
		else cnt--;
		if( cnt > ma ) ma = cnt;
	}
	string ans;
	if( ma > 0 ) ans += string( ma, '(' );
	ans += S;
	N = ans.size();
	cnt = 0;
	ma = 0;
	for( int i = N - 1; i >= 0; i-- ) {
		if( ans[i] == '(' ) cnt++;
		else cnt--;
		if( cnt > ma ) ma = cnt;
	}
	if( ma > 0 ) ans += string( ma, ')' );

	cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int dp[100100];

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<int> h(n);
  REP(i, n) cin >> h[i];
  REP(i, 100100) dp[i] = INF;
  dp[0] = 0;
  REP(i, n) {
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
  }
  cout << dp[n - 1] << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P  = pair<int, int>;
int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (ll& i : a) cin >> i;
    sort(a.begin(), a.end());
    ll res = a[0];
    for (int i = 1; i < n; ++i) {
        if (!a[i]) return cout << 0, 0;
        if (res > 1000000000000000000 / a[i]) return cout << -1, 0;
        res *= a[i];
        if (res > 1000000000000000000) return cout << -1, 0;
    }
    cout << res;
    return 0;
}


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

#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>

string S;

signed main()
{
    cin >> S;

    int tmp = 0;
    int ans = S.size();
    for(auto e : S)
    {
        if(e == 'T' && tmp)
        {
            tmp--;
            ans -= 2;
        }
        if(e == 'S')tmp++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3660
import java.util.*;
public class Main {
    static long MOD = (long)1e9+7;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] arr = new long[n];
        for (int i=0; i<n; i++) arr[i] = sc.nextLong();
//        Arrays.sort(arr);

        long ans = 0;

        for (int i=0; i<61; i++){
            long cnt = 0;
            for (int j=0; j<n; j++){
                if (((arr[j]>>i)&1)==1){
                    cnt++;
                }
//                ans += (cnt*(n-cnt)*((1<<i)%MOD))%MOD;
//                ans %= MOD;
//                System.out.println(cnt);
            }
            ans += ((cnt*(n-cnt))%MOD)*(((long)1<<i)%MOD)%MOD;
            ans %= MOD;

//            System.out.println(ans);
        }
//        for (int i=0; i<n; i++){
//            for (int j=0; j<100; j++) {
//                long cnt = 0;
//                if (((arr[i]>>j)&1)==1) {
//                    cnt++;
//                }
//                ans += (cnt*(n-cnt)*((1<<i)%MOD))%MOD;
//                ans %= MOD;
//            }
//        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 96692
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define ll long long

int main(){
  int n;cin>>n;
  vector<int>l(n);
  for(int i=0;i<n;++i)cin>>l[i];
  
  int longest=0;
  int sum=0;
  for(int i=0;i<n;++i){
    longest=max(longest,l[i]);
    sum+=l[i];
  }
  sum-=longest;
  if(longest<sum)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}




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

#define int long long
#define ld long double

#define pb push_back
#define F first
#define S second
#define I insert
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()

#define debug1(a) cerr<<" "<<#a<<" : "<<a<<"\n"
#define debug2(a,b) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define debug3(a,b,c) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define debug4(a,b,c,d) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"
 
#define INF (int)100000000000000000
#define PI (double)3.14159265358979
#define MOD 1000000007


signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
        string s;
        cin>>s;
    int ans =0;
    for (auto j:s)
    {   
        ans += j-'0';
        ans %= 9;
    }

    cout << ((ans == 0) ? "Yes" : "No");
 
    return 0;
}

Measured memory_bytes: 3740
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Y = sc.nextInt();
		int M = 0;
		int G = 0;
		int S = 0;
		int chek = 0;

		loop: for(int i = 0; i <= N; i++) {
			if(i == 0 && N * 10000 == Y) {
				M = N;
				chek = 1;
				break loop ;
			}
			if(i == 0 && N * 5000 == Y) {
				G = N;
				chek = 1;
				break loop ;
			}
			if(i == 0 && N * 1000 == Y) {
				S = N;
				chek = 1;
				break loop ;
			}
			if(Y >= i * 10000 && Y <= N * 10000) {
				M = i;
			}
			for(int j = 0; j <= N - M; j++) {
				G = j;
				if(M + G == N && M * 10000 + G * 5000 == Y) {
					chek = 1;
					break loop;
				}
				if((Y - (M * 10000 + G * 5000)) / 1000 == N - M - G) {
					S = (Y - (M * 10000 + G * 5000)) / 1000;
					chek = 1;
					break loop;
				}
			}
			G = 0;
		}
		if(chek == 0) {
			M = -1;
			G = -1;
			S = -1;
		}
		System.out.print(M + " " + G + " " + S);
	}
}

Measured memory_bytes: 23380
#include <stdio.h>
#include <math.h>
int main(void){
int p,q,r,swap;
scanf("%d %d %d",&p,&q,&r);
if (p>q)
{
  swap = p;
  p = q;
  q = swap;

}
if (q>r)
{
  swap = q;
  q = r;
  r = swap;
}
if (p>r)
{
  swap = p;
  p = r;
  r = swap;
}
printf ("%d",p+q);
 return 0;
}

Measured memory_bytes: 128