akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
string s;
cin>>s;

bool m1=false, m2=false;
//YYMM

if((s[0]=='0' && (s[1]>='1' && s[1]<='9'))|| 
    (s[0]=='1' && (s[1]=='1' || s[1]=='2')))
{
    m1=true;
}
    
if((s[2]=='0' && (s[3]>='1' && s[3]<='9'))|| 
    (s[2]=='1' && (s[3]=='1' || s[3]=='2'))){
    m2= true;
}
    

if(m1 && m2){
    cout<<"AMBIGUOUS";
}
else if(m1 || m2){
    if(m1){
        cout<<"MMYY";
    }else{
        cout<<"YYMM";
    }
}else{
    cout<<"NA";
}

    
    
}

    



Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int n,m,a[41][101];
//bool f[41][41];
int maxx;
void dfs(int x,int y,int sum)
{
    if(x<1||x>2||y<1||y>n) return;
    if(x==2&&y==n) maxx=max(maxx,sum);
    if(x<2) dfs(x+1,y,sum+a[x+1][y]);
    dfs(x,y+1,sum+a[x][y+1]);
}
int main()
{
	//ios::sync_with_stdio(false);
	int i,j;
	cin>>n;
	for(i=1;i<=2;i++)
	{
		for(j=1;j<=n;j++)
		{
			cin>>a[i][j];
		}
	}
	dfs(1,1,a[1][1]);
	cout<<maxx;
    //system("pause");
	return 0;
}

Measured memory_bytes: 256
import copy
n = int(input())
p = input().split()
for i in range(len(p)):
    p[i] = int(p[i])
l = copy.deepcopy(p)
l.sort()
k = 0
for i in range(len(l)):
    if l[i]!=p[i]:
        k+=1
if k==2or k==0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3572
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

struct /* ow the */ edge {
	int v;
	long long mult,rem;
	edge() {}
	edge(long long mult, int v, long long rem): v(v), mult(mult), rem(rem) {}
	};

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N,Q;
	cin >> N >> Q;
	vector<long long> L(Q+1);
	vector< vector<edge> > E(Q+1);
	vector< vector<long long> > RMQ(17,vector<long long>(Q+1,2e18));
	L[0] =RMQ[0][0] =N;
	for(int q =0; q < Q; q++) {
		long long x;
		cin >> x;
		L[q+1] =RMQ[0][q+1] =x;
		int cur =q+1;
		for(int i =1; i < 17; i++) if(q+2 >= (1<<i)) RMQ[i][q+1] =min(RMQ[i-1][q+1],RMQ[i-1][q+1-(1<<(i-1))]);
		while(x > 0) {
			int nxt =cur-1;
			for(int k =16; k >= 0; k--) if((1<<k) <= nxt+1 && RMQ[k][nxt] > x) nxt -=(1<<k);
/*			for(int i =cur-1; i >= 0; i--) if(L[i] < x) {
				nxt =i;
				break;}
*/			
//			cout << x/L[nxt] << ".\n";
			if(nxt == -1) {
				E[q+1].push_back(edge(1,0,x));
				break;}
			E[q+1].push_back(edge(x/L[nxt],nxt,-1));
			x =x%L[nxt];
			cur =nxt;}
		}
	vector<long long> ans(N+1,0),mult(Q+1,0);
	mult[Q] =1;
	for(int q =Q; q > 0; q--) 
		ALL_THE(E[q],it) {
			if(it->rem == -1) mult[it->v] +=mult[q]*(it->mult);
			else ans[it->rem] +=mult[q];}
	ans[N] +=mult[0];
	for(int i =N; i >= 1; i--) ans[i-1] +=ans[i];
	for(int i =1; i <= N; i++) cout << ans[i] << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 43504
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using static System.Math;

class P
{
    static void Main()
    {
        (string.Join("", Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x)) == "1479" ? "YES" : "NO").WriteLine();
    }
}


static class Writer
{
    public static void WriteLine<T>(this T item) => Console.WriteLine(item);

    public static void WriteLog<T>(this T item) => Debug.WriteLine(item);
}

Measured memory_bytes: 13396
#include<cstdio>
long long a[200005];

int main(){
    int n;
    scanf("%d",&n);
    long long Xor = 0;
    for(int i = 1; i <= n; i++){
        scanf("%lld",&a[i]);
        Xor ^= a[i];
    }
    for(int i = 1; i <= n; i++) printf("%lld ",Xor^a[i]);
    return 0;
}


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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

ll A, B, C, D;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

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

  cin >> A >> B >> C >> D;
  while(A > 0 || C > 0) {
    C-=B;
    if (C <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
    A-=D;
    if (A <= 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  return 0;
}


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

int main(){
    int n,m,c;
    cin >> n >> m >> c;
    vector<int> l(c);
    for(int i=0; i<c; i++){
        cin >> l[i];
    }
    vector<vector<int> > w(c);
    for(int i=0; i<n; i++){
        int color,weight;
        cin >> color >> weight;
        color--;
        w[color].push_back(weight);
    }
    vector<int> ball;
    for(int i=0; i<c; i++){
        sort(w[i].begin(), w[i].end(), greater<int>());
        for(int j=0; j<l[i] && j<(int)w[i].size(); j++){
            ball.push_back(w[i][j]);
        }
    }
    sort(ball.begin(), ball.end(), greater<int>());
    long long int ans = 0;
    for(int i=0; i<m; i++){
        ans += ball[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7876
#include<bits/stdc++.h>
#define lld long long int
#define pb push_back
#define in insert
#define mod 1000000007
#define pi 3.14159265358979

using namespace std;

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

    lld n,x,o=0;
    cin>>n;
    for(lld i=0;i<n;i++)
    {
        cin>>x;
        if(x%2!=0)o++;
    }
    if(o%2!=0)cout<<"NO"<<"\n";
    else cout<<"YES"<<"\n";
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int A,B;cin >> A >> B;
  if(A==1)A=14;
  if(B==1)B=14;
  if(A==B)cout << "Draw" << endl;
  else if(A<B) cout << "Bob" << endl;
  else cout << "Alice" << endl;
  return 0;
}


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

using ll = long long;

const int mod = 1000000007;
const int INF = 1000000000;
const double EPS = 1e-9;

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

ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a / g * b;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    vector<ll> A;
    for (int i = 0; i < N; ++i) {
        ll a;
        cin >> a;
        if (a % 2 == 1) continue;
        A.push_back(a);
    }
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    N = A.size();
    ll l = 1;
    for (int i = 0; i < N; ++i) l = lcm(l, A[i] / 2);
    bool ok = true;
    for (int i = 0; i < N; ++i) {
        if ((l / (A[i] / 2)) % 2 == 0) ok = false;
    }
    ll ans = (M - l) / 2 / l;
    if (M >= l) ++ans;
    else ans = 0;
    if (!ok) ans = 0;
    cout << ans << endl;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    if (abs(n - m) > 1) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    if (abs(n - m) == 1) {
        for (int i = 1; i <= n; i++) {
            ans = (ans * i) % ll(1e9 + 7);
        }
        for (int i = 1; i <= m; i++) {
            ans = (ans * i) % ll(1e9 + 7);
        }
    } else {
        for (int i = 1; i <= n; i++) {
            ans = (ans * i) % ll(1e9 + 7);
        }
        ans = (ans * ans * 2) % ll(1e9 + 7);
    }
    cout << ans << endl;
}


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

#define ll long long

ll sum(ll i){
	return i*(i+1)/2;
}

int main() {
//#ifndef ONLINE_JUGDE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

	ll n;
	cin>>n;
	ll ans=0;
	for(ll i=1;i<=n;i++){
		ans+=sum(i);
	}
	for(ll i=0;i<n-1;i++){
		ll a,b;
		cin>>a>>b;
		if(a>b){
			ll temp=a;
			a=b;
			b=temp;
		}
		assert(a<=b);
		ans-=a*(n-b+1);
	}
	cout<<ans;
	return 0;
}


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


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

  if(A == B){
      if(B == C){
          cout << "No" << endl; return 0;
      } else {
          cout << "Yes" << endl; return 0;
      }
  } else if (A == C || B == C){
      cout << "Yes" << endl; return 0;
  } else {
      cout << "No" << endl; return 0;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;
typedef long long ll;
ll n,m,q;
ll lft[200005]={0},rgt[200005]={0};
ll num[200005]={0};
bool used[200005];
void pop(ll a){
  used[a]=false;
  lft[rgt[a]]=lft[a];
  rgt[lft[a]]=rgt[a];
}
ll move(ll pos,ll move_num){
  if(move_num%2==0){
    for(int i=0;i<move_num;i++){
      pos=rgt[pos];
    }
  }
  else{
    for(int i=0;i<move_num;i++){
      pos=lft[pos];
    }
  }
  ll ret=rgt[pos];
  pop(pos);
  return ret;
}
int main(){
  cin>>n>>m>>q;
  for(int i=0;i<n;i++){
    rgt[i]=i+1;
    lft[i]=i-1;
    used[i]=true;
  }
  lft[0]=n-1;
  rgt[n-1]=0;
  ll pos=0;
  for(int i=0;i<m;i++){
    ll mnum;
    cin>>mnum;
    pos=move(pos,mnum);
  }
  for(int i=0;i<q;i++){
    ll qr;
    cin>>qr;
    cout<<(used[qr]?1:0)<<endl;
  }
}



Measured memory_bytes: 6396
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

const long long MOD_CONST = 1000000007;


int main() {

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

	sort(a.begin(), a.end());
	a.emplace_back(0);
	int ans = 0;
	int cnt = 0;
	for (int i = 1; i <=n; i++) {
		if (a[i] == a[i - 1]) {
			cnt++;
		}
		else {
			cnt++;
			if (cnt < a[i - 1]) {
				ans += cnt;
			}
			else {
				ans += (cnt - a[i - 1]);
			}
			cnt = 0;
		}
	}
	cout << ans << endl;
}

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

int count(vector<vector<char>> v){
  int count=0;
  for(int i=0;i<(int)v.size();i++){
   for(int j=0;j<(int)v.at(0).size();j++){
     if(v.at(i).at(j)=='#'){
     count++;
     }
   }
  }
  return count;
}  


int main() {
  int H,W,K,Ans=0;
  cin>>H>>W>>K;
  vector<vector<char>> v(H,vector<char>(W));
  
 for(int i=0;i<H;i++){
   for(int j=0;j<W;j++){
    cin>>v.at(i).at(j); 
   }
 }
  
  for (int h = 0; h < (1 << H); h++) {
    for (int w= 0; w < (1 << W); w++) {
      bitset<6> s(h);
      bitset<6> t(w);
      vector<vector<char>> x=v;
      for(int i=0;i<H;i++){ 
        if(s.test(i)){
          for(int j=0;j<W;j++){
            x.at(i).at(j)='.';
          }
        }
      }
      for(int i=0;i<W;i++){ 
        if(t.test(i)){
          for(int j=0;j<H;j++){
            x.at(j).at(i)='.';
          }
        }
      }  
    if(K==count(x)){
      Ans+=1;
    }  
    }//tが終わり     
  }//sが終わり
  
  cout<<Ans<<endl;
}

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

int main()
{
  int n;
  cin >> n;
  bool f = 0;
  rep(i, 3){
    if(n % 10 == 7) f = 1;
    n /= 10;
  }
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define MAXX 100005
#define INF INT_MAX

#define PI   3.14159265358979323846264338327950

#define PB push_back
#define PF push_front
#define F first
#define S second

#define fixx(n) fixed << setprecision(n)

#define ll 	 long long 

#define mod  1000000007



int main()
{
	FAST;
	int a, b;
	cin >> a >> b;
	if(a + b == 15){
		cout << "+"; return 0;
	}
	if(a * b == 15){
		cout << "*"; return 0;
	}
	cout << "x";
	return 0;
	
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
//#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a%2==1||b%2==1||c%2==1){
    cout<<0<<endl;
    return 0;
  }
  if(a==b&&b==c){
    cout<<-1<<endl;
    return 0;
  }
  int ans=0;
  int man[3]={a,b,c};
  while(1){
    int x=man[0],y=man[1],z=man[2];
    man[0]=y/2+z/2;
    man[1]=x/2+z/2;
    man[2]=x/2+y/2;
    ans++;
    REP(i,3){
      if(man[i]%2==1)goto at;
    }
  }
  at: ;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
#define ALL(s) (s).begin(), (s).end()
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;

const string D_blue    = "\x1b[36m";
const string D_green   = "\x1b[32m";
const string D_red     = "\x1b[31m";
const string D_yellow  = "\x1b[33m";
const string Db_red    = "\x1b[41m";
const string Db_yellow = "\x1b[43m";
const string D_end     = "\x1b[39m";
const string Db_end    = "\x1b[49m";

int main (){
  int n;
  while (cin >> n){
    vector<int> vi;
    vector<int> vi2;
    REP(i,n){
      int in;
      cin >> in;
      vi.push_back(in);
    }
    sort(ALL(vi));
    vi.erase(unique(ALL(vi)),vi.end());
    cout << vi.size() << endl;
    vi.clear();
  }
  return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string a = Console.ReadLine();
        string b = Console.ReadLine();
        string c = Console.ReadLine();

        int count = 0;

        for (int i = 0; i < N; i++)
        {
            if (a[i] == b[i] && b[i] == c[i])
            {
                continue;
            }

            if (a[i] == b[i])
            {
                c.Remove(i);
                c.Insert(i, a[i].ToString());
            }
            else if (b[i] == c[i])
            {
                a.Remove(i);
                a.Insert(i, b[i].ToString());
            }
            else if (a[i] == c[i])
            {
                b.Remove(i);
                b.Insert(i, a[i].ToString());
            }
            else {
                b.Remove(i);
                b.Insert(i, a[i].ToString());
                count++;
                c.Remove(i);
                c.Insert(i, a[i].ToString());
            }
            count++;
        }


        //出力
        Console.WriteLine(count);
        //string s = Console.ReadLine();
    }
}

Measured memory_bytes: 13140
N = int(input())
A = [int(i) for i in input().split()]

maxdig = 60
mod = 10**9+7

ans = 0
for i in range(60+1):
  cnt1 = sum([1 for a in A if (a >> i) & 1])
  ans += (cnt1*(N-cnt1)*(1<<i))
  ans = ans%mod

print(ans)

Measured memory_bytes: 42156
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int mod = 998244353;
const int maxn = 2e5 + 233;
int cnt[maxn];
int main()
{
	int n;cin>>n;
	int maxi = 0;
	bool bad = 0;
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		if(i==1&&x){
			bad = 1;
		}
		cnt[x]++;
		maxi = max(maxi,x);
	}
	if(cnt[0]>=2)bad = 1;
	for(int i=0;i<=maxi;i++)
		if(!cnt[i])bad = 1;
	if(bad){
		cout<<0<<endl;
		return 0;
	}
	ll ans = 1;
	for(int i=1;i<=maxi;i++){
		for(int j=1;j<=cnt[i];j++)
			ans = ans*cnt[i-1]%mod;
	}
	cout << ans <<endl;
	return 0;
}


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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, N) for(int i = 0; i < int(N); i++)
#define rep1(i, N) for (int i = 1; i <= int(N); i++)
#define fs first
#define sc second
#define pb push_back
#define PB push_back
#define MP make_pair
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)

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

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

template <uint MD> struct ModInt {
    using M = ModInt;
    uint v;
    ModInt() : v{0} {}
    ModInt(ll _v) { set_v(_v % MD + MD); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M(0) - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return (*this).pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<998244353>;

int main() {
    int n;
    cin >> n;
    V<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());


    // naive solution
/*    V<ll> sm(n+1);
    V<int> idx(n);
    iota(idx.begin(), idx.end(), 0);

    do {
        V<bool> used(n);
        ll buf = 1; int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (used[i]) continue;
            cnt++;
            int p = i;
            ll mi = TEN(18);
            do {
                mi = min(mi, a[p]);
                used[p] = true;
                p = idx[p];
            } while (p != i);
            buf *= mi;
        }
        sm[cnt] += buf;
    } while (next_permutation(idx.begin(), idx.end()));

    for (auto d: sm) cout << d << ", ";
    cout << endl;

    ll ans = 0;
    for (auto d: sm) ans = gcd(ans, d);
    cout << ans << endl;*/

    Mint ans = 1;
    for (int i = 0; i < n; i++) {
        ans *= gcd(i, a[i]);
    }
    cout << ans.v << endl;
    return 0;
}

Measured memory_bytes: 1024
N,M,S,T = map(int,input().split())
S,T = S-1,T-1
UVAB = [tuple(map(int,input().split())) for i in range(M)]
es = [[] for _ in range(N)]
for u,v,a,b in UVAB:
    u,v = u-1,v-1
    es[u].append((v,a,b))
    es[v].append((u,a,b))

import heapq
INF = float('inf')
cy = [INF] * N
cy[S] = 0
hq = [(0,S)]
heapq.heapify(hq)
while hq:
    c,v = heapq.heappop(hq)
    for to,a,_ in es[v]:
        if c+a >= cy[to]: continue
        cy[to] = c+a
        heapq.heappush(hq, (c+a, to))
cs = [INF] * N
cs[T] = 0
hq = [(0,T)]
heapq.heapify(hq)
while hq:
    c,v = heapq.heappop(hq)
    for to,_,b in es[v]:
        if c+b >= cs[to]: continue
        cs[to] = c+b
        heapq.heappush(hq, (c+b, to))

ans = [-1] * N
minc = INF
for i,(y,s) in reversed(list(enumerate(zip(cy,cs)))):
    minc = min(minc, y+s)
    ans[i] = 10**15 - minc
print(*ans, sep='\n')

Measured memory_bytes: 87208
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, n);

    vector<vector<int>> alpha(26, vector<int>(n, 0));

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < s.size(); j++) {
            alpha[ s[j]-'a' ][i]++;
        }
    }

    string ans = "";

    for (int i = 0; i < 26; i++) {
        int MIN = 1e9;
        for (int j = 0; j < n; j++) {
            MIN = min(MIN, alpha[i][j]);
        }
        if ( MIN > 0 ) {
            ans += string(MIN, 'a'+i);
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    ll N,K,c;
    cin >> N >> K;

    c = N / K;

    if(c >= 1){
        N = abs(N - K * c);
    }

    cout << min(abs(N - K), N) << endl;
}

Measured memory_bytes: 256
sx, sy, tx, ty = gets.chomp.split(" ").map(&:to_i)
x = tx-sx
y = ty-sy
print "R" * x
print "U" * y
print "L" * x
print "D" * (y+1)
print "R" * (x+1)
print "U" * (y+1)
print "L"
print "U"
print "L" * (x+1)
print "D" * (y+1)
print "R"

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 2e5 + 5;
ll n, k;
int main() {
    cin >> n >> k;
    ld ans = 0;
    for(ll i = 1; i <= n; i++) {
        ll c = i;
        ld p = 1.0 / n ;
        while(c < k) {
            c *= 2;
            p /= 2;
        }
        ans += p ;
    }
    printf("%.30Lf", ans) ;
    return 0;
}
/*
100000 5
*/


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main(){
  ll n;
  cin >> n;
  vll a(n);
  vin(a);
  map<ll, ll> cnt;
  rep(j, 0, n) cnt[j - a.at(j)]++;
  ll ans = 0;
  rep(i, 0, n){
    if(cnt.count(a.at(i) + i)) ans += cnt.at(a.at(i) + i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 16328
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
using P = pair<int, int>;

constexpr int INF = 1e9;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(N), b(N), c(M), d(M);
    for(int i=0; i<N; ++i) {
        cin >> a[i] >> b[i];
    }
    for(int i=0; i<M; ++i) {
        cin >> c[i] >> d[i];
    }
    for(int i=0; i<N; ++i) {
        int res = 0;
        for(int j=0; j<M; ++j) {
            if(abs(a[i] - c[res]) + abs(b[i] - d[res]) > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
                res = j;
            }
        }
        cout << res + 1 << endl;
    }
}


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

int main() {
  int N ;
  int l , r ;
  cin >> N ;
  int i = 0 , j = 0 ;
  
  
  while ( i < N ) {
    cin >> l >> r ;
    j += r - l + 1 ;
    i++ ;
  }
  cout << j << endl ;
}
    


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int A,B;
    scanf("%d%d",&A,&B);
    if(A+B>=A-B&&A+B>=A*B)
    printf("%d",A+B);
    else if(A-B>=A+B&&A-B>=A*B)
        printf("%d",A-B);
    else if(A*B>=A+B&&A*B>=A-B)
        printf("%d",A*B);
    return 0;

}


Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mm(a,x) memset(a,x,sizeof(a))
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
#define ll long long
using namespace std;
int main(void)
{
    sync;
    string s;
    cin>>s;
    bool flag=1;
    if(s[2]!=s[3])
        flag=0;
    if(s[4]!=s[5])
        flag=0;
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
n,x = map(int,input().split())
cities = list(map(int,input().split()))
dist = []
for city in cities:
    dist.append(abs(city-x))

gcf = dist[0]

def gcd(x,y):
    a = max(x,y)
    b = min(x,y)
    while a%b !=0:
        a,b = b,a%b
    return b
for i in dist:
    gcf = gcd(gcf,i)
print(gcf)

Measured memory_bytes: 14224
import java.util.*;

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

        int n = sc.nextInt();

        int[] a = new int[n];

        for (int i=0; i<n; i++) a[i] = sc.nextInt();

        int idx = 0;
        int ans = 0;

        for (int i=0; i<n; i++){
            if (a[i]!=idx+1){
                ans++;
            }else {
                idx++;
            }
        }

        if (ans==n){
            System.out.println(-1);
        }else {
            System.out.println(ans);
        }

    }

}


Measured memory_bytes: 86324
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
dice = np.arange(1, N+1, dtype=np.int32)
need = np.zeros(N, np.int32)

for i in range(20):
    target = dice < K
    need[target] += 1
    dice[target] <<= 1 #2倍

power = (.5) ** need
answer = power.sum() / N
print(answer)
# 58

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

using namespace std;

int main()
{
    int n, m, i, vote, min_vote, total_vote = 0;
    vector <int> items;

    cin >> n >> m;

    for(i = 0; i < n; i++) {
        cin >> vote;
        items.push_back(vote);
        total_vote += vote;
    }

    min_vote = ceil(total_vote / (4.0 * m));

    //cout << min_vote << endl;

    sort(items.begin(), items.end(), greater <int> ());

    if(items[m - 1] >= min_vote)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    city = []
    for i in range(n):
        x,y = map(int, input().split())
        city.append((x,y,i))
    edges = []
    # x
    city.sort()
    for i in range(n-1):
        dist = city[i+1][0] - city[i][0]
        edges.append((dist, city[i][2], city[i+1][2]))
    # y
    city.sort(key=lambda x:x[1])
    for i in range(n-1):
        dist = city[i+1][1] - city[i][1]
        edges.append((dist, city[i][2], city[i+1][2]))

    edges.sort()
    ans = 0

    uf = [-1]*n
    def root(x):
        if uf[x] < 0:
            return x
        uf[x] = root(uf[x])
        return uf[x]
    def unite(x,y):
        rx, ry = root(x), root(y)
        if rx == ry:
            return False
        if rx > ry:
            rx,ry = ry,rx
        uf[rx] += uf[ry]
        uf[ry] = rx
        return True

    for dist, from_, to in edges:
        if unite(from_, to):
            ans += dist
    print(ans)

if __name__ == '__main__':
    main()

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

int main()
{
  ll r, D , x;
  cin >> r >> D >> x;
  rep(i, 10){
    cout << x * r - D << endl;
    x = x * r - D;
  }
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <cctype>
using namespace std;
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int x,y;
    while(cin>>x>>y && x){
        puts(x%2==0 || y%2==0 ? "yes" : "no");
    }
}

Measured memory_bytes: 1108
#include<stdio.h>

int main(void){

  int a,b,c,d;

  scanf("%d %d %d %d", &a, &b, &c, &d);

  if(abs(a-c) <= d || ( abs(a-b) <= d && abs(b-c) <= d )) printf("Yes");
  else printf("No");

  return 0;

}


Measured memory_bytes: 128
# ALDS_11_C - 幅優先探索
import sys
import heapq

N = int(input())
G = []
for _ in range(N):
    u, k, *v = map(int, sys.stdin.readline().strip().split())
    v = [i - 1 for i in v]
    G.append(v)


distance = [-1] * N
q = []
fp = [True] * N  # 探索可能か記録する
heapq.heapify(q)
heapq.heappush(q, (0, 0))
fp[0] = False


while q:
    dist, u = heapq.heappop(q)
    distance[u] = dist
    for v in G[u]:
        if fp[v] is True:
            heapq.heappush(q, (dist + 1, v))
            fp[v] = False

for i, d in enumerate(distance):
    print(i + 1, d)



Measured memory_bytes: 5680
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
const int nmax = 8;
bool G[nmax][nmax];


int dfs(int v, int n, bool visited[nmax]){
    bool all_visited = true;
    for (int i = 0; i < n; i++){
        if(!visited[i]){
            all_visited = false;
        }
    }
    if (all_visited) return 1;

    int ret = 0;

    for (int i = 0; i < n; i++){
        if (visited[i]) continue;
        if (G[v][i] == false) continue;

        visited[i] = true;
        ret += dfs(i,n,visited);
        visited[i] = false;
    }
    return ret;
}


int main(void){
    int n,m;
    cin >> n >> m;
    int a,b;
    rep(i,m){
        cin >> a >> b;
        G[a-1][b-1] = true;
        G[b-1][a-1] = true;
    }
    bool visited[nmax];
    rep(i,nmax) visited[i] = false;
    visited[0] = true;

    cout << dfs(0,n,visited) << endl;

    return 0;
}

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;
using P = pair<int,int>;

int main() {
  int X;
  cin >> X;

  int h = 0;
  h += (X / 500) * 1000 + ((X % 500) / 5) * 5;
  cout << h << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int N, A, B;
	cin >> N >> A >> B;
	if( N == 1 ){
		cout << "Hello World" << endl;
	} else {
		cout << A+B << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int n,ct = 0;
  cin >> n;
  int now;
  rep(i,0,n){
    cin >> now;
    while(now%2==0){
      ct++;
      now /= 2;
    }
  }
  cout << ct << endl;
}

Measured memory_bytes: 256
A, B=map(int, input().split())
ans=0
for i in range(A, B+1):
  s=str(i)
  n=len(s)
  j=True
  for x in range(n//2):
    if s[x]!=s[-1-x]:
      j=False
      
  if j:
    ans+=1
    
print(ans)

Measured memory_bytes: 9104
#include <bits/stdc++.h>
     
#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair
     
using namespace std;
     
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  int ans = 0;
  for (int a = 1; a < n; a++) {
    for (int b = 1; a * b < n; b++) {
      ans += 1;
    }
  }
  cout << ans << '\n';
  return (0);
}


Measured memory_bytes: 3644
package main
 
import (
  "fmt"
)
 
func main() {
  var n int
  fmt.Scan(&n)
  a := make([]int, n - 1)
  ans := make([]int, n)
  for i := range a {
    fmt.Scan(&a[i])
    ans[a[i]-1] += 1
  }
  for i := range ans {
    fmt.Println(ans[i])
  }
}

Measured memory_bytes: 8528
#include <iostream>
#include <algorithm>

using namespace std;

class Card {
public:
	int suffix;

	char design;
	int value;
} card[2][36];

void bubble_sort(Card a[], int n) {
	bool flag = true;

	while (flag) {
		flag = false;
		for (int i = 0; i < n - 1; i++) {
			if (a[i].value > a[i + 1].value) {
				swap(a[i].suffix, a[i + 1].suffix);
				swap(a[i].value, a[i + 1].value);
				swap(a[i].design, a[i + 1].design);
				flag = true;
			}
		}
	}
}

void selection_sort(Card a[], int n) {
	for (int i = 0; i < n; i++) {
		int minj = i;
		for (int j = i; j < n; j++) {
			if (a[minj].value > a[j].value) {
				minj = j;
			}
		}
		swap(a[i].suffix, a[minj].suffix);
		swap(a[i].value, a[minj].value);
		swap(a[i].design, a[minj].design);
	}
}

bool stable(Card a[], int n) {
	for (int i = 0; i < n - 1; i++){
		if (a[i].value == a[i + 1].value) {
			if (a[i].suffix > a[i + 1].suffix) {
				return false;
			}
		}
	}
	return true;
}

void print_array(Card a[], int n) {
	for (int i = 0; i < n; i++) {
		cout << a[i].design << a[i].value;
		if (i < n - 1) {
			cout << ' ';
		}
	}
	cout << endl;
}

int main() {
	int n, value;
	char design;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> design >> value;
		for (int j = 0; j < 2; j++) {
			card[j][i].value = value;
			card[j][i].design = design;
			card[j][i].suffix = i;
		}
	}

	bubble_sort(card[0], n);
	print_array(card[0], n);
	if (stable(card[0], n) == true) {
		cout << "Stable" << endl;
	}
	else {
		cout << "Not stable" << endl;
	}

	selection_sort(card[1], n);
	print_array(card[1], n);
	if (stable(card[1], n) == true) {
		cout << "Stable" << endl;
	}
	else {
		cout << "Not stable" << endl;
	}

	return 0;
}

Measured memory_bytes: 1164
a = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
ans  = [[False]*3 for _ in range(3)]
result = 'No'
for i in range(3):
  for j in range(3):
    for k in b:
      if a[i][j] == k:
        ans[i][j] = True 
for i in ans:
    if all(i):
      result = 'Yes'
for i in range(3):
  cnt = 0
  for j in range(3):
    if ans[j][i]:
      cnt += 1
  if cnt == 3:
    result = 'Yes'
    break
if ans[0][0] and ans[1][1] and ans[2][2]:
  result = "Yes"
if ans[0][2] and ans[1][1] and ans[2][0]:
  result = "Yes"
print(result)

Measured memory_bytes: 38480
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll H, W, ans = 0;
int magi[10][10];
vi A[205];

priority_queue<pii, vector<pii>, greater<pii>> Q;

int dist[10], id;
bool used[10];

void Dijkstra() {
    dist[1] = 0;
    Q.push(make_pair(dist[1], 1));

    while(!Q.empty()){
        pii tmp = Q.top();
        Q.pop();
        // cout << tmp. first << " " << tmp.second << endl;
        id = tmp.second;

        if(dist[id] < tmp.first) continue;

        if(!used[id]){
            used[id] = true;
            dist[id] = tmp.first;
            rep(i, 10){
                Q.push(make_pair(dist[id]+magi[i][id], i));
            }
        }
    }
}

void solve(){
    fill(dist, dist+10, INF);
    fill(used, used+10, false);

    Dijkstra();

    rep(i, H){
        rep(j, W){
            if(A[i][j] != -1)
                ans += dist[A[i][j]];
        }
    }

    cout << ans << endl;
}

int main(){
    cin >> H >> W;

    rep(i, 10){
        rep(j, 10){
            cin >> magi[i][j];
        }
    }

    rep(i, H){
        A[i].resize(W);
        rep(j, W){
            cin >> A[i][j];
        }
    }

    solve();
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	string s;
	cin >> s;
	string t = "keyence";
	int ans = 0;
	int n = s.size();
	for(int i = 0;i<7;i++)
	{
		if(t[i]==s[i])ans ++ ;
		else break;
	}
	for(int i = 0;i<7;i++)
	{
		if(t[6-i]==s[s.size()-1-i])ans ++ ;
	}
	if(ans>=7)
	{
		cout<<"YES"<<endl;
	}
	else
	{
		cout<<"NO"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int r,g,b;
	scanf("%d%d%d",&r,&g,&b);
	int s=r*100+g*10+b;
	if(0==s%4)
		printf("YES\n");
	else
		printf("NO\n");
	
	return 0;
} 

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	char a, b;
	cin >> a >> b;
	if(a == b) cout << 'H';
	else cout << 'D';
	return 0;
}

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

const int N = 1e5 + 5;
 int dp[N],arr[N];
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

  int n;
  cin>>n;
  for(int i=0;i<n;i++){
   cin>>arr[i];
  }
 dp[1]=abs(arr[0]-arr[1]);
 dp[0]=0;
 for(int i=2;i<n;i++){
    dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
 }
 cout<<dp[n-1];

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int n,t,i,p[110],a,m,j;
  while(scanf("%d",&n),n){
    int d[110][110]={0};
    for(i=t=0;i<n;i++){
      scanf("%d",&m);
      for(j=0;j<m;j++){
	scanf("%d",&a);
	d[i][a]=1;
      }
    }
    scanf("%d",&m);
    for(i=0;i<m;i++)scanf("%d",&p[i]);
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
	if(d[i][p[j]]==0)break;
      }
      if(j==m)t=t?-1:i+1;
    }
    printf("%d\n",t<1?-1:t);
  }
  return 0;
}

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

typedef pair<int, int> P;
 
int main(){
  int N, a;
  cin >> N;
  int cnt = 0;
  for(int i=0; i<N; i++){
    cin >> a;
    if(a-1!=i){
      cnt+=1;
    }
  }
  if(cnt==0 | cnt==2){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

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

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

  cout << (a + b) * h / 2 << endl;
}

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

int main(){
	char a, b;
	
	scanf("%c %c", &a, &b);
	if(a=='H'){
		if(b=='H') printf("H\n");
		else if(b='D') printf("D\n");
	}else if(a=='D'){
		if(b=='H') printf("D\n");
		else if(b='D') printf("H\n");
	}
	//getchar();
	//getchar();
	return 0;
}

Measured memory_bytes: 128
def bit_remove(x,bit):
    return ((x>>(bit+1))<<bit)+(x%(1<<bit))
def bit_insert(x,bit,i):
    return ((x>>bit)<<(bit+1))+(i<<bit)+(x%(1<<bit))

def solve(n,a,b):
    if n==1:
        return [a,b]
    for bit in range(n):
        if (a^b)&(1<<bit):
            break
    c,d=bit_remove(a,bit),bit_remove(b,bit)
    L=list(map(lambda x: bit_insert(x,bit,(a>>bit)&1),solve(n-1,c,c^1)))
    R=list(map(lambda x: bit_insert(x,bit,(b>>bit)&1),solve(n-1,c^1,d)))
    return L+R

n,a,b=map(int,input().split())
if not bin(a^b).count('1')%2:
    print('NO')
else:
    print('YES')
    print(*solve(n,a,b))

Measured memory_bytes: 65112
using System;
using System.Collections.Generic;
class Program
    {
    	static void Main(string[] args)
    	{
            string[] s = Console.ReadLine().Split(' ');
            if (s[0] == s[1] && s[1] == s[2]) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
    //mcs Main.cs
    //mono Main.exe

Measured memory_bytes: 13140
inpu [x]       = [x]
inpu (x:y:z)
 | x == y      =   inpu $ y:z
 | otherwise   = x : (inpu $ y:z )

main = do
 _ <- getLine
 xs <- getLine
-- xs <- map read . words <$> getLine :: IO String
 print $ length$ inpu xs

Measured memory_bytes: 4988
import sys
G = list(map(int, input().split()))
total = G[0] + G[1]
if total % 3 != 0:
  print(0)
  sys.exit(0)

total //= 3
dis = G[0] - total

MOD = 10 ** 9 + 7
def inv_mod(a, p=MOD):
    def inv_mod_sub(a, p):
        if a == 1:
            return 1, 0
        else:
            d, r = p//a, p%a
            x, y = inv_mod_sub(r, a)
            return y-d*x, x
    if p < 0: p = -p
    a %= p
    return inv_mod_sub(a,p)[0] % p

def comb_mod(n, k):
    if k < 0 or k > n:
        return 0
    else:
        return f_mod[n]*f_mod_inverse[k]*f_mod_inverse[n-k] % MOD
f_mod=[1]*(10**6)
f_mod_inverse=[1]*(10**6)
for i in range(1,10**6):
  f_mod[i]=f_mod[i-1]*i%MOD
  f_mod_inverse[i]=f_mod_inverse[i-1]*inv_mod(i)%MOD

print(comb_mod(total, dis))


Measured memory_bytes: 108376
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <cstdlib>
using namespace std;
using ll = long long int;


int main()
{
    int N,X;
    cin >> N >> X;
    vector<int> x;
    for (int i = 0; i < N; i++) {
        int x1;
        cin >> x1;
        x.push_back(x1);
    }
    x.push_back(X);

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

    int A[N];
    for (int i = 0; i < N; i++) {
        A[i] = x[i+1]-x[i];
    }

    sort(A,A+N);

    int dmax = 0;
    for (int i = A[0]; i >= 1; i--) {
        int b = 1;
        for (int j = 0; j < N; j++) {
            if (A[j] % i != 0) {
                b = 0;
            }
        }
        if (b == 1) {
            dmax = i;
            cout << dmax << endl;
            return 0;
        }
    }

    cout << dmax << endl;
}


Measured memory_bytes: 1144
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m


N = int(input())
A = list(map(int, input().split()))

"順方向累積GCD"
forward_gcd = [0]

for i in range(0, N):
    forward_gcd.append(gcd(forward_gcd[-1], A[i]))

"逆方向累積GCD"
reverse_gcd = [0]
for i in range(N-1, -1, -1):
    reverse_gcd.append(gcd(reverse_gcd[-1], A[i]))

reverse_gcd.reverse()

ans = 0
for i in range(N):
    ans = max(ans, gcd(forward_gcd[i], reverse_gcd[i+1]))

# gcd_list = [gcd(forward_gcd[i], reverse_gcd[i+1]) for ]

print(ans)


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

int datas[105];

int main()
{
	int N;
	cin>>N;
	for(int a=0;a<N;a++)
	{
		cin>>datas[a];
	}
	sort(datas, datas+N);
	int count=1, pos=datas[0];
	for(int a=1;a<N;a++)
	{
		if(pos < datas[a])
		{
			count++;
			pos=datas[a];
		}
	}
	cout<<count<<endl;
	return 0;
}

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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  std::cin >> N;

  int r = N % 10;
  if(r == 3) {
    std::cout << "bon" << '\n';
    return 0;
  }
  if(r == 0 || r == 1 || r == 6 || r == 8) {
    std::cout << "pon" << '\n';
    return 0;
  }

  std::cout << "hon" << '\n';
  
}


Measured memory_bytes: 3640
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <bitset>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, string> P;
typedef unsigned long long ull;
const int INF = 1e9 + 7;
const int MAX_N = 14;

const ull B = 100000007;

// aはbに含まれているか
bool contain(string a, string b){
  int al = a.length(), bl = b.length();
  if(al > bl) return false;

  ull t = 1;
  REP(i, al) t *= B;

  ull ah = 0, bh = 0;
  REP(i, al) ah = ah * B + a[i];
  REP(i, al) bh = bh * B + b[i];

  for(int i = 0; i + al <= bl; ++i){
    if(ah == bh) return true; // bのi9文字目からのal文字が一致
    if(i + al < bl) bh = bh * B + b[i + al] - b[i] * t;
  }
  return false;
}

// aの末尾とbの先頭を何文字重ねることができるか
int overlap(string a, string b){
  int al = a.length(), bl = b.length();
  int ans = 0;
  ull ah = 0, bh = 0, t = 1;
  for(int i = 1; i <= min(al, bl); ++i){
    ah = ah + a[al - i] * t;
    bh = bh * B + b[i - 1];
    if(ah == bh) ans = i;
    t *= B;
  }
  return ans;
}

vector<string> make_ss(vector<string> &_ss, int N){
  vector<string> res;
  REP(i, N){
    bool f = true;
    REP(j, N){
      if(i != j && contain(_ss[i], _ss[j])) f = false;
    }
    if(f) res.push_back(_ss[i]);
  }
  return res;
}

int main(){
  int N;
  while(cin >>N && N){
    vector<string> _ss(N); REP(i, N) cin >>_ss[i];
    vector<string> ss = make_ss(_ss, N);
    N = ss.size();
    //REP(i, N) cout <<ss[i] <<", "; cout <<endl;
    int dp[(1 << MAX_N)][MAX_N];
    REP(i, (1 << MAX_N)) REP(j, N) dp[i][j] = INF;
    REP(i, N) dp[(1 << i)][i] = ss[i].length();
    int cost[MAX_N][MAX_N];
    REP(i, N) REP(j, N) cost[i][j] = (int)(ss[j].length()) - overlap(ss[i], ss[j]);
    //REP(i, N) REP(j, N) cout <<ss[i] <<", " <<ss[j] <<" = " <<cost[i][j] <<endl;
    REP(i, (1 << MAX_N)){
      REP(j, N){
        if(dp[i][j] == INF) continue;
        //cout <<i <<", " <<dp[i][j] <<endl;
        REP(b, N){
          if(i & (1 << b)) continue;
          //cout <<i <<", " <<b <<", " <<(1 << b) <<", " <<(i | (1 << b)) <<", " <<tmp <<", " <<(int)(tmp.length()) <<", " <<dp[i || (1 << b)].first <<endl;
          if(dp[i][j] + cost[j][b] < dp[i | (1 << b)][b]) dp[i | (1 << b)][b] = dp[i][j] + cost[j][b];
        }
      }
    }
    int ans = INF;
    REP(i, N) ans = min(ans, dp[(1 << N) - 1][i]);
    cout <<ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 2108