akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())

s = []

for i in range(m):
    array = list(map(int, input().split()))
    s.append(array[1:])

check = list(map(int, input().split()))

ans = 0
for i in range(2**n):
    flag =True
    for j in range(m):
        a = 0
        for k in range(n):
            if ((i >>k)&1) == 1 and k+1 in s[j]:
                a += 1
        if a%2 == check[j]:
            continue
        else:
            flag = False
            break
    if flag is True:
        ans += 1
print(ans)

Measured memory_bytes: 41072
# -*- coding: utf-8 -*-
import numpy as np
def fnSolv():
  iNum = int(input())
  sIn  = input()
  iRet = 0
  for i, s in enumerate(sIn):
    if s == 'A':
      if sIn[i:i+3] == 'ABC':
        iRet += 1
  print(abs(iRet))

if __name__ == '__main__':
  fnSolv()


Measured memory_bytes: 12276
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
using namespace std;
int main()
{
	int a, b, c, max,k,ans;
	scanf("%d%d%d%d", &a, &b, &c, &k);
	ans = a + b + c;
	max = a >= b ? a : b;
	max = max >= c ? max : c;
	ans -= max;
	for (int i = 0; i < k; i++)
		max=2*max;
	printf("%d", max+ans);
	return 0;
}

Measured memory_bytes: 128
R,C=gets.chomp.split(" ").map(&:to_i)
last_low = Array.new(C+1, 0)
rows = []
R.times do
    arr=gets.chomp.split(" ").map(&:to_i)
    arr.push(arr.inject(:+))
    puts arr.join(" ")
    last_low = [last_low, arr].transpose.map{|a| a.inject(:+) }
end

puts last_low.join(" ")



Measured memory_bytes: 7032
n, K = map(int,input().split())
v = list(map(int,input().split()))

ans = 0
for k in range(K+1):
    for a in range(min(k,n)+1):
        for b in range(min(k,n)-a+1):
            V = v[:a] + v[n-b:]
            V.sort()
            if k-a-b <= a+b:
                ans = max(ans,sum(V[k-a-b:]))
print(ans)

Measured memory_bytes: 3064
N = gets.chomp.to_i
B = gets.chomp.split.map(&:to_i)
# s = gets.chomp
# A, B, C = gets.chomp.split.map(&:to_i)

A = Array.new(N)
A[N-1] = B[N-2]
(N-2).downto(1).each do |i|
  A[i] = [B[i-1], B[i]].min
end
A[0] = B[0]

p A.inject(&:+)


Measured memory_bytes: 1788
//Robs Code

/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>

/***********MACROS***************/
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>

using namespace std;

const int N = 1e5 + 1;
int n,m,i,j,k,l,x,y,z,cnt[3],sum[3];

/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int arr[3];
	cin>>arr[0]>>arr[1]>>arr[2];
	cout<<arr[2]<<" "<<arr[0]<<' '<<arr[1]<<"\n";
}
//.........

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <iterator>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long LL;
const int maxn = 2020;
const LL INF = 100000000000000LL;
const LL mod = 1e9 + 9;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define For(i,a,b) for(int i=a;i<=b;++i)

char s[maxn];
int vis[maxn];
int mk[maxn];

void solve() {
	int n;
	memset(vis, 0, sizeof(vis));
	memset(mk, 0, sizeof(mk));
	cin >> n;
	cin >> s + 1;
	int len = strlen(s + 1);
	int sum = 0;
	for(int i = 1;i <= len;i++) {
		if(vis[s[i] - 'a'] == 0) sum++;
		vis[s[i] - 'a']++;
	}
	int cnt  = 0;
	int ans = 0;
	for(int i = 1;i < len;i++) {
		vis[s[i] - 'a']--;
		if(!mk[s[i] - 'a']) mk[s[i] - 'a'] = 1, cnt++;
		if(vis[s[i] - 'a'] == 0) cnt--;
		ans = max(ans, cnt);
	}
	cout << ans << endl;
}

int main() {
	int t = 1;
	while(t--) {
		solve();
	}
	int mark_EOF;
	if(scanf("%d", &mark_EOF) == EOF) return 0;
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		string a;
		cin >> a;
		if (a == "Y") {
			cout << "Four" << endl;
			return 0;
		}
	}
	cout << "Three" << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

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

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

int N, K;
vector<int> A;
vector<int> dp(100100, 0);

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

    cin >> N >> K;
    A.resize(N, 0);
    REP(i, N) cin >> A.at(i);

    dp.at(0) = -1;

    for (int i = 0; i <= K; i++) {
        bool isloser = true;
        for (int j = 0; j < N; j++) {
            if (i >= A.at(j)) {
                if (dp.at(i - A.at(j)) == -1) {
                    dp.at(i) = A.at(j);
                    isloser = false;
                    break;
                }

            }
        }
        if (isloser) dp.at(i) = -1;
    }

    if (dp.at(K) == -1) {
        cout << "Second" << endl;
    } else {
        cout << "First" << endl;
    }
    
    return 0;
}

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

int H, W, h2, w2, h3, w3;
vector<int> ans;

int maxmin(int x, int y, int z){
  int M = max(x, max(y, z));
  int m = min(x, min(y, z));
  return M - m;
}

int main(void){
  cin >> H >> W;
  h3 = H / 3;
  w3 = W / 3;
  h2 = H / 2;
  w2 = W / 2;
  if(H % 3 == 0 or W % 3 == 0){
    cout << 0 << endl;
    return 0;
  }
  ans.push_back(H);
  ans.push_back(W);
  ans.push_back(maxmin(w3 * H, (W - w3) * h2, (W - w3) * (H - h2)) );
  ans.push_back(maxmin((w3 + 1) * H, (W - w3 - 1) * h2, (W - w3 - 1) * (H - h2) ));
  ans.push_back(maxmin(h3 * W, w2 * (H - h3), (W - w2) * (H - h3)) );
  ans.push_back(maxmin((h3 + 1) * W, (H - h3 - 1) * w2, (H - h3 - 1) * (W - w2) ) );
  sort(ans.begin(), ans.end());
  cout << ans[0] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve(){
  #ifndef ONLINE_JUDGE    
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf   
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t; 
    ll l=abs(a-b);
    ll l2=(v-w)*t; 
    (l2>=l)?(cout<<"YES"):(cout<<"NO");
    //printclock;
    return 0;
}
    

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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
    
	int n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	if (a[0]) {cout << -1; return 0;}
	for (int i = 1; i < n; i++) {
		if (a[i] > a[i-1] && abs(a[i] - a[i-1]) > 1) {cout << -1; return 0;}
	}
    
	ll ans = 0;
	a.push_back(1000000007);
	for (int i = 0; i < n; i++) {
		int pt = 0;
		while (a[i+1] == a[i] + 1) {i++;}
		ans += a[i];
	}
	
	cout << ans;
	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n,k;
    cin>>n>>k;
    k--;
    ll x=0;
    rep(i,n){
        ll tmp;
        cin>>tmp;
        if(tmp==1)x=i;
    }
    ll ans = (n-1+k-1)/k;
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<10)
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  string s;
  deque<char> str;
  int q, reversecount=0;
  cin>>s>>q;
  for(int i=0;i<s.length();i++){
    str.push_back(s[i]);
  }
  for(int i=0;i<q;i++){
    int t;
    cin>>t;
    if(t==1) reversecount++;
    else{
      int f;
      char c;
      cin>>f>>c;
      if((f+reversecount)%2==0)str.push_back(c);
      else str.push_front(c);
    }
  }
  if(reversecount%2==0){
    for(int i=0;i<str.size();i++)cout<<str[i];
  }
  else {
    reverse(str.begin(),str.end());
    for(int i=0;i<str.size();i++)cout<<str[i];
  }
  return 0;
}


Measured memory_bytes: 896
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int g = sc.nextInt();
    int b = sc.nextInt();
    if ((10*g+b)%4==0){
      System.out.println("YES");
    }
    else{
      System.out.println("NO");
    }
  }
}

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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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;
}
///////////////////////////////////////////////
/*（๑•﹏•๑｀) */

int main() {
	int A,P;
	cin >> A >> P;
	cout << (P+(A * 3)) / 2  << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int n,m; cin >> n>>m;
  dump(n,m);
  vector<pii> ba;
  rep(i,n){ int ai, bi; cin>>ai>>bi; ba.pb(mp(ai, bi)); }
  sort(all(ba));
  //rep(i,n) cerr << ba[i].Fi << " " << ba[i].Se << endl;

  priority_queue<int> buf;
  ll money = 0;
  int j=0;
  rep(i,1,m+1){
    while(j<ba.size() && ba[j].Fi<=i){ buf.push(ba[j++].Se); }
    if(buf.empty()) continue;
    int b = buf.top(); buf.pop();
    dump(i,b);
    money += b;
  }
  cout << money << endl;
  return 0;
}


Measured memory_bytes: 1908
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

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) {
    return a/gcd(a,b)*b;
}

int main() {
	long long a,b;cin>>a>>b;
	cout<<lcm(a,b)<<endl;
}


Measured memory_bytes: 256
#include <cstdio>

char S1[4]={'.','.','#','#'};
char S2[4]={'.','#','.','#'};

int main()
{
  int n;
  scanf("%d",&n);
  int P[1000],Q[1000];
  int N=0;
  while(N<n){
    bool F=0;
    for(int v=0;v<4;v++){
      for(int i=0;i<N;i++){
	putchar(S1[P[i]]);
      }
      putchar(S1[v]);
      putchar('\n');
      for(int i=0;i<N;i++){
	putchar(S2[P[i]]);
      }
      putchar(S2[v]);
      putchar('\n');
      fflush(stdout);
      char s[5];
      scanf("%s",s);
      if(s[0]!='F'){
	P[N]=v;
	F=1;
	break;
      }
    }
    if(!F){
      break;
    }
    N++;
  }
  for(int M=0;M<n-N;M++){
    for(int v=0;v<4;v++){
      putchar(S1[v]);
      for(int i=M-1;i>=0;i--){
	putchar(S1[Q[i]]);
      }
      for(int i=0;i<N;i++){
	putchar(S1[P[i]]);
      }
      putchar('\n');
      putchar(S2[v]);
      for(int i=M-1;i>=0;i--){
	putchar(S2[Q[i]]);
      }
      for(int i=0;i<N;i++){
	putchar(S2[P[i]]);
      }
      putchar('\n');
      fflush(stdout);
      char s[5];
      scanf("%s",s);
      if(s[0]!='F'){
	Q[M]=v;
	break;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;

#define ll long long

int main() {
  int n, ans = 0;
  int cnt[3] = {0};
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int len = s.size();
    for (int j = 1; j < len; j++) {
      if (s[j-1] == 'A' && s[j] == 'B') ans++;
    }
    if (len > 0) {
      if (s[0] == 'B' && s[len - 1] == 'A') cnt[0]++;
      else if (s[0] == 'B') cnt[1]++;
      else if (s[len - 1] == 'A') cnt[2]++;
    }
  }

  if (cnt[0] > 0) {
    ans += cnt[0] - 1;
    cnt[0] = 1;
  }
  if (cnt[0] == 1 && (cnt[1] || cnt[2])) ans++;
  ans += min(cnt[1], cnt[2]);

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
ll v[100000];
ll ncr(ll n, ll c){
    ll ans=1;
    FORR(i,n,n-c+1){
        ans *= i;
    }
    FORR(i,c,1){
        ans /= i;
    }
    return ans;
}
int main(){
    ll n,m; cin >> n >> m;
    REP(i,n){
        cin >> v[i]; 
        if(i!=0) v[i] += v[i-1];
        v[i] = v[i] % m;
    }
    map<ll,ll> ma;
    ma[0]++;
    REP(i,n){
        ma[v[i]]++;
    }
    auto it = ma.begin();
    ll ans =0;
    while(it!=ma.end()){
        ans += ncr((*it).second,2);
        it++;
    }
    cout<< ans << endl;

    
}

Measured memory_bytes: 4992
using System;

namespace V0003{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            foreach(var tri in sr.Next<int>(sr.Next<int>(), 3)){
                Array.Sort(tri);
                var ans = tri[0] * tri[0] + tri[1] * tri[1] == tri[2] * tri[2];
                Console.WriteLine(ans ? "YES" : "NO");
            }
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = Console.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[][] Next<T>(int y, int x){
            var result = new T[y][];
            for(var i = 0; i < y; ++i){
                result[i] = new T[x];
                for(var j = 0; j < x; ++j){
                    result[i][j] = Next<T>();
                }
            }
            return result;
        }
    }
}

Measured memory_bytes: 9948
let ab_s = Array.init 3 @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a, b
let cs = Array.make 5 0
let _ = Array.iter (fun (a, b) -> cs.(a) <- cs.(a) + 1; cs.(b) <- cs.(b) + 1) ab_s;
  for i = 1 to 4 do if cs.(i) = 0 || cs.(i) >= 3 then (print_endline "NO"; exit 0) done;
  print_endline "YES"

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

int main(void){
	int n;
	cin >> n;
	vector<int> d(n);
	for(int i = 0; i < n; ++i){
		cin >> d[i];
	}
	sort(d.begin(), d.end());
	int ans = 1;
	for(int i = 1; i < n; ++i){
		if(d[i] == d[i-1]) continue;
		ans++;
	}
	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 all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n,k;
  cin >> n >> k;
  vector<mint> D(k+5); //gcd(...) = i となるものの個数
  mint ans = 0;
  for (int i = 1; i <= k; ++i) {
    D[i] = k/i;
    D[i] = D[i].pow(n);
  }
  for (int i = k; i >= 1; --i) {
    for (int j = 2; j*i <= k; ++j) {
      D[i] -= D[j*i];
    }
    mint res = D[i];
    res *= i;
    ans += res;
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    std::string S;
    std::cin >> S;
    int num = 0, answer = 0;
    std::vector<int> subs;
    for (int i = 0; i < S.length() - 2; i++)
    {
        num = std::abs(753 - std::stoi(S.substr(i, 3)));
        subs.push_back(num);
    }
    std::sort(subs.begin(), subs.end());

    std::cout << subs[0] << std::endl;

    return 0;
}

Measured memory_bytes: 256
import math
X, D = map(int, input().split())

list_1 = []
for i in range(X):
    A = list(map(int, input().split()))
    list_1.append(A)

list_2 = []
for p in list_1:
    dist = math.sqrt(p[0]*p[0]+p[1]*p[1])
    list_2.append(dist)

ctr = 0
for q in list_2:
    if(q <= D):
        ctr += 1
print(ctr)

Measured memory_bytes: 53444
#define MOD 1000000007
#define Rep(i,a,n)for(int i=a;i<n;i++)
typedef long long LL;
LL mp(LL a,LL n,LL m){LL x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invmp(b,p)mp(b,p-2,p)
main(){
  LL s,f[2009]={1},a=0;
  scanf("%lld", &s);
  if(s>2){
    Rep(i,1,2009)f[i]=f[i-1]*i%MOD;
    Rep(n,1,1+s/3)a+=f[s-2*n-1]%MOD*invmp(f[n-1],MOD)%MOD*invmp(f[s-3*n],MOD)%MOD;
  }
  printf("%lld\n",a%MOD);
}

Measured memory_bytes: 1724
#include<stdio.h>

int main(){
    
    int h,m,s,a;
    scanf("%d",&a);
    h=a/3600;
    m=(a%3600)/60;
    s=(a%3600)%60;
    printf("%d:%d:%d\n",h,m,s);
    
    return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll mod = 1e9 + 7;

int main(){
    int h, w;
    cin >> h >> w;
    char A[h][w];
    ll B[h][w];

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> A[i][j];
            B[i][j] = 0;
        }
    }

    if(A[0][0] == '#')  cout << 0;
    else {
        B[0][0] = 1;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(A[i][j] == '.'){
                    if(i-1 >= 0){
                        B[i][j] = (B[i][j] + B[i-1][j]) % mod;
                    } if(j-1 >= 0){
                        B[i][j] = (B[i][j] + B[i][j-1]) % mod;
                    }
                }
            }
        }
        cout << (B[h-1][w-1])%mod;
    }

}


Measured memory_bytes: 12348
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int n;
  vector<int> v;
  v.resize(999999);
  fill(v.begin(), v.end(), 1);
  v[0] = 0;
  v[1] = 0;
  for (int i = 0; i * i < v.size(); ++i) {
    while (v[i] == 0) ++i;
    for (int m = i + 1; m < v.size(); ++m) {
      if (m % i == 0) {
        v[m] = 0;
      }
    }
  }
  while (cin >> n) {
      cout << accumulate(v.begin(), v.end() - (v.size() - (n + 1)), 0) << endl;
  }
  return 0;
}

Measured memory_bytes: 4900
package main

import (
	"fmt"
)

func trace(arr []int) {
	for i, e := range arr {
		if i == len(arr)-1 {
			fmt.Printf("%d\n", e)
		} else {
			fmt.Printf("%d ", e)
		}
	}
}

func selectionSort(arr []int, len int) {
	count := 0
	for i := 0; i < len; i++ {
		minIndex := i
		for j := i + 1; j < len; j++ {
			if arr[j] < arr[minIndex] {
				minIndex = j
			}
		}
		if i != minIndex {
			arr[i], arr[minIndex] = arr[minIndex], arr[i]
			count++
		}
	}
	trace(arr)
	fmt.Println(count)
}

func main() {
	var n int
	fmt.Scan(&n)

	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	selectionSort(arr, n)
}



Measured memory_bytes: 1152
// Reference: https://atcoder.jp/posts/517
struct FenwickTree<T> {
    n: usize,
    init: T,
    data: Vec<T>,
}

impl<T: Copy + std::ops::AddAssign> FenwickTree<T> {
    fn new(n: usize, init: T) -> FenwickTree<T> {
        FenwickTree { n, init, data: vec![init; n] }
    }

    fn add(&mut self, mut p: usize, x: T) {
        p += 1;
        while p <= self.n {
            self.data[p - 1] += x;
            p += p & (!p + 1);
        }
    }

    fn sum(&self, mut r: usize) -> T {
        let mut res = self.init;
        while r > 0 {
            res += self.data[r - 1];
            r -= r & (!r + 1);
        }
        res
    }
}

fn main() {
    let (n, q): (usize, usize) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    let a: Vec<i64> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };

    let mut ft = FenwickTree::new(n, 0);

    for i in 0..n {
        ft.add(i, a[i]);
    }

    let mut ans = Vec::new();
    for _ in 0..q {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        let t = iter.next().unwrap();
        if t == "0" {
            let p: usize = iter.next().unwrap().parse().unwrap();
            let x: i64 = iter.next().unwrap().parse().unwrap();
            ft.add(p, x);
        } else {
            let l: usize = iter.next().unwrap().parse().unwrap();
            let r: usize = iter.next().unwrap().parse().unwrap();
            ans.push((ft.sum(r) - ft.sum(l)).to_string());
        }
    }
    println!("{}", ans.join("\n"));
}

Measured memory_bytes: 29592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)

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

    if(n==25){
        cout << "Christmas" << endl;
    }else if(n==24){
        cout << "Christmas Eve" << endl;
    }else if(n==23){
        cout << "Christmas Eve Eve" << endl;
    }else if(n==22){
        cout << "Christmas Eve Eve Eve" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long

signed main(){
  int N;cin>>N;
  map<int,int> m;
  for(int i=2;i*i<=N;i++){
    if(N%i==0){
      m[i]++;
      N/=i;
      i=1;
    }
  }
  m[N]++;
  cout<<m.size()<<" ";
  int ans=1;
  for(auto p:m)ans*=(p.second+1);
  cout<<ans-1<<endl;
}



Measured memory_bytes: 3096
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#include <cassert>
#include <chrono>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int> > vpi;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int h, w, k;

int cnt(int mh, int mw, vs& mat) {
    int b = 0;
    FOR (i, 0, h) {
        FOR (j, 0, w) {
            if (((1<<i)&mh) or ((1<<j)&mw))
                continue;
            b += (mat[i][j] == '#');
        }
    }
    return b;
}

void solve() {
    cin >> h >> w >> k;
    int msh = (1<<h), msw = (1<<w);
    vs mat(h);
    FOR (i, 0, h)
        cin >> mat[i];

    int ans = 0;
    FOR (i, 0, msh) {
        FOR (j, 0, msw) {
            if (cnt(i, j, mat) == k)
                ans++;
        }
    }

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

int main() {
    #ifdef LOCAL
    auto t1 = std::chrono::high_resolution_clock::now();
    #endif

    io;
    int t = 1;
    tc(t) {
        solve();
    }

    #ifdef LOCAL
    auto t2 = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();

    std::cout << "Time Taken: " << duration << "\n";
    #endif

}
//check for edge cases in limits
//printing double may print 1.223232e9 like values, beware of that


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=int(a);i<=int(b);i++)
#define ROF(i,a,b) for(int i=int(b);i>=int(a);i--)
#define pb push_back
using namespace std;
struct data{int v,idx;};
int n,tmp,ecnt,ocnt;
data even[100010],odd[100010];
bool cmp(data A,data B){return A.v>B.v;}
int main(){
    cin>>n;
    FOR(i,1,100000) even[i]=odd[i]=(data){0,i};
    FOR(i,1,n){
        scanf("%d",&tmp);
        if(i%2){
            ocnt++;
            odd[tmp].v++;
        }
        else{
            ecnt++;
            even[tmp].v++;
        }
    }
    sort(even+1,even+100001,cmp);
    sort(odd+1,odd+100001,cmp);
    if(even[1].idx!=odd[1].idx) cout<<(ecnt-even[1].v)+(ocnt-odd[1].v);
    else{
        cout<<min((ocnt-odd[1].v)+(ecnt-even[2].v),(ocnt-odd[2].v)+(ecnt-even[1].v));
    }
}


Measured memory_bytes: 2300
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
using namespace std;
using ll = long long;
using ld = long double;

// ----本問について----
// 問題：Reconstruction of a Tree
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_7_D
// 所要時間：
// 学んだこと：
// ------------------

// ----ここから本問のソースコード----

// グローバル変数（入力）
ll n;
vll pre, in;

// 二分木をpostorderで出力する
// 木はpreorderの[pl,pr)，inorderの[il,ir)を情報として利用する．
void ReconstructTree(ll pl, ll pr, ll il, ll ir) {
  ll root = pre[pl]; // 根の値
  ll rootIndex;

  // inorder中の根のインデックスを探る
  for (ll i = il; i < ir; i++) {
    if (in[i] == root) {
      rootIndex = i;
      break;
    }
  }

  if (rootIndex > il) { // 左側が存在したら
    ReconstructTree(pl + 1, pl + 1 + rootIndex - il, il, rootIndex);
  }

  if (rootIndex < ir - 1) { // 右側が存在したら
    ReconstructTree(pr - ir + rootIndex + 1, pr, rootIndex + 1, ir);
  }

  // 根を出力
  cout << root;
  if (!(pl == 0 && pr == n)) { cout << " "; } // 最後以外空白を入れる
}

void solve() {
  ReconstructTree(0, n, 0, n);
  cout << endl;
}

int main() {
  cin >> n;
  rep(i, n) {
    ll a;
    cin >> a;
    pre.push_back(a);
  }
  rep(i, n) {
    ll a;
    cin >> a;
    in.push_back(a);
  }
  solve();
  return 0;
}



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

#累積和を出す
t = [0] * (len(p) + 1)
for i in range(len(p)):
  t[i + 1] = t[i] + p[i]

#連続するK個の和で、最大の値を取得する。
maximum = -1
start = -1

for i in range(len(p) - k + 1):
  temp = t[i + k] - t[i]
  if temp > maximum:
    maximum = temp
    start = i

#期待値
exp = 0
for i in range(start, start + k):
  temp = 1 / 2 * p[i] * (p[i] + 1)
  exp += temp / p[i]

print(exp)

Measured memory_bytes: 25604
#include <cstdio>
#include <algorithm>
using namespace std;
bool a[1000010];
int b[200010],n,cnt;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",b+i);
	}
	sort(b+1,b+1+n);
	b[n+1]=1e9;
	for(int i=1;i<=n;++i){
		if(!a[b[i]]){
			a[b[i]]=true;
			if(b[i+1]>b[i]){
				++cnt;
			}
			for(int j=2*b[i];j<=1e6;j+=b[i]){
				a[j]=true;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 3488
#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>;
using vi = vector<int>;
const int MOD = 1000000007;

int main(){
    int n,k;
    cin>>n>>k;
    vi p(n);
    rep(i,n)cin>>p[i];
    sort(p.begin(), p.end());
    
    int ans =0;
    
    rep(i,k)ans+=p[i];
    
    cout<< ans <<endl;
    
    return 0;
}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

void solve() {
    int N;
    cin >> N;
    vi A(N + 1);
    rep(i, N)cin >> A[i + 1];
    
    
    int ok = N, ng = 0;
    while (ok - ng > 1) {
        stack<pii> U;
        int lim = (ok + ng) / 2;
        bool res = true;
        for (int i = 1; i <= N; ++i) {
            if (A[i] > A[i - 1]) {
                U.push({ 1, A[i] - A[i - 1] });
            } else {
                int cnt = A[i - 1] - A[i];
                while (cnt > 0) {
                    int &num = U.top().second;
                    int dec = min(cnt, num);
                    num -= dec;
                    cnt -= dec;
                    if (num == 0)U.pop();
                }
                assert(cnt == 0);
                while (!U.empty() && U.top().first == lim) {
                    cnt += U.top().second;
                    U.pop();
                }
                if (U.empty()) {
                    res = false;
                    break;
                }

                int last = U.top().first;
                if (--U.top().second == 0) {
                    U.pop();
                }
                U.push({ last + 1,1 });
                if (cnt > 0) {
                    U.push({ 1, cnt });
                }
            }
        }
        (res ? ok : ng) = lim;
    }

    cout << ok << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 2752
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define trav(x,c) for(auto &x:c)
using namespace std;

int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int sum(int x) {
  int s = 0;
  while(x) {
    s += x%10;
    x /= 10;
  }
  return s;
} 

int main() {
  int h,w;
  cin>>h>>w;
  string a[h];
  frn(i,h) cin>>a[i];
  int ans[h][w];
  memset(ans,0,sizeof ans);
  int di[] = {-1,-1,-1,0,0,1,1,1};
  int dj[] = {-1,0,1,-1,1,-1,0,1};
  frn(i,h) {
    frn(j,w) {
      if(a[i][j]=='#') {
        frn(d,8) {
          int x = i+di[d];
          int y = j+dj[d];
          if(x >= 0 && x < h && y >= 0 && y < w && a[x][y]=='.') ans[x][y]++;
        }
      }
    }
  } 
  frn(i,h){
    frn(j,w) {
      if(a[i][j]=='.')cout<<ans[i][j];
      else cout<<a[i][j];
    }
    nl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] heights = new int[N];
        for (int i=0; i<N; i++){
            heights[i]= sc.nextInt();
        }
        int[] cost = new int[N];
        cost[1]= Math.abs(heights[1]-heights[0]);
        for (int i=2; i<N; i++){
            cost[i] = Math.min(cost[i-1] + Math.abs(heights[i-1]-heights[i]), cost[i-2] + Math.abs(heights[i-2]-heights[i]));
        }
        System.out.println(cost[N-1]);
    }

}

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

int main() {
  int n;
  cin >> n;
  vector<int> a;
  int temp;
  rep(i,n){ 
    cin >> temp;
    a.push_back(temp);
  }
  vector<int> left(n,0), right(n,0);
  left[0] = a[0];
  right[n-1] = a[n-1];
  for(int i=1; i<n; i++){
    left[i] = (max(left[i-1],a[i]));
  }
  for(int i=n-2; i>=0; i--){
    right[i] = max(right[i+1],a[i]);
  }

  vector<int> ans(n,0);
  ans[0] = right[1];
  ans[n-1] = left[n-2];
  for(int i=1; i<n-1; i++){
    ans[i] = max(left[i-1],right[i+1]);
  }
  rep(i,n){
    cout << ans[i] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 4980
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,n,s) for(int i=(int)(s);i<(int)(n);++i)
#define RREP(i,n,s) for(int i=(int)(s);i>=(int)(n);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int n;cin>>n;
    if (n == 10 || n == 100 || n== 1000|| n== 10000 || n==100000) {
        cout << 10 << endl;
        return 0;
    }
    int res = 0;
    while(n >= 1) {
        res += n % 10;
        n /=10;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;


int main(){

	int e,minimum;

	while(true){
		scanf("%d",&e);
		if(e == 0)break;

		minimum = 10000000;

		for(int z = 0; z*z*z <= e;z++){
			for(int y = 0; y*y <= e-z*z*z; y++){
				minimum = min(minimum,y+z+(e-(z*z*z+y*y)));
			}
		}
		printf("%d\n",minimum);
	}
	return 0;
}

Measured memory_bytes: 2512
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

var graph [][]int
var dist [][]int

func main() {
	sc.Split(bufio.ScanWords)
	n, x, y := readInt(), readInt(), readInt()
	x--
	y--

	graph = make([][]int, n)
	for i := 0; i < n; i++ {
		graph[i] = make([]int, 0)
		if i+1 < n {
			graph[i] = append(graph[i], i+1)
		}
		if i-1 >= 0 {
			graph[i] = append(graph[i], i-1)
		}
	}
	graph[x] = append(graph[x], y)
	graph[y] = append(graph[y], x)

	counter := make(map[int]int, 0)

	for sv := 0; sv < n; sv++ {
		queue := make([]int, 1)
		queue[0] = sv

		dist := make([]int, n)
		for i := 0; i < n; i++ {
			dist[i] = -1
		}
		dist[sv] = 0

		for len(queue) > 0 {
			v := queue[0]
			queue = queue[1:]

			for _, nextv := range graph[v] {
				if dist[nextv] == -1 {
					queue = append(queue, nextv)
					dist[nextv] = dist[v] + 1
					counter[dist[nextv]]++
				}
			}
		}
	}
	for i := 1; i < n; i++ {
		fmt.Println(counter[i] / 2)
	}
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


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

using namespace std;
int a[200005];
int main() {
#ifdef LDT
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    sort(a + 1, a + 1 + n);
    long long res = 0;
    for (int i = 1; i <= n - k; ++i)
        res += a[i];
    cout << res;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  ll minigcd;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    if(i > 0) {
      minigcd = gcd(minigcd, a[i]);
    } else {
      minigcd = a[i];
    }
  }

  if(k <= *max_element(a.begin(), a.end()) && k % minigcd == 0) {
    cout << "POSSIBLE\n";
  } else {
    cout << "IMPOSSIBLE\n";
  }
  return 0;
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  cin.ignore();

  map <string, int> mp;

  string str;
  for(int i = 0; i < n; i++){
    cin >> str;
    cin.ignore();
    if(mp.find(str) == mp.end()){
      mp.insert(make_pair(str, 1));
    } 
  }

  cout << mp.size() << endl;
  return 0;
}
  


Measured memory_bytes: 19224
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int bipartiteMaximumMatchings(const vector<vector<bool> >& graph)
{
    int ret = 0;
    int n = graph.size();
    int m = graph[0].size();
    vector<int> selectN(n, -1);
    vector<int> selectM(m, -1);

    for(int i=0; i<n; ++i){
        vector<bool> visitedN(n, false);
        vector<bool> visitedM(m, false);
        visitedN[i] = true;
        vector<int> path(min(n,m)*2, -1);

        path[0] = i;
        int index = 1;
        for(;;){
            while(++path[index] < m && (!graph[path[index-1]][path[index]] || selectN[path[index-1]]==path[index] || visitedM[path[index]]));
            if(path[index] < m){
                if(selectM[path[index]] == -1){
                    for(int j=0; j<index; j+=2){
                        selectN[path[j]] = path[j+1];
                        selectM[path[j+1]] = path[j];
                    }
                    ++ ret;
                    break;
                }
                if(!visitedN[selectM[path[index]]]){
                    path[index+1] = selectM[path[index]];
                    visitedM[path[index]] = true;
                    visitedN[path[index+1]] = true;
                    index += 2;
                }
            }
            else{
                path[index] = -1;
                index -= 2;
                if(index < 0)
                    break;
            }
        }

        if(ret == m)
            break;
    }

    return ret;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n), d(n);
    for(int i=0; i<n; ++i)
        cin >> a[i] >> b[i];
    for(int i=0; i<n; ++i)
        cin >> c[i] >> d[i];

    vector<vector<bool> > v(n, vector<bool>(n));
    for(int i=0; i<n; ++i){
        for(int j=0; j<n; ++j){
            v[i][j] = (a[i] < c[j] && b[i] < d[j]);
        }
    }
    cout << bipartiteMaximumMatchings(v) << endl;

    return 0;
}


Measured memory_bytes: 256
N,D = gets.split.map &:to_i
X = Array.new(N){gets.split.map &:to_i}

count = 0
for i in 0..(N-2)
  for j in (i+1)..(N-1)
    sum = 0
    for k in 0..(D-1)
      sum += (X[i][k] - X[j][k])**2
    end
    if Math.sqrt(sum).to_i**2 == sum
      count += 1
    end
  end
end

puts count

Measured memory_bytes: 1788
count = 0
get_string = gets.chomp
sl = get_string.length
  
# 最初がBなら1
count_b = get_string[0] == 'B' ? 1 : 0

(1..sl-1).each do |num|
  if get_string[num] == 'B'
    count_b += 1
    next
  end

  # Bの文字数を足す
  count += count_b
end

puts count


Measured memory_bytes: 2172