akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
print = sys.stdout.write

class Node:
    __slots__ = ["key", "priority", "left", "right"]
    def __init__(self, key, priority):
        self.key = key
        self.priority = priority
        self.left = None
        self.right = None
        
class Treap:
    def insert(self, node, key, priority):
        if node is None:
            return Node(key, priority)
        if key == node.key:
            return node
        if key < node.key:
            node.left = self.insert(node.left, key, priority)
            if node.priority < node.left.priority:
                node = right_rotate(node)
        else:
            node.right = self.insert(node.right, key, priority)
            if node.priority < node.right.priority:
                node = left_rotate(node)
        return node

    def delete(self, node, key):
        if node is None:
            return None
        if key < node.key:
            node.left = self.delete(node.left, key)
        elif key > node.key:
            node.right = self.delete(node.right, key)
        else:
            return self._delete(node, key)
        return node
    
    def _delete(self, node, key):
        if node.left is None and node.right is None:
            return None
        if node.left is None:
            node = left_rotate(node)
        elif node.right is None:
            node = right_rotate(node)
        else:
            if node.left.priority > node.right.priority:
                node = right_rotate(node)
            else:
                node = left_rotate(node)
        return self.delete(node, key)
    
    def find(self, node, key):
        if node is None:
            print("no\n")
            return
        while node:
            if node.key == key:
                print("yes\n")
                return
            node = node.left if key < node.key else node.right
        print("no\n")
        return
            

def right_rotate(node):
    child = node.left
    node.left, child.right = child.right, node
    return child

def left_rotate(node):
    child = node.right
    node.right, child.left = child.left, node
    return child

def print_preorder(node):
    print(" {}".format(node.key))
    if node.left:
        print_preorder(node.left)
    if node.right:
        print_preorder(node.right)

def print_inorder(node):
    if node.left:
        print_inorder(node.left)
    print(" {}".format(node.key))
    if node.right:
        print_inorder(node.right)

if __name__ == "__main__":
    n = int(input())
    treap = Treap()
    root = None
    for _ in range(n):
        operation, *num = input().split()
        if operation[0] == "i":
            root = treap.insert(root, int(num[0]), int(num[1]))
        elif operation[0] == "f":
            treap.find(root, int(num[0]))
        elif operation[0] == "d":
            root = treap.delete(root, int(num[0]))
        elif root is not None:
            print_inorder(root)
            print("\n")
            print_preorder(root)
            print("\n")


Measured memory_bytes: 32772
using System;
class Program{
  static void Main(string[] args){
    int n = int.Parse(Console.ReadLine());
    string[] v = Console.ReadLine().Split(' ');
    string[] c = Console.ReadLine().Split(' ');
    int p=0;
    for(int i=0;i<n;i++){
      if(int.Parse(v[i])-int.Parse(c[i])>0){
        p+=int.Parse(v[i])-int.Parse(c[i]);
      }
    }
    Console.WriteLine(p);
  }
}


Measured memory_bytes: 11092
/*
 *  AUTHOR : MANAV PATEl
*/
#include<bits/stdc++.h>
#include<functional>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

namespace fastio
{

	template <class T> istream &operator>>(istream &os, vector<T> & vec)
	{
		for (auto &u : vec)os >> u;
		return os;
	}
	template <class T> ostream &operator<<(ostream &os, const vector<T> & vec)
	{
		for (auto &u : vec)os << u << " ";
		return os;
	}
	template<class T1, class T2> inline istream& operator>>(istream& os, pair<T1, T2>& p)
	{
		return os >> p.first >> p.second;
	}
	template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p)
	{
		return os << p.first << " " << p.second;
	}
	template <class T> ostream &operator<<(ostream &os, set<T> & con)
	{
		for (auto &u : con) os << u << " ";
		return os;
	}
	void re() {}
	template <typename T, typename... args> void re(T& x, args&... tail)
	{
		cin >> x;
		re(tail...);
	}
	void pr() {}
	template <typename T> void pr(const T& x)
	{
		cout << x;
	}
	template <typename T, typename... args> void pr(const T& x, const args&... tail)
	{
		cout << x << " ";
		pr(tail...);
	}
	template <typename... args> void prln(const args&... tail)
	{
		pr(tail...);
		cout << "\n";
	}
}
using namespace fastio;

typedef long long int ll;
typedef long double ld;

const ll mod = 1e9+7;
const ll mod1 = 998244353;

#define fill(a)  memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back

int main()
{
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	int h, w, k, k1 = 1;
	re(h,w,k);
	string s[h];
	int arr[h][w];
	for(int i=0; i<h; i++) for(int j=0; j<w; j++) arr[i][j] = 0;
	for(int i=0; i<h; i++) cin>>s[i];
	for(int i=0; i<h; i++)
		for(int j=0; j<w; j++)
			if(s[i][j]=='#') arr[i][j] = k1, k1++;
	for(int i=0; i<h; i++)
	{
		int x = 0;
		for(int j=0; j<w; j++)
		{
			if(s[i][j]=='#') x = arr[i][j];
			else arr[i][j] = x;
		}
		for(int j = w-1;  j>=0; j--)
		{
			if(s[i][j]=='#') x = arr[i][j];
			if(arr[i][j]==0) arr[i][j] = x;
		}
	}
	for(int j=0; j<w; j++)
	{
		int x = 0;
		for(int i=0; i<h; i++)
		{
			if(arr[i][j]) x = arr[i][j];
			if(arr[i][j]==0) arr[i][j] = x;
		}
		for(int i=h-1; i>=0; i--)
		{
			if(arr[i][j]!=0) x = arr[i][j];
			if(arr[i][j]==0) arr[i][j] = x;
		}
	}
	for(int i=0; i<h; i++)
	{
		for(int j=0;  j<w; j++)
			cout<<arr[i][j]<<" ";
		prln();
	}
}




Measured memory_bytes: 1280
def main():
    N, K = list(map(int, input().split(' ')))
    S = input()
    char_change_cnt = 0
    before_char = S[0]
    for c in S:
        if before_char == c:
            continue
        before_char = c
        char_change_cnt += 1
    char_change_cnt -= min([char_change_cnt, 2 * K])
    print(N - char_change_cnt - 1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,k;
  cin>>n>>k;
  vll h(n);
  rep(i,n) cin>>h[i];
  vll dp(n,INF);
  dp[0]=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<min(n,k+i+1);j++){
      dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
    }
  }
  COUT(dp[n-1]);
}



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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

int main(){
  int N; ll L; cin >> N >> L ;
  ll s = 0;
  vl a(N);
  rep(i,N){
    cin >> a[i] ;
  }
  int idx = -1;
  rep(i,N-1){
    if(a[i]+a[i+1]<L) continue;
    idx = i;
    break;
  }
  if(idx==-1){
    cout << "Impossible" << endl;
    return 0;
  }
  cout << "Possible" << endl;
  rep(i,idx) cout << i+1 << endl;
  RREP(i,N-1,idx+1) cout << i << endl;
  return 0;
}


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


int main(){
      
       int n; cin >> n;
       set<int> s;
       int z = n;
       while(z--){
              
              int k; cin >> k;
              s.insert(k);
       }
    //   cout << s.size();
      // cout << n << endl;
       int l = s.size();
       if(n == l)
       cout << "YES" << endl;
       else
       cout << "NO" << endl;
}

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

int n,m,a[110],p;
vector<int>v;
int main(){
	cin>>n>>m;
	if (n==1) return 0*printf("1\n1\n1");
	for (int i=1;i<=m;++i) {
		cin>>a[i]; if (a[i]&1) v.push_back(i);
	}
	if (v.size()){
		swap(a[1],a[v[0]]);
		if (v.size()>1){
			swap(a[m],a[v[1]]);
			if (v.size()>2) return 0*puts("Impossible");
		}
	}
	for (int i=1;i<=m;++i) printf("%d ",a[i]);
	if (m==1) return 0*printf("\n2\n1 %d",n-1);
	p=--a[1]?1:2, ++a[m];
	printf("\n%d\n",m-p+1);
	for (int i=p;i<=m;++i) printf("%d ",a[i]);
}

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

#define REP(i, a) for (ll i = 0; i < (a); ++i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

void Main() {
  int N, M;
  cin >> N >> M;
  multiset<int> A;
  int a;
  REP(i, N) {
    cin >> a;
    A.insert(a);
  }
  REP(m, M) {
    auto itr = A.end();
    itr--;
    A.insert((*itr) / 2);
    A.erase(itr);
  }
  ll ans = 0;
  for (auto itr = A.begin(); itr != A.end(); itr++) {
    ans += *itr;
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
 long long  A,B,K;
  cin >> A >> B >> K;
  
  if(K>=A && K<A+B){
    cout << 0 << ' ' << B-(K-A) << endl;
  }
  if(K<A){
    cout << A-K << ' ' << B << endl;
  }
  if(K>=A+B){
    cout << 0 << ' ' << 0 <<endl;
  }
 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>

using namespace std;

typedef pair<int,int> Point;

int triarea(Point a,Point b,Point c){//(B-A)x(C-A)
	b.first-=a.first;
	b.second-=a.second;
	c.first-=a.first;
	c.second-=a.second;
	return b.first*c.second-b.second*c.first;
}

int main(){
	vector<Point> points;
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int tx,ty;
		cin >> tx >> ty;
		points.push_back(make_pair(tx,ty));
	}
	sort(points.begin(),points.end());
	
	Point lside=points.front(),rside=points.back();
	
	vector<Point> uhalf;
	uhalf.push_back(points.at(0));
	uhalf.push_back(points.at(1));
	for(int i=2;i<points.size();i++){
		Point p=points.at(i);
		while(true){
			Point q1=uhalf.at(uhalf.size()-2);
			Point q2=uhalf.at(uhalf.size()-1);
			
			int s=triarea(q1,q2,p);
			
			if(s<=0){
				break;
			}
			uhalf.erase(uhalf.end()-1);
			if(uhalf.size()<2){
				break;
			}
		}
		uhalf.push_back(p);
	}

	vector<Point> lhalf;
	lhalf.push_back(points.at(0));
	lhalf.push_back(points.at(1));
	for(int i=2;i<points.size();i++){
		Point p=points.at(i);
		while(true){
			Point q1=lhalf.at(lhalf.size()-2);
			Point q2=lhalf.at(lhalf.size()-1);
			
			int s=triarea(q1,q2,p);
			
			if(s>=0){
				break;
			}
			lhalf.erase(lhalf.end()-1);
			if(lhalf.size()<2){
				break;
			}
		}
		lhalf.push_back(p);
	}
	int startidx=0;
	int miny=lhalf.at(0).second;
	for(vector<Point>::iterator it=lhalf.begin()+1;it!=lhalf.end();it++){
		if(it->second>=miny){
			startidx;
			break;
		}
		miny=it->second;
		startidx++;
	}
	cout << lhalf.size()+uhalf.size()-2 << endl;
	for(int i=startidx;i<lhalf.size();i++){
		cout << lhalf.at(i).first << " " << lhalf.at(i).second << endl;
	}
	for(int i=uhalf.size()-2;0<i;i--){
		cout << uhalf.at(i).first << " " << uhalf.at(i).second << endl;
	}
	for(int i=0;i<startidx;i++){
		cout << lhalf.at(i).first << " " << lhalf.at(i).second << endl;
	}

}


Measured memory_bytes: 2832
def calc_area(v_end, v_start, v_max, dt):
    kouten_v = (v_end + v_start + dt) / 2
    kouten_t = kouten_v - v_start
    kouten_t_limit1 = max(v_max - v_start, 0)
    kouten_t_limit2 = min(v_end + dt - v_max, dt)
    if 0 < kouten_t < dt:
        area = (v_start + kouten_v) * kouten_t / 2
        area +=  (v_end + kouten_v) * (dt - kouten_t) / 2
        area -=  (kouten_t_limit2  - kouten_t_limit1) * max(0, (kouten_v - v_max)) / 2
    else:
        area = (v_start + v_end) *  dt / 2
    return area

n=int(input())
t=[int(i) for i in input().split()]
v=[int(i) for i in input().split()]

max_velocity = [0]
for i in range(1, n):
    max_velocity_ = min(v[i-1], v[i], max_velocity[i-1] + t[i-1], sum(t) - sum(t[:i]))
    max_velocity.append(max_velocity_)
max_velocity.append(0)

ok = 0
while ok==0:
    for i in range(n-1):
        if  abs((max_velocity[i+1]-max_velocity[i])/t[i]) >1:
                max_velocity[i]=max_velocity[i]-1
                break
    else:
        ok=1



ans = 0
for i in range(n):
    ans += calc_area(max_velocity[i+1], max_velocity[i], v[i], t[i])
print(ans)

Measured memory_bytes: 3064
a,b=map(float,input().split())
 
import math 
 
x=a//0.08 
 

f=0
for i in range(100000):
    x=i
    
 
    if a==math.floor(x*0.08) and b==math.floor(x*0.1) :
        print(i)
        f=1
        break
if f==0:
    print(-1)

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

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

        int N = Integer.parseInt(sc.next());
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        int max = -1;
        int max_index = -1;
        int second = -1;
        int second_index = -1;
        for (int i = 0; i < N; i++) {
            if (max < A[i]) {
                second = max;
                second_index = max_index;
                max = A[i];
                max_index = i;
            } else if (second < A[i]) {
                second = A[i];
                second_index = i;
            }
        }

        for (int i = 0; i < N; i++) {
            if (max_index == i) {
                out.printf("%d\n", A[second_index]);
            }
            else {
                out.printf("%d\n", A[max_index]);
            }
        }
        out.flush();
    }
}


Measured memory_bytes: 119164
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b){
  return *(int*)a - *(int*)b;
}
int main(void){
  int n,k,i,ans=0;
  scanf("%d %d",&n,&k);
  int d[n];
  for(i=0;i<n;i++){
    scanf("%d",&d[i]);
  }
  qsort(d,n,sizeof(int),compare_int);
  for(i=n-1;i>n-k-1;i--){
      ans=ans+d[i];
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n; ld l,r,x;
int main()
{
	scanf("%d%lf%lf",&n,&l,&x);
	r=(n*2-1)*x+l;
	ld ans=0;
	while(n)
	{
		ans+=(l+r)/2.0;
		ld d=(r-l)/(n*2-1);
		l=(l*3+d*5)/(2.0*n)+l*(ld)(2*n-1)/(2*n);
		r=(r*3-d*5)/(2.0*n)+r*(ld)(2*n-1)/(2*n);
		n--;
	}
	printf("%.15lf\n",ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

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

int main() {
    int A, B, K;
    scanf("%d %d %d", &A, &B, &K);

    vector<int> v;
    REP(A, i, min(A + K, B + 1)) {
        v.push_back(i);
    }

    REP(max(A, B - K + 1), i, B + 1) {
        v.push_back(i);
    }

    sort(v.begin(), v.end());
    vector<int>::iterator it = unique(v.begin(), v.end());
    v.erase(it, v.end());

    for (it = v.begin(); it != v.end(); ++it) {
        printf("%d\n", *it);
    }

    return 0;
}


Measured memory_bytes: 256
H, W = list(map(int, input().split()))
c = [input() for _ in range(H)]

moves = [(-1, 0), (1, 0), (0, -1), (0, 1)]

def bfs():
    visited = [[False for _ in range(W)] for _ in range(H)]
    dist = [[0 for _ in range(W)] for _ in range(H)]
    routes = [(0, 0)]
    visited[0][0] = True

    while len(routes) > 0:
        x, y = routes.pop(0)
        for move in moves:
            cx, cy = x + move[0], y + move[1]
            if cx < 0 or cy < 0 or cx >= W or cy >= H or c[cy][cx] == '#' or visited[cy][cx]:
                continue
            if cx == W-1 and cy == H-1:
                return sum([line.count('.')for line in c]) - dist[y][x] - 2
            visited[cy][cx] = True
            routes.append((cx, cy))
            dist[cy][cx] = dist[y][x] + 1
    return -1

print(bfs())

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

using namespace std;


int main()
{
        int n,x;
        cin>>n;
        set<int> s;
        map<int,int> m;
         
        for(int i=0;i<n;i++) cin>>x,s.insert(x),m[x]++;
        if(s.size()==1 && x==0)
        {
                cout<<"Yes";

        }
        else if(*s.begin()==0 && s.size()==2 && n%3==0)
        {
                auto it=s.begin();
                it++;
                if(m[0]==n/3)
                {
                        cout<<"Yes";
                }
                else
                {
                        cout<<"No";
                }
        }
        else if(s.size()!=3 || n%3)
        {
                cout<<"No";
        }
        else
        {
                int flag=1;

                vector<int> v;
                for(auto i:m)
                {v.push_back(i.first);
                if(i.second!=n/3) flag=0;}
                if((v[0]^v[1])!=v[2]) flag=0;
                cout<<(flag?"Yes":"No");

        } 

}





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

using namespace std;

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, a, b) for (int i = a; i < b; i++)

int main()
{
	int res = 0;
	int N;
	int a[100];
	cin >> N;
	rep(i, N) {
		cin >> a[i];
	}
	sort(a, a+N);
	int x = 1;
	rep(i, N) {
		res += a[i] * x;
		x *= -1;
	}
	cout << abs(res) << endl;
	return 0;
}

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

typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
int main(void)
{
  bool prime[1048576];
  REP(i,1048576) prime[i]=true;
  prime[0]=false;
  prime[1]=false;
  REP(i,sqrt(1048576)+10){
    if(prime[i]) for(int j=i*i;j<1048576;j+=i) prime[j]=false;
  }
  for(;;){
    int a,d,n;
    cin >> a >> d >> n;
    if(!a&&!d&&!n) return 0;
    int answer=a;
    while(n--){
      while(!prime[answer]) answer+=d;
      answer+=d;
    }
    cout << answer-d << endl;
  }
}

Measured memory_bytes: 2184
def gcd(a, b):
	k = 0
	while b != 0:
		r = a % b
		a, b = b, r
		k += 1
	return [a, k]

while True:
	x, y = list(map(int, input().split()))
	if x == 0: break
	if x < y: x, y = y, x
	ans = gcd(x, y)
	print(*ans)





Measured memory_bytes: 5608
import sys
import os

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

N = int(input())
listN = make_divisors(N)
mini = 10**12
if len(listN) == 1:
    x = N
    y = 1
else:
    for i in range(len(listN)):
        x = listN[i]
        y = N//x
        mini = min(x+y,mini)
print(x-1+y-1)


Measured memory_bytes: 3268
#ifdef DBG1
  #define LOCAL
#endif

#ifdef LOCAL
  #define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifdef DBG1
    #define dbg(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;

const int P = int(1e9) + 7;

int& add(int &a, int b) {
  if ((a += b) >= P) {
    a -= P;
  }
  return a;
}

int prod(int a, int b) {
  return (int)(ll(a) * b % P);
}

bool solve() {
  int n, x;
  if (scanf("%d%d", &n, &x) != 2) { return false; }

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

  sort(a.begin(), a.end());
  int MAX = max(x, a.back());
  vector<int> dp(MAX + 1, 0);
  dp[x] = 1;
  for (int j = n - 1; j >= 0; --j) {
    for (int i = 0; i <= MAX; ++i) {
      int val = dp[i];
      dp[i] = prod(val, j);
      add(dp[i % a[j]], val);
    }
    for (int i = 0; i <= MAX; ++i) {
      if (dp[i]) {
        dbg("%d: %d\n", i, dp[i]);
      }
    }
    dbg("\n");
  }
  int s = 0;
  for (int i = 0; i <= MAX; ++i) {
    if (dp[i]) dbg("%d * %d\n", i, dp[i]);
    add(s, prod(dp[i], i));
  }
  dbg("\n");
  printf("%d\n", s);
  return true;
}

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て

int		main(void)
{
	int H, W;
	cin >> H >> W;
	ll ans = (ll)H * W / 2;
	if (H%2 == 1 && W%2 == 1)
		ans += 1;
	if (H == 1 || W == 1)
		ans = 1;
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

typedef struct xy{
  double x,y;
}XY;

void Koch(int n,XY p1,XY p2){
  if(n == 0) return;
  XY s,t,u;
  double tmp = M_PI/3.0;

  s.x = (2.0*p1.x + 1.0*p2.x)/3.0;
  s.y = (2.0*p1.y + 1.0*p2.y)/3.0;
  t.x = (1.0*p1.x + 2.0*p2.x)/3.0;
  t.y = (1.0*p1.y + 2.0*p2.y)/3.0;
  u.x = (t.x - s.x)*cos(tmp) - (t.y - s.y)*sin(tmp) + s.x;
  u.y = (t.x - s.x)*sin(tmp) + (t.y - s.y)*cos(tmp) + s.y;

  Koch(n-1,p1,s);
  printf("%.8f %.8f\n",s.x,s.y);
  Koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  Koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  Koch(n-1,t,p2);
}
  
int main()
{
  int n;
  XY p1,p2;
  scanf("%d",&n);
  p1.x = 0;
  p1.y = 0;
  p2.x = 100;
  p2.y = 0;
  printf("%.8f %.8f\n",p1.x,p1.y);
  Koch(n,p1,p2);
  printf("%.8f %.8f\n",p2.x,p2.y);

  return 0;
}




Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
typedef long long ll;
/**
 * Uncomment the #define below if problem contains multiple test cases
 */
// #define MULTIPLE_TESTS 1

void solve() {
  int th, ts, ah, as;
  cin >> th >> ts >> ah >> as;
  int t_turn = 1;
  while (th > 0 && ah > 0) {
    if (t_turn) {
      ah -= ts;
    } else {
      th -= as;
    }
    t_turn = t_turn ^ 1;
  }
  if (th <= 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

int main() {
  FAST_IO;
  int t = 1;
#ifdef MULTIPLE_TESTS
  cin >> t;
#endif

  while (t--) {
    solve();
  }

  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    int n ,m;
    cin >> n  >> m;
    int a[m] ,b[m],c[n] ,d[n];
    for(int i = 0 ; i < m ; i++){
        cin >> a[i] >> b[i];
    }
    
    for(int v = 0; v < n ; v++){
        d[v] = 0;
    }
    for(int j = 0 ; j < n ; j++){
        for(int t = 0;t < m;t++){
            if(a[t] == j+1 || b[t] == j+1){
                d[j] += 1;
            }    
        }
    }
    
    for(int y = 0;y < n;y++){
        cout << d[y] << endl;
    }
    
    
    
}

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

int main() {
  int a=0;
  rep(i,5){
    cin>>a;
    if(a==0){
      cout<<i+1;
    }
  }
}


Measured memory_bytes: 3564
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
ll f[N], g[N];
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, m, p, c = 0, w = 0;
    string s;
    cin >> n >> m;
    for (ll i = 0; i < m; i++)
    {
        cin >> p >> s;
        if (!f[p])
            if (s == "AC")
                f[p] = 1, c++, w += g[p];
            else
                g[p]++;
    }
    cout << c << " " << w;
    return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, l, r, ans = 0;
    cin >> n;
    while(n--) {
        cin >> l >> r;
        ans += (r-l+1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3660
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int n,k;
vi a;

vi divs(int x){
    vi ret;
    for (int i = 1; i*i <= x; i++){
        if (x%i == 0){
            ret.pb(i);
            ret.pb(x/i);
        }
    }
    sort(all(ret));
    uniq(ret);
    return ret;
}
int xsort;
bool f(int x){
    auto ai = a;
    REP(i,n) ai[i] %= x;
    sort(all(ai));
    
    auto acump = ai;
    REP(i,n-1) acump[i+1] += acump[i];
    auto acumn = ai;
    REP(i,n) acumn[i] = x - acumn[i];
    REPN(i,n-1) acumn[i] += acumn[i+1];
    acumn.pb(0);

    int op = INT64_MAX;
    REP(i,n) op = min(op, max(acump[i] , acumn[i+1]));
    cerr << x << " " << op << endl;
    return op <= k;
}

signed main(){
    I(n); I(k);
    a.resize(n);
    REP(i,n) I(a[i]);
    int asum = accumulate(all(a), 0LL);
    // cerr << asum << endl;
    auto dv = divs(asum);
    int ok = 0;
    REP(i,sz(dv)) ok = f(dv[i]) ? i : ok;
    cout << dv[ok] << endl;
}


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

using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
const ll MAXN = 2e6 + 10, inf = 1e18, mod = 1e9 + 7;

struct pair_hash {
	template <class T1, class T2>
	std::size_t operator () (const std::pair<T1,T2> &p) const {
		auto h1 = std::hash<T1>{}(p.first);
		auto h2 = std::hash<T2>{}(p.second);

		return h1 ^ h2;  
	}
};

ll pw(ll te, ll tee) {
	if (tee == 0)	return 1;
	ll res = pw(te, tee / 2);
	return (tee % 2 ? te * res * res : res * res);
}

ll n, a[MAXN], t, k, p;

void Read_input() {
	cin >> n;
	for (ll i = 1; i <= n; i++)	cin >> a[i];
}

void Solve() {
	for (ll i = 1; i <= n; i++) {
		if (a[i] % 2)	t++;
		else if (a[i] % 4 == 0)	k++;
		else	p++;
	}
	if (k >= t or (p == 0 and k >= t - 1))	cout << "Yes";
	else	cout << "No";
}


int main() {

	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	//freopen("input.txt", "r", stdin),	freopen("output.txt", "w", stdout);

	Read_input(),	Solve();
	return 0;
}

Measured memory_bytes: 1024
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-01-26 20:28:17
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

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

  int n, k; cin >> n >> k;
  vector<int64> h(n); cin >> h;
  sort(all(h));

  debug(h);

  int64 ans = 0;

  for (int i = 0; i < n - k; ++i) {
    ans += h[i];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll x, y;
    cin >> x >> y;
    
    ll ans = 0;
    if (x<0&&y<0&&x>=y) {ans+=2;ans+=abs(x-y);}
	if (x<0&&y<0&&x<y) {ans+=abs(x-y);}
	if (x<0&&y>0) {ans=1;ans+=abs(y+x);}
	if (x>0&&y<0) {ans=1;ans+=abs(y+x);}
	if (x>0&&y>0&&x<=y) {ans+=abs(y-x);}
	if (x>0&&y>0&&x>y) {ans=2;ans+=abs(y-x);}
	if (!x||!y) {
		if (x>y) ans+=abs(y-x)+1;else ans+=abs(y-x);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
#define FU(i,a,b) for(register int i = a ; i <= b ; ++i)
#define FD(i,a,b) for(register int i = a ; i >= b ; --i)
#define set_max(a) memset(a,0x3f,sizeof a)
#define set_min(a) memset(a,~0x3f,sizeof a)
#define clear(a) memset(a,0,sizeof a)

using namespace std;

template<typename T>inline void chkmax(T & a,T b){ if(a < b) a = b ; }
template<typename T>inline void chkmin(T & a,T b){ if(a > b) a = b ; }

template<typename T>
inline T read()
{
	int res = 0 , flag = 1 ;
	char ch = getchar();
	while(!isdigit(ch))
	{
		if(ch == '-') flag = -1;
		ch = getchar();
	}
	while(isdigit(ch))
	{
		res = (res << 3) + (res << 1) + ch - '0';
		ch = getchar();
	}
	return res * flag;
}

template<typename T>
inline void write(T x)
{
	if(x/10) write(x/10);
	putchar(x%10+'0');
}

const int INF=0x3f3f3f3f;
const int N=4e1;
int n,m,hx,hy;
int ice[N+5][N+5],dp[N+5][N+5][N+5][N+5];

inline void Input()
{
	n = read<int>(); m = read<int>();

	char ch;
	for(register int i = 1 ; i <= n ; ++i)
	 for(register int j = 1 ; j <= m ; ++j)
	 {
		cin >> ch;
		ice[i][j] = ice[i-1][j] + ice[i][j-1] -ice[i-1][j-1] + (ch == '#');
		if(ch == 'P') { hx = i ; hy = j ; }
	 }
}

inline int thick(int dx,int dy,int rx,int ry)
{
//	if(dx > rx || dy > ry) return 0;
	return ice[rx][ry] - ice[rx][dy-1] - ice[dx-1][ry] + ice[dx-1][dy-1];
}

inline int MIN(int a,int b,int c,int d)
{
	return min(min(a,b),min(c,d));
}

inline void Solve()
{
	int ans = INF;
	set_max(dp);
	dp[1][1][n][m] = 0;
	for(register int i = 1 ; i <= hx ; ++i)
	 for(register int j = 1 ; j <= hy ; ++j)
	  for(register int k = n ; k >= hx ; --k)
	   for(register int p = m ; p >= hy ; --p)
	   {
			chkmin(ans , dp[i][j][k][p] + MIN(thick(i,j,hx,hy),thick(hx,hy,k,p),thick(hx,j,k,hy),thick(i,hy,hx,p)));
			for(register int s = i ; s <= k ; ++s)
			 for(register int t = j ; t <= p ; ++t)
			 {
				 if(s >= hx && t >= hy) chkmin(dp[i][j][s][t],dp[i][j][k][p] + thick(s+1,j,k,t) + thick(i,t+1,s,p));
				 if(s <= hx && t <= hy) chkmin(dp[s][t][k][p],dp[i][j][k][p] + thick(s,j,k,t-1) + thick(i,t,s-1,p));
				 if(s >= hx && t <= hy) chkmin(dp[i][t][s][p],dp[i][j][k][p] + thick(i,j,s,t-1) + thick(s+1,t,k,p));
				 if(s <= hx && t >= hy) chkmin(dp[s][j][k][t],dp[i][j][k][p] + thick(i,j,s-1,t) + thick(s,t+1,k,p));
			 }
	   }

	write(ans); putchar('\n');
}

inline void File()
{
	freopen("haner.in","r",stdin);
	freopen("haner.out","w",stdout);
}

int main()
{
	//File();

	Input();
	Solve();

	return 0;
}


Measured memory_bytes: 16256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl A(N);
  REP(i, N) cin >> A[i];
  ll now = 1000;
  ll kabu = 0;
  ll last = 0;
  REP(i, N) {
    if (i < N - 1 && A[i + 1] > A[i]) {
      kabu += now / A[i];
      now = now % A[i];
    } else if (i < N - 1 && A[i] > A[i + 1]) {
      now += kabu * A[i];
      kabu = 0;
    } else if (i == N - 1) {
      now += kabu * A[i];
      kabu = 0;
    }
  }
  cout << now << endl;

  return 0;
}


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

#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++)

using namespace std;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

int main() {
	int N; cin >> N;
	map<int, int> A;
	long long ans = 0;
	rep(i, N) {
		int a; cin >> a;
		++A[a];
		ans += a;
	}
	int Q; cin >> Q;
	vector <long long> B(Q), C(Q);
	rep(i, Q)cin >> B[i] >> C[i];
	rep(i, Q) {
		if (A[B[i]] != 0) {
			long long temp = A[B[i]];
			A[B[i]] = 0;
			A[C[i]] += temp;
			ans = ans - B[i] * temp + C[i] * temp;
			//cout << temp << "," << B[i] << "," << C[i] << endl;
		}
		cout << ans << endl;
	}
	
}



Measured memory_bytes: 8980
import java.util.Scanner;
//EphSon solution

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x=sc.nextInt();
        int n=sc.nextInt();
        int[] p=new int[n];
        for(int i=0;i<n;i++) {
        	p[i]=sc.nextInt();
        }
        for(int i=0;i<=100;i++) {
        	int num1=x-i,num2=x+i;
        	int count1=0,count2=0;
        	for(int j=0;j<n;j++) {
        		if(p[j]==num1)	count1++;
        		if(p[j]==num2)	count2++;
        	}
        	if(count1==0) {
        		System.out.println(num1);
        		break;
        	}else if(count2==0) {
        		System.out.println(num2);
        		break;
        	}
        }
    }
}


Measured memory_bytes: 35804
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 998244353


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """

    def __init__(self, n_max, mod=10 ** 9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
        return modinv


def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


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


def main():
    N, M, K = map(int, input().split())
    comb = Combination(n_max=N, mod=MOD)
    ans = 0

    ans = 0
    for k in range(K + 1):
        tmp = M % MOD
        tmp *= comb(N - 1, k) * modpow(M - 1, N - k - 1, MOD)
        ans += tmp
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 32908
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define show(x) cout<<x<<'\n'
#define showh(x) cout<<x<<' '
#define go(i,a,n) for(ll i=a;i<n;i++)
#define gor(i,a,n) for(ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
bool prime[100001];
bool ispoweroftwo(ll x)
{
    return x && !(x & (x-1));
}
ll xorcal(ll n)
{
    if(n%4==0)
        return n;
    if(n%4==1)
        return 1;
    if(n%4==2)
        return n+1;
    if(n%4==3)
        return 0;
}
void sieve(ll n)
{
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(ll i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    show(prime[89]);
}
bool isprime(ll n)
{
    if (n<=1) return false;
    if (n<=3) return true;

    if(n%2==0 or n%3==0) return false;

    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0 or n%(i+2)==0) return false;
    }
    return true;
}

ll modinverse(ll a,ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m; a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
       x += m0;

    return x;
}

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

ll power(ll A, ll B)
{
    if (A == 0)
        return 0;
    if (B == 0)
        return 1;

    ll y;
    if (B % 2 == 0) {
        y = power(A, B / 2);
        y = (y * y) % mod;
    }

    else {
        y = A % mod;
        y = (y * power(A, B - 1) % mod) % mod;
    }

    return (ll)((y + mod) % mod);
}
int main()
{
    ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll b[n],a[n+1]={0};
    go(i,1,n)
    {
        cin>>b[i];
    }
    a[1]=b[1];
    a[2] = min(b[1],b[2]);
    go(i,2,n-1)
    {
        a[i+1] = min(b[i],b[i+1]);
    }
    a[n] = b[n-1];
    ll sum = 0;
    go(i,1,n+1)
    {
        sum += a[i];
    }
    show(sum);
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=1e5+10;
char str[N];
int n,k;
int main() {
	rd(n),rd(k);
	scanf("%s",str+1);
	int cnt=0;
	for(int i=2;i<=n;++i) cnt+=str[i]!=str[i-1];
	cnt++;
	printf("%d\n",n-1-max(0,cnt-2*k-1));
	return 0;
}

Measured memory_bytes: 384
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    A = [NI() for _ in range(N)]

    ans = 0
    cnt = 0
    for i in range(N-1,-1,-1):
        if cnt == 0:
            ans += A[i]
            cnt = A[i]
        elif A[i] < cnt -1:
            print(-1)
            return
        elif A[i] >= cnt:
            ans += A[i]
            cnt = A[i]
        else:
            cnt -= 1
    if cnt > 0:
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()

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

using namespace std;

int main(){
    int N;cin >> N;
    int a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    vector<int> v;
    for(int i=0;i<N;i++){
        if(i%2==1){
            v.push_back(a[i]);
        } else {
            v.insert(v.begin(),a[i]);
        }
    }
    if(N%2==1){
        for(int i=0;i<N;i++){
            cout << v[i] << " ";
        }
    } else {
        for(int i=N-1;i>=0;i--){
            cout << v[i] << " ";
        }
    }

}

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

using namespace std;

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

int main(){
  int n , t , dp[3050][6100] = {-100000009};
  cin >> n >> t;
  vector<pair<int,int>> s(n);
  
  for(int i=0;i<n;i++){
    
  cin >> s[i].first >> s[i].second;
    
  }
  
  sort(s.begin(),s.end());
  
  dp[0][0] =0;
  for(int i=0;i<n;i++){
    
   for(int j=0;j<3100;j++){
     
     if(j < t) chmax(dp[i+1][j+s[i].first],dp[i][j]+s[i].second);
     chmax(dp[i+1][j],dp[i][j]);
   }
  }
  
  int res = 0;
  
    for(int i=0;i<=n;i++){
  for(int j=0;j<6100;j++){
    
       chmax(res , dp[i][j]);
  }
    } 
  
  cout << res << endl;
}


Measured memory_bytes: 72960