akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

using ll = long long;
template <ll MOD = 1000000007>
struct Mint{
    ll x;

    Mint() : x(0) {}
    Mint(ll t){
        x = t % MOD;
        if(x < 0) x += MOD;
    }
    
    Mint pow(ll n){
        Mint res(1), t(x);
        while(n > 0){
            if(n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        ll a = x, b = MOD, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint & operator += (Mint a){
        x += a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    Mint & operator -= (Mint a){
        x += MOD - a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    Mint & operator *= (Mint a){
        x = 1LL * x * a.x % MOD;
        return *this;
    }
    Mint & operator /= (Mint a){
        return (*this) *= a.inv();
    }

    Mint operator + (Mint a) const { return Mint(x) += a; }
    Mint operator - (Mint a) const { return Mint(x) -= a; }
    Mint operator * (Mint a) const { return Mint(x) *= a; }
    Mint operator / (Mint a) const { return Mint(x) /= a; }

    Mint operator - () const{ return Mint(-x); }

    bool operator == (const Mint a){ return x == a.x; }
    bool operator != (const Mint a){ return x != a.x; }
    bool operator < (const Mint a){ return x < a.x; }

    friend ostream & operator << (ostream & os, const Mint &a){
        return os << a.x;
    }

    friend istream & operator >> (istream & is, Mint &a){
        ll t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main(){
    int n;
    cin >> n;
    vector<int> vec[n];
    REP(i,n){
        REP(j,n){
            int a;
            cin >> a;
            if(a == 1){
                vec[i].emplace_back(1 << j);
            }
        }
    }
    vector<vector<ll>> dp(vector<vector<ll>>(n + 1, vector<ll>(1 << n, 0)));
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int bit = 0; bit < (1 << n); bit++){
            if(i != __builtin_popcount(bit)) continue;
            for(int j = 0; j < vec[i].size(); j++){
                dp[i + 1][bit | vec[i][j]] += dp[i][bit];
                dp[i + 1][bit | vec[i][j]] %= MOD;
            }
        }
    }
    cout << dp[n][(1 << n) - 1] << endl;
    return 0;
}

Measured memory_bytes: 377216
#include <climits>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

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

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

    int min_time = INT_MAX;
    for (int i = 0; i < n - k + 1; ++i) {
        int left_first = abs(v[i]) + abs(v[i + k - 1] - v[i]);
        int right_first = abs(v[i + k - 1]) + abs(v[i + k - 1] - v[i]);
        min_time = min(min_time, min(left_first, right_first));
    }
    cout << min_time << '\n';
}


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

using ll = long long;
using namespace std;

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

	int n; cin >> n;

	if(n == 0){
		cout << "0" << endl;
		return 0;
	}

	string ans = "";

	while(n){
		if(n%-2 < 0){
			ans = "1" + ans;
			n = n/-2 + 1;
		}else if(n%-2 == 0){
			ans = "0" + ans;
			n = n/-2;
		}else{
			ans = "1" + ans;
			n = n/-2;
		}
	}	

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>

int n, A[50];

int solve (int i, int m) {
   if (m == 0) return 1;
   if (i >= n) return 0;
   int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
   return res;
}


int main() {
   int q, M, i;


   scanf("%d", &n);
   for (i = 0; i < n; i++) scanf("%d", &A[i]);
   scanf("%d", &q);
   for (i = 0; i < q; i++) {
     scanf("%d", &M);
     if (solve(0, M)) printf("yes\n");
     else printf("no\n");
   }


  return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define sc second
typedef long long int ll;
typedef pair<ll,int> P;
typedef pair<ll,P> PP;
int N,M;
ll X;
ll H[111111];
vector<P>G[111111];
ll S[111111],he[111111];
int main()
{
	scanf("%d%d%lld",&N,&M,&X);
	for(int i=0;i<N;i++){
		scanf("%lld",&H[i]);
	}
	for(int i=0;i<M;i++){
		int A,B;ll T;
		scanf("%d%d%lld",&A,&B,&T);A--;B--;
		G[A].pb(P(T,B));
		G[B].pb(P(T,A));
	}
	for(int i=0;i<N;i++){
		S[i]=1001001001001001001;
	}
	priority_queue<PP,vector<PP>,greater<PP> >que;
	que.push(PP(0,P(X,0)));
	while(!que.empty()){
		PP p=que.top();que.pop();
		if(S[p.sc.sc]<=p.fi)continue;
		//printf("%lld %lld %d\n",p.fi,p.sc.fi,p.sc.sc);
		S[p.sc.sc]=p.fi;
		he[p.sc.sc]=p.sc.fi;
		for(int i=0;i<(int)G[p.sc.sc].size();i++){
			if(H[p.sc.sc]<G[p.sc.sc][i].fi)continue;
			//printf("%d\n",i);
			if(p.sc.fi<G[p.sc.sc][i].fi){
				ll l=2*G[p.sc.sc][i].fi-p.sc.fi;
				if(p.fi+l<S[G[p.sc.sc][i].sc])que.push(PP(p.fi+l,P(0,G[p.sc.sc][i].sc)));
			}
			else if(p.sc.fi-G[p.sc.sc][i].fi>H[G[p.sc.sc][i].sc]){
				ll l=p.sc.fi-H[G[p.sc.sc][i].sc];
				if(p.fi+l<S[G[p.sc.sc][i].sc])que.push(PP(p.fi+l,P(H[G[p.sc.sc][i].sc],G[p.sc.sc][i].sc)));
			}
			else{
				ll l=G[p.sc.sc][i].fi;
				if(p.fi+l<S[G[p.sc.sc][i].sc])que.push(PP(p.fi+l,P(p.sc.fi-l,G[p.sc.sc][i].sc)));
			}
		}
	}
	if(S[N-1]==1001001001001001001){
		printf("-1\n");
	}
	else{
		printf("%lld\n",S[N-1]+H[N-1]-he[N-1]);
	}
	return 0;
}

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

inline int read() {
	int res = 0, flag = 1;
	char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-') flag = -1;
	for(; isdigit(c); c = getchar()) res = (res<<3) + (res<<1) + (c^48);
	return res * flag;
}

int h, w, d;
char s[4] = { 'R', 'Y', 'G', 'B' };

int main() {
	h = read(); w = read(); d = read();
	for(int i = 1; i <= h; i++, printf("\n"))
		for(int j = 1; j <= w; j++) {
			int x = i + j + w, y = i - j + w;
			printf("%c", s[(((x / d) & 1) * 2 + ((y / d) & 1))]);
		}
	return 0;
}

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

const ll MAX = pow(10,18);

int main(){
  int N;
  cin >> N;
  ll A[N];
  rep(i,N) {
    cin >> A[i];
    if(A[i]==0){
      cout << 0 << endl;
      return 0;
    }
  }
  ll M = 1;
  rep(i,N){
    if(A[i]==1) continue;
    if(A[i]>MAX/M){
      M = -1;
      break;
    }
    else M *= A[i];
  }
  cout << M << endl;
}

Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define pb push_back
typedef long double ld;
typedef vector<ll> vll;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
const ll mod = 1e9+7;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
       ll n,m; cin >> n >> m;
       vll a(n);
       ll tot =0;
       rep(i,n) {
            cin >> a[i], tot+=a[i];
        }
        ld c = tot/(4.00*m);
        ll f=0; tot =0;
        rep(i,n){
            if(a[i]>=c){
                tot ++;
            }
            if(tot>=m){
                f=1;
                break;
            }
        }
       if(f){
        cout << "Yes" << endl;
       }else{
        cout << "No" << endl;
       }
    }
}


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

using namespace std;

const int INF=1000000000;

int n;
int p[100001];
bool passed[100001];
int to[100001];

int dfs(int s){
	passed[s]=true;
	// goal
	if(p[s]==0)return to[s]=s;
	int a=p[s]+s;
	//if(p[a]==0)return to[s]=a;
	// ·ÅÉn_ª©Â©ÁÄ¢é
	if(to[a]!=-1)return to[s]=to[a];
	if(passed[a])return to[s]=INF;
	return to[s]=dfs(a);
}

int bfs(){
	int cnt=1;
	memset(passed,0,sizeof(passed));
	queue<int> q[2];
	int cur=0;
	int nxt=1;
	q[cur].push(0);
	passed[0]=true;
	while(q[cur].size()){
		while(q[cur].size()){
			int cp=q[cur].front();
			q[cur].pop();
			for(int i=1;i<=6;i++){
				int np=i+cp;
				if(np>=n-1)return cnt;
				np=to[np];// npÌê©ç¢¯éê
				if(np==n-1)return cnt;
				if(np!=INF&&!passed[np]){
					passed[np]=true;
					q[nxt].push(np);
				}
			}
		}
		cnt++;
		swap(cur,nxt);
	}
	return INF;
}

int main(){

	cin>>n;
	for(int i=0;i<n;i++)cin>>p[i];
	memset(to,-1,sizeof(to));
	for(int i=0;i<=n;i++){
		if(!passed[i]){
			// Ú®Èµ
			if(p[i]==0){
				passed[i]=true;
				to[i]=i;
			}
			else to[i]=dfs(i);
		}
	}
	int a=to[2];
	// Dæ
	int res=bfs();
	cout<<res<<endl;

	return 0;
}

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

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


int main()
{
  int N;
  ll A, B;
  cin >> N >> A >> B;
  ll h[N];
  ll hmax = 0;
  REP(i, 0, N)
  {
    cin >> h[i];
    hmax = max(hmax, h[i]);
  }
  ll lo = 1;
  ll hi = hmax;
  while (lo<hi)
  {
    ll T = (hi + lo) / 2;
    ll ans = 0;
    REP(i,0,N){
      if(h[i]>B*T){
        if((h[i]-B*T)%(A-B)==0){
          ans += (h[i] - B * T) / (A - B);
        }else{
          ans += (h[i] - B * T) / (A - B)+1;
        }
      }
    }
    if (ans <= T)
    {
      hi = T;
    }else{
      lo = T+1;
    }
  }
  cout << hi << endl;

  return 0;
}

Measured memory_bytes: 1024
import java.text.DecimalFormat;
import java.util.*;

public class Main {
    public static void main(String[] args)  throws java.io.IOException{
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.close();

        DecimalFormat df1 = new DecimalFormat("0.00000");
        Double c = a*1.0/b;
        System.out.println(a/b + " " +a%b  + " " + df1.format(c));
    }
}

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

using namespace std;

int main() {
    int n, m, x, a, cnt1 = 0, cnt2 = 0;
    cin >> n >> m >> x;

    for (int i = 0; i < m; i++) {
        cin >> a;
        if (a > x) cnt1++;
        else cnt2++;
    }

    if (cnt1 > cnt2) cout << cnt2;
    else cout << cnt1;

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
from operator import itemgetter

N = int(input())
l = []
for i in range(N):
    r = input().split()	
    l.append(r)
    

    
l_copy = [] #ソート前
for i in range(N):
    l_copy.append(l[i])
l.sort(key=lambda x:(x[0],-int(x[1])))


#print(l_copy)
#print(l)
for i in range(N):
    num = 0
    target = l[i]
    for j in range(N):
        if l_copy[j] == target:
            num = j + 1
            print(num)
            break

Measured memory_bytes: 38896
import java.util.Scanner;

public class Main {
    private static final String YES = "YES";
    private static final String NO = "NO";

    public static void main(String[] args) {
        TestCase testCase = readFromInput();

        final String result = process(testCase);

        output(result);
    }

    private static TestCase readFromInput() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();

        sc.close();
        return new TestCase(n, k);
    }

    public static String process(TestCase testCase) {
        final int k = testCase.K;
        final int n = testCase.N;

        if (k <= 1) {
            return YES;
        } else {
            return (((n + 1) / 2) >= k) ? YES : NO;
        }
    }


    private static void output(String result) {
        System.out.println(result);
    }

    public static class TestCase {
        final int N, K;

        public TestCase(int n, int k) {
            N = n;
            K = k;
        }
    }
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;

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

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

    int ans = 0;

    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            int t = l[i] + l[j];

            auto it = lower_bound(l.begin(), l.end(), t);

            int key = it - l.begin();

            ans += max(0, key - (j+1));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

const int INF = 1e9;

int N;
vector< int > X[200000];

const int SZ = 100011;
int memo[5][SZ];
bool vis[5][SZ];

int go(int last, int day){
  if(day >= N){
    return 0;
  }
  if(vis[last][day]){ return memo[last][day]; }
  int best = 0;
  vector<int> x = X[day]; //cero base
  for(int i = 0; i < 3; i++){
    if(last == i){continue;}
    int res = x[i] + go(i, day + 1);
    best = max(best, res);
  }
  vis[last][day] = best;
  memo[last][day] = best;
  return best;
}

int main() {
  cin>>N;
  int a, b, c;
  for(int i = 0; i < N; i++){
    cin>>a>>b>>c;
    X[i].push_back(a);
    X[i].push_back(b);
    X[i].push_back(c);
  }
  cout<<go(4, 0); //cuidado!!
  return 0;
}

Measured memory_bytes: 20864
import java.util.*;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[]A = new int[N];
    int[]B = new int[N];
    int[]C = new int[N];

    int all = 0;
    for(int i=0; i<N; i++){
        A[i] = sc.nextInt();
}
    for(int i=0; i<N; i++){
        B[i] = sc.nextInt();
           all += B[i];
}
    for(int i=0; i<N-1; i++){
        C[i] = sc.nextInt();
    }    
   for(int j=0; j<N-1; j++){
    if(A[j+1]==A[j]+1){
       all += C[A[j]-1];
    }
}
    System.out.println(all);
 }
}


Measured memory_bytes: 35824
N, M = map(int, input().split())
a = [0]*M
b = [0]*M
c = [0]*M
for i in range(M):
    a[i], b[i] = map(int, input().split())
    cc = list(map(int, input().split()))
    for ccc in cc:
        ccc -= 1
        c[i] += (1 << ccc)

INF = float('inf')
dp = [[INF]*5000 for _ in range(M+1)]
dp[0][0] = 0

for i in range(M):
    for j in range((1 << N)):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        nj = j | c[i]
        dp[i+1][nj] = min(dp[i+1][nj], dp[i][j] + a[i])
if dp[M][(1 << N)-1] == INF:
    print(-1)
else:
    print(dp[M][(1 << N)-1])


Measured memory_bytes: 152152
#include <iostream>
    using namespace std;
     
    int main() {
    	int N = 0;
    	cin >> N;
    	int N100 = N / 100;
    	int N001 = N % 10;
    	if (N100 == N001){
    		cout << "Yes";
    	}else{
    		cout << "No";
    	}
    	return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 200100
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const ll mod = 1e9 + 7;
int roads[MAXN], rails[MAXN];
map <pii, int> freq;

int find_road(int i){
    return roads[i] = (i == roads[i]? i : find_road(roads[i]));
}
int find_rail(int i){
    return rails[i] = (i == rails[i]? i : find_rail(rails[i]));
}
void merge_road(int a, int b){
    int fa = find_road(a);
    int fb = find_road(b);

    if (fa != fb){
        roads[fb] = fa;
    }
}

void merge_rail(int a, int b){
    int fa = find_rail(a);
    int fb = find_rail(b);

    if (fa != fb){
        rails[fb] = fa;
    }
}

int main (){
    ios_base::sync_with_stdio(false);
    int n, m, time[110], soma = 0;

    cin >> n;

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

    cin >> m;

    for (int i=0; i<m; i++){
        int a, b;

        cin >> a >> b;

        cout << soma - (time[a] - b) << endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++)
	{
		if (i + 1 < s.length() && s[i] == s[i+1])
		{
			cout << i + 1 << ' ' << i + 2 << '\n';
			return 0;
		}
		if (i + 2 < s.length() && s[i] == s[i+2])
		{
			cout << i + 1 << ' ' << i + 3 << '\n';
			return 0;
		}
	}
	cout << "-1 -1\n";
	return 0;
}


Measured memory_bytes: 512
if __name__ == "__main__":
	N = int(input())
	List = list(map(int,input().split()))
	
	list.sort(List)
	# print(List)
	
	ans = (List[0]+ List[1])/2
	i = 2
	while i < len(List):
		ans = (ans + List[i])/2
		i += 1
	print(ans)

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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> h(n);
    vector<int> a(m);
    vector<int> b(m);
    vector<bool> ch(n,true);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        if(h[a[i]-1]>h[b[i]-1]){
            ch[b[i]-1]=false;
        }else if(h[a[i]-1]<h[b[i]-1]){
            ch[a[i]-1]=false;
        }else if(h[a[i]-1]==h[b[i]-1]){
            ch[a[i]-1]=false;
            ch[b[i]-1]=false;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(ch[i]){
            ans++;
        }
    }
    cout<<ans<<endl;

}

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

using namespace std;

typedef long long ll;

ll w[100], v[100], dp[101][100001];

int main() {
    int n, W;
    cin >> n >> W;
    for(int i=0;i<n;++i) cin >> w[i] >> v[i];

    for(int i=0;i<n;++i) {
        for(int wi=0;wi<=W;++wi) {
            dp[i+1][wi] = max(dp[i+1][wi], dp[i][wi]);
            if(wi+w[i] <= W) dp[i+1][wi+w[i]] = max(dp[i+1][wi+w[i]], dp[i][wi]+v[i]);
        }
    }

    ll ans = 0LL;
    for(int wi=0;wi<=W;++wi) {
        ans = max(ans, dp[n][wi]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 78336
#include <iostream>
#include <cstring>

using namespace std;

const int N = 1e5;
int h[N], dp[N];

int main(int argc, char** argv)
{
#ifdef LOCAL
  freopen(strcat(argv[0], ".in"), "ab+", stdin);
#endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> h[i];
  
  dp[1] = abs(h[0] - h[1]);

  for (int i = 2; i < n; i++) {
    dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
  }

  cout << dp[n - 1] << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i, 1000){
    string now = to_string(i);
    while(now.size() < 3)
      now = '0' + now;
    int num = 0;
    rep(j, n){
      if (now[num] == s[j]){
        num++;
      }
      if (num == 3){
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<ll, ll> pll;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;


int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	vector<int> c(m);

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

		int ci = 0;
		for (int j = 0; j < b;j++) {
			int cj;
			cin >> cj;
			cj--;
			ci += (1 << cj);

		}
		c[i] = ci;
	}

	vector<int> dp((1 << n), BIG_INT);
	dp[0] = 0;
	for (int b = 0; b < (1 << n);b++) {

		for (int i = 0; i < m;i++) {
			dp[b | c[i]] = min(dp[b | c[i]], dp[b] + a[i]);

		}
	}
	int ans = dp[(1 << n) - 1];
	if (ans != BIG_INT) {
		cout << ans << endl;
	}
	else {
		cout << -1 << endl;
	}

}



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

int main(){
    int D, N;
    cin >> D >> N;

    if(D==0){
        if(N != 100){
            cout << N << endl;
        }
        else{
            cout << 101 << endl;
        }
    }
    else if(D==1){
        if(N != 100){
            cout << N*100 << endl;
        }
        else{
            cout << 101*100 << endl;
        }
    }
    else{
        if(N != 100){
            cout << N*10000 << endl;
        }
        else{
            cout << 101*10000 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
using namespace std;

typedef vector<int>::iterator vitr;
typedef map<int, int>::iterator mitr;

map<int, int> w[100];
int d[100];

vector<int> a;
vector<int> b;

void findPath(){
    int candiW = INT_MAX;
    vitr candiI;
    for(vitr i=a.begin();i!=a.end();i++){
        for(vitr j=b.begin();j!=b.end();j++){
            mitr k = w[*i].find(*j);
            if(k == w[*i].end())continue;
            if(k->second + d[*i] < candiW){
                candiW = k->second + d[*i];
                candiI = j;
            }
        }
    }
    a.push_back(*candiI);
    d[*candiI] = candiW;
    b.erase(candiI);
}

int main(){
    int i,j,u,k,n,v,c;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d %d",&v,&c);
            w[u][v] = c;
        }
    }

    d[0] = 0;
    a.push_back(0);
    for(i=1;i<n;i++)b.push_back(i);

    for(i=1;i<n;i++)findPath();

    for(i=0;i<n;i++)printf("%d %d\n",i,d[i]);

    return 0;
}



Measured memory_bytes: 2880
fun main(args: Array<String>) {
    val l = readLine()!!
    val n = l.toInt()

    var sn = n % 10
    if (n >= 2) {
        var nTemp = n
        for (i in 2..l.length) {
            nTemp /= 10
            sn += nTemp % 10
        }
    }
    if (n % sn == 0)
        println("Yes")
    else
        println("No")
}

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

int main(){
	int n,cnt[13] = {},ma = 0;
	cin >> n;
	for(int i = 0;i < n;i++){
		int d;
		cin >> d;
		cnt[d]++;
	}
	cnt[0]++;
	for(int i = 0;i <= 12;i++){
		if(cnt[i] >= 3){
			cout << 0 << endl;
			return 0;
		}
	}
	for(int i = 0;i < (1 << 13);i++){
		int mi = 30;
		vector<int> vec;
		for(int j = 0;j < 13;j++){
			if(!cnt[j]) continue;
			if(cnt[j] == 2 || ((i >> j) & 1)) vec.push_back(j);
			if(cnt[j] == 2 || !((i >> j) & 1)) vec.push_back(24 - j);
		}
		for(int j = 0;j < vec.size();j++){
			for(int k = j + 1;k < vec.size();k++) mi = min(mi,min(abs(vec[j] - vec[k]),24 - abs(vec[j] - vec[k])));
		}
		ma = max(ma,mi);
	}
	cout << ma << endl;
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

ll N;
ll ans = 0;
void dfs(string current) {
    if(!current.empty()) {
        if(stoll(current) > N) {
            return;
        } else if(stoll(current) <= N) {
            map<char, ll> m;
            iter(c, current) m[c]++;
            if(m['7'] > 0 && m['5'] > 0 && m['3'] > 0) ans++;
        }
    }
    iter(c, string("753")) {
        string temp = current;
        temp.push_back(c);
        dfs(temp);
    }
}

int main(void) {
    cin >> N;
    dfs("");
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

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

    int min = 10000000, left = x[0], right = x[0];
    for (int i = 0; i < n; i++) {
        if (x[i] < left) left = x[i];
        if (right < x[i]) right = x[i];
    }
    for (int i = left; i <= right; i++) {
        int sum = 0;
        for (int j = 0; j < n; j++) sum += (x[j]-i)*(x[j]-i);
        if (sum < min) min = sum;
    }

    cout << min << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<pair<int, int>> v;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		v.emplace_back(a, i + 1);
	}

	sort(v.begin(), v.end());
	for (int i = 0; i < N; ++i) {
		cout << v[i].second << (i == N - 1 ? "\n" : " ");
	}

	return 0;
}


Measured memory_bytes: 1780
n=int(input())
l=[[] for i in range(n)]
ans=[-1 for i in range(n)]
for i in range(n-1):
  u,v,w=[int(x) for x in input().rstrip().split()]
  l[u-1].append([v-1,w])
  l[v-1].append([u-1,w])

def bfs():
  ans[0]=0
  que=[0]
  while(que):
    now=que.pop(0)
    for i,j in l[now]:
      if ans[i]==-1:
        if j%2==0:
          ans[i]=ans[now]
        else:
          ans[i]=(ans[now]+1)%2
        que.append(i)

bfs()
for i in ans:print(i)

Measured memory_bytes: 44972
# ABC109D - Make Them Even (str-format style)
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    A = list(list(map(lambda x: int(x) % 2, input().split())) for _ in range(H))
    ans = []
    for i in range(H):  # move left to right
        for j in range(W - 1):
            if A[i][j]:
                A[i][j] ^= 1
                A[i][j + 1] ^= 1
                ans += ["{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2)]

    for i in range(H - 1):  # move up to down
        if A[i][W - 1]:
            A[i][W - 1] ^= 1
            A[i + 1][W - 1] ^= 1
            ans += ["{} {} {} {}".format(i + 1, W, i + 2, W)]
    print(len(ans))
    for i in ans:
        print(i)


if __name__ == "__main__":
    main()

Measured memory_bytes: 16472
n,m = map(int,input().split())

#重み付きUnion-Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        px = find(par[x])
        wei[x] += wei[par[x]]
        par[x] = px
        return px

#xの根から距離
def weight(x):
    find(x)
    return wei[x]


#w[y]=w[x]+wとなるようにxとyを併合
def unite(x,y,w):
    w += wei[x]-wei[y]
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
            w = -w
        par[x] += par[y]
        par[y] = x
        wei[y] = w
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#x,yが同じ集合に属するときのwei[y]-wei[x]
def diff(x,y):
    return weight(y)-weight(x)

#初期化
#par:根なら-size,子なら親の頂点
#wei:親からの距離,根なら0
par = [-1]*n
wei = [0]*n
"""
重さが追加されるのは、yの方。
yにxの重さとwの合計が記録される。
"""
for i in range(m):
    l,r,d = map(int,input().split())
    l,r = l-1,r-1
    if same(l,r):#矛盾が生じる条件は、lとrが同じグループにいて、その重さの差の辻褄が合わなかったとき
        if d != diff(l,r):
            print("No")
            exit()
    else:
        unite(l,r,d)
print("Yes")

Measured memory_bytes: 103512
// OfficialHouse.c
// Ａ大学は１フロア１０部屋、３階建ての公舎４棟を管理しています。
// 公舎の入居・退去の情報を読み込み、各部屋の入居者数を出力するプログラムを作成して下さい。
// n件の情報が与えられます。各情報では、４つの整数b, f, r, vが与えられます。
// これは、b棟f階のr番目の部屋にv人が追加で入居したことを示します。
// vが負の値の場合、-v人退去したことを示します。
// 最初、全ての部屋には誰も入居していないものとします。
// 【入力】
// 最初の行に情報の数 n が与えられます。
// 続いて n 件の情報が与えられます。
// 各情報には４つの整数 b, f, r, v が空白区切りで１行に与えられます。
// 【出力】
// ４棟について入居者数を出力して下さい。
// 各棟について、１階、２階、３階の順に入居者数を出力します。
// 各階については、１番目、２番目、・・・、１０番目の部屋の入居者数を順番に出力します。
// 入居者数の前には１つの空白を出力して下さい。
// また、各棟の間には####################(20個の#)で区切って下さい。
// 【制約】
// ・間違った棟番号・階・部屋番号は与えられない。
// ・管理の過程で１部屋の入居者数が０より少なくなることはない。
// ・管理の過程で１部屋の入居者数が9より多くなることはない。
// 【例】
// 入力：
// 3
// 1 1 3 8
// 3 2 2 7
// 4 3 8 1
// 出力：
//  0 0 8 0 0 0 0 0 0 0
//  0 0 0 0 0 0 0 0 0 0
//  0 0 0 0 0 0 0 0 0 0
// ####################
//  0 0 0 0 0 0 0 0 0 0
//  0 0 0 0 0 0 0 0 0 0
//  0 0 0 0 0 0 0 0 0 0
// ####################
//  0 0 0 0 0 0 0 0 0 0
//  0 7 0 0 0 0 0 0 0 0
//  0 0 0 0 0 0 0 0 0 0
// ####################
//  0 0 0 0 0 0 0 0 0 0
//  0 0 0 0 0 0 0 0 0 0
//  0 0 0 0 0 0 0 1 0 0
#include<stdio.h>

int main( void) {
  int n;	// 情報の数
  int b, f, r, v;	// b棟、f階、r番目の部屋、v人
  int move_in_person_num[ 4][ 3][ 10] = {};

  // 入居者情報の入力
  scanf( "%d", &n);
  for ( int i = 0; i < n; i++) {
    scanf( "%d %d %d %d", &b, &f, &r, &v);
    move_in_person_num[ b-1][ f-1][ r-1] += v;
  }

  for ( int i = 0; i < 4; i++) {	// 1-4棟
    for ( int j = 0; j < 3; j++) {	// 1-3階
      for ( int k = 0; k < 10; k++) {	// 1-10部屋
	printf( " %d" ,move_in_person_num[ i][ j][ k]);
      }
      printf( "\n");
    }
    if ( i < 3) printf( "####################\n");
  }

  return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=1e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false); 

    int h,w;
    cin >> h >> w;
    int si,sj,gi,gj;
    cin >> si >> sj >> gi >> gj;
    vector<string> d(h);
    rep(i,h) cin >> d[i];
    priority_queue<pair<int,P>,vector<pair<int,P>>,greater<pair<int,P>>> pq;
    vector<vector<int>> c(h,vector<int>(w,INF));
    pq.push({0,{si-1,sj-1}});
    c[si-1][sj-1]=0;
    while (!pq.empty()) {
        P p=pq.top().second;
        int i=p.first;
        int j=p.second;
        pq.pop();
        repr(di,-2,3) {
            repr(dj,-2,3) {
                int ni=i+di;
                int nj=j+dj;
                if (ni>=0 && ni<h && nj>=0 && nj<w) {
                    if (abs(di)+abs(dj)==1 && c[ni][nj]>c[i][j] && d[ni][nj]=='.') {
                        c[ni][nj]=c[i][j];
                        pq.push({c[ni][nj],{ni,nj}});
                    } else if (c[ni][nj]>c[i][j]+1 && d[ni][nj]=='.') {
                        c[ni][nj]=c[i][j]+1;
                        pq.push({c[ni][nj],{ni,nj}}); 
                    }
                }
            }
        }
    }
    if (c[gi-1][gj-1]==INF) cout << -1 << endl;
    else cout << c[gi-1][gj-1] << endl;
    
    return 0;
}


Measured memory_bytes: 8528
#include<iostream>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int s1=s.size(),t1=t.size();
	int dp[s1+1][t1+1];

	for(int i=0;i<=s1;++i)
	{
		for(int j=0;j<=t1;++j)
		{
			if(i==0 || j==0)
			{
				dp[i][j]=0;
				continue;
			}

			if(s[i-1]==t[j-1])
			{
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else
			{
				if(dp[i][j-1]>dp[i-1][j])
					dp[i][j]=dp[i][j-1];
				else
					dp[i][j]=dp[i-1][j];
			}
		}
	}
	string s11="";
	int i,j;
	i=s1,j=t1;
	while(1)
	{
		if(s[i-1]==t[j-1])
		{
			s11.push_back(s[i-1]);
			i--,j--;
		}
		else
		{
			if(dp[i][j-1]>dp[i-1][j])
			{
				j--;
			}
			else
			{
				i--;
			}
		}
		if(i==0 || j==0)
			break;
	}
	for(i=s11.size()-1;i>=0;--i)
	cout<<s11[i];
}


Measured memory_bytes: 35456
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

bool isPrime(ll n) {
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}
vector<ll> primes(ll n){
  vector<ll> v(1,1);
  for (ll i = 2; n >= i * i; ++i) {
		if(!(n % i)){
      v.pb(i);
	  }
  }
  if(v.size()==1)v.pb(n);
  return v;
}


int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  int ans;
  for(long double i = 0;i < 50000.0;i++){
    if((int)(((long double)i * (long double)1.08)) == n){
      ans = i;
      print(ans);
      return 0;
    }
  }
  print(":(");
  return 0;
} 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int a[200000];
int main(void){
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> a[i];
    
    int flag_inx = 1;
    bool flag = false;
    for (int i = 0; i < N; i++) {
        if (flag_inx == a[i]) {
            flag_inx++;
            flag = true;
        }
    }
    if (flag)
        cout << N-(flag_inx-1) << endl;
    else
        cout << -1 << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
int main(){
    char S[200002],T[200002];
    int ans = 0;
    scanf("%s",S);
    scanf("%s",T);
    for(int i=0;i<strlen(S);i++){
        if(S[i] != T[i])
            ans++;
    }
    printf("%d",ans);
}


Measured memory_bytes: 2096
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    int N,W;
    cin>>N>>W;
    vector<ll> w(N);
    vector<ll> v(N);
    for(int i=0;i<N;i++){
        cin>>w[i]>>v[i];
    }
    vector<ll> dp(W+1,0);
    for(int i=1;i<=N;i++){
        vector<ll> temp(W+1,0);
        for(int j=1;j<=W;j++){
            if(w[i-1]<=j){
                temp[j] = max(dp[j],v[i-1]+dp[j-w[i-1]]);
            }
            else{
                temp[j] = dp[j];
            }
        }
        dp = temp;
    }
    cout<<dp[W];
}

Measured memory_bytes: 1804
#include <bits/stdc++.h>
using namespace std;
#define int long long 
using ldb = long double;
using pa = pair < int, int >;
#define pb push_back
#define F  first
#define S  second
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)

const int MOD = 1e9 + 7, N = 2e5 + 10;
const int p=1e9+7;
const int LINF = LLONG_MAX;
int fact[N];
int modpow(int x, int y){
    int ans=1;
    if(y==1){
        return x%MOD;
    }
    x=x % MOD;
    y=y % (MOD-1);
    while(y){
        if(y & 1){
            ans = (ans*x) %MOD;
        }
        x *= x;
        x = x % MOD;
        y >>= 1;
    }
    return ans;
}

int modinv(int x){
    return modpow(x,MOD-2);
}
int sub(int x, int y) {
    x -= y;
    if (x < 0) return x + MOD;
    return x;
}
int add(int x, int y) {
    x += y;
    if (x >= MOD) return x - MOD;
    return x;
}
int multiply(int a,int b){
    return (a*b)%MOD;
}
int binomialCoeff(int n, int k)  {  
    int res = 1;  
  
    // Since C(n, k) = C(n, n-k)  
    if ( k > n - k )  
        k = n - k;  
  
    // Calculate value of  
    // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]  
    for (int i = 0; i < k; ++i)  
    {  
        res = multiply(res,(sub(n,i)));  
        res = multiply(res,modinv(i + 1));  
    }  
  
    return res;  
}  
int32_t main() {
    fast();
    int n,a,b;
    cin >> n >> a >> b;
    int ans1=modpow(2,n);
    int ans2=binomialCoeff(n,a);
    int ans3=binomialCoeff(n,b);
    int final=sub(ans1,add(ans2,ans3));
    cout<<sub(final,1);
    return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    int n;
    cin >>n;
    vector<int> f(n);
    rep(i,n)rep(j,10)
    {
        int a;
        cin >>a;
        f[i]|=(a<<j);
    }

    vector<vector<int>> p(n,vector<int>(11));
    rep(i,n)rep(j,11) cin >>p[i][j];

    int ans = -1919191919;
    for(int mask=1; mask<(1<<10); ++mask)
    {
        int t = 0;
        rep(i,n)
        {
            int m = mask&f[i];
            t += p[i][__builtin_popcount(m)];
        }
        ans = max(ans,t);
    }

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


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

template<typename T> class Dijkstra {
  struct edge {
    int to; T cost;
  };
  int N;
  vector<vector<edge>> G;
public:
  vector<T> D;
  Dijkstra(int n) : N(n), G(n), D(n, numeric_limits<T>::max()) {}
  void add(int from, int to, T cost) {
    G.at(from).push_back((edge) {to, cost});
  }
  using pit = pair<int, T>;
  void solve(int start) {
    priority_queue<pit, vector<pit>, greater<pit>> Q;
    D.at(start) = 0;
    Q.push(pit(start, 0));
    while (Q.size()) {
      auto [now, dist] = Q.top();
      Q.pop();
      if (dist > D.at(now)) continue;
      for (auto [next, cost] : G.at(now)) {
        if (dist + cost < D.at(next)) {
          D.at(next) = dist + cost;
          Q.push(pit(next, D.at(next)));
        }
      }
    }
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int H, W, sh, sw, gh, gw;
  cin >> H >> W >> sh >> sw >> gh >> gw;
  sh--, sw--, gh--, gw--;
  int st = 0, go = 0;
  vector<vector<pair<int, char>>> S(H, vector<pair<int, char>>(W));
  for (int i = 0, id = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char c;
      cin >> c;
      if (i == sh && j == sw) st = id;
      if (i == gh && j == gw) go = id;
      S.at(i).at(j) = {id++, c};
    }
  }
  
  vector<int> mh(4), mw(4);
  mh = {-1, 0, 1, 0};
  mw = {0, 1, 0, -1};

  Dijkstra<long> D(H * W);
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      for (int i = h - 2; i <= h + 2; i++) {
        for (int j = w - 2; j <= w + 2; j++) {
          if (i < 0 || i >= H || j < 0 || j >= W) continue;
          if (S.at(i).at(j).second == '.') D.add(S.at(h).at(w).first, S.at(i).at(j).first, 1);
        }
      }
      for (int i = 0; i < 4; i++) {
        int nh = h + mh.at(i);
        int nw = w + mw.at(i);
        if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
        if (S.at(nh).at(nw).second == '.') D.add(S.at(h).at(w).first, S.at(nh).at(nw).first, 0);
      }
    }
  }

  D.solve(st);

  if (D.D.at(go) == LONG_MAX) return cout << -1 << "\n", 0;
  cout << D.D.at(go) << "\n";
}


Measured memory_bytes: 368720
#include <algorithm>
#include <cmath>
#include <limits>
#include <iostream>
#include <vector>


int main() {
    std::ios_base::sync_with_stdio (false);
    int n;
    std::cin >> n;
    std::vector<int> heights(n);
    for(int& h : heights) std::cin >> h;

    if(heights.size() <= 1) {
        std::cout << "0\n";
        return 0;
    }
    int prevPrev = 0;
    int prev = std::abs(heights[0] - heights[1]);
    int ans = prev;
    for(std::size_t i = 2; i < heights.size(); i++) {
        int op1 = prev + std::abs(heights[i - 1] - heights[i]);
        int op2 = prevPrev + std::abs(heights[i - 2] - heights[i]);
        ans = std::min(op1, op2);
        prevPrev = prev;
        prev = ans;
    }
    std::cout << ans << "\n";
}


Measured memory_bytes: 640
#include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>

using namespace std;


int main(int argc, char const* argv[])
{
    int a=0;
    int b=0;
    int tmp;
    for (int i = 0; i < 4; i++) 
    {
        cin >> tmp;
        a += tmp;
    }
    for (int i = 0; i < 4; i++) 
    {
        cin >> tmp;
        b += tmp;
    }
    cout << max( a, b) << endl;
    return 0;
}

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

int main(){
  char S[3],T[3];
  for (size_t i = 0; i < 3; i++) {
    cin >> S[i];
  }

  int res = 0;

  for (size_t i = 0; i < 3; i++) {
    cin >> T[i];
    if (S[i] == T[i]) {
      res++;
    }
  }
    cout << res << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n; cin >> n;
  int a[200005];
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a,a+n);
  bool flag = true; 
  for(int i=0;i<n-1;i++){
    if(a[i] == a[i+1]) flag = false;
  }
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>

using namespace std;

int main() {

    int n;
    cin >> n;
    vector<string> strs(n);
    vector<int> alphs(26, INT_MAX);

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 26; j++) {
            char srch_alph = (char)('a' + j);
            int cnt = 0;
            for (int k = 0; k < strs[i].size(); k++) {
                if (strs[i][k] == srch_alph) {
                    cnt++;
                }
            }
            alphs[j] = min(cnt, alphs[j]);
        }
    }

    for (int i = 0; i < 26; i++) {
        for (int j = 0; j < alphs[i]; j++) {
            cout << (char)('a' + i);
        }
    }
    cout << endl;

    return 0;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,ans,u[20];
int c[20],p[20];
void dfs(int x) {
	if (x>n) {
		ll s=0; int a=0;
		for (int i=1;i<=n;i++)
			if (u[i]) s+=p[i]+c[i]*i*100,a+=c[i];
		for (int i=n;i>=1;i--)
			if (!u[i]&&s<m) {
				if (s+(c[i]-1)*i*100<=m) s+=(c[i]-1)*i*100,a+=c[i]-1;
				else {
					int tmp=(m-s)/(i*100);
					a+=tmp; s+=tmp*i*100;
				}
			}
		if (s>=m) ans=min(ans,a);
		return;
	}
	u[x]=1; dfs(x+1); u[x]=0; dfs(x+1);
}
int main() {
	scanf("%d %d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d %d",&c[i],&p[i]);
	ans=1e9;
	dfs(1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){

	Scanner sc = new Scanner(System.in);

	int n = sc.nextInt();
	int temp = 0;
	
	int[] table = new int[n];
	

	for(int i=0;i<n;i++){
	    table[i] = sc.nextInt();
	}
	
	for(int i=0;i<n-1;i++){

	    for(int j=i+1;j<n;j++){
		if(table[i]<table[j]){
		    temp = table[i];
		    table[i] = table[j];
		    table[j] = temp;
		}
	    }
	}

	int a = 0;
	int b = 0;

	for(int i=0;i<n;i++){
	    if(i%2 == 0) a = a + table[i];
	    else b = b + table[i];
	}
	System.out.println(a-b);
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll K = 0;
ll t;
ll ret = 1000000;
string s;
ll X[100];

void input() {
  IN(N);
  REP(i, N) {
    IN(t);
    X[i] = t;
  }
}

void solve() {
  REP(i, 101) {
    ll cost = 0;
    REP(j, N) {
      cost += (X[j] - i) * (X[j] - i);
    }
    CHMIN(ret, cost);
  }
  PRINT(ret);
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 256