akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n, cnt, ans;
    cin >> n;
    long long int h[n+1];
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    cnt = 0;
    ans = 0;
    for (int i = 0; i < n-1; i++) {
        if (h[i] >= h[i+1]) {
            cnt++;
            ans = max(cnt, ans);
        }

        else {
            cnt = 0;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define pb emplace_back
#define mp make_pair

using namespace std;

int main()
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10);
	#ifdef PIYUSH_HOME
		I_O;
	#else
	#define print(...) 0
	#endif
	int n;
	cin >> n;
	int res = 0;
	for (int i = 0; i < n; ++i)
		{
			int c;
			cin >> c;
			res += c;
		}
		res -= n;
		cout << res;
}

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

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b != 0) gcd(b, a%b);
  return b;
}

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

int main(){
 
  int a,b,c; cin >> a>> b >> c;
  if(a == b and b == c){
    pr("Yes");
  }
  else
    pr("No");


  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
  int a, b;
  cin >> a >> b;
  vector<pair<int, int>> zei(1001);
  for(int i = 1; i <= 1000; ++i) {
    zei[i].first = i * 0.08;
    zei[i].second = i * 0.1;
  }
  
  for(int i = 1; i <= 1000; ++i) {
    if(zei[i].first == a && zei[i].second == b) {
      cout << i << endl;
      return 0;
    } 
  }
  
  
  cout << -1 << endl;


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second

//int m,n;



signed main() 
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int n,a,b,c=0;
    cin>>n>>a>>b;

    cout<<min(a,b)<<" "<<max(a+b-n,c);

    

    

    
     return 0;

}

//       g++ -g c.cpp ; ./a.exe

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

#define int long long
#define pb push_back
#define st first
#define nd second
#define sz(x) ((int)x.size())
#define ins insert
using namespace std;

const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,x,t;
    cin>>n>>x>>t;
    cout<<((n-1)/x+1)*t<<endl;

}
/**
1
3 1
1 3
**/


Measured memory_bytes: 3644
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#include <vector>

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

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

const int MOD = 1e9 + 7;

signed main(void)
{
  int num;
  int n; cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; ++i) cin >> d[i];
  sort(d.begin(), d.end());

  num = 0;
  for (int i = d.front(); i <= d.back(); ++i) {
    int dist = distance(d.cbegin(), lower_bound(d.cbegin(), d.cend(), i));
    if (n / 2 == dist) {
      ++num;
    } else if (n / 2 < dist) break;

  }

  cout << num << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
using namespace std;
using ll = long long;

int main(){
    ll n;
    cin >> n;
    ll m = 1000000, cnt=0;
    for(ll i=0;i<n;i++){
        ll x;
        cin >> x;
        if(x<=m){
            m = x;
            cnt++;
        }
    }
    cout << cnt;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
set<int> R[1000005], C[1000005];
char s[1000005];
vector<bool> c[1000005];
vector<int> dp[1000005];
void del(int x, int y){
    R[x].erase(R[x].find(y));
    C[y].erase(C[y].find(x));
}
int main(){
    int h, w, k;
    scanf("%d%d%d", &h, &w, &k);
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++) R[i].insert(j);
    }
    for(int j=1;j<=w;j++){
        for(int i=1;i<=h;i++) C[j].insert(i);
    }
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    for(int i=1;i<=h;i++) c[i].resize(w+1), dp[i].resize(w+1);
    for(int i=1;i<=h;i++){
        scanf("%s", s+1);
        int n = strlen(s+1);
        for(int j=1;j<=w;j++){
            if(s[j] == '@') c[i][j] = 1;
            else c[i][j] = 0;
        }
    }
    queue<pii> q;
    dp[x1][y1] = 0;
    q.push(mp(x1, y1));
    del(x1, y1);
    while(!q.empty()){
        int x = q.front().first, y = q.front().second;
        q.pop();
        if(x == x2 && y == y2){
            printf("%d\n", dp[x][y]);
            return 0;
        }

        auto its = R[x].lower_bound(y);
        while(its != R[x].end()){
            if(*its-k > y) break;
            if(c[x][*its] == 1) break;
            auto its2 = its;
            its2++;

            dp[x][*its] = dp[x][y] + 1;
            q.push(mp(x, *its));
            del(x, *its);

            its = its2;
        }

        its = R[x].lower_bound(y);
        if(its != R[x].begin()){
            its--;
            while(1){
                if(*its+k < y) break;
                if(c[x][*its] == 1) break;
                auto its2 = its;
                bool b = 1;
                if(its != R[x].begin()) its2--, b = 0;

                dp[x][*its] = dp[x][y] + 1;
                q.push(mp(x, *its));
                del(x, *its);

                if(b) break;
                its = its2;
            }
        }

        its = C[y].lower_bound(x);
        while(its != C[y].end()){
            if(*its-k > x) break;
            if(c[*its][y] == 1) break;
            auto its2 = its;
            its2++;

            dp[*its][y] = dp[x][y] + 1;
            q.push(mp(*its, y));
            del(*its, y);

            its = its2;
        }

        its = C[y].lower_bound(x);
        if(its != C[y].begin()){
            its--;
            while(1){
                if(*its+k < x) break;
                if(c[*its][y] == 1) break;
                auto its2 = its;
                bool b = 1;
                if(its != C[y].begin()) its2--, b = 0;

                dp[*its][y] = dp[x][y] + 1;
                q.push(mp(*its, y));
                del(*its, y);

                if(b) break;
                its = its2;
            }
        }
    }
    printf("-1\n");
}

Measured memory_bytes: 258192
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<iostream>

using namespace std;

int a, b, c, d, e, f, g, result;

int main(void) {

	cin >> a >> b >> c;

	for (int i = 0; i < c; i++) {
		if (i % 2 == 0) {
			if (a % 2 != 0) {
				a = a - 1;
			}

			b += a / 2;
			a = a / 2;
		}
		else{
			if (b % 2 != 0) {
				b = b - 1;
			}

			a += b / 2;
			b = b / 2;
		}
	}

	cout << a << " " << b << "\n";
}

Measured memory_bytes: 256
//#define NDEBUG

#pragma region cp_template

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  return a < b ? b - a : a - b;
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b)
    a = b;
}
template <class F> class rec_lambda {
  F f;

public:
  rec_lambda(F &&f) : f(std::move(f)) {}
  template <class... Args> auto operator()(Args &&... args) const {
    return f(*this, std::forward<Args>(args)...);
  }
};
template <class F> auto make_rec(F &&f) { return rec_lambda<F>(std::move(f)); }
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}
constexpr char eoln = '\n';
template <class T> T ceildiv(const T &l, const T &r) {
  return l / r + (l % r != 0 ? 1 : 0);
}

} // namespace n91

#pragma endregion cp_template

#include <atcoder/dsu>

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  const usize n = scan<usize>();
  const usize m = scan<usize>();
  atcoder::dsu dsu(n);
  for (const usize i : rep(0, m)) {
    const usize a = scan<usize>() - 1;
    const usize b = scan<usize>() - 1;
    dsu.merge(a, b);
  }
  std::cout << dsu.groups().size() - 1 << eoln;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 8840
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>

using namespace std;
#define MAX 1000000
//priority_queue<int,vector<int>, less<int> > rq1;
//priority_queue<int, vector< int>, greater<int> > rq;
typedef long long ll;

struct node
{
    ll x,y;
};

bool com(node a,node d)
{
    return a.x<d.x;
}
node arr[100005];

int main()
{
    ll n,c,K;
    while (cin >>n>>c>>K)
    {
        memset(arr,0,sizeof(arr));
        for(int i=0; i<n; i++)
        {
            cin>>arr[i].x;
            arr[i].y=arr[i].x+K;
        }
        sort(arr,arr+n,com);

        node k=arr[0];
        ll sum=0;
        int rs=1;
        for(int i=1; i<n; i++)
        {
            // cout <<rs<<"res"<<endl;
            if(arr[i].x<=k.y)
            {

                if(rs==c)
                {
                    sum++;
                    rs=1;
                    k=arr[i];
                    //  cout <<k.x<<"*****";

                }
                else
                    rs++;
            }
            if(arr[i].x>k.y)
            {
                sum++;
                rs=1;
                k=arr[i];
                // cout <<k.x<<"********";
            }

        }
        //cout <<rs<<"rs"<<endl;
        if(rs>0)
            sum++;
        cout <<sum<<endl;
    }


    return 0;
}


Measured memory_bytes: 1792
void main() {
	auto s = rs.to!(dchar[]);
	s[5] = s[13] = ' ';
	s.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#import <Foundation/Foundation.h>
int main(){
    int N;
    scanf("%d",&N);
    NSMutableArray *B = [NSMutableArray array];
    for(int i=0;i<N;i++){
        int b;
        scanf("%d",&b);
        if(b>i+1) {
            puts("-1");
            return 0;
        }
        [B addObject:@(b)];
    }
    NSMutableArray *result = [NSMutableArray array];
    while([B count]>0){
        for(int i=[B count]-1;i>=0;i--){
            if(i+1==[[B objectAtIndex:i] integerValue]) {
                [result insertObject:@(i+1) atIndex:0];
                [B removeObjectAtIndex:i];
                break;
            }
        }
    }
    printf("%s", [result componentsJoinedByString:@"\n"].UTF8String);
}


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

int main() {
    string s;
    int a=0,b=0;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            if(s[i]!='0') a++;
        }
        else{
            if(s[i]!='1') a++;
        }
    }
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            if(s[i]!='1') b++;
        }
        else{
            if(s[i]!='0') b++;
        }
    }
    cout<<min(a,b)<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N, M;
    cin >> N >> M;
    VVL G(N+1);
    rep(i, 0, M){
        ll u, v;
        cin >> u >> v;
        G[u].push_back(v);
    }
    ll S, T;
    cin >> S >> T;
    VVL dist(N+1, VL(3, -1));
    dist[S][0] = 0;
    queue<PL> que;
    que.push({S, 0});
    while(!que.empty()){
        auto q = que.front();
        que.pop();
        for(auto g : G[q.first]){
            ll ns = (q.second + 1) % 3;
            if(dist[g][ns] == -1){
                dist[g][ns] = dist[q.first][q.second] + 1;
                que.push({g, ns});
            }
        }
    }
    if(dist[T][0] == -1) cout << -1 << endl;
    else cout << dist[T][0]/3 << endl;
    return 0;
}

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

int main(){
  int N, C;
  cin >> N >> C;
  vector<vector<int> > Using(100001, vector<int>(C,0));
  for (int i=0; i<N; i++){
    int s, t, c;
    cin >> s >> t >> c;
    for (int j=s-1; j<t; j++) Using[j][c-1] = 1;
  }
  int ans = 0;
  for (int i=0; i<100001; i++){
    int sc = 0;
    for (int j=0; j<C; j++) sc += Using[i][j];
    ans = max(ans, sc);
  }
  cout << ans << endl;
}


Measured memory_bytes: 15232
#include <iostream>
#include <cstdlib>

int solve(std::string str, char target){
    int ret = 0;
    const int length = str.length();
    int counter = 0;
    for (int i=0; i<length; ++i){
        if(target == str[i]){
            ret = std::max(ret, counter);
            counter = 0;
        }
        else {
            counter++;
        }
    }
    ret = std::max(ret, counter);
    return ret;
}

int main()
{
    std::string s;
    std::cin >> s;
    int ans = 101;
    for (int i=0; i<26; ++i){
        ans = std::min(ans, solve(s, 'a' + i));
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter

n = int(input())
arr = list(map(int, input().split()))

c = Counter(arr)

c = list(c.values())
c = [x - 1 for x in c if x > 1]

if len(c) == 0:
    print(n)
    sys.exit()

if len(c) == 0:
    print(n - 2 * sum(c))
    sys.exit()

print(n - (sum(c) + 1) // 2 * 2)

Measured memory_bytes: 18656
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 1011
#define mod 1000000007

int n, i, j;
vector<int> divs[maxN];
int p[maxN];

ll ans = 1;

int main()
{
    //freopen("test.in","r",stdin);

    scanf("%d", &n);
    for (i = 2; i <= n; i++) {
        if (divs[i].empty()) {
            for (j = i; j <= n; j += i)
                divs[j].pb(i);
        }

        int aux = i;
        for (auto d : divs[i]) {
            while (aux % d == 0) {
                aux /= d;
                p[d]++;
            }
        }
    }

    for (i = 1; i <= n; i++)
        ans = (ans * (p[i] + 1)) % mod;

    printf("%lld", ans);



    return 0;
}


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

int Dist(pair<int, int> P) { return P.first * P.first + P.second * P.second; }

int main() {
	vector<pair<int, int> > V;
	for (int i = 1; i <= 150; i++) {
		for (int j = i + 1; j <= 150; j++) {
			V.push_back({ i, j });
		}
	}
	sort(V.begin(), V.end(), [](pair<int, int> P1, pair<int, int> P2) {return Dist(P1) == Dist(P2) ? P1.first * P1.second < P2.first * P2.second : Dist(P1) < Dist(P2); });
	int H, W;
	while (cin >> H >> W) {
		if (H == 0 && W == 0) return 0;
		for (int i = 0; ; i++) {
			if (V[i].first == H && V[i].second == W) {
				cout << V[i + 1].first << ' ' << V[i + 1].second << endl;
				break;
			}
		}
	}
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int n, m;
vector<int> G[100010];
int in[100010], out[100010];
int d[100010];
bool f[100010];
int now = 0;
int tp[100010];
vector<int> p[100010];

void dfs(int v){
    if(f[v]) return;
    f[v] = true;
    for(auto i : G[v]){
        dfs(i);
    }
    tp[v] = now++;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    rep(i, 0, n - 1 + m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        out[a]++;
        in[b]++;
        p[b].push_back(a);
        G[a].push_back(b);
    }
    int root = -1;
    rep(i, 0, n){
        if(in[i] == 0){
            root = i; break;
        }
    }
    dfs(root);
    vector<int> ans(n);
    // rep(i, 0, n){
    //     cout << tp[i] << endl;
    // }
    rep(i, 0, n){
        if(i == root){
            ans[i] = -1;
            continue;
        }
        int MIN = INF, idx = -1;
        for(auto j : p[i]){
            if(tp[j] < MIN){
                MIN = tp[j];
                idx = j;
            }
        }
        ans[i] = idx;
    }
    rep(i, 0, n){
        cout << ans[i] + 1 << endl;
    }
}

Measured memory_bytes: 18944
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <numeric>
#include <iomanip>
#define FI first
#define SE second
#define MP make_pair
#define PB emplace_back
#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 1100000000
#define LLINF 1100000000000000000LL
#define Decimal fixed << setprecision(20)
#define ALL(c) c.begin(),c.end()
#define SHOWVEC(v, sz) for(int i = 0; i < sz; i++) cerr << v[i] << ' '; cerr << endl;
#define SHOWX(x) cerr << #x << ": " << x << endl;
#define SHOWP(p) cerr << "[" << p.first << ',' << p.second << "]";

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int cnt[110000];
int ans[110000];
vector<vector<pair<int, int>>> v(110000);
int mv;

void dfs(int now, int par, int col) {
  int cnt = 1;
  for (auto u : v[now]) {
    int to = u.FI, e = u.SE;
    if (to == par) continue;
    if (cnt == col) cnt++;
    ans[e] = cnt++;
    dfs(to, now, ans[e]);
  }
}

int main()
{
  int N; cin >> N;
  REP(i, N-1) {
    int a, b; cin >> a >> b;
    a--, b--;
    v[a].PB(MP(b, i));
    v[b].PB(MP(a, i));
    cnt[a]++;
    cnt[b]++;
  }

  REP(i, N) {
    if (cnt[mv] < cnt[i]) mv = i;
  }

  dfs(mv, -1, -1);
  cout << cnt[mv] << endl;
  REP(i, N-1) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 9728
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <thread>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int n;
    cin >> n;
    ll s=0;
    ll i=0;
    while(s<n){
        i++;
        s+=i;
    }
    ll hoge = s-n;
    for(int h =1;h<=i;h++){
        if(h!=hoge){
            cout << h << endl;
        }
    }
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15); 
    int n, N; 
    cin >> n;
    N = (1 << n); 
    vector<int> a(N); 
    vector<pair<int, int>> b(N, make_pair(0, 0));  
    for (int i = 0; i < N; ++i) cin >> a[i];
    for (int i = 0; i < N; ++i) {
        b[i].first = a[0];
        for (int j = i; j != 0; j = (j - 1) & i) {
            if (a[j] > b[i].first) b[i].second = b[i].first, b[i].first = a[j];
            else if (a[j] > b[i].second) b[i].second = a[j]; 
        }
    }
/*
    for (int i = 1; i < N; ++i) {
        cerr << b[i].first << ' ' << b[i].second << endl; 
    }
*/
    int ans = 0; 
    for (int i = 1; i < N; ++i) {
        ans = max(ans, b[i].first + b[i].second); 
        cout << ans << endl; 
    }
    return 0;  
}

Measured memory_bytes: 6144
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();
		long mod=1000000007;
		long[][] dp=new long[n+1][k+1];
		Arrays.fill(dp[0],1);
		for(int i=1; i<=n; i++){
			int a=sc.nextInt();
			dp[i][0]=dp[i-1][0];
			for(int j=1; j<=k; j++){
				dp[i][j]=dp[i-1][j]+dp[i][j-1];
				if(j-a-1>=0){
					dp[i][j]-=dp[i-1][j-a-1];
				}
				dp[i][j]=(dp[i][j]+mod)%mod;
			}
		}
		if(k==0){
			System.out.println(1);
		}else{
			System.out.println((dp[n][k]-dp[n][k-1]+mod)%mod);
		}
	}
}

Measured memory_bytes: 126292
#include<bits/stdc++.h>
#define M 1000000007
#define pb push_back
#define ll long long int
using namespace std;

int main()
{

	int n;
	cin>>n;
	double p[n];
	double heads[n][n+1];
	int i,j;
	for(i=0;i<n;i++)
		cin>>p[i];
	for(i=0;i<n;i++)
	{
		for(j=0;j<=n;j++)
		{
			if(j>i+1)
			{
				heads[i][j] = 0;
				continue;
			}
			if(i==0)
			{
				if(j==0)
				{
					heads[i][j] = 1-p[i];
				}
				else
				{
					heads[i][j] = p[i];
				}
			}
			else
			{
				if(j==0)
				{
					heads[i][j] = (1-p[i])*heads[i-1][j];
				}
				else
				{
					heads[i][j] = (1-p[i])*heads[i-1][j]+p[i]*heads[i-1][j-1];
				}
			}
		}
	}
	double ans = 0;
	for(i=n/2+1;i<=n;i++)
		ans += heads[n-1][i];
	printf("%.10lf",ans);
	return 0;
}


Measured memory_bytes: 74088
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
	int A,B,C,D;
	string S;
	cin >> S;
	A = S[0]-'0', B = S[1]-'0', C = S[2]-'0', D = S[3]-'0';
	     if (A + B + C + D == 7)printf("%d+%d+%d+%d=7\n",A,B,C,D);
	else if (A - B + C + D == 7)printf("%d-%d+%d+%d=7\n", A, B, C, D);
	else if (A + B - C + D == 7)printf("%d+%d-%d+%d=7\n", A, B, C, D);
	else if (A + B + C - D == 7)printf("%d+%d+%d-%d=7\n", A, B, C, D);
	else if (A - B - C + D == 7)printf("%d-%d-%d+%d=7\n", A, B, C, D);
	else if (A + B - C - D == 7)printf("%d+%d-%d-%d=7\n", A, B, C, D);
	else if (A - B + C - D == 7)printf("%d-%d+%d-%d=7\n", A, B, C, D);
	else printf("%d-%d-%d-%d=7\n", A, B, C, D);


	return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 1010

ll N;
ll T[MAX_N] = {};
ll A[MAX_N] = {};

signed main()
{
    cin >> N;
    REP(i, N) {
        cin >> T[i] >> A[i];
    }
    // 現在の得票数
    ll t = T[0], a = A[0];
    for(int i = 1; i < N; ++i) {
        DBG("%lld %lld\n", T[i], A[i]);
        // t を基準とした場合
        ll cand1_t, cand1_a;
        {
            ll next_t = t;
            if(next_t % T[i] != 0) { next_t = ((next_t / T[i]) + 1) * T[i]; }
            ll one_t = next_t / T[i];
            cand1_t = next_t;
            cand1_a = A[i] * one_t;
        }
        // a を基準とした場合
        ll cand2_t, cand2_a;
        {
            ll next_a = a;
            if(next_a % A[i] != 0) { next_a = ((next_a / A[i]) + 1) * A[i]; }
            ll one_a = next_a / A[i];
            cand2_a = next_a;
            cand2_t = T[i] * one_a;
        }
        DBG("  cand1: %lld %lld cand2: %lld %lld\n", cand1_t, cand1_a, cand2_t, cand2_a);
        if(cand1_t >= t && cand1_a >= a) {
            if( (cand2_t >= t && cand2_a >= a && cand1_t + cand1_a <= cand2_t + cand2_a)
                || (cand2_t < t || cand2_a < a) ){
                t = cand1_t; a = cand1_a;
            }
        }
        else if(cand2_t >= t && cand2_a >= a) {
            if( (cand1_t >= t && cand1_a >= a && cand1_t + cand1_a >= cand2_t + cand2_a)
                || (cand1_t < t || cand1_a < a) ){
                t = cand2_t; a = cand2_a;
            }
        }
        else {
            assert(false);
        }
        DBG("  t: %lld a: %lld\n", t, a);
    }
    printf("%lld\n", t + a);
    return 0;
}


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

using namespace std ;

#define Abs(x) ((x)>0?(x):-(x))
const int N=1e5+10 ;
const int inf=1e9+1 ;

int a[N] ;
int n ;
int main ()
{
    int i ;
    scanf("%d",&n);
    for ( i=1 ; i<=n ; i++ ) scanf("%d",a+i),a[i]+=a[i-1];
    int res=inf ;
    for ( i=1 ; i<n ; i++ ) res=min(res,Abs(2*a[i]-a[n]));
    printf("%d\n",res);
    return 0 ;
}

Measured memory_bytes: 256
#pypyは内包表記使わない
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N = int(input())
    print(N//3)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import java.util.*;

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

		Scanner scanner = new Scanner(System.in);
		
	    String S = scanner.next();

	    String T = scanner.next();

		int a = scanner.nextInt();
		int b = scanner.nextInt();
	    String U = scanner.next();
 if(U.equals(S)) {
	    	System.out.println((a-1)+" "+b);
	    }else if(U.equals(T)) {
	    	System.out.println(a+" "+(b-1));
	    }
	  		scanner.close();
    }

}



Measured memory_bytes: 22740
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


int main(){
    int n ;
    cin >> n  ;
    vector<char> s(n) ;
    for (size_t i = 0; i < n; i++)
    {
        cin >> s.at(i) ;
    }
    
    vector<int> r(n+1,0) ;
    vector<int> g(n+1,0) ;
    vector<int> b(n+1,0) ;
    vector<int> rr(n+2,0) ;
    vector<int> rg(n+2,0) ;
    vector<int> rb(n+2,0) ;
    for (size_t i = 0; i < n; i++)
    {
        if (s.at(i) == 'R')
        {
            r.at(i+1) ++ ;
        }else if (s.at(i) == 'G')
        {
            g.at(i+1) ++ ;
        }else if (s.at(i) == 'B')
        {
            b.at(i+1) ++ ;
        }
        r.at(i+1) += r.at(i) ;
        g.at(i+1) += g.at(i) ;
        b.at(i+1) += b.at(i) ;
    }
    for (size_t i = s.size()-1; i > 0; i--)
    {
        if (s.at(i) == 'R')
        {
            rr.at(i) ++ ;
        }else if (s.at(i) == 'G')
        {
            rg.at(i) ++ ;
        }else if (s.at(i) == 'B')
        {
            rb.at(i) ++ ;
        }
        rr.at(i) += rr.at(i+1) ;
        rg.at(i) += rg.at(i+1) ;
        rb.at(i) += rb.at(i+1) ;
    }
    int64_t ans = 0;
    int k ;
    for (size_t i = 0; i < n-2; i++)
    {
        for (size_t j = i+1; j < n-1; j++)
        {
            if (s.at(i) == s.at(j) )
            {
                continue ;
            }
            if ((s.at(i) == 'R' && s.at(j) == 'B') || (s.at(i) == 'B' && s.at(j) == 'R'))
            {
                k = min(2*j-i,n) ;
                ans += g.at(k) - g.at(j+1) +rg.at(k+1) ;
            }else if ((s.at(i) == 'G' && s.at(j) == 'B') || (s.at(i) == 'B' && s.at(j) == 'G'))
            {
                k = min(2*j-i,n) ;
                ans += r.at(k) - r.at(j+1) +rr.at(k+1) ;
            }else if ((s.at(i) == 'R' && s.at(j) == 'G') || (s.at(i) == 'G' && s.at(j) == 'R'))
            {
                k = min(2*j-i,n) ;
                ans += b.at(k) - b.at(j+1) +rb.at(k+1) ;
            }
            
        }
        
    }
    cout << ans << endl ;
}

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

int main() {
  char s;
  int N;
  int i = 0;

  cin >> N;

  for(i = 0;i < N;i++){
    cin >> s;

    if(s == 'Y'){
      cout << "Four" << endl;
      break;
    }
  }

  if(i == N){
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
/*
  __________    							|										   ___  __
	|       |     						    |											|   /
	|       |     						    |									  		|  /
	|       |                               |                         __                | /      _______
	|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
	| \               | |      | |          |      |          | / | /   |               |\       |
	|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
	|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
  __|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int 				long long
#define ull 				unsigned long long int
#define ld 					long double
#define vi 					vector<int>
#define vii 				vector<pair<int,int>>
#define vvi 				vector<vector<int>>
#define pf 					push_front
#define popb 				pop_back
#define pb 					push_back
#define eb 					emplace_back
#define pii 				pair<int,int>
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define mset(a,b) 			memset(a,b,sizeof(a))
#define mcpy(a,b) 			memcpy(a,b,sizeof(a))
#define fo0(i,n) 			for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) 			for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) 			for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)			for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)			for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define inf 1e18
const int mod=1e9+7;
const int N=4e5+10;

void solve(){
	int a,b;cin>>a>>b;
	if(a==b)
		cout<<"Yes";
	else
		cout<<"No";
}

int32_t main()
{
	
	fast;int t=1;
	//cin>>t;
	while(t--){
		solve();
	}

}

Measured memory_bytes: 256
#!/mnt/c/Users/moiki/bash/env/bin/python
A,B,C = list(map(int, input().split()))

# ans = min(C-(A+B-1), C) + 
ans = 0
if (C-1) >= (A+B):
    # print("True")
    ans += A+B+1
else:
    # print("else")
    ans += C
ans += B
print(ans)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int a,b,c;
  std::cin >> a >> b >> c;
  int surplus = a%b, d = a%b;
  while(d != 0) {
    if(d == c){
      std::cout << "YES" << '\n';
      return 0;
    }
    d += surplus;
    d %= b;
  }

  std::cout << "NO" << '\n';
  
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define mst(a,b) memset((a),(b),sizeof(a))
#define PII pair<int,int>
using namespace std;
template<class T>inline void read(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;
const int maxn=200050;
ll n,k,sum[maxn];
map<ll,ll> mp;
ll ans;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++) read(sum[i]);
	for(int i=1;i<=n;i++) sum[i]+=sum[i-1];
	mp[0]++;
	for(int i=1;i<=n;i++)
	{
		if(i>=k) mp[(sum[i-k]-(i-k))%k]--;
		ans+=mp[(sum[i]-i)%k];
		mp[(sum[i]-i)%k]++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 14336
import sys
input = sys.stdin.readline


def main():
    S = input().rstrip()

    y, m, d = map(int, S.split("/"))
    if y <= 2018:
        ans = "Heisei"
    elif y == 2019:
        if m <= 3:
            ans = "Heisei"
        elif m == 4:
            if d <= 30:
                ans = "Heisei"
            else:
                ans = "TBD"
        else:
            ans = "TBD"
    else:
        ans = "TBD"

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
import itertools
L,R = list(map(int,input().split()))
if R-L >= 2020:
  print(0)
  exit()
N_list = [i for i in range(L,R+1)]
P = itertools.combinations(N_list,2)
P = list(P)
ans = L*(L+1)%2019
for p in P[1:]:
    ans = min(ans,p[0]*p[1]%2019)
print(ans)

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

int main(){
    string str;
    int K;
    cin >> K;
    cin >>str;
    if(str.size() <= K){
        cout << str <<endl;
        
        return 0;
    }
    string str2;
    str2 = str.substr(0,K);
    cout << str2 + "..." <<endl;
    
    return 0;
}


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

int main () {
    int N, K, Q;
    cin >> N >> K >> Q;
    int A[Q], point[N], count[N];
    for (int i = 0; i < Q; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        point[i] = K - Q;
        count[i] = 0;
    }

    sort(A, A+Q);
    int j = 0;
    
    for (int i = 0; i < N; i++) {
        while (A[j] == i+1 && j < Q) {
            count[i]++;
            j++;
        }
    }
       
    for (int i = 0; i < N; i++) {
        point[i] += count[i];
        if (point[i] > 0) 
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }

    return 0;
}

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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll n;
    cin >> n;
    vector<ll> h(n);
    REP(i, n) cin >> h[i];
    ll ans = 0, tmp = 0;
    REP(i, n-1){
        if(h[i] >= h[i+1]) tmp++;
        else{
            ans = max(ans, tmp);
            tmp = 0;
        }
    }
    ans = max(ans, tmp);
    cout << ans;
    return 0;
}

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

string s;
int a[1000000];

int main()
{
	cin >> s;
		
	int n = s.length();

	for (int i = 0; i < n; i++)
	{
		if (s[i] == '<')
		{
			a[i + 1] = a[i] + 1;
			
		}
	}
	for (int i = n-1; i >= 0; i--)
	{
		if (s[i] == '>')
		{
			a[i] = a[i + 1] + 1;
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (s[i] == '<')
		{
			if(a[i+1] <= a[i])
				a[i + 1] = a[i] + 1;

		}
	}
	for (int i = n - 1; i >= 0; i--)
	{
		if (s[i] == '>')
		{
			if (a[i] <= a[i + 1])
				a[i] = a[i + 1] + 1;
		}
	}
	long sum = 0;
	for (int i = 0; i <= n; i++)
	{
		sum += a[i];
		//cout << a[i] << s[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 2820
#include <iostream>

using namespace std;

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

    int a, b;
    cin >> a >> b;

    int c1 = max(a, b);
    int c2 = max(c1 - 1, min(a, b));

    cout << c1+c2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
#define MAX 2000000
 
void MaxHeap(int*,int);
int Insert(int*,int);
int Extract(int*);
 
int h=0;
 
int main(void){
  int S[MAX],key=0;
  char states[8];
 
  while(1){
    scanf("%s", states);
 
    if(!strcmp(states, "end")) break;
    else if(!strcmp(states, "insert")){
      scanf("%d", &key);
      Insert(S, key);
    } else if(!strcmp(states, "extract")){
      Extract(S);
    }
 
  }
 
  return 0;
}
 
int Insert(int *S, int key){
  int i, tmp;
 
  h++; i = h;
  S[i] = key;
 
  while(i > 1 && S[i/2] < S[i]){
    tmp = S[i];
    S[i] = S[i/2];
    S[i/2] = tmp;
    i = i/2;
  }
 
  return;
}
 
int Extract(int *S){
  int max;
 
  max = S[1]; S[1] = S[h];
  h--;
 
  MaxHeap(S, 1);
  printf("%d\n", max);
 
  return;
}
 
void MaxHeap(int *S, int i){
  int left, right, large, tmp;
 
  if(i*2 <= h) left = i*2;
  else left = i;
 
  if(i*2+1 <= h) right = i*2+1;
  else right = i;
 
  if(left < h+1 && S[left] && S[left] > S[i]) large = left;
  else large = i;
 
  if(right < h+1 && S[right] > S[large]) large = right;
 
  if(large != i){
    tmp = S[i];
    S[i] = S[large];
    S[large] = tmp;
    MaxHeap(S, large);
  }
 
    return;
}

Measured memory_bytes: 6196
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long k,a,b;
    cin>>k>>a>>b;
    if(a>=b-2||1+k<=a){
        cout<<k+1;
    }
    else{
        k-=a-1;
        cout<<a+(k/2)*(b-a)+k%2;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]
int gcd(int x, int y)
{
    if(y==0)
        return x;
    return gcd(y, x%y);
}

 long long numbers[500005];

//int a[100005];

 int main(){

 long long n,Q,sum=0; cin>>n;
 int a[n];

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

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

 cin>>Q;

 while(Q--){

  long long x,y;
  cin>>x>>y;

  sum = sum-b[x]*x+b[x]*y;
  b[y]  += b[x];
  b[x] = 0;

   if(Q!=0)
    cout<<sum<<endl;
   else
    cout<<sum<<endl;

 }

 return 0;
 }

Measured memory_bytes: 4748
//#############################################################################
//----------------------------Karma is Real------------------------------------
#include "bits/stdc++.h"
//#############################################################################
//Macros 
#define MOD 1000000007
#define eb emplace_back
#define mp make_pair
#define fr first
#define sc second
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
//Type Defs
typedef long long ll;
typedef unsigned long long ull;
//#############################################################################
using namespace std;
//#############################################################################
//Helpers
void io_handler()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
void print_matrix(vector<vector<ll>> mat){
    for(auto row: mat){
        for(auto e : row){cout << e << " ";}
        cout << endl;
    }
}
void print_vector(vector<ll> vec){
    for(auto e : vec){cout<< e <<" ";}
    cout<<endl;
}
map<int,int> get_count(vector<ll> vec){
    map<int,int> count;
    for(auto e: vec){
        if(count.find(e)!=count.end()){count[e]++;}
        else{count[e] = 1;}}
    return count;
}
//#############################################################################
//Solution
void solve(){
    ll n,w;
    cin>>n>>w;
    vector<ll> wt(n),val(n);
    for(ll i = 0; i<n; i++){
        cin>>wt[i]>>val[i];
    }
    vector<ll> tmp(w+1,0);
    vector<ll> dp(w+1,0); 

    for(ll i = 0; i<n; i++){
        for(ll j = 0; j<=w; j++){
            if(j-wt[i]>=0){
                tmp[j] = max(dp[j],val[i]+dp[j-wt[i]]);
            } else {
                tmp[j] = dp[j];
            }            
        }
        swap(tmp,dp);
    }
    cout<<dp[w]<<endl;
}
//#############################################################################
//Driver
int main()
{
    io_handler();
    int t = 1;
    //cin>>t;
    for (int i = 0; i < t; i++){
        solve();
    }
    return 0;
}
//#############################################################################

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

int main() {
   string a,b;
   cin >>a >>b;
   
   int n = (int)a.length();
   int m = (int)b.length();
   
   int dp[n+1][m+1];
   memset(dp, 0, sizeof(dp));
   
   for(int i=1;i<=n;i++){
       for(int j=1;j<=m;j++){
           if(a[i-1]==b[j-1]){
               dp[i][j] = 1+dp[i-1][j-1];
           }
           else{
               dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
           }
       }
   }
   
   string s("");
   
   int i=n,j=m;
   
   while(i>0 && j>0){
       if(a[i-1]==b[j-1]){
           s.pb(a[i-1]);
           i--;   j--;
       }
       else if(dp[i-1][j] > dp[i][j-1]){
           i--;
       }
       else{
           j--;
       }
   }
   reverse(s.begin(), s.end()); 
       
   cout<<s;
    
    return 0;
}

Measured memory_bytes: 38792
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

int dp[105][4][2];

int main() {
    string upper;
    cin >> upper;
    int N = upper.size();
    int K;
    cin >> K;
    dp[0][0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 2; k++) {
                int digit_num = upper[i] - '0';
                for (int d = 0; d < 10; d++) {
                    int next_i = i + 1, next_j = j, next_k = k;
                    if (d != 0) {
                        next_j++;
                    }
                    if (next_j > K) {
                        continue;
                    }
                    if (k == 0) {
                        if (d > digit_num) {
                            continue;
                        }
                        if (d < digit_num) {
                            next_k = 1;
                        }
                    }
                    dp[next_i][next_j][next_k] += dp[i][j][k];
                }
            }
        }
    }
    int ans = dp[N][K][0] + dp[N][K][1];
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 384
# from math import gcd
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)


N, M = map(int, input().split())
S = input()
T = input()

if N > M:
  N, M = M, N
  S, T = T, S

i = 0

while True:
  i += 1
  L = i*lcm(N, M)
  N_list = [(L//N)*k + 1 for k in range(N)]
  M_list = [(L//M)*k + 1 for k in range(M)]

  # print(N_list)
  # print(M_list)

  memo = {}

  for idx, n in enumerate(N_list):
    memo[n] = S[idx]

  for idx, m in enumerate(M_list):
    if m in memo.keys():
      if memo[m] != T[idx]:
        break
  else:
    print(L)
    exit(0)

  # if L == N*M:
  break

print(-1)


Measured memory_bytes: 17892