akhauriyash/Code-Regression huggingface dataset:
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
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; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

class UFT {
private:
  vi data, rnk;

public:
  UFT(const int &size)
    : data(size), rnk(size) {
    iota(all(data), 0);
  }

  int root(const int &x) {
    return data[x] == x ? x : data[x] = root(data[x]);
  }

  bool same(const int &a, const int &b) {
    return root(a) == root(b);
  }

  void unite(int a, int b) {
    a = root(a), b = root(b);
    if (a == b) return;
    if (rnk[a] < rnk[b]) swap(a, b);
    data[b] = a;
    if (rnk[a] == rnk[b]) rnk[a]++;
  }
};

void solve() {
  int n, m;
  while (cin >> n >> m, n) {
    vector<tuple<int, int, int>> v;
    while (m--) {
      int t, s, d;
      cin >> t >> s >> d;
      v.emplace_back(t, --s, --d);
    }
    sort(all(v));
    UFT uf(n);
    rep(i, v.size()) {
      int s, d;
      tie(ignore, s, d) = v[i];
      if (uf.same(0, s)) uf.unite(0, d);
    }
    int c = 0;
    rep(i, n) c += uf.same(0, i);
    cout << c << endl;
  }
}

Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;


vector<int> score_alone;
vector<int> score_sum;
vector<vector<int>> paths;

void recursive(int no) {
  int this_score = score_alone[no];
  score_sum[no] += this_score;
  vector<int> children = paths[no];
  for (int child : children) {
    score_sum[child] += score_sum[no];
    recursive(child);
  }
}

signed main() {
  int N, Q; cin >> N >> Q;
  vector<int> as(N-1);
  vector<int> bs(N-1);
  vector<int> ps(Q);
  vector<int> xs(Q);
  rep(i,N-1) cin >> as[i] >> bs[i];
  rep(i,Q) cin >> ps[i] >> xs[i];
  // create path for walk
  rep(i,N) {
    vector<int> v;
    paths.push_back(v);
  }
  rep(i,N-1) {
    paths[as[i]-1].push_back(bs[i]-1);
  }

  // calc score
  rep(i,N) {
    score_alone.push_back(0);
    score_sum.push_back(0);
  }
  rep(i,Q) {
    score_alone[ps[i]-1] += xs[i];
  }
  recursive(0);
  bool first = true;
  for(int s : score_sum) {
    if (first) {
      first = false;
    } else {
      cout << " ";
    }
    cout << s;
  }
  cout << endl;
}


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

using namespace std;

int n;
vector<int> G[100005];
vector<int> g[100005];
bool leaf[100005];
bool used[100005];
vector<int> vec, vec2, seq;

void dfs(int v, int prev, vector<int> &vec)
{
	vec.push_back(G[v].size());
	for(int i = 0; i < g[v].size(); i++){
		if(g[v][i] == prev) continue;
		dfs(g[v][i], v, vec);
	}
}

int main(void)
{
	cin >> n;
	int u, v;
	for(int i = 0; i < n-1; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	if(n == 2){
		cout << 1 << " " << 2 << endl;
		return 0;
	}
	for(int i = 1; i <= n; i++){
		if(G[i].size() == 1) leaf[i] = true;
	}
	for(int i = 1; i <= n; i++){
		if(leaf[i]) continue;
		for(int j = 0; j < G[i].size(); j++){
			if(!leaf[G[i][j]]) g[i].push_back(G[i][j]);
		}
	}
	
	for(int i = 1; i <= n; i++){
		if(!leaf[i] && g[i].size() >= 3){
			cout << -1 << endl;
			return 0;
		}
	}
	
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		if(leaf[i]) continue;
		if(g[i].size() <= 1){
			if(!cnt){
				dfs(i, -1, vec);
				cnt++;
			}else{
				dfs(i, -1, vec2);
				cnt++;
			}
		}
	}
	
	int res = 0;
	if(cnt == 2){
		for(int i = 0; i < vec.size(); i++){
			if(vec[i] < vec2[i]){
				res = 0;
				break;
			}
			if(vec[i] > vec2[i]){
				res = 1;
				break;
			}
		}
	}
	for(int i = 0; i < vec.size(); i++){
		seq.push_back( (res?vec2:vec)[i] );
	}
	seq.front(), seq.back()--;
	
	
	vector<int> cand, ans;
	cand.push_back(1);
	int nx = 2;
	for(int i = 0; i < seq.size(); i++){
		cand.push_back(nx);
		nx += seq[i]-1;
	}
	cand.push_back(n);
	
	for(int i = 0; i < cand.size(); i++) used[cand[i]] = true;
	reverse(cand.begin(), cand.end());
	int pre = n;
	for(int i = 0; i < cand.size(); i++){
		ans.push_back(cand[i]);
		for(int j = pre; j >= cand[i]; j--){
			if(!used[j]) ans.push_back(j);
		}
		pre = cand[i];
	}
	reverse(ans.begin(), ans.end());
	for(int i = 0; i < ans.size(); i++){
		cout << ans[i] << " ";
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 21756
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;

int main(){
	int n=0;
	set<string> used;
	string opp;
	char p='a';
	while(1){
		string s;
		s+=p;
		s+=n%26+'a';
		s+=n/26+'a';
		s+='a';
		n++;
		cout<<'?'<<s<<endl;
		cin>>opp;
		if('a'!=opp[0])break;
		if(used.find(opp)!=used.end())break;
		used.insert(opp);
		p=opp[opp.size()-1];
	}
	cout<<"!OUT"<<endl;
	return 0;
}

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

using namespace std;

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

int main(){
    string s;
    cin >> s;
    
    int i = 1;
    while(s[i] != '\0'){
        if(s[i] == s[i-1]){
            cout << "Bad";
            return 0;
        }
        i++;
    }
    cout << "Good";
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 100005;
int p[N];

int find(int v){
	return (p[v] < 0)?v:(p[v] = find(p[v]));
}

ll combine(int u, int v){
	u = find(u);
	v = find(v);
	if(u == v)return 0;
	ll ret = p[u]*1LL*p[v];
	if(p[u] > p[v])swap(u, v);
	p[u] += p[v];
	p[v] = u;
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, m;
	cin>>n>>m;
	vector<int> a(m), b(m);
	for(int i = 0; i < m; i++){
		cin>>a[i]>>b[i];
	}
	memset(p, -1, sizeof(p));
	vector<ll> ans(m);
	ll cur = n*1LL*(n - 1)/2;
	for(int i = m - 1; i >= 0; i--){
		ans[i] = cur;
		cur -= combine(a[i], b[i]);
	}
	for(auto x : ans){
		cout<<x<<'\n';
	}

	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define inf 1000000000000000001
#define mp make_pair
#define N 100009
#define PI acos(-1.0)
using namespace std;

int main()
{

  // added the two lines below 
  ios_base::sync_with_stdio (false); 
  cin.tie(NULL);
  cout.tie(0);
 
  // ll t;
  ll t=1;
  // cin>>t;
  
  while(t--){
    ll n,k,r,s,p;
    cin>>n>>k>>r>>s>>p;
    string t;
    cin>>t;
    ll ans=0;
    vector<char>v;
    for(int i=0;i<k;i++){
      if(t[i]=='r'){
        v.push_back('p');
        ans+=p;
      }
      else if(t[i]=='p'){
        v.push_back('s');
        ans+=s;
      }
      else {
        v.push_back('r');
        ans+=r;
      }
    }
    for(int i=k;i<n;i++){
      if(t[i]=='r'){
        if(v[i-k]!='p'){
          ans+=p;
          v.push_back('p');
        }
        else v.push_back('?');
      }
      else if(t[i]=='p'){
        if(v[i-k]!='s'){
          ans+=s;
          v.push_back('s');
        }
        else v.push_back('?');
      }
      else {
        if(v[i-k]!='r'){
          v.push_back('r');
          ans+=r;
        }
        else v.push_back('?');
      }
    }
   
    cout<<ans;


  }  
 

}




  




 

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int main()
{
 int a,b,c,d,common;

 while(~scanf("%d %d %d %d",&a,&b,&c,&d)){

 if(a>=d || c>=b || a==b || c==d)
      common=0;

 else
   {if   (c>=a && d<=b)
        common=d-c;
    else if (c>=a && b<d)
        common=b-c;
    else if (c<a && b<=d)
        common=b-a;
    else if (c<a && d<b)
        common=d-a;
   }
printf("%d\n",common);
  }
}

Measured memory_bytes: 128
let rec power m n = match n with
	| 0 -> 1
	| 1 -> m
	| x -> m * power m (n - 1)

let solve n k = k * power (k - 1) (n - 1)

let _ =
	Scanf.scanf "%d %d" (fun x y -> solve x y) |> Printf.printf "%d"


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

const int MAX_N = 2e5;

//----------------------------------------------------------------------

// p84 Union-Find 木の実装
// init は init_union_find に変更

int par[MAX_N];   // 親
int _rank[MAX_N];  // 木の深さ

// n 要素で初期化
void init_union_find(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    _rank[i] = 0;
  }
}

// 木の根を求める
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

// x と y の属する集合を併合
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return;
  if (_rank[x] < _rank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (_rank[x] == _rank[y])
      _rank[x]++;
  }
}

// x と y が同じ集合に属するか否か
bool same(int x, int y) {
  return find(x) == find(y);
}

//----------------------------------------------------------------------

void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B){
    init_union_find(N);
    for (int i = 0 ; i < M ; i++) {
        unite(A[i]-1, B[i]-1);
    }
    vector<int> cnt(N);
    int ans = 0;
    for (int i = 0 ; i < N ; i++) {
        int r = find(i);
        cnt[r]++;
        ans = max(ans, cnt[r]);
    }
    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  vector<int64_t> l(n + 1);
  l.at(0) = 2;
  l.at(1) = 1;
  
  for (int i = 2; i < n + 1; i++) {
    l.at(i) = l.at(i - 2) + l.at(i - 1);
  }
  
  cout << l.at(n) << endl;
}

Measured memory_bytes: 3504
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[int(input())-1])

Measured memory_bytes: 2940
#pragma GCC optimize ("O3")
#pragma message("HOLY SHIT")
#pragma message("FUCK")

#include<bits/stdc++.h>
#define inf 1e8
using namespace std;

struct edge{
    int to;
    int cost;
};


int main(){
    int k;cin>>k;
    vector<edge>e[k];
    for(int i=1;i<=k-1;i++){
        e[i].push_back(edge{(i+1)%k,1});
    }
    int dis[k];for(int i=0;i<=k-1;i++)dis[i]=inf;dis[1]=1;
    for(int i=1;i<=k-1;i++){
        e[i].push_back(edge{(i*10)%k,0});
    }
    queue<int> q;
    q.push(1);
    while(!q.empty()){
        int top=q.front();q.pop();
        for(auto x:e[top]){
            if(x.cost+dis[top]<dis[x.to]){
                dis[x.to]=x.cost+dis[top];
                q.push(x.to);
            }
        }
    }
    cout<<dis[0]<<endl;
    return 0;
}

Measured memory_bytes: 6272
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]


from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

N=int(input())
A=[int(input()) for i in range(N)]

c = Counter(A)

ans = 0
for k, v in c.items():
    if v % 2 == 1:
        ans += 1

print(ans)

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

// clang-format off
template<typename T>
bool chmax(T& a, const T& b) {if (a<b){a=b;return true;}return false;}
template<typename T>
bool chmin(T& a, const T& b) {if (a>b){a=b;return true;}return false;}
// clang-format on

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

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

template <typename T>
int index(T& vec, typename T::iterator it) {
    return distance(vec.begin(), it);
}

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vec a(n);
    init(a);
    vec dp(n, INF);

    rep (i, n)
        *upper_bound(all(dp), -a[i]) = -a[i];
    print(index(dp, lower_bound(all(dp), INF)));

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    ll n, m; cin >> n >> m;
    vector<ll> H(n);
    REP(i, n) cin >> H[i];
    vector<ll> I(n, 0);
    REP(i, m){
        ll a, b; cin >> a >> b;
        ll h1 = H[a-1], h2 = H[b-1];
        //cout << h1 << " " << h2 << endl;
        if(h1 > h2){
            I[b-1] = -1;
        }
        else if(h1 == h2){
            I[a-1] = -1;
            I[b-1] = -1;
        }
        else{
            I[a-1] = -1;
        }
    }
    //cout << H << endl;
    ll res = 0;
    REP(i, n){
        if(I[i] != -1) res++;
    }
    cout << res << endl;
}

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


Measured memory_bytes: 4784
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		String t = sc.next();
		long MOD = 1000000007;
		long ans = 1;
		// 一番最近見たドミノが縦のパターンの場合TRUE, それ以外はFALSE
		boolean before = false;
		for(int i = 0; i < n;) {
			if(i == 0) {
				if(s.charAt(i) == t.charAt(i)) {
					ans = 3;
					i++;
					before = true;
				} else {
					ans = 6;
					i += 2;
					before = false;
				}
			} else {
				if(before) {
					if(s.charAt(i) == t.charAt(i)) {
						ans = ans * 2 % MOD;
						i++;
						before = true;
					} else {
						ans = ans * 2 % MOD;
						i += 2;
						before = false;
					}
				} else {
					if(s.charAt(i) == t.charAt(i)) {
						i++;
						before = true;
					} else {
						ans = ans * 3 % MOD;
						i += 2;
						before = false;
					}
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
n,m=map(int,input().split())
l=[0]*(m+1)
for i in range(n):
    a=list(map(int,input().split()))
    for j in range(1,a[0]+1):
        l[a[j]]+=1
if max(l)==n:
    print(l.count(max(l)))
else:
    print(0)


Measured memory_bytes: 3060
a, b, c = map(int, input().split())

n_5 = 0
n_7 = 0

if a == 5:
    n_5 +=1
elif a == 7:
    n_7 +=1

if b == 5:
    n_5 +=1
elif b == 7:
    n_7 +=1

if c == 5:
    n_5 +=1
elif c == 7:
    n_7 +=1

if n_5 == 2 and n_7 == 1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9188
package main

import "fmt"

const (
	max = 100000
	mod = 1e9 + 7
)

var fact, invFact []int

func powmod(a, m int) int {
	b := 1
	for m > 0 {
		if m&1 != 0 {
			b = b * a % mod
		}
		a = a * a % mod
		m >>= 1
	}
	return b
}

func combmod(n, r int) int {
	c := fact[n]
	c *= invFact[n-r]
	c %= mod
	c *= invFact[r]
	c %= mod
	return c
}

func main() {
	var H, W, A, B int
	fmt.Scan(&H, &W, &A, &B)

	max := H + W + 1
	fact = make([]int, max+1)
	invFact = make([]int, max+1)
	fact[0] = 1
	invFact[0] = 1
	for i := 1; i <= max; i++ {
		fact[i] = (i * fact[i-1]) % mod
		invFact[i] = powmod(i, mod-2)
		invFact[i] = (invFact[i] * invFact[i-1]) % mod
	}

	s := 0
	for i := 0; i < H-A; i++ {
		x := combmod(i+1+B-2, i)
		y := combmod(W-B+H-i-2, H-i-1)
		z := (x * y) % mod
		s = (s + z) % mod
	}
	fmt.Println(s)
}


Measured memory_bytes: 4352
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
const int INT_MAX = 1000000000;

int n, arr[100005];
int dp[100005];
int f(int ind){ 
    if(ind==n-1) return 0;
    if(ind>=n) return INT_MAX;
    if(dp[ind]!=-1) return dp[ind];
    int left = abs(arr[ind]-arr[ind+1])+f(ind+1);
    int right=INT_MAX;
    if(ind+2<n)
    {
        right =abs(arr[ind]-arr[ind+2])+f(ind+2);
    }
    return dp[ind]=min(left,right);
}
signed main(){
   
    cin>>n;
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    

    cout<<f(0);
}

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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORR(i,n,a) for(int i=(n); i>=(a); i--)
#define REPR(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

int a[2002][2002];

void minit() {
	REP(i,2000) {
		REP(j,2000) {
			a[i][j] = 0;
		}
	}	
	a[0][0] = 1;
	FOR(i,0,2001) {
		FOR(j,0,i+1) {
			a[i+1][j] = (a[i+1][j] + a[i][j]) % MOD;
			a[i+1][j+1] = (a[i+1][j+1] + a[i][j]) % MOD;
		}
	}
}

ll mod_comb(int i, int j) {
	if(i == 0) return 0;
	if(j == 0) return 0;
	if(i<j) return 0;
	return a[i][j];
}

int main() {
	minit();
	int n,k;
	cin >> n >> k;
	int m = n-k; // red

	ll ans = m+1;
	cout << ans << endl;
	FOR(i,2,k+1) {
		ll tmp = mod_comb(m+1,i) * mod_comb(k-1,i-1) % MOD;
		cout << tmp << endl;
	}
}



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

using namespace std;



int strcmp1(char* c1,char* c2){
    int len1 = 0,len2 = 0;
    for(int i = 0;c1[i]!='\0';i++) len1++;
    for(int i = 0;c2[i]!='\0';i++) len2++;
    if(len1!=len2) return -1;
    int div;
    for(int i = 0;i<len1;i++){
        div = c1[i] - c2[i];
        if(div!=0 && div!=32 && div!=-32) return -1;
    }
    return 0;

}

int main()
{
    char s1[11];
    char s2[1001];
    scanf("%s",s1);
    int count = 0;
    while(true){
        scanf("%s",s2);
        if(strcmp(s2,"END_OF_TEXT")==0) break;
        if(strcmp1(s1,s2)==0) count++;
    }
    cout << count << endl;
    
    return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	std::string s; cin >> s;

	std::vector<std::vector<int>> A(3, std::vector<int>(n + 1));
	for(int i = 0; i < n; i++) {
		A[0][i + 1] = A[0][i] + (s[i] == 'R');
		A[1][i + 1] = A[1][i] + (s[i] == 'G');
		A[2][i + 1] = A[2][i] + (s[i] == 'B');
	}

	i64 ans = 0;
	std::string c = "RGB";
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			if(s[i] == s[j]) continue;

			for(int k = 0; k < 3; k++) {
				if(s[i] == c[k] or s[j] == c[k]) continue;
				ans += (A[k][j] - A[k][i]);

				if((i + j) % 2) continue;
				ans -= (s[(i + j) >> 1] == c[k]);
			}
		}
	}

	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3792
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

//strattime:2017/10/9 21:12
//endtime:2017/10/9 21:16

map<LL,int> a;
int n,i,m;
LL x;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>x;
		a[x]++;
	}
	cin>>m;
	int flag=0;
	for(i=1;i<=m;i++)
	{
		cin>>x;
		if(a[x]==0)
		{
			flag=1;
		}
		else
			a[x]--;
	}
	if(flag==1)
		cout<<"NO"<<endl;
	else
		cout<<"YES"<<endl;
}


Measured memory_bytes: 14720
#include <iostream>

using namespace std;

int main(){
  
  int N;
  long K,Q,suv[100005]{};
  
  int ans[100005]{};
  
  cin>>N>>K>>Q;
  
  int a;
  
  for(int i=0;i<Q;i++){
    cin>>a;
    ans[a]++;
    
  }
  
  for(int i=1;i<N+1;i++){
    suv[i]=K-Q+ans[i];
    if(suv[i]<1){
      cout<<"No\n";
    }else{
      cout<<"Yes\n";
    }
  }
  
  
  return 0; 
}

Measured memory_bytes: 1272
n, c = map(int, input().split())
x = [tuple(map(int, input().split())) for _ in range(n)]

S_cw = [0]
S_ccw = [0]
S_cw_return = [0]
S_ccw_return = [0]

for i in range(n):
    S_cw.append(S_cw[-1]+x[i][1])
    S_ccw.append(S_ccw[-1]+x[n-1-i][1])

for i in range(n):
    S_cw[i+1] -= x[i][0]
    S_ccw[i+1] -= c-x[n-1-i][0]
    S_cw_return.append(S_cw[i+1] - x[i][0])
    S_ccw_return.append(S_ccw[i+1] - (c-x[n-1-i][0]))

S_cw_return_max = [0]
S_ccw_return_max = [0]
for i in range(n):
    if S_cw_return[i+1] > S_cw_return_max[-1]:
        S_cw_return_max.append(S_cw_return[i+1])
    else:
        S_cw_return_max.append(S_cw_return_max[-1])

    if S_ccw_return[i+1] > S_ccw_return_max[-1]:
        S_ccw_return_max.append(S_ccw_return[i+1])
    else:
        S_ccw_return_max.append(S_ccw_return_max[-1])

ans = 0
for i in range(n+1):
    idx = n-i
    ans = max(ans, S_cw[i]+S_ccw_return_max[idx], S_ccw[i]+S_cw_return_max[idx])
print(ans)



Measured memory_bytes: 38756
import sys

def main():
    input = sys.stdin.readline

    N = int(input())
    S = []

    for _ in range(N):
        S.append(input())
    print("AC"+" x "+ str(S.count('AC\n')))
    print("WA"+" x "+ str(S.count('WA\n')))
    print("TLE"+" x "+ str(S.count('TLE\n')))
    print("RE"+" x "+ str(S.count('RE\n')))


    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 16176
# region header
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
import copy
# @lru_cache(maxsize=None)
# sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
# endregion
# region input function


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


# endregion
a, b, c, d = inpl()
ans = -INF
tmp = [a * c, b * c, a * d, b * d]
if (a <= 0 and b >= 0)or (c <= 0 and d >= 0):
    ans = 0
else:
    ans = -INF
tmp = max(tmp)
ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 68392
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
	let s = read_line().split_whitespace().map(|e|e.parse().unwrap())
	.collect::<Vec<i32>>();
	let n = s[0]*s[1];
	if n % 2 == 0 {
		println!("Even");
	}else{
		println!("Odd");
	}
}


Measured memory_bytes: 4352
#include <stdio.h>
int main (int argc, char * argv[])
{
    int a[100];
    int n,b,c;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&b);
        a[i] = b;
    }
    for(int j=0;j<n/2;j++){
        c = a[j];
        a[j] = a[n-j-1];
        a[n-j-1] = c;
    }
    for(int i=0;i<n;i++){
        printf("%d",a[i]);
        if(i<n-1){
        printf(" ");
        }
        if(i==n-1){
            printf("\n");
        }
    }
  
    return 0;
}



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

int main () {
  int n;
  cin >> n;
  
  if (n == 3 || n == 5 || n == 7) {
    cout << "YES" << endl;
    return 0;
  } else {
    cout << "NO" << endl;
    return 0;
  }
  
  return -1;
}

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

int main() {
	int a,b;
	cin >> a >> b;
	if ( a < b  ){
		cout << "a < b"<< endl;
	}else if ( a > b ){
		cout << "a > b"<< endl;
	}else{
		cout << "a == b" << endl;
	}
	return 0;
}


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

main()
{
  int a, b;
  int fact[100005];

  fact[1] = 1;
  for(int i = 2; i < 100005; i++) {
    fact[i] = (fact[i - 1] * i) % 1000000007;
  }
  
  cin >> a >> b;

  if(abs(a - b) >= 2) {
    cout << 0 << endl;
  } else if(a == b) {
    cout << (fact[a] * fact[b] * 2) % 1000000007;
  } else {
    cout << (fact[a] * fact[b]) % 1000000007<< endl;
  }

  return (0);
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
  int n,a,h[100000],i,n1=0,n2=0,n4=0;
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%d",&a);
    if (a%4==0) n4++;
    else if (a%2==0) n2++;
    else n1++;
  }
  if (n2) printf("%s\n",(n1<=n4)? "Yes":"No");
  else printf("%s\n",(n1<=n4+1)? "Yes":"No");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define double long double
const int INF = (int)1e18 + 18;
const int maxn = (int) 1e6 + 6; 
using namespace std;

int n, temp = 0;
vector<int> h;
vector<int> cmp;

signed main() {
    cin >> n;
    
    for(int i = 0; i < n; i++){
        int inp; cin >> inp;
        h.push_back(inp);
    }
    
    for(int i = 0; i < n-1; i++){
        
        if(h[i] > h[i+1] || h[i] == h[i+1]){
            temp++;
            if(i == n-2){
                cmp.push_back(temp);
            }
        }
        else{
            cmp.push_back(temp);
            temp = 0;
        }
    }
    cmp.push_back(0);
    sort(cmp.begin(), cmp.end());
    
    cout << cmp.back();
    
	return 0;
}


Measured memory_bytes: 2548
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

int main() {
	cin.sync_with_stdio(false); cin.tie(nullptr);
	int X, Y, an, bn, cn;
	cin >> X >> Y >> an >> bn >> cn;
	vector<long long> a(an+1), b(bn+1), c(cn);
	for (int i = 1; i <= an; ++i) cin >> a[i];
	for (int i = 1; i <= bn; ++i) cin >> b[i];
	for (int i = 0; i < cn; ++i) cin >> c[i];
	a[0] = b[0] = 1e9 + 7;
	sort(a.rbegin(), a.rend());
	sort(b.rbegin(), b.rend());
	sort(c.rbegin(), c.rend());
	int i = 0, x = X, y = Y;
	while (true) {
		long long maxi = max(c[i] - a[x], c[i] - b[y]);
		if (maxi <= 0) break;
		if (maxi == c[i] - a[x]) swap(c[i], a[x]), x--;
		else swap(c[i], b[y]), y--;
		i++;
		if (i == cn) break;
	}
	long long sol = 0LL;
	for (int i = 1; i <= X; i++) sol += a[i];
	for (int i = 1; i <= Y; i++) sol += b[i];
	cout << sol << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  int t=c-a;
  int l=d-b;
  cout<<c-l<<endl;
  cout<<d+t<<endl;
  cout<<a-l<<endl;
  cout<<b+t<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int map[90][90],n,m;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};


int search(int x,int y){
	int i,p,max=1;
	map[x][y]=0;
	for(i=0;i<4;i++){
		if(0<=x+dx[i] && x+dx[i]<n && 0<=y+dy[i] && y+dy[i]<m){
			if(map[x+dx[i]][y+dy[i]]==1){
				p=1+search(x+dx[i],y+dy[i]);
				max=(p>max)?p:max;
			}
		}
	}
	map[x][y]=1;
	return max;
}

int main(){
	int i,j,max,p;
	while(1){
		scanf("%d",&m);
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				scanf("%d",&map[i][j]);
			}
		}
		max=0;
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				if(map[i][j]==1){
					p=search(i,j);
					max=(p>max)?p:max;
				}
			}
		}
		printf("%d\n",max);
	}
	return 0;
}

Measured memory_bytes: 632
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int main()
{
    int m,n,o,i;
    string a;
    cin>>m;
    if(m==1)
    {
        cout<<"Hello World";
    }
    else
    {
        cin>>n>>o;
        cout<<n+o;
    }
    //cin>>a;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>

#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;

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

	int l[51] = {};

	int ans = 0;
	while(N-- > 0){
		cin >> l[N];
	}
	for(int i = 0; i < 49; ++i){
		for(int j = i+1; j < 50; ++j){
			if(l[i] < l[j]){
				int tmp = l[i];
				l[i] = l[j];
				l[j] = tmp;
			}
		}
	}

	for(int i = 0; i < K; ++i){
		ans += l[i];
	}
	
	cout << ans << endl;
}


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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int64_t a,int64_t b){return a/gcd(a, b)*b;}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }

int main()
{
	int64_t n, m, ans;

	cin >> n >> m;
	ans = min(n, m / 2);
	if (n < m / 2)
	{
		m -= n * 2;
		ans += m / 4;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3604
n=gets.to_i
as=gets.split.map(&:to_i).sort
ans=0
minus=0
absmin=10**9
as.each do |an|
  absmin=[absmin,an.abs].min
  if an<0
    minus+=1
    ans+=an.abs
  else
    ans+=an.abs
  end
end
puts minus.even? ? ans:ans-2*absmin


Measured memory_bytes: 22308
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int MAXM = 4e2 + 5;
const int MAXN = 26 + 5;
const ll linf = 0x3f3f3f3f3f3f3f3f;

int c[MAXN];
int a[MAXM][MAXN];

int main(void)
{
	int n=26, m;
	scanf("%d",&m);
	for(int i=1; i<=n; ++i) scanf("%d",&c[i]);
	for(int i=1; i<=m; ++i)
		for(int j=1; j<=n; ++j)
			scanf("%d",&a[i][j]);
	
	static int lst[MAXM];
	
	for(int k=1; k<=m; ++k)
	{
		ll mx = -linf;
		int mxi = -1;
		for(int i=1; i<=n; ++i)
		{
			ll res = a[k][i];
			for(int j=1; j<=n; ++j) if(j!=i)
				res -= c[j] * (k-lst[j]);
			
			if(mxi==-1 || mx < res)
				mxi = i, mx = res;
		}
		lst[mxi] = k;
		
		printf("%d\n",mxi);
	}
	return 0;
}

Measured memory_bytes: 1780
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args)throws Throwable {
        MyScanner sc=new MyScanner();
        PrintWriter pw=new PrintWriter(System.out);

        int n=sc.nextInt();
        long [] a=new long [n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
            if(i>0)
                a[i]+=a[i-1];
        }
        long min=Long.MAX_VALUE;
        TreeSet<Long> set1=new TreeSet<>();
        TreeSet<Long> set2=new TreeSet<>();
        for(int i=0;i<n-2;i++)
            set1.add(a[i]);
        set2.add(a[n-1]-a[n-2]);
        set2.add(a[n-1]-a[n-3]);
        for(int i=n-3;i>0;i--){
            long s1=set1.last();
            long s2=set2.last();

//            System.err.println(set1+" "+set2);
            long x1=set1.higher(s1/2-1);
            long y1=s1-x1;

            long d1=Math.abs(y1-x1);

            if(set1.lower(x1)!=null){
                x1=set1.lower(x1);
                y1=s1-x1;
                if(Math.abs(y1-x1)>d1){
                    x1=set1.higher(x1);
                    y1=s1-x1;
                }
            }

            long x2=set2.higher(s2/2-1);
            long y2=s2-x2;

            long d2=Math.abs(y2-x2);

            if(set2.lower(x2)!=null){
                x2=set2.lower(x2);
                y2=s2-x2;
                if(Math.abs(y2-x2)>d2){
                    x2=set2.higher(x2);
                    y2=s2-x2;
                }
            }

            long [] arr={x1,y1,x2,y2};
            long mx=0;
            for(int j=0;j<4;j++)
                for(int k=j+1;k<4;k++)
                    mx=Math.max(mx,Math.abs(arr[j]-arr[k]));
            min=Math.min(min,mx);
            set1.remove(a[i]);
            set2.add(a[n-1]-a[i-1]);
        }



        pw.println(min);
        pw.flush();
        pw.close();
    }

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {while (st == null || !st.hasMoreElements()) {
            try {st = new StringTokenizer(br.readLine());}
            catch (IOException e) {e.printStackTrace();}}
            return st.nextToken();}
        int nextInt() {return Integer.parseInt(next());}
        long nextLong() {return Long.parseLong(next());}
        double nextDouble() {return Double.parseDouble(next());}
        String nextLine(){String str = "";
            try {str = br.readLine();}
            catch (IOException e) {e.printStackTrace();}
            return str;}
    }
} 

Measured memory_bytes: 83548
#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  endl           "\n"
#define  pb             push_back
#define  sym(s)         s="#"+s+"#";
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());

typedef  long long             ll;
typedef  unsigned long long    ull;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   N  =  3e+5+7;

vll adj[N];ll vis[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n,q;
ll ch,x;
set<pll>set1,set2;
//<<-----Implement Functions Here---->>//


//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n>>q;
		ll ans = (n-2)*(n-2);	
		set1.insert({n,n});
		set2.insert({n,n});
		for(ll i=1;i<=q;i++)
		{	
			cin>>ch>>x;
			if(ch == 1)
			{
				auto it = set2.lower_bound({x,-1e18});
				ll r = (*it).s;ll c = (*it).f;
				ans -= (r-2);
				set1.insert({r,x});set2.insert({x,r});
			}
			else
			{
				auto it = set1.lower_bound({x,-1e18});
				ll r = (*it).f;ll c = (*it).s;
				ans -= (c-2);
				set1.insert({x,c});set2.insert({c,x});
			}
		}
		cout<<ans<<endl;
}

int main(){
    fastio;randomINIT;

    //cin>>t;
    while(t--){
        MAIN();
    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}

Measured memory_bytes: 35632
#include<stdio.h>

int main(void){
  int i,j,s,n,m;
  static int a[100][100],b[100],c[100];

  scanf("%d %d",&n,&m);
 
  for(i = 0;i < n;i++)
    for(j=0;j<m;j++)
      scanf("%d",&a[i][j]);

  for(i = 0;i < m;i++)
    scanf("%d",&c[i]);

  for(i = 0;i < n;i++){
    s = 0;
    for(j = 0;j < m;j++)
      s += a[i][j] * c[j];
    printf("%d\n",s);
  }
  
  return 0;
}



Measured memory_bytes: 2108
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=200+10;
int a[maxn];
bool bz[maxn];
int i,j,k,l,t,n,m,mx,cnt;
bool czy;
int main(){
	scanf("%d",&n);
	fo(i,1,n){
		scanf("%d",&a[i]);
		mx=max(mx,a[i]);
	}
	czy=1;
	fo(i,1,n)
		if (!bz[i]&&a[i]==mx&&cnt<2){
			bz[i]=1;
			cnt++;
		}
	if (cnt<2){
		printf("Impossible\n");
		return 0;
	}
	if (mx%2==0){
		l=mx/2+1;
		fo(i,mx/2+1,mx-1){
			cnt=0;
			fo(j,1,n)
				if (!bz[j]&&a[j]==i&&cnt<2){
					bz[j]=1;
					cnt++;
				}
			if (cnt<2){
				printf("Impossible\n");
				return 0;
			}
		}
		cnt=0;
		fo(i,1,n)
			if (!bz[i]&&a[i]==mx/2&&cnt<1){
				bz[i]=1;
				cnt++;
			}
		if (!cnt){
			printf("Impossible\n");
			return 0;
		}
		fo(i,1,n)
			if (!bz[i]&&a[i]<l){
				printf("Impossible\n");
				return 0;
			}
	}
	else{
		l=(mx+1)/2+1;
		fo(i,(mx+1)/2,mx-1){
			cnt=0;
			fo(j,1,n)
				if (!bz[j]&&a[j]==i&&cnt<2){
					bz[j]=1;
					cnt++;
				}
			if (cnt<2){
				printf("Impossible\n");
				return 0;
			}
		}
		if (!cnt){
			printf("Impossible\n");
			return 0;
		}
		fo(i,1,n)
			if (!bz[i]&&a[i]<l){
				printf("Impossible\n");
				return 0;
			}
	}
	printf("Possible\n");
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d ;
  if(a+b > c+d) cout << "Left";
  else if(a+b < c+d) cout << "Right";
  else cout << "Balanced";
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main () {
    int n;
    std::cin >> n;
    if (n >= 195) {
        std::cout << "5" << std::endl;
    }
    else if (n >= 189) {
        std::cout << "4" << std::endl;
    }
    else if (n >= 165) {
        std::cout << "3" << std::endl;
    }
    else if (n >= 135) {
        std::cout << "2" << std::endl;
    }
    else if (n >= 105) {
        std::cout << "1" << std::endl;
    }
    else {
        std::cout << "0" << std::endl;
    }
}


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


int main() {
  int N;
  cin >> N;
  
  vector<int> L(N);
  for(int i=0; i<N; i++) {
    cin >> L.at(i);
  }
  
  int cnt = 0;
  for(int i=0; i<N; i++) {
    for(int j=i+1; j<N; j++) {
      for(int k=j+1; k<N; k++) {
        if (L.at(i)==L.at(j) || L.at(j)==L.at(k) || L.at(k)==L.at(i)) {
          continue;
        }
        if (L.at(i)+L.at(j)>L.at(k) && L.at(j)+L.at(k)>L.at(i) && L.at(k)+L.at(i)>L.at(j)) {
          cnt++;
        }
      }
    }
  }
        
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string n;
cin>>n;
int sum=0;
rep(i,n.size()){
    sum+=n[i]-'0';
}
if(stoi(n)%sum==0){
    cout<<"Yes"<<endl;
}
else{
    cout<<"No"<<endl;
}


//system("pause");
return 0;
}

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

using namespace std;

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

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll l = c*d/__gcd(c,d);
    --a;
    ll x = a - (a/c) - (a/d) + (a/l);
    ll y = b - (b/c) - (b/d) + (b/l);
    cout<<(y-x)<<endl;
    return 0;
}


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

struct UnionFind
{
	vector<long long> par;

	void init(long long n) {par.assign(n, -1);}

	long long root(long long x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool merge(long long x, long long y)
	{
		x = root(x);
		y = root(y);
		if(x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	bool issame(long long x, long long y)
	{
		return root(x) == root(y);
	}

	long long size(long long x)
	{
		return -par[root(x)];
	}
};


ll N, M;
vector<ll> A, B;

int main(int argc, char **argv)
{
	cin >> N >> M;
	A.resize(M);
	B.resize(M);
	UnionFind uf;
	uf.init(N);

	REP(i, M)
	{
		cin >> A[i] >> B[i];
		--A[i], --B[i];
	}

	vector<ll> res;
	ll can{N*(N-1)/2};
	for (ll i = M-1; i >= 0; --i)
	{
		res.push_back(can);
		if (uf.issame(A[i], B[i])) continue;
		
		can -= uf.size(A[i]) * uf.size(B[i]);
		uf.merge(A[i], B[i]);
	}

	reverse(ALL(res));
	for (auto &e : res)
		std::cout << e << std::endl;
}


Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll X;
  cin>>X;
  ll now=X;
  while(now!=1){
ll num=0;
    for(ll i=1;i<=now/2;i++){
if(now%i==0){
num++;
}
    }
if(num==1){
cout<<now<<endl;
  break;
}
else{
now++;
}
  }
  
}

      
      

Measured memory_bytes: 256
#include <stdlib.h>
#include <iostream>

using namespace std;

int main(){
  int a[3][3];
  for(int i=0;i<3;i++){
    for(int j=0; j<3; j++){
      cin >> a[i][j];
    }
  }
  int n; cin >> n;
  for(int m=0; m<n; m++){
    int k; cin >> k;
    for(int i=0; i<3; i++){
      for(int j=0;j<3; j++){
        if(a[i][j] == k){
          a[i][j] =0;
        }
      }
    }
  }
  if(a[0][0]==0 && a[0][1]==0 && a[0][2]==0){
    cout << "Yes" << endl;
    return 0;
  }
  if(a[1][0]==0 && a[1][1]==0 && a[1][2]==0){
    cout << "Yes" << endl;
    return 0;
  }
  if(a[2][0]==0 && a[2][1]==0 && a[2][2]==0){
    cout << "Yes" << endl;
    return 0;
  }
  if(a[0][0]==0 && a[1][0]==0 && a[2][0]==0){
    cout << "Yes" << endl;
    return 0;
  }
  if(a[0][1]==0 && a[1][1]==0 && a[2][1]==0){
    cout << "Yes" << endl;
    return 0;
  }
  if(a[0][2]==0 && a[1][2]==0 && a[2][2]==0){
    cout << "Yes" << endl;
    return 0;
  }
  if(a[0][0]==0 && a[1][1]==0 && a[2][2]==0){
    cout << "Yes" << endl;
    return 0;
  }
  if(a[2][0]==0 && a[1][1]==0 && a[0][2]==0){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if ((1LL*a*b)%3==0) {
		cout << 0 << endl;
		return 0;
	}
	long long s1, s2, res = 1000000000000LL, s3;
	for(int i = 1; i <= a/2; ++i) {
		long long s1 = 1LL*i*b;
		if ((1LL*(a-i)*b) % 2 == 0) s2 = s3 = 1LL*(a-i)*b/2;
		else {
			s2 = 1LL*min(a-i,b)*(max(a-i,b)/2);
			s3 = 1LL*(a-i)*b-s2;
		}
		//cout << s1 << " " << s2 << " " << s3 << endl;
		res = min(max(s3,s1)-min(s1,s2),res);
	}
	for(int i = 1; i <= b/2; ++i) {
		long long s1 = 1LL*i*a;
		if ((1LL*(b-i)*a) % 2 == 0) s2 = s3 = 1LL*(b-i)*a/2;
		else {
			s2 = 1LL*min(b-i,a)*(max(b-i,a)/2);
			s3 = 1LL*(b-i)*a-s2;
		}
		res = min(max(s3,s1)-min(s1,s2),res);
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n,m;
  cin>>n>>m;
  vector<int> freq(m);
  rep(i,n) {
    int k;
    cin>>k;
    rep(j,k) {
      int a;
      cin>>a;
      freq[a-1]++;
    }
  }
  ll ans=0;
  rep(i,m) {
    ans+=(freq[i]==n);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

#define int long long
typedef pair<int, int> P;

int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*
#define cin ifs
#define cout ofs
ifstream ifs("in.txt");
ofstream ofs("out.txt");
//*/

int n;
int a[220000];

signed main() {
    cin >> n;
    int ans1 = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        ans1 = max(a[i], ans1);
    }
    double mid = ans1 / 2.0;
    double sa = LLONG_MAX;
    int ans2;
    for (int i = 0; i < n; i++) {
        if (ans1 == a[i]) continue;
        double cur = abs(a[i] - mid);
        if (cur < sa) {
            sa = cur;
            ans2 = a[i];
        }
    }
    cout << ans1 << " " << ans2 << endl;
    return 0;
}

Measured memory_bytes: 1024