akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int INF = 1e9 + 5;

int main(){
	
	int n;
    scanf("%d", &n);
    vector<int> fill(n);
    for(int& x : fill) {
        scanf("%d", &x);
    }
    vector<int> dp(n, INF);
    dp[0] = 0;
	dp[1] = abs(fill[1]-fill[0]);
	
	for(int i=2;i<n;i++){
		dp[i] = min(dp[i-2]+abs(fill[i-2]-fill[i]),dp[i-1]+abs(fill[i-1]-fill[i]));
	}
	
    printf("%d\n", dp[n-1]);
	
	return 0;
}


Measured memory_bytes: 1024
using System;
using System.Linq;
using static System.Console;
using static System.Math;

namespace abc80_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[][] f = new int [n][];
            int[][] p = new int [n][];

            for(int i=0; i<n; i++){
                int[] tmp = ReadLine().Split().Select(int.Parse).ToArray();
                f[i] = tmp;
            }
            for(int i=0; i<n; i++){
                int[] tmp = ReadLine().Split().Select(int.Parse).ToArray();
                p[i] = tmp;
            }

            int max = int.MinValue;
            for(int i=1; i<(1<<10); i++){ //bit全探索
                int cc = 0;
                for(int j=0; j<n; j++){
                    int c=0;
                    for(int k=0; k<10; k++){
                        if( ((i>>k&1) == 1) && f[j][k] == 1) c++;
                    }
                    cc += p[j][c];
                }
                max = Max(max, cc);
            }
            WriteLine(max);
        }
    }
}

Measured memory_bytes: 13396
N, M = map(int, input().split())

problems = [0] * N
ans = [0, 0]

for _ in range(M):
    p, S = input().split()
    i = int(p) - 1
    if problems[i] == -1:
        continue
    if S == "WA":
        problems[i] += 1
    else:
        ans[0] += 1
        ans[1] += problems[i]
        problems[i] = -1

print(" ".join(map(str, ans)))


Measured memory_bytes: 3828
import java.util.*;
public class Main {

	public static void main(String[] args) {
		int n,max,min;
		long sum;
		Scanner scan = new Scanner(System.in);
		n=scan.nextInt();
		sum=max=min=scan.nextInt();
		for(int i=2;i<=n;i++){
			int temp = scan.nextInt();
			sum += temp;
			if(max<temp)
				max=temp;
			if(min>temp){
				min=temp;
			}
		}
		System.out.println(min + " " + max + " " + sum);
	}
}



Measured memory_bytes: 41836
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int dp[110][10010]={0};
int main(){
	int n,W;
	cin>>n>>W;
	vi v(n),w(n);
	rep(i,n)cin>>v[i]>>w[i];
	vi dp(W+1);
	rep(i,n)rep(j,W-w[i]+1)cmax(dp[j+w[i]],dp[j]+v[i]);
	cout<<dp[W]<<endl;
}

Measured memory_bytes: 3108
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,X = inpl()
a = inpl()
f = [False] * n
for x in a:
    f[x] = True
print(min(sum(f[:X]), sum(f[X:])))


Measured memory_bytes: 77300
#include <iostream>
#include <vector>

int main()
{
    int A, B;
    std::cin >> A >> B;
    if (A < 1 || 9 < A || B < 1 || 9 < B) {
        std::cout << -1 << std::endl;
    } else {
        std::cout << A*B << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define long long long
#define read cin >>
#define echo cout <<
#define fin << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  int n, k;
  read n >> k;
  vector<int> data(n);
  REP(i, n) {
    int tmp;
    read tmp;
    data.push_back(tmp);
  }
  sort(data.begin(), data.end());
  reverse(data.begin(), data.end());
  long ans = 0;
  FOR(i, k, n) { ans += data[i]; }
  echo ans fin;
}


Measured memory_bytes: 1792
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

typedef pair<int, int> Edge;

int main() {
  int h, w; cin >> h >> w;
  vector<Edge> G[10];
  loop(i,0,10) loop(j,0,10) {
    int w; cin >> w;
    if (w > 0) G[j].emplace_back(i, w);
  }
  const int INF = 1000000000;
  vector<int> D(10, INF);
  {
    vector<bool> done(10, false);
    priority_queue<pair<int, int> > Q;
    Q.push({ 0, 1 });
    D[1] = 0;
    while (Q.size()) {
      auto p = Q.top(); Q.pop();
      int v = p.second;
      if (done[v]) continue;
      done[v] = true;
      for (auto &&edge: G[v]) {
        int u = edge.first, w = edge.second;
        if (D[u] > D[v] + w) {
          D[u] = D[v] + w;
          Q.push({ -D[u], u });
        }
      }
    }
  }
  
  ll ans = 0;
  loop(y,0,h) loop(x,0,w) {
    int a; cin >> a;
    if (a == -1) continue;
    ans += D[a];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;

#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif
#define out(v) cout<<v<<"\n"
#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload3(__VA_ARGS__,42,_all2,_all1,)(__VA_ARGS__)
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
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; }
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

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

  if (N % 2)
    cout << 0 << "\n";
  else {
    ll n = N / 2;
    ll ans = 0;
    rep(i, 100) {
      if (n <= 0)
        break;
      n /= 5;
      ans += n;
    }
    cout << ans << "\n";
  }

  return 0;
}


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

int main() {
  int n, t, a;
  cin >> n >> t >> a;
  vector<double> kion(n);
  for (int i = 0; i < n; i++) {
    int h;
    cin >> h;
    kion.at(i) = (double)t - (double)(3 * h) / (double)500;
  }
  
  double ans = abs(a - kion.at(0));
  int count = 1;
  for (int i = 1; i < n; i++) {
    if (ans > abs(a - kion.at(i))) {
      ans = abs(a - kion.at(i));
      count = i + 1;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N, sum = 0;
  cin >> N;
  for(int i = 1; i < N+1; i++) if(i % 15 == 0 || i % 3 == 0 || i % 5 == 0) continue;
  else sum += i;
  cout << sum << endl;
}

Measured memory_bytes: 3556
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define FOREQ(i, s, n) for (ll i = (s); i <= (ll)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

typedef vector<ll> Array;
typedef vector<Array> Matrix;
const ll MOD = 1e+9 + 9;
ll w, h, n;
ll m;
ll field[100][100];
ll Y[100];
ll ys[100];
ll xs[100];
Matrix p2[100];

void PrintMatrix(const Matrix &mat) {
  REP(y, mat.size()) {
    REP(x, mat[y].size()) {
      printf("%lld ", mat[y][x]);
    }
    puts("");
  }
  puts("");
}

Matrix Mul(const Matrix &lhs, const Matrix &rhs) {
  const ll h = lhs.size();
  const ll in = lhs[0].size();
  const ll w = rhs[0].size();
  assert(lhs[0].size() == rhs.size());
  Matrix ret(h, Array(w, 0));
  REP(y, h) REP(i, in) REP(x, w) {
    ret[y][x] = (ret[y][x] + lhs[y][i] * rhs[i][x]) % MOD;
  }
  return ret;
}

void Make(ll n) {
  p2[0] = Matrix(n, Array(n, 0));
  p2[1] = Matrix(n, Array(n, 0));
  REP(x, n) {
    p2[0][x][x] = 1;
    FOREQ(dx, -1, 1) {
      if (0 <= x + dx && x + dx < n) { p2[1][x][x + dx] = 1; }
    }
  }
  FOREQ(i, 1, 64) { p2[i + 1] = Mul(p2[i], p2[i]); }
}

void PowMod(ll power, Matrix &vect) {
  ll index = 0;
  while (power > 0) {
    if (power & 1) { vect = Mul(p2[index + 1], vect); }
    index++;
    power >>= 1;
  }
}

int main() {
  int test_case = 0;
  while (scanf("%lld %lld %lld", &w, &h, &n), w|h|n) {
    test_case++;
    Make(w);
    MEMSET(field, 0);
    {
      set<ll> open;
      open.insert(0);
      open.insert(h - 1);
      REP(i, n) {
        scanf("%lld %lld", &xs[i], &ys[i]);
        xs[i]--; ys[i]--;
        while (xs[i] < 0 || xs[i] >= w || ys[i] < 0 || ys[i] >= h) {
          continue;
        }
        open.insert(ys[i] - 1);
        open.insert(ys[i]);
        open.insert(ys[i] + 1);
      }
      map<ll, ll> mapto;
      m = 0;
      FORIT(it, open) {
        if (*it < 0 || *it >= h) { continue; }
        Y[m] = *it;
        mapto[*it] = m++;
      }
      REP(i, n) {
        field[mapto[ys[i]]][xs[i]] = 1;
      }
    }
    Matrix prev(w, Array(1, 0));
    prev[0][0] = 1;
    REP(y, m - 1) {
      Matrix next(w, Array(1, 0));
      if (Y[y + 1] - Y[y] == 1) {
        REP(x, w) {
          FOREQ(dx, -1, 1) {
            if (x + dx < 0 || x + dx >= w) { continue; }
            if (field[y + 1][x + dx] == 1) { continue; }
            next[x + dx][0] += prev[x][0];
          }
        }
      } else {
        next = prev;
        PowMod(Y[y + 1] - Y[y], next);
      }
      prev = next;
    }
    printf("Case %d: %lld\n", test_case, prev[w - 1][0]);
  }
}

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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000001
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<int, int>

int main() {
  int n;
  cin >> n;
  ll a[n];
  REP(i, n) cin >> a[i];
  sort(a, a+n);
  ll ans = 0;
  if(n%2 == 0){
    REP(i, n/2) ans -= a[i]*2;
    ans += a[n/2-1];
    REP(i, n/2) ans += a[i+n/2]*2;
    ans -= a[n/2];
  }
  else{
    ll ans1 = 0, ans2 = 0;
    REP(i, (n+1)/2) ans1 -= 2*a[i];
    ans1 += a[(n-1)/2] + a[(n-3)/2];
    REP(i, (n-1)/2) ans1 += 2*a[i+(n+1)/2];
    REP(i, (n-1)/2) ans2 -= 2*a[i];
    REP(i, (n+1)/2) ans2 += 2*a[i+(n-1)/2];
    ans2 -= a[(n-1)/2] + a[(n+1)/2];
    ans = (ans1>ans2?ans1:ans2);
  }
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if(a + c == 2*b) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}

	}

}


Measured memory_bytes: 23252
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#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--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;



typedef struct union_find{
    
    vector<ll> pa;//親
    vector<ll> ra;//木の深さ
    vector<ll> siz;
    //n要素で初期化
    void init(ll n){
        pa.resize(n);
        ra.resize(n);
        siz.resize(n);
        for(ll i = 0;i < n;i++){
            pa[i] = i;/*各ノードに番号を振る,この時par[x]=xとなる時は木の根となる*/
            ra[i] = 0LL;/*各ノード自体の高さは0*/
            siz[i] = 1LL;
        }
    }
    //木の根を求める
    ll find(ll x){
        if(pa[x] == x){
            return x;/*根ならそのノードの番号を返す*/
        }else{
            return pa[x] = find(pa[x]);/*根でないならさらにノードの根を探す*/
        }
    }

    //xとyの属する集合を併合する
    void unite(ll x,ll y){
        x = find(x);//xの根の番号を探す
        y = find(y);//yの根の番号を探す
        if(x == y){//一致すればつながっている
            return;
        }
        pa[y] = x;
        siz[x] += siz[y];
        /*if(ra[x] < ra[y]){//xの高さが低いなら高いほうにつなぐ、そして高さは大きい方(y)になる
        }else{
            pa[y] = x;//yの高さが低いなら高いほうにつなぐ、そして高さは大きいほう(x)になる
            siz[x] += siz[y];
            if(ra[x] == ra[y]){//高さが一致しているなら併合の高さは1増える
                ra[x]++;
            }
        }*/
    }

    //xとyが同じ集合に属するか判定
    bool same(ll x,ll y){
        return find(x) == find(y);//同じ集合なら1、違うなら0が返る
    }
}UF;


int main(){

    ll n,m;
    cin >> n >> m;
    UF tree;
    tree.init(n);

    vector<ll> a(m),b(m);
    for(ll i = 0;i < m;i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    vector<ll> ans;
    ans.push_back((n*(n-1))/2);

    ll tmp = (n*(n-1))/2;

    for(ll i = m-1;i >= 0;i--){

        if(tmp == 0){
            ans.push_back(0);
            continue;
        }
        ll diff1 = tree.siz[tree.find(a[i])];
        ll diff2 = tree.siz[tree.find(b[i])];
        if(tree.same(a[i],b[i])){
            ans.push_back(tmp);
            tree.unite(a[i],b[i]);
            continue;
        }
        tree.unite(a[i],b[i]);
        //a←bにつなげる
        if(diff1 == 1LL && diff2 == 1LL){
            //両方1個ずつしかない場合
            tmp--;
        }else{
            ll node = tree.siz[tree.find(a[i])];//つなげた後のノードの個数
            tmp = tmp - ((node*(node-1))/2  - (diff1*(diff1-1))/2 - (diff2*(diff2-1))/2 );
        }
        ans.push_back(tmp);
    }

    for(int i = ans.size()-2;i >= 0;i--){
        cout << ans[i] << endl;
    }


    return 0;
}


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

#define int long long

const int N = 1e2 + 10, M = 32e3 + 10, mod = 1e9 + 7;
int n, k, ans, dp[3][M], total, psum[M];

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	
	int sq = 1;
	while (sq * sq <= n)
		sq++;
	
	dp[0][0] = 1;
	for (int i = 0; i < sq; i++)
		psum[i] = 1;
	for (int i = 1; i < sq; i++)
		dp[1][i] = 1;
	total = sq - 1;
	
	for (int i = 2; i <= k; i++) {
		int now = (i % 3), prv = (now + 2) % 3, ppr = (now + 1) % 3;
		
		int tmp = 0;
		for (int z = 2; z < sq; z++)
			tmp = (tmp + dp[ppr][z] * (n / z - sq + 1) % mod) % mod;
		
		for (int j = 1; j < sq; j++) {
			int add = (n / j - sq + 1) * psum[j] % mod;
			dp[now][j] = (total + tmp + add) % mod;
			
//			cout << i << ' ' << j << " : " << dp[now][j] << ' ' << tmp << ' ' << add << endl;
			tmp = (tmp - dp[ppr][j + 1] * (n / (j + 1) - sq + 1) % mod) % mod;
		}
			
		psum[0] = total = 0;
		for (int j = 1; j < sq; j++)
			total = (total + dp[now][j]) % mod;
		for (int j = 1; j < sq; j++)
			psum[j] = (psum[j - 1] + dp[prv][j]) % mod;
	}
	
	for (int i = 1; i < sq; i++) {
		ans = (ans + dp[k % 3][i]) % mod;
		ans = (ans + dp[(k + 2) % 3][i] * (n / i - sq + 1) % mod) % mod;
	}
	cout << (ans + mod) % mod << endl;
}

Measured memory_bytes: 1280
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int k = 0;
		for ( int i=0; i<n; i++ ) {
			int d1 = sc.nextInt();
			int d2 = sc.nextInt();

			if ( d1==d2 ) {
				k++;
				if ( k>=3 ) {
					System.out.println("Yes");
					System.exit(0);
				}
			} else {
				k = 0;
			}
		}

		System.out.println("No");
	}
}

Measured memory_bytes: 36008
N = int(input())
S = input()

def foo(alphabet, n):
    NUM_OF_ALPHABETS = 26
    diff = ord(alphabet) - ord('A')
    index = (diff + n) % NUM_OF_ALPHABETS
    result = chr(ord('A') + index)

    return result


def calculate(str, n):
    calculated = ''.join([foo(alphabet, n) for alphabet in str])

    return calculated

answer = calculate(S, N)

print(answer)


Measured memory_bytes: 3060
#include <stdio.h>
#include <cstdio>
#include <string>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>


int main()
{

	long long int Q, H, S, D, N;

	scanf("%lld%lld%lld%lld%lld", &Q, &H, &S, &D, &N);

	long long int OneMin;

	OneMin = std::min(Q * 4, std::min(H * 2, S));

	printf("%lld\n", N / 2 * std::min(OneMin * 2, D) + (N % 2) * OneMin);



	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N+1];
		for(int i=0; i<N; i++) {
			A[i] = sc.nextInt();
		}
		
		// for文内での判定で次の数と自分が同じかの比較があるので
		// 範囲外の値（ソート後に最大値になるように）を入れておく
		A[N] = 1000001; 
		
		Arrays.sort(A);
		boolean[] check = new boolean[1000001]; // 数列に含まれる最大値まで判定用の配列を用意
		Arrays.fill(check, true);
		int ans = 0;
		// 小さい順から、割り切れるか判定していく
		for (int i = 0; i < N; i++) {
			// 数列の次の値が自身と同じではなく、自身の約数が数列に存在していなければ、カウントを増やす
			if (A[i + 1] != A[i] && check[A[i]]) {
				ans++;
			}
			// 自分が割り切ることのできる数（自分の倍数）について、判定用の数列をfalseにする
			for (int j = A[i]; j <= A[N - 1]; j += A[i]) {
				check[j] = false;
			}
		}
		System.out.println(ans);



	}
}

/*　学んだこと
 * 
 *　事前にあり得る範囲の配列を用意しておくことで、２重ループを避けることができる！
 * 
*/


Measured memory_bytes: 62020
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		int num[5001];
		for(int i = 0; i < n; i++){
			cin>>num[i];
		}
		
		int dp[5001];
		dp[0]=num[0];
		int maxNum=(
			dp[0]);
		for(int i = 1; i < n; i++){
			dp[i]=max(num[i],dp[i-1]+num[i]);
			maxNum=max(maxNum,dp[i]);
		}
		cout<<maxNum<<endl;
		
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <math.h>
#include <limits>

template <typename T>
void vc(T t) {
    std::cout << t << " ";
}

template<typename T, typename... Args>
void vc(T t, Args... args) {
// recursive variadic function
    std::cout << t << " ";
    vc(args...) ;
}

const int N = 1;
int a[N];
void once() {
  int a;
  std::cin >> a;
  std::set<std::string> s;
  for (int i = 0; i < a; ++i) {
    std::string s2;
    std::cin >> s2;
    s.insert(s2);
  }
  std::cout << s.size() << std::endl;
}

int
main() {
  int n = 1;
  std::ios::sync_with_stdio(false);
  // std::cin >> n;
  while (n--) {
    once();
  }
}

Measured memory_bytes: 15644
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int parse[100010][21];
int n;
int a[100010];
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
	}
	a[n+1] = 1234567890;
	int q;
	scanf("%d", &q);
	for (int i = 1; i <=n; i++)
	{
		int t = upper_bound(a, a + n+1, a[i] + q) - a;
		parse[i][0] = t - 1;
	}
	for (int i = 1; i < 21; i++)
	{
		for (int y = 1; y <=n; y++)
			parse[y][i] = parse[parse[y][i - 1]][i - 1];
	}
	int o;
	scanf("%d", &o);
	while (o--)
	{
		int w, e;
		scanf("%d %d", &w, &e);
		if (w > e)
			swap(w, e);
		int dap = 0;
		for (int i = 20; i >= 0; i--)
		{

			if (parse[w][i] == 0)continue;
			if (parse[w][i] < e)
			{
				dap += (1 << i);
				w = parse[w][i];
			}
		}
		dap++;
		printf("%d\n", dap);
	}
}

Measured memory_bytes: 9344
#include<stdio.h>
#define g -3
#define w -2
#define b -1
 
int temp[101],d[101],f[101];
int time,N;
int A[101][101];
 void DFS();
 void DFSvisit(int u){
  int v;
  temp[u]=g;
  time++;
  d[u]=time;
 
  for(v=1;v<=N;v++){
    if(A[u][v]==0){
      continue;
    }
    if(temp[v]==w){
      DFSvisit(v);
    }
  }  
    temp[u] = b;
  f[u] = ++time;
}
 
void DFS(){
  int i;
  for(i=1;i<=N;i++){
    temp[i] = w;
  }
   time=0;
   for(i=1;i<=N;i++){
    if(temp[i]==w){
      DFSvisit(i);
    }
  }
}
 int main (){
  int i,j,k,n,u;
 
  for(i=1;i<101;i++){
    for(j=1;j<101;j++){
      A[i][j] = 0;
    }
  }
 
  scanf("%d",&N);
 
  for(i=1;i<=N;i++){ 
    scanf("%d %d",&n,&k); 
    for(j=1;j<=k;j++){
      scanf("%d",&u);
      A[n][u]=1;
    }
  }
   DFS();
   for(i=1;i<=N;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
 
  return 0;
}

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

#define ll   long long int
#define rep(i,n)    for(int i=0;i<(int)n;i++)
#define show(s)     cout<<s<<endl

int main() {

    string S;
    cin >> S;

    int ans1 = 0;
    int ans2 = 0;

    int N = S.size();

    rep(i,N){
        if(i%2){
            if(S[i] != '0') ans1++;
            else            ans2++;
        }else{
            if(S[i] != '1') ans1++;
            else            ans2++;
        }
    }

    show(min(ans1,ans2));

    return 0;
}


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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int, int>;
const ll mod = 1e9+7;

struct Edge {
  int id, to;
  Edge(int id, int to): id(id), to(to) {}
};

vector<vector<Edge>> g(51);
ll path;

bool dfs(int v, int to, int p=0) {
  if(v==to) {
    path = 0;
    return true;
  }
  for(auto edge: g[v]) {
    if(edge.to==p) continue;
    if(dfs(edge.to, to, v)) {
      path |= 1ll<<edge.id;
      return true;
    }
  }
  return false;
}

int main(int argc, char const* argv[])
{
  int n;
  cin>>n;
  REP(i,n-1) {
    int a, b;
    cin>>a>>b;
    g[a].emplace_back(i, b);
    g[b].emplace_back(i, a);
  }

  int m;
  cin>>m;
  vector<ll> paths;
  REP(i,m) {
    int u, v;
    cin>>u>>v;
    dfs(u, v);
    paths.push_back(path);
  }

  ll ans = 0;
  for(ll i=0; i<1ll<<m; i++) {
    ll constraint = i;
    int constraint_count = __builtin_popcountll(constraint);
    ll white = 0;
    while(constraint) {
      int pos = ffsll(constraint)-1;
      white |= paths[pos];
      constraint-=constraint&(-constraint);
    }
    int white_count = __builtin_popcountll(white);
    ll total = 1ll<<(n-1-white_count);
    if (constraint_count&1) ans-=total;
    else ans+=total;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

#include <atcoder/twosat>

int main() {
	int N, D;
	scanf("%d %d", &N, &D);
	vector<int> X(N), Y(N);
	REP(i, N) scanf("%d %d", &X[i], &Y[i]);
	
	atcoder::two_sat sat(N);
	REP(i, N) FOR(j, i + 1, N) {
		if (abs(X[i] - X[j]) < D) sat.add_clause(i, true, j, true);
		if (abs(X[i] - Y[j]) < D) sat.add_clause(i, true, j, false);
		if (abs(Y[i] - X[j]) < D) sat.add_clause(i, false, j, true);
		if (abs(Y[i] - Y[j]) < D) sat.add_clause(i, false, j, false);
	}
	
	if (!sat.satisfiable()) {
		puts("No");
		return 0;
	}
	puts("Yes");
	auto ans = sat.answer();
	REP(i, N) printf("%d\n", ans[i] ? Y[i] : X[i]);
	return 0;
}


Measured memory_bytes: 3848
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	elems, err := nextInts(n, sc)
	if err != nil {
		panic(err)
	}
	pivotInd := partition(elems, 0, len(elems)-1)
	printlnInts(elems[:pivotInd], elems[pivotInd], elems[pivotInd+1:])
}

func partition(elems []int, p int, r int) int {
	pivot := elems[r]
	i := p - 1
	for j := p; j < r; j++ {
		if elems[j] <= pivot {
			i++
			elems[i], elems[j] = elems[j], elems[i]
		}
	}
	elems[i+1], elems[r] = elems[r], elems[i+1]
	return i + 1
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func nextInts(n int, sc *bufio.Scanner) ([]int, error) {
	rs := make([]int, n)
	for i, _ := range rs {
		x, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		rs[i] = x
	}
	return rs, nil
}

func printlnInts(left []int, pivot int, right []int) {
	rs := make([]string, len(left)+1+len(right))
	for i, v := range left {
		rs[i] = strconv.Itoa(v)
	}
	rs[len(left)] = "[" + strconv.Itoa(pivot) + "]"
	for i, v := range right {
		rs[i+len(left)+1] = strconv.Itoa(v)
	}
	fmt.Println(strings.Join(rs, " "))
}



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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int x=(c-1)/b+1;//a
  int y=(a-1)/d+1;//t
  if (x>y) cout << "No" << endl;
  else cout << "Yes" << endl;

}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};


int main(){
	ll dp[M]={};
	int n,h;
	cin>>n;
	int a,b,c;
	if(n==1){
		cin>>h;
		print(0);
	}else if(n==2){
		cin>>h;a=h;
		cin>>h;b=h;
		print(abs(a-b));
	}else{
		cin>>h;a=h;
		cin>>h;b=h;
		cin>>h;c=h;
		dp[2]=abs(a-b);
		dp[3]=min(abs(a-c)+dp[1],abs(b-c)+dp[2]);
		rep(i,4,n+1){
			cin>>h;
			a=b,b=c,c=h;
			dp[i]=min(abs(a-c)+dp[i-2],abs(b-c)+dp[i-1]);
		}
		cout<<dp[n]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			int[] s = new int[n];
			for(int i=0;i<n;i++) s[i] = sc.nextInt();
			Arrays.sort(s);
			int sum = 0;
			for(int i=1;i<n-1;i++) sum += s[i];
			System.out.println(sum / (n-2));
		}
		sc.close();
	}
}

Measured memory_bytes: 20944
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}


int main(){
  ll i,j,N,M,X;
  cin>>N>>M>>X;
  vector<ll> v(N+1,0);
  rep(i,M){
    cin>>j;
    v[j]++;
  }
  rep1(i,N+1){
    v[i]+=v[i-1];
  }
  cout<<min(v[X]-v[0],v[N]-v[X])<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
struct tree {int p,l,r;};
using namespace std;
vector<int> g;
int n,l;
tree a[200000];
void dfs(int a0,int h){
  if(!~a[a0].l^!~a[a0].r) g.push_back(l-h);
  if(~a[a0].l) dfs(a[a0].l,h+1);
  if(~a[a0].r) dfs(a[a0].r,h+1);
}
signed main(){
  int r=1,cnt=1;
  char c;
  cin>>n>>l;scanf("%c",&c);
  for(int i=0;i<200000;i++) a[i].p=a[i].l=a[i].r=-1;
  for(int i=0;i<n;i++){
    int whe=0;
    for(;scanf("%c",&c)&&c!='\n';){
      if(c=='0'){
	if(!~a[whe].l) a[whe].l=cnt,a[cnt].p=whe,cnt++;
	whe=a[whe].l;
      }
      else{
	if(!~a[whe].r) a[whe].r=cnt,a[cnt].p=whe,cnt++;
	whe=a[whe].r;	
      }
    }
  }
  dfs(0,0);
  if(g.empty()) cout<<"Bob"<<endl;
  else{
    for(;!(g[0]%(r*2));r*=2);
    for(int i=1;i<(int)g.size();i++){
      int b=1;
      for(;!(g[i]%(b*2));b*=2);
      r^=b;
    }
    cout<<(r?"Alice":"Bob")<<endl;
  }
  return 0;
}

Measured memory_bytes: 10484
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;



int main()
{
    int s;
    cin >> s;
    set<int> show;
    while (!show.count(s))
    {
        show.insert(s);
        if (s & 1) s = s * 3 + 1;
        else s /= 2;
    }
    cout << show.size() + 1 << endl;
}


Measured memory_bytes: 256
N, Y = map(int, input().split())

flag = False
for a in range(N+1):
	for b in range(N+1-a):
		if 10000 * a + 5000 * b + 1000 * (N - a - b) == Y:
			print(a, b, N-a-b)
			flag = True
			break
	if flag:
		break

if flag == False:
	print(-1, -1, -1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
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; }
const int MOD = 998244353;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

int main() {
    int N;
    cin >> N;
    ll ans = 0;
    map<ll, int> save;
    for (int i = 0; i < N; i++) {
        int temp;
        cin >> temp;
        save[temp]++;
        ans += temp;
    }
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        ll B, C;
        cin >> B >> C;
        ll dif = (C - B) * save[B];
        int cnt = save[B];
        save.erase(B);
        save[C] += cnt;
        ans += dif;
        cout << ans << endl;
    }
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

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

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif
	for(string s;cin>>s;){
		cout<<(count(all(s),'9')?"Yes":"No")<<endl;
	}
}


Measured memory_bytes: 256
// ~/BAU/ACM-ICPC/Teams/Rampage/Abukhadijah
// ~/Remember,remember the 6th of March
#include <functional>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include<complex>
#include <unordered_map>
#include<unordered_set>
#include <numeric>
#include <string>
#include<iostream>
#include <fstream>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include<cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
using namespace std;
const double PI = acos(-1.0);
const double  EPS = 1e-11;
typedef long long ll;
const ll MOD = 1000000007;
const int N = 100000;
typedef unsigned long long ull;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
void fast()
{
	std::ios_base::sync_with_stdio(0);
}
int main()
{
	ll n, x, cnt = 0;
	scanf("%lld", &n);
	ll sum = 0;
	unordered_map<ll, ll>ump;
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &x);
		sum += x;
		if (sum == 0)
			cnt++;
		if (ump.find(sum) != ump.end())
			cnt += ump[sum];
		ump[sum]++;
	}
	printf("%lld\n", cnt);
	return 0;
}

Measured memory_bytes: 8520
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<int> cnt(m);
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int city;
			cin >> city;
			cnt[city - 1]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < m; i++)
		if (cnt[i] == n)
			ans++;
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3588
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <deque>
#include <unordered_set>
#include <functional>
 
using namespace std;

int main() {
    string s;
    cin>>s;
    if (s.size()%2!=0){
        cout<<"No";
        return 0;
    }
    for (int i=0;i<s.size()/2;++i){
        if (s[2*i]!='h'||s[2*i+1]!='i'){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <tuple>
#include <numeric>

using namespace std;

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

    string ret = "Yes";
    int n = s.length();
    for(int i=0; i<n/2; ++i){
        if(s[i] != s[n-1-i]){
            ret = "No";
        }
    }
    for(int i=0; i<n/4; ++i){
        if(s[i] != s[n/2-1-i]){
            ret = "No";
        }
    }
    for(int i=0; i<n/4; ++i){
        if(s[n/2+1+i] != s[n-1-i]){
            ret = "No";
        }
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n,a,b;

int main(void){
	scanf("%lld%lld%lld",&n,&a,&b);
	ll dif=b-a;
	if(dif%2LL==0){
		printf("%lld\n",dif/2LL);
	}else{
		ll v1=a-1;
		ll ap=1,bp=b-(a-1);
		while((bp-ap)%2LL!=0LL){
			v1++;
			bp--;
		}
		v1+=(bp-ap)/2LL;
		ll v2=n-b;
		ap=a+v2,bp=n;
		while((bp-ap)%2LL!=0LL){
			v2++;
			ap++;
		}
		v2+=(bp-ap)/2LL;
		printf("%lld\n",min(v1,v2));
	}
	return 0;
}


Measured memory_bytes: 256
n, d = map(int, input().split())
L = []
for i in range(n):
    a = input().split()
    a = [int(j) for j in a]
    L.append(a)

A = []
for i in range(n):
    for k in range(i + 1, n):
        tmp = 0
        for j in range(d):
            tmp += (L[i][j] - L[k][j]) ** 2
        A.append(pow(tmp, 0.5))

ans = 0

for i in A:
    if i.is_integer():
        ans += 1

print(ans)


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


int main()
{
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;

	if (0 <= x - r && x + r <= w) {
		if (0 <= y - r && y + r <= h) {
			cout << "Yes" << endl;

			return 0;
		}
	}
	cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 3116
// clang-format off

#include <bits/stdc++.h>

#define int long long int
#define main signed main()
#define bye return 0
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++)
#define all(v) (v).begin(), (v).end()
#define prec(n) fixed << setprecision(n)
#define dump(x) cerr << "(L" << __LINE__ << ") " << #x << " = " << (x) << endl
#define clr(x, a) memset(x, a, sizeof(x))

#define sum(v) accumulate(all(v), 0)
#define stlice(s, l) substr(s, (s) + (l) + 1)
#define odd(n) ((n) % 2)
#define even(n) (!((n) % 2))

#define INF 1000000000
#define MOD 1000000007

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define str string
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<str>

using namespace std;

// clang-format on

main {
  int a, b, c;
  cin >> a >> b >> c;
  loop(i, 1, b - 1) {
    if ((a * i) % b == c) {
      cout << "YES" << endl;
      bye;
    }
  }
  cout << "NO" << endl;
  bye;
}


Measured memory_bytes: 256
import Control.Applicative ((<$>))
import Data.List (sort)

main :: IO ()
main = solve <$> map read <$> words <$> getLine >>= print

solve :: [Int] -> Int
solve [a1, a2, a3] = sum . take 2 . sort $ [abs (a1 - a2), abs (a2 - a3) , abs (a3 - a1)]


Measured memory_bytes: 508
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <string>
#include <set>
#include <map>
using namespace std;
using ll = long long;



int main() {
	int n,sum=0,m=99999999,a;
	cin >> n;
	vector<int> w(n);
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		sum += w[i];
	}
	for (int i = 1; i < n;i++) {
		a = 0;
		for (int j = 0; j < i; j++) {
			a += w[j];
		}
		int b = sum - a;
		m = min(m,abs(a-b));
	}
	cout << m << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int temp;
        for(int i=0; i<n; i++){
            int[] hen = new int[3];
            
            for(int j=0;j<3;j++){
                hen[j] = sc.nextInt();
            }
            for(int j=1;j<3;j++){
                for(int k=j;k>0;k--){
                    if(hen[k]>hen[k-1]){
                        temp = hen[k-1];
                        hen[k-1] = hen[k];
                        hen[k] = temp;                        
                    }
                }
            }
            
            if(hen[0]*hen[0]==hen[1]*hen[1] + hen[2]*hen[2])
                System.out.println("YES");
            else{
                System.out.println("NO");
            }
            
        }
    }
}

Measured memory_bytes: 23380
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<class T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return 1; } return 0; }

int N;
string S;
long long M, C, P;

void add (int i) {
    if (S[i] == 'M') M++;
    else if (S[i] == 'C') { C++; P += M; }
}

void erase (int i) {
    if (S[i] == 'M') { M--; P -= C; }
    else if (S[i] == 'C') C--;
}

long long solve(int K) {
    long long ans = 0;
    M = 0, C = 0, P = 0;
    int left = 0;
    for (int right = 0; right < N;) {
        while (left < N && abs(right-left) < K) add(left++);
        if (S[right] == 'D') ans += P;
        erase(right++);
    }
    return ans;
}

int main() {
    int Q;
    cin >> N >> S >> Q;
    for (int i = 0; i < Q; i++) {
        int k; cin >> k;
        cout << solve(k) << endl;
    }
    return 0;
}

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

inline bool IsMovable(const string& s, int idx, int x){
  if (idx+x>=s.size()) return false;
  return s[idx+x]=='.';
}

bool F(string& s, int& idx, char c, int target){
  if (IsMovable(s,idx,1)){
    s[idx]='.'; idx++; s[idx]=c;
    return true;
  }
  else if (IsMovable(s,idx,2) && (idx+1!=target)){
    s[idx]='.'; idx+=2; s[idx]=c;
    return true;
  }
  else
    return false;
}

int main(){
  int N,A,B,C,D;
  cin>>N>>A>>B>>C>>D;
  A--;
  B--;
  C--;
  D--;
  
  string s;
  cin>>s;
  s[A]='A';
  s[B]='B';
  
  bool is_capable=true;
  bool A_reached = false;
  bool B_reached = false;
  bool A_can_move=true;
  bool B_can_move=true;
  while(1){
    if(C>D){
      A_reached=A==C;
      B_reached=B==D;
      if (!A_reached)
      	A_can_move = F(s, A, 'A', C);
      if (!B_reached && (A_reached || !A_can_move)){
        B_can_move = F(s, B, 'B', D);
      }
    }
    else{
      A_reached=A==C;
      B_reached=B==D;
      if (!B_reached)
      	B_can_move = F(s, B, 'B', D);
      if (!A_reached && (B_reached || !B_can_move)){
        A_can_move = F(s, A, 'A', C);
      }
    }
    
    if (A_reached && B_reached){
      is_capable = true;
      break;
    }
    else if(A_reached&&!B_can_move){
      is_capable=false;
      break;
    }
    else if(B_reached&&!A_can_move){
      is_capable=false;
      break;
    }
    else if (!A_can_move && !B_can_move){
      is_capable=false;
      break;
    }
  }
  cout<< (is_capable?"Yes":"No")<<endl;
  return 0;
}

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

#define pb push_back
#define mp make_pair

#define F first
#define S second

using ll = long long;
using namespace std;

void chmin(ll &a, ll b) { if (a > b) a = b; }

const int mod = 1000000007;
const int INF = 1e+9;

int main() {
    int n; cin >> n;
    vector<ll> h(n);
    vector<ll> dp(n+1);

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


Measured memory_bytes: 1792