akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N;
	M = 100;
	while (M < N) {
		M += M / 100;
		K++;
	}
	cout << K << endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int lli;
#define optimize ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define forab(i,a,b) for(int i = a; i<b; i++)
#define forll(i,a,b) for(lli i = a; i<b; i++)
#define mp make_pair
#define pb push_back
#define sortv(v) sort(v.begin(), v.end())
#define mod1 1000000007
#define mod2 998244353
#define debug(x) cout<<#x<<" : "<<x<<endl

int main()
{
	optimize

	int a;
	cin>>a;

	cout<<a+a*a+a*a*a<<endl;


	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#define r(i,n) for(int i=0;i<n;i++)

using namespace std;

int main(){
	int n,ans=-1,cnt=0;
    cin>>n;
    vector<int> a(n);

    r(i,n){
        cin>>a.at(i);
        if(a.at(i)%2!=0)ans=0;
    }

        while(ans!=0){
            r(j,n){
                if(a.at(j)%2==0){a.at(j)=a.at(j)/2;cnt++;}
                else {ans=0;}
            }
            
        }
        //if(ans==0)cout<<ans<<endl;
        cout<<cnt/n<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n],b[n];
    ll sum=0,num=0,niko=0;
    vector<pair<ll,ll> > v;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
        if(a[i]<b[i]){
            num+=b[i]-a[i];
            niko++;
        }else if(a[i]>b[i]){
            v.pb(make_pair(a[i]-b[i],i));
        }
    }
    sort(be(v));
    reverse(be(v));
    ll maki=v.size();
    for(int i=0;i<maki;i++){
        if(num==0){
            break;
        }
        if(v[i].first>=num){
            niko++;
            num=0;
        }else{
            niko++;
            num-=v[i].first;
        }
    }
    cout<< ((num==0)?niko:-1)<<endl;
    return 0;
}

Measured memory_bytes: 2804
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q, H, W, A, B;
signed main() {
	cin >> A >> B;
	vector< string > S(100);
	rep(i, 50) {
		rep(k, 100) {
			S[i].push_back('.');
			S[i + 50].push_back('#');
		}
	}
	--A;
	--B;

	pii c(51, 0);
	while (A--) {
		S[c.first][c.second] = '.';
		c.second += 2;
		if (c.second >= 100) {
			c.second = 0;
			c.first += 2;
		}
	}

	c = pii(48, 0);
	while (B--) {
		S[c.first][c.second] = '#';
		c.second += 2;
		if (c.second >= 100) {
			c.second = 0;
			c.first -= 2;
		}
	}
	cout << "100 100" << endl;
	rep(i, 100) cout << S[i] << endl;
	return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
a_list = []
b_list = []
cnt = 0
cnt_list = []
for i in range(M):
    a,b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)
for i in range(1,N+1):
    for j in range(M):
        if i == a_list[j] or i == b_list[j]:
            cnt += 1
    cnt_list.append(cnt)
    cnt = 0
for i in range(len(cnt_list)):
    print(cnt_list[i])

Measured memory_bytes: 3064
#include <cstdio>
#include <utility>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
#include <string.h>

using namespace std;

int main(){
   
 while(1){ 
   
    string s; cin>>s; 
    
    if(s[0]=='-') break;
    
    int m; cin>>m;
    
    for(int i=0; i<m; i++){
      
      int h; cin>>h; string w;
      
      for(int j=0; j<h; j++){
        w+=s[j];
        }
        
      s+=w;
        
      s.erase(0,h);
      
      }
      
      cout<<s<<endl;
    
  }

}

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

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

template<typename T> T gcd(T a, T b){return (a % b)? gcd(b, a % b) : b;}
template<typename T> T lcm(T a, T b){return a * b / gcd(a, b);}

int main(void){
    int x;
    cin >> x;
    x /= 10;
    if(40 <= x&& x <= 59) cout << 8 << endl;
    else if(60 <= x&& x <= 79) cout << 7 << endl;
    else if(80 <= x&& x <= 99) cout << 6 << endl;
    else if(100 <= x&& x <= 119) cout << 5 << endl;
    else if(120 <= x&& x <= 139) cout << 4 << endl;
    else if(140 <= x&& x <= 159) cout << 3 << endl;
    else if(160 <= x&& x <= 179) cout << 2 << endl;
    else cout << 1 << endl;
    
    
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm> 
#include<climits>
#include<stack>
#include<queue>
#include<set>
#include<cctype>
#include<bitset> 
#include<type_traits>
#include<numeric>
#include<array>
using namespace std;

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<int,int> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

const int mod = 1000000007;
const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
}

int N;
auto dp = make_vec<double>(310,310,310); 

// あと1枚がi種、あと2枚がj種、あと3枚がk種、
double solve(int i,int j,int k){
    if(dp[i][j][k]>=0) return dp[i][j][k];

    double ret = 0.0;
    if(i>0) ret += solve(i-1,j  ,k  ) * i;
    if(j>0) ret += solve(i+1,j-1,k  ) * j;
    if(k>0) ret += solve(i  ,j+1,k-1) * k;
    ret += N;
    ret *= 1.0 / (i+j+k);

    return dp[i][j][k] = ret;
}

int main(){

    cin >> N;
    fill_v(dp,-1);
    dp[0][0][0]=0;

    map<int,int> mp;
    REP(i,3) mp[i+1]=0;

    REP(i,N) {
        int tmp;cin >> tmp;
        mp[tmp]++;
    }

    printf("%.12f\n",solve(mp[1],mp[2],mp[3]));

    return 0;
}

Measured memory_bytes: 237568
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i=0; i < n; ++i)
#define rep2(i, x, n) for (int i = x; i < n; ++i)

int main()
{
    const int INF = 1e9+1;
    int n,m,l;
    cin >> n >> m >> l;
    
    vector<vector<int>> d(n,vector<int>(n,INF));
    rep(i,n) d[i][i] = 0;

    rep(i,m)
    {
        int a,b,c;
        cin >> a >> b >> c;
        d[a-1][b-1] = c;
        d[b-1][a-1] = c;
    }

    rep(k,n)
        rep(i,n)
            rep(j,n)
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]);

    vector<vector<int>> cnt(n,vector<int>(n,INF));
    
    rep(i,n) 
        rep(j,n)
            if(d[i][j]<=l) cnt[i][j] = 1;
    rep(i,n) cnt[i][i] = 0;

    rep(k,n)
        rep(i,n)
            rep(j,n)
                cnt[i][j] = min(cnt[i][j],cnt[i][k]+cnt[k][j]);
    
    int q;
    cin >> q;
    rep(i,q)
    {
        int s,t;
        cin >> s >> t;
        int di = cnt[s-1][t-1];
        cout << (di==INF ? -1 : di-1) << endl;
    }

    return 0;
}

Measured memory_bytes: 1280
program atcoder
    implicit none
    integer :: i,n,k,j
    integer,allocatable,dimension(:) :: a,dp
    read*,n,k
    allocate(a(0:n))
    allocate(dp(0:n+3))
    read(*,*)(a(i),i=1,n)
    dp = 1000000007
    dp(1) = 0
    do i = 1,n
        do j = 1,k
            if(i+j<=n) then
                dp(i+j) = min( dp(i+j) , dp(i)+abs(a(i)-a(i+j)) )
            endif
        end do
    end do
    write(*,'(I0)')dp(n)
    stop 
!---------------------------------------
contains

end program atcoder


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <ctime>
#include <unordered_map>
#include <stdlib.h>
using namespace std;
#define ll  long long int
#define mod 1000000007
#define modd 998244353
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// #include<boost/multiprecision/cpp_int.hpp>
// using boost ::multiprecision::cpp_int;
/*__builtin_clz();
__builtin_ctz();
__builtin_popcount();*/
int main()
{
    boost;
    ll n,w;
    cin>>n>>w;
    ll a[n+1];
    ll b[n+1];
    for(ll i=1;i<=n;i++)
    cin>>a[i]>>b[i];
    ll dp[n+1][w+1];
    memset(dp,0,sizeof dp);
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=w;j++)
        {
            if(a[i] <= j)
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-a[i]] + b[i]);
            else 
            dp[i][j] = dp[i-1][j];
            // cout<<dp[i][j]<<" ";
        }
        // cout<<"\n";
    }
    cout<<dp[n][w]<<"\n";
    cerr << "\nTime elapsed: " << 1000 * clock()/CLOCKS_PER_SEC << "ms\n";
}
/* AnsHuman_7 || Anshuman Gaur */


Measured memory_bytes: 79104
#include <iostream>
#include <stack>
using namespace std;

int main () {
	stack<char> sc;
	int lim, m = 0, ds = 0, i = 0, k = 0, SS = 0;
	int s[5000];
	int rs[5000];
	char c;
	while(cin >> c) {
		sc.push(c);
		if (m == 0) {
			if (c == '\\')
				m++;
		}
		else {
			if (c == '/')
				m--;
			else if (c == '\\')
				m++;
		}
		ds = ds + m;
		if ((ds != 0) && (m == 0)) {
			s[i++] = ds;
			ds = 0;
			lim = sc.size();
			for(int j = 0; j < lim; j++)
				sc.pop();
		}
	}
	m = 0;
	ds = 0;
	lim = sc.size();
	for (int j = 0; j < lim; j++) {
		c = sc.top();
		sc.pop();
		if (m == 0) {
			if (c == '/')
				m++;
		}
		else {
			if (c == '\\')
				m--;
			else if (c == '/')
				m++;
		}
		ds = ds + m;
		if ((ds != 0) && (m == 0)) {
			rs[k++] = ds;
			ds = 0;
		}
	}
	for (int j = 0; j < i; j++)
		SS = SS + s[j];
	for (int j = 0; j < k; j++)
		SS = SS + rs[j];
	cout << SS << endl;
	cout << i + k;
	for (int j = 0; j < i; j++)
		cout << ' ' << s[j];
	for (int j = k - 1; j >= 0; j--)
		cout << ' ' << rs[j];
	cout << endl;
	return 0;
}

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

// シミュレート解
int main(){
    set<int> hand[2];
    int n;  cin >> n;
    while(n-- > 0){
        hand[0].clear(), hand[1].clear();
        int vergea = 0, vergeb = 0, one = 0, thirteen = 0;
        for(int i = 0; i < 6; i++){
            int x;  cin >> x;
            hand[0].insert(x);
            if(x == 1)  one = -1;
            if(x == 13) thirteen = -1;
        }
        for(int i = 1; i <= 13; i++){
            if(i == 7 || hand[0].count(i))  continue;
            hand[1].insert(i);
            if(i == 1)  one = 1;
            if(i == 13) thirteen = 1;
        }
        if(one*thirteen == 0){
            cout << (one+thirteen==2 ? "no" : "yes") << endl;
            continue;
        }
        int l = 6, r = 8, turn = 0;
        while(hand[0].size() && hand[1].size()){
            if(2*turn-1 == one){
                // prior on lower 
                if(hand[turn].count(l)){
                    hand[turn].erase(l);
                    l--;
                    turn = 1-turn;
                    continue;
                }else if(hand[turn].count(r)){
                    hand[turn].erase(r);
                    r++;
                    turn = 1-turn;
                    continue;
                }
            }else{
                // prior on higher
                if(hand[turn].count(r)){
                    hand[turn].erase(r);
                    r++;
                    turn = 1-turn;
                    continue;
                }else if(hand[turn].count(l)){
                    hand[turn].erase(l);
                    l--;
                    turn = 1-turn;
                    continue;
                }
            }
            turn = 1-turn;
        }
        cout << (hand[0].size()==0 ? "yes" : "no") << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
import java.util.Scanner

object Main {
  type T = Int

  sealed abstract class Node

  case class Branch(value: T, priority: Double, left: Node, right: Node) extends Node

  case object Leaf extends Node

  class MySet(val root: Node) {
    def insert(value: T): (MySet, Boolean) = if (contains(value)) {
        (new MySet(root), false)
      } else {
      val (left, right) = split_less(root, value)
      val single = Branch(value, math.random, Leaf, Leaf)
      (new MySet(merge(merge(left, single), right)), false)
    }

    def erase(value: T): (MySet, Boolean) = if (contains(value)) {
        val (left, tmp) = split_less(root, value)
        val (_, right) = split_leq(tmp, value)
        (new MySet(merge(left, right)), true)
      } else {
      (new MySet(root), false)
    }

    def contains(value: T): Boolean = find(root, value)

    def toList(): List[T] = makeList(root)
  }

  def merge(left: Node, right: Node): Node = (left, right) match {
    case (Leaf, r) => r
    case (l, Leaf) => l
    case (l: Branch, r: Branch) => {
      if (l.priority > r.priority) {
        Branch(l.value, l.priority, l.left, merge(l.right, right))
      } else {
        Branch(r.value, r.priority, merge(left, r.left), r.right)
      }
    }
  }

  def split_less(node: Node, value: T): (Node, Node) = node match {
    case Leaf => (Leaf, Leaf)
    case Branch(x, p, l, r) => {
      if (x < value) {
        val (rl, rr) = split_less(r, value)
        (Branch(x, p, l, rl), rr)
      } else {
        val (ll, lr) = split_less(l, value)
        (ll, Branch(x, p, lr, r))
      }
    }
  }

  def split_leq(node: Node, value: T): (Node, Node) = node match {
    case Leaf => (Leaf, Leaf)
    case Branch(x, p, l, r) => {
      if (x <= value) {
        val (rl, rr) = split_leq(r, value)
        (Branch(x, p, l, rl), rr)
      } else {
        val (ll, lr) = split_leq(l, value)
        (ll, Branch(x, p, lr, r))
      }
    }
  }

  def find(node: Node, value: T): Boolean = node match {
    case Leaf => false
    case Branch(x, _, l, r) => {
      if (value < x) find(l, value)
      else if (x == value) true
      else find(r, value)
    }
  }

  def makeList(tree: Node): List[T] = tree match {
    case Leaf => Nil
    case Branch(x, _, l, r) => makeList(l) ++ List(x) ++ makeList(r)
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt

    var s = new MySet(Leaf)
    for (_ <- 0 until n) s = s.insert(sc.nextInt)._1
    val ls = s.toList()
    // println(ls)
    println(ls.length)
  }
}

Measured memory_bytes: 27448
N, M, C = list(map(int, input().split()))
b = list(map(int, input().split()))
a = []
for i in range(N):
    a.append(list(map(int, input().split())))
ans = 0
for i in range(N):
    tmp = 0
    for j in range(M):
        tmp += a[i][j] * b[j]
    if 0 < tmp + C:
        ans += 1
print(ans)


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

int main(){
    string s;
    int k;
    set<string> se;

    cin>>s>>k;

    int size = s.size();

    for(int i=0; i<size; i++){
        string tmp;
        for(int j=0; j<k; j++){
            tmp = s.substr(i,j+1);
            se.insert(tmp);           
        }
    }

    set<string> ::iterator itr = se.begin();

    for(int i=1; i<k; i++) itr++;

    cout<<*itr<<endl;

    return 0;
}

Measured memory_bytes: 1664
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int X = sc.nextInt();
    int array[] = new int[M];

    for(int i=0;i<M;i++){
      array[i] = sc.nextInt();
    }
    int[] cell = new int[N+1];

    Arrays.fill(cell,0);

    for(int i : array){
        cell[i] = 1;
    }

    int cost0 = 0;
    for(int i=X;i>=0;i--){
      cost0 += cell[i];
    }

    int costN = 0;
    for(int i=X;i<N+1;i++){
      costN += cell[i];
    }

    int cost = cost0 <= costN ? cost0 : costN;
    System.out.println(cost);
    }
}


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

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

 int mat_a[n][m];
 int input_num;
 for( int i=0; i<n; i++ ){
  for( int j=0; j<m; j++ ){
    cin >> input_num;
    mat_a[i][j] = input_num;
  }
 }

 int mat_b[m];
 for( int k=0; k<m; k++ ){
   cin >> input_num;
   mat_b[k] = input_num;
 }

 int mat_c[n];
 for( int o=0; o<n; o++ ){
    mat_c[o] = 0;
  for( int p=0; p<m; p++ ){
    mat_c[o] += mat_a[o][p]*mat_b[p];
  }
 }

 for( int q=0; q<n; q++ ){
   cout << mat_c[q] << endl;
 }

 return 0;
}


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

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //int n=Readint();
            //string[] str = Console.ReadLine().Split(' ');

            long n = Readlong();

            var a = new long[n];
            a = ReadArray(n);

            long q = Readlong();

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

            long sum = a.Sum();


            for (long i = 0; i < q; i++)
            {
                string[] str = Console.ReadLine().Split(' ');
                long b = long.Parse(str[0]);
                long c = long.Parse(str[1]);

                sum += count[b] * (c - b);
                Cout(sum);

                count[c] += count[b];
                count[b] = 0;
            }


            //ここまで
        }

        static void Cout(string s)
        {
            Console.WriteLine(s);
            return;
        }

        static void Cout(int n)
        {
            Console.WriteLine(n);
            return;
        }

        static void Cout(long n)
        {
            Console.WriteLine(n);
            return;
        }

        static int Readint()
        {
            return int.Parse(Console.ReadLine());
        }

        static int[] ReadArray(int n)
        {
            string[] str = Console.ReadLine().Split(' ');
            int[] a = new int[n];
            for (int i=0; i < n; i++){ a[i] = int.Parse(str[i]); }
            return a;
        }
        static long[] ReadArray(long n)
        {
            string[] str = Console.ReadLine().Split(' ');
           long[] a = new long[n];
            for (long i = 0; i < n; i++) { a[i] = long.Parse(str[i]); }
            return a;
        }

        static long Readlong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int Min(int a, int b)
        {
            if (a < b) return a;
            return b;
        }

        static int Max(int a, int b)
        {
            if (a > b) return a;
            return b;
        }


    }

}


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

int main(){
	int n , m;
	while(cin>>n , n){
		bool field[21][21]={false};
		vector< pair<int,int> > v(n);
		
		for(int i=0;i<n;++i){
			cin >> v[i].first >> v[i].second;
		}
		cin >> m;
		vector< pair<char,int> > o(m);
		for(int i=0;i<m;++i){
			cin >> o[i].first >> o[i].second;
		}
		int px=10, py=10;
		for(int i=0;i<m;++i){
			switch(o[i].first){
				case 'N':
				for(int j=0;j<o[i].second+1;++j){
					field[px][py+j]=true;
				}
				py+=o[i].second;
				break;
				case 'E':
				for(int j=0;j<o[i].second+1;++j){
					field[px+j][py]=true;
				}
				px+=o[i].second;
				break;
				case 'S':
				for(int j=0;j!=-o[i].second-1;--j){
					field[px][py+j]=true;
				}
				py-=o[i].second;
				break;
				case 'W':
				for(int j=0;j!=-o[i].second-1;--j){
					field[px+j][py]=true;
				}
				px-=o[i].second;
				break;
			}
		}
		bool b=true;
		
		for(int i=0;i<n;++i){
			if(!field[v[i].first][v[i].second]) {
				b=false;
				break;
			}
		}
		cout << (b ? "Yes" : "No") << endl;
	}
	return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main(){
    gearup;
    ll n;cin>>n;
    vl a(n);
    rep(i,n)cin>>a[i];
    deque<int> d;
    rep(i,n){
        if(i % 2 == 1)d.push_front(a[i]);
        else d.push_back(a[i]);
    }
    bool is_first = false;
    while(!d.empty()){
        if(!is_first)is_first=true;
        else cout << " ";
        if(n % 2==0){
            cout << d.front();
            d.pop_front();
        }
        else{
            cout << d.back();
            d.pop_back();
        }
    }
    cout << endl;
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,a[N],tr[N<<2],ans[N];
vector<int>e[N],v;
void update(int k,int l,int r,int x,int v)
{
	if(l==r)
	{
		tr[k]=v;
		return;
	}
	int mid=l+r>>1;
	if(x<=mid) update(k<<1,l,mid,x,v);
	else update(k<<1|1,mid+1,r,x,v);
	tr[k]=max(tr[k<<1],tr[k<<1|1]);
}
int query(int k,int l,int r,int a,int b)
{
	if(a>b)
		return 0;
	if(l==a&&r==b)
		return tr[k];
	int mid=l+r>>1;
	if(b<=mid) return query(k<<1,l,mid,a,b);
	else if(a>mid) return query(k<<1|1,mid+1,r,a,b);
	else return max(query(k<<1,l,mid,a,mid),query(k<<1|1,mid+1,r,mid+1,b));
}
void dfs(int u,int f)
{
	int x=a[u];
	int zh=query(1,1,n,x,x),k=query(1,1,n,1,x-1);
	update(1,1,n,x,k+1);
	ans[u]=query(1,1,n,1,n);
	for(auto v:e[u])
		if(v!=f)
			dfs(v,u);
	update(1,1,n,x,zh);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		v.push_back(a[i]);
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	for(int i=1;i<=n;i++)
		a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin()+1;
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
		printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 28052
#include <stdio.h>

void printArray(int A[], int N)
{
    int i;
    for(i = 0; i < N-1; i++) {
        printf("%d ", A[i]);
    }
    if(N >= 1) {
        printf("%d\n", A[i]);
    }
}

void insertionSort(int A[], int N)
{
    int i;
    int v;
    int j;
    for(i = 1; i < N; i++) {
        v = A[i];
        j = i - 1;
        while(j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        printArray(&A[0], N);
    }
}

int main()
{
    int N;
    int i;
    int A[1000];

    scanf("%d", &N);
    for(i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }

    printArray(&A[0], N);
    insertionSort(&(A[0]), N);

    return 0;
}


Measured memory_bytes: 2028
#include <stdio.h>
int main () {
    int N, A, B;
    scanf("%d%d%d", &N, &A, &B);
    int M, m;
    if (A+B <= N) {
        m = 0;
    }
    else {
        m = A+B-N;
    }
    if (A > B) M = B;
    else M = A;
    printf("%d %d\n", M, m);
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    pii v[10000];
    string s;
    rep(i,n){
      int a,b;
      cin>>s;
      a=(s[0]-'0')*10+(s[1]-'0');
      a*=60;
      a+=(s[3]-'0')*10+(s[4]-'0');
      a*=60;
      a+=(s[6]-'0')*10+(s[7]-'0');
      cin>>s;
      b=(s[0]-'0')*10+(s[1]-'0');
      b*=60;
      b+=(s[3]-'0')*10+(s[4]-'0');
      b*=60;
      b+=(s[6]-'0')*10+(s[7]-'0');
      v[i].first=a;
      v[i].second=b; 
   }
    sort(v,v+n);
    priority_queue<int> q;
    q.push(-v[0].second);
    loop(i,1,n){
      if(q.top()>=-v[i].first)q.pop();
      q.push(-v[i].second);
    }
    cout<<q.size()<<endl;
  }
}

Measured memory_bytes: 3124
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<String, Integer> word = new HashMap<String, Integer>();
        String newWord;
        int num = 0;
        for(int i = 0; i < n; i++) {
            newWord = sc.next();
            if(!word.containsKey(newWord)){
                word.put(newWord, 1);
            }else{
                num = word.get(newWord);
                word.remove(newWord);
                word.put(newWord, num + 1);
            }
        }
        int mostNum = 0;
        int current = 0;
        Iterator<Integer> it = word.values().iterator();
        while(it.hasNext()) {
            current = it.next();
            if(mostNum< current) {
                mostNum = current;
            }
        }

        String[] allWords = new String[n];
        Iterator<String> it3 = word.keySet().iterator();
        int q = 0;
        while(it3.hasNext()) {
            allWords[q] = it3.next();
            q++;
        }

        ArrayList<String> mostWords = new ArrayList<String>();
        for(int i = 0; i < q; i++) {
            if(word.get(allWords[i]) == mostNum) {
                mostWords.add(allWords[i]);
            }
        }
        Collections.sort(mostWords);
        for(int a = 0; a < mostWords.size(); a++) {
            System.out.println(mostWords.get(a));
        }
    }
}

Measured memory_bytes: 81900
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<queue>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll Pow_mod(ll a, ll b, ll c){
    ll ans = 1;
    a %= c;
    while (b){
        if (b & 1) ans = (ans * a) % c;
        a = (a * a) % c;
        b >>= 1;
    }
    return (ans % c);
}

int main(){
    int n, d;
    scanf("%d%d", &n, &d);
    if (n % (2 * d + 1)) printf("%d\n", n / (2 * d + 1) + 1);
    else printf("%d\n", n / (2 * d + 1));
    return 0;
}


Measured memory_bytes: 256
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
n=n0()
if int(str(n)[-1]) in [2,4,5,7,9]:
    print("hon")
elif int(str(n)[-1]) in [0,1,6,8]:
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9248
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;
const int sz = 1e5 + 1;

ll n, k;
ll dp[sz];

ll bpow(ll x, ll p) {
	if (p == 0)
		return 1;
	if (p % 2)
		return (bpow(x, p - 1) * x) % mod;
	else {
		ll b = bpow(x, p / 2);
		return (b * b) % mod;
	}
}

void solve() {
	cin >> n >> k;
	dp[k] = 1;
	for (int i = k - 1; i >= 1; i--) {
		int j = 2;
		ll cnt = k / i;
		dp[i] = bpow(cnt, n);
		while (i * j <= k) {
			dp[i] -= dp[i * j++];
			dp[i] += mod;
			dp[i] %= mod;
		}
	}
	ll ans = 0;
	for (int i = 1; i <= k; i++) {
		ans += (dp[i] * i) % mod;
		ans %= mod;
	}
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}


Measured memory_bytes: 4368
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r) 
{
	if (l == r) return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l, m);
	rec(m + 1, r);
	post.push_back(root);
}

void solve() {
	pos = 0;
	rec(0, pre.size());
	for (int i = 0; i < n; i++)
	{
		if (i) cout << " ";
		cout << post[i];
	}
	cout << endl;
}

int main() {
	int k;
	cin >> n;
	for (int i = 0; i < n; i++) 
	{
		cin >> k;
		pre.push_back(k);
	}

	for (int i = 0; i < n; i++) 
	{
		cin >> k;
		in.push_back(k);
	}

	solve();

	return 0;
}

Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define maxll pow(10,18)
int main(){
  vector<ll> dish(5);
  for(int i = 0;i < 5;i++)cin >> dish[i];
  vector<ll> num = {0,1,2,3,4};
  ll res = 0;
  res = maxll;
  do{
    ll before = 0;
    for(int i = 0;i < 5;i++){
      if(before % 10 != 0)before += 10 - before % 10;
      before += dish[num[i]];
    }
    res = min(res,before);
    //cout << endl;
  }while(next_permutation(num.begin(),num.end()));
  cout << res << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int K = reader.nextInt();
		String ans = ":(";
		if (N <= 8 && K <=8) {
			ans = "Yay!";
		}
		System.out.print(ans);
		reader.close();
	}
}


Measured memory_bytes: 21844
M1, D1 = tuple(map(int, input().split()))
M2, D2 = tuple(map(int, input().split()))
M1 = 1 if M1 + 1 > 12 else M1 + 1
if M1 == M2 and D2 == 1:
    print(1)
else:
    print(0)


Measured memory_bytes: 2940
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// for loop
#define REP(i, n) for ((i) = 0;(i) < (ll)(n);(i)++)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

int solve() {
	ll n, m, x;
	cin >> n >> m >> x;

	vector<ll> cs(n);
	vector<vector<ll>> as(n, vector<ll>(m));

	for (ll i = 0; i < n; ++i) {
		cin >> cs[i];
		for (ll j = 0; j < m; ++j) {
			cin >> as[i][j];
		}
	}

	ll res = (1LL << 60LL);
	vector<ll> understandings(m);
	for (ll i = 0; i < (1LL << n); ++i) {
		ll money = 0;
		for (ll j = 0; j < m; ++j) {
			understandings[j] = 0;
		}
		for (ll bit = 0; bit < n; ++bit) {
			if (((i >> bit) & 1LL) == 1LL) {
				money += cs[bit];
				for (ll j = 0; j < m; ++j) {
					understandings[j] += as[bit][j];
				}
			}
		}
		bool accomplished = true;
		for (ll j = 0; j < m; ++j) {
			if (understandings[j] < x) {
				accomplished = false;
			}
		}
		if (accomplished) {
			res = min(res, money);
		}
	}

	if (res >= (1LL << 60LL)) {
		res = -1LL;
	}

	cout << res << endl;

	return 0;
}

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

	solve();

	return 0;
}


Measured memory_bytes: 3652
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int H = sc.nextInt();
	int W = sc.nextInt();
	String[] a = new String[H];
	for(int i = 0; i<H; i++) {
	    a[i] = sc.next();
	}
	for(int i = 0; i<H*2; i++) {
	    System.out.println(a[i/2]);
	}
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,string> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  string a[n];
  rep(i,0,n) cin>>a[i];
  sort(a,a+n);
  vector<P> b;
  b.push_back(P(1,a[0]));
  rep(i,0,n-1){
    if(a[i+1]==a[i]){
      b[b.size()-1].first++;
    }
    else{
      b.push_back(P(1,a[i+1]));
    }
  }
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  vector<string> c;
  c.push_back(b[0].second);
  int i=1;
  while(i<b.size() && b[i].first==b[0].first){
    c.push_back(b[i].second);
    i++;
  }
  rep(i,0,c.size()){
    cout<<c[c.size()-1-i]<<endl;
  }
}

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

int main(int argc, char *argv[]) {
  int D, G;
  cin >> D >> G;
  int p[D];
  int c[D];
  for(int i = 0; i < D; i++) {
    cin >> p[i] >> c[i];
  }
  int ans = 1e9;
  for(int mask = 0; mask < (1 << D); mask++) {
    int s = 0;
    int num = 0;
    int rest_max = -1;
    for(int i = 0; i < D; i++) {
      if(mask >> i & 1) {
        s += 100 * (i + 1) * p[i] + c[i];
        num += p[i];
      } else {
        rest_max = i;
      }
    }
    if(s < G) {
      int s1 = 100 * (rest_max + 1);
      int need = (G - s + s1 - 1) / s1;
      if(need >= p[rest_max]) continue;
      num += need;
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int t1[103];
	int ans=0;
	for(int i=0; i<n; i++)
	{
		scanf("%d",&t1[i]);
		ans+=t1[i];
	} 
	int m;
	int t2[103];
	int num[103];
	scanf("%d",&m);
	for(int i=0; i<m; i++)
	    scanf("%d%d",&num[i],&t2[i]);
	int sum=0;
	for(int i=0; i<m; i++)
	{
		int k=num[i];
		{
			sum=t2[i]+ans-t1[k-1];
		    printf("%d\n",sum);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
int N;
char s[100000];
int ans[100001];
int i = 1;
void result() {
	for (int j = 0; j < N; j++) {
		if (ans[j] == 1) {
			std::cout << "S";
		}
		else if (ans[j] == -1) {
			std::cout << "W";
		}
	}
	std::cout << std::endl;
}
bool solve(int one) {
	ans[i] = one;
	if (i == N) {
		if (ans[0] != ans[N]) {
			i = 1;
			return false;
		}
		if (ans[0] == 1) {
			if (s[0] == 'o') {
				i = 1;
				return ans[1] == ans[N - 1];

			}
			else {
				i = 1;
				return ans[1] != ans[N - 1];
			}
		}
		else if (ans[0] == -1) {
			if (s[0] == 'o') {
				i = 1;
				return ans[1] != ans[N - 1];
			}
			else {
				i = 1;
				return ans[1] == ans[N - 1];
			}
		}
	}
	if (one == 1) {
		if (s[i] == 'o') {
			ans[i + 1] = ans[i - 1];
			i++;
			solve(ans[i]);
		}
		else {
			ans[i + 1] = -ans[i - 1];
			i++;
			solve(ans[i]);
		}
	}
	else if (one == -1) {
		if (s[i] == 'o') {
			ans[i + 1] = -ans[i - 1];
			i++;
			solve(ans[i]);
		}
		else {
			ans[i + 1] = ans[i - 1];
			i++;
			solve(ans[i]);
		}
	}
}
void zero() {
	for (int q = 0; q < N + 1; q++) {
		ans[q] = 0;
	}
}
int main() {
	std::cin >> N;
	for (int j = 0; j < N; j++) {
		std::cin >> s[j];
	}
	ans[0] = 1;
	if (solve(1)) {
		result();
		return 0;
	}
	else {
		zero();
	}
	ans[0] = 1;
	if (solve(-1)) {
		result();
		return 0;
	}
	else {
		zero();
	}
	ans[0] = -1;
	if (solve(1)) {
		result();
		return 0;
	}
	else {
		zero();
	}
	ans[0] = -1;
	if (solve(-1)) {
		result();
		return 0;
	}
	else {
		zero();
	}
	std::cout << -1 << std::endl;
	return 0;
}

Measured memory_bytes: 768
def sign(x):
    if x == 0:
        return 0
    return x // abs(x)


def main():
    x, y = map(int, input().split())

    if x == 0 or y == 0:
        if y - x >= 0:
            print(y-x)
        else:
            print(x-y+1)
    elif sign(x) == sign(y):
        if y >= x:
            print(y-x)
        else:
            print(x-y+2)
    else:
        print(abs(abs(x)-abs(y))+1)


if __name__ == '__main__':
    main()


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define A first
#define B second
#define MOD 1000000007

typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;

int mulmd(ll a, ll b){
    ll ret = (a * b) % MOD;
    return (int)ret;
}

inline int power(ll x, ll y, int p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = mulmd(res,x);
        y = y>>1;
        x = mulmd(x,x);
    }
    return (int)res;
}

int submd(ll a, ll b){
    ll ret = a-b;
    if(ret<0){
        ret+=MOD;
    }
    return (int)ret;
}

int addmd(ll a, ll b){
    ll ret = (a + b) % MOD;
    return (int)ret;
}

int phi(int n){
    int result = n;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            while(n%i==0){
                n=n/i;
            }
            result-=result/i;
        }
    }
    if(n>1) result-=result/n;
    return result;
}

const int N = 1e5 + 5;

int arr[N];

/**
    Check out for boundary cases, (n = 1 or n = 0)
    check for integer overflow

**/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b;
    cin >> a >> b;
    cout << max(a * b, max(a + b, a - b));
}



Measured memory_bytes: 256
import java.util.*;

public class Main {    
    public static void main(String[] args){        
        Scanner sc = new Scanner(System.in);                
         
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        int count[] = new int[N];
        
        for(int i = 0;i < M;i++){
            count[sc.nextInt() - 1]++;
            count[sc.nextInt() - 1]++;
        }
                     
        for(int i = 0;i < N;i++){
            System.out.println(count[i]);
        }       
        
    }            
}


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

const int size_d = 100000;


int divi( int a,int b){
  return (a+b-1)/b;
}

int main(){
  int n, h, maxa = 0, work, ans=0;
  int b[100000];

  
  cin >> n >> h;

  for(int i=0; i<n; ++i){
    cin >> work >> b[i];
    maxa = max(maxa, work);
  }


  sort(b, b+n);
  //  reverse(b, b+n);

  int cnt=n-1;
  while(h > 0){

    if(cnt>=0 && b[cnt] > maxa){
      h -= b[cnt];
      --cnt;
    }else{
      ans+=  divi( h , maxa );
      break;
    }
    ++ans;
  }

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


Measured memory_bytes: 640
import sys
S = str(input())
i = 0
j = len(S) - 1
c = 0
while(True):
    if i >= j:
        break
    if (S[i] == S[j]):
        i += 1
        j -= 1
    else:
        if (S[i] == 'x'):
            i += 1
            c += 1
        elif (S[j] == 'x'):
            j -= 1
            c += 1
        else:
            print('-1')
            sys.exit()
print(c)

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    int a, b, c, k; cin >> a>> b>> c>>k;
    
    int res = a+b+c;
    int mx = max(a, max(b, c));

    res -= mx;

    cout << res + (mx*((int)pow(2,k))) << endl;
    return 0;
}



Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main()
{
    int i;
    string s;
    cin>>s;
    for(i=1;i<4;i++){
        if(s.substr(i,1)==s.substr(i-1,1)){
            cout<<"Bad"<<endl;
            break;
        }
    }
    if(i==4){
        cout<<"Good"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main() {
    int a,b,c,d;

    cin >> a >> b >> c >> d;
    while(1) {
        c = c - b;
        
        if(c <= 0){
            cout << "Yes" << endl;
            break;
        }
        
        a = a - d;
        if(a <= 0){
            cout << "No" << endl;
            break;
        }
        
    }
    
}

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

// fold {
#define debug(var)  do{ std::cout << #var << " : "; view(var); }while(0)
using ll = long long;
using ld = long double;
inline int num (const std::string& S, int idx) noexcept { return S.at(idx) - '0'; }
inline int ctoi(char c) noexcept { return c - '0'; }
inline bool isNumber(char c) noexcept { return ('0'<c && c<'9'? true : false); }
inline int safeCtoi(char c) { if(isNumber(c)) { return ctoi(c); } else { throw 1; } }
inline char itoc(int i) noexcept { return i + '0'; }
inline unsigned int bitMask(int i) noexcept { return (1 << i); }
inline bool isTrue(unsigned int bit, int i) noexcept { return bit & bitMask(i); }
inline bool isEven(int num) noexcept { return !num%2; }
inline bool isOdd(int num) noexcept { return num%2; }
template<typename T> inline short sgn(T num) noexcept { return (num==0? 0 : (num>0? 1 : -1) ); }
template<typename T> inline bool isZero(T num) noexcept { return (num==0? true : false); }
template<typename T> inline bool isPositive(T num) noexcept { return (num>0? true : false); }
template<typename T> inline bool isNegative(T num) noexcept { return (num<0? true : false); }
template<typename T> void view(T e) noexcept { cout << e; }
template<typename T> void view(std::vector<T> v) noexcept { for(const auto& e : v) cout << e << " "; }
template<typename T> void view(std::vector<std::vector<T>> vv) noexcept { for(const auto& v : vv) view(v); }
// }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string str;
	cin >> str;
	for(auto& c : str){
		if( c == '?' ){
			c = 'D';
		}
	}
	cout << str << endl;
	return 0;
}

Measured memory_bytes: 3772