akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
using namespace std;
typedef long long ll;

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

  int N,M;
  cin >> N >> M;

  map<int, int> m;
  int mod = 0;
  ll ans = 0;
  m[0]++;
  rep(i, N) {
    int a; cin >> a;
    mod = (mod + a) % M;
    ans += m[mod];
    m[mod]++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3200
#include <iostream>

int main(){

        int maxNUM;
        int countA=0, countB=0;

        std::cin >> maxNUM;

        for(int i=1;i<=maxNUM; i++){
                countA = 0;
                if(i%2 == 0) continue;

                for(int j=1;j<=i;j++)
                        if ( i%j == 0 ) countA++;

                if( countA == 8 ) countB++;
        }
        std::cout << countB << std::endl;

        return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
a = 0
b = 0
for i in range(0,n):
    a = a + p[i]
for j in range(0,n):
    b = b + p[j]**2
c = (a**2 - b) // 2
print(c % ((10**9) + 7))

Measured memory_bytes: 31436
#!/usr/bin/env python3

def simCost(n,a,c,direction,cost=0):
    if c == 0 or c == n:
        return cost
    elif c in a:
        return simCost(n,a,c+direction,direction,cost+1)
    else:
        return simCost(n,a,c+direction,direction,cost)

    

def solve(n,x,a):
    return min(simCost(n,a,x,+1),simCost(n,a,x,-1))

def main():
    N,M,X = map(int,input().split())
    A = list(map(int,input().split()))
    print(solve(N,X,A))




if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
import heapq

n = int(input())
v = list(map(float,input().split()))

heapq.heapify(v) 

for i in range(n-1):
    a = heapq.heappop(v)
    b = heapq.heappop(v)
    c = (a+b)/2
    heapq.heappush(v,c)
   
x = heapq.heappop(v)   
print(x)
    
    

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N, Q;

int R[200011];
int C[200011];

void MAIN() {
    scanf("%d%d", &N, &Q);

    LL black = (LL) (N-2) * (N-2);

    int down = N;
    int right = N;

    REP ($, Q) {
	int t, x;
	scanf("%d%d", &t, &x);
	if (t == 1) {
	    if (x < right) {
		black -= down - 2;
		for (int i=x+1; i<right; i++) C[i] = down;
		right = x;
	    } else {
		black -= C[x] - 2;
	    }
	} else {
	    if (x < down) {
		black -= right - 2;
		for (int i=x+1; i<down; i++) R[i] = right;
		down = x;
	    } else {
		black -= R[x] - 2;
	    }
	}

    }

    printf("%lld\n", black);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



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

using namespace std;

int main(){

   int n;
   long long int a[100001] = {0};
   vector<long long int> ans;
   long long int sum = 0;

   cin >> n;
   for(int i = 0; i < n; i++){
      int num;
      cin >> num;
      a[num]++;
      sum += num;
   }

   int q;
   long long int b, c;

   cin >> q;

   for(int i = 0; i < q; i++){
      cin >> b >> c;

      sum =  sum - b * a[b] + c * a[b];
      a[c] += a[b];
      a[b] = 0;

      ans.push_back(sum);
   }

   for(int i = 0; i < ans.size(); i++){
      cout << ans[i] << endl;
   }

   return 0;
}

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

int main(){
  long long a,b,x;
  cin >> a >> b >> x;
  
  long long count = 0;
  b = b / x;
  if(a % x == 0){
    a = a / x - 1;
  }
  else{
    a = a / x;
  }
  count = b - a;
  
  cout << count << endl;
}


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

int main(void){
    int WA[100000],isAC[100000],N,M,p,i,ACs=0,pe=0;
    char s[2];
    scanf("%d %d",&N,&M);
    
    for(i=0;i<100000;i++){
        WA[i] = 0;
        isAC[i] = 0;
    }
    
    for(i=0;i<M;++i){
        scanf("%d %s",&p,s);
        if(strcmp(s,"WA")==0 && isAC[p-1] == 0)   WA[p-1] += 1;
        else if(strcmp(s,"AC")==0)      isAC[p-1] = 1;
    }
    for(i=0;i<N;i++){
        ACs += isAC[i];
        if(isAC[i] == 1) pe += WA[i];
    }
    printf("%d %d\n",ACs,pe);
    return 0;

}

Measured memory_bytes: 896
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a1: usize,
        a2: usize,
        a3: usize,
    }
    println!("{}", if a1 + a2 + a3 >= 22 { "bust" } else { "win" });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n = s.length();
    ll ans = 0;
    REP(bit, (1<<n-1)) {
        ll sum = 0;
        string str = "";
        str += s[0];
        REP(i,n-1) {
            if(bit & (1<<i)) {
                sum += stoll(str);
                str = "";
                str += s[i+1];
            } 
            else str += s[i+1];
        }
        sum += stoll(str);
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}

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


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        int min = 0;
        int max = 0;
        int sum = 0;
        int ans = 0;

        for(int i = 0 ; i < N ; i++){
            a[i] = sc.nextInt();
            min = a[0];
            max = a[0];

            if(min > a[i]){
                min = a[i];
            }

            if(max < a[i]){
                max = a[i];
            }
        }

        for(int j = -100 ; j <= 100 ; j ++){
            sum = 0;
            
            for (int i = 0 ; i < N ; i++){
                sum = sum + (a[i] - j) * (a[i] - j) ;
            }

            if(j == -100){
                ans = sum;
            }

            if(ans > sum){
                ans = sum;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define int LL
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

const int MXN = 2e6+5;
int mod = 1e9+7;
LL sil[MXN];
LL inv[MXN];

LL pot(LL a, LL n)
  {
  if(n == 0)return 1;
  if(n % 2 == 0)return pot(a * a % mod, n/2);
  return pot(a, n-1) * a % mod;
  }

LL C(int n, int k)
  {
  return sil[n] * inv[n-k] % mod * inv[k] % mod;
  }

int32_t main()
  {
  ios_base::sync_with_stdio(0); 

  sil[0] = 1;
  FOR(i, 1, MXN-1)
    sil[i] = sil[i-1] * i % mod;

  inv[MXN-1] = pot(sil[MXN-1], mod-2);
  FORD(i, MXN-2, 0)
    inv[i] = inv[i+1] * (i+1) % mod;

  int k;
  cin >> k;
  string s;
  cin >> s;
  
  LL res = 0;
  FOR(i, s.size(), s.size()+k)
    {
    res += C(k + s.size(), i) * pot(25, k + s.size() - i) % mod;
    }
  res %= mod;
  cout << res << endl;
  }

Measured memory_bytes: 35576
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template< typename T > using matrix = vector< vector< T > >;

//FUNCTION  

void solve(void)
{
  string str;
  cin>>str;
  int pstk = 0;
  int WIN = 0, LOSE = 0;
  int C = 0;
  for (int i = 0; i < str.size(); i++)
  {
    if(str[i] == 'p')C++;
  }
  int N = str.size();
  int P = N/2;
  cout<<P - C<<endl;
  


  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
long long a[330000];
long long cnt[66];
int main()
{
    long long n ;
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }
    rep(i,61){
        cnt[i] = 0;
    }
    rep(i,n){
        rep(j,60){
            cnt[j] += (a[i] >> j)%2;
        }
    
    }
    long long ans = 0;
    long long MOD = 1e9+7;
    rep(b,60){
        long long remaining = n - cnt[b];
        long long val = (1LL << b) % MOD;
        val %= MOD;
        val *= cnt[b];
        val %= MOD;
        val *= remaining;
        val %= MOD;
        ans += val; 
        ans %= MOD;
        
    }
    cout << ans << endl;


    return 0;
}

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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    map<ll,ll> mp;
    for(i=2;i*i<=n;i++){
        while(n%i==0){
            mp[i]++;
            n/=i;
        }
    }
    if(n>1)mp[n]++;
    ll cnt = 0;
    for(auto &x:mp){
        ll tmp = x.second;
        ll ok =1,ng = 1000000000;
        while(ng-ok>1){
            ll mid = (ok+ng)/2;
            if((1+mid)*mid/2<=tmp){
                ok = mid;
            }else ng = mid;
        }
        cnt += ok;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3632
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

//typedef
//------------------------------------------
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstring;
typedef pair<int, int> pint;
typedef pair<pint, int> ppint;
typedef pair<int, pint> pintp;
typedef unsigned int uint;
typedef long long llint;
typedef unsigned long long int ullint;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const int INF = 100000000;

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

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;



int main() {
	static int t;
	cin >> t;
	for(int i = 0; i < t; i++) {
		static int n;
		cin >> n;
		int prev = 0;
		int up = 0;
		int down = 0;
		cin >> prev;
		for(int j = 1; j < n; j++) {
			int next;
			cin >> next;
			if(next > prev) {
				up = max(up, next - prev);
			} else if(next < prev) {
				down = max(down, prev - next);
			}
			prev = next;
		}
		printf("%d %d\n", up, down);
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }




int main() {
    int n; cin >> n;
    map<int, int> mp;
    rep(i, n) {
        int tmp; cin >> tmp;
        mp[tmp]++;
        mp[tmp-1]++;
        mp[tmp+1]++;
    }
    int ans = 0;
    for(auto iter = begin(mp); iter != end(mp); ++iter) {
        chmax(ans, iter->second);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    ll n;
    cin >> n;

    if (n % 2)
    {
        cout << 0 << endl;
        return 0;
    }

    ll res = 0;

    ll i = 10;

    while (i <= n)
    {
        res += n / i;

        i *= 5;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 764
//package abc074_d;

import java.util.Scanner;

public class Main {

    private static int N;
    private static int[][] SRC;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        SRC = new int[N][N];
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                SRC[i][j] = sc.nextInt();
            }
        }
        long ans = 0;
        for(int i = 0; i < N-1; i++) {
            for(int j = i+1; j < N; j++) {
                boolean necessary = true;
                for(int k = 0; k < N; k++) {
                    if(k == i || k == j) continue;
                    if(SRC[i][j] > SRC[i][k] + SRC[k][j]) {
                        System.out.println(-1);
                        return;
                    }
                    if(SRC[i][j] == SRC[i][k] + SRC[k][j]) {
                        necessary = false;
                    }
                }
                if(necessary) ans += SRC[i][j];
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 52040
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#define SNPI 2019810931

using namespace std;

struct Node{
  int key;
  Node *right,*left,*parent;
};

Node *T=(Node*)malloc(sizeof(Node));

void insert(Node *T, int u){
  Node *y=nullptr;
  Node *x=T;
  while(x!=nullptr){
    y=x;
    if(u < x->key) x=x->left;
    else x=x->right;
  }
  Node *z=(Node*)malloc(sizeof(Node));
  z->parent=y;
  z->key=u;
  z->right=nullptr;
  z->left=nullptr;
  if(y==nullptr) T=z;
  else if (z->key < y->key) y->left=z;
  else y->right=z;
}

void inorder(Node *T){
  if(T==nullptr) return;
  inorder(T->left);
  if(T->key<SNPI)
    cout << " " << T->key;
  inorder(T->right);
}

void preorder(Node *T){
  if(T==nullptr) return;
  if(T->key<SNPI)
    cout << " " << T->key;
  preorder(T->left);
  preorder(T->right);
}

bool find(Node *x, int k){
  while (x!=nullptr && k!=x->key){
    if(k < x->key) x=x->left;
    else x=x->right;
  }
  if(x==nullptr) return false;
  else return true;
}

int main(){
  int n,num;
  string command;
  T->key=SNPI;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> command;
    if(command=="insert") {
      cin >> num;
      insert(T,num);
    }
    else if(command=="print"){
      inorder(T);
      cout << endl;
      preorder(T);
      cout << endl;
    }
    else if(command=="find"){
      cin >> num;
      if(find(T,num)) cout << "yes"<< endl;
      else cout << "no" << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 21904
#include <stdio.h>

int main(void)
{
	int n;
	int x1, y1, z1, w1, x2, y2, z2, w2;
	int i;
	
	while (1){
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		for (i = 0; i < n; i++){
		scanf("%d%d%d%d%d%d%d%d", &x1, &y1, &z1, &w1, &x2, &y2, &z2, &w2);
		
		printf("%d ",x1 * x2 - y1 * y2 - z1 * z2 - w1 * w2);
		
		printf("%d ",x1 * y2 + y1 * x2 - w1 * z2 + z1 * w2);
		
		printf("%d ",z1 * x2 + w1 * y2 - w2 * y1 + x1 * z2);
		
		printf("%d\n",w1 * x2 - z1 * y2 + y1 * z2 + w2 * x1);
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;
 
template<typename T1, typename T2>
ostream& operator << (ostream& os, const pair<T1, T2>& p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
 
template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    os << "{";
    for(int i = 0; i < v.size(); i++)
        os << v[i] << (i+1<v.size()?", ":"");
    os << "}";
    return os;
}
 
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }
 
void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}
//}}}
 
int main(){
    iostream_init();
    int N, W, H;
    cin >> N >> W >> H;
    vector<pair<int, int>> xs(N);
    vector<pair<int, int>> ys(N);
    REP(i, N){
        int x, y, w;
        cin >> x >> y >> w;
        xs[i] = make_pair(2*x, 2*w);
        ys[i] = make_pair(2*y, 2*w);
    }
 
    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());
 
    bool ans = false;
    W *= 2;
    H *= 2;
    {
        int cur = 0;
        bool ok = true;
        REP(i, W+1) {
            while(cur < N && abs(xs[cur].first - i) > xs[cur].second) {
                cur++;
            }
            if(cur == N){
                ok = false;
                break;
            }
        }
        ans = ans || ok;
    }
    {
        int cur = 0;
        bool ok = true;
        REP(i, H+1) {
            while(cur < N && abs(ys[cur].first - i) > ys[cur].second) {
                cur++;
            }
            if(cur == N){
                ok = false;
                break;
            }
        }
        ans = ans || ok;
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}
 
/* vim:set foldmethod=marker: */

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

class Prime {
public:
    Prime(ll n) {
        mPrimeTbl.clear();
        vector<bool> u(n, false);
        for (ll i = 2; i <= n; ++i) {
            if (u[i])
                continue;
            mPrimeTbl.push_back(i);
            for (ll p = i; p <= n; p += i)
                u[p] = true;
        }
    }

    ~Prime() {}

    ll num() {
        return static_cast<ll>(mPrimeTbl.size());
    }

    ll get(ll index) {
        return mPrimeTbl[index];
    }

private:
    vector<ll> mPrimeTbl;
};


vector<ll> calc(ll n) {
    vector<ll> ret;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) {
                ret.push_back(n / i);
            }
        }
    }
    ret.push_back(n);
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    if (N == 2) {
        cout << 1 << endl;
        return 0;
    }

    vector<ll> ans;
    {
        vector<ll> v = calc(N - 1);
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        REP(i, v.size()) {
            if (v[i] > 1)
                ans.push_back(v[i]);
        }
    }
    {
        vector<ll> v = calc(N);
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        REP(i, v.size()) {
            if (v[i] == 1)
                continue;
            ll n = N;
            while (n % v[i] == 0)
                n /= v[i];
            if (n % v[i] == 1)
                ans.push_back(v[i]);
        }
    }
    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    cout << ans.size() << endl;

    return 0;
}

Measured memory_bytes: 384
def divisors(n):
    res = []
    for d in range(1, int(n**0.5)+1):
        if n%d==0:
            res.append(d)
            res.append(n//d)
    res = sorted(set(res))
    return res

# 素因数分解
def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

N, K = map(int, input().split())
invK = modinv(K)
P = [0] * (K+1)
mod = 10**9+7
for i in range(1, K+1):
    p = pow(K//i * invK, N, mod)
    P[i] = p
KN = pow(K, N, mod)
ans = 0


# https://kazuma8128.hatenablog.com/entry/2018/07/29/231819
for i in range(K, 1, -1):
    #print(i, divisors(i))
    for d in divisors(i):
        if d!=i:
            P[d] -= P[i]
for i, p in enumerate(P[1:], 1):
    n = p * KN % mod
    #print(i, n)
    ans = (ans + n * i) % mod
print(ans)


Measured memory_bytes: 14760
import java.util.Scanner;


public class Main {

    public static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args) {

		int t = scanner.nextInt();
		int result = 0;
		while(t-- > 0) {
			int n = scanner.nextInt();
			while((n & 1) == 0) {
				n = n >> 1;
				result++;
			}
		}
		System.out.println(result);
	}

}


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

typedef long long ll;

int main()
{
    ll n,a,b;
    cin >> n >> a >> b;
    if(a > b){
        swap(a,b);
    }
    if((b-a)%2 == 0){
        cout << (b-a)/2 << endl;
    }else{
        ll tmp1 = a-1+1+(b-a-1)/2;
        ll tmp2 = n-b+1+(b-a-1)/2;
        cout << min(tmp1,tmp2) << endl;
    }
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  /*
   * a-----b
   *    c------d
   *
   */
  int ans = 0;
  if(a <= c && d <= b) {
    ans = d - c;
  }
  else if(c <= a && b <= d) {
    ans = b - a;
  }
  else if(c <= b && a <= d) {
    ans = min(abs(b-c), abs(a-d));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double best = 999999999;
        ArrayList<Integer> locations = new ArrayList<>();
        int people = sc.nextInt();
        for (int i=0;i<people;i++){
            locations.add(sc.nextInt());
        }
        int locationlength = locations.size();
        for (int i=0;i<101;i++) {
            double thisres = 0;
            for (int j=0;j<locationlength;j++) {
                thisres += Math.pow(Math.abs(i-locations.get(j)), 2);
            }
            if (thisres < best) {
                best = thisres;
            }
        }
        System.out.println((int) best);

    }
}


Measured memory_bytes: 22996
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) rep2(i,0,n-1)
int MOD=1000000000+7;
int INF=1e6;
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

string s;

main(){
    cin>>s;
    vector<string> v;
    int t=s.size();
    rep2(i,1,5){
        rep(j,t+1-i){
            v.push_back(s.substr(j,i));
        }
    }
    sort(v.begin(),v.end());
    unique(v.begin(),v.end());
  int k;
  cin>>k;
    cout<<v[k-1];
}


Measured memory_bytes: 1660
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int dp[100005];//石の数が残りi個のときの勝敗を表すdp[i]

int main(){
    int n,k;
    memset(dp,0,sizeof(dp));
    cin>>n>>k;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    for(int i=1;i<=k;++i){
        rep(j,n){
            if(i>=a[j]&&dp[i-a[j]]==0)dp[i]=1;//どれか1つでも負けになる方法があるならそれを押しつけて勝利,なければ敗北
        }
    }
    if(dp[k])cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    return 0;
}


Measured memory_bytes: 640
N = int(input())
src = [tuple(map(int,input().split())) for i in range(N)]

INF = float('inf')
for cx in range(0,101):
    for cy in range(0,101):
        tmph = None
        maxh = INF
        for x,y,h in src:
            if h > 0:
                tmp = h + abs(x-cx) + abs(y-cy)
                if tmph is None:
                    tmph = tmp
                else:
                    if tmp != tmph:
                        break
                if tmph > maxh:
                    break
            else:
                maxh = min(maxh, abs(x-cx) + abs(y-cy))
                if maxh == 1:
                    tmph = 1
        else:
            for x,y,h in src:
                if max(tmph - abs(x-cx) - abs(y-cy), 0) != h:
                    break
            else:
                print(cx,cy,tmph)
                exit()

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
import math

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

udeg = 90
deg = 45
ldeg = 0

v = a * a * b

for _ in range(30):
    # 左に傾ける
    
    deg_ = 90 - deg
    rad_ = math.radians(deg_)
    rad = math.radians(deg)
    l = b * math.sin(rad_)
    r = a * math.sin(rad)
    if l > r:
        b_ = b * math.cos(rad_) * (r / l) 
        _v = v - a * (a * math.cos(rad) + b_) * (a * math.sin(rad)) / 2
    else:
        a_ = b * math.sin(rad_) / math.sin(rad)
        _v = a * a_ * b / 2

    if _v < x:
        udeg = deg
    else:
        ldeg = deg
    deg = (udeg + ldeg) / 2

print(deg)



Measured memory_bytes: 3064
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

m, d = na()
if d < 22:
    print(0)
else:
    d10max = int(str(d)[0])
    d1max = int(str(d)[1])
    c = 0
    for d10 in range(2, d10max):
        for i in range(2, 10):
            if d10 * i <= m:
                c += 1

    for i in range(2, d1max+ 1):
        if d10max * i <= m:
            c += 1
    print(c)




Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

int main () {
    
    vector<int> a(5, 0);
    for(int i = 0; i < 5; i++)
    {
        cin >> a[i];
    }
    int k;
    cin >> k;

    REP(i,5) {
        REP(j,5) 
        if(a[i] - a[j] > k) {
            cout << ":(" << endl;
            return 0;
        }
    }  

    cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256
import math

n = int(input())

cities = []
for i in range(n):
  cities.append(tuple(map(int, input().split())))
  
score = 0
for i in range(n-1):
  city1 = cities[i]
  for j in range(i+1, n):
    city2 = cities[j]
    distance = math.sqrt(
      (city1[0] - city2[0]) ** 2 + \
      (city1[1] - city2[1]) ** 2
    )
    score += distance
    
print(2 * score / n)

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

int main() {
    int N;
    cin >> N;
    //vector<int> A;
    int MX = 100001;
    vector<int> int_list(MX);
    ll sum = 0;
    rep(i, N){
        int a;
        cin >> a; 
      //  A.at(i) = a;
        int_list.at(a) += 1;
        sum += a; 
    }
    int Q;
    cin >> Q;
    rep(i, Q){
        int B, C;
        cin >> B >> C;
        sum += (C-B) * int_list.at(B);
        cout << sum << endl;
        int_list.at(C) += int_list.at(B);
        int_list.at(B) = 0;
    }
}

Measured memory_bytes: 3772
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()

	x := sc.ReadInt()
	y := sc.ReadInt()
	z := sc.ReadInt()

	fmt.Printf("%d %d %d\n", z, x, y)
}

// util
// * math

func AbsInt(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func MinInt(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

// * io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


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

int p[1010];

inline int read(){
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}

inline void write(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}

inline void writeln(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
     puts("");
}

signed main(){
    int n=read(),k=read();
    
    for(int i=1;i<=n;i++)
        p[i]=read();
        
    sort(p+1,p+n+1);
    
    int ans=0;
    
    for(int i=1;i<=k;i++)
        ans+=p[i];
        
    writeln(ans);
    return 0;
}

Measured memory_bytes: 3592
// use std::cmp;
// use std::collections::HashMap;
// use std::collections::HashSet;
// use std::collections::VecDeque;


// const INF: i64 = 1_000_000_000;


fn main() {
    let cin = stdin();
    let mut sc = Scanner::new(cin.lock());
    let n: i64 = sc.read();
    let ans = (n - 1) / 2;
    println!("{}", ans);
}

// thanks, ir5
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}

using namespace std;



void solve(){
    int h,w;
    cin>>h>>w;
    int cnt=0;
    rep(i,h)rep(j,w){
        char c;
        cin>>c;
        if(c=='#')++cnt;
    }
    if(cnt==h+w-1)cout<<"Possible\n";//最短経路分のマスしか存在しない
    else cout<<"Impossible\n";
}
 
signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 256
import sys

n = int(input())

for i in range(1, 3500):
    for j in range(1, 3500):
        rest = 4 * i * j - (i + j) * n
        if rest > 0:
            ans = n * i * j / rest
            if ans.is_integer():
                print(i, j, int(ans))
                sys.exit()

Measured memory_bytes: 67440
#include <stdio.h>

char sa[101] = {'\0'};
char sb[101] = {'\0'};
char sc[101] = {'\0'};
int a = 0,b = 0,c = 0;

int check(char *ptr,int i){
	int checker;
	checker = *(ptr+i) - '\0';	
	return checker;
}

int check2(char *ptr, int i){
	if(*(ptr+i) == 'a'){
		return 1;
	} else if(*(ptr+i) == 'b'){
		return 2;
	} else {
		return 3;
	}
}

int search(int n){
	int tmp, result, s;
	char *ptr;
	while(1){
		result = n;
		if(n == 1){
			ptr = sa;
			tmp = check(ptr,a);
			s = a;
			a++;
		} else if(n == 2){
			ptr = sb;
			tmp = check(ptr,b);
			s = b;
			b++;
		} else { 
			ptr = sc;
			tmp = check(ptr,c);
			s = c;
			c++;
		}
		if(!tmp){
			break;
		}
		n = check2(ptr,s);
	}
	return result;
}
	
int main(void){
	int ans;
	scanf("%s",sa);
	scanf("%s",sb);
	scanf("%s",sc);
	ans = search(1);
	if(ans == 1){
		printf("A\n");
	} else if(ans == 2){
		printf("B\n");
	} else {
		printf("C\n");
	}
	return 0;
}

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

int main() {
  int n, m;
  float base;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  base = accumulate(a.rbegin(),a.rend(),0) / (4.0 * m);
  int count = 0;
  rep(i, n) {
    if(a[i] >= base) { count++; }
  }
  if(count >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

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

int main()
{
	string s;
	 cin>>s;
	 int cnt=0;
	 for(int i=0;i<6;i++)
	 {
	 	if(s[i]=='1') cnt++;
	 }
	cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N;
    void solve()
    {
        var S = cin.next;
        for (int i = 0; i < S.Length; i++)
        {
            Write(S[i]);
            if (i == 3) Write(" ");
        }
        WriteLine();
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

#define int long long

int k, dp[105][2][105];
string digit;

int digitdp(int id, bool can, int sum)
{
	if(id == digit.size())
	{
		if(sum == k)
			return 1;

		return 0;
	}

	if(dp[id][can][sum] != -1)
		return dp[id][can][sum];

	int d = digit[id] - '0';

	int ans=0;
	for(int i=0; i<10; i++)
		if(i<=d or can)
			ans += digitdp(id+1, i<d or can, sum+(i!=0));

	return dp[id][can][sum] = ans;
}

int32_t main()
{
	cin >> digit >> k;

	memset(dp, -1, sizeof(dp));

	digitdp(0,0,0);

	cout << dp[0][0][0] << '\n';
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
    char S[200];
    scanf("%s",S);
    if(strcmp(S,"Sunny")==0)
        printf("Cloudy\n");
    else if(strcmp(S,"Cloudy")==0)
        printf("Rainy\n");
    else if(strcmp(S,"Rainy")==0)
        printf("Sunny\n");
    //std::cin.get();
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
    uint64_t N, X;
    uint64_t base, l, tmp;
    uint64_t ans;

    scanf("%lu %lu", &N, &X);
    
    ans = N;

    base = N - X;
    l = X;

    // printf("default ans = %u\n", ans);
    while (l) {
        // printf("add: (base / l) * 2 * l = %u\n", (base / l) * 2 * l);
        ans += ((base - 1) / l) * (2 * l);
        tmp = base;
        base = l;
        if ((tmp % l) == 0) {
            ans += l;
        }
        l = tmp % l;
    }

    printf("%lu\n", ans);
}



Measured memory_bytes: 256
oni_pos, oni_V = map(int, input().split())
nige_pos, nige_W = map(int, input().split())
T_s = int(input())

diff = abs(oni_pos - nige_pos)
d_V = oni_V - nige_W


if (oni_V == nige_W):
    print('NO')
    exit()

time = diff / d_V

if (d_V < 0):
    print('NO')
    exit()
    
if (time <= T_s):
    print('YES')
else:
    print('NO')



Measured memory_bytes: 9128
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,m;
  cin>>n>>m;
  int a[n],b[n],c[m],d[m];
  for(int i=0;i<n;i++) cin>>a[i]>>b[i];
  for(int i=0;i<m;i++) cin>>c[i]>>d[i];
  for(int i=0;i<n;i++){
    int ans=0;
    for(int j=0;j<m;j++){
      if(abs(a[i]-c[j])+abs(b[i]-d[j])<abs(a[i]-c[ans])+abs(b[i]-d[ans]))
	ans=j;
    }
    cout<<ans+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int count=0;
	bool f=false;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		if(x==y) count++;
		else count=0;
		if(count==3){
			f=true;
		}
	}
	if(f) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3668
x, y = map(int, input().split())
group2 = [4,6,9,11]
group3 = [2]
if x in group2 and y in group2:
    print("Yes")
elif x not in group2 and x not in group3 and y not in group2 and y not in group3:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 200100;
int n, a[N];

struct RMQ {

	int n, m;
	vector <int> v;
	vector <int> rmq[20];
	vector <int> lg;

	RMQ(vector <int> &v) {
		n = v.size();
		lg.resize(n + 1);
		this->v = v;

		lg[1] = 0;
		for(int i = 1; i <= n; i++)
			lg[i] = 1 + lg[i / 2];
		m = lg[n];

		for(int i = 0; i < m; i++) rmq[i].resize(n);

		for(int i = 0; i < v.size(); i++) 
			rmq[0][i] = i;

		for(int i = 1; i < m; i++) 
			for(int j = 0; j + (1 << i) <= v.size(); j++)
				rmq[i][j] = (v[rmq[i - 1][j]] > v[rmq[i - 1][j + (1 << (i - 1))]] ? rmq[i - 1][j + (1 << (i - 1))] : rmq[i - 1][j]);
	}

	int getMinPos(int l, int r) {
		int i = lg[r - l + 1];
		i--;
		int p1 = rmq[i][l];
		int p2 = rmq[i][r - (1 << i) + 1];
		if(v[p1] < v[p2]) return p1;
		return p2;
	}
} ;

RMQ* rmq[2];

void add(priority_queue<pair<int, pair<int,int> > > &pq, int l, int r) {
	if(l > r) return;
	// dbg(l, r, rmq[l % 2]->getMinPos(l, r));
	pq.push({-a[rmq[l % 2]->getMinPos(l, r)], {l, r}});
}

vector <int> par, impar, ans;

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		if(i % 2 == 0) {
			par.push_back(a[i]);
			impar.push_back(1e9);
		} else {
			impar.push_back(a[i]);
			par.push_back(1e9);
		}
	}

	// dbg(impar);
	rmq[0] = new RMQ(par);
	dbg_ok;
	rmq[1] = new RMQ(impar);

	// dbg(rmq[1]->rmq[0]);
	// dbg(rmq[1]->rmq[1]);
	// dbg(rmq[1]->rmq[2]);

	priority_queue <pair<int, pair<int, int> > > pq;
	// pq.push({-a[rmq_par.getMinPos(0, n -  1)], {0, n - 1}});
	add(pq, 0, n - 1);

	while(!pq.empty()) {
		auto x = pq.top();
		pq.pop();
		// dbg(x);
		int split_l = rmq[x.nd.st % 2]->getMinPos(x.nd.st, x.nd.nd);
		int split_r = rmq[1 - (x.nd.st % 2)]->getMinPos(split_l + 1, x.nd.nd);
		add(pq, x.nd.st, split_l - 1);
		add(pq, split_l + 1, split_r - 1);
		add(pq, split_r + 1, x.nd.nd);
		ans.push_back(a[split_l]);
		ans.push_back(a[split_r]);
	}
	cout << ans << '\n';


}	

	

Measured memory_bytes: 39020
main(a,b,i,x,y){char map[104][104];for(;scanf("%d%d",&a,&b),a+b;){for(b=x=y=0;a-b;)scanf("%s",map[b++]);for(;map[x][y]-46?i=map[a=x][b=y]:0;map[a][b]=0)i>93?i>95?x++:x--:i<63?i<61?y--:y++:1;map[x][y]?printf("%d %d\n",y,x):puts("LOOP");}}

Measured memory_bytes: 628