akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll n, a, b; cin >> n >> a >> b;
  ll ans = (n - 1) * b + a - (n - 1) * a - b + 1;
  if(ans < 0) ans = 0;
  fin(ans)
  return;
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

Measured memory_bytes: 256
n   = gets.to_s.to_i
ary = gets.to_s.split.map{|i|i.to_i}

dp_not  = Hash.new(-10**18)
dp_take = Hash.new(-10**18)
dp_not[[0,0]] = 0

ary.each_with_index do |a,i|
  j = i / 2
  (j..j+1).each do |n|
    dp_not[[i+1,n]] = [dp_not[[i,n]], dp_take[[i,n]]].max
    dp_take[[i+1,n]] = dp_not[[i,n-1]] + a
  end
end

ans = [dp_not[[n,n/2]], dp_take[[n,n/2]]].max
puts ans

Measured memory_bytes: 90076
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;

const int INF = 100000000;

template <typename T>
struct Edge
{
    int to;
    T cost;
};

template <typename T>
struct WeightedGraph
{
    int n;
    vector<vector<Edge<T>>> g;
    
    WeightedGraph(int n) : n(n){
        g.resize(n);
    }
    
    void init(int n_){
        n = n_;
        g.resize(n_);
    }
    
    void add_edge(int from, int to, T cost){
        g[from].push_back((Edge<T>){to, cost});
    }
};

template <typename T>
vector<T> Dijkstra(WeightedGraph<T> &g, int s){
    typedef pair<T, int> P;
    int n = g.n;
    vector<T> d(n);
    fill(d.begin(), d.end(), INF);
    priority_queue<P, vector<P>, greater<P>> que;
    d[s] = 0;
    que.push(P(0, s));
    while(que.size()){
        P nowp = que.top();
        que.pop();
        if(d[nowp.second] < nowp.first) continue;
        for(Edge<T> e : g.g[nowp.second]){
            if(d[e.to] > d[nowp.second] + e.cost){
                d[e.to] = d[nowp.second] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    return d;
}

int main()
{
    int n, x, y;
    cin >> n >> x >> y;
    WeightedGraph<int> g(n);
    for(int i = 0; i < n - 1; i++){
        g.add_edge(i, i + 1, 1);
        g.add_edge(i + 1, i, 1);
    }
    g.add_edge(x - 1, y - 1, 1);
    g.add_edge(y - 1, x - 1, 1);
    int ans[2005]{0};
    for(int i = 0; i < n; i++){
        vector<int> d = Dijkstra(g, i);
        for(int j = 0; j < n; j++) ans[d[j]]++;
    }
    for(int k = 1; k < n; k++) cout << ans[k] / 2 << endl;
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

const int N = 1e5 + 10 , M = 1e2 + 10 ;

ll dp[N][M] ;
int w[M] , v[M] ;

int n , W ;
const ll inf = 1e12 ;

ll f ( int cap , int indx )
{
    if ( cap < 0 )
        return -inf ;

    if ( indx == 0 )
        return 0LL ;

    if ( dp[cap][indx] != -1 )
        return dp[cap][indx] ;

    ll ans = max ( f ( cap - w[indx] , indx - 1 ) + v[indx] , f ( cap , indx - 1 ) ) ;
    ans = max ( ans , 0LL ) ;

    dp[cap][indx] = ans ;

    return dp[cap][indx] ;
}

void solve ( int test_case )
{
    cin >> n >> W ;

    for ( int i=0 ; i <= W ; i ++ )
    {
        for ( int j = 0 ; j <= n + 2 ; j ++ )
            dp[i][j] = -1 ;
    }

    for ( int i = 1 ; i <= n ; i ++ )
        cin >> w[i] >> v[i] ;

    f ( W , n ) ;
    ll ans = dp[W][n] ;

    cout << ans ; line ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


Measured memory_bytes: 86272
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] v = new int[n];
        for (int i = 0; i < n; i++) {
            v[i] = scanner.nextInt();
        }

        long ans = Integer.MIN_VALUE;
        for (int i = 0; i <= Math.min(k, n); i++) {
            for (int j = 0; j <= i; j++) {
                List<Integer> list = new ArrayList<>();
                for (int l = 0; l < j; l++) {
                    list.add(v[l]);
                }
                for (int l = 0; l < i - j; l++) {
                    list.add(v[n - l - 1]);
                }
                Collections.sort(list);
                long sum = 0;
                int r = k - i;
                for (int l : list) {
                    if (l < 0 && r > 0) {
                        r--;
                    } else {
                        sum += l;
                    }
                }
                ans = Math.max(ans, sum);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23628
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([][]int, 2)
	t := [2]int{0, 0}
	for i := 0; i < 2; i++ {
		a[i] = make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Scan(&a[i][j])
			t[i] += a[i][j]
		}
	}

	ans := 0
	for i := 0; i < n; i++ {
		sum := 0
		for j := 0; j <= i; j++ {
			sum += a[0][j]
		}
		for j := i; j < n; j++ {
			sum += a[1][j]
		}

		if ans < sum {
			ans = sum
		}
	}

	fmt.Println(ans)
}


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

int main(){
    string S;
    cin >> S;
    int K;
    cin >> K;
    rep(i,S.size()){
        if(S[i] == 'a') continue;
        if('z' - S[i] + 1 <= K){
            K -= 'z' - S[i] + 1;
            S[i] = 'a';
        }
    }
    if(K > 0) K %= 26;
    rep(i,K){
        S[S.size()-1] = S[S.size()-1] + 1;
        if(S[S.size()-1] == 'z' + 1) S[S.size()-1] = 'a';
    }
    cout << S << endl;

    return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ll n,m;cin >> n >> m;
  if(n == 1 && m == 1){
    cout << 1 << endl;
  } else if(n == 1){
    cout << m-2 << endl;
  } else if(m == 1){
    cout << n-2 << endl;
  } else {
    cout << n*m - (2*n+2*m-4) << endl;
  }
}



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

int n;
int a[100000];
int p[100000];
int l[2][100000];
int r[2][100000];

void sub(int (*r)[100000]) {
  for (int k = 0; k < 2; ++k) {
    for (int i = 0; i < n; ++i) {
      r[k][i] = n;
    }
  }
  
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    auto rit = mp.lower_bound(a[i]);
    for (auto it = mp.begin(); it != rit;) {
      r[it->second][p[it->first]] = i;
      ++it->second;
      if (it->second == 2) {
        it = mp.erase(it);
      } else {
        ++it;
      }
    }
    mp[a[i]] = 0;
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    --a[i];
    p[a[i]] = i;
  }
  
  sub(r);
  reverse(a, a + n);
  sub(l);
  reverse(a, a + n);
  for (int k = 0; k < 2; ++k) {
    for (int i = 0; i < n; ++i) {
      l[k][i] = n - 1 - l[k][i];
    }
  }
  
  long sum = 0;
  for (int i = 0; i < n; ++i) {
    long tmp = long(l[0][i] - l[1][i]) * (r[0][i] - i)
             + long(r[1][i] - r[0][i]) * (i - l[0][i]);
    sum += (a[i] + 1) * tmp;
  }
  cout << sum << endl;
}

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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int a,int b){return (int64_t)a*b/gcd(a, b);}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }

int main()
{
  int64_t ans = 0, c = pow(10, 9) + 7;
  int n;

  cin >> n;
  vector<int64_t> a(n);
  vector<int64_t> sum_a(n);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++)
  {
    if (i == 0)
      sum_a[n - 1 - i] = a[n - 1 - i];
    else
      sum_a[n - 1 - i] = (a[n - 1 - i] + sum_a[n - i]) % c;
  }
  for (int i = 0; i < n - 1; i++)
  {
    ans += a[i] * sum_a[i + 1];
    ans %= c;
  }
  cout << ans << endl;
}


Measured memory_bytes: 6420
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var lcm = 1L;
            for (int i = 0; i < N; i++)
            {
                var t = ReadLong();
                lcm = Lcm(lcm, t);
            }

            return lcm;
        }
        /// <summary>
        /// 最大公約数を求める
        /// </summary>
        public static long Gcd(long a, long b)
        {
            // 引数を入替えて自分を呼び出す
            if (a < b) return Gcd(b, a);

            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }
        /// <summary>
        /// 最小公倍数を求める
        /// </summary>
        public static long Lcm(long a, long b)
        {
            return a / Gcd(a, b) * b;
        }
        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 27472
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
signed main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a[21][21]={},dp[1<<21]={};
  cin >> n;
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) {
      cin >> a[i][j];
    }
  }
  dp[0]=1;
  for(int i=0; i<(1<<n); i++) {
    int cnt=__builtin_popcount(i);
    for(int j=0; j<n; j++) {
      if((i&(1<<j))&&a[cnt-1][j]) {
        (dp[i]+=dp[i^(1<<j)])%=MOD;
      }
    }
  }
  cout << dp[(1<<n)-1] << endl;
}

Measured memory_bytes: 16640
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;
 
#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first                 
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()           
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   N     =  1e6+5;
const ll   mod   =  1e9;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll test = 1, n, d;

void solve(){
	int ans = 0;
	cin >> n >> d;
	for(int i = 0; i < n; i++){
		ll x, y; cin >> x >> y;
		if(x*x + y*y <= d*d) ans++;
	}
	deb1(ans)
}

int main(){
	GODSPEED;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);


            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = input[0];
            int K = input[1];
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

            Console.WriteLine((N + K - 3) / (K - 1));

            //Console.Out.Flush();
            
        }
    }



    public class Calculation
    {

    }

    public class Graph
    {

    }
}



Measured memory_bytes: 18016
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
Int n,ans=0;
void dfs(Int x,Int a,Int b,Int c){
  if(x>n) return; 
  if(a&&b&&c) ans++;
  dfs(x*10+3,1,b,c);
  dfs(x*10+5,a,1,c);
  dfs(x*10+7,a,b,1);
}
signed main(){
  cin>>n;
  dfs(0,0,0,0);
  cout<<ans<<endl;
  return 0;
}


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

int main() {
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a+b+1>c) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


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

public class Solution
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        var sum = a.Sum(x => 1.0 / x);
        Console.WriteLine(1/ sum);
    }
}

Measured memory_bytes: 11348
#include <stdio.h>
#define MAX (300000)

char prime[MAX + 1];

int main(void)
{
	int i, j;
	int n, num;
	
	prime[0] = prime[1] = 0;
	for (i = 2; i <= MAX; i++){
		prime[i] = 1;
	}
	
	for (i = 2; i * i <= MAX; i++){
		for (j = i * i; j <= MAX; j += i){
			prime[j] = 0;
		}
	}
	
	while (scanf("%d", &n), n){
		num = 0;
		i = n + 1;
		n *= 2;
		
		for (; i <= n; i++){
			if (prime[i]){
				num++;
			}
		}
		
		printf("%d\n", num);
	}
	
	return (0);
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <chrono> 
using namespace std::chrono;
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_mset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fr(i,a,b) for (int i=(a); i<(b);++i)
#define frr(i,a,b) for(int i=(a-1);i>=(b);--i)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int> 
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define sz(a) (ll)a.size()
#define endl "\n"
#define po(a,b) (ll)(pow(a,b)+0.5)
#define double long double
#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;
const ll M=1e9+7;
const int MaxM=501;
ll dp[2000005];


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

   
   ll n;
   cin>>n;
     
    ll a[n];
    map<ll,ll> m;
    ll sum=0;
    fr(i,0,n)
    {
      cin>>a[i];
      m[a[i]]++;sum+=a[i];
    }

    int q;cin>>q;
    while(q--)
    {
       ll x,y;
       cin>>x>>y;
       sum+=(y-x)*m[x];
       m[y]+=m[x];
       m.erase(x);
       cout<<sum<<endl;
    }

   }



Measured memory_bytes: 8376
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


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


def S(): return input()


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


def MS(): return map(str, input().split())


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


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


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


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


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


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


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

show_flg = False
# show_flg = True


def main():
    A, B, C = MI()
    m = {}
    m[A] = 0
    m[B] = 0
    m[C] = 0
    m[A] += 1
    m[B] += 1
    m[C] += 1

    if len(m.keys()) == 2:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38640
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes printf("Yes\n")
#define no printf("No\n")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using ull=unsigned long long;
using vi=vector<int>;
using pint=pair<int,int>;

const int INF=1LL<<55;

int n;
int a,b;

int ans=INF;

int tmp;

int x(int x){
    int ret=0;
    while(x!=0){
        ret+=(x%10);
        x/=10;
    }
    return ret;
}

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

    cin>>n;
    for(a=1, b=n-1;b>=1;a++,b--){
        tmp=x(a);
        tmp+=x(b);
        ans=min(tmp,ans);
    }
    cout<<ans<<endl;

    return 0;
}


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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int inf = int (1e9) + int (1e5);
const ll infl = ll(2e18) + ll(1e10);
const ui M = 1E9 + 7;
const double eps = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);i++)
#define MP make_pair

const int NMAX=100000;

struct tree {
    int N;
    vii G[NMAX];
    ll h[NMAX];
    tree(int n) : N(n) {};

    void add_edge(int a, int b, int w = 0) {G[a].push_back(MP(b, w));G[b].push_back(MP(a, w));}

    void build(int root) {
        dfs(root);
    }

    void dfs(int node, int p = -1, ll hh = 0LL) {
        h[node] = hh;
        for(auto c : G[node]) {
            if(c.first != p) {
                dfs(c.first, node, hh + c.second);
            }
        }
    }
};

int main() {
    int N,Q,K,a,b,w;
    cin >> N;
    tree t(N);
    FOR (i,N-1){
        scanf("%d %d %d",&a,&b,&w);
        t.add_edge(--a,--b,w);
    }

    cin >> Q >> K;
    t.build(--K);
    FOR(i,Q){
        scanf("%d %d",&a,&b);
        cout << t.h[--a]+t.h[--b] << endl;
    }

    return 0;
}


Measured memory_bytes: 11136
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

n, a, b = map(int, input().split())

if (b - a) % 2 == 0:
    print(int((b - a) // 2))
else:
    if a - 1 < n - b:
        print(int(a - 1 + 1 + (b - a - 1) // 2))
    else:
        print(int(n - b + 1 + (b - a - 1) // 2))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int p,q;
    char x,y;
    cin>>x>>y;
    p=x,q=y;

    if(p>=65 && p<=70 && q>=65 && q<=70)
    {
        if(p>q) cout<<">\n";
        else if(p<q) cout<<"<\n";
        else if(p==q) cout<<"=\n";
    }
    return 0;
}


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

using namespace std;

int main()
{
  long long int n,m,b;
  cin>>n>>m;
  long long int s=0;
  while(m--)
  {
      cin>>b;
      s=s+b;

  }
  if(s>=n)
      {
          cout<<"Yes"<<endl;
      }
      else
      {
          cout<<"No"<<endl;
      }

    return 0;
}


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

int a,b,k,cnt=0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>a>>b>>k;
	for(int i=100;i>=1;i--){
		if(a%i==0 && b%i==0){
			cnt++;
		}
		if(cnt==k){
			cout<<i;
			break;
		}

	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int main() {
    int x; cin >> x;
    int ans = 0;
    if (x < 600) {
        ans = 8;
    } else if (x < 800) {
        ans = 7;
    } else if (x < 1000) {
        ans = 6;
    } else if (x < 1200) {
        ans = 5;
    } else if (x < 1400) {
        ans = 4;
    } else if (x < 1600) {
        ans = 3;
    } else if (x < 1800) {
        ans = 2;
    } else if (x < 2000) {
        ans = 1;
    }

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

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <set>
using  namespace std;
#define ll long long 
const int maxx = 105;
int a[maxx];
set<int> s;
int main()
{
	
	int n,y;
	cin>>n>>y;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++){
			int k = n - i - j;
			if(k < 0){
				continue ;
			}
			if(i*1000 + j*5000 + k*10000 == y){
				cout<<k<<" "<<j<<" "<<i<<endl;
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1"<<endl;
	
	
	return 0;
} 

Measured memory_bytes: 256
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Main
int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
    }
    
    vector<bool> aaaaa(n, false);
    while (true) {
        bool flag = false;
        rep(i, n) {
            if (!g[i].size() && !aaaaa[i]) {
                vector<vector<int>> new_g(n);
                rep(j, n) {
                    if (j == i) continue;
                    for (int v : g[j]) {
                        if (v != i) new_g[j].push_back(v);
                    }
                }
                g = new_g;
                flag = true;
                aaaaa[i] = true;
                break;
            }
        }
        if (!flag) break;
    }
    int v = -1;
    rep(i, n) {
        if (g[i].size()) v = i;
    }
    if (v == -1) {
        cout << "-1\n";
        return 0;
    }
    vector<bool> visited(n, false);
    visited[v] = true;
    while (true) {
        v = g[v][0];
        if (visited[v]) break;
        visited[v] = true;
    }
    vector<bool> isc(n, false);
    vector<int> nxt(n, -1);
    int x = v;
    do {
        isc[x] = true;
        nxt[x] = g[x][0];
        x = g[x][0];
    } while (x != v);
    
    while (true) {
        bool flag = false;
        [&]{rep(j, n) {
            if (!isc[j]) continue;
            for (int v : g[j]) {
                if (isc[v] && nxt[j] != v) {
                    flag = true;
                    nxt[j] = v;
                    isc = vector<bool>(n, false);
                    int u = j;
                    do {
                        isc[u] = true;
                        u = nxt[u];
                    } while (u != j);
                    return;
                }
            }
        }}();
        if (!flag) break;
    }
    
    vector<int> vec;
    rep(i, n) {
        if (isc[i]) {
            int v = i;
            do {
                vec.push_back(v);
                v = nxt[v];
            } while (v != i);
            break;
        }
    }
    cout << vec.size() << "\n";
    for (int v : vec) cout << v + 1 << "\n";
    return 0;
}


Measured memory_bytes: 3672
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int M1, D1, M2, D2; std::cin >> M1 >> D1 >> M2 >> D2;
  if ( M1 == M2 ) std::cout << 0 << std::endl;
  else std::cout << 1 << std::endl;
  return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 2000010


int main(){
	IOS;
	
	
	ll n,x,y;
	cin>>n>>x>>y;
	ll t=y-x+1;
	ll d[n]={0};
	d[1]=n-1;
	rep(i,2,n)d[i]=d[i-1]-1;
	rep(i,x,y)rep(j,i+1,y+1){
	    ll z=j-i;
	    d[z]--;
	    z=min(z,t-z);
	    d[z]++;
	}
	rep(i,1,x)rep(j,y+1,n+1){
	    ll z=j-i;
	    d[z]--;
	    z=z-(y-x)+1;
	    d[z]++;
	}
	rep(i,1,x)rep(j,x,y+1){
		ll z=j-i;
		d[z]--;
		z=min(z,x-i+1+y-j);
		d[z]++;
	}
	rep(i,y+1,n+1)rep(j,x,y+1){
		ll z=i-j;
		d[z]--;
		z=min(z,i-y+1+j-x);
		d[z]++;
	}
	rep(i,1,n)cout<<d[i]<<"\n";
	
	
	
	
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
int n,X[9],Y[9],a[9];
bool vis[9];
long double tot;
inline long double getdis(int k1,int k2) {
	return sqrt((X[k1]-X[k2])*(X[k1]-X[k2])+(Y[k1]-Y[k2])*(Y[k1]-Y[k2]));
}
inline void check() {
	for(res i=1;i<n;++i) tot+=getdis(a[i],a[i+1]);
}
void dfs(int x) {
	if(x>n) return (void)(check());
	for(res i=1;i<=n;++i) if(!vis[i]) a[x]=i,vis[i]=true,dfs(x+1),vis[i]=false;
}
int main()
{
	cin>>n;
	for(res i=1;i<=n;++i) cin>>X[i]>>Y[i];
	dfs(1);
	int fac=1;
	for(res i=2;i<=n;++i) fac*=i;
	printf("%.10Lf\n",tot/fac);
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 256
/*I MAY NOT GET THE SUCCESS IMMEDIATELY BUT I WILL GET IT FOR SURE*/
#include<bits/stdc++.h>
#define opt std::ios_base::sync_with_stdio(false)
#define I int
#define li		int32_t
#define lli		long long
#define ulli unsigned long long

#define pn			 printf("\n")
#define nl			 cout<<'\n'
#define sf(N)        scanf("%lld",&N)
#define pf(N)        printf("%lld",N)
#define sf1(N1,N2)    scanf("%lld %lld",&N1,&N2)
#define pf1(N1,N2)    printf("%lld %lld",N1,N2)
#define sf2(N1,N2,N3) scanf("%lld %lld %lld",&N1,&N2,&N3)
#define pf2(N1,N2,N3) printf("%lld %lld %lld",N1,N2,N3)

#define sl          cout<<' '
#define ps          printf(" ")

#define rep(i,a,b)	for(i=a;i<b;i++)
#define repr(i,a,b)	for(i=a;i>b;i--)
#define elif		else if
#define mset(a,b)	memset(a,b,sizeof(a))

#define pb		push_back
#define pob		pop_back
#define itr		iterator
#define sz()	size()
#define szof    sizeof
#define lb		lower_bound
#define ub		upper_bound
#define mp		make_pair
#define vlli    vector<lli>
#define plli	pair<lli,lli>
#define vplli	vector<plli >
#define F   	first
#define S		second
#define Dup     erase(unique(V.begin(),V.end()),V.end())

#define bs      binary_search
#define ub      upper_bound
#define lb      lower_bound

#define ALL(V)  V.begin(),V.end()

#define MX1     100000
#define MX2     1000000
#define Inf     1000000000000000
#define mod		1000000007
#define mod1    1000000007
#define mod2    1000000009
using namespace std;

lli Power(lli a,lli b)
{
    lli result=1;

    while(b)
    {
        if(b%2)
        {
            result=(result*a)%mod;
        }

        b=b>>1;
        a=(a*a)%mod;
    }

 return result;
}

int main()
{
    opt;

    /*#ifndef ONLINE_JUDGE
    freopen("double_squares.txt","r",stdin);
    freopen("double_squares_out.txt","w",stdout);
    #endif // ONLINE_JUDGE*/

    lli N;
    cin>>N;

    lli A,B;
    cin>>A>>B;

    cout<<min(N*A,B);







 return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Data.List
import qualified Data.Vector.Unboxed as U

solve n goods w = U.last $ foldl' f initial goods where
  f acc (w, v) = U.zipWith max acc pick where
    pick = U.map (v+) $ U.replicate w (-v) U.++ acc
  initial = U.replicate (w+1) (0::Int)

main = do
  [n,w] <- map read.words <$> getLine
  goods <- replicateM n $ (\[a,b]->(a,b)).map read.words <$> getLine
  print $ solve n goods w

Measured memory_bytes: 12412
using System.Linq;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Numerics;
using System.Runtime.CompilerServices;

namespace AtCoder
{
    class Program
    {

        const int BiggestMod = 1000000007;

        public static void Main()
        {

            var args = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var lumps = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var num = args[0];
            var count = args[1];

            if (count > 50) count = 50;

            for (int i = 0; i < count; i++)
            {
                var memo = new int[num];
                for (int j = 0; j < num; j++)
                    memo[i] = 0;

                for (int j = 0; j < num; j++)
                {

                    memo[Math.Max(0, j - lumps[j])]++;
                    if (j + lumps[j] + 1 < num) memo[j + lumps[j] + 1]--;

                }

                for (int j = 1; j < num; j++)
                    memo[j] += memo[j - 1];

                lumps = memo;

            }

            Console.WriteLine(string.Join(' ', lumps.ToList().ConvertAll(x => x.ToString())));

        }

    }

}


Measured memory_bytes: 64232
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 878;
int G[MAXN][MAXN];
int tag[MAXN], cnt[2];
bool visit[MAXN];
bool dp[MAXN][MAXN];

bool dfs(int N, int cur, int tg) {
     visit[cur] = 1;
     tag[cur] = tg;
     cnt[tg]++;
     bool OK = true;
     for (int i = 1; i <= N; i++) {
         if (cur == i || G[cur][i]) continue;
         if (visit[i] && tg == tag[i]) OK = false;
         else if (!visit[i] && !dfs(N, i, tg ^ 1)) OK = false;
     }
     return OK;
}

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    for (int i = 0; i < M; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        G[x][y] = 1;
        G[y][x] = 1;
    }
    int sum = 0, ans = M;
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        if (!visit[i]) {
           sum++;
           cnt[1] = cnt[0] = 0;
           if (!dfs(N, i, 0)) ans = -1;
           for (int j = 0; j <= N; j++) {
               for (int k = 0; k < 2; k++) {
                   if (j >= cnt[k])
                      dp[sum][j] |= dp[sum - 1][j - cnt[k]];
               }
           }
        }
    }
    for (int i = 0; i <= N; i++) {
        if (dp[sum][i]) {
           ans = min(ans, (i * (i - 1) + (N - i) * (N - i - 1)) / 2);
        }
    }
    printf("%d\n", ans);
    return 0;
}


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

using i64 = int64_t;

constexpr int MAX_N = 100005;

bool used[MAX_N]={0};
vector<int> graph[MAX_N];
int dp[MAX_N]={0};

void dfs(vector<int> &v, int n){
    if(used[n])return;
    used[n] = true;
    for(auto e: graph[n])dfs(v, e);
    v.push_back(n);
}

vector<int> tsort(int size){
    vector<int> res;
    for(int i=1;i<=size;++i)dfs(res, i);
    reverse(res.begin(), res.end());
    return res;
}

int main(){
    int n, m;
    cin >> n >> m;
    for(int i=0;i<m;++i){
        int x, y;
        cin >> x >> y;
        graph[x].push_back(y);
    }
    vector<int> sorted_idxs = tsort(n);
    int ans = 0;
    for(auto i: sorted_idxs){
        ans = max(ans, dp[i]);
        for(auto e: graph[i]){
            dp[e] = max(dp[e], dp[i]+1);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8824
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int h, w, dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
	cin >> h >> w;
	vector<string> a(h);
	rep(snip_i, h) cin >> a.at(snip_i);
	queue<tuple<int, int, int>> q;
	rep(i, h){
		rep(j, w){
			char c = a.at(i)[j];
			if(c == '#') q.push(make_tuple(i, j, 0));
		}
	}

	int ans = -1;
	while(!q.empty()){
		auto t = q.front(); q.pop();
		int y, x, co;
		tie(y, x, co) = t;
		rep(i, 4){
			int nx = x + dx[i], ny = y + dy[i];
			if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
			if(a.at(ny)[nx] == '.'){
				a.at(ny)[nx] = '#';
				q.push(make_tuple(ny, nx, co+1));
			}
		}
		ans = co;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 13456
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[10010];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++) cin>>a[i];
	for(int i=1;i<=m;i++) n-=a[i];
	if(n<0) n=-1;
	cout<<n;
	return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>
using namespace std;

int find(vector<int> &tab, int a){
    if(tab[a]==-1)return a;
    tab[a]=find(tab, tab[a]);
    return tab[a];
}

void utree(vector<int> &tab, int a, int b){
    auto pa=find(tab, a);
    auto pb=find(tab, b);
    if(pa!=pb)tab[pb]=pa;
}

void solve(long long N, std::vector<long long> x, std::vector<long long> y){
    auto ans=(long long)pow(10,10);

    if(N==1){
        cout << 1 << endl;
        return;
    }

    set<pair<int, int>> pqcands;
    for(int i=0; i<N-1; i++){
        for(int j=i; j<N; j++){
            auto w = x[i]-x[j], h=y[i]-y[j];
            pqcands.insert(make_pair(w, h));
        }
    }

    for(auto pq: pqcands){
        auto p=pq.first, q=pq.second;
        vector<int> tab(N, -1);
        set<int> parents;

        for(int i=0; i<N-1; i++){
            for(int j=i; j<N; j++){
                auto w = x[i]-x[j], h=y[i]-y[j];
                if((w==p && h==q) || (w==-p && h==-q))
                    utree(tab, i, j);
            }
        }

        for(int i=0; i<N; i++)
            parents.insert(find(tab, i));

        if(parents.size() < ans)
            ans = parents.size();
    }

    cout << ans << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
    }
    solve(N, std::move(x), std::move(y));
    return 0;
}


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

using namespace std;
#define ll long long
const ll MOD = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    ll INF = (ll)1 << 60;
    ll u = INF, d = -INF;
    while (u - d > 1) {
        ll m = (u + d) / 2, c = 0;
        for (ll i = 0; i < N; i++) {
            if (A[i] * A[i] <= m) c--;
            if (A[i] < 0) {
                ll mn = (m / A[i]) - 5;
                while (mn * A[i] > m) mn++;
                ll pos = lower_bound(A.begin(), A.end(), mn) - A.begin();
                c += N - pos;
            } else if (A[i] > 0) {
                ll mx = (m / A[i]) + 5;
                while (mx * A[i] > m) mx--;
                ll pos = upper_bound(A.begin(), A.end(), mx) - A.begin();
                c += pos;
            } else {
                if (m >= 0) {
                    c += N;
                }
            }
        }
        c /= 2;
        if (c >= K) {
            u = m;
        } else {
            d = m;
        }
    }
    cout << u << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
typedef long double lb;
using namespace std;
ll gcd(ll P, ll Q){
  return Q ? gcd(Q,P % Q):P;
}
ll lcm(ll P, ll Q){
  return P / gcd(P,Q) * Q;
}
string change_big(string str){
  transform(str.begin(), str.end(), str.begin(), ::toupper);
}
string change_small(string str){
  transform(str.begin(), str.end(), str.begin(), ::tolower);
}
bool is_prime(int x){
  if(x<=1) return false;
  for(int i=2;i*i<=x;i++)
    if(x%i==0) return false;
  return true;
}
int main(){
  ll N;
  cin >> N;
  ll P[N];
  ll ans = 0;
  for(int i = 0; i < N; i++){
    cin >> P[i];
    if(is_prime(P[i]) == true){
      ans++;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3056
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		long A[]=new long[N];
		int z=0;
		long sum=0,x=1,ans=0;
		while(z<N){
			A[z]=stdIn.nextInt();
			sum+=A[z];
			A[z]=sum;
			if(A[z]==0)
				ans++;
			z++;
		}z=1;sum=1;
		Arrays.sort(A);
		while(z<N){
			if(A[z]!=A[z-1]){
				ans+=x-sum;
				x=0;sum=0;
			}
			sum++;x+=sum;
			z++;
		}
		ans+=x-sum;
		System.out.println(ans);
	}
}

Measured memory_bytes: 89128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  ll n, k;
  cin >> n >> k;
  
  ll ans = 0;
  vector<ll> x(n);  
  rep(i, 0, n) {
    cin >> x[i];
    ans += min(k-x[i], x[i]-0);
  }
  
  cout << ans*2 << "\n";
  
  //cout << (  ?"Yes" :"No") << "\n";
  
  //cout << fixed << setprecision(15) << n << "\n";

}

Measured memory_bytes: 256
X = int(input())
ans =0 
while(1):
    if X < 5:
        break
    elif X<500:
        tmp = X // 5
        ans +=tmp*5
        X = X% 5
    else:
        tmp = X // 500
        ans +=tmp*1000
        X = X %500
print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

ll tri[101010];

ll hoge(ll a, ll b, ll c, ll d){
    a = (a * b) % MOD;
    c = (c * d) % MOD;
    return (a * c) % MOD;
}

ll calc(ll A, ll L, ll C, ll R){
    ll tmp = 0;
    tmp = (tmp + hoge(A, C, tri[L], tri[R])) % MOD;
    if(R)tmp = (tmp + hoge(A, R, tri[L], tri[R - 1])) % MOD;
    if(L)tmp = (tmp + hoge(L, C, tri[L - 1], tri[R])) % MOD;
    if(L && R)tmp = (tmp + hoge(L, R, tri[L - 1], tri[R - 1])) % MOD;
    return tmp;
}

int main(){

    tri[0] = 1;
    for(ll i = 1; i < 101000; i++){
        tri[i] = tri[i - 1] * 3 % MOD;
    }

    string s;
    cin >> s;
    s = "@" + s + "@";
    ll sz = s.size();
    vector<ll>A(sz, 0);
    vector<ll>L(sz, 0);
    vector<ll>C(sz, 0);
    vector<ll>R(sz, 0);
    for(ll i = 1; i < s.size(); i++){
        A[i] = A[i - 1];
        L[i] = L[i - 1];
        if(s[i] == 'A')A[i]++;
        if(s[i] == '?')L[i]++;
    }
    for(ll i = s.size() - 2; i >= 0; i--){
        C[i] = C[i + 1];
        R[i] = R[i + 1];
        if(s[i] == 'C')C[i]++;
        if(s[i] == '?')R[i]++;
    }
    ll ans = 0;
    for(ll i = 1; i + 1 < s.size(); i++){
        if(s[i] == 'A' || s[i] == 'C')continue;
        ans = (ans + calc(A[i - 1], L[i - 1], C[i + 1], R[i + 1])) % MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4348