akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)

using namespace std;


int64_t gcd(int64_t a, int64_t b) {
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	return gcd(b, a % b);
}


bitset<1000001> primes;
// sqrt(n) までの素数を求める。 10^12 まで対応
void create_primes(int64_t n) {
	primes.flip();

	int64_t u_b = sqrt(n + 1);
	assert(u_b < 1000002);

	{
		for (int64_t j = 4; j <= u_b; j += 2) {
			primes.reset(j);
		}
	}
	for (int64_t i = 3; i <= u_b; i += 2) {
		if (!primes.test(i)) continue;

		for (int64_t j = i * 2; j <= u_b; j += i) {
			primes.reset(j);
		}
	}
}

struct FactorInfo {
	int64_t v;
	int64_t c;
};

// n の素因数分解を行う。 
vector<FactorInfo> make_factors(int64_t n)
{
	int64_t v = n;
	int64_t limit = sqrt(n + 1);

	vector<FactorInfo> ans;
	FOR_LE(i, 2, limit) {
		if (!primes.test(i)) continue;

		int64_t count = 0;
		while (v % i == 0) {
			v /= i;
			count++;
		}

		if (count != 0) {
			ans.push_back({ i, count });
		}
	}

	if (v != 1) {
		ans.push_back({ v , 1 });
	}

	return ans;
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	vector<int64_t> as(n); for (auto& a : as) { cin >> a; }

	// pair
	{
		bool is_ok = true;

		create_primes(1000001);
		vector<int64_t> ps(1000001);
		FOR_LT(i, 0, n) {
			vector<FactorInfo> fi = make_factors(as[i]);
			for (auto& f : fi) {
				if (ps[f.v]) {
					is_ok = false;
					break;
				}
				ps[f.v] = 1;
			}
			if (!is_ok) {
				break;
			}
		}

		if (is_ok) {
			cout << "pairwise coprime" << endl;
			return 0;
		}
	}

	// set
	{
		int64_t v = as[0];
		FOR_LT(i, 1, n) {
			v = gcd(v, as[i]);
		}
		if (v == 1) {
			cout << "setwise coprime" << endl;
			return 0;
		}
	}

	std::cout << "not coprime" << endl;



	return 0;
}

Measured memory_bytes: 19036
// B. 

#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	int ans = max(0, ((n - 75) / 30)) + (n >= 189);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;

int n;
int a[1<<20];
vector<pair<int,int> > r;

int main(){
	scanf("%d",&n);
	fore(i,0,n)scanf("%d",a+i);
	int k=0;
	fore(i,1,n)if(abs(a[i])>abs(a[k]))k=i;
	if(!a[k]){puts("0");return 0;}
	fore(i,0,n)if(i!=k)r.pb(mp(k,i)),a[i]+=a[k];
	if(a[k]>0){
		fore(i,0,n-1)if(a[i]>a[i+1])r.pb(mp(i,i+1)),a[i+1]+=a[i];
	}
	else {
		for(int i=n-1;i>0;--i)if(a[i-1]>a[i])r.pb(mp(i,i-1)),a[i-1]+=a[i];
	}
	printf("%d\n",SZ(r));
	for(auto p:r)printf("%d %d\n",p.fst+1,p.snd+1);
	fore(i,0,n)deb(" %d",a[i]);deb("\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    bool key=false;
    for(int i=0;i<=n/4;i++){
        if((n-4*i)%7==0){
            key=true;
        }
    }
    if(key){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
#define LL long long
#define For(i,n) for(int i=1;i<=n;i++)

using namespace std;
int n,m,t;

int main()
{
	cin>>n>>m>>t;
	int x=min(m,t);
	int y=max(m,t);
	if(x+n>=y)cout<<0<<endl;
	else cout<<y-(x+n)<<endl;
	
	
	
	
	return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CSubarraySum {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, K, S;
        cin >> N >> K >> S;

        REP(i, N) {
            if (i < K) {
                cout << S << " ";
            } else {
                if (S < 1000000000) {
                    cout << S + 1 << " ";
                } else {
                    cout << 1 << " ";
                }
            }
        }
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CSubarraySum solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1280
import java.math.BigInteger

fun main(args: Array<String>) {
    val INF = BigInteger.valueOf(2000000000000000000L);
    val n = readLine()!!.toInt()
    val x = readLine()!!.split(" ").map { it.toBigInteger() }.reduce { x, y -> (x * y).min(INF) }
    if (x > BigInteger.valueOf(1000000000000000000L)) {
        println(-1)
    } else {
        println(x)
    }
}

Measured memory_bytes: 71732
package main

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

const M = 1046527

var T [M]string

func getKey(s string) int64 {
	h := int64(0)
	p := int64(1)
	for _, c := range s {
		x := int64(c - 'A' + 1)
		h += p * x
		p *= 5
	}
	return h
}

func h1(k int64) int64 {
	return k % M
}

func h2(k int64) int64 {
	return k % (M - 1)
}

func find(s string) bool {
	key := getKey(s)
	for i := int64(0); ; i++ {
		h := (h1(key) + i*h2(key)) % M
		if T[h] == s {
			return true
		}
		if len(T[h]) == 0 {
			return false
		}
	}
	return false
}

func insert(s string) {
	key := getKey(s)
	for i := int64(0); ; i++ {
		h := (h1(key) + i*h2(key)) % M
		if T[h] == s {
			return
		}
		if len(T[h]) == 0 {
			T[h] = s
			return
		}
	}
}

func main() {
	n := 0
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	var cmd, key string
	for i := 0; i < n; i++ {
		sc.Scan()
		cmd = sc.Text()
		sc.Scan()
		key = sc.Text()
		if cmd[0] == 'f' {
			if find(key) {
				fmt.Fprintf(w, "yes\n")
			} else {
				fmt.Fprintf(w, "no\n")
			}
		} else {
			insert(key)
		}
	}
	w.Flush()
}



Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

ll calc(ll x){
	return x * x * x;
}

int main(){
	int i,j,m,l,x,y,z; string s;
	ll n, k;
	cin >> n >> k;

	ll f = 0LL;
	if(k%2 == 1){
		f = calc(n/k);
	}else{
		f = calc((n+k/2)/k) + calc(n/k);
	}

	cout << f << endl;

}

Measured memory_bytes: 256
def segfunc(x,y):return min(x,y)
ide_ele=10**18
class segtree():
  def __init__(self,init_val,segfunc=segfunc,ide_ele=ide_ele):
    n=len(init_val)
    self.segfunc=segfunc
    self.ide_ele=ide_ele
    self.num=1<<(n-1).bit_length()
    self.tree=[ide_ele]*2*self.num
    for i in range(n):
      self.tree[self.num+i]=init_val[i]
    for i in range(self.num-1,0,-1):
      self.tree[i]=self.segfunc(self.tree[2*i], self.tree[2*i+1])
  def update(self,k,x):
    k+=self.num
    self.tree[k]=x
    while k>1:
      self.tree[k>>1]=self.segfunc(self.tree[k],self.tree[k^1])
      k>>=1
  def query(self,l,r):
    res=self.ide_ele
    l+=self.num
    r+=self.num+1
    while l<r:
      if l&1:
        res=self.segfunc(res,self.tree[l])
        l+=1
      if r&1:
        res=self.segfunc(res,self.tree[r-1])
      l>>=1
      r>>=1
    return res
n,q=map(int,input().split())
stx=segtree([ide_ele]*n)
sty=segtree([ide_ele]*n)
stx.update(n-1,n-2)
sty.update(n-1,n-2)
ans=(n-2)*(n-2)
for _ in range(q):
  x,y=map(int,input().split())
  if x==1:
    x=stx.query(y-1,n)
    ans-=x
    sty.update(x,min(y-2,sty.query(x,n)))
  else:
    x=sty.query(y-1,n)
    ans-=x
    stx.update(x,min(y-2,stx.query(x,n)))
print(ans)

Measured memory_bytes: 124752
{-# LANGUAGE ScopedTypeVariables #-}

import Control.Applicative
import Data.List

main = do
  [w, h, x, y, r]::[Int] <- map read . words <$> getLine
  if x - r >= 0 && y - r >= 0 && x + r <= w && y + r <= h
    then putStrLn "Yes"
    else putStrLn "No"

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

using namespace std;
typedef long long ll;
const int MAXN = 200100;
const ll MOD = 1e9 + 7;
const ll P = 2413;

string S, T;
ll phash[MAXN];
ll pmult[MAXN];
ll sz[100];
ll cc[100][26];

string get_nv ()
{
    int N = S.length();
    phash[0] = 0;
    pmult[0] = 1;
    for (int i = 0; i < N; i++)
    {
        phash[i+1] = (phash[i] * P + S[i]) % MOD;
        pmult[i+1] = (pmult[i] * P) % MOD;
    }

    for (int i = N + 2; ; i += 2)
    {
        int cchunk = i / 2;
        ll lhs = phash[N-cchunk];
        ll rhs = phash[N] - phash[cchunk] * pmult[N-cchunk];
        if ((lhs - rhs) % MOD == 0)
        {
            return S + S.substr(N - cchunk, i - N);
        }
    }
}

vector <ll> gogo (ll x)
{
    if (x < sz[0])
    {
        vector <ll> res;
        for (int i = 0; i < 26; i++)
            res.push_back(0);

        for (int i = 0; i < x; i++)
            res[S[i]-'a']++;
        return res;
    }

    int chi = 0;
    while (x >= sz[chi+1])
        chi++;

    vector <ll> res;
    for (int i = 0; i < 26; i++)
        res.push_back(cc[chi][i]);

    vector <ll> nleft = gogo (x - sz[chi]);
    for (int i = 0; i < 26; i++)
        res[i] += nleft[i];
    return res;
}

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

    cin >> S;
    T = get_nv ();

    //cout << T << "\n";

    sz[0] = S.length() / 2;
    for (int i = 0; i < S.length() / 2; i++)
    {
        int nv = S[i] - 'a';
        cc[0][nv]++;
    }
    sz[1] = T.length() / 2;
    for (int i = 0; i < T.length() / 2; i++)
    {
        int nv = T[i] - 'a';
        cc[1][nv]++;
    }
    
    int chi = 2;
    while (true)
    {
        sz[chi] = sz[chi-1] + sz[chi-2];
        for (int i = 0; i < 26; i++)
        {
            cc[chi][i] = cc[chi-1][i] + cc[chi-2][i];
        }

        if (sz[chi] > 2e18)
            break;
        chi++;
    }

    ll L, R;
    cin >> L >> R;
    vector <ll> res1 = gogo (R), res2 = gogo (L - 1);
    for (int i = 0; i < 26; i++)
        res1[i] -= res2[i];

    for (int i = 0; i < 26; i++)
    {
        if (i) cout << " ";
        cout << res1[i];
    }
    cout << "\n";
}

Measured memory_bytes: 4176
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

ll A[200000];
ll B[200005];

int main(){
  int N, K;
  cin >> N >> K;
  rep(i, N){
    cin >> A[i];
  }

  rep(i, N){
    B[i + 1] = B[i] + A[i];
    B[i + 1] %= K;
  }

  rep(i, N + 1){
    B[i] += N - i;
    B[i] %= K;
  }

  map<ll, int> mp;
  rep(i, N + 1){
    mp[B[i]]++;
  }

  //rep(i, N + 1){ cout << B[i] << " "; } cout << endl;
  // rep(i, N + 1){ cout << mp[i] << " "; } cout << endl;

  map<int, int> cnt;
  int l = 0;
  int r = min(N, K - 1);

  ll ans = 0;
  rep(i, r + 1){
    ans += cnt[B[i]];
    cnt[B[i]]++;
  }
  //cout << ans << endl;

  while(1){
    if(r == N) break;
    cnt[B[l]]--;
    l++;
    r++;
    ans += cnt[B[r]];
    cnt[B[r]]++;
  }

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


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int a = 0, b = 0;
  rep(i,n) if (s[i] == 'R') ++a;
  int ans = max(a,b);
  rep(i,n) {
    if (s[i] == 'R') --a;
    else ++b;
    int now = max(a,b);
    ans = min(ans, now);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3720
MM = input().split()
W = int(MM[0])
H = int(MM[1])
N = int(MM[2])
a = 0
b = 0
c = W
d = H
for i in range(N):
  LL = input().split()
  x = int(LL[0])
  y = int(LL[1])
  aa = int(LL[2])
  if aa == 1:
    if x > a:
      a = x
  elif aa == 2:
    if x < c:
      c = x
  elif aa == 3:
    if y > b:
      b = y
  else:
    if y < d:
      d  = y

if (c-a) > 0 and (d -b) > 0:
  ans = (c-a) * (d -b)
  print(ans)
else:
  print(0)

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

int main() {
    long long n, a, b;
    cin >> n >> a >> b;
    long long x = n % (a + b), y = n / (a + b);
    long long ans = y * a + min(x, a);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#define inf 1e9

using namespace std;

int n, m;
int b[505][505];
int B[505];
int bit[505];
int dp[2][1 << 22];

int main(void)
{
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		
		for(int i = 1; i <= n; i++){
			for(int j = 0; j < m; j++){
				char c;
				cin >> c;
				b[i][j] = c - '0';
			}
		}
		
		int ans = 0;
		if(n <= 22){
			int S = 1 << n;
			for(int i = 0; i < S; i++){
				int cnt = 0;
				for(int j = 0; j < m; j++) bit[j] = 0;
				for(int j = 1; j <= n; j++){
					if( (i & (1<<(j-1))) == 0) continue;
					cnt++;
					for(int k = 0; k < m; k++) bit[k] ^= b[j][k];
				}
				bool flag = false;
				for(int j = 0; j < m; j++) flag |= bit[j];
				if(!flag) ans = max(ans, cnt);
			}
		}
		else{
			
			for(int i = 1; i <= n; i++){
				B[i] = 0;
				for(int j = 0; j < m; j++) B[i] |= (b[i][j] << j);
			}
			
			int S = 1 << m;
			for(int i = 0; i < S; i++) dp[0][i] = dp[1][i] = -inf;
			dp[0][0] = 0;
			for(int i = 0; i < n; i++){
				for(int j = 0; j < S; j++){
					dp[(i+1)%2][j^B[i+1]] = max(dp[(i+1)%2][j^B[i+1]], dp[i%2][j] + 1);
					dp[(i+1)%2][j] = max(dp[(i+1)%2][j], dp[i%2][j]);
				}
			}
			ans = dp[n%2][0];
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 20464
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int n2 = 1 << n;
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n2];
		for (int i = 0; i < n2; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		List<PriorityQueue<Integer>> list = new ArrayList<>();
		for (int i = 0; i < n2; i++) {
			PriorityQueue<Integer> que = new PriorityQueue<>();
			que.add(a[i]);
			list.add(que);
		}
		for (int j = 0; j < n; j++) {
			for (int i = 0; i < n2; i++) {
				if ((i >> j & 1) == 1) {
					PriorityQueue<Integer> que = list.get(i);
					que.addAll(list.get(i & ~(1 << j)));
					while (que.size() > 2) {
						que.poll();
					}
				}
			}
		}

		PrintWriter pw = new PrintWriter(System.out);
		int ans = 0;
		for (int i = 1; i < n2; i++) {
			int val = 0;
			for (int o : list.get(i)) {
				val += o;
			}
			ans = Math.max(ans, val);
			pw.println(ans);
		}
		pw.flush();
	}
}


Measured memory_bytes: 99676
#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
using namespace std;

int main(){
    long long int X;
    cin >> X;
    for (long long int i = -200; i <= 200; i++) {
        for (long long int j = -200; j <= 200; j++) {
            long long int ans = (long long)pow(i, 5) - (long long)pow(j, 5);
            if (ans == X) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4072
#include <bits/stdc++.h>
using namespace std;
int n,m,tot=0,head[100001],nxt[200002],to[200002];
long long g[100001],f[100001];
vector<long long> pre[100001],rev[100001];
void addedge(int u,int v)
{
	++tot;
	nxt[tot]=head[u];
	to[tot]=v;
	head[u]=tot;
	return;
}
long long dfs(int index,int p)
{
	int flag=0,u,v,i;
	g[index]=1;
    vector<long long> tmp;
	for(u=head[index];u;u=nxt[u])
	{
		v=to[u];
		if(v==p)
			continue;
        flag=1;
		g[index]=g[index]*(dfs(v,index)+1)%m;
        tmp.push_back(g[v]+1);
      //  printf("&&&%lld %d\n",g[v],index);
	}
    if(flag)
    {
        pre[index].resize(tmp.size()+1);
        pre[index][1]=1;
        rev[index].resize(tmp.size()+2);
        rev[index][tmp.size()]=1;
        for(i=2;i<=tmp.size();i++)
        {
            pre[index][i]=pre[index][i-1]*tmp[i-2]%m;
           // printf("ppp %d %d %lld\n",index,i,pre[index][i]);
        }
        for(i=tmp.size()-1;i>=1;i--)
        {
            rev[index][i]=rev[index][i+1]*tmp[i]%m;
           // printf("rrr %d %d %lld\n",index,i,rev[index][i]);
        }
    }
	return g[index];
}
void ddfs(int index,int k,int p)
{
	int u,v,l=0;
	f[index]=k*g[index]%m;
   // printf("%d %d %d\n",index,k,p);
	for(u=head[index];u;u=nxt[u])
	{
		v=to[u];
		if(v!=p)
        {
            l++;
      //      printf("***%lld %lld\n",pre[index][l],rev[index][l]);
			ddfs(v,(pre[index][l]*rev[index][l]%m*k%m+1)%m,index);
        }
	}
}
int main()
{
	int i,u,v,j;
	scanf("%d%d",&n,&m);
	for(i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		addedge(u,v);
		addedge(v,u);
	}
	dfs(1,0);
    /*for(i=1;i<=n;i++)
    {
        for(j=1;j<=pre[i].size()-1;j++)
            printf("%lld ",pre[i][j]);
        printf("\n");
    }*/
	ddfs(1,1,0);
	for(i=1;i<=n;i++)
		printf("%lld\n",f[i]%m);
	return 0;
}

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

int absolute(int x){
    return (x>0) ? x : x*(-1);
}

int mini(int a, int b){
    return (a>b) ? b : a;
}


int main(){

    int n, h1, h2, h3;
    cin >> n >> h2 >> h3;
    int dp[n];

    dp[0] = 0;
    dp[1] = absolute(h2-h3);

    for(int i = 2; i < n; i++){
        h1 = h2;
        h2 = h3;
        cin >> h3;
        dp[i] = mini((dp[i-2]+absolute(h3-h1)),(dp[i-1]+absolute(h3-h2)));
    }

    cout << dp[n-1];

    return 0;
}


Measured memory_bytes: 640
import std.stdio;
import std.string;
import std.array; // split
import std.conv; // to

void main()
{
   string n = chomp(readln());
   int a = to!int(n);
   if(a/100%10 == a/10%10 && (a/100%10 == a/1000 || a/100%10 == a%10)){
       writeln("Yes");
   } else {
       writeln("No");
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 110;
int A, B;

int main(int argc, const char * argv[]) {
    cin >> A >> B;
    int ans = 0;
    int plug = 1;
    while (plug < B) {
        plug = plug + A - 1;
        ans++;
    }

    output(ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long ans;
int st[30000001],tail;
int a[3000001];
void calc(int x)
{
  int le=0,ri=tail,mid,ret=0;
  while(le<=ri)
  {
    mid=(le+ri)>>1;
    if(a[st[mid]]>x)ret=mid,le=mid+1;
    else ri=mid-1;
  }
  if(!ret)ans+=tail;
  else ans+=tail-ret+1;
}
int main()
{
	int a,b,c;
  cin>>a>>b>>c;
  cout<<(a-b)%c;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int k,a,b;
    int f=0;
    scanf("%d",&k);
    scanf("%d %d",&a, &b);
    for(int i=a; i<=b; i++){
        if(i%k==0){
            printf("OK\n");
            f=1;
            break;
        }
    }
    if(f==0){
        printf("NG\n");
    }
    return 0;
}

Measured memory_bytes: 1648
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<sstream>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<ctime>
using namespace std;

int main()
{
    long long a, b, n;
    cin >> a >> b >> n;
    long long p = n >= b ? b - 1 : n;
    cout << (a/b*p+a%b*p/b) << endl;
    return 0;
}

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

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  rep(i,s.size()){
    if(s[i] + n > 90)
      s[i] = s[i] + n - 26;
    else
      s[i] = s[i] + n;
    }
    cout << s << endl;
}


Measured memory_bytes: 256
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define int          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005
ll n,m,x[N],y[N],parent[N],size[N],p[N];
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
    parent[v] = v;
    size[v] = 1;
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (size[a] < size[b])
            swap(a, b);
        parent[b] = a;
        size[a] += size[b];
    }
}
signed main()
{
	ios
	ll i,j,ans=0;
	cin>>n>>m;
	for(i=1;i<=n;i++){
		make_set(i);
		cin>>p[i];
	}
	for(i=0;i<m;i++){
		cin>>x[i]>>y[i];
		union_sets(x[i],y[i]);
	}
	for(i=1;i<=n;i++){
		ll p1=find_set(p[i]),p2=find_set(i);
		if(p1==p2)ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4224
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);


int m, n;
int maze[11][11];
int house[11][11];
int housecount;

int dfs(int y, int x, int depth) {
	int ret = 0;
	for (int i = y - 1; i >= 0; --i) {
		if (depth == housecount && maze[i][x] == 2)
			return 1;

		if (maze[i][x] == 1) {
			maze[i][x] = 0;
			ret += dfs(i, x, depth + 1);
			maze[i][x] = 1;

			break;
		}
	}
	for (int i = y + 1; i < n; ++i) {
		if (depth == housecount && maze[i][x] == 2)
			return 1;

		if (maze[i][x] == 1) {
			maze[i][x] = 0;
			ret += dfs(i, x, depth + 1);
			maze[i][x] = 1;

			break;
		}
	}
	for (int i = x - 1; i >= 0; --i) {
		if (depth == housecount && maze[y][i] == 2)
			return 1;

		if (maze[y][i] == 1) {
			maze[y][i] = 0;
			ret += dfs(y, i, depth + 1);
			maze[y][i] = 1;

			break;
		}
	}
	for (int i = x + 1; i < m; ++i) {
		if (depth == housecount && maze[y][i] == 2)
			return 1;

		if (maze[y][i] == 1) {
			maze[y][i] = 0;
			ret += dfs(y, i, depth + 1);
			maze[y][i] = 1;

			break;
		}
	}

	if (depth == housecount)
		return 0;

	return ret;
}

int main() {
	while (cin >> m >> n && (m || n)) {
		housecount = 0;
		for (int i = 0; i < 11; i++)for (int j = 0; j < 11; j++)maze[i][j] = house[i][j] = 0;
		int si, sj;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cin >> maze[i][j];
				if (maze[i][j] == 1) {
					house[i][j] = housecount;
					housecount++;
				}
				if (maze[i][j] == 2) {
					si = i, sj = j;
				}
			}
		}
		cout << dfs(si, sj, 0) << endl;
	}
}

Measured memory_bytes: 3096
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

struct MinimumCostFlow {
	using Flow = int;
	using Cost = int;
	struct Edge {
		int to, rev;
		Flow cap;
		Cost cost;
		Edge() {}
		Edge(int to, int rev, Flow cap, Cost cost) :to(to), rev(rev), cap(cap), cost(cost) {}
	};
	int n;
	vector<vector<Edge>> g;
	vector<int> dist;
	vector<int> prevv, preve;
	MinimumCostFlow(int n) :n(n), g(n), dist(n), prevv(n), preve(n) {}
	void addArc(int from, int to, Flow cap, Cost cost) {
		g[from].emplace_back(to, (int)g[to].size(), cap, cost);
		g[to].emplace_back(from, (int)g[from].size() - 1, 0, -cost);
	}
	// s??????t????????????f???????°??????¨???
	// ??????????????´?????? -1
	Cost minimumCostFlow(int s, int t, Flow f) {
		Cost total = 0;
		while (f > 0) {
			// Bellman-Ford
			fill(dist.begin(), dist.end(), INF);
			dist[s] = 0;
			bool update = true;
			while (update) {
				update = false;
				for (int v = 0; v < n; v++) {
					if (dist[v] == INF)continue;
					for (int i = 0; i < g[v].size(); i++) {
						Edge &e = g[v][i];
						if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
							dist[e.to] = dist[v] + e.cost;
							prevv[e.to] = v;
							preve[e.to] = i;
							update = true;
						}
					}
				}
			}
			// ????????\???????????????
			if (dist[t] == INF)
				return -1;
			// ?????????????????£??????????????????
			int d = f;
			for (int v = t; v != s; v = prevv[v])
				d = min(d, g[prevv[v]][preve[v]].cap);
			f -= d;
			total += d*dist[t];
			for (int v = t; v != s; v = prevv[v]) {
				Edge &e = g[prevv[v]][preve[v]];
				e.cap -= d;
				g[v][e.rev].cap += d;
			}
		}
		return total;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int M, W; cin >> M >> W&&M;) {
		vector<int> bm(M); rep(i, 0, M) {
			cin >> bm[i];
		}
		vector<int> bw(W); rep(i, 0, W) {
			cin >> bw[i];
		}
		MinimumCostFlow mcf(M + W + 2);
		int s = M + W, t = s + 1;
		rep(i, 0, M) {
			mcf.addArc(s, i, 1, 0);
		}
		rep(i, 0, W) {
			mcf.addArc(i + M, t, 1, 0);
		}
		rep(i, 0, M)rep(j, 0, W) {
			mcf.addArc(i, j + M, 1, -abs(bm[i] - bw[j])*(abs(bm[i] - bw[j]) - 30)*(abs(bm[i] - bw[j]) - 30));
		}
		int ans = 0;
		rep(i, 0, M + 1) {
			MinimumCostFlow tmcf = mcf;
			MinimumCostFlow::Cost cost = -tmcf.minimumCostFlow(s, t, i);
			chmax(ans, cost);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3208
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
long mod=1e9+7;
int N,M,S,T;
vector<pair<int,int> >G[1<<17];
long a[1<<17],b[1<<17],c[1<<17],d[1<<17];
void calc(int S,long*d,long*w)
{
	for(int i=0;i++<N;)d[i]=1e18;
	priority_queue<pair<long,int> >P;
	d[S]=0;
	w[S]=1;
	P.push(make_pair(0,S));
	while(!P.empty())
	{
		long c=-P.top().first;
		int u=P.top().second;
		P.pop();
		if(d[u]<c)continue;
		for(pair<int,int>p:G[u])
		{
			int v=p.first;
			long nxt=c+p.second;
			if(d[v]>nxt)
			{
				d[v]=nxt;
				w[v]=w[u];
				P.push(make_pair(-d[v],v));
			}
			else if(d[v]==nxt)(w[v]+=w[u])%=mod;
		}
	}
}
main()
{
	cin>>N>>M>>S>>T;
	for(int i=0;i<M;i++)
	{
		int u,v,d;cin>>u>>v>>d;
		G[u].push_back(make_pair(v,d));
		G[v].push_back(make_pair(u,d));
	}
	calc(S,a,b);
	calc(T,c,d);
	long ans=b[T]*b[T];
	for(int i=0;i++<N;)
	{
		if(2*a[i]==a[T])ans-=b[i]*b[i]%mod*d[i]%mod*d[i]%mod;
		for(pair<int,int>p:G[i])
		{
			int v=p.first;
			if(2*a[i]<a[T]&&2*a[v]>a[T]&&a[i]+c[v]+p.second==a[T])
				ans-=b[i]*b[i]%mod*d[v]%mod*d[v]%mod;
		}
	}
	cout<<(ans+mod)%mod<<endl;
}


Measured memory_bytes: 16340
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    int ans = 0;
    int m = 0;
    rep(i, n) {
        if (h[i]>=m) {
            ans++;
            m = h[i];
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int K;
    cin >> K;
    if(K==1) cout << 1 ;
    else if(K==2) cout << 1;
    else if(K==3) cout << 1;
    else if(K==4) cout << 2;
    else if(K==5) cout << 1;
    else if(K==6) cout << 2;
    else if(K==7) cout << 1;
    else if(K==8) cout << 5;
    else if(K==9) cout << 2;
    else if(K==10) cout << 2;
    else if(K==11) cout << 1;
    else if(K==12) cout << 5;
    else if(K==13) cout << 1;
    else if(K==14) cout << 2;
    else if(K==15) cout << 1;
    else if(K==16) cout << 14;
    else if(K==17) cout << 1;
    else if(K==18) cout << 5;
    else if(K==19) cout << 1;
    else if(K==20) cout << 5;
    else if(K==21) cout << 2;
    else if(K==22) cout << 2;
    else if(K==23) cout << 1;
    else if(K==24) cout << 15;
    else if(K==25) cout << 2;
    else if(K==26) cout << 2;
    else if(K==27) cout << 5;
    else if(K==28) cout << 4;
    else if(K==29) cout << 1;
    else if(K==30) cout << 4;
    else if(K==31) cout << 1;
    else if(K==32) cout << 51;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <stack>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0;i < n;i++)cin >> a[i];

	ll ans = 0;
	for(int i = 0;i < n;i++){
		int j = i;
		ll sum = 0;
		while(j < n && a[j] != 0){
			sum += a[j];
			j++;
		}
		ans += sum / 2;
		i = j;
	}

	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
  int h,w,d;
  cin>>h>>w>>d;
  vector<vector<int>> a(h,vector<int>(w));
  vector<pair<int,int>> p(h*w);
  rep(i,h) rep(j,w){
    cin>>a[i][j];
    p[--a[i][j]] = {i,j};
  }

  vector<vector<int>> step(d);
  rep(i,d){
    auto pre = p[i];
    for(int j=i; j<h*w; j+=d){
      step[i].pb(abs(pre.first - p[j].first) + abs(pre.second - p[j].second));
      pre = p[j];
    }
    int acc = 0;
    for(auto &x : step[i]){
      acc += x;
      x = acc;
    }
  }

  int q;
  cin>>q;
  rep(i,q){
    int s,t;
    cin>>s>>t;
    s--;t--;
    cout << step[t%d][t/d] - step[s%d][s/d] << "\n";
  }

  return 0;
}


Measured memory_bytes: 6400
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

int calc(int a, int b) {
	if (a==b) return (a-1)*2;
	if (a>b) swap(a, b);
	
	int res = a-1;
	long long int m = 1LL*a*b-1;
	/*long long int lo = a+2, hi = m, pos;
	while(lo<=hi) {
		long long int mi = (lo+hi)/2;
		if (m/mi == m/(mi-1) || mi>a+2 && m/(mi-1)==m/(mi-2)) {
			pos = mi;
			hi=mi-1;
		} else lo=mi+1;
	}
	printf("- %d\n", pos);
	return res + pos-1-a + m/pos-1;*/
	long long int it = a+1, y=m/it, x;
	long long ran = sqrt(m-1);
	if (ran > it) {
		res += ran-1-it; it=ran-1;
	}
	do {
		res++;
		it++;
		x=y; y = m/it;
	} while (y!=x);
	//printf("- %d\n", it-ran);
	return res + y-1;
}

int main() {
	int q, a, b;
	for(scanf("%d", &q); q--;) {
		scanf("%d%d", &a, &b);
		printf("%d\n", calc(a, b));
	}
	
	return 0;
}

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

int main(int argc, const char * argv[]) {
    int a, b, c;
    
    cin >> a >> b >> c;
    if (a + b >= c) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


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

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

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  string s, t, u ;
  cin >> s >> t >> u ;
  cout << s.at(0)<<t.at(1)<<u.at(2)<<endl ;
    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int dp[1000010][2];

int main() {
	string N;
	cin >> N;
	reverse(N.begin(), N.end());
	N += '0';
	dp[0][0]=0;
	dp[0][1]=1e5;
	for(int i=0; i<N.size(); ++i){
		dp[i+1][0]=min(dp[i][0]+(N[i]-'0'), dp[i][1]+(N[i]-'0')+1);
		dp[i+1][1]=min(dp[i][0]+10-(N[i]-'0'), dp[i][1]+9-(N[i]-'0'));
	}
	cout << dp[N.size()][0] << endl;
	return 0;
}

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,k;
  cin>>n>>k;
  vlong sum(n);
  vlong a(n);
  cin>>a[0];
  sum[0]=a[0];
  REP(i,1,n){
    cin>>a[i];
    sum[i]+=sum[i-1]+a[i];
  }
  ll zen;
  zen=sum[k-1];
  rep(i,n-k){
    if(zen<sum[k+i]-sum[i]){
      cout<<"Yes"<<'\n';
    }
    else{
      cout<<"No"<<'\n';
    }
    zen=sum[k+i]-sum[i];
  }
  return(0);
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
int main(){
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> sum;
    sum.push_back(0);
    for(int i = 0; i < n; i++){
        ll l; cin >> l;
        sum.push_back(sum[sum.size()-1] + l);
    }
    ll ans = 1e15;
    for(int i = 1; i < n; i++){
        ans = min(ans, (ll)abs(sum[i] - (sum[n] - sum[i])));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 2420
#include<iostream>

using namespace std;

int main(){
    int x, y;

    cin >> x >> y;

    if(x==2){
        if(y==2)cout << "Yes" << endl;
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    else if(x==4 || x==6 || x==9 || x==11){
        if(y==4 || y==6 || y==9 || y==11)cout << "Yes" << endl;
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    else{
        if(y==1 || y==3 || y==5 || y==7 || y==8 || y==10 || y==12)cout << "Yes" << endl;
        else{
            cout << "No" << endl;
            return 0;
        }
    }
}


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

// varibable settings
#define int long long
const int INF=1e18;
const int MOD=1e9+7;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int n;cin>>n;
  string s;cin>>s;

  set<string> st;
  vi x(10);
  vi y(100);
  vi z(1000);

  st.insert("");
  rep(i, n){
    int v = s[i]-'0';
    rep(j, 100){
      if (y[j]) z[j + 100*v] = 1;
    }
    rep(j, 10){
      if (x[j]) y[j + 10*v] = 1;
    }
    x[v] = 1;
  }
  int ans = 0;
  rep(i, 1000) {
    if (z[i]) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	double a, b;
	cin >> a >> b;

	printd((a * b) / 3.305785, 6);
}


Measured memory_bytes: 3276
n = gets.to_i
h = Hash.new(0)
sum = 0

'1'.upto(n.to_s) do |c|
  h[[c[0], c[-1]]] += 1
end

'1'.upto('9') do |i|
  '1'.upto('9') do |j|
    sum += h[[i, j]] * h[[j, i]]
  end
end

puts sum

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;

int main()
{
    int N, A, B, C;
    cin >> N >> A >> B >> C;

    vector<int> l(N);
    for(int i = 0; i < N; i++)
    {
        cin >> l[i];
    }

    int ans = __INT_MAX__;
    for(int i = 0; i < (1 << (2 * N)); i++)
    {
        vector<int> v(N);
        for(int j = 0; j < N; j++)
        {
            v[N - j - 1] = (i >> (j * 2)) & 3;
        }

        vector<int> x(4, 0), cnt(4, 0);
        for(int j = 0; j < N; j++)
        {
            x[v[j]] += l[j];
            cnt[v[j]]++;
        }

        bool ok = true;
        for(int j = 0; j < 3; j++)
        {
            if(cnt[j] == 0)
            {
                ok = false;
            }
        }

        if(!ok)
        {
            continue;
        }

        int res = 0;
        for(int j = 0; j < 3; j++)
        {
            res += (cnt[j] - 1) * 10;
        }

        res += abs(A - x[0]) + abs(B - x[1]) + abs(C - x[2]);
        ans = min(ans, res);
    }

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

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <map>
using namespace std;
map<int, int> m;
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        ++m[x];
    }
//    for (auto it = m.begin(); it != m.end(); ++it) printf("%d %d\n", it->first, it->second);
    auto it = m.end();
    --it;
    int sz = m.size();
    int cnt = 1;
    while (cnt <= sz && it->second < 2) {
//        printf("%d\n", it->first);
        --it;
        ++cnt;
    }
    if (cnt > sz) printf("0\n");
    else {
        int a = it->first;
        if (it->second >= 4) printf("%lld\n", 1LL * a * a);
        else {
            --it;
//            printf("%d\n", it->first);
            while (cnt <= sz && it->second < 2) {
//                printf("%d\n", it->first);
                --it;
            }
            if (cnt > sz) printf("0\n");
            else {
                int b = it->first;
                printf("%lld\n", 1LL * a * b);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4992
import java.util.*;

public class Main {
	
	static double[] solve(double a, double b, double c, double d, double e, double f){
			double det = a*e-b*d;
			double[] ans = new double[2];
			ans[0] = (c*e-b*f)/det;
			ans[1] = (a*f-c*d)/det;
			for(int i=0; i<2; i++) if(ans[i]==-0) ans[i] = 0;
			return ans;
	}
	

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		for(int i=0; i<n; i++){
			double x1 = stdIn.nextDouble();
			double y1 = stdIn.nextDouble();
			double x2 = stdIn.nextDouble();
			double y2 = stdIn.nextDouble();
			double x3 = stdIn.nextDouble();
			double y3 = stdIn.nextDouble();
		
			double[] ans = solve(x1-x2,y1-y2,x1*(x1-x2)+y1*(y1-y2),x3-x2,y3-y2,x3*(x3-x2)+y3*(y3-y2));
			double xp,yp,r;
			xp = (x2 + ans[0])/2.0;
			yp = (y2 + ans[1])/2.0;
			r = Math.sqrt((xp-x2)*(xp-x2)+(yp-y2)*(yp-y2));
			System.out.printf("%.3f %.3f %.3f",xp,yp,r);
			System.out.println();
		}
	}

}

Measured memory_bytes: 12000
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
        // TODO: メモリの使用量がやばいので Token ごとに読む
        // Reference: https://atcoder.jp/contests/abc148/submissions/9067537
        bufsize := 100 * 1024 * 1024
        sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
}
func readInt() int              { return readIntArray()[0] }
func readInt2() (int, int)      { a := readIntArray(); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(); return a[0], a[1], a[2] }
func readIntArray() []int {
        a := make([]int, 0, 1000)
        sc.Scan()
        for _, v := range strings.Split(sc.Text(), " ") {
                vv, _ := strconv.Atoi(v)
                a = append(a, vv)
        }
        return a
}
func readString() string            { return readStringArray()[0] }
func readString2() (string, string) { a := readStringArray(); return a[0], a[1] }
func readStringArray() []string     { sc.Scan(); return strings.Split(sc.Text(), " ") }

func main() {
        n := readInt()
        hs := readIntArray()

        dp := make([]int, n)

        dp[0] = 0
        dp[1] = abs(hs[1] - hs[0])

        for i := range dp {
                if i <= 1 {
                        continue
                }
                onestep := abs(hs[i]-hs[i-1]) + dp[i-1]
                twostep := abs(hs[i]-hs[i-2]) + dp[i-2]
                if onestep < twostep {
                        dp[i] = onestep
                } else {
                        dp[i] = twostep
                }
        }

        fmt.Println(dp[n-1])

}

func abs(x int) int {
        if x < 0 {
                return -x
        }
        return x
}

Measured memory_bytes: 8320
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long ans = A * B / gcd(A, B);
        System.out.println(ans);
    }
    
    static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
double dot(double ax, double ay, double bx, double by) {
	return ax*bx+ay*by;
}
int main() {
	int n,m;
	while(cin >> n, n) {
		double x[100],y[100],r[100];
		rep(i,n) {
			cin >> x[i] >> y[i] >> r[i];
		}
		cin >> m;
		double tx,ty,sx,sy;
		rep(i,m) {
			cin >> tx >> ty >> sx >> sy;
			bool flag = 0;
			rep(j,n) {
				double vx1 = tx-sx, vy1 = ty-sy;
				double vx2 = x[j]-sx, vy2 = y[j]-sy;
				double slen = sqrt(vx2*vx2+vy2*vy2);
				double tlen = sqrt(pow(x[j]-tx,2)+pow(y[j]-ty,2));				
				if(slen<r[j] && tlen>r[j] || slen>r[j] && tlen<r[j]) {
					flag = 1;
					break;
				} else {
					double n1 = dot(vx1,vy1,vx2,vy2);
					double n2 =	dot(vx1,vy1,vx1,vy1);
					double n3 = dot(vx2,vy2,vx2,vy2);
					if(n1>0 && n2>n1 && !(tlen<r[j]&&slen<r[j]) && n3-(n1/n2)*n1<=r[j]*r[j]) {
						flag = 1;
						break;
					}
				}
			}
			if(flag) cout << "Safe" << endl;
			else cout << "Danger" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1224