akhauriyash/Code-Regression huggingface dataset:
n, m = gets.rstrip.split.map(&:to_i)
lrs = m.times.map{ gets.rstrip.split.map(&:to_i) }

ans = ('1' * n).to_i
lr = lrs.shift
l1 = lr[0]
r1 = lr[1]
lrs.each do | lr |
  l2, r2 = lr[0], lr[1]

  # 1 l1---r1
  # 2       l2----r2
  if r1 < l2
    p 0
    exit
  end

  # 1       l1----r1
  # 2 l2---r2
  if l1 > r2
    p 0
    exit
  end

  # 1 l1-----r1
  # 2 l2-----r2
  if l1 == l2 and r1 == r2
    next
  end

  # 1 l1------r1
  # 2     l2-----r2
  if l1 <= l2 and r1 >= l2 and r1 <= r2 and  r1 >= l2
    l1 = l2
    next
  end

  # 1   l1------r1
  # 2 l2-----r2
  if l1 >= l2 and l1 <= r2 and r1 >= r2 and  r2 >= l1
    r1 = r2
    next
  end

  # 1 l1--------r1
  # 2   l2---r2
  if l1 <= l2 and r1 >= r2
    l1 = l2
    r1 = r2
    next
  end

  # 1   l1---r1
  # 2 l2--------r2
  if l2 <= l1 and r2 >= r1
    next
  end
end

p (r1 - l1) + 1


Measured memory_bytes: 10156
/**
  * author : thegeniushead
**/
#include <bits/stdc++.h>
 
/*.....DEFINITIONS...... */
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define T() int tt; cin>>tt; while(tt--)
#define rep(i,start,lim) for(int i=start;i<lim;i++)
#define rep1(i,start,lim) for(int i=start; i<=lim; ++i)
#define repd(i,start,lim) for(int i=start;i>=lim;i--)
#define mp make_pair
#define pb push_back
#define lchild (2*node+1)
#define rchild (2*node+2)
#define ff first
#define ss second
#define br cout<<"\n"
#define MOD (1000000007LL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define eps (1e-6)
#define what_is(x) cerr << #x << " is " << x << "\n";
#define int long long int
#define infll 9e18
#define inf 1e12

using namespace std;
 
/*.....TYPEDEFS ....*/
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef long double ld;
 
/*....USEFUL FUNCTIONS....*/
ll pwr(ll base, ll exp, ll mod=MOD){ll res=1; while(exp>0){if(exp%2){res=(res*base)%mod;}base=(base*base)%mod;exp/=2;}return res;}
ll gcd(ll a, ll b){ if(b==0)return a; else gcd(b, a%b);}
bool isPrime(ll n){if(n<=1)return false;if(n<=3)return true;if (n%2==0||n%3==0)return false;for(int i=5; i*i<=n; i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
 
/*....I/O Functions...*/
inline string rs(){char x[1234567];scanf("%s", x);string s = x; return s;}
inline int ri(){int x; scanf("%d", &x);return x;}
inline long long rl(){long long x; scanf("%lld", &x); return x;}
 
/*---------Solution below this line --------*/
 
const int N = 1234567;

string s, t;
vector<int> v;

bool valid(string temp){
	if(temp.length() != t.length()) return false;	
	if(temp.compare(t) == 0)return true;
		
	rep(i,0,t.length()){
		if(temp[i] != '?' and temp[i]!=t[i])return false;
	}
	return true;
}

void print(int idx){
	int x = t.length();
	int j = 0;
	rep(i,0,s.length()){
		if(i >= idx and i < x + idx){
			s[i] = t[j];
			++j;
		}
		else if(s[i] == '?') s[i] = 'a';
	}
	
	cout << s << '\n';
	
}

int32_t main()
{
	FIO
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	cin >> s >> t;
	
	rep(i,0,s.length()){
		string temp = s.substr(i,(int)t.length());
		//cout << temp << '\n';
		if(valid(temp)){
			v.pb(i);
		}
	}
	
	sort(all(v));
	
	if(!v.empty()){
		int idx = v.back();
		print(idx);
	}
	else
		cout << "UNRESTORABLE\n";
	
	

	return 0;
}

Measured memory_bytes: 256
def Kaibun(s):
    imax = int(len(s)/2)
    i = 0
    while i < imax:
        if s[i] != s[-(1+i)]:
            return False
        i += 1
    return True
    
a,b = map(int,input().split(' '))
List = [str(i) for i in range(a,b+1)]
count = 0
for s in List:
    if Kaibun(s):
        count += 1
print(count)

Measured memory_bytes: 8728
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define N 666
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
int n,m,a[N][N],del[N],go[N],num[N];
inline int check(int k)
{	queue<int> q; int gg=0;
	for(rint i=1;i<=m;i++) num[i]=0;
	for(rint i=1;i<=n;i++) num[a[i][1]]++,go[i]=1;
	for(rint i=1;i<=m;i++) if(num[i]>k) q.push(i),del[i]=1,++gg; else del[i]=0;
	if(gg==m) return 0;
	while(!q.empty())
	{	int x=q.front(); q.pop();// debug(x);
		for(rint i=1;i<=n;i++)
		if(a[i][go[i]]==x)
		{	for(++go[i];del[a[i][go[i]]];go[i]++);
			num[a[i][go[i]]]++;// debug(a[i][go[i]]);
			if(num[a[i][go[i]]]>k)
			{	++gg;del[a[i][go[i]]]=1,q.push(a[i][go[i]]);
				if(gg==m) return 0;
			}
		}
	}
	return 1;
}
int main()
{	cin>>n>>m;
	for(rint i=1;i<=n;i++)
	for(rint j=1;j<=m;j++) scanf("%d",&a[i][j]);
	int l=1,r=n,ans=-1;
	while(l<=r)
	{	int mid=(l+r)>>1;// debug(mid);
		if(check(mid)) ans=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define nl '\n' 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
ll m=1000000007;
int main()
{
	fast;
	int n;cin>>n;
	ll a[n];
	ll total=0;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=1;i<n;i++)
	{
		if(a[i-1]>a[i])
		{
			total+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	cout<<total;
}

Measured memory_bytes: 5172
/**

つのデータがどれだけ似ているかを、それらの距離で測る手法は、クラスタリングや分類など、様々なところで使われています。
ここでは、２つの n  次元ベクトル x={x 1 ,x 2 ,...,x n }  と y={y 1 ,y 2 ,...,y n }  の距離を計算してみましょう。

このようなデータの距離を測る指標のひとつとして、次のミンコフスキー距離が知られています。

D xy =(? i=1 n |x i −y i | p ) 1p

p=1  のとき

D xy =|x 1 −y 1 |+|x 2 −y 2 |+...+|x n −y n |

となり、これはマンハッタン距離とよばれます。

p=2  のとき

D xy =  √(|x 1 −y 1 |) 2 +(|x 2 −y 2 |) 2 +...+(|x n −y n |) 2

となり、これは一般的に使われるユークリッド距離になります。

p=∞  のとき


D xy =max n i=1 (|x i −y i |)


となり、これはチェビシェフ距離と呼ばれます。

２つの n  次元ベクトルが与えられるので、p  がそれぞれ 1、2、3、∞  のミンコフスキー距離を求めるプログラムを作成してください。


 */

//スキャナつかうため

import java.util.Scanner;

public class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成

		Scanner sc = new Scanner(System.in);

		// 整数を１受け取る
		int intN = sc.nextInt();
		// 受け取った数字の数の配列X,Yをつくる。
		int[] X = new int[intN];
		int[] Y = new int[intN];
		// intNの数だけ数字を配列Xに入れる
		for (int i = 0; i < intN; i++) {
			X[i] = sc.nextInt();
		}
		// intYの数だけ数字を配列Xに入れる
		for (int j = 0; j < intN; j++) {
			Y[j] = sc.nextInt();
		}
		// 計算結果を入れる変数を作成
		double dbP1 = 0;
		double dbP2 = 0;
		double dbP3 = 0;
		double dbPoo = 0;
		//intNの回数処理を繰り返す
		for (int i = 0; i < intN; i++) {
			//計算式
			dbP1 += Math.abs(X[i] - Y[i]);
			dbP2 += Math.pow(Math.abs(X[i] - Y[i]), 2);
			dbP3 += Math.pow(Math.abs(X[i] - Y[i]), 3);
			if (dbPoo < Math.abs(X[i] - Y[i])) {
				dbPoo = Math.abs(X[i] - Y[i]);
			}
		}
		//繰り返さない計算
		dbP2 = Math.pow(dbP2, 1.0 / 2.0);
		dbP3 = Math.pow(dbP3, 1.0 / 3.0);
		
		//結果表示
		System.out.println(dbP1);
		System.out.println(dbP2);
		System.out.println(dbP3);
		System.out.println(dbPoo);
	}
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B == C + D){
   	cout << "Balanced";
    }
  else if(A + B > C + D){
    cout << "Left";
  }
  else{
    cout << "Right";
  }
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,a,b = [int(i) for i in readline().split()]
x = [int(i) for i in readline().split()]

walk = [xj-xi for xi,xj in zip(x,x[1:]) if a*(xj-xi) < b]

w = sum(walk)*a
t = (n-1-len(walk))*b

print(t+w)


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

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

vector<vector<int>> G;
int dp[100010];

int rec(int v){
  if(dp[v]!=-1) return dp[v];
  int res=0;
  for(auto nv:G[v]){
    chmax(res,rec(nv)+1);
  }
  return dp[v] = res;
}

int main(){
  int n,m;
  cin >> n >> m;
  G.assign(n, vector<int>());
  vector<int> x(m),y(m);
  rep(i,m){
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
    G[x[i]].push_back(y[i]);
  }
  rep(i,n) dp[i]=-1;
  int res=0;
  rep(i,n) chmax(res,rec(i));
  cout << res << endl;
  return 0;

}


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

using namespace std;

int main(){
	int a, b;
  	cin >> a >> b;
  	for( int i=1; i<=100*a; i++){
    	int v1 = 8*i/100;
      	int v2 = 10*i/100;
      	if(v1==a && v2==b){
        	cout << i << "\n";
          	return 0;
        }
    }
  	cout << -1;
  
  	return 0;
}

Measured memory_bytes: 256
S=input()

ans = [0]*len(S)

R_begin = 0
R_end   = 0
L_begin = 0
L_end   = 0

# count 'R'
while R_begin < len(S):
    while S[R_end+1]=='R':
        R_end += 1
    #print(R_begin, R_end)
    # count 'L'
    L_begin = R_end + 1
    L_end   = R_end + 1
    if L_end == len(S)-1:
        pass
    else:
        while S[L_end+1]=='L':
            L_end += 1
            if L_end == len(S)-1:
                break
    #print(L_begin, L_end)

    R_count = R_end - R_begin + 1
    L_count = L_end - L_begin + 1

    if R_count >= L_count:
        if R_count % 2 == 1:
            ans[R_end]   = (R_count+L_count)//2 + (R_count-L_count)%2
            ans[L_begin] = (R_count+L_count)//2
        else:
            ans[R_end]   = (R_count+L_count)//2
            ans[L_begin] = (R_count+L_count)//2 + (R_count-L_count)%2
    else:
        if L_count % 2 == 1:
            ans[R_end]   = (R_count+L_count)//2
            ans[L_begin] = (R_count+L_count)//2 + (L_count-R_count)%2
        else:
            ans[R_end]   = (R_count+L_count)//2 + (L_count-R_count)%2
            ans[L_begin] = (R_count+L_count)//2
    #print(ans)

    R_begin = L_end + 1
    R_end   = L_end + 1

    #print(R_begin, R_end)
#print(ans)
for ii in range( len(ans) ):
    if ii==len(ans)-1:
        print(ans[ii])
    else:
        print('%s ' % ans[ii], end='')


Measured memory_bytes: 5108
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int[] a = new int[5];
        int ans = 0;
        for(int i = 0; i < 5; i++){
            a[i]=sc.nextInt();
            if(a[i]==0) {
                ans = i+1;
            }
        }
        System.out.println(ans);

    }
}

Measured memory_bytes: 26916
import math

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())))[::-1]


def is_ok(x):
    cnt = 0
    for i in range(N):
        if A[i]*F[i] > x:
            cnt += A[i] - math.floor(x / F[i])
    return cnt <= K


def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok


ans = meguru_bisect(-1, max([a * f for a, f in zip(A, F)]))
print(ans)


Measured memory_bytes: 126296
def main():
    N, A, B = map(int, input().split())
    ans = 0

    if A > B:
        ans = 0
    else:
        if N == 1:
            if A != B:
                ans = 0
            else:
                ans = 1
        elif N == 2:
            ans = 1
        else:
            ans = (B - A)*(N - 2) + 1

    print(ans)
    
if __name__ == "__main__":
    main()

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

int main()
{
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  for (int i = 0; i < N; ++i)
    cin >> S[i];
  sort(S.begin(), S.end());
  for (int i = 0; i < N; ++i)
    cout << S[i];
  return 0;
}


Measured memory_bytes: 256
//Solution for aoj:0537 Bingo
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const int surplus = 100000;
int N, ans;
int b[2][2001][3001];
int main(){
	int n, m, s;
	while (cin >> n >> m >> s){
		if (!n&&!m&&!s)
			return 0;
		ans = 0;
		N = n*n;
		FOR(i, 1, m + 1)
			b[0][i][i] = 1;
		for (int i = 2; i < N + 1; i++){
			for (int j = 1; j < m; j++){
				for (int k = j; k < s; k++){
					b[1][j + 1][k + 1] = b[1][j][k] + b[0][j][k - j];
					b[1][j + 1][k + 1] %= surplus;
					if (i == N&&k + 1 == s){
						ans += b[1][j + 1][k + 1];
					}
				}
			}
			FOR(j, 1, m){
				FOR(k, 1, s){
					b[0][j][k] = b[1][j][k];
					if (i == N)
						b[0][j][k] = 0;
				}
			}
		}
		cout << ans%surplus << endl;
	}
}

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

class dice{
    public:
    int d[7];

    dice(){ //??????????????????????????????
    	
    }

    void east(){
    	d[0]=d[1],d[1]=d[4],d[4]=d[6],d[6]=d[3],d[3]=d[0];
    }

    void north(){
    	d[0]=d[5],d[5]=d[1],d[1]=d[2],d[2]=d[6],d[6]=d[0];
    }

    void turn(){
        d[0]=d[2],d[2]=d[4],d[4]=d[5],d[5]=d[3],d[3]=d[0];    
    }

};

bool check16(dice D1, dice D2){
    for(int i=1; i<7; i++){
        if( D1.d[i] != D2.d[i])return false;
    }
    return true;
}

bool check(dice D1, dice D2){
    for(int i=1; i<7; i++){
        for(int j=0; j<4; j++){
            if(check16(D1, D2))return true; 
            D2.turn();
        }           
        
        if(i%2==1)D2.east();
        else D2.north();
    }

    return false;
}

int main(){
    dice D[100];
    int n=0;
    cin >> n;
    for(int j=0; j<n; j++){
        for(int i=1; i<7; i++)cin >> D[j].d[i];
    }

    for(int i=0; i<n-1; i++){
        for(int j=1;i+j<n; j++){
            if(check(D[i],D[i+j])){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}

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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

int main() {
  int a, b;
  int ans;
  
  cin >> a >> b;
  
  if(a >= 1 && a <= 9 && b >= 1 && b <= 9) ans = a * b;
  else ans = -1;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>

using namespace std;
int a[1000000]={0};
int k,sum=0;
int main() {
   int n;
   cin>>n;
   for(int i=0;i<n;i++)
   {
   	cin>>k;
   	if(k<1000000)
   	a[k]++;
   	else sum++;
   }
   for(int i=0;i<1000000;i++)
   if(a[i]>i)
   {
   	sum+=a[i]-i;
   }
   else if(a[i]<i)
   {
   	sum+=a[i];
   }
   
   cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
#define pi pair<ll,ll>
#define vi vector<ll>
#define vii vector<pi>
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showvector1(vector <T> v)
{
    ll n=v.size();
    fo1(i,n-1)
        cout<<v[i]<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{   if(x<=1)
     return false;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
/// check for test case before submitting
void vfun()
{
    ll n,k;
    cin>>n;
    vector <ll> v(n);
    fo(i,n)
    cin>>v[i];

}

int main()
{
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
    //cin>>test;
    while(test--)
    {

            ll n,m,ans=0;;
            cin>>n>>m;
            if(m<2*n)
                ans=m/2;
            else
                ans=n+(m-2*n)/4;
            cout<<ans<<endl;
//         if(vfun())
//            cout<<"YES\n";
//         else
//            cout<<"NO\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not





Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int count=0;
    cin>>s;
    for(int i=0;i<s.size()/2;i++){
        if(s[i]!=s[s.size()-1-i])count++;
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endlvd;
struct edge{int to,cost;};
typedef pair<int,int> P;
int dh[4]={0,1,0,-1},dw[4]={1,0,-1,0},mp[30][30],h,w,c[4],d[124*31],inf=1e8;
void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> > que;
	rep(i,124*31) d[i]=inf;
	d[s]=0;
	que.push(P(0,s));
	while(!que.empty()){
		P p=que.top();
		que.pop();
		int v=p.sc;
		int vh=v/124,vw=v%124/4,vd=v%4;
		if(d[v]<p.fs) continue;
		if(mp[vh][vw]!=4){
			int dd=mp[vh][vw];
			int nd=(vd+dd)%4,nh=vh+dh[nd],nw=vw+dw[nd];
			if(0<=nh && nh<h && 0<=nw && nw<w){
				int to=nh*124+nw*4+nd;
				if(d[to]>d[v]){
					d[to]=d[v];
					que.push(P(d[to],to));
				}
			}
		}
		rep(i,4){
			int dd=i;
			int nd=(vd+dd)%4,nh=vh+dh[nd],nw=vw+dw[nd];
			if(0<=nh && nh<h && 0<=nw && nw<w){
				int to=nh*124+nw*4+nd;
				if(d[to]>d[v]+c[dd]){
					d[to]=d[v]+c[dd];
					que.push(P(d[to],to));
				}
			}
		}
	}
}
int main(){
	while(true){
		cin >> w>>h;
		if(w==0) break;
		rep(i,h) rep(j,w) cin >> mp[i][j];
		rep(i,4) cin >> c[i];
		dijkstra(0);
		int ans=inf;
		rep(i,4) ans=min(ans,d[(h-1)*124+(w-1)*4+i]);
		cout << ans << endl;
	}
}

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

int main(){
 vector<int> vec(5);
 for(int i=0;i<5;i++){
   cin >> vec.at(i);
 }
 int j=0;
 while(vec.at(j)!=0){
   j++;
 }
cout << j+1 << endl;
}


Measured memory_bytes: 3516
#include <stdio.h>

int main(void)
{
    int done[32] = {0};
    int n;
    int i;

    for (i = 0; i < 28; i++){
        scanf("%d", &n);
        done[n] = 1;
    }

    for (i = 1; i <= 30; i++){
        if (done[i] == 0){
            printf("%d\n", i);
        }
    }

    return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	ll N;
	cin >> N;
	ll ans = inf;
	for(ll A = 1; A <= sqrt(N); A++) {
		if(N % A == 0) {
			ll B = N / A;
			ll tmp = max(A, B);
			ll cnt = 0;
			while(tmp) {
				cnt++;
				tmp /= 10;
			}
			ans = min(ans, cnt);
		}
	}
	cout << ans << "\n";
	return 0;
}


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

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        a_list: [usize; n]
    }
    let ans: usize = a_list.iter().map(|&a| {
        let mut count = 0;
        let mut b = a;
        while b % 2 == 0 {
            b = b / 2;
            count += 1;
        };
        count
    }).min().unwrap();
    println!("{}", ans);
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

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

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n;
  cin >> n;
  string s;
  cin >> s;
  vi a(n);
  rep(i,0,n) {
    if (s[i] == 'G') a[i] = 1;
    if (s[i] == 'B') a[i] = 2;
  }
  vvi occ(3, vi(n));
  occ[a[0]][0] = 1;
  rep(i,1,n) {
    occ[0][i] = occ[0][i-1];
    occ[1][i] = occ[1][i-1];
    occ[2][i] = occ[2][i-1];
    ++occ[a[i]][i];
  }

  auto other = [&](int a,  int b) {
    if (b<a) swap(a,b);
    if (a==0 and b==1) return 2;
    if (a==0 and b==2) return 1;
    return 0;
  };

  ll ans = 0;
  rep(i,0,n-2) {
    rep(j,i+1,n-1) {
      if (a[i] == a[j]) continue;
      ans += occ[other(a[i],a[j])][n-1]- occ[other(a[i],a[j])][j];
      int idx = j+(j-i);
      if (idx<n and a[idx]==other(a[i],a[j])) --ans;
    }
  }

  cout << ans << '\n';

}

Measured memory_bytes: 3704
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main(){
  long long  a,b,f=0,g=0;cin>>a;
  map<long long ,long long >c;
  rep(i,a){
    cin>>b;
    b*=-1;
    if(c.count(b))c[b]++;
    else c[b]=1;
  }
  auto d=c.end(),e=c.begin();
  for(auto i=e;i!=d;i++){
    if(i->second>1&&f==0){
      f=i->first;
      c[i->first]-=2;
      }
      if(i->second>1&&f!=0&&g==0)g=i->first;
      if(f!=0&&g!=0)break;
  }
  cout<<f*g;
  }


Measured memory_bytes: 6528
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

string s;

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

  ll ans = 0;
  ll a_num = 0;
  ll b_num = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      if (b_num > 0) {
        a_num = 1;
        b_num = 0;
      } else {
        a_num++;
      }
    } else if (s[i] == 'B' && a_num > 0 && b_num == 0) {
      b_num++;
    } else if (s[i] == 'C' && a_num > 0 && b_num > 0) {
      ans += a_num;
      b_num = 0;
    } else {
      a_num = 0;
      b_num = 0;
    }
  }

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

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

int main(){
  int N, K, X, Y;
  cin >> N;
  cin >> K;
  cin >> X;
  cin >> Y;
  int sum;
  if (N>=K){
    sum = K*X+(N-K)*Y;
  }
  else {
    sum = N*X;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <unordered_map>
#include <cmath>
int main() {
	int n, q;
	std::cin >> n >> q;
	
	std::unordered_map<int, int> parent_map;
	for (int i = 0; i < n - 1; i++)
	{
		int parent, child;
		std::cin >> parent >> child;
		parent_map.emplace(child, parent);
	}

	std::unordered_map<int, int> counter_map;
	for (int i = 0; i < q; i++)
	{
		int point, value;
		std::cin >> point >> value;
		counter_map[point] = value + counter_map[point];
	}

	std::vector<int> result;
	std::string ans;
	for (int i = 1; i < n + 1; i++)
	{
		int parent_value = i == 1 ? 0 : result[parent_map[i] -1];
		int res = parent_value + counter_map[i];
		ans += std::to_string(res);
        if (i < n) {
            ans += " ";
        }
		result.push_back(res);
	}
	std::cout << ans << "\n";
}

Measured memory_bytes: 22472
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

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

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int ans;
  for (int i = 1; i <= 5; i++) {
    int a; cin >> a;
    if (a == 0) ans = i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;





int main() {
    int N, X, T;
    cin>>N>>X>>T;
    int s = 0;
    while(N > 0){
        N -= X;
        s += T;
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 3604
r()=chomp(readline())

pInt(r)=parse(Int,r)
S=r()
Q=pInt(r())
Qi=Array(String,Q)
#Qi=Array{String}(undef,Q)
for i in 1:Q
    Qi[i]=r()
end

function chS(Q,Qii,S)
    #S_head,S_foot=Array{UInt8}(undef,Q),Array{UInt8}(undef,Q)
    S_head,S_foot=Array(UInt8,Q),Array(UInt8,Q)
    n_head,n_foot=0,0
    rev=false
    for i in 1:Q
        Qi=split(Qii[i]," ")
        if pInt(Qi[1])==1
            rev=!rev
        else
            if (pInt(Qi[2])==1 && !rev) || (pInt(Qi[2])==2 && rev)
                n_head+=1
                S_head[n_head]=(Qi[3][1])
            else
                n_foot+=1
                S_foot[n_foot]=(Qi[3][1])
            end
        end
    end
    #S=reverse(S_head[1:n_head])*S*S_foot[1:n_head]
    #rev && ( S=reverse(S) )
    #S
    rev,Char.(reverse(S_head[1:n_head])),Char.(S_foot[1:n_foot])
end
rev,S_head,S_foot=chS(Q,Qi,S)
if !rev
    print.(S_head)
    print(S)
    print.(S_foot)
else
    print.(reverse(S_foot))
    print(reverse(S))
    print.(reverse(S_head))
end

Measured memory_bytes: 172672
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <vector>
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uit;
typedef double f2;
typedef long double f3;
#define N 100050
#define OUTSIZE 1050
#define rep(n) for(i=1;i<=n;i++)
#define per(n) for(i=n;i;i--)
namespace SA {
	int n,ws[OUTSIZE],wa[OUTSIZE],wb[OUTSIZE],rk[OUTSIZE],height[OUTSIZE],sa[OUTSIZE];
	char w[OUTSIZE];
	void build(int m) {
		int i,j,p,*x=wa,*y=wb;
		rep(m)ws[i]=0;
		rep(n)ws[x[i]=w[i]]++;
		rep(m)ws[i]+=ws[i-1];
		per(n)sa[ws[x[i]]--]=i;
		for(j=1;j<n;j<<=1) {
			for(p=0,i=n;i>n-j;i--) y[++p]=i;
			rep(n)if(sa[i]>j) y[++p]=sa[i]-j;
			rep(m)ws[i]=0;
			rep(n)ws[x[i]]++;
			rep(m)ws[i]+=ws[i-1];
			per(n)sa[ws[x[y[i]]]--]=y[i];
			swap(x,y);
			m=1;
			rep(n)x[sa[i]]=y[sa[i]+j]==y[sa[i+1]+j]&&y[sa[i]]==y[sa[i+1]]?m:m++;
			if(m>n) break;
		}
		rep(n)rk[sa[i]]=i; 
		p=0;
		rep(n)if(rk[i]!=n) {
			j=rk[i]+1;
			for(;w[i+p]==w[sa[j]+p];p++) ;
			height[rk[i]]=p;
			if(p) p--;
		}
	}
	void init() {
		n=6; w[1]='a'; w[2]='b'; w[3]='a'; w[4]='b'; w[5]='b'; w[6]='a';
		build(128);
	}
}
namespace Scape_Goat_Tree {
	#define ls ch[p][0]
	#define rs ch[p][0]
	int ch[OUTSIZE][2],val[OUTSIZE],siz[OUTSIZE],tot[OUTSIZE],ex[OUTSIZE],S[OUTSIZE],V[OUTSIZE],tp,koishi;
	int root,f[OUTSIZE],cnt;
	f2 AL=0.75;
	void pushup(int p) {
		siz[p]=siz[ls]+siz[rs]+ex[p];
		tot[p]=tot[ls]+tot[rs]+1;
	}
	int GG(int p) {
		return tot[p]*AL<max(tot[ls],tot[rs]);
	}
	int newnode(int v) {int p=++cnt; siz[p]=tot[p]=ex[p]=1; val[p]=v; return p;}
	void insert(int &p,int v,int fa) {
    	if(!p) {p=newnode(v); f[p]=fa; return ;}
    	insert(ch[p][v>val[p]],v,p);
    	pushup(p); if(GG(p)) koishi=p;
	}
	void init() {
		insert(root,1,0); insert(root,2,0); insert(root,3,0);
		insert(root,4,0); insert(root,5,0);
	}
	#undef ls
	#undef rs
}
#undef N
#define N 300050
int n,a[N],b[N],Q[N],l,r,mp[1050][1050];
ll ans;
int main() {

	scanf("%d",&n);
	int i,flg=0;
	for(i=1;i<=1000;i++) {
		if(i*(i+1)/2==n) {
			flg=1; break;
		}
	}
	if(!flg) {puts("No"); return 0;}
	int K=i+1,j;

	int cnt=0;
	for(i=1;i<K;i++) {
		for(j=1;j<=i;j++) {
			mp[j][i]=++cnt;
		}
	}

	cnt=0;
	for(i=2;i<=K;i++) {
		for(j=1;j<i;j++) {
			mp[i][j]=++cnt;
		}
	}

	puts("Yes");
	printf("%d\n",K);
	for(i=1;i<=K;i++) {
		printf("%d ",K-1);
		for(j=1;j<K;j++) printf("%d ",mp[i][j]); puts("");
	}
}

Measured memory_bytes: 3200
#include<cstdio>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
int main()
{
	ll n;
	scanf("%lld", &n);
	while (n--)
	{
		ll q, w;
		scanf("%lld %lld", &q, &w);
		if (q == 1 && w == 1)
		{
			puts("0");
			continue;
		}
		if (q < w)
			swap(q, w);
		ll dap = w - 1;
		ll ch = (q*w);
		ch = sqrt(ch);
		dap += (ch - 1);
		ll ri = (q*w-1)/ch;
		ll le = (q*w-1 )/(q-1);
		le = max(w + 1, le);
		if (ri >= le)
			dap += (ri - le+1);
		printf("%lld\n", dap);
	}
}

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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

ll a, b, c, d;

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

bool solve() {
    if(a < b) return false; // 最初に買えないので
    if(d < b) return false; // 追加が追いつかないゆえ
    if(c >= b - 1) return true;

    ll g = gcd(b, d);
    // できる整数は D*p - B*q + A -> A + g*x -> g で割って A%g 余る.
    // g で割って a%g あまる数で、c より大きく b 未満な整数を知りたい
    // g で割って a%g 余る数の b 未満の最大の数. A + (Gの倍数)
    ll Max = (b - a % g + g - 1) / g * g + a % g - g;
    Max = b + a % g - g;
    if(Max > c)
        return false;
    else
        return true;
}

int main() {
    ll n, m, i, j, k;
    ll T;
    cin >> T;
    for(ll t = 0; t < T; t++) {
        set<ll> st;
        st.insert(a);
        cin >> a >> b >> c >> d;
        if(solve())
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897932
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}
int main() {
  
  long long X,Y;
  cin>>X>>Y;
  
  long long i=1;
  
  long long sum=X;
  
  
  while(sum*2<=Y){
    i++;
    sum+=sum;
  }
  
  cout<<i<<endl;
}

Measured memory_bytes: 3584
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]

square = [i**2 for i in range(500)]
ans = 0
for i in range(N):
  for j in range(i):
    x = X[i]
    y = X[j]
    dist = 0
    for k in range(D):
      dist += (x[k] - y[k])**2
    if dist in square:
      ans += 1
      
print(ans)

Measured memory_bytes: 3064
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private void solve(Scanner sc) {
        long x = sc.nextLong();
 
        long cnt = (x + 10) / 11 * 2;
        if (cnt / 2 * 11 - 5 >= x) {
            --cnt;
        }
 
        _out.println(cnt);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<functional>
#include<limits.h>
#include<string.h>
#include<algorithm> 
#define int long long
#define mod 1000000007
using namespace std;

int p(int a, int b) {
	int c = 1;
	while (b > 1) {
		if (b & 1)c *= a;
		b >>= 1;
		a *= a;
		a %= mod;
		c %= mod;
	}
	return a*c%mod;
}
vector<int>V;
void saiki(int k) {
	for (int i = 2; i*i <= k; i++) {
		if (k%i == 0) {
			V.push_back(i);
			saiki(k / i);
			return;
		}
	}
	V.push_back(k);
}
signed main() {
	int n, m; cin >> n >> m;
	if (m == 1) { puts("1"); return 0; }
	saiki(m);
	int ans = 1;
	for (int i = 0; i < V.size(); i++) {
		for (int j = i; j < V.size(); j++) {
			if (j + 1 == V.size() || V[j + 1] != V[i]) {
				for (int k = j - i + n; k > n-1; k--) {
					ans *= k; ans %= mod;
				}
				for (int k = 1; k <= j - i + 1; k++) {
					ans *= p(k, mod - 2);
					ans %= mod;
				}
				i = j;
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
 
int main(){
  ll N,K;
  cin>>N>>K;
  ll ans=pow(N/K,3);
  if(K%2==0) ans+=pow((N/(K/2)+1)/2,3);
  cout<<ans<<endl;
}

Measured memory_bytes: 384
def main():
  n = int(input())
  a = input_list()
  ac = collections.Counter(a)
  f_list = {}
  f_sum = 0
  for k, c in ac.items():
    if c <= 1:
      f_list[k] = (c, 0)
    else:
      cc = combinations_count(c, 2)
      f_list[k] = (c, cc)
      f_sum += cc
  for i in a:
    t = f_list[i]
    tv = t[1] - (t[0] - 1)
    print(f_sum - t[1] + tv)
          
  
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
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

import math
import fractions
import collections
from functools import reduce
main()

Measured memory_bytes: 40748
import numpy as np

def resolve():
    n = int(input())
    h = np.array(list(map(int, input().split())))
    k = 2

    dp = np.zeros(n, dtype=int)

    for i in range(1, n):
        start = max(0, i - k)
        dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))

    print(dp[n - 1])

resolve()

Measured memory_bytes: 22832
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");
        String arr02[] = mylist.get(1).split(" ");
        int n = Integer.valueOf(arr01[0]);

        List<String> list01 = Arrays.asList(arr02);
        List<String> list02 = list01.stream().distinct().collect(Collectors.toList());

        System.out.println(list01.size() == list02.size() ? "YES" : "NO");

    }

}


Measured memory_bytes: 68776
#include<bits/stdc++.h>
//树链剖分 模板题 
using namespace std;
const int N=4e5+10;
struct node{//链式前向星 
	int next;
	int from;
	int to;
	int v;
}edge[N];
long long dep[N];//节点深度
int top[N];//当前链顶端节点编号
int son[N];//重儿子编号
int siz[N];//子树大小
int fa[N];//父亲节点编号
int id[N];//新编号
int w[N];
 
int cnt;//dfs_clock/dfs序 
int base,d[N],t,head[N],edge_num,vis[N];
void add(int x,int y,int z){
	edge[++edge_num].to=y;
	edge[edge_num].v=z;
	edge[edge_num].next=head[x];
	head[x]=edge_num;
}
long long sum=0;
#define il inline
il void dfs1(int x,int f){//x当前节点 f父亲 deep深度
	//标记每个点的深度 
	for(int i=head[x];i;i=edge[i].next){
		int y=edge[i].to;
		if(y==f)continue;//若为父亲则continue
		sum+=edge[i].v;
		dep[y]=sum;
		dfs1(y,x);//dfs其儿子 
		sum-=edge[i].v;
		siz[x]+=siz[y];//回溯累加儿子数加到它身上 
	} 	
}
int main(){
	int n;
	cin>>n;
	int v,u,z;
	for(int i=1;i<=n-1;++i){
		cin>>u>>v>>z;
		add(u,v,z);
		add(v,u,z);
	}
	int q,k;
	cin>>q>>k;
	dfs1(k,0);
	int l,r;
	while(q--){
		cin>>l>>r;
		cout<<dep[l]+dep[r]<<endl;
	}
	return 0;
} 


Measured memory_bytes: 14848
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;


const ll MOD=1e9+7;

ll powm(ll x,ll k){
    ll res=1;
    while(k){
        if(k&1) res=res*x%MOD;
        x=x*x%MOD;
        k>>=1;
    }
    return res;
}

ll modInv(ll x){
    return powm(x,MOD-2);
}
const int SIZE=1e6+2;
vector<ll> fact(SIZE);
vector<ll> invFact(SIZE);

ll comb(ll n,ll x){
    return fact[n]*invFact[x]%MOD*invFact[n-x]%MOD;
}

int main(){
    int x,y;
    cin>>x>>y;

    fact[0]=1;
    for(int i=1;i<SIZE;i++){
        fact[i]=fact[i-1]*i%MOD;
    }

    invFact[SIZE-1]=modInv(fact[SIZE-1]);
    for(int i=SIZE-1;i>0;i--){
        invFact[i-1]=invFact[i]*i%MOD;
    }

    ll res=0;
    for(int i=0;i<=1e6;i++){
        int tmpX=x-i;
        int tmpY=y-i;
        if(i==tmpX+tmpY && tmpX>=0 && tmpY>=0){
            res+=comb(i,tmpX);
            res%=MOD;
        }
    }
    cout<<res<<endl;
    
    return 0;
}


Measured memory_bytes: 16000
#include <iostream>
using namespace std;
 
void display(int A[], int n)
{
    for(int i = 1; i <= n; i++)
    {
        cout << A[i];
        if(i < n)
        {
            cout << " ";
        }
    }
    cout << endl;
}
 
int main(void)
{
    int N = 1000;
    int n;
    int A[N+1];
 
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> A[i];
    }
 
    for(int j = 1; j <= n; j++)
    {
        int v = A[j];
        int k = j-1;
        while(k >= 1 && A[k] > v)
        {
            A[k+1] = A[k];
            k--;
        }
        A[k+1] = v;
        display(A, n);
    }
 
//    display(A, n);
    return 0;
}

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

int main() {
	vector<int> num = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int K;
	cin >> K;
	cout << num[K - 1] << endl;
}

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

int main() {
  int s, w;
  cin >> s >> w;

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


Measured memory_bytes: 3636
import           Control.Monad
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [x, y, z] <- getIntList
  putStrLn $ show z ++ " " ++ show x ++ " " ++ show y

Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,t=0,r,c=0,a;
    cin>>n>>m;
    m=m+1;
    while(m>n)
    {
        a=n;

        while(n!=0)
        {
            r=n%10;
            t=r+t*10;
            n=n/10;
        }
        if(t==a)
        {
            c++;
            n=a+1;
            t=0;

        }
        else
        {

            n=a+1;
            t=0;

        }}
        cout<<c<<endl;
    }


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


signed main(){

    std::vector<int> v(3);

    for(int i = 0; i < 3; i++){
        std::cin >> v[i];
    }

    std::sort(v.begin(), v.end());

    std::cout << v[0] << " " << v[1] << " " << v[2] << std::endl;

    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[0]=='C')
    {
        cout<<"Rainy"<<endl;
    }
    else if(s[0]=='R')
    {
        cout<<"Sunny"<<endl;
    }
    else{
        cout<<"Cloudy"<<endl;
    }
    return 0;
}


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


using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	while (true) {
		int n, mi, ma; cin >> n >> mi >> ma;
		

		if (n == 0 && mi == 0 && ma == 0)return 0;

		mi--; ma--; 

		vector<int> a(n);

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

		int diff = 0;
		int ans = -1;
		int index = 0;
		for (int i = mi; i <=ma; i++) {
			diff = abs(a[i] - a[i + 1]);

			if (ans <= diff) {
				ans = diff;
				index = i;
			}
		}

		cout << ++index << endl;
	}

	return 0;
}


Measured memory_bytes: 3060
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<climits>
using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  int h[N+1];
  for(int i = 1; i <= N; i++) cin >> h[i];
  int c[N+1];
  c[1] = 0;
//  c[2] = c[1] + abs(h[2] - h[1]);
  for(int i = 2; i <= N; i++){
        c[i] = INT_MAX;
        for(int j = 1; j <= K && i - j > 0; j++){
                c[i] = min(c[i],c[i-j] + abs(h[i-j] - h[i]));
        }
  }
  cout << c[N] << endl;
  return 0;
}

Measured memory_bytes: 1024
n, m = map(int, input().split())
card=[0 for _ in range(n)]
l, r = map(int, input().split())
l-=1
for i in range(m-1):
    li, ri = map(int, input().split())
    li-=1
    if li>r or ri<l:
        l=r
        break
    elif li>=l and ri<=r:
        l=li; r=ri
    elif li<=l and ri>=r:
        pass
    elif li<=r and ri>=r:
        l=li
    elif ri>=l and li<=l:
        r=ri
    else:
        pass
print(r-l)


Measured memory_bytes: 3888