akhauriyash/Code-Regression huggingface dataset:
import collections
import itertools
import operator


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


a,b =  map(int, input().split())
uf = UnionFind(a)
for i in range(b):
    com , x,y =map(int, input().split())
    if com == 0:
        uf.union(x, y)  # (3)
    elif com == 1:
        print(1 if uf.same_check(x, y) else 0)  # (3)


Measured memory_bytes: 6424
import java.math.*;
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        double a = sc.nextInt();
        double b = sc.nextInt();
        double ans =-1d;
        outloop: for(double i = 1.0;i<=1009.0;i=i+1.0){
            double ia =Math.floor(i*0.08);
            double ib =Math.floor(i*0.1);
            if(ia==a&&ib==b){
                ans =i;
                break outloop;
            }
            }
            int an =(int)ans;
            System.out.println(an);
        }
	}

Measured memory_bytes: 21844
(defun main ()
  (let ((n (read))
        (m (read))
        (a)
        (x 0)
        (ans "Yes"))
    (dotimes (i n)
      (push (read) a)
      (setf x (+ x(first a))))
    (setf a (sort (copy-list a) #'>))
    (dotimes (i m)
      (when (> (* (/ 1 (* 4 m)) x) (nth i a))
        (setf ans "No")
        (return)))
    ans))

(format t "~a~%" (main))


Measured memory_bytes: 13028
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

double p;
vector<pair<int,double> > g[100001];
double dfs(int v,int par,double co){
    int n=g[v].size();
    double ret=co;
    rep(i,n){
        if(g[v][i].first!=par){
            ret+=dfs(g[v][i].first,v,co)*p+g[v][i].second*p;
        }
    }
    return ret;
}
int main(){
    int n;
    cin>>p>>n;
    int xi,yi;
    double ci;
    rep(i,n-1){
        cin>>xi>>yi>>ci;
        --xi,--yi;
        g[xi].pb(yi,ci);
        g[yi].pb(xi,ci);
    }
    double pc=dfs(0,-1,0);
    double ans=dfs(0,-1,pc);
    cout<<fixed<<setprecision(12)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 18040
#include <iostream>

using namespace std;

int main() {
	int M1, D1;
	int M2, D2;
	cin >> M1 >> D1;
	cin >> M2 >> D2;

	int result = 0;
	if(D1 >= D2) {
		result = 1;
	}
	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
s = input()
x = list(map(int, list(s)))
x = x[::-1]
dic = [0 for _ in range(2020)]
ten = 1
y = 0
for i in range(len(s)):
    y = (y+ten*x[i])%2019
    dic[y] += 1
    ten = (ten*10)%2019
result = 0
for i in range(2019):
    result += max([dic[i]*(dic[i]-1)//2, 0])
result += dic[0]
print(result)

Measured memory_bytes: 88260
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());

        int[][] dp = new int[N][3];
        String[] first_input_str_array = br.readLine().split(" ");
        dp[0][0] = Integer.parseInt(first_input_str_array[0]);
        dp[0][1] = Integer.parseInt(first_input_str_array[1]);
        dp[0][2] = Integer.parseInt(first_input_str_array[2]);

        for(int i = 1; i < N; i++) {

            String[] input_str_array = br.readLine().split(" ");
            
            for(int j = 0; j < 3; j++) {

                for(int k = 0; k < 3; k++) {

                    if(j == k) continue;
                    dp[i][k] = Math.max(dp[i-1][j] + Integer.parseInt(input_str_array[k]), dp[i][k]);

                }
            }
        }

        int[] ans_array = dp[N-1];
        Arrays.sort(ans_array);
        
        pw.println(ans_array[2]);
        pw.close();
        br.close();
    }
}


Measured memory_bytes: 59428
import java.io.{PrintWriter, _}
import java.util._


object Main {
  def main(args: Array[String]): Unit = {
    val inputStream = System.in
    val outputStream = System.out
    val in = new InputReader(inputStream)
    val out = new PrintWriter(outputStream)
    val solver = new Task
    solver.solve(1, in, out)
    out.close()
  }

  class Task {
    def solve(testNumber: Int, in: InputReader, out: PrintWriter): Unit = {
      val a = in.next
      val b = in.next
      val c = in.next
      out.println(if (a(a.length - 1) == b(0) && b(b.length - 1) == c(0)) "YES" else "NO")
    }
  }

  class InputReader(val stream: InputStream) extends AutoCloseable {
    //reader = new BufferedReader(new FileReader(stream), 32768);
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer = new StringTokenizer("")


    def next: String = {
      while ( {
        tokenizer == null || !tokenizer.hasMoreTokens
      }) try
        tokenizer = new StringTokenizer(reader.readLine)
      catch {
        case e: IOException =>
          throw new RuntimeException(e)
      }
      tokenizer.nextToken
    }

    def nextLine: String = {
      try
        return reader.readLine
      catch {
        case e: IOException =>
          e.printStackTrace()
      }
      ""
    }

    def nextInt: Int = next.toInt

    def nextLong: Long = next.toLong

    override def close(): Unit = {
    }
  }

}


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

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

    vector<int> height(n);

    for(int i = 0; i < n; i++){
        cin >> height.at(i);
    }

    reverse(height.begin(), height.end());

    int ans = 0;
    int cnt = 0;
  
    for(int i = 1; i < n; i++){
        if(height.at(i - 1) <= height.at(i)){
            cnt++;
        }
        else{
            cnt = 0;
        }
        ans = max(ans, cnt);   
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int a[3];
  rep(i,3) cin>>a[i];
  if(a[0]==a[1] && a[1]==a[2]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define int long long
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
#define left sefude
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl; 
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
const int N = 110;
int l[N];

int32_t main(){
  fastio;
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> l[i];
  }
  sort(l,l+n);
  int ans=0;
  rep(i,0,n)rep(j,i+1,n)rep(k,j+1,n){
    if(l[i] != l[j] and l[j]!=l[k] and l[i]!=l[k] and l[k] < l[i] + l[j]){
      ans++;
    }
  }
  cout << ans << endl;
  // math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 3640
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

// =========ここまでテンプレ============

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll total = 0;
    rep(i, n) total = total ^ a[i];
    rep(i, n) cout << (total ^ a[i]) << ' ';
    cout << endl;
}

Measured memory_bytes: 4352
#include <iostream>
using namespace std;
 
int main(){  
    int H, W, i, j, k;
    for(i = 0; i < 90000; i++){
    cin >> H >>W;
    if ( H == 0 && W == 0) break;
     
     for (j = 0; j < H; j++){
        if(j%2== 0){
        for(k = 0; k < W; k++){
        if(k%2== 0)
        cout << "#";
        else cout << ".";
        }}
        else{
        for(k = 0; k < W; k++){
        if(k%2 == 0) cout << ".";
        else cout <<"#";
        }}
        cout << endl;
    }cout << endl;}
return 0;}



Measured memory_bytes: 3096
#include <iostream>
#include <vector>

using namespace std;

vector<int> GetDistances(const vector<int> &next, int start)
{
    vector<int> dist(next.size(), -1);
    for (auto steps = 0; dist[start] == -1; steps += 1) {
        dist[start] = steps;
        start = next[start];
    }
    return dist;
}

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

    vector<int> next(n);
    for (auto &pos : next) {
        cin >> pos;
        pos -= 1;
    }

    auto dist = GetDistances(next, 0);
    cout << dist[1] << "\n";

    return 0;
}


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

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] xyh = new int[3*n];
		for (int i=0; i<n; i++) {
			xyh[i*3] = sc.nextInt();
			xyh[i*3+1] = sc.nextInt();
			xyh[i*3+2] = sc.nextInt();
		}

		for (int i=0; i<=100; i++) {
			for (int j=0; j<=100; j++) {
				int h = 0;
				for (int k=0; k<n; k++) {
					if (xyh[k*3+2] != 0) {
						h = Math.abs(i-xyh[k*3]) + Math.abs(j-xyh[k*3+1]) + xyh[k*3+2];
					}
				}

				boolean ok = true;
				for (int k=0; k<n; k++) {
					int dx = Math.abs(i-xyh[k*3]);
					int dy = Math.abs(j-xyh[k*3+1]);
					if (xyh[k*3+2] == 0) {
						if (h > dx + dy) {
							ok = false;
							break;
						}
					} else if (h != dx + dy + xyh[k*3+2]) {
						ok = false;
						break;
					}
				}

				if (ok) {
					System.out.println(i + " " + j + " " + h);
					return;
				}
			}
		}
	}
}

Measured memory_bytes: 23892
#include<stdio.h>


int main(void)
{   
    int n,a,b;
    scanf("%d",&n);
    if(n==1){
        printf("Hello World\n");
    }   
    else{
        scanf("%d%d",&a,&b);
        printf("%d\n",a+b);
    }   

    return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 7;
int dig[N];
int dp[N][100][2], k;

int dfs(int pos, int num, bool ismax){
	if(pos == 0) return num == k;
	int &v = dp[pos][num][ismax];
	if(v != -1) return v;
	v = 0;
	int mx = ismax ? dig[pos] : 9;
	for(int i = 0; i <= mx; ++ i){
		if(i) v += dfs(pos - 1, num + 1, ismax && i == mx);
		else v += dfs(pos - 1, num, ismax && i == mx);
	}
	return v;
}

int solve(string &s){
	memset(dp, -1, sizeof dp);
	int len = 0;
	for(int i = s.size() - 1; ~i; -- i){
		dig[++ len] = s[i] - '0';
	}
	return dfs(len, 0, 1);
}

int main(){
	ios::sync_with_stdio(false); cin.tie(nullptr);
	string s; cin >> s >> k;
	cout << solve(s) << '\n';
	return 0;
}

Measured memory_bytes: 156544
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	ll m = 1;
	const ll inf = 1e18;
	bool bad = false;
	while(n--){
		ll x;
		cin >> x;
		if(x == 0){
			cout << 0 << '\n';
			return 0;
		}
		if(!(m <= inf/x)){
			bad = 1;
		}
		m *= x;
	}
	if(bad){
		cout << -1 << '\n';
		return 0;
	}
	else{
		cout << m << '\n';
	}
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>

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

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

lli f(lli a, lli b) {
	lli count_a, count_b;

	count_a = count_b = 0;

	while (a > 0) {
		count_a++;
		a /= 10;
	}
	while (b > 0) {
		count_b++;
		b /= 10;
	}

	return max(count_a,count_b);
}

void yaku(lli n) {
	lli i, j, k,min_k;

	j = lli(sqrt(n));

	min_k = f(1, n);

	for (i = 2; i <= j; i++) {
		if (n%i == 0) {
			k = f(i, n / i);
			min_k = min_k > k ? k : min_k;
		}
	}

	cout << min_k;
}

int main() {
	lli n;

	cin >> n;

	yaku(n);
	
	return 0;
}

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

using namespace std;
using ll = int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using tpi = tuple<int, int, int>;

using vqi = vector<queue<int>>;
using vpi = vector<pii>;
using bs = bitset<60>;
using vbi = vector<bs>;

ll gcd(ll a, ll b) {
    if (a < b) {
        swap(a, b);
    }

    /* ユークリッドの互除法 */
    ll r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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

constexpr int64_t __pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    if (p == 0) {
        return 1;
    }
    if (p % 2 == 0) {
        int64_t t = __pow_mod(n, p / 2, mod);
        return (t * t) % mod;
    }
    return (n * (__pow_mod(n, p - 1, mod) % mod)) % mod;
}

constexpr int64_t pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    int64_t res = __pow_mod(n, p, mod);
    if (res == 0) {
        res = mod;
    }
    return res;
}


// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
    long long N;
    std::cin >> N;

    map<string, int> m;

    int max_l = 0;
    vector<string> v;
    for (int i = 0; i < N; i++) {
        string s;
        std::cin >> s;
        m[s]++;
        max_l = max(max_l, m[s]);
    }

    for (auto&& item:m) {
        if (item.second == max_l) {
            v.emplace_back(item.first);
        }
    }
    sort(v.begin(), v.end());
    for (auto&& item: v) {
        cout << item << endl;
    }
    return 0;
}


Measured memory_bytes: 26868
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
    char suit;
    int value;
};

struct Card L[MAX/2 + 2], R[MAX/2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right){
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for (i = 0; i < n1; i++) L[i] = A[left + i];
    for (i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for (k = left; k < right; k++){
        if (L[i].value <= R[j].value){
            A[k] = L[i++];
        }else{
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right){
    int mid;
    if (left + 1 < right){
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r){
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p - 1;
    for (j = p; j < r; j++){
        if (A[j].value <= x.value){
            i++;
            t = A[i];
            A[i] = A[j];
            A[j] = t;
        }
    }
    t = A[i + 1];
    A[i + 1] = A[r];
    A[r] = t;
    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r){
    int q;
    if (p < r){
        q = partition(A, n, p, r);
        quickSort(A, n, p, q - 1);
        quickSort(A, n, q + 1, r);
    }
}

int main(){
    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;

    scanf("%d", &n);

    for (i = 0; i < n; i++){
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n -1);

    for (i = 0; i < n; i++){
        // マージソートとクイックソートの結果を比べる
        if (A[i].suit != B[i].suit) stable = 0;
    }

    if (stable == 1) printf("Stable\n");
    else printf("Not stable\n");
    for (i = 0; i < n; i++){
        printf("%c %d\n", B[i].suit, B[i].value);
    }

    return 0;
}


Measured memory_bytes: 4072
#include<iostream>
using namespace std;
int main(){
	int i,a[26]={0};
	int f=1;
    string s;
    cin >> s;
    for(i=0;i<s.size();i++){
    	a[s[i]-'a']++;
    }
    for(i=0;i<26;i++){
    	if(a[i]%2!=0){
    		f=0;
    		break;
		}
    }
    if(f)
    	cout << "Yes" << endl;
    else
    	cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner s=new Scanner(System.in);
        long a=s.nextLong(),b=s.nextLong(),r=0;
        if(a%2==1){
            r^=a;
            ++a;
        }
        if(b%2==0){
            r^=b;
            --b;
        }
        r^=(b-a+1)/2%2;
        System.out.println(r);
    }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<unordered_set>
#include<unordered_set>
#include<cmath>
#define mod 1000000000000000000
int main(void) {
int n;int k;
cin>>n>>k;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
sort(arr,arr+n);
long long int sum=0;
for(int i=0;i<k;i++)
sum=sum+arr[i];
cout<<sum<<"\n";
	return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <map>
#include <vector>
#include <cmath>
#include <string> // これがないとstringの出力がエラー
#include <sstream>
#include <algorithm>
#include <bitset>
#include <list>
#include <set>
using namespace std;

typedef long long ll;

void flip(string& str, int n) {
	str[n] = '0';
	str[n + 1] = '1';
	str[n + 2] = '0';
}

map<string,ll> dp;
ll dfs(string str, ll cnt)
{
	if (dp.count(str) != 0) {
		return dp[str];
	}
	//cerr << str << " " << cnt << endl;
	ll maximum = 0;
	for (int i = 0; i < str.size() - 2; ++i) {
		if (i + 2 >= str.size()) continue;
		if (str[i] == '1' && str[i + 1] == '0' && str[i + 2] == '1') {
			string next = str;
			flip(next, i);
			maximum = max(maximum, dfs(next, cnt + 1));
		}
	}
	ll ret = max(cnt, maximum);
	dp[str] = ret;
	return ret;
}

void pA()
{
	int N; cin >> N;
	string str; cin >> str;
	cout << dfs(str, 0) << endl;
}

void pB()
{
	int H, W; cin >> H >> W;
	vector<string> mp(H);
	for (auto& m : mp)
		cin >> m;

	int dx[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
	int dy[] = { -1, -1, 0, 1, 1, 1, 0, -1 };
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (mp[i][j] == '.') {
				int cnt = 0;
				for (int k = 0; k < 8; ++k) {
					int ny = i + dy[k];
					int nx = j + dx[k];
					if (ny < 0 || ny >= H) continue;
					if (nx < 0 || nx >= W) continue;
					if (mp[i + dy[k]][j + dx[k]] == '#')
						cnt++;
				}
				mp[i][j] = '0' + cnt;
			}
		}
	}

	for (auto m : mp)
		cout << m << endl;
}

unsigned bit_count(unsigned n)
{
	unsigned i = 0;

	while (n) {
		i += n & 1;
		n >>= 1;
	}

	return i;
}

int N, M;
set<int> path[100004];

ll addPath()
{
	ll cnt = 0;
	for (int n0 = 1; n0 <= N; ++n0) {
		for (auto n1 : path[n0]) {
			if (n0 == n1) continue;
			for (auto n2 : path[n1]) {
				if (n1 == n2) continue;
				if (n0 == n2) continue;
				for (auto n3 : path[n2]) {
					if (n2 == n3) continue;
					if (n1 == n3) continue;
					if (n0 == n3) continue;
					if (path[n0].find(n3) == path[n0].end()) {
						cnt++;
						path[n0].insert(n3);
						path[n3].insert(n0);
					}
				}
			}
		}
	}
	return cnt;
}

void pC()
{
	cin >> N >> M;
	for (int m = 0; m < M; ++m) {
		int a, b; cin >> a >> b;
		path[a].insert(b);
		path[b].insert(a);
	}

	cout << addPath() << endl;
}

int main()
{
	pB();

	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
int main() {
long long p,N,jud,q;
  jud=0;
  cin >> p;
  vector<int> keta(p+1);
  for (int j=1; j<p+1;j++){keta.at(j)=0;}
 
  cin >> N;
  vector<int> vec(N*2);
for (int i = 0; i < N; i++) {
  cin >> vec.at(i*2);
  cin >> vec.at(i*2+1);
  if (vec.at(i*2)==1 && vec.at(i*2+1)==0 && p>1) {jud=100;}
  if (keta.at(vec.at(i*2))==0) {
    keta.at(vec.at(i*2))=vec.at(i*2+1);
  }
  else if (keta.at(vec.at(i*2)) != vec.at(i*2+1)) {
  jud=100;
  }
  
}
  if (keta.at(1)==0 && p>1) {keta.at(1)=1;}
for (int i=1;i<p+1;i++){
  q=q+keta.at(p+1-i)*pow(10,i-1);
}
if (jud==0) {cout << q << endl;}  
else {cout << -1 << endl;}
  
}

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

int main() {
    int n, T;
    cin >> n >> T;
    int t[n];
    rep(i, n) cin >> t[i];

    ll ans = T;
    rep(i, n - 1) ans += min(T, t[i + 1] - t[i]);

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


Measured memory_bytes: 4340
N, *A = map(int, open(0).read().split())

ma = max(A)
mi = min(A)

if abs(mi) <= abs(ma):
    p = A.index(ma)
    ans = [(p, i) for i in range(N)]
    ans += [(i - 1, i) for i in range(1, N)]
else:
    p = A.index(mi)
    ans = [(p, i) for i in range(N)]
    ans += [(i, i - 1) for i in reversed(range(1, N))]

print(len(ans))
for x, y in ans:
    print(x + 1, y + 1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a) for(int i = 0; i < a; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int a,b,c,d; cin>>a>>b>>c>>d;
    if(abs(a-c)<=d) cout<<"Yes"<<endl;
    else if(abs(b-a)<=d&&abs(c-b)<=d)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_Node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main()
{
    fastIO;
    ll n;
    cin>>n;
    vector<ll>a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    vector<ll>pre(n+1),suf(n+1);
    pre[0]=a[0];
    suf[n-1]=a[n-1];
    for(int i=1;i<n;i++)
    {
        pre[i]=__gcd(pre[i-1],a[i]);
    }
    for(int i=n-2;i>=0;i--)
    {
        suf[i]=__gcd(suf[i+1],a[i]);
    }
    ll val,val1,ans=max(pre[n-2],suf[1]);
    for(int i=1;i<n-1;i++)
    {
        val=pre[i-1];
        val1=suf[i+1];
        ans=max(ans,__gcd(val,val1));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5544
#include<stdio.h>
int main()
{
	int p[10001]={1},i,j;
	for(i=2;i<100;i++)
		if(!p[i])
			for(j=i*2;j<10001;j+=i)
				p[j]=1;
	for(;scanf("%d",&i),i;)
		for(;i>1;i--)
			if((!p[i])&&(!p[i-2]))
			{
				printf("%d %d\n",i-2,i);
				break;
			}
	return 0;
}

Measured memory_bytes: 648
#include<bits/stdc++.h>
#define mod 1000000007
#define lim 15000005
using namespace std;
typedef long long int ll;
typedef pair<int,int> pi;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n,x;
    cin>>n>>x;
    int a[n];
    for (int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    int ct=0;
    for (int i=0;i<n && x>0;i++) {
        if (a[i]<=x) ct++;
        x-=a[i];
    }
    if (x>0) ct--;
    cout<<ct;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;


int main()
{

while(1){
    int n;
    cin >> n;

    if(n==0) break;
    double s[n],mean=0,sd=0;


    rep(i,n){
        cin >> s[i];
        mean += s[i];
    }

    mean /= n;

    rep(i,n){
        sd += pow(s[i]-mean,2);
    }

    sd = sqrt(sd/n);

    printf("%.7f\n",sd);
}

    return 0;

}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  combination comb(n + k);

  // when s = "abc" and k = 2, the result will be as follows: "○a○b○c○"
  // the combination of the rightmost section (the right side of "c") is 26^(k - i) ways.
  // the combination of the other section is 25^(k) * (k + n - 1)Comb(i)
  mint ans = 0;
  rep(i, k + 1) {
    ans += mint(25).pow(i) * comb(n + i - 1, i) * mint(26).pow(k - i);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 35648
import java.util.*;
import java.io.*;

public class Main {
    static int[] ans;
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = scanner.nextInt();
        int[] dams = new int[N];
        for(int i = 0; i < N; i++) {
            dams[i] = scanner.nextInt();
        }
        ans = new int[N];
        int lo = 1;
        int hi = dams[0];
        while(lo <= hi) {
            int mid = (lo + hi)/2;
            if (check(mid, Arrays.copyOf(dams, N))) hi = mid-1;
            else lo = mid + 1;
        }
        check(lo-1, dams);
        out.print(2*ans[N-1]);
        for(int i = 0; i < N-1; i++) {
            out.print(" " + 2*ans[i]);
        }
        out.println();
        out.flush();
    }
    
    static boolean check(int mid, int[] dams) {
        dams[0] -= mid;
        dams[1] -= mid;
        int N = dams.length;
        ans[0] = mid;
        for(int i = 1; i < N; i++) {
            ans[i] = dams[i];
            dams[(i+1)%N] -= ans[i];
        }
        return dams[0] < 0;
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}


Measured memory_bytes: 45340
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    A = list([0])
    A.extend(a)
    A.append(0)

    sum = 0
    for i in range(1, n+2):
        sum += abs(A[i]-A[i-1])
    for i in range(1, n+1):
        print(sum-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))


Measured memory_bytes: 14048
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 1000 + 10;
const ll N2      = 70;
const ld PI      = 3.141592653589793;
//template<class T>using onset=tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
void solve(){
  #ifndef ONLINE_JUDGE  
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
signed main(){
    fastio();
    //cout<<fixed<<setprecision(20);
    ll d,t,s;
    cin>>d>>t>>s; 
    if(t*s>=d){
      cout<<"Yes";
    }
    else
    cout<<"No";
    return 0;
}   

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    long long n;
    cin >> n;
    vector<long long> v;
    for (long long i = 1; i <= sqrt(n); ++i) {
        if (n % i == 0) {
            v.push_back(i);
            if (i * i != n) {
                v.push_back(n / i);
            }
        }
    }
    long long answer = n - 1;
    for (long long l : v) {
        answer = min(answer, l + (n / l) - 2);
    }
    cout << answer << endl;
}


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

int main() {
  #define int long long
  int a, b, k;
  cin >> a >> b >> k;
  if (k <= a) {
    cout << a - k << " "  << b << endl;
  }
  else if (a < k && k <= a + b) {
    cout << 0 << " " << a + b - k << endl;
  }
  else {
    cout << 0 << " " << 0 << endl;
  }
    
}


Measured memory_bytes: 256
/* ****_hela**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		int n;
		cin>>n;
		ll int sum=0;
		for(int i=1;i<=n;i++){
			if(i%3!=0 && i%5!=0)sum+=i;
		}		
		cout<<sum;
	}
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using T = tuple<ll,int,int>;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9 + 7;

ll fact[5000];
ll rfact[5000];

int main(void){
  fact[0] = 1LL;
  for(int i = 1;i < 5000;++i){
    fact[i] = fact[i-1] * i;
    fact[i] %= mod;
  }
  
  ll p = mod - 2;
  ll x = fact[4999];
  rfact[4999] = 1;
  while(p > 0){
    if(p & 1){
      rfact[4999] = (rfact[4999] * x) % mod;
    }
    x = (x * x) % mod;
    p >>= 1;
  }
  
  for(int i = 4999;i > 0;--i){
    rfact[i-1] = rfact[i] * i;
    rfact[i-1] %= mod;
  }
  int n,k;
  cin >> n >> k;
  for(int i = 1;i <= k;++i){
    if(n - k < i - 1){
      puts("0");
      continue;
    }
    ll blue;
    ll numblue = k - i;
    blue = (fact[numblue+i-1] * rfact[i-1]) % mod;
    blue = (blue * rfact[numblue]) % mod;
    ll red;
    ll numred = n - k - (i-1);
    red = (fact[numred+i] * rfact[i]) % mod;
    red = (red * rfact[numred]) % mod;
    printf("%lld\n", (blue * red) % mod);
  }
  return 0;
}


Measured memory_bytes: 384
h, w = map(int, input().split())
r = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
     "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
     ]

for i in range(h):
    s_in = list(input().split())
    judge = "snuke" in s_in
    if judge:
        line = i + 1
        row = r[s_in.index("snuke")]

print("{}{}".format(row, line))


Measured memory_bytes: 3064
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int a, b;
	int min = 1010101010;
	int t;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		if (min > b) {
			min = b;
			t = a;
		}
	}
	cout << min + t << endl;

	return 0;
}

Measured memory_bytes: 384
N=int(input())
h=list(map(int,input().split()))

ans=0

while h!=[]:
	if h[0]==0:
		h.pop(0)
		continue
	i=0
	while True:
		if i<len(h) and h[i]!=0:
			h[i]-=1
			i+=1
		else:
			i=0
			ans+=1
			break

print(ans)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
# input
s = input()

while len(s) > 4:
    if s[-5:] == 'dream':
        s = s[:-5]
    elif s[-7:] == 'dreamer':
        s = s[:-7]
    elif s[-5:] == 'erase':
        s = s[:-5]
    elif s[-6:] == 'eraser':
        s = s[:-6]
    else:
        break

if len(s) > 0:
    print('NO')
else:
    print('YES')


Measured memory_bytes: 3188
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const K = Number(input[0][0]);

  return K % 2 === 0 ? (K / 2) ** 2 : ((K - 1) / 2) ** 2 + (K - 1) / 2;
};

console.log(main(read()));


Measured memory_bytes: 29612
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end() 
#define MOD 1000000007
#define N 200005
#define pll pair<ll,ll>
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
ll dp1[N][3],dp2[N][2],a[N],n;
ll solve1(ll id,ll taken)
{
     if(id==n+1 && taken==0)
     {
          return -1e18;
     }
     if(id==n+2 && taken==1)
     {
          return -1e18;
     }
     if(id>=n)    return 0;
     ll ans = dp1[id][taken];
     if(ans!=-1)    return ans;
     ans = -1e18;
     if(taken<=1)
     {
          ans = max(ans,a[id]+solve1(id+3,taken+1));
     }
     ans = max(ans,a[id]+solve1(id+2,taken));
     return dp1[id][taken] = ans;
}
ll solve2(ll id,ll taken)
{
     if(id>=n)   return 0;
     ll ans = dp2[id][taken];
     if(ans!=-1)    return ans;
     ans = -1e18;
     if(taken==0)
     {
          ans = max(ans,a[id]+solve2(id+3,1));
     }
     ans = max(ans,a[id]+solve2(id+2,taken));
     return dp2[id][taken] = ans;
}
void solve()
{ 
     cin >> n;
     for(ll i=0;i<n;i++)   cin >> a[i];
     if(n%2)
     {
          memset(dp1,-1,sizeof(dp1));
          memset(dp2,-1,sizeof(dp2));
          ll ans = solve2(1,0);
          ll sum = 0;
          for(ll i=2;i<n;i+=2)    sum += a[i];
          ans = max(ans,sum);
          sum = 0;
          ll ele = 0;
          for(ll i=0;i<n;i+=2)
          {
               ele++;
               sum += a[i];
               if(ele==n/2)     break;
          }
          ans = max(ans,sum);
          ll ans1 = solve1(0,0);
          ans = max(ans,ans1);
          cout<<ans;
     }
     else
     {
          memset(dp2,-1,sizeof(dp2));
          ll ans = solve2(0,0);
          ll sum = 0;
          for(ll i=1;i<n;i+=2)     sum += a[i];
          ans = max(ans,sum);
          cout<<ans;
     }
}
int main()
{
     FAST;
     ll t = 1;
  ///   cin >> t;
     while(t--)
     {     
          solve();
     }
}


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

int main(){
  int a,b;
  cin >> a >> b;
  string s(b,'0'+a);
  string t(a,'0'+b);
  if(a>=b) cout << t << endl;
  else cout << s << endl;
  return 0;
}

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

int main()
{
	long long n;
	cin >> n;
	long long sum = 0;
	vector<long long> avc(100001, 0);
	for (long long i = 0; i < n; ++i) {
		long long a;
		cin >> a;
		++avc[a];
		sum += a;
	}

	long long q;
	cin >> q;
	for (long long i = 0; i < q; ++i)
	{
		long long b, c;
		cin >> b >> c;
		sum += c * avc[b] - b * avc[b];
		cout << sum << endl;
		avc[c] += avc[b];
		avc[b] = 0;
	}

	return 0;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

typedef tuple<int, int, int> T;

int main(){
    int N, Q; cin >> N >> Q;
    vector<T> xst(N);

    for(int i=0; i<N; ++i){
        int s, t, x; cin >> s >> t >> x;
        s -= x; t -= x;
        xst[i] = make_tuple(x, s, t);
    }
    sort(xst.begin(), xst.end());

    set<pair<int, int>> se;
    for(int i=0; i<Q; ++i){
        int d; cin >> d;
        se.insert(make_pair(d, i));
    }

    vector<int> ans(Q, -1);

    for(int i=0; i<N; ++i){
        int x, s, t;
        tie(x, s, t) = xst[i];
        auto itr = se.lower_bound(make_pair(s, -1));
        while(itr != se.end()){
            if(itr->first >= t) break;
            ans[itr->second] = x;
            se.erase(itr++);
        }
    }

    for(auto e:ans) cout << e << endl;
    
}

Measured memory_bytes: 14336
N = int(input())
task = []

for _ in range(N):
    task.append(tuple(map(int,input().split())))

task.sort(key=lambda x: x[1])

t = 0
ok = True
for a,b in task:
    if t+a>b:
        ok = False
        break

    t += a

if ok :
    print('Yes')
else:
    print('No')


Measured memory_bytes: 81588
#include<iostream>
#include<vector>
using namespace std;
int main(int argc, char *argv[])
{
    const int N = 1000001;
    vector<bool> prime(N, true);
    prime[0] = false;
    prime[1] = false;
    for(int i = 2; i < N; i++) {
        if(prime[i]) {
            for(int j = i + i; j < N; j += i) {
                prime[j] = false;
            }
        }
    }
    for(;;) {
        int a, d, n;
        cin >> a >> d >> n;
        if(a == 0) break;
        for(;;) {
            while(!prime[a]) {
                a += d;
            }
            n--;
            if(n == 0) break;
            a += d;
        }
        cout << a << endl;
    }
    return 0;
}


Measured memory_bytes: 3248
#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 a[100100];

int main()
{
    int N;
    cin >> N;
    rep(i, N)
    {
        int x;
        cin >> x;
        a[x]++;
    }
    int res = 0;
    for (int i = 1; i < 100100; i++)
    {
        res = max(res, a[i - 1] + a[i] + a[i + 1]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3908
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(),(x).end()

int main(){
	vector<int> v(3);
	rep(i,3) cin>>v[i];
	sort(all(v));
	cout<<v[0]+v[1]<<endl;
}

Measured memory_bytes: 3572
a,b,c,d,e = input().split(" ")

W = int(a)
H = int(b)
x = int(c)
y = int(d)
r = int(e)

if x+r <= W and x-r>=0 and y+r <= H and y-r>=0 :
    print("Yes")
else :
    print("No")
    


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

int main()
{
    long long n, sum=0;
    cin >> n;
    vector<long long> d(n);
    for (long i = 0; i < n;i++){
        cin >> d.at(i);
    }

    sort(d.begin(), d.end());
    for (long i = 0; i < n; i++)
    {
        //cout << d.at(i) << " ";
        sum += d.at(i);
    }
    //cout << endl;
    /*
    if(d.at(n/2)>=sum/n){
        cout << d.at(n / 2) - d.at((n/2)-1)  << endl;
    }
    else{
        cout << "0" << endl;

    }
    
    cout << endl;
    cout << sum/n << endl;
    cout <<n/2<< endl;
    */
    cout << d.at(n / 2) - d.at((n / 2) - 1) << endl;
}

Measured memory_bytes: 1024
program biscuit
  implicit none
  integer(8) :: k, a, b, m
  m = 1_8
  read(*,*) k, a, b
  if ((k.lt.a-1_8).or.(b.le.a+2_8)) then
    write(*,'(i0)') k+1_8
    stop
  end if
  k = k - a + 1_8
  m = a
  if (mod(k,2_8).eq.1_8) then
    k = k - 1_8
    m = m + 1_8
  end if
  m = m + (k/2_8)*(b-a)
  write(*,'(i0)') m
  stop
end program biscuit

Measured memory_bytes: 256
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};

fn main() {
    input! {
        n: usize,
        x: usize,
        m: usize,
    }

    let mut t = 0;
    let mut s = 0;
    let mut sr = vec![0];
    let mut hp = HashMap::new();
    for i in 0..n {
        if i == 0 {
            t = x;
        } else {
            t = t * t % m;
        }

        // the left part is all zero
        if t == 0 {
            break;
        }
        // the left part is some looping
        if hp.contains_key(&t) {
            let pi = *hp.get(&t).unwrap();
            let sl = sr[i] - sr[pi as usize];
            // println!("i:{}, pi:{}, sl:{}", i, pi, sl);
            let d = i - pi;
            let cnt = (n - i) / d;
            s += cnt * sl;
            let r = (n - i) % d;
            // println!("r:{}", r);
            let rv = sr[pi + r] - sr[pi];
            s += rv;
            // println!("cnt:{}, sum:{}", cnt, s);
            break;
        }

        hp.insert(t, i);
        s += t;
        sr.push(s);
    }

    // let mut a = vec![0; n];
    // let mut v = vec![0];
    // let mut sum = x;
    // let mut map: HashMap<usize, usize> = HashMap::new();
    // a[0] = x;
    // for i in 1..n {
    //     let x = a[i - 1].pow(2) % m;
    //     if x == 0 {
    //         break;
    //     }
    //     if map.contains_key(&x) {
    //         let l = map.get(&x).unwrap();
    //         let r = i - 1;
    //         println!("l:{}, r:{}, v:{}", l, r, v.len());
    //         sum += (v[r] - v[*l - 1 as usize]) * n - l / (r - *l + 1);
    //         break;
    //     }
    //     map.insert(x, i);
    //
    //     sum += x;
    //     a[i] = x;
    //     v.push(sum);
    // }
    println!("{}", s);
}


Measured memory_bytes: 3800
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(m)]

for a, b in ab:
  cost, idx = 10**18, 0
  for i, (c, d) in enumerate(cd):
    if cost > abs(a - c) + abs(b - d):
      cost = abs(a - c) + abs(b - d)
      idx = i + 1
  print(idx)


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

int main() {
  int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
  int a = x2-x1, b = y2-y1;
  cout << x2-b << " " << y2+a << " " << x1-b << " " << y1+a << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX5 100010
#define MAX6 1000010
#define pb push_back
#define mp make_pair
typedef long long int ll;
int main()
{
    ll n,k;
    cin>>n>>k;
    ll arr[MAX5];
    for(ll i=1;i<=n;i++)
        cin>>arr[i];
    ll dp[MAX5];
    for(ll i=1;i<=n;i++)
        dp[i]=INT_MAX;
    dp[1]=0;
    for(ll i=2;i<=n;i++)
    {
        for(ll j=1;j<=k;j++)
        {
            if(i-j>=1)
            {
                dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
            }
        }
    }
    //cout<<dp[2]<<'\n';
    //for(ll i=1;i<=n;i++)
      // cout<<dp[i]<<" ";
    cout<<dp[n]<<'\n';
return 0;
}

    

Measured memory_bytes: 1792