akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define INF 1145141919810893931
using namespace std;

void func(vector<ll> &a,ll p,ll r) {
	vector<ll> temp_p(p-1);
	rep(i, p - 1) temp_p[i] = a[i];
	vector<ll> temp_r(r);
	rep(i, r) temp_r[i] = a[i + p - 1];
	rep(i, r) a[i] = temp_r[i];
	rep(i, p - 1) a[i + r] = temp_p[i];
}

int main() {
	ll n, r; cin >> n >> r;
	vector<ll> a;
	while (n && r) {
		a.resize(n);
		rep(i, n) a[i] = n - i;
		rep(i, r) {
			ll p, c; cin >> p >> c;
			func(a,p,c);
		}cout << a[0] << endl;
		cin >> n >> r;
	}
	return 0;
}

Measured memory_bytes: 3156
//  RAKSHIT KADAM
//USE LONG LONG INT ONLY WHEN ITS NECESSARY!!! OR ELSE IT MAY LEAD TO MLE OR RTE
 #include <bits/stdc++.h>
 
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
 #warning !!!check the size of arrayss!!!
 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define newMOD  998244353
 #define MAX 300006
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define INF 2000000000000000005

 #define vi vector<ll>
#define pi 3.1415926535897932384626433832795
#define Endl endl
#define lb lower_bound
#define ub upper_bound

using namespace std;
//ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}
 

//ll modInverse(int a, int m){ return power(a, m-2, m);} // if a and m are relativelyprime

void solve()
{
    ll n,k;cin>>n>>k;
    ll pre[n+3],suf[n+3];  ll a[n+3];
    for(ll i=0;i<=n+2;i++)pre[i]=suf[i]=a[i]=0;
  
    for(ll i=0;i<=n;i++)
    {
        a[i+1]=i;
    }
    for(ll i=1;i<=n+1;i++)
        (pre[i]=pre[i-1]+a[i])%=MOD;
    ll ans=0;
    for(ll i=n+1,j=1;i>0;i--,j++)
    {
        (suf[j]=suf[j-1]+a[i])%=MOD;
    }
    for(ll i=k;i<=n+1;i++)
    {
       ( ans+=suf[i]-pre[i]+1+2*MOD)%=MOD;
    }
    cout<<ans<<endl;
}
signed main()
{
 
   
    Need_for_speed(activated);
//satisfy
//    {
//   solve();
//    }

//
  solve();
    return 0;
}


Measured memory_bytes: 8336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int n,l,sum,mini,ans;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>l;
    for(int i=1;i<=n;i++){
        int f = l+i-1;
        sum+=f;
    }
    mini = INT_MAX;
    for(int i=1;i<=n;i++){
        int f = l+i-1;
        int temp = sum-f;
        int sel = abs(temp-sum);
        if(sel<mini){
            mini = sel;
            ans = temp;
        }
    }
    cout<<ans<<newl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    string s, t;
    cin >> s >> t;
    puts((t.substr(0, s.size()) == s ? "Yes" : "No"));

    return 0;
}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;

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

    if(n%2 == 0)
        impare = n/2;
    else
        impare = n/2 + 1;

    float rezultat = (float)impare / n;
    cout << rezultat << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++)
	{
		int s;
		cin>>s;
		a[i]=s;
	}
	sort(a+1,a+n+1);
	for(int i=2;i<=n;i++)
	if(a[i]==a[i-1])
	{
		cout<<"NO";
		return 0;
	}
	cout<<"YES";
	return 0;
 } 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
struct fast_ios { fast_ios(){cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast_ios_;

int main()
{
    int a, b;
    
    cin >> a >> b;
    vector<string> s(2);

    {
        string A;
        rep(i, b)
        {
            A.push_back(a+'0');
        }
        s[0] = A;
    }
    {
        string A;
        rep(i, a)
        {
            A.push_back(b+'0');
        }
        s[1] = A;
    }

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

    cout << s.front() << endl;

    
    return 0;
}

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

int main() {
  const std::pair<int32_t, int32_t> diff[4] = {
      {-1, 0}, {0, -1}, {0, 1}, {1, 0}};
  uint32_t H = 0, W = 0;
  std::cin >> H >> W;
  std::vector<std::string> grid(H + 2);
  grid[0] = std::string('.', W + 2);
  grid[H + 1] = std::string('.', W + 2);
  for (size_t i = 1; i < H + 1; i++) {
    std::string s;
    std::cin >> s;
    grid[i] = '.' + s + '.';
  }

  bool all_flag = true;
  for (size_t h = 1; h < H + 1 && all_flag; h++) {
    for (size_t w = 1; w < W + 1 && all_flag; w++) {
      if (grid[h][w] != '#') continue;
      bool flag = false;
      for (auto &&d : diff) {
        if (grid[h + d.first][w + d.second] == '#') {
          flag = true;
          break;
        }
      }
      if (!flag) {
        all_flag = false;
        break;
      }
    }
  }

  std::cout << (all_flag ? "Yes" : "No") << std::endl;

  return 0;
}

Measured memory_bytes: 256
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e4+5;

int n;
int m;
int valid;
int mem[N];
int cost[10];

int go(int lft){
    if(lft == 0)
        return 0;
    if(~mem[lft])
        return mem[lft];
    int bst = -1e2;
    for(int i = 1; i <= 9; i++){
        if(valid & (1 << i) && lft >= cost[i]){
            int ret = go(lft - cost[i]);
            if(ret != -1e2)
                bst = max(bst , ret + 1);
        }
    }
    return mem[lft] = bst;
}

vector < int > mine;

void build(int lft){
    for(int i = 9; i >= 1; i--){
        if(valid & (1 << i) && lft >= cost[i] && go(lft) >= 0 && go(lft - cost[i]) >= 0 && go(lft) == go(lft - cost[i]) + 1){
            mine.push_back(i);
            build(lft - cost[i]);
            break;
        }
    }
}

int main(){
    memset(mem , -1 , sizeof mem);
    cost[1] = 2;
    cost[2] = 5;
    cost[3] = 5;
    cost[4] = 4;
    cost[5] = 5;
    cost[6] = 6;
    cost[7] = 3;
    cost[8] = 7;
    cost[9] = 6;
    scanf("%d%d" , &n , &m);
    for(int i = 1; i <= m; i++){
        int x;
        scanf("%d" , &x);
        valid |= 1 << x;
    }
    int sz = go(n);
    build(n);
    sort(mine.rbegin() , mine.rend());
    for(auto v : mine)
        printf("%d" , v);
}



Measured memory_bytes: 512
from collections import Counter
import sys
N, M = map(int, input().split())

lis = []
for m in range(M):
    a, b = map(int, input().split())
    lis.append(a)
    lis.append(b)

for value in Counter(lis).values():
    if value % 2 != 0:
        print('NO')
        sys.exit()
print('YES')

Measured memory_bytes: 16000
#include <stdio.h>
int main(void){
  int n, i, j;
  scanf("%d", &n);
  int p[n], exp=0, sum=0;
  for(i=0; i<n; i++){
    scanf("%d", &p[i]);
    sum+=p[i];
    if(exp<=p[i])
      exp=p[i];
  }
  sum=sum-0.5*exp;
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <sstream>
#include <random>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#include <iostream>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <set>
#include <iomanip>

#define ll long long
#define mod 1000000007
using namespace std;

int computeFirstDigit(int a) {
    while(a >= 10) {
        a = a/10;
    }
    return a;
}


int main() {

    int n;
    cin>>n;

    int digits[10][10];
    for(int i = 0; i <= 9; i++) {
        for(int j = 0; j <= 9; j++) {
            digits[i][j] = 0;
        }
    }

    for(int i = 1; i <= n; i++) {
        digits[computeFirstDigit(i)][i%10] += 1;
    }

    ll total = 0;
    for(int i = 1; i <= 9; i++) {
        for(int j = 1; j <= 9; j++) {
            if(i == j) {
                total += digits[i][j]*digits[i][j];
            }
            else {
                total += digits[i][j]*digits[j][i];
            }
        }
    }
    cout<<total<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define MAX 100000

struct Person{
    int id;
    bool flag;
    std::vector<int> child;
    int label;
};

Person p[MAX];
int stack[MAX];
int sp = 0;

void push(int id){
    stack[sp++] = id;
    p[id].flag = true;
}

void pop(){
    sp--;
}

void dfs(int id,int k){
    p[id].label = k;
    push(id);
    int size = p[id].child.size();
    for(int i=0;i<size;i++){
        if(p[p[id].child[i]].flag == false){
            dfs(p[id].child[i],k);
        }
    }
    pop();
}

int main(){
    int n,m;
    int s,t,q;
    std::cin >> n >> m;
    
    for(int i=0;i<m;i++){
        std::cin >> s >> t;
        p[s].child.push_back(t);
        p[t].child.push_back(s);
    }
    
    for(int i=0;i<n;i++){
        p[i].id = i;
        if(p[i].flag == false){
            dfs(i,i);
        }
    }
    
    std::cin >> q;
    for(int i=0;i<q;i++){
        std::cin >> s >> t;
        if(p[s].label == p[t].label){
            std::cout << "yes\n";
        }else{
            std::cout << "no\n";
        }
    }
    
    return 0;
}



Measured memory_bytes: 15160
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

string s;
int main() {
    cin >> s;
    int slen = s.length();
    int maxlen = 0;
    for(int i = 0; i < slen; ++i) {
        int cnt = 0;
        for(int j = i; j < slen; ++j ) {
            if(s.at(j) == 'A' || s.at(j) == 'C' || s.at(j) == 'G' || s.at(j) == 'T') cnt++;
            else break;
        }
        chmax(maxlen, cnt);
    }
    cout << maxlen << endl;
}

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

// Common file
#include <ext/pb_ds/assoc_container.hpp>
// Including tree_order_statistics_node_update
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>



#define pb push_back
#define F first
#define S second
#define rep(i,n) for(int i = 0; i < (n); i++)

using ll = long long;
using ld = long double;
using ul = unsigned long long;
using ii = pair<int, int>;
#define Mosta     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ReadFile            freopen("input.in","r",stdin)
#define WriteFile           freopen("output.txt","w",stdout)
const ll mod7 = 1000000007,mod = 1000000000,OO = 0x3f3f3f3f;
const ld EPS = 1e-7;
double Pi=acos(-1);
const ld rad=Pi/180.0;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
            y = y>>1;
            x = (x*x) % p;
    }
    return res;
}
ll nCr (ll n,ll m)
{
    return(m == 0)?1:n*nCr(n-1,m-1)/m;
}

/*****************************************************/

const int N = 2e5 + 3;
ll a[N] , af[N] , b[N] , bf[N] , n , m , k , ans = 0;
ll rem_book = 0;

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

    rep(i , n)
        cin >> a[i];
    rep(i , n)
        af[i + 1] = af[i] + a[i];

    rep(i , m)
        cin >> b[i];
    rep(i , m)
        bf[i + 1] = bf[i] + b[i];

    rep(i , n + 1) {
        rem_book= k - af[i];
        if(rem_book < 0)
            continue;
        ll remToK = lower_bound(bf , bf + m , rem_book) - bf;

        if(remToK > m || bf[remToK] > rem_book)
            --remToK;

        ans = max(ans , i + remToK);
        //cout << "ans: " << ans << " i: "
        //<< i << " rem_book: " << rem_book << " remToK: " << remToK << "\n";
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 9848
#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 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 10010

ll N, M;
vector<ll> A;
// 数字 i を作るときに必要なマッチの本数
ll need[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

// -1: 未検証 0: 作れなかった 1: 作れた
ll dp1[MAX_N] = {};
string dp2[MAX_N];

// n1 > n2 なら true
static inline bool comp(string n1, string n2) {
    if(n1.length() != n2.length()) { return (n1.length() > n2.length()); }
    REP(i, n1.length()) {
        int num1 = n1[i] - '0';
        int num2 = n2[i] - '0';
        if(num1 != num2) { return (num1 > num2); }
    }
    return false;
}

// 残りのマッチ棒が i 本の時の作成できる数の最大
string dfs(ll i) {
    assert(i >= 0);
    if(i == 0) {
        dp1[i] = 1;
        return "";
    }

    ll& made = dp1[i];
    if(~made) { return dp2[i]; }
    string& ret = dp2[i];
    ret = "";

    REP(j, M) {
        if(need[A[j]] <= i) {
            string tmp = to_string(A[j]) + dfs(i - need[A[j]]);
            if(dp1[i - need[A[j]]] == 1 && !comp(ret, tmp)) {
                ret = tmp;
            }
        }
    }
    made = (ret.length() < 1) ? 0 : 1;
    return ret;
}

string solve() {
    MINUS(dp1);
    return dfs(N);
}

signed main()
{
    cin >> N >> M;
    A.resize(M);
    REP(i, M) { cin >> A[i]; }
    string res = solve();
    printf("%s\n", res.c_str());
    return 0;
}


Measured memory_bytes: 31104
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

lint LCM(lint a,lint b){
  if(a==0 || b==0) return 0;
  lint tmp,r,x;
  x=a*b;
  if(a<b) tmp=a,a=b,b=tmp;
  r=a%b;
  while(r!=0) a=b,b=r,r=a%b;
  x=x/b;
  return x;
}

lint GCD(lint a,lint b){
  if(a==0 || b==0) return max(a,b);
  else return (a*b)/LCM(a,b);
}

int main(void){
    lint A,B;
    cin >> A >> B;
    cout << LCM(A,B) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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 maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    /*
    ll n=1;
    while(1){
        if(n*n*n*n*n-(n-1)*(n-1)*(n-1)*(n-1)*(n-1)>pw10[9]) break;
        n++;
    }
    cout<<n<<endl;
    return 0;
     */
    ll X; cin>>X;
    FOR(A,-123,124)FOR(B,-123,124){
        if((A*A*A*A*A-B*B*B*B*B)==X){
            cout<<A<<" "<<B<<endl;
            return 0;
        }
    }
}



Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
void solve(){
    int k;
    string s;
    cin>>k;
    cin>>s;
    if(s.length()<=k) cout<<s;
    else
    {
        for(int i=0;i<k;i++){
            cout<<s[i];
        }
        cout<<"...";
    }
}
int  main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
    //cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3644
#include<iostream>、
using namespace std;
int main() {
    int N, res; //数字个数、交换次数
    int num[150];//储存数字
    cin >> N;
    for(int i = 0; i < N; i++) { //读取数据
        cin >> num[i];
    }
    for(int i = 0 ; i < N ; i++) {
        int minIndex = i;//当前位置后最小数的索引
        for(int j = i; j < N; j++) { //寻找更小的数
            if(num[j] < num[minIndex]) {
                minIndex = j;
            }
        }
        if(minIndex != i) { //找到更小的数则进行交换
            num[i] ^= num[minIndex];
            num[minIndex] ^= num[i];
            num[i] ^= num[minIndex];
            res++;//计数
        }
    }
    for(int i = 0; i < N; i++) {//输出数组
        cout << num[i];
        if(i < N - 1) cout << ' ';
    }
    cout << "\n" << res << endl;//输出交换次数
    return 0;
}



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

typedef long long ll;

int main() {
    
    ll a,b,c;
    cin >> a >> b >> c;
    ll ans = 0;
    if( a%2 == 0 or b%2 == 0 or c%2 == 0) {
	ans = 0;
    }
    else {
	ans = min(a*b, min(b*c,c*a));
    }
    cout << ans << endl;
    
    
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main(){
	int n;
	cin>>n;
	vvi G(n);
	vi h(n);
	int co=0;
	rep(i,n){
		int m;
		cin>>m;
		vi t(m);
		bool q=false;
		rep(j,m)cin>>t[j];
		rep(j,m)if(i+1==t[j])q=true;
		if(q)co++;
		else{
			rep(j,m){
				int a=t[j];
				if(i+2==a)h[i]=1;
				else if(i+1==a){
					co++;
				}else G[a-1].pb(i);
			}
		}
	}
//	show1d(h);
//	show2d(G);

	rep(i,n)if(h[i]){
		int l=i,r;
		while(h[i])i++;
		r=i;
		vp in;
		loop(j,l,r)rep(k,G[j].size())
			if(G[j][k]<=r)in.pb({G[j][k],j});
		
		sort(all(in));
//		cout<<l<<" "<<r<<endl;
//		rep(j,in.size())cout<<" "<<in[j].first<<" "<<in[j].second<<endl;
//		cout<<endl;
		int t=-1;
		rep(j,in.size()){
			if(t<in[j].second){
				co++;
				t=in[j].first;
			}
		}
	}
	cout<<co<<endl;
	
}










Measured memory_bytes: 6828
n = int(input())
a = [int(x) for x in input().split()]
from collections import defaultdict
d = defaultdict(int)
for i in a:
  d[i] += 1

total = 0
for i in set(a):
  x = d[i]
  total += x*(x-1)/2

for i in a:
  x = d[i]
  print(int(total-((x*(x-1)/2))+((x-1)*(x-2)/2)))

Measured memory_bytes: 26144
#include<stdio.h>
int n;
int A[2000001];
int B[2000001];
void CountingSort(int *,int *,int k);
int main(){
  int i;
  int mx=0;
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%d",&A[i]);
    if(mx<A[i]) mx=A[i];
  }
  CountingSort(A,B,mx);
  
  return 0;
}

void CountingSort(int A[],int B[],int k){
  int C[10001];
  int i,j;
  for(i=0;i<=k;i++) C[i]=0;
  for(i=0;i<n;i++) C[A[i]]++;
  for(i=1;i<=k;i++) C[i]+=C[i-1];
  /*
  for(i=0;i<=k;i++){
    printf("%d\n",C[i]);
  }
  */
  for(j=n-1;j>=0;j--) {
    B[C[A[j]]-1] = A[j];
    C[A[j]]--;
  }

  for(i=0;i<n;i++){
    printf("%d",B[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n");
}



Measured memory_bytes: 17360
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
#include <cmath>
int main() {
    static const double pi = acos(-1);
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    double th = 2 * pi * (H * 60 + M) / 720;
    double tm = 2 * pi * M / 60;
    double theta  = th - tm;
    double ans;
    ans = sqrt(A * A + B * B - 2 * A * B * cos(theta));

    printf("%.10f\n",ans);
      
    return 0;
}

Measured memory_bytes: 4208
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  map<int, int> odd, even;
  rep(i, n) {
    if (i % 2 == 0)
      odd[v[i]]++;
    else
      even[v[i]]++;
  }

  int num_even1 = 0, num_even2 = 0, num_odd1 = 0, num_odd2 = 0;
  int times_even1 = 0, times_even2 = 0, times_odd1 = 0, times_odd2 = 0;

  //偶数番目最大値
  int count = 0;
  for (auto itr = even.begin(); itr != even.end(); itr++) {
    if (itr->second > count) {
      count = itr->second;
      num_even1 = itr->first;
    }
  }
  times_even1 = count;

  //偶数番目二番目に大きい値
  count = 0;
  for (auto itr = even.begin(); itr != even.end(); itr++) {
    if (itr->second > count && itr->first != num_even1) {
      count = itr->second;
      num_even2 = itr->first;
    }
  }
  times_even2 = count;

  //奇数番目最大値
  count = 0;
  for (auto itr = odd.begin(); itr != odd.end(); itr++) {
    if (itr->second > count) {
      count = itr->second;
      num_odd1 = itr->first;
    }
  }
  times_odd1 = count;

  //奇数番目二番目に大きい値
  count = 0;
  for (auto itr = odd.begin(); itr != odd.end(); itr++) {
    if (itr->second > count && itr->first != num_odd1) {
      count = itr->second;
      num_odd2 = itr->first;
    }
  }
  times_odd2 = count;

  //出力
  if (num_even1 == num_odd1) {
    cout << min(n - times_even1 - times_odd2, n - times_even2 - times_odd1)
         << endl;
  } else {
    cout << n - times_even1 - times_odd1 << endl;
  }
  return 0;
}

Measured memory_bytes: 8220
/*

  _|_|                              _|  _|    _|
_|    _|  _|  _|_|  _|_|_|_|        _|  _|  _|
_|    _|  _|_|          _|          _|  _|_|
_|    _|  _|          _|      _|    _|  _|  _|
  _|_|    _|        _|_|_|_|    _|_|    _|    _|

*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
//#define ls (rt<<1)
//#define rs (rt<<1|1)
#define vi vector<int>
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define fi first
#define se second
typedef long long ll;
using namespace std;
const int maxn=5005;
int n,a,b;
ll dp[maxn];
int main(){
    ios::sync_with_stdio(0);
    memset(dp,0x3f,sizeof(dp));dp[0]=0;
    cin>>n>>a>>b;
    rep(i,1,n){
        int num;cin>>num;
        ll mi=1e18;
        rep(j,0,num)mi=min(mi,dp[j]);
        rep(j,0,num-1)dp[j]+=a;
        rep(j,num+1,n)dp[j]+=b;
        dp[num]=min(dp[num],mi);
    }
    ll ans=1e18;
    rep(i,1,n)ans=min(ans,dp[i]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3648
// SeeAlso: https://atcoder.jp/contests/abc142/tasks/abc142_a

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }


int N;

int main() {

    cin >> N;
    int a = N/2+N%2;
    double n = N;
    double ans = a/n;
    print(ans); 
    return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    A, B, K = MI()

    if K <= A:
        print(A - K, B)
    else:
        K -= A
        print(0, max(B - K, 0))


if __name__ == '__main__':
    main()


Measured memory_bytes: 64812
n=int(input())
if n%3==0:
    for i in range(n//3):
        print("a.."*(n//3))
        print("a.."*(n//3))
        print(".aa"*(n//3))
elif n%2==0 and n>=4:
    x="aacd"+"."*(n-4)
    y="bbcd"+"."*(n-4)
    for i in range(n//2):
        print(x)
        print(y)
        x=x[2:]+x[:2]
        y=y[2:]+y[:2]
elif n>=13:
    x="aacd"+"."*(n-13)
    y="bbcd"+"."*(n-13)
    for i in range((n-9)//2):
        print(x+"."*9)
        print(y+"."*9)
        x=x[2:]+x[:2]
        y=y[2:]+y[:2]
    for i in range(3):
        print("."*(n-9)+"a..a..a..")
        print("."*(n-9)+"a..a..a..")
        print("."*(n-9)+".aa.aa.aa")   
elif n==5:
    print("aabba")
    print("bc..a")
    print("bc..b")
    print("a.ddb")
    print("abbaa")
elif n==7:
    print("aabbcc.")
    print("dd.dd.a")
    print("..e..ea")
    print("..e..eb")
    print("dd.dd.b")
    print("..e..ec")
    print("..e..ec")
elif n==11:
    print("aabbcc.....")
    print("dd.dd.a....")
    print("..e..ea....")
    print("..e..eb....")
    print("dd.dd.b....")
    print("..e..ec....")
    print("..e..ec....")
    print(".......aacd")
    print(".......bbcd")
    print(".......cdaa")
    print(".......cdbb")
else:
    print(-1)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    ll a;ll sum=0;
    map<ll,ll> m;
    rep(i,n){
        cin>>a;
        m[a]++;
        sum+=a;
    }
    int q;cin>>q;
    ll b,c;vll ans(q);
    rep(i,q){
        cin>>b>>c;
        sum+=(c-b)*m[b];
        ans[i]=sum;
        m[c]+=m[b];
        m[b]=0;
    }
    rep(i,q)cout<<ans[i]<<endl;
}

Measured memory_bytes: 10024
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def isSame(self, x, y):
        return self.find(x) == self.find(y)

def solve():
    N,M = map(int,input().split())
    p = list(map(int,input().split()))
    uf = UnionFind(N)

    for i in range(M):
        x,y = map(int,input().split())
        x -= 1
        y -= 1
        uf.unite(x,y)
    
    ans = 0
    for i in range(N):
        if uf.isSame(p[i]-1,i):
            ans += 1
    
    print(ans)

if __name__ == '__main__':
    solve()

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

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

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

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

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

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

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

random_device seed_gen;
mt19937 engine(seed_gen());
// 0, 1, 2 のどれかが得られる一様分布
// uniform_int_distribution<> dist(0, 2);
// cout << dist(engine) << endl;
// みたいに、先に確率分布を宣言して、そこにengineを与えて使う。

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

int main()
{
  vector<bool> aho(60000000000,true);
  aho[0]=false;
  aho[59999999999]=false;
    ll n, x, t;
    cin >> n >> x >> t;
    ll m = n / x;
    if (n % x != 0)
    {
        ++m;
    }
    cout << t * m << endl;
    return 0;
}


Measured memory_bytes: 3156
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;
    if(a%2==1&&b%2==1)
       cout << "Odd" << endl;
    else
       cout <<"Even" <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define mm map<ii>
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast


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

    cout<<max(max(a+b,a*b),a-b);



    return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

T gcd(T)(T a, T b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

long calc(int[] a) {
    long m = 1;
    foreach (x; a) m = lcm(m, x);

    int ans = 0;
    return a.map!(e => (e - 1) % m).sum;
}

void main() {
    readint;
    auto a = readints;
    writeln(calc(a));
}


Measured memory_bytes: 2300
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int H,W;
    cin>>H>>W;
    char s[H][W];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>s[i][j];
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(s[i][j]=='#'){
                if(s[i-1][j]=='.'&&s[i+1][j]=='.'&&s[i][j-1]=='.'&&s[i][j+1]=='.'){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
n = int(input())
al = list(map(int,input().split()))

kabu = 0
money = 1000
for i in range(n-1):
    if al[i] < al[i+1]:
        # 全部売る
        money += kabu * al[i]
        kabu = 0
        # 全部買う
        kabu += money // al[i]
        money = money % al[i]
    else:
        # 全部売る
        money += kabu * al[i]
        kabu = 0

print(money+ kabu*al[-1])

Measured memory_bytes: 9092
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return ReadLine().Split().Select(int.Parse).ToList(); }

        static int N;
        static int[,] Move;
        static int[,] dp;
        static void Main(string[] args)
        {
            var S = ReadLine();
            var T = ReadLine();
            var dp = new int[T.Length + 1, S.Length + 1];

            for (var t = 1; t < T.Length + 1; ++t)
                for (var s = 1; s < S.Length + 1; ++s)
                {
                    if (T[t - 1] == S[s - 1])
                        dp[t, s] = dp[t - 1, s - 1] + 1;
                    else
                        dp[t, s] = Max(dp[t, s - 1], dp[t - 1, s]);
                }
            var chs = new List<char>();
            var ti = T.Length;
            var si = S.Length;

            var st = dp[ti, si];
            while (st != 0)
            {
                while (dp[ti, si - 1] == st) --si;
                while (dp[ti - 1, si] == st) --ti;
                chs.Add(S[si - 1]);
                --si; --ti;
                st = dp[ti, si];
            }
            chs.Reverse();
            WriteLine(string.Join("", chs));
        }
    }
}

Measured memory_bytes: 48224
def resolve():
    import sys
    sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
    to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
    print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

    # 入力を整数に変換して受け取る
    def input_int():
        return int(input())

    def map_int_input():
        return map(int, input())

    MII = map_int_input

    def MII_split():
        return map(int, input().split())

    def MII_to_index():
        return map(to_index, input())

    def MII_split_to_index():
        return map(to_index, input().split())

    # 入力全てを整数に変換したものの配列を受け取る
    def list_int_inputs():
        return list(map(int, input()))

    LII = list_int_inputs

    def LII_split():
        return list(map(int, input().split()))

    # 2次元リスト化
    def LII_2D(rows_number):
        return [LII() for _ in range(rows_number)]

    def LII_split_2D(rows_number):
        return [LII_split() for _ in range(rows_number)]

    N = input_int()
    As = LII_split()
    Q = input_int()

    d = dict()
    for i in range(int(1e5)):
        d[i + 1] = 0
    for A in As:
        d[A] += 1

    ans = sum(As)
    for _ in range(Q):
        B, C = MII_split()
        d[C] += d[B]
        ans += (C - B) * d[B]
        d[B] = 0
        print(ans)
        
resolve()

Measured memory_bytes: 24396
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main () {
  string S;
  cin >> S;
  if (S[0] == S[1] && S[1] == S[2]) {
    printf("No\n");
  } else {
    printf("Yes\n");
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
const int mod=1e9+7;

int num=0;

void marge(int a[], int left, int mid, int right){
	int n1 = mid-left;
	int n2 = right-mid;
	vector<int> a1(n1);
	for(int i=0; i<n1; i++)
		a1[i] = a[left+i];
	a1.push_back(INT_MAX);
	vector<int> a2(n2);
	for(int i=0; i<n2; i++)
		a2[i] = a[mid+i];
	a2.push_back(INT_MAX);
	int ltop = 0;
	int rtop = 0;
	for(int i=left; i<right; i++){
		if(a1[ltop]<=a2[rtop]){
			a[i] = a1[ltop];
			ltop++;
		}else{
			a[i] = a2[rtop];
			rtop++;
		}
		num++;
	}
}

void margeSort(int a[], int left, int right){
	if(left+1<right){
		margeSort(a, left, (left+right)/2);
		margeSort(a, (left+right)/2, right);
		marge(a, left, (left+right)/2, right);
	}
}

int main(){
	int n;
	cin >> n;
	int s[500000];
	for(int i=0; i<n; i++)
		cin >> s[i];
	margeSort(s, 0, n);
	for(int i=0; i<n; i++){
		if(i)
			cout << ' ';
		cout << s[i];
	}
	cout << endl;
	cout << num << endl;
	return 0;
}


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

const int INF = 1000000000;

int main() {
	int h, w; cin >> h >> w;
	vector<string>A(h); for (auto&& x : A)cin >> x;
	vector<vector<int>>G(h, vector<int>(w, INF));
	queue<pair<int, int>>que;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (A[i][j] == '#') {
				G[i][j] = 0;
				que.push({ i,j });
			}
		}
	}

	int ans = 0;
	int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
	while (!que.empty()) {
		int x = que.front().second, y = que.front().first;
		que.pop();
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i], ny = y + dy[i];
			if (0 > nx || 0 > ny || nx >= w || ny >= h || G[ny][nx] != INF)continue;
			G[ny][nx] = G[y][x] + 1;
			que.push({ ny,nx });
			ans = max(ans, G[ny][nx]);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 13456
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;

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

template<class T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

template<typename T>
struct SparseTable {
    vector<vector<T>> table;
    vector<int> power_index;
    const int n;
    
    SparseTable(vector<T>& v) : n((int)v.size()){
        int sz = 0;
        while((1 << sz) <= n)   ++sz;
        table.resize(sz, vector<T>(n));
        power_index.resize(n + 1);
        table[0] = v;
        for(int i = 1; i < sz; ++i){
            for(int j = 0; j + (1 << i) <= n; ++j){
                table[i][j] = min(table[i - 1][j], table[i - 1][j + (1 << (i - 1))]);
            }
        }
        for(int i = 2; i <= n; ++i){
            power_index[i] = power_index[i >> 1] + 1;
        }
    }
    
    T query(int l, int r){
        int p = power_index[r - l];
        return min(table[p][l], table[p][r - (1 << p)]);
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    --s, --t;
    vector<vector<P>> g1(n), g2(n);
    for(int i = 0; i < m; ++i){
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        --u, --v;
        g1[u].emplace_back(v, a);
        g1[v].emplace_back(u, a);
        g2[u].emplace_back(v, b);
        g2[v].emplace_back(u, b);
    }
    
    constexpr ll inf = 1e+18;
    auto dijkstra = [&](vector<vector<P>>& g, int root) -> vector<ll> {
        vector<ll> dist(n, inf);
        dist[root] = 0;
        using Data = pair<ll, int>;
        priority_queue<Data, vector<Data>, greater<Data>> que;
        que.emplace(0, root);
        while(!que.empty()){
            ll d = que.top().first;
            int from = que.top().second;
            que.pop();
            if(d > dist[from])  continue;
            for(auto& e : g[from]){
                int to = e.first, cost = e.second;
                if(chmin(dist[to], dist[from] + cost)){
                    que.emplace(dist[to], to);
                }
            }
        }
        return dist;
    };
    
    vector<vector<ll>> dist(2);
    dist[0] = dijkstra(g1, s);
    dist[1] = dijkstra(g2, t);
    
    vector<ll> min_cost(n);
    for(int i = 0; i < n; ++i)  min_cost[i] = dist[0][i] + dist[1][i];
    SparseTable<ll> table(min_cost);
    
    constexpr ll init_cost = 1e+15;
    for(int i = 0; i < n; ++i){
        cout << init_cost - table.query(i, n) << '\n';
    }
}

Measured memory_bytes: 31268
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
 
using namespace std;

int delete_piece();

int puzzle[10][5];
int h;

int main()
{
    while(1){
        cin >> h;
        if(h == 0) break;
        for(int i = h - 1; i >= 0; i--){
            for(int j = 0; j < 5; j++){
                cin >> puzzle[i][j];
            }
        }
        int get_score = 0;
        int total_score = 0;
        while(1){
            get_score = delete_piece();
            if(get_score == 0) break;
            else total_score += get_score;
        }
        cout << total_score << endl;
    }
    return 0;
}

int delete_piece()
{
    int sum_score = 0;
    for(int i = h - 1; i >= 0; i--){
        int delete_start = 0;
        int delete_end = 0;
        for(int j = 0; j < 3; j++){
            if(puzzle[i][j] != 0 && puzzle[i][j] == puzzle[i][j + 1] && puzzle[i][j] == puzzle[i][j + 2]){
                delete_start = j;
                if(j == 0){
                    if(puzzle[i][j] == puzzle[i][j + 3]){
                        if(puzzle[i][j] == puzzle[i][j + 4]) delete_end = 5;
                        else delete_end = 4;
                    } else delete_end = 3;
                } else if(j == 1){
                    if(puzzle[i][j] == puzzle[i][j + 3]) delete_end = 4;
                    else delete_end = 3;
                } else delete_end = 3;
                break;
            }
        }
        if(delete_end == 0) continue;
        sum_score += puzzle[i][delete_start] * delete_end;
        for(int j = delete_start; j < delete_start + delete_end; j++){
            puzzle[i][j] = 0;
        }
    }
    if(sum_score == 0) return 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < 5; j++){
            if(puzzle[i][j] == 0){
                if(i != h - 1){
                    for(int k = 1; i + k < h; k++){
                        if(puzzle[i + k][j] != 0){
                            puzzle[i][j] = puzzle[i + k][j];
                            puzzle[i + k][j] = 0;
                            break;
                        }
                    }
                } else puzzle[i][j] = 0;
            }
        }
    }
    return sum_score;
}

Measured memory_bytes: 1160