akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
    


  int main(){
     string s,t;
     cin>>s>>t;
     lint ans=0;
     rep(i,s.size()){
         if(s[i]!=t[i])ans++;
     }
     cout<<ans<<endl;
     }
     

  
 
  
      
      
    
 
  
          
  

Measured memory_bytes: 3980
primes = [2]
for n in range(3, 55555 + 1, 2):
    is_prime = True
    for p in primes:
        if p * p > n:
            break
        if n % p == 0:
            is_prime = False
            break
    if is_prime:
        primes.append(n)
primes1mod5 = list(filter(lambda x: x % 5 == 1, primes))
N = int(input())
print(" ".join(map(str, primes1mod5[:N])))

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

int count(vector<vector<int>> &board,int W,int H){
  int count = 0;
  for(int i = 0; i < W; i++){
    for(int j = 0; j < H; j++){
      if(board.at(j).at(i) == 0){
        count++;
      }
    }
  }
  return count;
}

int paint(vector<vector<int>> &board, int x, int y, int a, int &W, int &H){
  if(a == 2){
    for(int i = x; i < W; i++){
      for(int j = 0;j < H; j++){
        board.at(j).at(i) = 1;
      }
    }
  }
  
  if(a == 1){
    for(int i = x - 1; i >= 0; i--){
      for(int j = 0;j < H; j++){
        board.at(j).at(i) = 1;
      }
    }
  }
  
  if(a == 4){
    for(int i = 0; i < W; i++){
      for(int j = y;j < H; j++){
        board.at(j).at(i) = 1;
      }
    }
  }
  
  if(a == 3){
    for(int i = 0; i < W; i++){
      for(int j = y - 1;j >= 0; j--){
        board.at(j).at(i) = 1;
      }
    }
  }
}
int main(){
  int W, H, N;
  cin >> W >> H >> N;
  vector<tuple<int, int, int>> data(N);
  for(int i = 0; i < N; i++){
    int a, b,c;
    cin >>a >> b >> c;
    data.at(i) = make_tuple(a, b, c);
  }
  
  vector<vector<int>> board(H, vector<int>(W, 0));
  
  for(int i = 0; i < N; i++){
    int a, b, c;
    a = get<0>(data.at(i));
    b = get<1>(data.at(i));
    c = get<2>(data.at(i));
    paint(board, a, b, c, W, H);
  }
  cout << count(board,W,H) <<endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
R,S,P=map(int,input().split())
t=input()
ans=0
ra=[]
for i in range(k):
  if t[i]=='r':
    ra.append('p')
    ans+=P
  if t[i]=='p':
    ra.append('s')
    ans+=S
  if t[i]=='s':
    ra.append('r')
    ans+=R
for i in range(k,n):
  if t[i]=='r':
    if ra[i-k]=='p':
      ra.append('a')
    else:
      ra.append('p')
      ans+=P
  if t[i]=='p':
    if ra[i-k]=='s':
      ra.append('a')
    else:
      ra.append('s')
      ans+=S
  if t[i]=='s':
    if ra[i-k]=='r':
      ra.append('a')
    else:
      ra.append('r')
      ans+=R
print(ans)

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

#define OnlineJudge1

#define loop(a,n) for(int i = a;i<n;i++)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define readline(s) getline(cin,s)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)


typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
    #ifdef OnlineJudge
        freopen("in.in","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
}
int main(){
    init();
ll n,sum = 0,mx = 0;
cin >> n;
for(int i = 0;i < n;i++){
int x;
cin >> x;
sum+=x;
mx = max(mx,(ll)x);
}
sum -= (mx/2);
cout << sum;
}

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

int n, x, l;

int main(){
	cin >> n >> x;
	vector<int>l(n);

	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	int ans = 1;
	int p = 0;
	for (int i = 0; i < n; i++) {
		p += l[i];
		if (p <= x)
			ans++;
		else if (p > x)
			break;
	}

	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int i, j, n = scanner.nextInt();
        int count = 0;
        
        for(i = 0; i < n; ++i){
            int input = scanner.nextInt();
            int root = (int)Math.sqrt(input);
            for(j = 2; j <= root; ++j) if(input%j == 0) break;
            if(j == root + 1 || input == 2) ++count;
        } 
        System.out.println(count);
        scanner.close();
    }
}


Measured memory_bytes: 41432
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.12.28 20:11:35
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (ll i = 0; i < x; i++)
#define rep1(i, x) for (ll i = 1; i <= x; i++)
#define rrep(i, x) for (ll i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (ll i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const ll INF = 100000000;
const ll M = 100000000;
const ll dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const ll dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    ll n, a, b;
    scanf("%lld%lld%lld", &n, &a, &b);

    ll ret = -1;
    if (abs(a - b) % 2 == 0) {
        ret = abs(a - b) / 2;
    } else {
        ll x1, x2;
        x1 = min(abs(a - 1), abs(b - 1));
        x2 = min(abs(a - n), abs(b - n));
        ll x3 = min(x1, x2);
        ret = x3 + (abs(a - b) + 1) / 2;
    }

    printf("%lld\n", ret);

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=500010, inf=2e9;

int n;
int A[110];
int D[101][110];

int d(int i, int j){
    int &res=D[i][j];
    if(res>=0) return res;
    res=inf;
    for(int x=1; x<=n; x++){
        if(x==j) continue;
        res=min(res, d(i-1,x));
    }
    res+=(A[i]==j ? 0 : 1);
    return res;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int i=1; i<=n; i++) cin>>A[i];
    int ans=inf;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            D[i][j]=-1;
    for(int i=1; i<=n; i++)
        D[1][i] = (A[1]==i ? 0 : 1);


    for(int i=1; i<=n; i++) ans=min(ans, d(n,i));
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
R, G, B, N = map(int,input().split())
cnt = 0
for r in range(N//R + 1):
    for g in range((N-R*r)//G + 1):
        x = N - R*r - G*g
        if x >= 0 and x % B == 0:
            cnt += 1
print(cnt)


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

long long N;
long long X[200000],A[200000];

void solve(){
  int mid_l,mid_h;
  for(int i=0; i<N; i++){
    A[i] = X[i];
  }
  sort(A,A+N);
  mid_l = A[N/2-1];
  mid_h = A[N/2];

  for(int i=0; i<N; i++){
    if(X[i] <= mid_l){
      cout << mid_h << endl;
    }else if(X[i] >= mid_h){
      cout << mid_l << endl;
    }
  }
}

int main(){
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> X[i];
  }
  solve();
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

/*
ull gcd(ull a ull b){
	if(!b) return a;
	return gcd(b,a%b);
}
*/

int main(){
	int n;
	cin >> n;
	ull a[n],memo,ans = 0;
	
	rep(i,0,n){
		cin >> a[i];
		ans += a[i]-1;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace codeTester.contest190707
{
    class ProblemD
    {
        static readonly long modBasis = 1000000007;
        static long n = 0;
        static List<long> values = new List<long>();
        static List<long> answers = new List<long>();

        public static void Main(string[] args)
        {
            Input();
            Logic();
            Output();
        }

        static void Input()
        {
            n = int.Parse(Console.ReadLine());
            values = ReadSpaceSeparatedValues();
        }

        public static List<long> ReadSpaceSeparatedValues()
        {
            List<long> values = new List<long>();
            string[] inputs = Console.ReadLine().Split(' ');
            foreach (string input in inputs)
            {
                values.Add(long.Parse(input));
            }

            return values;
        }

        static void Logic()
        {
            List<long> mayAnswer = new List<long>();
            // 山1に降った雨の量を 0 と仮定する
            long supposedMountain1Rain = 0;
            DebugPrint("-- suppose " + supposedMountain1Rain.ToString() + " --");
            mayAnswer = new List<long>();
            mayAnswer.Add(supposedMountain1Rain * 2);
            long remainRain = values[0] - supposedMountain1Rain; // 山1以外から来た雨量
            for (int damNo = 1; damNo < n; damNo++)
            {
                DebugPrint("damNo " + damNo.ToString() + ", remainRain " + remainRain.ToString());
                mayAnswer.Add(remainRain * 2);
                remainRain = values[damNo] - remainRain;
            }
            if (remainRain == supposedMountain1Rain)
            {
                answers = mayAnswer;
                return;
            }

            supposedMountain1Rain = remainRain / 2;
            DebugPrint("-- suppose " + supposedMountain1Rain.ToString() + " --");
            mayAnswer = new List<long>();
            mayAnswer.Add(supposedMountain1Rain * 2);
            remainRain = values[0] - supposedMountain1Rain; // 山1以外から来た雨量
            for (int damNo = 1; damNo < n; damNo++)
            {
                DebugPrint("damNo " + damNo.ToString() + ", remainRain " + remainRain.ToString());
                mayAnswer.Add(remainRain * 2);
                remainRain = values[damNo] - remainRain;
            }
            if (remainRain == supposedMountain1Rain)
            {
                answers = mayAnswer;
                return;
            }
        }

        static void Output()
        {
            Console.WriteLine(string.Join(" ", answers));
        }

        static void DebugPrint(string msg)
        {
            // 提出時に消す
            // Console.WriteLine(msg);
        }
    }
}


Measured memory_bytes: 34500
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
#include <math.h>
#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    int n;
    vector<LL> a;
    LL tmp_a;
    LL b0;
    LL b1;
    LL b2;
    LL ans0=0;
    LL ans1=0;
    LL ans2=0;
    LL ans;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> tmp_a;
        tmp_a=tmp_a-(i+1);
        a.push_back(tmp_a);
    }
    sort(a.begin(), a.end());
    b0=a[n/2-1];
    b1=(a[n/2-1]+a[n/2])/2;
    b2=a[n/2];
    for(int i=0; i<n; i++){
        ans0+=(LL)abs(a[i]-b0);
        ans1+=(LL)abs(a[i]-b1);
        ans2+=(LL)abs(a[i]-b2);
    }
    if(ans2>ans1){
        if(ans1>ans0){
            ans = ans0;
        }else{
            ans = ans1;
        }
    }else{
        if(ans2>ans0){
            ans = ans0;
        }else{
            ans = ans2;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll (i) = (s); (i) < (x); (i) ++)
#define REP(i, x) PREP(i, 0, x)
#define MREP(i, s, x) for(ll (i) = (s); (i) >= (x); (i) --)
#define MOD7 (1000000007LL)
#define MOD9 998244353LL
#define INF (1LL<<60)
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll dx[4] = {0, 1, 0, -1};
ll dy[4] = {1, 0, -1, 0};

ll dfs(vector<string> &field, vector<vector<bool>> &seen, ll x, ll y, ll gx, ll gy, ll kai, ll h, ll w){
    seen[x][y] = true;
    cout << x << " " << y;
    cout << " " << kai << endl;

    ll res = INF;
    if(x == gx && y == gy) return kai;
    REP(dd, 4){
        ll next_x = x+dx[dd], next_y = y+dy[dd];
        cout << " " << next_x << " " << next_y << endl;

        if(next_x < 0 || next_x >= h) continue;
        if(next_y < 0 || next_y >= w) continue;
        if(seen[x+dx[dd]][y+dy[dd]] == true) continue;
        if(field[next_x][next_y] == '#') continue;
        cout << " " << "yap" << endl;
        ll hoge = dfs(field, seen, next_x, next_y, gx, gy, kai+1, h, w);
        chmin(res, hoge);
    }
    return res;
}

int main(){
    ll h, w;
    cin >> h >> w;
    vector<string> field(h);
    REP(i, h){
        cin >> field[i];
    }

    ll ans = 0;

    PREP(sx, 0, h){ // O(h)
        PREP(sy, 0, w){ // O(w)
            if(field[sx][sy] == '#') continue;
            vector<vector<ll>> seen(h, vector<ll>(w, -1));
            ll this_ans  = 0;
            queue<pair<pair<ll, ll>, ll>> que;
            que.push(make_pair(make_pair(sx, sy), 0));
            
            while(!que.empty()){ // O(HW)
                ll x = que.front().first.first;
                ll y = que.front().first.second;
                ll kai = que.front().second;
                que.pop();
                if(seen[x][y] != -1) continue;
                seen[x][y] = kai;
                chmax(ans, kai);

                REP(d, 4){
                    ll next_x = x + dx[d], next_y = y + dy[d];
                    
                    if(next_x < 0 || next_x >= h) continue;
                    if(next_y < 0 || next_y >= w) continue;
                    if(seen[next_x][next_y] != -1) continue;
                    if(field[next_x][next_y] == '#') continue;

                    que.push(make_pair(make_pair(next_x, next_y), kai+1));
                }
            }
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
count = 0
ans = 0

L,R,d = I()

for i in range(L,R+1):
    if i % d == 0:
        ans += 1
print(ans)

Measured memory_bytes: 9120
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getString()
	m := getInt()
	n := len(N)

	s := make([]int, n)
	for i := 0; i < n; i++ {
		s[i] = int(N[i] - '0')
	}

	var dp [101][4][2]int
	dp[0][0][0] = 1
	for i := 0; i < n; i++ {
		for j := 0; j <= m; j++ {
			for k := 0; k < 2; k++ {
				for l := 0; l < 10; l++ {
					nj, nk := j, k
					if l != 0 {
						nj++
					}
					if nj > m {
						continue
					}
					if s[i] < l && k == 0 {
						continue
					}
					if s[i] > l {
						nk = 1
					}
					dp[i+1][nj][nk] += dp[i][j][k]
				}
			}
		}
	}
	out(dp[n][m][0] + dp[n][m][1])
}


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vec h = ivec(n);
    sort(all(h), greater<int>());

    int ans = 0;
    rep (i, n) {
        if (k > 0) {
            k--;
            continue;
        }
        ans += h[i];
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 1792
from collections import defaultdict

def main():
    N, M = map(int, input().split())
    heights = list(map(int, input().split()))
    d = defaultdict(set)
    mous = set()
    for i in range(M):
        a, b = map(int, input().split())
        d[a-1].add(heights[b-1])
        d[b-1].add(heights[a-1])
        mous.add(a)
        mous.add(b)
    num_good = 0
    for k in set(d.keys()):
        is_good = True
        if heights[k] <= max(d[k]):
            is_good = False
        if is_good:
            num_good += 1
    num_good += N - len(mous)

    print(num_good)

if __name__ == "__main__":
    main()

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

using namespace std;
#define ll long long
#define cni const int
#define cnl const long long

cni maxn = 1e5+20;
ll dp[maxn];
ll inf=1e18+10;
int mod=1e9 + 7;
int ar[maxn], maxx[maxn], mxx[maxn];


int main() 
{
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	for(int i=0;i<n;i++)
		cin >> ar[i], dp[i]=inf;
		
    dp[0] = 0;
    dp[1] = abs(ar[1]-ar[0]);
    for(int i=2;i<n;i++)          
		dp[i] = min(dp[i-1] + abs(ar[i]-ar[i-1]), dp[i-2] + abs(ar[i]-ar[i-2]));
		
    cout << dp[n-1];
}




Measured memory_bytes: 1408
n = int(input())


import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

#n = 997764507000
A = prime_factorize(n)
C = collections.Counter(A)


count = 0
#print(C.values())
for v in C.values():
    i = 1
    while v >= i*(i+1)/2:
        i += 1
    count += i-1
print(count)

Measured memory_bytes: 65888
import fractions
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
S = input(); T = input()
gcd = fractions.gcd(N,M)
N_prime = N //gcd; M_prime = M // gcd
for i in range(0,N,N_prime):
    for j in range(0,M,M_prime):
        if i * M_prime - j * N_prime == 0 and S[i] != T[j]:
            print(-1)
            exit()
print(N*M // gcd)

Measured memory_bytes: 66792
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	vector<int> n(4);
	cin >> n[0] >> n[1] >> n[2] >> n[3];
  
  	sort(n.begin(), n.end());
  	if(n[0]==1 && n[1]==4 && n[2]==7 && n[3]==9){
		cout << "YES" << endl;
    }else{
    	cout << "NO" << endl;
    }

	return 0;
}


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

int main(){

    string s;
    cin >> s;

    int size = s.size(), cnt = 0;
    bool flg = true;
    if (s.at(0) != 'A') flg = false;
    for (int i=1; i<size; i++){
        if (s.at(i) == 'C'){
            cnt++;
            if ((i < 2) || (i>=(size-1)) || (cnt!=1)){
                flg = false;
            }
            continue;
        }
        if (isupper(s.at(i))) flg = false;
    }
    if (cnt == 0) flg = false;

    if (flg) cout << "AC" << endl;
    else cout << "WA" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

constexpr auto INF = INT_MAX/2;
constexpr auto MOD = 1000000007;


int main() {
	int n, m, d;
	cin >> n >> m >> d;
	cout << fixed << setprecision(8);

	if (d == 0)cout << (double)(m - 1) / n << endl;
	else cout << (double)2 * (n - d) * (m - 1) / n / n;

}

Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE BangPatterns #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Map.Strict (Map)
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import Data.Set (Set)

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Mutable as MVector
import Data.Vector.Mutable (STVector)
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToVector :: ByteString -> Vector Int
readIntToVector = Vector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToVectorN :: Int -> ByteString -> Vector.Vector Int
readIntToVectorN n = Vector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace


first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

average :: Fractional a => [a] -> a
average xs = sum xs / (fromIntegral . length) xs

-- ----------

main :: IO ()
main = do
	[n, k] <- readIntToList <$> BS.getLine
	let n1 = n `mod` k
	let n2 = abs $ n1 - k
	print $ min n1 n2


Measured memory_bytes: 380
N = int(input())

a = sorted([int(i) for i in input().split()])
b = sorted([int(i) for i in input().split()])
c = sorted([int(i) for i in input().split()])

import bisect

ans = 0
for i in range(N):
    lefta = bisect.bisect_left(a, b[i])
    leftc = N - bisect.bisect_right(c, b[i])

    ans += lefta * leftc

print(ans)



Measured memory_bytes: 22720
A, B, K = map(int, input().split())
cnt = 0
ans = 0
for i in range(100, 0, -1): # 100 から 1 まで -1ずつ
    if(A % i == 0 and B % i == 0):
        cnt = cnt + 1
    if(cnt == K):
        ans = i
        break #ループ抜ける
        
print(ans)

Measured memory_bytes: 2940
package main

import (
  "fmt"
)

var cand = map[int]int{7:0, 5:0, 3:0}

func main() {
  var x int
  fmt.Scan(&x)
  ans := "NO"
  if _, ok := cand[x]; ok {ans = "YES"}
  fmt.Println(ans)

}

Measured memory_bytes: 512
#include<stdio.h>
 
int main(void){
  
  int N,Flag = 0;
  scanf("%d",&N);
  
  if( N%10 == 7){
	Flag = 1;
  }else{
    N = N/10;
  }
  
  if( N%10 == 7 ){
	Flag = 1;
  }else{
    N = N/10;
  }
  
   if( N%10 == 7 ){
	Flag = 1;
  }else{

  }

  if( Flag == 1 ){
    printf("Yes");
  }else{
    printf("No");
  }
  
  return 0;
 
}

Measured memory_bytes: 2148
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

    
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    READV(K);
    READAR(A,N);
    sort(A,A+N);
    ll x=0;
    FORI(i,0,N-K)
    {
        x+=A[i];
    }
    cout<<x<<endl;

//-----------------------------------------------------------------------------------------------------------//


  
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif

const int MAXN = 100005;
const ll MOD = 1000000007;

int par[MAXN], n, dep[MAXN];
vector<int> edge[MAXN];

void build_par (int nd, int p) {
    par[nd] = p;
    dep[nd] = dep[p] + 1;
    for (auto v : edge[nd]) {
        if (v != p) {
            build_par(v, nd);
        }
    }
}

int wsz;
void dfs (int nd) {
    wsz++;
    debug(nd);
    for (auto v : edge[nd]) {
        if (v != par[nd]) {
            dfs(v);
        }
    }
}
/*********************GoodLuck***********************/
int main () {
    IOS();

    cin >> n;
    REP (i, n-1) {
        int u, v;
        cin >> u >> v;
        edge[u].emplace_back(v);
        edge[v].emplace_back(u);
    }

    build_par(1, 1);

    int wt = n;
    REP (i, (dep[n] - dep[1] - 1) / 2) {
        wt = par[wt];
    }
    debug(wt);
    dfs(wt);

    int bsz = n - wsz;

    debug(bsz, wsz);
    if (bsz <= wsz) {
        cout << "Snuke" << endl;
    } else {
        cout << "Fennec" << endl;
    }
    return 0;
}


Measured memory_bytes: 11264
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
typedef long long int ll;

int main(){
	int n,m;
	cin >> n >> m;
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		int tmp1 = min(a-1,n-a);
		int tmp2 = min(b-1,n-b);
		int num = min(tmp1,tmp2);
		int ans = num % 3;
		cout << ans+1 << endl;
	}
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){return modpow(x,mod-2);}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n;
int dp[1000010];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    dp[0]=1,dp[1]=n;
    int sum=n+1;
    for(int i=2;i<=n;i++){
        dp[i]=(sum-dp[i-2]+mod+(n-i+1)+(n-1)*(n-1))%mod;
        sum+=dp[i];
        sum%=mod;
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 8448
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=a; i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto& e:c)
#define iter(it,c) for(auto it=c.begin(); it!=c.end(); ++it)

double const inf = 1e20;
double const pi = acos(-1);
double eps = 1e-5;
double x[1024];
double y[1024];
int to_id[1024];
int to_no[1024];

double jump[1024][1024];
int n;

vi solve(int s, int g){
    static int from[1024];
    static double d[1024];
    static bool vis[1024];
    rep(i,n){
        d[i]=inf;
        vis[i]=false;
        from[i]=-1;
    }
    d[s]=0;
    while(1){
        bool fine=true;
        rep(i,n){
            if(vis[i]) continue;
            fine=false;break;
        }
        if(fine)break;
        double nd=inf;
        int v;
        rep(i,n){
            if(vis[i])continue;
            if(d[i]<nd){
                nd=d[i];v=i;
            }
        }
        if(nd==inf)break;
        vis[v]=true;
        rep(i,n){
            if(d[i]>d[v]+jump[v][i]){
                d[i]=d[v]+jump[v][i];
                from[i]=v;
            }
        }
    }
    if(d[g]==inf){
        return vi();
    }else{
        vi ans{g};
        int v=g;
        while(v!=-1){
            ans.push_back(from[v]);
            v=from[v];
        }
        return ans;
    }
}

int main(){
    while(cin>>n && n){
        rep(i,n){
            int t;
            cin>>t>>x[i]>>y[i];
            to_no[t]=i;
            to_id[i]=t;
        }
        rep(i,n)rep(j,n){
            double dx=x[i]-x[j];
            double dy=y[i]-y[j];
            double t=sqrt(dx*dx+dy*dy);
            if(t-eps>50)t=inf;
            jump[i][j]=t;
        }

        int m;cin>>m;
        rep(i,m){
            int s,g;cin>>s>>g;
            vi ans=solve(to_no[s],to_no[g]);
            if(ans.size()){
                for(int i=ans.size()-2;i>=0;i--){
                    cout << to_id[ans[i]] << (i==0?"\n":" ");
                }
            }else{
                cout << "NA" << endl;
            }
        }
    }
}

Measured memory_bytes: 1676
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    int s;
    int w;
    cin >> s >> w;
    if(w>=s){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi a(n);
    int cnt = 0;
    rep(i, n) {
        cin >> a[i];
        if (a[i] < 0) cnt++;
        a[i] = abs(a[i]);
    }
    sort(a.begin(), a.end());
    ll ans;
    if (cnt % 2 == 0) ans = accumulate(a.begin(), a.end(), 0LL);
    else ans = accumulate(a.begin()+1, a.end(), 0LL) - a[0];
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
	int A, B, C, ans;
	cin >> A >> B >> C;
	if (A == B)
	{
		ans = C;
	}
	else {
		if ((A - B) >= C)
		{
			ans = 0;
		}
		else {
			ans = C - (A - B);
		}
	}
	cout << ans;
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 1e5 + 10;
int a[maxN], b[maxN], c[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    ll ans = 0;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    for (int i = 1; i <= n; i++) {
        cin >> b[i];
    }

    for (int i = 1; i <= n; i++) {
        cin >> c[i];
    }
    sort(a + 1, a + n + 1);
    sort(c + 1, c + n + 1);
    for (int i = 1; i <= n; i++) {
        int p = upper_bound(c + 1, c + n + 1, b[i]) - c;
        int t = lower_bound(a + 1, a + n + 1, b[i]) - a - 1;
//        cout << t << " " << p << endl;
        ans += 1LL * t * (n - p + 1);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include<string>
#include<array>
#include <vector>
using ll = long long;
using namespace std;
int main()
{
    int N;
    cin >> N;
    string s;
    cin >> s;
    vector<int> r,g,b;
    for (int i = 0; i < N; i ++){
        if(s[i] == 'R') r.push_back(i);
        else if (s[i] == 'G')   g.push_back(i);
        else    b.push_back(i);
    }
    long long ans = r.size() * g.size() * b.size();
    int count = 0;
    for (int i : r){
        for (int j : b){
            int minn = min(i,j);
            int maxx = max(i,j);
            int d = maxx - minn;
            if(minn - d >= 0 && s[minn -d] == 'G') count ++;
            if(maxx + d < N && s[maxx + d] == 'G') count ++;
            if((i + j) % 2 == 0 && s[(i + j)/2] == 'G') count ++;
        }
    }
    cout << ans - count << endl;
    return 0;
}

Measured memory_bytes: 3264
def dfs(A, d):
    ans = 0
    if d == N:
        for a, b, c, d in ABCD:
            if A[b] - A[a] == c:
                ans += d
        return ans
    if A:
        s = A[-1]
    else:
        s = 1
    for i in range(s, M+1):
        ans = max(ans, dfs(A+[i], d+1))
    return ans

N, M, Q = map(int, input().split())
ABCD = []
for q in range(Q):
    a, b, c, d = map(int, input().split())
    ABCD += [[a-1, b-1, c, d]]

print(dfs([], 0))

Measured memory_bytes: 72896
n = gets.chomp.to_i
hash = Hash.new(0)
sentou = Hash.new(0)
n.times do |i|
    s = gets.chomp
    if s[0] == "M" || s[0] == "A" || s[0] == "R" || s[0] == "C" || s[0] == "H"
    hash[s] += 1
    sentou[s[0]] += 1
    end
end
arr = []
hash.each do |i|
    arr << i[0][0]
end
arr = arr.uniq.sort
ar = []
arr.permutation (3) do |i|
    ar << i.sort
end
ar =  ar.uniq
all = 0
ar.each do |j|
    count = 1
    j.each do |k|
        count *= sentou[k]
    end
    all += count
end
puts all

Measured memory_bytes: 33492
from sys import setrecursionlimit as SRL, stdin

SRL(10 ** 7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())

q = [[]]
l = [0] * 1005
d = [0] * 1005
hv = [0] * 1005

def dfs(x,y):
    hv[x] = 1
    for i in range(l[x],n-1):

        if q[x][i] == y:
            l[x] = i+1
            hv[x] = 0

            d[q[x][i]] += 1
            d[x] += 1
            d[x] = max(d[x],d[q[x][i]])
            d[q[x][i]] = max(d[x], d[q[x][i]])

            return
        if hv[q[x][i]]:
            print(-1)
            exit(0)
        dfs(q[x][i],x)
        d[x] = max(d[q[x][i]],d[x])


    hv[x] = 0
    l[x] = n

n = int(input())
for i in range(n):
    a = list(rrd())
    q.append(a)

for i in range(1,n+1):
    dfs(i,0)

print(max(d))

Measured memory_bytes: 64476
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define maxn 55
#define pii pair<int,pair<int,int> > 
#define f first
#define s second
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  int no_of_vertex,no_of_edge,currsilver;
  int input1,input2,input3,input4;
  int dist[55][11000];
  for(int i=0;i<55;i++){
    for(int j=0;j<11000;j++){
      dist[i][j] = INT_MAX;
    }
  }
  priority_queue<pii,vector<pii>,greater<pii> > q1;
  vector<vector<pii> > adj(maxn);
  cin >> no_of_vertex >> no_of_edge >> currsilver;
  currsilver = min(currsilver,(int)10999);
  for(int i=0;i<no_of_edge;i++){
    cin >> input1 >> input2 >> input3 >> input4;
    adj[input1].push_back({input2,{input3,input4}});
    adj[input2].push_back({input1,{input3,input4}});
  }
  vector<pair<int,int> > change(maxn);
  for(int i=1;i<=no_of_vertex;i++){
    cin >> change[i].first >> change[i].second;
  }
  for(int i=1;i<=no_of_vertex;i++){
    adj[i].push_back({i,{0,0}});
  }
  dist[1][currsilver] = 0;
  q1.push({0,{1,currsilver}});
  while(q1.size()!=0){
    pii a = q1.top();
    q1.pop();
    //cout << a.f << " " << a.s.f << " " << a.s.s << endl;
    if(dist[a.s.f][a.s.s]!=a.f){
      continue;
    }
    {
      int add = change[a.s.f].first;
      int time = change[a.s.f].second;
      for(auto k:adj[a.s.f]){
        if(add+a.s.s>=k.s.f&&add+a.s.s-k.s.f<11000){
          if(dist[k.f][add+a.s.s-k.s.f]>time+a.first+k.s.s){
            dist[k.f][add+a.s.s-k.s.f] = time+a.first+k.s.s;
            q1.push({dist[k.f][add+a.s.s-k.s.f],{k.f,add+a.s.s-k.s.f}});
          }
        }
      }
    }
    {
      int add = 0;
      int time = 0;
      for(auto k:adj[a.s.f]){
        if(add+a.s.s>=k.s.f){
          if(dist[k.f][add+a.s.s-k.s.f]>time+a.first+k.s.s){
            dist[k.f][add+a.s.s-k.s.f] = time+a.first+k.s.s;
            q1.push({dist[k.f][add+a.s.s-k.s.f],{k.f,add+a.s.s-k.s.f}});
          }
        }
      }
    }

  }
  vector<int> mini(maxn,INT_MAX);
  for(int i=2;i<=no_of_vertex;i++){
    for(int j=0;j<11000;j++){
      mini[i] = min(mini[i],dist[i][j]);
    }
  }
  for(int i=2;i<=no_of_vertex;i++){
    cout << mini[i] << "\n";
  }
}

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

int main(){
    
    int N;
    cin >> N;
    
    if(N%2 == 0.0){
        cout << 0.5000000000 << endl;
    }
    else{
        double ans = (N/2+1)/(double)N;
        cout << setprecision(10) << ans << endl;
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a[110000], b[110000], n, h, res, k;
int main(void){
    // Your code here!
    cin >> n >> h;
    for (ll i = 0; i < n; i++) cin >> a[i] >> b[i];
    sort(a, a + n);
    sort(b, b + n);
    for (ll i = 0; i < n; i++) {
        if (b[i] >= a[n - 1]) {
            k = i;
            break;
        }
    }
    for (ll i = n - 1; i >= k; i--) {
        h -= b[i];
        res++;
        if (h <= 0) {
            cout << res << endl;
            return 0;
        }
    }
    cout << res + (h - 1) / a[n - 1] + 1 << endl;
}


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

ll inf=9223372036854775806;

int gcd(int a,int b){
	while (a!=0&&b!=0){if (a>b){a%=b;}else{b%=a;}}
	return a+b;
}

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int i,j,k,a[100001],b[100000],n,ans;
	cin>>n;
	for (i=0;i<n+1;i++){
		cin>>a[i];
	}
	sort(a,a+n+1);
	for (i=0;i<n;i++){
		b[i]=a[i+1]-a[i];
	}
	ans=gcd(b[0],b[1]);
	for (i=2;i<n;i++){
		ans=gcd(ans,b[i]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
/*
  AOJ 0525
  Title:Osenbei
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

#define max(x,y) (((x)>(y))?(x):(y))

int R,C;
int senbei[10][10000];
int senbei2[10][10000];


main()
{
  int i,j,k,i2,ret,s,sum;
  while(scanf("%d %d",&R,&C)  && (R||C))
    {
      for(i=0;i<R;i++)
	for(j=0;j<C;j++)
	  scanf("%d",&senbei[i][j]);

      for(i=ret=0;i<(1<<R);i++)
	{
	  memcpy(senbei2,senbei,sizeof(senbei));
	  i2=i;
	  for(j=0;j<R;i2>>=1,j++)
	    {
	      if(i2 & 1)
		for(k=0;k<C;k++)
		  senbei2[j][k] ^=1;
	      
	    }
	  sum=0;
	  for(j=0;j<C;j++)
	    {
	      for(s=k=0;k<R;k++)
		s+=senbei2[k][j];
	      if(s<(R+1)/2)
		s = R-s;
	      sum+=s;
	    }
	  ret=max(ret,sum);
	}
      printf("%d\n",ret);
    }
  return(0);
}

Measured memory_bytes: 1388