akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n;
int a[300000];
int flag;
vector<int> ans;
int main()
{
	cin>>n;
	rep(i,n)cin>>a[i];
	if(n%4==0)
	{
		for(int i=n-1;i>=0;i-=2)
		{
			ans.push_back(a[i]);
			//cout<<a[i]<<" ";
		}
		for(int i=0;i<n;i+=2)
		{
			ans.push_back(a[i]);
			}
		
	}
	if(n%4==1)
	{
		for(int i=n-2;i>=0;i-=2)
		{
			ans.push_back(a[i]);
			//cout<<a[i]<<" ";
		}
		for(int i=0;i<n;i+=2)
		{
			ans.push_back(a[i]);
			}
	}
	if(n%4==2)
	{
		for(int i=n-1;i>=0;i-=2)
		{
			//cout<<a[i]<<" ";
			ans.push_back(a[i]);
		}
		for(int i=0;i<n;i+=2)
		{
			ans.push_back(a[i]);
			}
	}
	if(n%4==3)
	{
		for(int i=n-2;i>=0;i-=2)
		{
			ans.push_back(a[i]);
			//cout<<a[i]<<" ";
		}
		for(int i=0;i<n;i+=2)
		{
			ans.push_back(a[i]);
			}
	}
	if(n%2==0)
	{
		rep(i,n)
		{
			cout<<ans[i];
			if(i==n-1)cout<<endl;
			else cout<<" ";
		}
	}
	else
	{
		for(int i=n-1;i>=0;i--)
		{
			cout<<ans[i];
			if(i==0)cout<<endl;
			else cout<<" ";
		}
	}
	return 0;
}

Measured memory_bytes: 3828
n = int(input())
d,x = (int(_) for _ in input().split())
a = [int(input()) for i in range(n)]

su = 0
for i in a:
        c = [(j*i+1) for j in range(0,d) if (j*i+1) <= d]
        # print(c)
        su = su + len(c)
print(su+x)

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

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

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

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

  ll a, b, c, d; cin >> a >> b >> c >> d;

  cout << max(a * c, max(a * d, max(b * c, b * d))) << endl;

  return 0;
}








Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=(int)(n);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    char a,b;
    cin>>a>>b;
    if(a=='H') cout<<b<<endl;
    else {
        if(b=='H') cout<<'D'<<endl;
        else cout<<'H'<<endl;
    }
    return 0;
}


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

using namespace std;

struct DATA{
  char name;
  int number;
};

bool compare(const DATA&, const DATA&);

int main(){
  int i, s1, s2;
  char c[5] = {'A', 'B', 'C', 'D', 'E'};
  DATA data[5];

  while(1){
    for(i=0; i<5; ++i){
      cin >> s1 >> s2;
      if(s1 == 0 && s2 == 0) break;
      data[i].name = c[i];
      data[i].number = s1 + s2;
    }

    if(s1 == 0 && s2 == 0) break;
    sort(data, data+5, compare);
    cout << data[0].name << " " << data[0].number << endl;
  }

  return 0;
}

bool compare(const DATA& x, const DATA& y){
  return x.number > y.number;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10 ** 7)

N, M = map(int, input().split())
AB = [[int(x) for x in input().split()] for _ in range(M)]
G = [[] for _ in range(N+1)]
for a,b in AB:  
  G[a].append(b)
  G[b].append(a)
color = [None]*(N+1)  
# 二部グラフ判定
def dfs(v, c):
  color[v] = c
  for e in G[v]:
    if color[e] == None:
      color[e] = 1 - color[v]      
      dfs(e, c^1) # c^1 == xor (0+1==True)
dfs(1, 0)      
bl = all(color[a] != color[b] for a, b in AB)      
# ans
if bl:
  # 二部グラフ
  x = sum(color[1:])
  y = N-x
  print(x*y-M)
else:
  # 完全グラフ
  print(N*(N-1)//2-M)

Measured memory_bytes: 55780
using System;
using System.Collections.Generic;

namespace abc173
{
    class Program
    {
        static int[] ReadNumList()
        {
            var line = Console.ReadLine().Split(' ');
            var numList = new int[line.Length];
            for (var i = 0; i < line.Length; ++i)
            {
                numList[i] = int.Parse(line[i]);
            }
            return numList;
        }
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var aList = ReadNumList();
            Array.Sort(aList);

            var q = new Queue<int>();
            var total = 0L;
            q.Enqueue(aList[aList.Length - 1]);
            for (var i = aList.Length - 2; i >= 0; --i)
            {
                total += q.Dequeue();
                q.Enqueue(aList[i]);
                q.Enqueue(aList[i]);
            }
            Console.WriteLine(total);
        }
    }
}


Measured memory_bytes: 48204
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

string S[110];
int cnt[26];
int main()
{
	int H, W;
	cin >> H >> W;
	for (int i = 0; i < H; i++) cin >> S[i];
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cnt[S[i][j] - 'a']++;
		}
	}
	//for (int i = 0; i < 26; i++) cout << char('a' + i) << " " << cnt[i] << endl;
	if (H % 2 == 0 && W % 2 == 0) {
		for (int i = 0; i < H / 2 * W / 2; i++) {
			for (int j = 0; j < 26; j++) {
				if (cnt[j] >= 4) {
					cnt[j] -= 4;
					break;
				}
			}
		}
		for (int i = 0; i < 26; i++) {
			if (cnt[i] > 0) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	else if (H % 2 == 1 && W % 2 == 1) {
		for (int i = 0; i < H / 2 * W / 2; i++) {
			for (int j = 0; j < 26; j++) {
				if (cnt[j] >= 4) {
					cnt[j] -= 4;
					break;
				}
			}
		}
		for (int i = 0; i < H / 2 + W / 2; i++) {
			for (int j = 0; j < 26; j++) {
				if (cnt[j] >= 2) {
					cnt[j] -= 2;
					break;
				}
			}
		}
		for (int i = 0; i < 26; i++) {
			if (cnt[i] >= 1) {
				cnt[i] -= 1;
				break;
			}
		}
		for (int i = 0; i < 26; i++) {
			if (cnt[i] > 0) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	else {
		for (int i = 0; i < H / 2 * W / 2; i++) {
			for (int j = 0; j < 26; j++) {
				if (cnt[j] >= 4) {
					cnt[j] -= 4;
					break;
				}
			}
		}
		int n;
		if (H % 2 == 0) n = H / 2;
		else n = W / 2;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 26; j++) {
				if (cnt[j] >= 2) {
					cnt[j] -= 2;
					break;
				}
			}
		}
		for (int i = 0; i < 26; i++) {
			if (cnt[i] > 0) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}


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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second

#ifdef LOCAL
#define cerr cout
#else
#endif

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N = 1 << 16, M = 20;
int a[M];
const int mod = 1e9 + 7;
int fact[N], invfact[N];
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (((ll) x) * y) % mod;}
inline int powr(int a, ll b){
	int x = 1 % mod;
	while(b){
		if(b & 1) x = mul(x, a);
		a = mul(a, a);
		b >>= 1;
	}
	return x;
}
inline int inv(int a){ return powr(a, mod - 2);}
void pre(){
	fact[0] = invfact[0] = 1;
	for(int i = 1;i < N; i++) fact[i] = mul(i, fact[i - 1]);
	invfact[N - 1] = inv(fact[N - 1]);
	for(int i = N - 2; i >= 1; i--) invfact[i] = mul(invfact[i + 1], i + 1);
	assert(invfact[1] == 1);
}

inline int C(int n, int k){
	if(n < k || k < 0) return 0;
	return mul(fact[n], mul(invfact[k], invfact[n - k]));
}

inline int getRange(int x, int y){
	if(x > y) return 1;
	if(x <= 0 || y <= 0) return 0;
	return mul(fact[y], invfact[x - 1]);
}

int dp[M][N];
int main(){
	pre();
	int n, m;
	sd(n); sd(m);
	for(int i = 1; i <= m; i++) sd(a[i]);
	reverse(a + 1, a + m + 1);
	dp[0][0] = 1;
	for(int i = 1; i <= m; i++){ 
		for(int j = 0; j < (1 << n); j++){
			int available = (1 << n) - a[i] - j;
			int ways = dp[i - 1][j];
			dp[i][j] = add(dp[i][j], ways);
			for(int t = 0; t < n; t++){
				if(!(j >> t & 1)){
					dp[i][j ^ (1 << t)] = add(dp[i][j ^ (1 << t)], mul(1 << t, mul(ways,
					getRange(available - (1 << t) + 2, available))));
				}
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < (1 << n); i++){
		int ways = mul(fact[(1 << n) - 1 - i], dp[m][i]);
		if(__builtin_popcount(i) & 1){
			ans = sub(ans, ways);
		} else ans = add(ans, ways);
	}
	printf("%d\n", mul(1 << n, ans));
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a.at(i);
    vi b(n);
    ll sum = 0;
    rep(i,n-1) {
        sum += a.at(i);
        b.at(i) = sum % INF;
    }
    ll res = 0;
    rep(i,n-1){
        res += (a.at(i+1) * b.at(i)) % INF;
        res %= INF;
    }
    cout << res << endl;
}

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

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

  int n, s;
  vector<int> x;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    int xi;
    cin >> xi;

    x.push_back(xi);
  }

  x.push_back(s);

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

  int ans = -1;
  for (int i = 0; i < x.size() - 1; i++) {
    int diff = x.at(i + 1) - x.at(i);

    if (ans == -1) {
      ans = diff;
    } else {
      ans = __gcd(ans, diff);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 892
#include<iostream>
#define ll long long

using namespace std;

int main(void)

{
    ll k, c = 7, i, ans = -1;
    cin>>k;
    for(i = 1; i <= k; i++){
        if(c%k == 0){
            ans = i;
            break;
        }
        else c %= k;
            c = c*10+7;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
# define pb push_back
typedef long long ll;

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

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main(){
    ll a,b;
    cin >> a >> b;
    ll d = gcd(a,b);
    vector<pair<ll,ll>> f=prime_factorize(d);
    cout << f.size()+1;
}

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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cerr << #x << " : " << x << '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e16;

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

  LL ans;
  int A, B;
  cin >> A >> B;

  ans = (A + B) % 24;

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            long tmp = 0;
            long cnt = 0;
            while (true)
            {
                cnt++;
                tmp += n;
                if (tmp % 360 == 0)
                {
                    break;
                }
            }

            string result = cnt.ToString();
            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


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

using namespace std;

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

	if (A == B && A != C) {
		cout << "Yes" << endl;
	}
	else if (A == C && A != B) {
		cout << "Yes" << endl;
	}
	else if (B == C && A != C) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


}





Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
using namespace std;

bool a[1000000];

int main()
{
	int n;
	while (cin >> n)
	{
		if (n == 1)
		{
			cout << 0 << endl;
		}
		else
		{
			memset(a, false, sizeof(a));

			int cnt = 0;
			for (int i = 2; i <= n; i++)
			{
				if (a[i] == false)
				{
					cnt++;
					for (int j = 1; i * j <= n; j++)
					{
						a[i * j] = true;
					}
				}
			}
			cout << cnt << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 2144
# coding: utf-8
# Your code here!

n = input()
op_cnt = len(n) - 1  # すき間の個数
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt  # あらかじめ ["-", "-", "-"] というリストを作っておく
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[j] = "+"  # フラグが立っていた箇所を "+" で上書き

    formula = ""
    for p_n, p_o in zip(n, op + [""]):  # 少々モヤッとする
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Measured memory_bytes: 38256
#include<iostream>
int main(){
	int n;
	std::cin>>n;
	int s=100000;
	for(int i=0;i<n;i++){
		s*=1.05;
		if(s%1000!=0)s/=1000,s+=1;
		else s/=1000;
		s*=1000;
	}
	std::cout<<s<<std::endl;
	return 0;
}

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

int main(){
  int a,b,c,n;
  int j[1000],k[1000],l[1000],r[1000];
  int check[301];

  while(1){
    cin >> a >> b >> c;
    if(!a && !b && !c)break;

    for(int i=0;i<=a+b+c;i++)check[i] = 2;

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

    for(int i=0;i<n;i++){
      if(r[i]){
	check[j[i]] = 1;
	check[k[i]] = 1;
	check[l[i]] = 1;
      }
    }

    for(int i=0;i<n;i++){
      if(!r[i]){
	if(check[j[i]] == 1 && check[k[i]] == 1)check[l[i]] = 0;
	if(check[k[i]] == 1 && check[l[i]] == 1)check[j[i]] = 0;
	if(check[l[i]] == 1 && check[j[i]] == 1)check[k[i]] = 0;
      }
    }

    for(int i=1;i<=a+b+c;i++)cout << check[i] << endl;
  }
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = input()
'''
s_cnt = 0
for m in S:
    if m == 'S':
        s_cnt += 1
    elif m == 'T' and s_cnt > 0:
        s_cnt -= 1

print(2 * s_cnt)
'''
ans = []
for m in S:
    if m == 'S':
        ans.append(m)
    elif m == 'T':
        if ans and ans[-1] == 'S':
            ans.pop(-1)
        else:
            ans.append(m)
print(len(ans))

Measured memory_bytes: 5092
from collections import deque
 
N, M = map(int, input().split())
G = [[] for _ in range(N+1)]
for i in range(M):
  A, B = map(int, input().split())
  G[A].append(B)
  G[B].append(A)
 
seen = [0 for _ in range(N+1)]
seen[1] = 1
shirube = [-1 for _ in range(N+1)]
 
stack = deque([1])
while stack:
  now = stack.popleft()
  #print(now)
  for i in G[now]:
    if seen[i] == 0:
      seen[i] = 1
      stack.append(i)
      shirube[i] = now
      #print(shirube)
#print(G)
#print(seen)
#print(shirube)

for i in range(2,N+1):
  if seen[i] == 0:
    print('No')
    exit()
    
print('Yes')
for j in range(2,N+1):
  print(shirube[j])

Measured memory_bytes: 34832
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());

        var edges = new List<int>[n];
        for (int i = 0; i < edges.Length; ++i)
            edges[i] = new List<int>();

        for (var count = n - 1; count != 0; --count)
        {
            var list = Console.ReadLine().Split(' ');
            var a = int.Parse(list[0]) - 1;
            var b = int.Parse(list[1]) - 1;
            edges[a].Add(b);
            edges[b].Add(a);
        }

        var list2 = Console.ReadLine().Split(' ');
        var cs = new int[n];
        for (int i = 0; i < cs.Length; ++i)
            cs[i] = int.Parse(list2[i]);
        Array.Sort(cs);

        int total = 0;
        var weights = new int[n];

        var candidates = new HashSet<int>();
        for (int i = 0; i < edges.Length; ++i)
        {
            var count = edges[i].Count;
            if (count == 1)
                candidates.Add(i);
        }

        for (int i = 0; i < cs.Length; ++i)
        {
            var e = candidates.GetEnumerator();
            e.MoveNext();
            var candidate = e.Current;
            var edge = edges[candidate];
            for (; edge.Count > 1;)
            {
                e.MoveNext();
                candidate = e.Current;
                edge = edges[candidate];
            }
            e.Dispose();
            candidates.Remove(candidate);

            weights[candidate] = cs[i];

            if (edge.Count == 0)
                continue;

            total += cs[i];

            var next = edge[0];
            edge.Clear();
            edges[next].Remove(candidate);
            candidates.Add(next);
        }

        Console.WriteLine(total);
        for (int i = 0; i < weights.Length; ++i)
            Console.WriteLine(weights[i]);
    }

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


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

using ll = long long;

using namespace std;

int main() {
    int x, y;
    cin >> x >> y;
    for (int c = 0; c <= 100; c++) {
        for (int t = 0; t <= 100; t++) {
            if (c + t == x && c * 2 + t * 4 == y) {
                cout << "Yes" << '\n';
                return 0;
            }
        }
    }
    cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define all(x) (x).begin(),(x).end()
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

struct UnionFind {
  vector<int> par;

  UnionFind(int n) : par(n, -1) { }
  void init(int n) { par.assign(n, -1); }
  int root(int x) {
    if (par[x] < 0) return x;
    else return par[x] = root(par[x]);
  }
  bool issame(int x, int y) {
    return root(x) == root(y);
  }
  bool merge(int x, int 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;
  }
  int size(int x) {
    return -par[root(x)];
  }
};

int main() {
  ll N, M; cin >> N >> M;
  vector<int> A(M), B(M);
  rep(i, M) cin >> A[i] >> B[i], --A[i], --B[i];

  UnionFind uf(N);
  ll cur = N * (N-1) / 2;
  vector<ll> res;
  rep(i, M) {
    res.push_back(cur);

    int a = A[M-1-i], b = B[M-1-i];
    if (uf.issame(a, b)) continue;

    ll sa = uf.size(a), sb = uf.size(b);
    cur -= sa * sb;
    uf.merge(a, b);
  }

  reverse(all(res));
  rep(i, res.size()) cout << res[i] << endl;
}


Measured memory_bytes: 3444
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
    int a, b, d, r;
    double f;
    cin >> a >> b;
    d = a / b;
    r = a % b;
    f = double(a) / double(b);
    cout << d << " " << r << " " << fixed << setprecision(5) << f << endl;
    return 0;
}



Measured memory_bytes: 3284
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
    public static void Main(string[] args)
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToList();
        var n = input[0];
        var a = input[1];
        var b = input[2];
        var result = new Mint(2).Pow(n);
        result -= 1;
        result -= Mint.Combination(n, a);
        result -= Mint.Combination(n, b);
        Console.WriteLine(result);
    }
}

public class Mint
{
    public const long Mod = (long)1e9 + 7;
    public long Number { get; private set; }
    public Mint Inv => Pow(Mod - 2);

    public Mint(long number = 0)
    {
        Number = (number % Mod + Mod) % Mod;
    }

    public Mint Pow(long t)
    {
        if (t == 0)
        {
            return new Mint(1);
        }

        var result = Pow(t >> 1);
        result *= result;

        if ((t & 1) > 0)
        {
            result *= this;
        }

        return result;
    }

    public static Mint Combination(Mint m, Mint n)
        => Permutation(m, n) / Permutation(n, n);

    public static Mint Permutation(Mint m, Mint n)
        => Enumerable.Range(m - n + 1, n).Select(target => new Mint(target)).Aggregate((a, b) => a * b);

    public static Mint operator +(Mint m) => m;
    public static Mint operator -(Mint m) => new Mint(-m.Number);
    public static Mint operator +(Mint a, Mint b) => new Mint(a.Number + b.Number);
    public static Mint operator -(Mint a, Mint b) => new Mint(a.Number - b.Number);
    public static Mint operator *(Mint a, Mint b) => new Mint(a.Number * b.Number);
    public static Mint operator /(Mint a, Mint b) => a * b.Inv;
    public static implicit operator Mint(long i) => new Mint(i);
    public static implicit operator Mint(int i) => new Mint(i);
    public static implicit operator long(Mint m) => m.Number;
    public static implicit operator int(Mint m) => (int)m.Number;
    public override string ToString() => Number.ToString();
}


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

int main() {
  int A, B, C;
  int ans = 0;
  cin >> A >> B;
  
  C = B - A + 1;
  for (int i = 0; i < C; i++) {
   if (A / 10000 == A % 10 && (A % 10000) / 1000 == (A % 100) / 10) {
     ans++;
   }
    A++;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

#define DEBUG 0

#if DEBUG
  #define DLOG(...) fprintf(stderr, __VA_ARGS__)
  #define DFUNC(fname, ...) fname(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DFUNC(fname, ...)
#endif

ll A,B;

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> A >> B;
  ll x;
  if (A >= 13)  x = B;
  else if (A >= 6)  x = B / 2;
  else  x = 0;
  cout << x << endl;

  return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	Scanner sc;
	void run() {
		sc = new Scanner(System.in);
		while (true) {
			int n= sc.nextInt();
			if(n == 0) break;
			int cnt =0;
			for(int i=1;i<n;i++) for(int j=i+1;j<n;j++) {
				if (n == i*(j-i+1) + (j-i+1)*(j-i)/2 ) cnt++; 
			}
			System.out.println(cnt);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
b = gets.chop.split(" ").map(&:to_i)

if b[0] > b[1]
  s = b[1]
  b[1] = b[0]
  b[0] = s
end

if b[1] >= b[2] and b[0] <= b[2]
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=j;i<n;i++)
struct Card{ char suit,value;};
void bubblesort(struct Card A[],int N){
    rep(i,0,N){
        for(int j=N-1;j>i;j--){
            if(A[j].value<A[j-1].value)swap(A[j],A[j-1]);
        }
    }
}
void selectionsort(struct Card A[],int n){
    rep(i,0,n-1){
        int minv=i;
        rep(j,i+1,n){
            if(A[minv].value>A[j].value)minv=j;
        }
        if(minv!=i)swap(A[i],A[minv]);
    }
}
void print(int n,struct Card A[]){
    rep(i,0,n-1)cout<<A[i].suit<<A[i].value<<" ";
    cout<<A[n-1].suit<<A[n-1].value<<endl;
}
bool ST(struct Card C1[],struct Card C2[],int n){
    rep(i,0,n){
        if(C1[i].suit!=C2[i].suit)return false;
    }
    return true;
}
int main(){
    int n;cin>>n;
    Card C1[n],C2[n];
    rep(i,0,n){
        cin>>C1[i].suit>>C1[i].value;
        C2[i]=C1[i];
    }
    bubblesort(C1,n);
    selectionsort(C2,n);
    print(n,C1);
    cout<<"Stable"<<endl;
    print(n,C2);
    if(ST(C1,C2,n))cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;
}


Measured memory_bytes: 3124
N = int(input())
Ss = [input() for _ in range(N)]

import collections

c = collections.Counter(Ss)

print("AC x " + str(c["AC"]))
print("WA x " + str(c["WA"]))
print("TLE x " + str(c["TLE"]))
print("RE x " + str(c["RE"]))

Measured memory_bytes: 16464
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
int N;
int a,b,c,d;
cin>>N;
for (int i=0; i<N; i++){
    cin>>a>>b>>c>>d;
    int e=(a*c)+(b*d);
    e=min(e,4*(a*max(c,5)+b*max(d,2))/5);
    cout<<e<<endl;
    
}




}



Measured memory_bytes: 3104
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	S := nextLine()
	ans := make([]int, len(S))
	var memo, cnt int
	cnt++
	for i := 1; i < len(S); i++ {
		if S[i-1] == 'R' && S[i] == 'L' {
			ans[i-1] += (cnt + 1) / 2
			ans[i] += cnt / 2
			memo = i
			cnt = 0
		}
		if S[i-1] == 'L' && S[i] == 'R' {
			ans[memo-1] += cnt / 2
			ans[memo] += (cnt + 1) / 2
			cnt = 0
		}
		cnt++
		if i == len(S)-1 {
			ans[memo-1] += cnt / 2
			ans[memo] += (cnt + 1) / 2
		}
		// fmt.Println(i, ans, memo, cnt, string(S[i])
	}
	fmt.Println(strings.Trim(fmt.Sprint(ans), "[]"))
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

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

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
    	ll i,j,k,l,m,n;
    	cin>>n;
    	double y;
    	y=(2*pii*1.0*n);
    	cout<<setprecision(20)<<y;
    }
    return 0;
}

Measured memory_bytes: 3816
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int H,W;
char field[51][51];

int main(){
	cin >> H >> W;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin >> field[i][j];
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(field[i][j]=='#'){
				if(field[i-1][j]=='#'|| field[i+1][j]=='#' || field[i][j-1]=='#'|| field[i][j+1]=='#'){
					int x=0;
				}
				else{
					cout << "No" <<  endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;

}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector <int> R(N, 0);
    int n;
    for (int i=0; i<M*2; i++) {
       cin >> n;
       R.at(n-1)++;
    }
    for (int r : R) cout << r << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(){

    char words[1200];
    for(int i = 0;i<1200;i++){
        scanf("%c",&words[i]);
        if(words[i] == '\n'){
            break;
        }
    }

    for(int i = 0;i<1200;i++){
        if(65 <= words[i] && words[i] <= 90){
            printf("%c",words[i]+32);
        }else if(97 <= words[i] && words[i] <= 122){
            printf("%c",words[i]-32);
        }else{
            printf("%c",words[i]);
        }   
        if(words[i] == '\n'){
            break;
        }
    }

    return 0;
}



Measured memory_bytes: 2692
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve()
{
	int n, r;
	cin >> n >> r;
	cout << max(0, 10 - n) * 100 + r;
}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <cstring>
#include <algorithm>
#include <iostream> 
#include <cmath>
#include <map>
 
using namespace std;
typedef long long ll;
typedef long double ld;

const ll MOD=ll(1e9+7);

//repetition
#define REP(i,n)  for(ll i=0;i<n;i++)

ll P_POW(ll i, ll n) {
  if(n==0) return 1;

  n--;
  ll rep = i;

  while(n) {
    rep = rep * i;
    n--;
  }
  return rep;
} 

unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
 
unsigned binarySearch(ll target, ll max, ll min) {
  while((max - min) > 1) {
      if((max + min)/2 > target) {
        max = (max + min)/2;
        min = min;
      } else {
        max = max;
        min = (max + min)/2;
      }
    }
}

ll n;


long long solve2(long long N) {
    if (N % 2 == 1) return 0;

    long long res = 0;
    N /= 2;
    while (N) {
        res += N / 5;
        cout << "N/5: " << N/5 <<  endl;
        cout << "res1: " << res <<  endl;
        N /= 5;
    }
    return res;
}


ll solve(ll n) {
    if (n % 2 == 1) return 0;

    ll res = 0;
    n /= 2;
    int c = 1;

    while ((ll) n/((ll)pow(5,c))) {
      res += n/P_POW(5,c);
      c++;
    }
    return res;
}

void f(int rest, string s) {
  char abc[] = "abc";
  if(rest == 0) {
    cout << s << endl;
  } else {
    for(int i=0; i < 3; i++) {
      f(rest - 1, s+abc[i]);
    }
  }
}

int main() {
  ll n;
  cin >> n;
  // 2次元vector
  //vector<vector<ll>> a(n ,vector<ll>{2,0});
  //vector<ll> s(n,0);
  //vector<vector<ll>> v;
  
  std::map<ll,ll> m;

  for(ll i = 1; i < n + 1; i++) {
    ll a;
    cin >> a;
    if(m[a] == 0) m[a] = 1;
    else m[a] = m[a] + 1;
    //cout << v1[5] << endl;
  }


  ll t = 0;
  for( auto i = m.begin(); i != m.end() ; ++i ) {
    if(i->first < i->second) t = t + (i->second) - (i->first);
    if(i->first > i->second) t = t + (i->second);
    //cout << v[i] << endl;
  }
  cout << t << endl;


}


Measured memory_bytes: 6272
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define pb push_back
#define lp(j, n)  for(int j=0; j<(int)(n); ++j)
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
#define F first
#define S second
#define m_p make_pair
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int,int> > vpii;
typedef map<int, int> mii;
const ll N=1e5+5;
ll arr[N],A[N],ARR[N]  ;
bool visited[N]={};
int cnt[N]={};
bool f;
int main()
{

 int n,a;
 vpii vp;
 cin>>n;
 for(int i=1;i<=n ; i++)
 {
     cin>>a;
     vp.pb(m_p(a,i));
 }
sort(all(vp));
for(int i=0 ;i<vp.size() ; i++)
{
    cout<<vp[i].S<<" ";
}
go;
}


Measured memory_bytes: 1780
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#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 repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>h(n); rep(i, n)cin >> h[i];
	vector<int>dp(n+1); rep(i, n+1)dp[i] = INF;
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if (i >= 2)chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n-1] << endl;
	return 0;
}

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

a = []
k = []
for _ in range(n):
    ka = [int(i) for i in input().split()]
    k.append(ka[0])
    a.append(ka[1:])

#%%

mlist = [0] * m

#%%
for i in range(len(a)):
    for j in range(len(a[i])):
        mlist[a[i][j] - 1] += 1

counter = 0
for mlisti in mlist:
    if mlisti == n:
        counter += 1

print(counter)
#%%


Measured memory_bytes: 3064
s = list(input())
if s[0] == "A":
  C = []
  for i in range(2, len(s)-1):
    if s[i] == "C":
      C.append(i)
  if len(C) != 1:
    print("WA")
  else:
    up = False
    for j in range(1,len(s)):
      if j == C[0]:
        continue
      elif not s[j].islower():
        up = True
    if up:
      print("WA")
    else:
      print("AC")
else:
  print("WA")
    


Measured memory_bytes: 3060
N = gets.to_i
xs, ys = [], []
N.times do |i|
    xs[i], ys[i] = gets.split.map(&:to_i)
end
MOD = 998244353

pmod2 = [1]
(1..N).each do |i|
    pmod2[i] = pmod2[i-1] * 2 % MOD
end

ans = (pmod2[N] - N - 1) % MOD
checked = Array.new(N){Array.new(N)}

N.times do |i|
    ((i+1)...N).each do |j|
        next if checked[i][j]
        pts = [i, j]
        ((j+1)...N).each do |k|
            if (xs[j]-xs[i]) * (ys[k]-ys[i]) == (xs[k]-xs[i]) * (ys[j]-ys[i])
                pts.push(k)
            end
        end
        num = pts.length
        ans = (ans - pmod2[num] + num + 1) % MOD
        num.times do |a|
            ((a+1)...num).each do |b|
                checked[pts[a]][pts[b]] = true
            end
        end
    end
end
puts ans

Measured memory_bytes: 2172
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
static const double EPS = 1e-8;
typedef long long ll;

int main()
{
	int a, b, c, d, e, f;
	while (scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f)
		, a || b || c || d || e || f)
	{
		int x, y, z;
		x = a + d;
		y = b + e;
		z = c + f;

		int ans = 0;
		for (int i = 0; i <= min(2, min(x, min(y, z))); ++i)
			ans = max(ans, i + (x-i)/3 + (y-i)/3 + (z-i)/3);

		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)(j);i <= (int)(k);i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define fix cout<<fixed<<setprecision(20);
const int maxn=(int)1e6+5;

typedef long long ll;
const ll N=2e5+7;
ll dp[N][2];
ll arr[N];
int main(){
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++)  cin>>arr[i];
    dp[2][0]=arr[1];
    dp[2][1]=arr[2];
    rep(i,3,n){
        if(i&1){
            dp[i][1]=max({dp[i-2][0],dp[i-2][1],dp[i-3][0],dp[i-3][0]})+arr[i];// 7 <- 5,4
            dp[i][0]=max(dp[i-1][1],dp[i-1][0]);//7<-6
        }
        else {
            dp[i][1]=max({dp[i-2][1],dp[i-2][0]})+arr[i];//6<-4 no 5 because dp[5][0]=max(dp[4][1],dp[4][0])
            dp[i][0]=dp[i-2][0]+arr[i-1];//6<-4 because dp[4][0]must take a[1] a[3]
        }
    }
    cout<<max(dp[n][0],dp[n][1])<<endl;
    return 0;
}
/* 
if N%2==0 2 choice


if N%2==1
dp[i][flag] 前i项，最后一项flag？拿:not take  
不行，还要记录拿几个（其实是可以的，再加一个约束：取i/2个，转移的时候不会考虑别的）
dp[i][j]
j=i/2-1 .. (i+1)/2
i=4 j= 1 2
i=3 j= 0 1 2
i=5 j= 1 2 3
5
1 2 3 4 5
1 3
1 4 
1 5
2 4
2 5
3 5
 */

Measured memory_bytes: 8280
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=200005;
int a[N];
vector<int> ind;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=n;i>=1;i--)
    {
        if(a[i]==1)
        {
            ind.push_back(i);
            if((int)sqrt(i)==sqrt(i))
            {
                for(int j=1;j<(int)sqrt(i);j++)
                {
                    if(i%j==0)
                    {
                        a[j]=(a[j]^1);
                        a[i/j]=(a[i/j]^1);
                    }
                }
                int x=(int)sqrt(i);
                a[x]=(a[x]^1);
                continue;
            }
            for(int j=1;j<=(int)sqrt(i);j++)
            {
                if(i%j==0)
                {
                    a[j]=(a[j]^1);
                    a[i/j]=(a[i/j]^1);
                }
            }
        }
    }
    bool ans=true;
    for(int i=1;i<=n;i++)
        if(a[i]==1)
            ans=false;
    if(ans==false)
    {
        cout<<-1<<endl;
        return 0;
    }
    reverse(ind.begin(),ind.end());
    cout<<ind.size()<<endl;
    for(int i=0;i<ind.size();i++)
        cout<<ind[i]<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 2424
dummy = list(map(int, input().split(" ")))
N = dummy[0]
K = dummy[1]
p = list(map(int, input().split(" ")))
p = [(dummy + 1) / 2 for dummy in p]
dummy = sum(p[:K])
convert = []
for i in range(N - K + 1):
    convert.append(dummy)
    if(i < N - K):
        dummy = dummy - p[i] + p[K + i]

print(max(convert))

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

using namespace std;
using LL = long long int;

const int MAX_N = 100005;

int N;
int A[MAX_N];
map<int, int> M;

int main() {
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    M[A[i]]++;
  }

  int ans = 0;
  for(auto it : M) {
    if(it.first < it.second) {
      ans += it.second - it.first;
    } else if(it.first > it.second) {
      ans += it.second;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5120
import collections
N = int(input())
a = list(map(int,input().split()))
B = collections.Counter(a)
k = list(B.keys())
v = list(B.values())

ans = "Yes"
if len(B) == 3 and k[0]^k[1]^k[2] == 0 and v[0] == v[1] == v[2]: pass
elif len(B) == 2 and 0 in k and (v[0] == 2*v[1] or v[1] == 2*v[0]): pass
elif len(B) == 1 and 0 in k: pass
else: ans = "No"
print(ans)

Measured memory_bytes: 20808
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int n; cin >> n;
  cout << 10 - n / 200 << endl;
  return 0;
}


Measured memory_bytes: 3620