akhauriyash/Code-Regression huggingface dataset:
;; D - Friend Suggestions

(defun solve (n m k ab cd)
  (let ((adj  (make-array n :initial-element nil))
        (conn (make-array n :initial-element nil))
        (nblock (make-array n :initial-element 0)))
    ; 連結リスト
    (loop for (a . b) in ab
      do (setf (aref adj (1- a)) (cons (1- b) (aref adj (1- a))))
         (setf (aref adj (1- b)) (cons (1- a) (aref adj (1- b)))))
    ; 連結成分
    (loop for a below n
      unless (aref conn a)
        do (find-connected-component a conn adj))
    ; 同じ連結成分内のブロック関係の数
    (loop for (c . d) in cd
      when (gethash (1- c) (cdr (aref conn (1- d)))) ; 同じ連結成分
        do (incf (aref nblock (1- c)))
           (incf (aref nblock (1- d))))
    ; 友達候補 = 連結成分 - 自分 - 友達関係 - ブロック関係
    (loop for a below n
      collect (- (car (aref conn a)) 1 (length (aref adj a))
                 (aref nblock a)))))

(defun find-connected-component (a conn adj)
  (setf (aref conn a) (cons 0 (make-hash-table)))
  (labels ((dfs (queue)
             (when queue
               (let ((x    (car queue))
                     (rest (cdr queue)))
                 (unless (gethash x (cdr (aref conn a)))
                   (setf (gethash x (cdr (aref conn a))) t)
                   (incf (car (aref conn a)))
                   (setf (aref conn x) (aref conn a))
                   (setf rest (append (aref adj x) rest)))
                 (dfs rest)))))
    (dfs (list a))))

(defun main ()
  (let* ((n (read))
         (m (read))
         (k (read))
         (ab (loop repeat m collect (cons (read) (read))))
         (cd (loop repeat k collect (cons (read) (read)))))
    (format t "~{~a~^ ~}~%" (solve n m k ab cd))))

(main)


Measured memory_bytes: 139976
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

void solve()
{
	string a,b,c;
	cin>>a>>b>>c;
		cout<<"A"<<b[0]<<"C";
	return;
}

int main()
{
	fast;
	ll q=1;
	// cin>>q;
	while(q--)
		solve();
	return 0;
}



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



int main(){
    ll N; cin >> N;
    
    vector<vector<int>> G(N+1, vector<int>(N+1));
    int p = 1, cnt = 0;
    if(N % 2 == 1) p = 0;
        
    for(int i = N; i > N/2+1; i--){
        for(int j = p+1; j < i; j++) {
            G[i][j] = 1;
            G[j][i] = 1;
            cnt++;
            if(p != 0){
                G[p][j] = 1;
                G[j][p] = 1;
                cnt++;
            }
        }
        p++;
    }
    cout << cnt << endl;
    for(int i = 1; i <= N-1; i++){
        for(int j = i+1; j <= N; j++){
            if(G[i][j] == 1) cout << i << " " << j << endl;
        }
    }

}


Measured memory_bytes: 256
import java.util.Scanner;

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

    int N = scanner.nextInt();

    long res = 1;
    for (int i = 0; i < N; i++) {
      long t = scanner.nextLong();
      res = lcm(res, t);
    }
    System.out.println(res);
  }

  private static long gcd(long i, long j) {
    if (i > j) return gcd(j, i);
    while (i > 0) {
      long r = j % i;
      j = i;
      i = r;
    }
    return j;
  }

  private static long lcm(long i, long j) {
    long gcd = gcd(i, j);
    return i / gcd * j;
  }
}


Measured memory_bytes: 24916
#include<stdio.h>

#define	Hex_5		0x55555555
#define	Hex_3		0x33333333
#define	Hex_0f		0x0f0f0f0f
#define	Hex_00ff	0x00ff00ff
#define	Hex_ffff	0x0000ffff

#define MaxC 100000

inline int BitCount( int bits )
{
	bits = (bits & Hex_5	) + ((bits >>  1) & Hex_5	) ;
	bits = (bits & Hex_3	) + ((bits >>  2) & Hex_3	) ;
	bits = (bits & Hex_0f	) + ((bits >>  4) & Hex_0f	) ;
	bits = (bits & Hex_00ff	) + ((bits >>  8) & Hex_00ff) ;
	bits = (bits & Hex_ffff	) + ((bits >> 16) & Hex_ffff) ;

	return bits ;
}

inline int max( int a ,int b )
{
	return a > b ? a : b ;
}


int main( void )
{
	int R ,C ,flag ;
	while( 1 )
	{
		scanf( "%d %d" ,&R ,&C ) ;
		if( (R | C) == 0 )
		{
			return 0 ;
		}

		int bit[ MaxC ] = { 0 } ;
		
		int i ,j ;
		for( i = 0 ; i < R ; ++i )
		{
			for( j = 0 ; j < C ; ++j )
			{
				scanf( "%d" ,&flag ) ;

				bit[ j ] |= flag << i ;
			}
		}

		int ans ,cnt ;
		ans = 0 ;

		int r = 1 << R ;
		for( i = 0 ; i < r ; ++i )
		{
			cnt = 0 ;
			for( j = 0 ; j < C ; ++j )
			{
				flag = BitCount( bit[ j ] ^ i ) ;

				cnt += max( flag ,R - flag ) ;
			}

			ans = max( ans ,cnt ) ;
		}

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


Measured memory_bytes: 2228
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = (to) - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define all(v) v.begin(), v.end()
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

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

  // 0 <= M < P ということを踏まえてると
  // Aを P = A - 1となるようにすれば Pに対するMが全て最大化される
  // したがって、1 ~ n - 1の和を求めれば良い
  n--;
  ll ans = n * (n + 1) / 2;

  cout << ans << endl;
}

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

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

using namespace std;

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

int main() {

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

	int n, t;
	cin >> n >> t;

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

	vector<int> dp(n + 1);
	int end_time = 0;
	for (int i = 1; i <= n; ++i) {
		if (time[i] > end_time) {
			dp[i] = dp[i - 1] + t;
		} else {
			dp[i] = dp[i - 1] + time[i] + t - end_time;
		}

		end_time = time[i] + t;
	}	

	cout << dp[n] << "\n";

	return 0;

}

Measured memory_bytes: 1792
import java.util.Scanner;

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

        int K = scanner.nextInt();
        int X = scanner.nextInt();

        int min = Math.max(-1000000, X - K + 1);
        int max = Math.min(1000000, X + K - 1);

        for (int i = min ; i <= max ; i++) {
            System.out.printf("%d ", i);
        }
        System.out.println();
    }
}


Measured memory_bytes: 36484
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

template<class T>inline bool chmax(T& a, T b) { if (a <= b) { a = b; return true; } else return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	ll n, k; cin >> n >> k;
	vector<ll> a(n); rep(i, n) { cin >> a[i]; a[i]--; }
	vector<ll> dist(n, -1);
	vector<ll> now(n, -1);
	ll d = 0, p = 0;
	while (dist[p] < 0) {
		now[d] = p;
		dist[p] = d; d++;
		p = a[p];
	}

		if (k <= dist[p]) {
			cout << 1LL + now[k] << endl;
		}
		else cout << 1LL + now[dist[p] + (k - dist[p]) % (d - dist[p])] << endl;


}

/*		*/

Measured memory_bytes: 7956
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include <vector>
using namespace std;
#define pi M_PI
#define ll long long

int main(){
    int n, i;
    cin >> n >> i;
    int ans = 0;

    ans = n - i + 1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

ll P(int N) {
  ll ans = 1;
  for(int i=N; i>0; --i) {
    ans *= i;
    ans = ans % MOD;
  }
  return ans;
}

int main() {
  ll N, M; cin >> N >> M;
  if(abs(N-M) == 1) {
    cout << (P(N) * P(M)) % MOD << endl;
  } else if(abs(N-M) == 0) {
    ll tmp = P(N);
    cout << (tmp * tmp * 2) % MOD << endl;
  } else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long;
using lli = long long int;

void ABC076D()
{
	int N;
	cin >> N;
	vector<int> ti(N);
	vector<int> Ti(N + 1);
	vector<int> vi(N+1);
	for (int i = 0; i < N; ++i)
	{
		cin >> ti[i];
		Ti[i + 1] = Ti[i] + ti[i];
	}
	for (int i = 0; i < N; ++i)
		cin >> vi[i];

	vi[N] = 0;
	for (int i = N-1; i >= 0; --i)
	{
		vi[i] = min(vi[i], vi[i + 1] + ti[i]);
	}
	for (int i = 0; i < N; ++i)
	{
		vi[i + 1] = min(vi[i + 1], vi[i] + ti[i + 1]);
	}

	int v = 0;
	double d = 0.0;
	for (int i = 0; i < N; ++i)
	{

		if (v + ti[i] < min(vi[i], vi[i + 1]))
		{
			d += v * ti[i] + 0.5 * ti[i] * ti[i];
			v += ti[i];
		}
		else
		{
			int t1 = vi[i] - v;
			int s = max(0, vi[i] - vi[i + 1]);
			int t2 = ti[i] - s;
			if (t1 <= t2)
			{
				d += v * ti[i] + 0.5 * t1 * t1 + (vi[i] - v) * (ti[i] - t1) - 0.5 * s * s;
			}
			else
			{
				double tmax = 0.5 * (ti[i] + vi[i + 1] - v);
				d += 0.5 * ((2 * v + tmax) * tmax + (vi[i + 1] + v + tmax) * (ti[i] - tmax));
			}
			v = min(vi[i], vi[i + 1]);
		}
	}
	cout << std::fixed << std::setprecision(10) << d << endl;
}

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

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

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

using namespace std;
using lint=long long;

const long long INF=1LL<<61;

class starry_sky_tree{
	int n;
	vector<lint> dat1,dat2;

	void add(int l,int r,int a,int b,int u,lint val){
		if(b<=l || r<=a) return;
		if(l<=a && b<=r){ dat1[u]+=val; return; }

		add(l,r,a,(a+b)/2,2*u+1,val);
		add(l,r,(a+b)/2,b,2*u+2,val);

		dat2[u]=max(dat2[2*u+1]+dat1[2*u+1],dat2[2*u+2]+dat1[2*u+2]);
	}

	lint query_max(int l,int r,int a,int b,int u){
		if(b<=l || r<=a) return -INF;
		if(l<=a && b<=r) return dat1[u]+dat2[u];

		lint res1=query_max(l,r,a,(a+b)/2,2*u+1);
		lint res2=query_max(l,r,(a+b)/2,b,2*u+2);
		return max(res1,res2)+dat1[u];
	}

public:
	starry_sky_tree(int N){
		for(n=1;n<N;n*=2);
		dat1.assign(2*n,0);
		dat2.assign(2*n,0);
	}

	void add(int l,int r,lint val){ add(l,r,0,n,0,val); }
	void update_max(int x,lint val){
		lint tmp=query_max(x,x+1);
		if(tmp<val) add(x,x+1,val-tmp);
	}

	lint query_max(int l,int r){ return query_max(l,r,0,n,0); }
};

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<int> l(m),r(m),val(m);
	rep(i,m) scanf("%d%d%d",&l[i],&r[i],&val[i]), r[i]++;

	vector<vector<int>> L(n+1),R(n+2);
	rep(i,m){
		L[l[i]].emplace_back(i);
		R[r[i]].emplace_back(i);
	}

	starry_sky_tree SS(n+1);
	SS.add(1,n+1,-INF);

	lint ans=0;
	rep(x,n+1){
		for(int i:R[x]) SS.add(0,l[i],-val[i]);
		for(int i:L[x]) SS.add(0,l[i], val[i]);

		SS.update_max(x,SS.query_max(0,x));
		ans=max(ans,SS.query_max(x,x+1));
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 32640
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define LL long long
using namespace std;
const int maxn=1010;
LL a[maxn][3];
LL s[maxn];
int n,m;
int main(){
    while (~scanf("%d%d",&n,&m)){
        for (int i=0;i<n;i++){
            for (int j=0;j<3;j++) scanf("%lld",&a[i][j]);
        }
        LL ans=0;
        for (int t=0;t<8;t++){
            for (int i=0;i<=n;i++){
                LL cnt=0;
                for (int j=0;j<3;j++) if (t&(1<<j)) cnt+=a[i][j];else cnt-=a[i][j];
                s[i]=cnt;
            }
            sort(s,s+n);
            LL tot=0;
            for (int i=1;i<=m;i++) tot+=s[n-i];
            ans=max(ans,tot);
        }
        printf("%lld\n",ans);
    }
    return 0;
}


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

int main(){
  vector<int> v;
  int d;
  for (int i = 0; i < 3; ++i) {
    cin >> d;
    v.push_back(d);
  }
  sort(v.begin(), v.end());
  cout << v.at(0) << " " << v.at(1) << " " << v.at(2) << endl;
}


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

int main() {
    int cur[3]{};
    string ss[3];
    cin>>ss[0]>>ss[1]>>ss[2];
    int nx=0;
    while (1) {
        if (cur[nx]==ss[nx].size()) {
            cout<<char('A'+nx)<<endl;
            break;
        }
      	cur[nx]++;
        nx=ss[nx][cur[nx]-1]-'a';
        
    }
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        a: usize,
        b: usize
    }
    let gf = factor(gcd(a, b));
    println!("{}", gf.len() + 1);
}

fn gcd(n: usize, m: usize) -> usize {
    let mut l = min(n, m);
    let mut r = max(n, m);
    while l > 0 {
        let t = l;
        l = r % l;
        r = t;
    }
    r
}

fn factor(mut n: usize) -> Vec<(usize, usize)> {
    let mut ret = vec![];
    let mut p = 0;
    while n % 2 == 0 {
        p += 1;
        n /= 2;
    }
    if p != 0 {
        ret.push((2, p));
    }
    let mut r = 3;
    while r * r <= n {
        p = 0;
        while n % r == 0 {
            p += 1;
            n /= r;
        }
        if p != 0 {
            ret.push((r, p));
        }
        r += 2;
    }
    if n != 1 {
        ret.push((n, 1));
    }
    ret
}


Measured memory_bytes: 4352
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
	class Program
	{
		public static void Main()
		{
			var intArray = IO.ReadIntArray();
			IO.Write(new[]
			{
				intArray[2] , intArray[0] , intArray[1]
			});
		}
	}

	public static class IO
	{
		public static string   Read()							  { return Console.ReadLine(); }
		public static string[] ReadArray(char iSplitter = ' ')	  { return Read().Split(iSplitter); }
		public static int	   ReadInt()						  { return int.Parse(Read()); }
		public static int[]	   ReadIntArray(char iSplitter = ' ') { return ReadArray().Select(iText => int.Parse(iText)).ToArray(); }
		public static char[]   ReadCharArray()					  { return Read().ToCharArray(); }

		public static void Write(string iValue)			  { Console.WriteLine(iValue); }
		public static void Write(int iValue)			  { Console.WriteLine(iValue); }
		public static void Write(IEnumerable<int> iValue) { Console.WriteLine(string.Join(" " , iValue)); }
		public static void Write(long iValue)			  { Console.WriteLine(iValue); }
		public static void Write(decimal iValue)		  { Console.WriteLine(iValue); }
		public static void Write(bool iValue)			  { Console.WriteLine(iValue ? "Yes" : "No"); }
	}

	public static class Util
	{
		public static long Gcd(long i0 , long i1)	{ return (i0 > i1) ? _Gcd(i0 , i1) : _Gcd(i0 , i1); }
		private static long _Gcd(long i0 , long i1)	{ return (i1 == 0) ? i0 : _Gcd(i1 , i0 % i1); }
		public static long ModPow(long iBaseNumber , long iPow , long iModNumber)
		{
			var num = 1L;
			while(iPow != 0)
			{
				if((iPow & 0x1) != 0)
				{
					num = (num * iBaseNumber) % iModNumber;
				}
				iBaseNumber = (iBaseNumber * iBaseNumber) % iModNumber;
				iPow >>= 1;
			}
			return num;
		}
	}
}


Measured memory_bytes: 11476
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll r, s, p; cin >> r >> s >> p;
  vector<ll> v;
  rep(i, p) {
    ll y, x; cin >> y >> x; --x, --y;
    if (x >= s) {
      x = x - s + 1;
    }
    else {
      x = s - x;
    }
    y = r - y;
    v.pb(x + y);
    // cout << x+y << endl;
  }
  sort(all(v));
  ll ans = 0;
  rep(i, 1, p) chmax(v[i], v[i-1]+1);
  cout << v.back() << endl;
}



Measured memory_bytes: 6908
n, a, b, c, d = (map(int, input().split()))
S = input()
if '##' in S[a-1:c] or '##' in S[b-1:d] :
	print('No')
elif d < c and not '...' in S[b-2:d+1]:
        print('No')
else:
    print('Yes')


Measured memory_bytes: 3572
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int N,T,A;
vector<int>G[1<<17];
vector<int>dist(int s)
{
	vector<int>ret(N,1<<20);
	ret[s]=0;
	queue<int>P;
	P.push(s);
	while(!P.empty())
	{
		int u=P.front();P.pop();
		for(int v:G[u])
		{
			if(ret[v]>ret[u]+1)
			{
				ret[v]=ret[u]+1;
				P.push(v);
			}
		}
	}
	return ret;
}
main()
{
	cin>>N>>T>>A;
	for(int i=1;i<N;i++)
	{
		int u,v;cin>>u>>v;u--,v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	vector<int>td=dist(T-1),ad=dist(A-1);
	int ans=0;
	for(int i=0;i<N;i++)
	{
		if(td[i]<ad[i])
		{
			ans=max(ans,td[i]+(ad[i]-td[i])-1);
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 7424
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main(){
    int N;
    cin >> N;
    vector<ll> A(N+1);
    vector<ll> B(N);
    rep(i,N+1){
        cin >> A[i];
    }
    rep(i,N){
        cin >> B[i];
    }
    ll cnt = 0; 
    rep(i,N){
        if(A[i]<=B[i]){
            cnt += A[i];
            if(A[i+1]-(B[i]-A[i])>=0){
                cnt += B[i]-A[i];
                A[i+1]-=(B[i]-A[i]);
            }else{
                cnt += A[i+1];
                A[i+1] = 0;
            }
        }else{
            cnt += B[i];
        }
    }
    cout << cnt << endl;
}

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

int main() {
    string s;
    cin >> s;
    
    int size = s.size();
    for (int i = 0; i < size; i++) {
        s.pop_back();
        int ss = s.size();
        if (s.substr(0, ss/2) == s.substr(ss/2, ss/2)) {
            cout << ss - 1 << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 int main()
{
	//arrays with number of days in month and the days names
    int days[] = {31,29,31,30,31,30,31,31,30,31,30,31};
    string week[7] = {"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
    int month, day;
    while(cin >> month >> day, month||day)//entering day
	{
		
        int n = 0;
        for(int i=1; i<month; i++)
		{
            n += days[i-1];
        }
        n += day;
 
        n %= 7;
        cout << week[n] <<endl;//printing the day
 
    }
  return 0;
}
  

Measured memory_bytes: 1196
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define Swap(x,y)	{int _t=x; x=y; y=_t;}

int main(void){
	int a[5];
	int count;
	int flg = 1;

	for (count = 0; count < 3; count++){
		scanf("%d", &a[count]);
	}

	while(flg==1){
		flg = 0;
		for (count = 0; count < 2; count++){
			if (a[count]>a[count + 1]){
				Swap(a[count], a[count + 1]);
				flg = 1;
			}
		}
	}
	for (count = 0; count < 3; count++){
		printf("%d", a[count]);
		if (count < 2){
			printf(" ");
		}
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <unordered_map>

using namespace std;

int main () {
  int n, k;
  cin >> n >> k;
  int ch, ip;
  unordered_map<int, int> mp;
  for (int i = 0; i < k; ++i) {
    cin >> ch;
    for (int d = 0; d < ch; ++d) {
      cin >> ip;
      mp[ip]++;
    }
  }
  cout << n - mp.size () << ' ';
  return 0;
}


Measured memory_bytes: 3604
#include<cstdio>
#include<vector>
#include<set>
int N,M,A[2010],B[2010],a[2010],b[2010];
struct edge{int to,val;edge*next;}E[40010],*ne=E,*fir[2010],*fir2[2010];
void link(int u,int v,int val=0){*ne=(edge){v,val,fir[u]};fir[u]=ne++;}
void link2(int u,int v,int val=0){*ne=(edge){v,val,fir2[u]};fir2[u]=ne++;}
std::set<int>chs[2010];
bool edel[2010],cdel[2010];
int fa[2010],dep[2010],ans=0;
int lca(int x,int y){
	while(x!=y)dep[x]>dep[y]?x=fa[x]:y=fa[y];
	return x;
}
void tag2(int x,int y){
	while(x!=y){
		if(dep[x]>dep[y]){
			if(!edel[x])edel[x]=1,ans+=2;
			x=fa[x];
		}
		else{
			if(!edel[y])edel[y]=1,ans+=2;
			y=fa[y];
		}
	}
}
void init(int i){
	for(edge*e=fir[i];e;e=e->next)if(e->to!=fa[i]){
		fa[e->to]=i;
		dep[e->to]=dep[i]+1;
		init(e->to);
	}
}
void dfs(int i){
	for(edge*e=fir[i];e;e=e->next)if(e->to!=fa[i]){
		dfs(e->to);
	}
	if(i==1)return;
	//printf("i=%d\n",i);
	//printf("3=(%d,%d) cdel3=%d\n",a[3],b[3],cdel[3]);
	for(std::set<int>::iterator it=chs[i].begin(),it2;it!=chs[i].end();it=it2){
		it2=it;++it2;
		int id=*it;
		if(cdel[id]||a[id]==b[id])chs[i].erase(it);
		//else printf("%d(%d,%d)\n",id,a[id],b[id]);
	}
	if(!edel[i]){
		if(chs[i].size()==1){
			ans++;
			int id=*chs[i].begin();
			if(a[id]==i)a[id]=fa[i];
			else b[id]=fa[i];
			chs[fa[i]].insert(id);
			edel[i]=1;
		}
		if(chs[i].size()>1){
//			printf("%d\n",i);
			std::set<int>::iterator it=chs[i].begin();
			int id1=*it;
			int id2=*++it;
//			printf("%d %d\n",a[id1],b[id1]);
	//		printf("%d %d\n",a[id2],b[id2]);
			bool ty1=a[id1]==i,ty2=a[id2]==i;
			int to1=ty1?b[id1]:a[id1],to2=ty2?b[id2]:a[id2];
			int l=lca(i,to1)^lca(i,to2)^lca(to1,to2);
			tag2(i,l);
			link2(id1,id2,ty1==ty2);
			link2(id2,id1,ty1==ty2);
			cdel[id1]=1;
			chs[a[id1]].erase(id1);
			chs[b[id1]].erase(id1);
			if(ty2){
				chs[a[id2]].erase(id2);
				a[id2]=ty1?b[id1]:a[id1];
				chs[a[id2]].insert(id2);
			}
			else{
				chs[b[id2]].erase(id2);
				b[id2]=ty1?b[id1]:a[id1];
				chs[b[id2]].insert(id2);
			}
			for(it=chs[i].begin();it!=chs[i].end();++it){
				int id=*it;
				if(a[id]==i)a[id]=fa[i];
				else b[id]=fa[i];
				chs[fa[i]].insert(id);
			}
		}
	}
	else{
		for(std::set<int>::iterator it=chs[i].begin();it!=chs[i].end();++it){
			int id=*it;
			if(a[id]==i)a[id]=fa[i];
			else b[id]=fa[i];
			chs[fa[i]].insert(id);
		}
	}
}
bool cvis[2010],col[2010];
void cdfs(int i,int c){
	cvis[i]=1;
	col[i]=c;
	for(edge*e=fir2[i];e;e=e->next)
		if(!cvis[e->to])cdfs(e->to,c^e->val);
}
int main(){
//freopen("cf.in","r",stdin);
	scanf("%d%d",&N,&M);
	for(int i=1,u,v;i<N;i++)scanf("%d%d",&u,&v),link(u,v),link(v,u);
	for(int i=0;i<M;i++){
		scanf("%d%d",A+i,B+i);
		chs[a[i]=A[i]].insert(i);
		chs[b[i]=B[i]].insert(i);
	}
	init(1);
	dfs(1);
	printf("%d\n",ans);
	for(int i=0;i<M;i++)if(!cvis[i])cdfs(i,0);
	for(int i=0;i<M;i++){
		if(col[i])printf("%d %d\n",B[i],A[i]);
		else printf("%d %d\n",A[i],B[i]);
	}
}

Measured memory_bytes: 56320
import java.util.Scanner;

public class Main {

     static Scanner scanner;

     public static void main(String[] args) {
         scanner = new Scanner(System.in);

         long H=gl();
         long W=gl();
         long A=gl();
         long B=gl();
         long ans=0;
         long p=1000000007;
         
         long t=H-A-1;
         long y=W-1;
         long n=t+y;
         long tmp=1;

         while(n>Math.max(t, y)) {
        	 tmp=(tmp*n)%p;
        	 n--;
         }
         long min=Math.min(t, y);
         while(min>0) {
        	 tmp=(tmp*modpow(min, p-2, p))%p;
        	 min--;
         }


         long t2=A-1;
         long y2=0;
         long n2=t2+y2;
         long tmp2=1;
         while(n2>Math.max(t2, y2)) {
        	 tmp2=(tmp2*n2)%p;
        	 n2--;
         }
         long min2=Math.min(t2, y2);
         while(min2>0) {
        	 tmp2=(tmp2*modpow(min2, p-2, p))%p;
        	 min2--;
         }
         long tmp3=(tmp*tmp2)%p;
         ans=(ans+tmp3)%p;
         for(long i=1; i<W-B;i++) {
             tmp=(tmp*(W-i))%p;
             tmp=(tmp*modpow(t+W-i,p-2,p))%p;
             
             tmp2=(tmp2*(A+i-1))%p;
             tmp2=(tmp2*modpow(i,p-2,p))%p;
             
             tmp3=(tmp*tmp2)%p;
             ans=(ans+tmp3)%p;
         }
         System.out.println(ans);
     }

  // a^nをmodで割ったあまり
 	public static long modpow(long a, long n, long mod) {
 		long res=1;
 		while(n>0) {
 			if((n & 1) == 1) res=res*a%mod;
 			a=a*a%mod;
 			n=n>>1;
 		}

 		return res;
 	}

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 35608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int q;
	cin >> q;
	vector<set<int>> is(26);
	rep(i, n) is[s[i] - 'a'].insert(i);
	rep(ri, q) {
		int t; cin >> t;
		if (t == 1) {
			int i; char c;
			cin >> i >> c;
			i--;
			is[s[i] - 'a'].erase(i);
			s[i] = c;
			is[s[i] - 'a'].insert(i);
		}
		else {
			int l, r; cin >> l >> r;
			l--; r--;
			int ans = 0;
			rep(i, 26) {
				auto itr = is[i].lower_bound(l);
				if (itr != is[i].end() && *itr <= r) ans++;
			}
			cout << ans << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 24220
#include <bits/stdc++.h>
using namespace std;
#define MX 2155
vector<int> pr;
map<long long,long long> cnt,m;
int main()
{
	for (int i=2;i<MX;i++)
	{
		bool ok=1;
		for (int j:pr)
		ok&=(bool)(i%j);
		if (ok)
		pr.push_back(i);
	}
	int n,ans=0;
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		long long a,na=1,inv=1;
		scanf("%lld",&a);
		for (int p:pr)
		{
			int expo=0;
			while (a%p==0)
			{
				a/=p;
				expo++;
			}
			expo%=3;
			for (int j=0;j<expo;j++)
			na*=p;
			for (int j=0;j<(3-expo)%3;j++)
			inv*=p;
			if (inv>1e10)
			inv=0;
		}
		na*=a;
		long long p=round(sqrt(a));
		if (p*p==a)
		inv*=p;
		else
		{
			inv*=a;
			if (inv>1e10 || a>1e5)
			inv=0;
			inv*=a;
			if (inv>1e10)
			inv=0;
		}
		cnt[na]++;
		m[na]=inv;
	}
	for (auto p:cnt)
	{
		if (!cnt.count(m[p.first]) || p.second>cnt[m[p.first]] || (p.second==cnt[m[p.first]] && p.first<m[p.first]))
		ans+=p.second;
	}
	ans+=min(cnt[1],1LL);
	printf("%d",ans);
}

Measured memory_bytes: 12800
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
 
int main(){
  int A,B;
  cin>>A>>B;
  cout<<6-A-B<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	int n=s.size(),m=t.size();
	map<char,vector<int>> mp;
	rep(i,n){
		mp[s[i]].push_back(i);
	}
	ll ans=0;
	ll ind=-1;
	rep(i,m){
		if(!mp.count(t[i])){
			cout<<-1<<endl;
			return 0;
		}
		vector<int> &vec=mp[t[i]];
		auto itr=upper_bound(begin(vec),end(vec),ind);
		if(itr==end(vec)){
			ans+=(n-1-ind);
			ind=*begin(vec);
			ans+=ind+1;
		}else{
			ans+=*itr-ind;
			ind=*itr;
		}
	}
	cout<<ans<<endl;
}

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

int main() {
int A,B,C,K,s;
cin >> A >> B >> C >> K;
s=0;
for (int i=0; i<K; i++){
  if(A>0){
  s++;
  A--;
  }
  else if(B>0) B--;
  else if(C>0){
  s--;
  C--;
  }
 }
cout << s<<endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <map>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 200001

using namespace std;

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	int N, K; cin >> N >> K;
	vector<int> vec;
	for (int i = 0; i < N; i++)
	{
		int temp; cin >> temp;
		vec.push_back(temp);
	}
	int ret = INT_MAX;

	for (int i = 0; i < N - (K - 1); i++)
	{
		int dis = vec[i + K - 1] - vec[i];
//		if (!(vec[i] <= 0 && 0 <= vec[i + K - 1]))
		{
			int offset = min(abs(vec[i]), abs(vec[i + K - 1]));
			dis += offset;
		}
		ret = min(ret, dis);
	}

	cout << ret << endl;
//	system("pause");
	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds; 
using namespace std;



typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
 
//defines
typedef long long ll;
typedef long double ld;
ll n,m,k,tar,a,b,d,e;
map<ll,ll>ff;
bool judgement_time(ll x)
{
    if(x==0)
    {
        if(ff[x]==0)return true;
        return false;
    }
    while(x>0)
    {
        if(ff[x%10]!=0)return false;
        x/=10;
    }
    return true;
}
ll solve(ll t)
{
    cin>>n>>k;
    
    for(ll i=0;i<k;i++)cin>>a,ff[a]++;
    
    while(1)
    {
        if(judgement_time(n)==true)break;
        n++;
    }
    
    cout<<n<<"\n";
    
    
}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
   //cin>>t;
    while(t--)
    {
        solve(t);
    }
    
        
    return 0;
}

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

using namespace std;

vector<vector<long long>> G(101010);

int main(void){
   
    int n, m;
    cin >> n >> m;
    
    vector<long long> H(n);
    for (int i = 0; i < n; i++) cin >> H[i];
    
    for (int i = 0; i < m; i++){
        long long a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    int ans = 0;
    
    for (int i = 0; i < n; i++){
        
        int check = true;
        
        for (auto e : G[i]){
            if (H[i] <=H[e]){
                check = false;
                break;
            }
        }
        
        if (check) ans++;
    }
    
    cout << ans << endl;
}


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

int main()
{
  string s;
  cin >> s;
  
  int chars[26] = {0};
  bool flag = true;
  for(unsigned int i = 0; i < s.length(); ++i)
  {
    if(chars[s[i] - 'a'] != 0)
    {
      flag = false;
      break;
    }
    chars[s[i] - 'a']++;
  }
  
  if(flag) cout << "yes" << endl;
  else cout << "no" << endl;
}

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

typedef long long ll;
const ll MOD = 1000000007;
ll mod;

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    map<string, int> m;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        m[s]++;
    }
    ll ans = 0;
    for (auto it : m) {
        int l = it.second;
        ans += (ll)l * (ll)(l - 1) / 2;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 11264
#include <iostream>

using namespace std;

int A[101];
int N;
void ordenar(){
	int aux;
	for(int i =0; i<N ; i++){
		for(int j =i+1; j<N ; j++){
			if (A[i]>A[j]){
				aux =A[i];
				A[i] = A[j];
				A[j] = aux;
			}
		}
	}
}

int main(void){
	cin >> N;
	for(int i =0; i<N ; i++){
		cin >> A[i];
	}
	ordenar();

	cout << A[N-1] - A[0];
	
	return 0;
}


Measured memory_bytes: 256
/**
 *  Hi, I'm Arpan.
 *  Hardwork beats talent if talents doesn't work hard.
 *
*/

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
#define inv(v)         \
    for (auto &it : v) \
        cin >> it;
#define MOD 1000000007
#define pb push_back

ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

void solve()
{
    int n,q;
    cin >> n;
    vl a(n);
    inv(a);
    int arr[100005] = {0};
    for(int i=0;i<n;i++){
		arr[a[i]]++;
    }
    ll sum = 0 ;
    for(int i=0;i<n;i++){
		sum+=a[i];
    }

    cin >> q;
    while(q--){
        int b,c;
        cin >> b >> c;
        sum=1ll*sum-1ll*b*arr[b]+1ll*c*arr[b];
        arr[c]+=arr[b];
        arr[b] = 0;
        cout << sum << endl;
    }
}

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


Measured memory_bytes: 4512
#include<bits/stdc++.h>
#define N 1000005
using namespace std;
int a[N],now[N],n;
long long ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int mx=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=20;j++)
		{
			if(a[i]&1)mx=max(mx,now[j]),now[j]=i;
			a[i]/=2;
		}
		ans+=i-mx;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4480
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> x(m);
  rep(i,m) cin >> x[i];
  if(n>=m){
    cout << 0 << endl;
    return 0;
  }

  sort(x.begin(),x.end());
  vector<int> d(m-1);
  rep(i,m-1) d[i] = x[i+1] - x[i];
  sort(d.begin(),d.end());
  int ans = 0;
  rep(i,m-n) ans += d[i];
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
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<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

vector<LL> fact;
vector<LL> inver(500001);
 
LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}
 
 
LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=500000;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[500000]=fpow(fact[500000],mod-2);
    for(int i=499999;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}
 
LL hcombi(LL n,LL r){
    return combi(n+r-1,r); 
}



LL f(LL n,LL k){
    LL ret = 1;
    for (int i = 1; i <= min(n-1,k); i++) {
        ret = (ret + hcombi(n-i,i) * combi(n,i)%mod)%mod;
    }
    return ret;
}



int main(){
    set_combi();
    LL n,k;cin >> n >> k;
    cout << f(n,k) << endl;
    return 0;
}


Measured memory_bytes: 10352
in_len = input().split(" ")
in_h = int(in_len[0])
in_a = int(in_len[1])

out_c = 0

while True:
  out_c += 1
  if(in_h - in_a <= 0):
    print(out_c)
    break
  else:
    in_h -= in_a

Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

template <class I>
class SegmentTree {
 public:
  using Op = function<I(const I&, const I&)>;

 private:
  int n;
  vector<I> dat;
  Op op;
  I e;

 public:
  SegmentTree(int n_, const Op& op, const I& e)
      : op(op), e(e) {
    n = 1;
    while (n < n_) n *= 2;
    dat.resize(2 * n - 1, e);
  }
  SegmentTree(const vector<I>& init, const Op& op, const I& e)
      : SegmentTree(init.size(), op, e) {
    for (int i = 0; i < init.size(); i++) {
      dat[i + n - 1] = init[i];
    }
    for (int i = n - 2; i >= 0; i--) {
      dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
  }
  const I& operator[](int k) const {
    return dat[k + n - 1];
  }
  void update(int k, const I& a) {
    k += n - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = op(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  // [a, b)
  I query(int a, int b) const {
    a += n - 1;
    b += n - 1;
    I vl = e;
    I vr = e;
    while (a < b) {
      if ((a & 1) == 0) vl = op(vl, dat[a]);
      if ((b & 1) == 0) vr = op(dat[b - 1], vr);
      a = a / 2;
      b = (b - 1) / 2;
    }
    return op(vl, vr);
  }
  // query(0, i) >= x となる最小のi
  int kth(const I& x) const {
    int k = 0;
    I v = e;
    while (k < n - 1) {
      I t = op(v, dat[k * 2 + 1]);
      if (x <= t) {
        k = k * 2 + 1;
      } else {
        v = t;
        k = k * 2 + 2;
      }
    }
    return k - (n - 1) + 1;
  }
};

int main() {
  int N;
  while (cin >> N) {
    vector<ll> h(N), a(N);
    for (int i = 0; i < N; i++) cin >> h[i];
    for (int i = 0; i < N; i++) cin >> a[i];
    SegmentTree<ll> seg(N + 10, [&](ll a, ll b) { return max(a, b); }, 0);
    for (int i = 0; i < N; i++) {
      ll mn = seg.query(1, h[i]);
      seg.update(h[i], mn + a[i]);
    }
    ll res = seg.query(1, N + 1);
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 7424
s = input()

mod = 10**9+7
n = len(s)
dp = [[0]*13 for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
    if s[i] == '?':
        for j in range(10):
            for k in range(13):
                dp[i+1][(k*10+j)%13] += dp[i][k]
    else:
        for k in range(13):
            dp[i+1][(k*10+int(s[i]))%13] += dp[i][k]
    for k in range(13):
        dp[i+1][k] %= mod
print(dp[n][5])


Measured memory_bytes: 61788
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

int main() {
    ll N, H, W;

    cin >> N >> H >> W;

    cout << (N - H + 1) * (N - W + 1) << endl;

    return 0;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int dx[8] = {-1,0,1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};

bool solve(){
  int p_x[SIZE], p_y[SIZE];

  int n;

  scanf("%d",&n);

  if(n == 0) return false;
  
  for(int i=1;i<n;i++){
    int m, d;

    scanf("%d%d",&m,&d);

    p_x[i] = p_x[m] + dx[d];
    p_y[i] = p_y[m] + dy[d];
  }

  int min_x = 0, max_x = 0, min_y = 0, max_y = 0;

  for(int i=0;i<n;i++){
    min_x = min(min_x, p_x[i]);
    max_x = max(max_x, p_x[i]);
    min_y = min(min_y, p_y[i]);
    max_y = max(max_y, p_y[i]);
  }

  printf("%d %d\n",max_x-min_x+1, max_y-min_y+1);

  return true;
}

int main(){

  while(solve());
  
  return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF=1e9+7;
int n,m,ans=INF,id[305],fav[305][305],cnt[305];
bool used[305];
int getfav(){
	rep1(k,m)cnt[k]=0;
	rep(k,n)cnt[fav[k][id[k]]]++;
	int cr=0;
	rep1(k,m)if(cnt[k]>cnt[cr])cr=k;
	used[cr]=true;
	ans=min(ans,cnt[cr]);
	return cr;
}
int main(){
	scanf("%d%d",&n,&m);
	rep(i,n)rep(j,m)scanf("%d",&fav[i][j]);
	while(1){
		int c=getfav();
		rep(k,n){
			while(id[k]<m&&used[fav[k][id[k]]]==true)id[k]++;
			if(id[k]==m){
				printf("%d",ans);
				return 0;
			}
		}
	}
}

Measured memory_bytes: 640