akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll             long long int
#define lb             lower_bound
#define fi             first
#define ub             upper_bound
#define se              second
#define mp             make_pair
#define vll            vector<ll>
#define mod            1000000007
#define endl            "\n"
#define fast           ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb             push_back
#define sz               size()
#define all(v)         v.begin(),v.end()
#define allr(v)        v.rbegin(),v.rend()
#define inp(V,n)       for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)       {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<double,double> &a,
               const pair<double,double> &b)
{
    if(a.fi==b.fi)
    {
    return (a.second >b.second);
    }
    else
        return (a.fi<b.fi);
}

int main()
{
  int T=1 ;
  //cin>>T;
   while(T--)
    { ll i,j,k,l,m,n,ans=mod;
   string s,t;
   cin>>s>>t;
       n=s.sz;
    m= t.sz;
for(i=0;i<n-m+1;i++)
{
    ll cnt=0;
    for(j=0;j<m;j++)
        cnt+=(s[i+j]!=t[j]);

        ans = min(ans,cnt);
}

   cout<<ans<<endl;


    }

return 0;
}




Measured memory_bytes: 3580
import sys

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

def main():
    s = read()
    pre = ""
    sur = ""
    rev = False
    for _ in range(int(read())):
        q = read()
        if q == "1":
            rev = not rev
            continue
        _, f, c = q.split()
        if rev ^ (f == "1"):
            pre += c
        else:
            sur += c
    print((pre[::-1] + s + sur)[::1 - 2 * rev])

if __name__ == '__main__':
    main()

Measured memory_bytes: 4468
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String[] C = new String[N];
        for(int i = 0; i < N; i++){
            C[i] = sc.next();
        }
        String[] B = C.clone();
        String[] S = C.clone();
        BubbleSort(B, N);
        for(int i = 0; i < N; i++){
            System.out.print(B[i]);
            if(i != N - 1){
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println("Stable");
        SelectionSort(S, N);
        for(int i = 0; i < N; i++){
            System.out.print(S[i]);
            if(i != N - 1){
                System.out.print(" ");
            }
        }
        System.out.println();
        if(isSame(B, S)){
            System.out.println("Stable");
        }else{
            System.out.println("Not stable");
        }
    }

    public static void BubbleSort(String[] C, int N){
        for(int i = 0; i < N; i++){
            for(int j = N - 1; j > i; j--){
                int val1 = Character.getNumericValue(C[j].charAt(1));
                int val2 = Character.getNumericValue(C[j - 1].charAt(1));
                if(val1 < val2){
                    String temp = C[j];
                    C[j] = C[j - 1];
                    C[j - 1] = temp;
                }
            }
        }
    }

    public static void SelectionSort(String[] C, int N){
        for(int i = 0; i < N; i++){
            int minj = i;
            for(int j = i; j < N; j++){
                if(Character.getNumericValue(C[j].charAt(1)) < Character.getNumericValue(C[minj].charAt(1))){
                    minj = j;
                }
            }
            String temp = C[i];
            C[i] = C[minj];
            C[minj] = temp;
        }
    }

    public static boolean isSame(String[] a, String[] b){
        for(int i = 0; i < a.length; i++){
            if(!a[i].equals(b[i])){
                return false;
            }
        }
        return true;
    }
}


Measured memory_bytes: 26252
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;
int main(void)
{
  int n,k,c;
  scanf("%d%d%d",&n,&k,&c);
  char str[n+1];
  int l[k],r[k],j=0;
  scanf("%s",str);
  for(int i=0;i<k;i++){
    while(str[j]=='x') j++;
    l[i]=j;
    j+=c+1;
  }
  j=n-1;
  for(int i=k-1;i>=0;i--){
    while(str[j]=='x') j--;
    r[i]=j;
    j-=c+1;
  }
  for(int i=0;i<k;i++)
    if(l[i]==r[i]) printf("%d\n",l[i]+1);

}

Measured memory_bytes: 3200
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    input! {
        n:usize,
        a:[usize;n],
    }

    let &max_num = a.iter().max().unwrap();
    let is_set_wise = a.iter().fold(0, |acc, ai| acc.gcd(ai)) == 1;

    let era = Eratosthenes::new(max_num);
    let mut divisor_counter = vec![0; max_num + 1];
    
    for ai in a {
        let hm = era.factorization(ai);

        for (k, _v) in hm {
            divisor_counter[k] += 1;
            if divisor_counter[k] >= 2 {
                break;
            }
        }
    }

    let is_pair_wise = *divisor_counter.iter().max().unwrap() <= 1;

    let ans = if is_pair_wise {
        "pairwise coprime"
    } else if is_set_wise {
        "setwise coprime"
    } else {
        "not coprime"
    };

    println!("{}", ans);
}

use itertools::Itertools;
use num::Integer;
use rustc_hash::FxHashMap;
use smallvec::alloc::collections::BTreeMap;
use std::collections::HashMap;
use std::mem::swap;

/// 二分累乗法
pub fn pow(x: isize, n: usize) -> isize {
    if n == 0 {
        1
    } else if n == 1 {
        x
    } else if n % 2 == 1 {
        x * pow(x, n - 1)
    } else {
        pow(x * x, n / 2)
    }
}

/// エラトステネスの篩
/// 構築 O(N log log N)
/// 素因数分解 O(log N)
/// 素数判定 O(log N)
pub struct Eratosthenes {
    smallest_prime_factors: Vec<usize>,
}

impl Eratosthenes {
    pub fn new(n: usize) -> Self {
        let mut smallest_prime_factors = (0..=n).collect_vec();

        for i in 2..n {
            if i * i > n {
                break;
            }

            if smallest_prime_factors[i] != i {
                continue;
            }

            let mut j = i * i;
            while j <= n {
                if smallest_prime_factors[j] == j {
                    smallest_prime_factors[j] = i;
                }

                j += i;
            }
        }

        Self {
            smallest_prime_factors,
        }
    }

    pub fn factorization(&self, mut i: usize) -> FxHashMap<usize, usize> {
        assert_ne!(i, 0);

        let mut factors = FxHashMap::default();
        
        while i != 1 {
            let divisor = self.smallest_prime_factors[i];
            *factors.entry(divisor).or_insert(0) += 1;

            i /= divisor;
        }

        factors
    }

    pub fn is_prime(&self, i: usize) -> bool {
        i >= 2 && self.smallest_prime_factors[i] == i
    }
}


Measured memory_bytes: 28344
N = int(input())
A = list(map(int,input().split()))
A.sort()
judge = 0
side = []
while judge != 2 and len(A) > 1:
	MAX_A = A[len(A) -1]
	if MAX_A == A[len(A) - 2]:
		side.append(MAX_A)
		judge += 1
		del A[len(A) - 2]
		del A[len(A) - 1]
	else:
		del A[len(A) -1]

if judge == 2:
	print(side[0] * side[1])
else:
	print(0)

		
	
 

Measured memory_bytes: 14224
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char c[200002][11];
void merge(int i,int j,char s[][11]){
  if(i!=j){
    merge(i,(i+j)/2,s);
    merge((i+j)/2+1,j,s);
    int a=i,b=(i+j)/2+1;
    int d;
    for(d=i;d<=j;d++){
      if((i+j)/2<a){
        strcpy(c[d],s[b]);
        b++;
      }
      else if(j<b){
        strcpy(c[d],s[a]);
        a++;
      }
      else if(strcmp(s[a],s[b])<0){
        strcpy(c[d],s[a]);
        a++;
      }
      else{
        strcpy(c[d],s[b]);
        b++;
      }
    }
    for(d=i;d<=j;d++)
      strcpy(s[d],c[d]);
  }
}

int main(){
  int n,i,j=0,max=0;
  scanf("%d",&n);
  int count[n];
  char s[n][11];
  char t[n][11];
  for(i=0;i<n;i++){
    scanf("%s",s[i]);
    count[i]=0;
  }
  merge(0,n-1,s);
  for(i=0;i<n;i++){
    if(strcmp(s[i],s[i+1])==0)
      count[j]++;
    else{
      count[j]++;
      if(max<count[j])
        max=count[j];
      strcpy(t[j],s[i]);
      j++;
    }
  }
  for(i=0;i<j;i++)
    if(max==count[i])
      printf("%s\n",t[i]);
  return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
#define F freopen("in.txt","r",stdin);
#define FOR(a) for(int i=0;i<a;i++)
using namespace std;




int main()
{
	//F
	int n;
	cin>>n;
	string ss;
	cin>>ss;

	int cnt=0;
	int i=0,j=n-1;

	while(i<j)
	{
		while(ss[i]!='W' and i<n)i++;

		while(ss[j]!='R' and j>=0)j--;

		if(i<j)
		{
			//cout<<i<<"  j="<<j<<endl;
			ss[i]='R';
			ss[j]='W';
			cnt++;

		}
	}

	cout<<cnt;




	return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 1e5 + 5;
string a, b, c;
int n, ans;
int main()
{
	cin >> n >> a >> b >> c;
	for (int i = 0; i < n; i++)
	{
		if (a[i] == b[i] && b[i] == c[i])
			continue;
		if (a[i] != b[i] && b[i] != c[i] && a[i] != c[i])
			ans += 2;
		else
			ans++;
	}
	cout << ans << endl;
	return 0;
}


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

using ll=long long;
constexpr ll mod=1000000007;

ll myPow(ll b, ll e){
    ll res=1;
    while(e){
        if(e&1)res=res*b%mod;
        b=b*b%mod;
        e>>=1;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n;
    cin>>n;
    ll a[n],b[n];
    for(ll i=0;i<n;++i){
        cin>>a[i]>>b[i];
    }
    map<pair<ll,ll>,ll> cnt;
    for(ll i=0;i<n;++i){
        if(a[i]==b[i] && b[i]==0){
            cnt[make_pair(0LL,0LL)]+=1;
        }else if(b[i]==0){
            cnt[make_pair(1LL,0LL)]+=1;
        }else if(a[i]==0){
            cnt[make_pair(0LL,1LL)]+=1;
        }else{
            ll gcd=__gcd(abs(a[i]),abs(b[i]));
            pair<ll,ll> p;
            p.first=a[i]/gcd;
            p.second=b[i]/gcd;
            if(p.second<0){
                p.first*=-1;
                p.second*=-1;
            }
            cnt[p]+=1;
        }
    }
    ll ans=1;
    for(auto it=cnt.begin();it!=cnt.end();++it){
        pair<ll,ll> p=it->first;
        if(p.first==0&&p.second==0)continue;
        pair<ll,ll> q;
        if(p.first<=0){
            q.first=p.second;
            q.second=-p.first;
        }else{
            q.first=-p.second;
            q.second=p.first;
        }
        auto itr=cnt.find(q);
        if(p.first<=0 && itr!=cnt.end())continue;
        ll a=it->second, b=(itr==cnt.end()?0:itr->second);
        ans=ans*(myPow(2,a)+myPow(2,b)+mod-1)%mod;
    }
    ans=(ans+cnt[make_pair(0LL,0LL)]+mod-1)%mod;
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 19124
#include <stdio.h>
#define MAX_N 300000
#define max(a, b) (((a) > (b)) ? (a) : (b)) 
#define f(a) (a-10 < 0) ? 0 : max(a-10, t[i])

int t[MAX_N];
int main() {
    int a;
    scanf("%d", &a);
    for (int i=0;i<a;i++) scanf("%d", t+i);
    int x = t[0];
    for (int i=1;i<a;i++) x = f(x);
    int y = t[a-1];
    for (int i=a-2;i>=0;i--) y = f(y);
    puts(x>0&&y>0 ? "yes" : "no");
}



Measured memory_bytes: 2880
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define UNWORDS(vec, str) for(int i = 0; i < (vec).size(); ++i) cout << (i ? str : "") << (vec)[i]
#define UNLINES(vec) for(int i = 0; i < (vec).size(); ++i) cout << (vec)[i] << endl
#define RS resize
#define CLR clear
#define PB push_back
using namespace std;

int main(){
	int n, field, turn;
	queue< char > card;
	vector< int > cardnum;
	
	while(cin >> n, n){
		cardnum.CLR();
		cardnum.RS(n);
		
		char mark;
		REP(i, 100){
			cin >> mark;
			card.push(mark);
		}
		field = 0;
		turn = 0;
		while(!card.empty()){
			char temp = card.front();
			card.pop();
			
			switch(temp){
			case 'M':
				++cardnum[turn];
				break;
			case 'S':
				field += cardnum[turn] + 1;
				cardnum[turn] = 0;
				break;
			case 'L':
				cardnum[turn] += field + 1;
				field = 0;
				break;
			default:
				break;
			}
			turn = (turn + 1) % n;
		}
		sort(cardnum.begin(), cardnum.end());
		UNWORDS(cardnum, " ");
		cout << " " << field << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1228
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int P = scanner.nextInt();
    char[] S = scanner.next().toCharArray();
    int[] remainders = new int[N];
    int r = 0;
    int k = 1;
    for (int i = 0; i < N; i++) {
      r = ((S[N - i - 1] - '0') * k + r) % P;
      remainders[i] = r;
      k *= 10;
      k %= P;
    }
    long res = 0;
    if (P == 2 || P == 5) {
      for (int i = 0; i < N; i++) if ((S[i] - '0') % P == 0) res += i + 1;
    } else {
      Map<Integer, Integer> freq = new HashMap<>();
      freq.put(0, 1);
      for (int i = 0; i < N; i++) {
        int ri = remainders[i];
        int f = freq.getOrDefault(ri, 0);
        res += f;
        freq.put(ri, f + 1);
      }
    }
    System.out.println(res);
  }
}


Measured memory_bytes: 35444
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
typedef complex<double> Point;
#define X real()
#define Y imag()
const double EPS = 1e-9;
#define EQ(n,m) (abs((n)-(m)) < EPS)

double cross(Point a, Point b) {
	return a.X*b.Y - a.Y*b.X;
}

Point crosspointLL(Point a1, Point a2, Point b1, Point b2) {
  double d1 = cross(b2-b1, b1-a1);
  double d2 = cross(b2-b1, a2-a1);
  if (EQ(d1, 0) && EQ(d2, 0)) return a1;  // same line
  if (EQ(d2, 0)) throw "kouten ga nai";   // ???????????????
  return a1 + d1/d2 * (a2-a1);
}

int main(void){
	int q;
	cin>>q;
	rep(i,q){
		double x0,y0,x1,y1,x2,y2,x3,y3;
		cin>>x0>>y0>>x1>>y1>>x2>>y2>>x3>>y3;
		Point p=crosspointLL({x0,y0},{x1,y1},{x2,y2},{x3,y3});
		printf("%.9f %.9f\n",p.X,p.Y);
	}
	return 0;
}

Measured memory_bytes: 3288
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#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>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#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())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

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

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n,k;
    cin >> n >> k;

    int ans=k;
    REP(i,n-1){
        ans*=k-1;
    }

    cout << ans << ENDL;
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  map<int, int> mp;
  set<int> st;
  REP(i, n) {
    int a; cin >> a;
    ++mp[a];
    st.insert(a);
  }
  int ans = 0;
  for (int e : st) if (mp[e] != e) {
    if (mp[e] > e) ans += mp[e] - e;
    else ans += mp[e];
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    for (int i = 0; i < X; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < Y; i++) {
        cin >> B[i];
    }
    for (int i = 0; i < Z; i++) {
        cin >> C[i];
    }
    sort(all(A), greater<>());
    sort(all(B), greater<>());
    sort(all(C), greater<>());
    priority_queue<ll> Q;
    Q.push(A[0] + B[0] + C[0]);
    vector<tuple<int,int,int>> I;
    set<tuple<int,int,int>> F;
    I.push_back(make_tuple(1, 0, 0));
    I.push_back(make_tuple(0, 1, 0));
    I.push_back(make_tuple(0, 0, 1));
    
    while(Q.size() != K) {
        vector<tuple<int,int,int>> II;
        vector<pair<ll, tuple<int, int, int>>> nxt;
        for(int j = 0; j < I.size(); j++) {
            int x = get<0>(I[j]);
            int y = get<1>(I[j]);
            int z = get<2>(I[j]);
            if (x >= X || y >= Y || z >= Z) continue;
            if (F.find(make_tuple(x, y, z)) != F.end()) continue;
            nxt.push_back({A[x] + B[y] + C[z], make_tuple(x, y, z)});
        }
        sort(all(nxt), greater<>());
        if (nxt.size() > 0) {     
            Q.push(nxt[0].first);
            int x = get<0>(nxt[0].second);
            int y = get<1>(nxt[0].second);
            int z = get<2>(nxt[0].second);
            if (x + 1 < X) II.push_back(make_tuple(x + 1, y, z));
            if (y + 1 < Y) II.push_back(make_tuple(x, y + 1, z));
            if (z + 1 < Z) II.push_back(make_tuple(x, y, z + 1));
            F.insert(make_tuple(x, y, z));
        }
        for (int i = 0; i < II.size(); i++) {
            I.push_back(II[i]);
        }
    }
    while(!Q.empty()) {
        ll p = Q.top(); Q.pop();
        cout << p << endl; 
    }
    
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 1020
/*Program from Luvwgyx*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=1e5+10;
const int maxm=2e5+10;
struct node{int to,nxt;}e[maxm<<1];
int tot,p,c,d,flag,head[maxn],deg[maxn],vis[maxn],col[maxn];
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(ll x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
void write(ll x){print(x);puts("");}
void add(int u,int v){e[++tot].to=v;e[tot].nxt=head[u];head[u]=tot;deg[u]++;}
void insert(int u,int v){add(u,v);add(v,u);}
void dfs(int x){
    vis[x]=1;
    for(int i=head[x],v=e[i].to;i;i=e[i].nxt,v=e[i].to){
        if(!vis[v])col[v]=col[x]^1,dfs(v);
        else if(col[v]^col[x]^1)c-=flag,d+=flag,flag=0;
    }
}
int main(){
    int n=read(),m=read();
    for(int i=1;i<=m;i++)insert(read(),read());
    for(int i=1;i<=n;i++){
        if(!deg[i])p++;
        else if(!vis[i])flag=1,c++,dfs(i);
    }write(1ll*p*n+1ll*p*(n-p)+1ll*d*d+1ll*c*2*(d+c));
    return 0;
}


Measured memory_bytes: 6656
from itertools import permutations
import math
n = int(input())
res = []
for i in range(n):
    s = list(map(int,input().split()))
    res.append(s)
perm= permutations(res)
ans = 0
total = 1
for i in range(1,n+1):
    total = total*i
for i in perm:
    k = 0
    for j in range(1,len(i)):
        k+=math.sqrt(((i[j][0]-i[j-1][0])**2)+((i[j][1]-i[j-1][1])**2))
    ans+=(k/total)
print(ans)


Measured memory_bytes: 3064
n = int(input())
p = list(map(int, input().split()))

cnt = 0

for i in range(n-2):
  pl = [p[j] for j in range(i, i+3)]
  if pl[0] < pl[1] <pl[2] or pl[2] < pl[1] < pl[0]:
    cnt += 1
  
print(cnt)

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vec L(N);
    REP(i,0,N) cin >> L[i];

    ASC(L);
    if(N == 1 && N == 2) PR(0);
    else {
        ll cnt = 0;
        REP(i,0,N-2) {
            REP(j,i+1,N-1) {
                REP(k,j+1,N) {
                    if(L[i]+L[j]>L[k] && L[j]+L[k]>L[i] && L[k]+L[i]>L[j] && L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) ++cnt;
                }
            }
        }
        PR(cnt);
    }

    return 0;
}

/*



*/

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;

int main(){
  string s; cin >> s;
  map<string, string> m;
  m["A"]="T";
  m["C"]="G";
  m["G"]="C";
  m["T"]="A";
  cout << m[s];
  return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main() {
    long long int K;
    cin >> K;

    if (K == 0) {
        cout << "4" << endl;
        cout << "3 3 3 3" << endl;
        return 0;
    }
    if (K == 1) {
        cout << "2" << endl;
        cout << "0 2" << endl;
        return 0;
    }

    if (2 <= K && K <= 50) {
        cout << K << endl;
        for (int i = 0; i < K; i++) {
            cout << K << " ";
        }
        cout << endl;
        return 0;
    }

    long long int p = (K + 50 * (50 - 1)) / 50;
    long long int k = K % 50;
    cout << 50 << endl;
    for (int i = 0; i < 50; i++) {
        if (i < k) {
            cout << p + 1 << " ";
        } else {
            cout << p - k << " ";
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template< typename S, typename T >
inline void chmax(S &a, const T &b) { if(a < b) a = b; }
 
template< typename S, typename T >
inline void chmin(S &a, const T &b) { if(a > b) a = b; }
 

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////

int main() {
	int uu;
	cin>>uu;
for(int u=1;u<=uu;u++){
ll a,b,c,d;
cin>>a>>b>>c>>d;

ll rem=a%b;
if(b>d || a<b){cout<<"No"<<endl;
continue;}
if(c+1>=b){cout<<"Yes"<<endl;
continue;}

d=d%b;
if(d==0)
{if(rem<=c){cout<<"Yes"<<endl;
continue;}
else{cout<<"No"<<endl;
continue;}
}

ll cir=gcd(b,d);
ll mxv=rem+cir*((b-rem)/cir);
if(mxv==b){mxv-=cir;}
if(mxv<=c){
	cout<<"Yes"<<endl;
}
else{
	cout<<"No"<<endl;
}






}
return 0;

}




Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
  int bc[6][6]={0},cc[6][6];
  int H,W,K,i,j,i1,j1,ic,jc,i2,j2,minu,sto=0,ans=0;
  char s[7];
  scanf("%d %d %d\n ",&H,&W,&K);
  for(i=0;i<H;i++){
    scanf("%s",s);
    for(j=0;j<W;j++){
     if(s[j]=='#'){
      bc[i][j]=1;
      sto++; 
     }
    }
  }
  
  for(i=0;i<pow(2,H);i++){
    for(j=0;j<pow(2,W);j++){
      for(i1=0;i1<H;i1++){
        for(j1=0;j1<W;j1++){
         cc[i1][j1]=bc[i1][j1]; 
        }
      }
      ic=i;
      jc=j;
      minu=0;
      if(ic/(int)pow(2,5)){
       ic-=pow(2,5);
       for(j2=0;j2<W;j2++){
        if(cc[5][j2]){
         cc[5][j2]=0;
         minu++;
        }
       }
      }
      if(ic/(int)(pow(2,4))==1){
       ic-=pow(2,4);
       for(j2=0;j2<W;j2++){
        if(cc[4][j2]){
         cc[4][j2]=0;
         minu++;
        }
       }
      }
      if(ic/(int)(pow(2,3))==1){
       ic-=pow(2,3);
       for(j2=0;j2<W;j2++){
        if(cc[3][j2]){
         cc[3][j2]=0;
         minu++;
        }
       }
      }
      if(ic/(int)(pow(2,2))==1){
       ic-=pow(2,2);
       for(j2=0;j2<W;j2++){
        if(cc[2][j2]){
         cc[2][j2]=0;
         minu++;
        }
       }
      }
      if(ic/(int)(pow(2,1))==1){
       ic-=pow(2,1);
       for(j2=0;j2<W;j2++){
        if(cc[1][j2]){
         cc[1][j2]=0;
         minu++;
        }
       }
      }
      if(ic/(int)(pow(2,0))==1){
       for(j2=0;j2<W;j2++){
        if(cc[0][j2]){
         cc[0][j2]=0;
         minu++;
        }
       }
      }
      if(jc/(int)(pow(2,5))==1){
       jc-=pow(2,5);
       for(j2=0;j2<H;j2++){
        if(cc[j2][5]){
         cc[j2][5]=0;
         minu++;
        }
       }
      }
      if(jc/(int)(pow(2,4))==1){
       jc-=pow(2,4);
       for(j2=0;j2<H;j2++){
        if(cc[j2][4]){
         cc[j2][4]=0;
         minu++;
        }
       }
      }
      if(jc/(int)(pow(2,3))==1){
       jc-=pow(2,3);
       for(j2=0;j2<H;j2++){
        if(cc[j2][3]){
         cc[j2][3]=0;
         minu++;
        }
       }
      }
      if(jc/(int)(pow(2,2))==1){
       jc-=pow(2,2);
       for(j2=0;j2<H;j2++){
        if(cc[j2][2]){
         cc[j2][2]=0;
         minu++;
        }
       }
      }
      if(jc/(int)(pow(2,1))==1){
       jc-=pow(2,1);
       for(j2=0;j2<H;j2++){
        if(cc[j2][1]){
         cc[j2][1]=0;
         minu++;
        }
       }
      }
      if(jc/(int)(pow(2,0))==1){
       for(j2=0;j2<H;j2++){
        if(cc[j2][0]){
         cc[j2][0]=0;
         minu++;
        }
       }
      }

      if((sto-minu)==K)
        ans++;
    }
  }
  printf("%d",ans);
  return 0;
}


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;

  if(b % a == 0) cout << (a + b) << endl;
  else cout << (b - a) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ii = pair<int, int>;
using ll = long long;

int32_t main(){
	ios::sync_with_stdio(0);	
	int n;
	cin >> n;
	vector<int> vs(n);
	for(auto &x:vs)
		cin >> x;
	int k = 1e9;
	set<int> st;
	int ans = 0;
	for(auto x:vs){
		if(x<=k) ++ans;
		k = min(x, k);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    cout << (a <= x && x <= a + b ? "YES":"NO") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=100005;
int n,S,tot,head[N],x[N];
ll p[N],ans[N],res;
struct edge{
	int to,next,v;
}e[N];
void add(int x,int y,int v){
	e[++tot]=(edge){y,head[x],v};
	head[x]=tot;
}
void dfs(int x){
	//printf("%d %d\n",x,ans[x]);
	for (int i=head[x];i;i=e[i].next){
		ans[e[i].to]=ans[x]+e[i].v;
		dfs(e[i].to);
	}
}
int main(){
	scanf("%d%d",&n,&S);
	For(i,1,n) scanf("%d%lld",&x[i],&p[i]);
	int l=1,r=n;
	while (l<r){
		if (x[l]>=S) add(l,l+1,x[l+1]-x[l]),++l;
		else if (x[r]<=S) add(r,r-1,x[r]-x[r-1]),--r;
		else if (p[l]>=p[r]) add(l,r,x[r]-x[l]),p[l]+=p[r],--r;
		else add(r,l,x[r]-x[l]),p[r]+=p[l],++l;
	}
	ans[l]=abs(S-x[l]); dfs(l);
	printf("%lld\n",max(ans[1],ans[n]));
}

Measured memory_bytes: 3328
/*
 *    FileName:
 *      Source:
 *        Date:
 *      Author: Mew
 *	  Function:
 */
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iomanip>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<iterator>
#include<ctime>
using namespace std;
int a[105];
int main()
{
	int k,t;
	cin>>k>>t;
	int maxa = 0;
	for(int i=1;i<=t;i++){
		cin>>a[i];
		if(a[i] > maxa)maxa = a[i];
	}
	int e = k - maxa;
	cout<<max(maxa-e-1,0)<<endl;
	return 0;
}



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

int main() {
  int A,B,C,K,D;
  cin >> A >> B >> C >> K;
  D = K - A - B;
 if(A >= K){
   cout << K << endl;
 }
  else if(A + B >= K){
    cout << A << endl;
  } 
  else{
  cout << A - D << endl;
  }
}


Measured memory_bytes: 3604
#![allow(non_snake_case,unused_imports,dead_code)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();

    let N = buf_it.next().unwrap().parse::<usize>().unwrap();
    let M = buf_it.next().unwrap().parse::<usize>().unwrap();
    let A = (0..N).map(|_| buf_it.next().unwrap().parse::<usize>().unwrap()).collect::<Vec<_>>();
    let XY = (0..M).map(|_| 
        (buf_it.next().unwrap().parse::<usize>().unwrap(),
         buf_it.next().unwrap().parse::<usize>().unwrap())
    ).collect::<Vec<_>>();

    let mut U = UnionFind::new(N);
    for &(x,y) in &XY{
        U.merge(x,y);
    }
    let mut C = (0..N).map(|_| Vec::new()).collect::<Vec<_>>();
    for i in 0..N{
        let p = U.get_parent(i);
        C[p].push(A[i]);
    }
    let mut t = 0;
    let mut ans = 0;
    for i in 0..N{
        if C[i].len()==0{continue;}
        t += 1;
        C[i].sort_by_key(|&x| 1_000_000_100-x);
        ans += C[i].pop().unwrap();
    }
    if t==1{ ans = 0;}
    if (t-1)*2 > N{
        println!("Impossible");
        return;
    }
    let mut D = Vec::new();
    for i in 0..N{
        D.append(&mut C[i]);
    }
    D.sort();
    ans += (0..max(2,t)-2).map(|i| D[i]).sum::<usize>();

    println!("{}",ans);

}

struct UnionFind{
    P: Vec<usize>,
}

impl UnionFind {
    fn new(n:usize) -> UnionFind{
        UnionFind {P:(0..n).collect()}
    }
    fn get_parent(&mut self,n:usize) -> usize{
        if self.P[n] == n{ return n;}
        let p = self.P[n];
        self.P[n] = self.get_parent(p);
        self.P[n]
    }
    fn is_unite(&mut self,x:usize,y:usize) -> bool{
        self.get_parent(x)==self.get_parent(y)
    }
    fn merge(&mut self,x:usize,y:usize){
        if self.is_unite(x,y) {return;}
        let i = self.get_parent(x);
        let j = self.get_parent(y);
        self.P[j] = i;
    }
}

Measured memory_bytes: 20600
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(true){ int a = sc.nextInt(); int b = sc.nextInt(); if( a == 0 && b == 0 ) break; if( a > b){a^=b;b^=a;a^=b;} System.out.println(a+" "+b); } } } 


Measured memory_bytes: 36116
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        char[] s = sc.nextLine().toCharArray();
        char[] t = sc.nextLine().toCharArray();
        int incorrect = 0;
        for(int i = 0;i < s.length;i++){
            if(s[i] != t[i]) incorrect++;
        }
        System.out.println(incorrect);
    }
}


Measured memory_bytes: 43144
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
 
#define endl '\n'
#define ll long long
 
using namespace std;
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
 
	int n;
	cin >> n;
 
	long long sum = 0;
	for (int i = 1; i <= n; i++)
	{
		if (i % 3 == 0 || i % 5 == 0) continue;
		sum += i;
	}
	cout << sum << endl;
 
	return 0;
}

Measured memory_bytes: 3636
class Binary_Indexed_Tree_Exception(Exception):
    pass

class Binary_Indexed_Tree():
    def __init__(self,N,L=[]):
        """calcを演算とするN項のBinary Indexed Treeを作成

        N:要素数
        """
        self.calc=lambda x,y:x+y
        self.unit=0

        N=max(N,len(L))

        k=1
        d=1

        while k<N:
            k*=2
            d+=1

        X=[None]+[0]*k

        self.num=k
        self.depth=d

        if L:
            for i in range(len(L)):
                p=i+1
                while p<=k:
                    X[p]+=L[i]
                    p+=p&(-p)
        self.data=X

    def index(self,k,index=1):
        """第k要素の値を出力する.

        k:数列の要素
        index:先頭の要素の番号
        """

        p=k+(1-index)
        return self.sub_array(p,p)

    def add(self,k,x,index=1):
        """第k要素にx加え,更新を行う.

        k:数列の要素
        x:更新後の値
        index:先頭の要素の番号
        """
        p=k+(1-index)
        while p<=self.num:
            self.data[p]+=x
            p+=p&(-p)

    def update(self,k,x,index=1):
        """第k要素をxに変え,更新を行う.

        k:数列の要素
        x:更新後の値
        """

        a=self.index(k,index)
        y=x-a

        self.add(k,y,index)

    def sub_array(self,From,To,index=1):
        """第From要素から第To要素までの総和を求める.

        From:始まり
        To:終わり
        index:先頭の要素の番号
        """
        alpha=max(1,From+(1-index))
        beta=min(self.num,To+(1-index))
        return self.__section(beta)-self.__section(alpha-1)

    def __section(self,To):
        S=0
        x=To
        while x>0:
            S+=self.data[x]
            x-=x&(-x)
        return S
#================================================
N,Q=map(int,input().split())
A=list(map(int,input().split()))
B=Binary_Indexed_Tree(N,A)

X=[]
for _ in range(Q):
    t,u,v=map(int,input().split())
    if t==0:
        B.add(u,v,0)
    else:
        X.append(B.sub_array(u,v-1,0))
print("\n".join(map(str,X)))

Measured memory_bytes: 194912
#include <stdio.h>

// 20min
int main(void){
  int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
  scanf("%d%d%d%d", &x1, &y1, &x2, &y2);

  // これ難しい
  printf("%d %d %d %d\n", x2-(y2-y1), (x2-x1)+y2, x1-(y2-y1), (x2-x1)+y1);

  return 0;


}


Measured memory_bytes: 128
import copy


def group(arr):
    r = {}
    for a in arr:
        if r.get(a[1]):
            r[a[1]] += a[0]
        else:
            r[a[1]] = a[0]

    return r


n = int(input())
A = list(input().split(' '))
_A = copy.deepcopy(A)

for _ in range(n - 1):
    for i in range(1, n)[::-1]:
        if A[i - 1][1] > A[i][1]:
            A[i - 1], A[i] = A[i], A[i - 1]
print(*A)
print('Stable')

A = copy.deepcopy(_A)

for i in range(n - 1):
    minv_idx = i
    for k in range(i + 1, n):
        if A[minv_idx][1] > A[k][1]:
            minv_idx = k
    if i != minv_idx:
        A[i], A[minv_idx] = A[minv_idx], A[i]

print(*A)
if group(A) == group(_A):
    print('Stable')
else:
    print('Not stable')



Measured memory_bytes: 6344
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans, cnt;

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

	ll N,K;
	cin >> N >> K;
	vector<pair<ll,ll>> p(N);
	rep(i, N) {
		cin >> p[i].first >> p[i].second;
	}

	sort(p.begin(), p.end());

	rep(i, N) {
		cnt += p[i].second;
		if (cnt >= K) {
			ans = p[i].first;
			break;
		}
	}

	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<functional>
#include<algorithm>
#include<queue>
#include<tuple>
using namespace std;
#pragma warning(disable:4996)
long long a[240000], b[240000], dist[240000][2], H, W, K;
vector<pair<int, int>>X[120000], Y[120000];
vector<tuple<long long, long long, long long>>x[240000][2];
priority_queue<tuple<long long, long long, long long>, vector<tuple<long long, long long, long long>>, greater<tuple<long long, long long, long long>>>Q;
void dijkstra() {
	for (int i = 0; i < 240000; i++) { dist[i][0] = 999999999999999999LL; dist[i][1] = 999999999999999999LL; }
	dist[0][0] = 0; Q.push(make_tuple(0, 0, 0));
	while (!Q.empty()) {
		long long a1 = get<0>(Q.top()), a2 = get<1>(Q.top()), a3 = get<2>(Q.top()); Q.pop();
		for (int i = 0; i < x[a2][a3].size(); i++) {
			long long to1 = get<0>(x[a2][a3][i]), to2 = get<1>(x[a2][a3][i]), cost = get<2>(x[a2][a3][i]);
			if (dist[to1][to2] > a1 + cost) {
				dist[to1][to2] = a1 + cost; Q.push(make_tuple(dist[to1][to2], to1, to2));
			}
		}
	}
}
int main() {
	cin >> H >> W >> K; X[1].push_back(make_pair(1, 0)); Y[1].push_back(make_pair(1, 0));
	X[H].push_back(make_pair(W, K + 1)); Y[W].push_back(make_pair(H, K + 1));
	for (int i = 1; i <= K; i++) { scanf("%d%d", &a[i], &b[i]); X[a[i]].push_back(make_pair(b[i], i)); Y[b[i]].push_back(make_pair(a[i], i)); }
	for (int i = 1; i <= H; i++) { sort(X[i].begin(), X[i].end()); }
	for (int i = 1; i <= W; i++) { sort(Y[i].begin(), Y[i].end()); }
	for (int i = 1; i <= H; i++) {
		for (int j = 0; j < X[i].size(); j++) {
			int G1 = X[i][j].first, G2 = X[i][j].second;
			if (G2 != 0 && G2 != K + 1) { x[G2][0].push_back(make_tuple(G2, 1, 1)); x[G2][1].push_back(make_tuple(G2, 0, 1)); }
			if (j != X[i].size() - 1) {
				int G3 = X[i][j + 1].first, G4 = X[i][j + 1].second;
				x[G2][0].push_back(make_tuple(G4, 0, abs(G1 - G3))); x[G4][0].push_back(make_tuple(G2, 0, abs(G1 - G3)));
			}
		}
	}
	for (int i = 1; i <= W; i++) {
		for (int j = 0; j < Y[i].size(); j++) {
			int G1 = Y[i][j].first, G2 = Y[i][j].second;
			if (G2 != 0 && G2 != K + 1) { x[G2][0].push_back(make_tuple(G2, 1, 1)); x[G2][1].push_back(make_tuple(G2, 0, 1)); }
			if (j != Y[i].size() - 1) {
				int G3 = Y[i][j + 1].first, G4 = Y[i][j + 1].second;
				x[G2][1].push_back(make_tuple(G4, 1, abs(G1 - G3))); x[G4][1].push_back(make_tuple(G2, 1, abs(G1 - G3)));
			}
		}
	}
	dijkstra();
	long long ans = min(dist[K + 1][0], dist[K + 1][1]);
	if (ans >= 999999999999999LL)ans = -1;
	cout << ans << endl;
	return 0;
}

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

int main(){
    int n ,i = 1;
    scanf("%d",&n);
    do{
        int x = i;
        if(x%3==0){
            printf(" %d",i);
        }else{
            do{
                if(x%10 == 3){
                    printf(" %d",i);
                    break;
                } 
                x/= 10;
            }while(x);
        }
    }while(++i<=n);
    putchar('\n');
    return 0;
}



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

int main(){
	std::string a, b;

	std::cin>>a>>b;

	long long aNum=0; 
	long long bNum=0;

	for(int i=0; i<a.size(); i++){
		aNum*=10;
		aNum+= a[i]- '0';
	}

	bool dot= false;
	int mpy=1;

	for(int i=0; i<b.size(); i++){
		if(b[i]=='.'){
			dot= true;
			continue;
		}

		if(dot)
			mpy*=10;

		bNum*=10;
		bNum+= b[i]- '0';		
	}

	long long ans= aNum* bNum/mpy;

	std::cout<<ans<<std::endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
const ll N = 123456;

string s[N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    rep(i , 1 , n) cin >> s[i];

    map < vector < ll > , ll > a;

    rep(i , 1 , n) {
        vector < ll > ans(26);

        rep(j , 0 , 25) ans[j] = 0;

        for(auto j : s[i]) {
            ans[j - 'a']++;
        }

        a[ans]++;
    }

    ll res = 0;
    for(auto j : a) {
        ll k = j.second;
        res += (k * (k - 1)) / 2;
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 35584
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

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

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

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

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

ll GetDigit(ll num)
{
  return log10(num) + 1;
}

//n ~ mの和
ll sigma(ll n, ll m)
{
  return ((n + m) * (m - n + 1) * 0.5);
}

void Main()
{
  ll l, r; cin >> l >> r;
  ll ans = MAX;
  for(ll i = l;i <= min(r, l + 5000);i++)
  {
    for(ll j = i + 1;j <= min(r, l + 5000);j++)
    {
      ll h = i * j;
      h %= 2019;
      ans = min(h, ans);
    }
  }
  fin(ans);
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


Measured memory_bytes: 256
object Main extends App {
	val N = scala.io.StdIn.readLong

	def f(x: Long): Long = {
		var temp = x
		var result = 0L

		while(temp/10L != 0){
			result = result + temp%10L
			temp = temp / 10L
		}
		result = result + temp

		result
	}

	if(N % f(N) == 0) println("Yes")
	else println("No")
}

Measured memory_bytes: 25540
#include<stdio.h>
int main(){
  int a1,a2,a3,a4;
  int b1,b2,b3,b4;
  int sum1,sum2;
  scanf("%d %d %d %d",&a1,&a2,&a3,&a4);
  scanf("%d %d %d %d",&b1,&b2,&b3,&b4);
  sum1=a1+a2+a3+a4;
  sum2=b1+b2+b3+b4;
  if(sum1 > sum2){
    printf("%d\n",sum1);
  }else if(sum1 < sum2){
    printf("%d\n",sum2);
  }else{
    printf("%d\n",sum1);
  }
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
#define db double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define endl "\n"
#define mp make_pair
#define f first
#define se second
#define PI 3.14159265358979
//ll string_inp() {cin.get(); for(int i =0;i<n;i++){ getline(cin,s[i]);}}

ll power(ll x, ll y, ll mod = 2e18) {ll ans = 1;x %= mod;while(y){if(y&1) ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}

ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m,a = t; t = y; y = x - q * y; x = t; } if(x < 0) x += m0;return x;}

int takemod(int a, int mod = MOD){a%=mod;if(a<0)a+=mod;return a;}

ll binsearch(std::vector<ll>& nums, ll target) {ll n = nums.size();ll l = 0;ll r = n-1;while(l<=r){ll mid = l+ (r-l)/2;if(nums[mid]==target)return mid;else if(nums[mid]>target)r = mid-1;else l = mid+1;}return -1;}


using namespace std;

int main()
{
   fastio
   ll t;

       int a,b,c,d;
       cin>>a>>b>>c>>d;
        double angle = abs((30*c+0.5*d) -(6 *d));

        double final =0.0;
        double r = min(angle,360.0-angle);
        if(r ==90.0)
            final = 0.0;
        else final = cos(r*PI/180.0);


            double result = sqrt((a*a)+(b*b) - (2*a*b*final));
           cout << fixed << setprecision(11)<<result<<endl;






}




Measured memory_bytes: 4168