akhauriyash/Code-Regression huggingface dataset:
open System
let n = stdin.ReadLine() |> int
let xy = Array.init n (fun _ -> stdin.ReadLine().Split() |> Array.map int |> (fun [|a;b|] -> (a,b)))

let d (x1,y1) (x2,y2) = Math.Sqrt (((float x1) - (float x2))**2.0 + ((float y1) - (float y2))**2.0)

let keisu = 2.0 / (float n)

let D = [for i in 0..(n - 1) do
         for j in (i + 1)..(n - 1) do
         yield (d xy.[i] xy.[j])] |> List.sum

D * keisu
|> stdout.WriteLine

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


int main() {
  int n,m;
  
  cin >> n >> m;
  
  int sum1=0,sum2=0;
  
  for(int i=0; i<n; i++){
    sum1+=i;
  }
  
  for(int i=0; i<m; i++){
    sum2+=i;
  }
  
  cout << sum1+sum2;
  
  
  
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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 ll;

const long long INF = 1LL << 60;

struct edge {
    ll from, to, cost;
};

int main()
{
    int N, M;
    cin >> N >> M;

    vector<edge> G(M);
    vector<ll> dist(N, INF);

    rep(i, M) {
        ll a, b, c;
        cin >> a >> b >> c;
        G[i] = {a - 1, b - 1, -c};
    }

    dist[0] = 0;
    bool flag = true;
    int cnt = 0;
    for(int i = 0; i <= 2*N; ++i){
        for(edge e : G){
            if(dist[e.from] != INF && dist[e.to] > dist[e.from] + e.cost){
                dist[e.to] = dist[e.from] + e.cost;
                if(i >= N && e.to == N-1){
                    cout << "inf" << endl;
                    return 0;
                }
            }
        }
    }

    cout << -dist[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class ABC155C
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var N = NN;
            var SList = NSList(N).GroupBy(e => e).ToDictionary(e => e.Key, e => e.Count());
            var max = SList.Values.Max();
            foreach (var item in SList.Where(e => e.Value == max).Select(e => e.Key).OrderBy())
            {
                Console.WriteLine(item);
            }
        }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static IEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderBy(e => e, StringComparer.Ordinal);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b + c || b == a + c || c == a + b){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <queue>


using namespace std;

typedef long long ll;
int c[505];
int s[505];
int f[505];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<n; i++)
        scanf("%d%d%d",&c[i],&s[i],&f[i]);
    for(int i=1; i<n; i++)
    {
        int ans=0;
        for(int j=i; j<n; j++)
        {
            if(ans<s[j])
                ans=s[j];
            if(ans%f[j]!=0)
                ans=ans+f[j]-ans%f[j];
            ans+=c[j];
        }
        printf("%d\n",ans);
    }
    cout<< 0 <<endl;
    return 0;
}















Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int x, y, z;
	int h_c, t_c;

	h_c = t_c = 0;

	while (scanf("%d,%d,%d", &x, &y, &z) != EOF){

		if (x == y){
			h_c++;
		}

		if (z * z == (x * x + y * y)){
			t_c++;
		}

	}

	printf("%d\n%d\n", t_c, h_c);

	return (0);
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}


// x^n(mod M)
ll mpow(ll x, ll n) {
    ll ans = 1ll;
    while(n != 0){
        if (n&1) ans = ans*x;
        x = x*x;
        n = n >> 1;
    }
    return ans;
}

int main(int argc, char const *argv[]) {
    int a,b,c; cin>>a>>b>>c;
    int k; cin>>k;
    bool ok = false;
    for (int i = 0; i <= k; ++i) {
        for (int j = 0; j+i <= k; ++j) {
            ll na,nb,nc;
            na = a; nb = b; nc = c;
            int I = mpow(2ll,i);
            int J = mpow(2ll,j);
            nb *= I;
            nc *= J;
            if (na < nb && nb < nc) {
                cout << "Yes" << '\n';
                return 0;
            }
        }
    }

    cout << "No" << '\n';
    return 0;
}

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

#ifndef ONLINE_JUDGE
#define debarr(a,x,y)cerr<<#a<<":";for(int i=x;i<=y;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define deb(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S, class T>ostream &operator<<(ostream &os, const pair<S, T> &p) {return os << "(" << p.first << "," << p.second << ")";}
template<class T>ostream &operator<<(ostream &os, const vector<T> &p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>ostream &operator<<(ostream &os, const set<T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>ostream &operator<<(ostream &os, const multiset<T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class S, class T>ostream &operator<<(ostream &os, const map<S, T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>void dbs(string str, T t) {cerr << str << ":" << t << "\n";}
template<class T, class...S>void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << ":" << t << ","; dbs(str.substr(idx + 1), s...);}
#else
#define deb(...){}
#define debarr(a,x,y){}
#define debmat(mat,row,col){}
#endif
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define pr(x) {cout << x << "\n"; return;}

#define int              long long
#define ll               long long
#define ld               long double
#define fi               first
#define se               second
#define mp               make_pair
#define pb               push_back
#define sz(x)            (int)x.size()
#define all(x)           x.begin(),x.end()
#define ini(x,y)         memset(x,y,sizeof(x))
#define rep(i,n)         for(int i=0;i<n;i++)
#define re(i,n)          for(int i=1;i<=n;i++)
#define fr(i,a,b)        for(int i=a;i<=b;i++)
#define fb(i,a,b)        for(int i=a;i>=b;i--)
typedef pair<int, int>   pii;
typedef vector<int>      vi;
typedef vector<pii>      vii;
typedef map<int, int>    mii;
typedef set<int>         si;
const int N = 2e5 + 10;

void solve(int tc)
{
	string s; cin >> s;
	int sum = 0;
	rep(i, s.length())
	{
		sum += s[i] - '0';
	}
	if (sum % 9 == 0) cout << "Yes\n";
	else cout << "No\n";
}
signed main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	//cin >> t;
	for (int i = 1; i <= t; i++) solve(i);
	return 0;
}

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

vector<long long> A, B, C, D;

int dfs(vector<long long> current, long long M, long long N, long long Q) {
    if (current.size() == N) {
        int i = 0;
        int point = 0;
        for (; i < Q; i++) {
            if (current[B[i]-1] - current[A[i]-1] == C[i]) {
                point += D[i];
            }
        }
        return point;
    }

    int val = current.size() == 0 ? 1 : current.back();
    int result = 0;
    for (int i = val; i <= M; i++) {
        current.push_back(i);
        result = max(result, dfs(current, M, N, Q));
        current.pop_back();
    }
    return result;
}

void solve(long long N, long long M, long long Q, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c, std::vector<long long> d){
    A = a;
    B = b;
    C = c;
    D = d;
    vector<long long> current;
    cout << dfs(current, M, N, Q) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> a(Q);
    std::vector<long long> b(Q);
    std::vector<long long> c(Q);
    std::vector<long long> d(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
        scanf("%lld",&c[i]);
        scanf("%lld",&d[i]);
    }
    solve(N, M, Q, std::move(a), std::move(b), std::move(c), std::move(d));
    return 0;
}


Measured memory_bytes: 3692
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
struct high { int x, y, h; };
high t[100];
int main() {
	int n; cin >> n;
	ll mi = INF;
	rep(i, n) {
		int x, y;ll h; cin >> x >> y >> h;
		t[i] = { x,y,h };
		mi = min(mi, h);
	}
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			for (ll k = mi; k <= mi + 200; k++) {
				bool f = true;
				rep(l, n) {
					int z = t[l].h + abs(t[l].x - i) + abs(t[l].y - j);
					if (t[l].h + abs(t[l].x - i) + abs(t[l].y - j) != k) {
						if (t[l].h != 0 || z < k) {
							f = false; break;
						}
					}
				}
				if (f) {
					cout << i << " " << j << " " << k << endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
class Main{
    public static void main(String[] args) throws IOException {
        int i,j,k;
        long sum;
        int[][] A = new int[101][101];
        int[][] B = new int[101][101];
        int[] n = new int[990];
        String[] str = new String[990];
        StringBuilder out = new StringBuilder();
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        str = in.readLine().split(" ");
        for(i=0;i<3;i++){
            n[i]=Integer.parseInt(str[i]);   
        }
        for(i=0;i<n[0];i++){
            str = in.readLine().split(" ");
            for(j=0;j<n[1];j++){
                A[i][j]=Integer.parseInt(str[j]);
            }
        }
        for(i=0;i<n[1];i++){
            str = in.readLine().split(" ");
            for(j=0;j<n[2];j++){
                B[i][j]=Integer.parseInt(str[j]);
            }
        }
        for(i=0;i<n[0];i++){
            for(j=0;j<n[2];j++){
                sum=0;
                for(k=0;k<n[1];k++){
                    sum += B[k][j]*A[i][k];             
                }
                if(j!=0) out.append(" ");
                out.append(sum);
            }
            out.append("\n");
        }   
        System.out.print(out);   
        System.out.flush();
    }
}



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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

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

int main(){
	int n, h[1000], cnt=0;
	cin >> n;
	rep(i, n) cin >> h[i];

	rep(i, n){
		bool f = true;

		repp(j, i){
			if(h[j] > h[i])
				f = false;
		}

		if(f) ++cnt;
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin >> n;
    pair<int,int> a[n],b[n];
    for (int i=0; i<n; i++){
        int x,y;
        cin>> x >>y;
        a[i]=make_pair(x,y);
    }
    for (int i=0; i<n; i++){
        int x,y;
        cin >> x >> y;
        b[i]=make_pair(y,x);
    }
    sort(a,a+n);
    reverse(a,a+n);
    sort(b,b+n);
    int ans=0;
    int used[n];
    for (int i=0; i<n; i++){
        used[i]=0;
    }
    for (int i=0; i<n; i++){
        for (int j=0; j<n; j++){
            if (a[i].first <b[j].second && a[i].second <b[j].first && used[j]==0){
                used[j]=1;
                ans++;
                break;
            }
        }
    }
    cout << ans ;
}

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

public class Main{

     public static void main(String []args)/*throws IOException*/{
        
        /*
        InputStreamReader reader=new InputStreamReader(System.in);
 
        BufferedReader input =
			new BufferedReader (new InputStreamReader (System.in));
			
		int key = reader.read();
		String str = input.readLine();
		*/
		Scanner stdIn = new Scanner(System.in);
		
		int a,b,c,d;
		
		a = stdIn.nextInt();
		b = stdIn.nextInt();
		c = stdIn.nextInt();
		d = stdIn.nextInt();
		
		String ans = "No";
		if(Math.abs(c - a) <= d || (Math.abs(b - a) <= d && Math.abs(c - b) <= d)){
		  ans = "Yes";
		}
		
		System.out.println(ans);
	
     }
}

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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N; 
  cin >> N;

  vector<pair<int, int>> ans;
  if(N%2 == 0){
    REP(i, N){
      FOR(j, i+1, N){
        if(j != N-i-1) ans.emplace_back(i, j);
      }
    }
  }else{
    REP(i, N-1) ans.emplace_back(i, N-1);
    REP(i, N-1){
      FOR(j, i+1, N-1){
        if(j != N-i-2) ans.emplace_back(i, j);
      }
    }
  }

  cout << ans.size() << endl;
  REP(i, ans.size()){
    cout << ans[i].first+1 << " " << ans[i].second+1 << endl;
  }


  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;

#define INF (1<<29)


bool f[50];
pair<int,int> pq[50*49/2];

int main(){
	int n,k;
	vector<int> b[50];
	cin>>n>>k;
	for(int i=0;i<k;i++){
		int m;
		cin>>m;
		for(int j=0;j<m;j++){
			int a;
			cin>>a;
			a--;
			b[i].push_back(a);
		}
	}
	int r;
	cin>>r;
	for(int i=0;i<r;i++){
		int p,q;
		cin>>p>>q;
		p--;q--;
		pq[i]=make_pair(p,q);
	}
	sort(pq,pq+r);
	for(int i=0;i<k;i++){
		for(int j=0;j<b[i].size();j++){
			for(int h=0;h<b[i].size();h++){
				if(binary_search(pq,pq+r,make_pair(b[i][j],b[i][h]))){
					f[b[i][j]]=true;
					f[b[i][h]]=true;
				}		
			}
		}
	}
	cout<<count(f,f+n,true)<<endl;	
	return 0;
}

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

int main(void)
{
	ios_base::sync_with_stdio(false);    
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	
	if(k<a)
		cout<<k<<"\n";
	else if(k>=a&&k<=a+b)
		cout<<a<<"\n";
	else if(k>a+b)
	{
		ll no=k-(a+b);
		cout<<a-no<<"\n";
	}
	
	return 0;
}

Measured memory_bytes: 3652
main :: IO ()
main = do
  (n:m:_) <- fmap (map read . words) getLine :: IO [Int]
  print $ solve n m

solve :: Int -> Int -> Int
solve n m = go (m `div` n) n m
  where
    go i n m
      | m `mod` i == 0 = if check n (m `div` i)
                         then i
                         else go (i+1) n m
      | otherwise = go (i-1) n m
    check n m = True


Measured memory_bytes: 508
from collections import Counter

n = int(input())
s = input()
counter = Counter(s)
ans = counter['R'] * counter['G'] * counter['B']
for i in range(n):
    for j in range(i, n):
        k = j + (j - i)
        if k >= n:
            break
        if s[i] != s[j] != s[k] != s[i]:
            ans -= 1

print(ans)

Measured memory_bytes: 9344
from collections import deque

H,W = map(int,input().split())
S = [[] for i in range(H)]
for i in range(H): S[i] = list(input())

dx = [0,1,0,-1]
dy = [1,0,-1,0]
seen = [[0]*W for i in range(H)]
que = deque([[0,0]])
seen[0][0] = 1
while True:
    if len(que) == 0: break #たどり着けない
    h,w = que.popleft()
    if h == H-1 and w == W-1: break #ゴール
    for i in range(0,4):
        if (h+dy[i]<0 or h+dy[i]>=H or w+dx[i]<0 or w+dx[i]>=W): continue
        if S[h+dy[i]][w+dx[i]] == "." and seen[h+dy[i]][w+dx[i]] == 0:
            seen[h+dy[i]][w+dx[i]] = seen[h][w]+1
            que.append([h+dy[i],w+dx[i]])

cnt = 0
for a in range(H):
    for b in range(W):
        if S[a][b] == ".": cnt += 1

if seen[H-1][W-1] == 0:
    print(-1)
else:
    print(cnt-seen[H-1][W-1])

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

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

#define sync std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define loopi(n) for(int i=0;i<n;i++)
#define loopj(n) for(int j=0;j<n;j++)
#define loop(a,b,c) for(int i=a;i<=b;i=i+c)

#define     deb(x)      cout<<#x<<"="<<x<<endl
#define     all(x)      (x).begin(),(x).end()
#define     reset(a)    memset(a,0,sizeof(a))
#define     sz(x)       ((int)(x.size()))
#define     pb          push_back
#define     pf          push_front
#define     pob	        pop_back
#define     pof         pop_front
#define     ins         insert
#define     F           first
#define     S           second
#define     mkp         make_pair
#define     mkt         make_tuple
#define     bitcount(x) __builtin_popcountll(x)
#define     gcd(a,b)    (__gcd(a,b))
#define     lcm(a,b)    ((a*b)/gcd(a,b))
#define PI 3.1415926535897932384626
 
const int mod = 1e9+7;

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

void solve()
{
	int n;
	cin>>n;
	cout<<(n?0:1);
}

int main() 
{
	sync;

	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
		cout<<endl;
	}
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void main_()
{
    ll N;
    cin >> N;
    vector<vector<bitset<16>>> testimony(N + 1, vector<bitset<16>>(2)); // 1-origin

    for (ll i = 1; i <= N; i++) {
        ll A;
        cin >> A;
        for (ll j = 0; j < A; j++) {
            int x, y;
            cin >> x >> y;
            testimony[i][y].set(x);
        }
    }

    ll ans = 0;
    for (ll i = 0; i < (2 << N); i += 2) {
        auto honest_assumption = bitset<16>(i);
        auto honest = bitset<16>(); // 正直者と仮定した人が正直と証言した人の集合
        for (ll j = 1; j <= N; j++) {
            if (honest_assumption[j]) {
                honest |= testimony[j][1];
            }
        }
        auto unkind = bitset<16>(); // 正直者と仮定した人が不誠実と証言した人の集合
        for (ll j = 1; j <= N; j++) {
            if (honest_assumption[j]) {
                unkind |= testimony[j][0];
            }
        }

        // 正直者の証言に矛盾が存在しないか
        // 正直者と証言した人はすべて正直者と仮定した集合に含まれる
        // 正直者が不誠実と証言した人は正直者と仮定した集合に含まれない
        if ((honest_assumption & honest) == honest && (honest_assumption & unkind).none()) {
            ans = max(ans, (ll)honest_assumption.count());
        }
    }

    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;

struct Point {
	int x, y;
};

const double EPS = 1E-10;
Point h, d, p[20];
int n;
bool flag[20];

bool dfs(double t, int s) 
{
	int i;
	for (i = 0; i < n; i++) {
		if (!flag[i]) break;
	}
	if (i == n) return true;
	
	Point pp = (s == -1) ? h : p[s];
	for (i = 0; i < n; i++) {
		if (flag[i]) continue;
		if (hypot(d.x - p[i].x, d.y - p[i].y) - hypot(pp.x - p[i].x, pp.y - p[i].y) - t < EPS) return false;
	}
	
	for (i = 0; i < n; i++) {
		if (flag[i]) continue;
		flag[i] = true;
		if (dfs(t + hypot(pp.x - p[i].x, pp.y - p[i].y), i)) return true;
		flag[i] = false;
	}
	
	return false;
}

int main()
{	
	while (cin >> n >> h.x >> h.y >> d.x >> d.y, n | h.x | h.y | d.x | d.y) {
		memset(flag, false, sizeof(flag));
		for (int i = 0; i < n; i++) {
			cin >> p[i].x >> p[i].y;
		}
		cout << (dfs(0, -1) ? "YES" : "NO") << endl;
	}
	
	return 0;
}

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

int main(void){
    ll n,m,i,j,c,d,k;
    while(1){
        cin >> n >> m;
        if(n*m==0)
            return 0;
        vector<int> h(n), w(m);
        for(i=0;i<n;i++) cin >> h[i];
        for(i=0;i<m;i++) cin >> w[i];
        vector<ll> hl, wl;

        ll cum;
        for(i=0;i<n;i++){
            cum=0;
            for(j=i;j<n;j++){
                cum += h[j];
                hl.push_back(cum);
            }
        }
        for(i=0;i<m;i++){
            cum=0;
            for(j=i;j<m;j++){
                cum += w[j];
                wl.push_back(cum);
            }
        }
        sort(hl.begin(), hl.end());
        sort(wl.begin(), wl.end());

        ll ans=0;
        i=0;j=0;
        while(i<hl.size() && j<wl.size()){
            if(hl[i]==wl[j]){
                c=0;d=0;
                k=hl[i];
                while(hl[i]==k && i<hl.size()){
                    c++;
                    i++;
                }
                k=wl[j];
                while(wl[j]==k && j<wl.size()){
                    d++;
                    j++;
                }
                ans += c*d;
            }else if(hl[i]<wl[j]){
                i++;
            }else{
                j++;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 36960
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def func(n):
    if n % 2 == 0:
        return n/2
    else:
        return 3 * n + 1

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [s] = [long(input_raw[0])]

    i = 0
    pre_a = s
    appare_set = set([pre_a])
    count = 1

    while 1:
        a = func(pre_a)
        count += 1
        if a in appare_set:
            print count
            return
        else:
            appare_set.add(a)
            pre_a = a



if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val x = (1..n).map {
        sc.nextInt()
    }

    println(abc156c(n, x))
}

private fun abc156c(n: Int, x: List<Int>): Int {
    val p = x.sum() / n

    val a = x.map { calc(it, p) }.sum()
    val b = x.map { calc(it, p + 1) }.sum()
    
    return Math.min(a, b)
}

private fun calc(xi: Int, p: Int): Int {
    var temp = xi - p
    return Math.pow(temp.toDouble(), 2.0).toInt()
}

Measured memory_bytes: 31512
#include <iostream>
#include <vector>
#include <string>
int main() {
  int n;
  bool a=true;
  std::vector<std::string> v(101);
  std::cin>>n;
  for(int i=0;i<n;++i){
    std::cin >> v[i];
    if(i){
      a=(v[i-1].back()==v[i][0]?a:false);
      for(int j=0;j<i;++j){a=(v[j]==v[i]?false:a);}
    }
  }
  std::cout<<(a?"Yes":"No")<<"\n";
}
    

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

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

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

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

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    string prefix, s, postfix;
    cin >> prefix >> s >> postfix;

    cout << "A" << s[0] << "C" << endl;
    return 0;
}


Measured memory_bytes: 256
def read():
    N = int(input().strip())
    S = input().strip()
    return N, S

def rle_encode(S):
    S1 = S + '@'
    rle = list()
    head = 0
    for i in range(0, len(S1)):
        if S1[i] != S1[head]:
            rle.append((S1[head], i-head))
            head = i
    return rle

def solve(N, S):
    return len(rle_encode(S))

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


Measured memory_bytes: 45680
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.StringTokenizer;

public class Main {
	
	public static double area(long W, long H, long x, long y) {
		final long total = W * H;
		
		final double dx = (double)(y) / x;

		final double upper = (double)(x * y) / 2;
		final double middle = (H - y) * x;
		
		final double nx = Math.min(W - x, (H - y) * dx);
		final double ry = (H - y) - Math.min(H - y, nx / dx);
		
		final double lower = ((H - y) - (ry)) * nx / 2.0;
		
		final double area = upper + middle + lower;
		return Math.min(area, total - area);
	}
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final long W = sc.nextLong();
			final long H = sc.nextLong();
			final long x = sc.nextLong();
			final long y = sc.nextLong();
			
			System.out.printf("%.10f %d\n", W * H / 2.0, (W == x * 2 && H == y * 2) ? 1 : 0);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

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

int n;
bool graph[60][60];
bool visited[60];

void dfs(int x){
    if(visited[x]) return;
    visited[x]=true;
    for(int i = 0; i < n; i++)
    {
        if(graph[x][i]){
            dfs(i);
        }
    }
}

int main(){
    int m;
    cin >> n >> m;
    int a[m], b[m];
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    int ans = 0;
    for(int i = 0; i < m; i++)
    {
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

        for(int i = 0; i < n; i++) visited[i]=false;
        dfs(0);
        bool connected = true;
        for(int i = 0; i < n; i++)
        {
            if(!visited[i]) connected = false;
        }
        if(!connected){
            ans++;
        }

        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
struct bian
{
	int nxt,to;
}bi[200020];
int n,m,head[100010],num,a[100010],b[100010],c[100010],f[100010],p[100010];
long long sum[100010],dp[100010];
vector<int>E[100010];
inline void add(int from,int to){bi[++num]=bian{head[from],to};head[from]=num;}
bool cmp(int x,int y){return c[x]<c[y];}
int find(int x){if(x!=f[x])return f[x]=find(f[x]);return x;}
void dfs(int v)
{
	sum[v]=b[v];
	if(!E[v].size())
	{
		dp[v]=max(a[v],b[v]);
		return ;
	}
	for(auto u:E[v])
	{
		dfs(u);
		sum[v]+=sum[u];
	}
	dp[v]=0x3f3f3f3f3f3f3f3f;
	for(auto u:E[v])dp[v]=min(dp[v],sum[v]-sum[u]+max(1ll*c[v],dp[u]));
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%d %d",&a[i],&b[i]),c[i]=max(a[i]-b[i],0);
	int x,y;
	for(int i=1;i<=m;++i)
	{
		scanf("%d %d",&x,&y);
		add(x,y),add(y,x);
	}
	for(int i=1;i<=n;++i)p[i]=i;
	sort(p+1,p+1+n,cmp);
	for(int i=1;i<=n;++i)
	{
		x=p[i];
		f[x]=x;
		for(int j=head[x],u;j;j=bi[j].nxt)
		{
			u=find(bi[j].to);
			if(u&&u!=x)
			{
				f[u]=x;
				E[x].push_back(u);
			}
		}
	}
	dfs(p[n]);
	printf("%lld",dp[p[n]]);
	return 0;
}


Measured memory_bytes: 14720
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>

int main(int argc, char *argv[]) {  
	std::string s;
	int k;
	std::cin >> s >> k;
//	std::vector<std::string> ss;
	std::set<std::string> ss;
	for (int i = 0; i < s.length(); i++) {
		for (int j = 1; j <= std::min((int)s.length()-i, 5); j++) {
//			ss.push_back(s.substr(i, j));
			ss.insert(s.substr(i, j));
		}
	}
//	std::sort(ss.begin(), ss.end());
//	std::unique(ss.begin(), ss.end());
//	std::cout << ss[k-1];
int cnt = 1;
	for (auto it: ss) {
		if (cnt == k) {
			std::cout << it;
		}
		cnt++;
	}
}

Measured memory_bytes: 1664
import sys
from collections import deque as dq
input = sys.stdin.readline
S = dq(list(input())[: -1])
Q = int(input())
rev = 0
ap = [dq([]), dq([])]
for _ in range(Q):
  t = input().split()
  if int(t[0]) == 1: rev = (rev + 1) % 2
  else:
    f, c = int(t[1]) - 1, t[2]
    if (f + rev) % 2: S.append(c)
    else: S.appendleft(c)
if rev: S.reverse()
print("".join(S))

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

int main(){
  int n;cin >> n;
  vector<int> t(n);
  vector<int> x(n);
  vector<int> y(n);
  bool ans=true;
  for(int i=0;i<n;i++)cin >> t[i] >> x[i] >> y[i];
  for(int i=0;i<n&&ans;i++){
    int a=x[i]+y[i];
    if(t[i]%2==0&&a%2==0){
      if(a<=t[i]){
        ans=true;
      }else{
        ans=false;
      }
    }else if(t[i]%2==1&&a%2==1){
      if(a<=t[i]){
        ans=true;
      }else{
        ans=false;
        break;
      }
    }else{
      ans=false;
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0; i < N ; i ++){
  cin >> vec.at(i) ;}
sort(vec.begin(), vec.end());
cout << vec.at(N-1) - vec.at(0) <<endl;
}

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

using namespace std;

int main()
{
    int num;

    cin >> num;
    for (int i = 0; i < num; i++) {
        string s1, s2;

        cin >> s1 >> s2;
        if (s1.size() > 80 || s2.size() > 80)
            cout << "overflow" << endl;
        else {
            int i1 = s1.size();
            int i2 = s2.size();
            string ans;
            int tmp = 0;
            int up = 0;

            for ( ; (i1 > 0) && (i2 > 0); i1--, i2-- ) {
                tmp = (s1[i1 - 1] + s2[i2 - 1]) - 2 * '0' + up;
                up = tmp / 10;
                tmp %= 10;
                ans = char(tmp + '0') + ans;
            }
            
            if (i1 > 0) {
                for ( ; i1 > 0; i1--) {
                    tmp = s1[i1 - 1] - '0' + up;
                    up = tmp / 10;
                    tmp %= 10;
                    ans = char(tmp + '0') + ans;
                }
            }
            else if (i2 > 0) {
                for ( ; i2 > 0; i2--) {
                    tmp = s2[i2 - 1] - '0' + up;
                    up = tmp / 10;
                    tmp %= 10;
                    ans = char(tmp + '0') + ans;
                }
            }

            if (up > 0)
                ans = char(up + '0') + ans;

            if (ans.size() > 80)
                cout << "overflow" << endl;
            else
                cout << ans << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}


template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
	ModInt pow(long long n){
		ModInt r=1,x2=x;
    	while(n){
    		r*=((n%2)?x2:1);
    		x2*=x2;
    		n>>=1;
    	}
    	return r;
	}
};
typedef ModInt<1000000007> mint;

long long gcd(long long a,long long b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll modpow(__int128_t a, ll n,ll mo) {
	__int128_t r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

/*
既約にすると、仲の悪いものが一意に定まる。
*/

ll n,a[200010],b[200010],zero=0;
map<pair<ll,ll>,ll> m;
mint ans=1;

int main(void){
	cin>>n;
	rep(i,n)cin>>a[i]>>b[i];
	rep(i,n){
		if(a[i]==0 && b[i]==0){
			zero++;
		}else{  // 一意な表現に変換
			ll g = gcd(a[i],b[i]);
			a[i]/=g;
			b[i]/=g;
			if(a[i]<0){
				a[i]=-a[i];
				b[i]=-b[i];
			}
			m[{a[i],b[i]}]++;
		}
	}
	for(auto itr=m.begin(); itr!=m.end(); itr++){
		ll c = itr->first.first, d = itr->first.second, cnt=itr->second;
		// 対となるものを求める
		ll e = d,f = -c;
		if(e<0){
			e=-e;
			f=-f;
		}
		if(cnt!=-1){
			ans *= modpow(2,m[{e,f}],1e9+7) + modpow(2,cnt,1e9+7) - 1;  // 「選ばない」が重複してる
		}
		m[{e,f}]=-1;
	}
	ans += zero - 1;
	cout<<ans.get()<<endl;
	return 0;
}

Measured memory_bytes: 31520
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#define ll long long
ll gcd(ll a,ll b){
    ll s=1,c;
    while(a&&b){
        if((~a&1)&&(~b&1))
            a>>=1,b>>=1,s<<=1;
        else if(~a&1)a>>=1;
        else if(~b&1)b>>=1;
        else if(a>b)a=a-b;
        else c=b-a,b=a,a=c;
    }
    if(!a)return b*s;
    if(!b)return a*s;
}
using namespace std;
int main(){
	ll ans=0;
	int s[100001]={0};
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		s[a[i]]++;
	}
	int m;
	cin>>m;
	int b[m],c[m];
	for(int i=0;i<m;i++){
		cin>>b[i]>>c[i];
	}
	for(int i=1;i<=100000;i++){
		ans+=s[i]*i;
	}
	for(int i=0;i<m;i++){
		ans+=s[b[i]]*(c[i]-b[i]);
		s[c[i]]+=s[b[i]];
		s[b[i]]=0;
		cout<<ans<<endl;
	}
	return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    pair<int, int> p[n];
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        p[i] = make_pair(a, b);
    }
    sort(p, p + n);
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        int cnt = min(p[i].second, m);
        ans += p[i].first * (long long)cnt;
        m -= cnt;
        if (!m) break;
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

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

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

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

    ll k;
    cin >> k;
    if(k == 1) {
        cout << 1 << endl;
        return 0;
    }
    k = 9 * k;
    k /= __gcd(7ll, k);
    bool ok = false;
    int i = 10 % k;
    int cnt = 1;
    rep(j,0,k + 1) {
        if(i % k == 1) {
            ok = true;
            break;
        }
        i *= 10;
        i %= k;
        cnt++;
    }
    if(ok) cout << cnt << endl;
    else cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
unsigned long long a[233],t;
int n;
unsigned long long gcd(unsigned long long a,unsigned long long b)
{
	if(a%b==0) return b;
	else return gcd(b,a%b);
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=2;i<=n;i++)
      a[i]=a[i]/gcd(a[i],a[i-1])*a[i-1];
    cout<<a[n]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    string s;
    cin>>s;
    ll n = s.size();
    vector<ll>  a(n,0);
    ll r = 0;
    for(int i=0;i<n-1;i++){
	if(s[i] == 'R' && s[i+1]=='L'){
	    r++;
	    a[i] += (r+1)/2;
	    a[i+1] += r/2;
	    r=0;
	}else if(s[i] == 'R'){
	    r++;
	}
    }
    ll l = 0;
    for(int i=n-1;i>=1;i--){
	if(s[i] =='L' && s[i-1] == 'R'){
	    l++;
	    a[i] += (l+1)/2;
	    a[i-1] += l/2;
	    l = 0;
	}else if(s[i] =='L'){
	    l++;
	}
    }
    cout<<a[0];
    for(int i=1;i<n;i++)cout<<' '<<a[i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

ll mpow(ll x, ll n, ll mod) { ll y = 1; for (; n; n /= 2) { y = n % 2 ? y * x % mod : y; x = x * x % mod; } return y; }

int main() {
    int N, P;
    string S;
    cin >> N >> P >> S;

    ll ans = 0;
    if (P == 2 || P == 5) {
        rep(i, N) {
            ans += ((S[i] - '0') % P == 0) * (i + 1);
        }
    }
    else {
        map<int, int> mp;
        for (int i = N - 1, r = 0; i >= 0; --i) {
            r = (r + (S[i] - '0') * mpow(10, N - 1 - i, P)) % P;
            mp[r]++;
        }
        for (int i = N - 1, r = 0; i >= 0; --i) {
            ans += mp[r];
            r = (r + (S[i] - '0') * mpow(10, N - 1 - i, P)) % P;
            mp[r]--;
        }
    }
    write(ans);
}

Measured memory_bytes: 916