akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000000000000000
typedef long long ll;

struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = mod;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e1, e2;
    e1.to = t, e1.cost = cost;
	e2.to = s, e2.cost = cost;
    G[s].push_back(e1);
    G[t].push_back(e2);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = mod;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};

int main(){
  ll n;
  cin >> n;
  graph g(n);
  rep(i, n-1){
    ll a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    g.add_edge(a,b,c);
  }
  ll q, k;
  cin >> q >> k;
  k--;
  g.dijkstra(k);
  rep(i, q){
    ll x, y;
    cin >> x >> y;
    x--; y--;
    cout << g.d[x]+g.d[y] << endl;
  }
  return 0;
}
  


Measured memory_bytes: 14104
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
#define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
#define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/
int gcd(int a, int b) {
  if (a > b) swap(a, b);
  if (a == 0) return b;
  return gcd(b%a, a);
}





int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.precision(10); cout << fixed;
#ifdef LOCAL
  freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
  int n; cin >> n;
  int tmp = gcd(n, 360);
  cout <<  360 / tmp << endl;







/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
  return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


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

long long r, n, m, ans = 0, now = 0, nextn = 0;
map<long long, long long> mp;
vector<long long> a;

int main() {
  long long i;
  cin >> n >> m;
  for(i = 0; i < n; ++i) {
    cin >> r;
    now += r;
    now %= m;
    if(mp.find(now) == mp.end())
      mp[now] = 1;
    else
      ++mp[now];
    a.push_back(r % m);
  }
  nextn = 0;
  // lを固定したときの数
  for(i = 0; i < n; ++i) {
    if(mp.find((nextn) % m) != mp.end() &&
       mp[(nextn) % m] > 0)
      ans += mp[(nextn) % m];
    nextn += a[i];
    nextn %= m;
    --mp[nextn];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5240
#include <bits/stdc++.h>
#define f(i,a,b) for(i=a;i<=b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define ll long long
#define mod (1000*1000*1000+7)
#define scan1(x) scanf("%lld",&x)
#define scan2(x,y) scanf("%lld %lld",&x,&y)
#define scan3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define print(x) printf("%lld\n",x)
#define ff first
#define ss second
using namespace std;


int main(){
    ll n,w,i,j;
    scan2(n,w);
    vector<vector<ll>> dp(n+1,vector<ll>(w+1));
    vector<ll> weight(n),value(n);
    f(i,0,n-1)
    scan2(weight[i],value[i]);
    
    dp[0][weight[0]]=value[0];
    
    f(i,1,n-1){
        if(weight[i]<=w)
        dp[i][weight[i]]=value[i];
        
        ll curr_weight=weight[i];
        ll curr_value=value[i];
        f(j,1,w)
        if(dp[i-1][j]){
            
            if(j+curr_weight<=w)
            dp[i][j+curr_weight]=max(dp[i][j+curr_weight],dp[i-1][j]+curr_value);
            
            dp[i][j]=max(dp[i-1][j],dp[i][j]);
            
        }
    }
    
    ll ans=INT_MIN;
    
    f(i,1,w)
    ans=max(ans,dp[n-1][i]);
    cout<<ans<<endl;
    
}

Measured memory_bytes: 80256
from itertools import permutations
n, m = map(int, input().split())

# 各edgeが結ばれているかどうかを二次元配列で保持(0:エッジなし, 1:エッジあり)
edges = [[0 for _ in range(n)] for _ in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    edges[a-1][b-1] = 1
    edges[b-1][a-1] = 1

ans = 0
for l in permutations(range(1,n)):
    l = [0] + list(l)
    cnt = 1
    for i in range(n-1):
        # エッジを持たない場合はカウントしない
        if edges[l[i]][l[i+1]] == 0:
            cnt = 0
            break
    ans += cnt
print(ans)

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

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

  if (A == B) {
    cout << A * 2 << endl;
  }
  else if (A > B) {
    cout << A * 2 - 1 << endl;
  }
  else {
    cout << B * 2 - 1 << endl;
  }
}


Measured memory_bytes: 256
import Control.Applicative
import Data.List
import Data.Array
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

listToTuple2 [a,b] = (a,b)
readIntBS = fst . fromJust . BS.readInt

main :: IO ()
main = do
  (n,k) <- listToTuple2 . map read . words <$> getLine :: IO (Int,Int)
  xs <- map readIntBS . BS.words <$> BS.getLine :: IO [Int]

  let
    (a,b) = span (<0) xs
    a_ = listArray (0,length a) $ 0 : (reverse $ map negate a)
    b_ = listArray (0,length b) $ 0 : b

  print $ minimum [min (a_!l*2+b_!r) (a_!l+b_!r*2) | l<-[0..length a], let r=if k-l<0 then 0 else k-l, r<=length b]


Measured memory_bytes: 16764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long LLINF = 1LL<<60;
const int INF = 1e9;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum+1; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int x; cin >> x;
    REP(i,x,100000000) {
        if(IsPrime(i)) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  vector<int> a;
  unordered_map<int, int> cnt;
  unordered_map<int, int> to;
  Solver(LL n) : n(n), a(n){};
  int comp(LL x) {
    LL m = 1;
    while (m <= x) {
      m *= 2;
    }
    return m - x;
  }
  void solve() {
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      cnt[a[i]]++;
      int c = comp(a[i]);
      if (c <= a[i]) {
        to[a[i]] = c;
      }
    }
    sort(a.rbegin(), a.rend());
    a.erase(unique(a.begin(), a.end()), a.end());
    DBG(a)
    DBG(cnt)
    DBG(to)
    int N = a.size();
    //vector<vector<int>> dp(N);
    //dp[N - 1].resize(cnt[a[N - 1]] + 1);
    /*for (int i = 0; i < dp[N - 1].size(); ++i) {
      dp[N - 1][i] = 0;
    }*/
    int ans = 0;
    for (int i = 0; i < N; ++i) {
      if (to[a[i]] == a[i]) {
        ans += cnt[a[i]] / 2;
      } else {
        int m = min(cnt[a[i]], cnt[to[a[i]]]);
        ans += m;
        cnt[to[a[i]]] -= m;
        cnt[a[i]] -= m;
      }
      DBG(a[i], ans)
      DBG(cnt)
      DBG(to)
    }
    cout << ans << endl;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 25916
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

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

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n,a,b;
    cin >> n >> a >> b;

    string s;
    cin >> s;

    int pass=0;
    int passfor=1;
    for(int i=0;i<n;i++){
        if(s[i]=='a' && pass<a+b){
            cout << "Yes" << endl;
            pass++;
            continue;
        }
        if(s[i]=='b' && pass<a+b){
            if(passfor<=b){
                cout << "Yes" << endl;
                pass++;
                passfor++;
                continue;
            }
        }
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3712
n, m = map(int, input().split())
a = [0] * n
k = [0] * n

ans = 0
for i in range(n):
    a[i] = list(map(int, input().split()))
    k[i] = a[i].pop(0)

b = [b for inner in a for b in inner]

for i in range(m):
    ans += (b.count(i+1) == n)

print(ans)


Measured memory_bytes: 3064
import collections
n = int(input())
a = [int(i) for i in input().split()]
ans = n
even = 0
c = collections.Counter(a)
for i in c:
        ans-=c[i]-1
        if c[i]%2 == 0:
                even += 1
if even%2 == 1:
        ans -= 1
print(ans)       

Measured memory_bytes: 18656
#include<iostream>
#include<vector>
#include<queue>
#define N 200000+5
using namespace std;
int n,color[N];
vector<int> ve[N];
queue<int> qu;
int main()
{
	cin>>n;
	color[1]=1,color[n]=2;
	for(int i=1;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		ve[x].push_back(y);
		ve[y].push_back(x);
	}
	qu.push(1),qu.push(n); 
	int sum[3]={0};
	while(!qu.empty()) 
	{
		int aim = qu.front();
		qu.pop();
		for(int i=0;i<ve[aim].size();i++)
		{
			if(color[ve[aim][i]]) continue;
			color[ve[aim][i]] = color[aim];
			qu.push(ve[aim][i]);
			sum[color[aim]]++;
		}
	}
	if(sum[1]>sum[2]) cout<<"Fennec"<<endl;
	else cout<<"Snuke"<<endl;
	return 0;
}

Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef vector<int> vec;
int main(){
  long double a,b,c,r,l;
  cin>>a>>b>>c;
  r=c-a-b;
  l=2*sqrt(a*b);
  
  cout<<(l<r?"Yes":"No");
  
}


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

using namespace std;

int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(a-c)<=d)cout<<"Yes";
    else if(abs(a-b)<=d&&abs(b-c)<=d)cout<<"Yes";
    else cout<<"No";
    return 0;
}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

Measured memory_bytes: 256
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
//string str;
//long long A[26];
int N;
int main(){
	cin>>N;
	if((N/10)==9){
		cout<<"Yes"<<endl;
	}else if((N-N/10*10)==9){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}

	}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX = 10000;
// const ll INF = 1LL<<60;
// // typedef struct Node { ll num; char c; } node;
// const ll N_MAX = 2000001;
// const ll V_MAX = 10000;
const int NIL = -1;

struct node { int parant, left, right; };
vector<int> depth, height;
vector<struct node> tree;

void preParse(int u) {
    if(u == NIL) return;
    printf(" %d", u);
    preParse(tree.at(u).left);
    preParse(tree.at(u).right);
}

void inParse(int u) {
    if(u == NIL) return;
    inParse(tree.at(u).left);
    printf(" %d", u);
    inParse(tree.at(u).right);
}

void postParse(int u) {
    if(u == NIL) return;
    postParse(tree.at(u).left);
    postParse(tree.at(u).right);
    printf(" %d", u);
}

signed main() {
    ll n; scanf("%lld", &n); 
    depth.resize(n); tree.resize(n); height.resize(n);
    ll l, c;
    for( ll i = 0; i < n; i++ ) tree.at(i).parant = NIL;
    for( ll i = 0; i < n; i++ ) {
        ll v, l, d; cin >> v >> l >> d;
        tree.at(v).left = l;
        tree.at(v).right = d;
        if( l != NIL ) tree.at(l).parant = v;
        if( d != NIL ) tree.at(d).parant = v;
    }
    int root = 0;
    for(ll i = 0; i < n; i++) if( tree.at(i).parant == NIL ) root = i;
    printf("Preorder\n");
    preParse(root);
    putchar('\n');
    printf("Inorder\n");
    inParse(root);
    putchar('\n');
    printf("Postorder\n");
    postParse(root);
    putchar('\n');

    return 0;
}




Measured memory_bytes: 3180
n = int(input())
AB = [list(map(int, input().split())) for _ in range(n)]
AB.sort(reverse = True,key = lambda x:x[0]+x[1])
ans = 0
for i in range(n):
    if i % 2 == 0:
        ans += AB[i][0]
    else:
        ans -= AB[i][1]
print(ans)


Measured memory_bytes: 32224
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	ll x;
	cin >> x;
	if(x % 2 == 1)
		x*=2;
	cout << x;
		





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 256
//#include "SaveFuncs.cpp"

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
//#define int long long
constexpr int INF = 2000000100;
constexpr int DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> T divUp(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T math_C(T m, T n) { T ret = mathP(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
bool compare_by_b(pair<int, int> a, pair<int, int> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }

/*****/

int Main()
{
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>> A(N);
	rep(i, N)
	{
		int a, b;
		cin >> a >> b;
		A.at(i) = pair(a, b);
	}

	sort(all(A), compare_by_b);
	reverse(all(A));

	vector<int> P(M, -1), PEnd(M + 1);
	int remain = M;
	int ret = 0;

	rep(i, M)
	{
		PEnd.at(i) = i;
	}

	rep(i, N)
	{
		if (remain == 0)
			break;

		if (A.at(i).first >= M + 1)
			continue;

		bool ok = true;
		for (int j = PEnd.at(A.at(i).first - 1); j < M; j++)
		{
			if (P.at(j) == -1)
			{
				ret += A.at(i).second;
				P.at(j) = i;
				remain--;
				PEnd.at(A.at(i).first) = j + 1;
				ok = false;
				break;
			}
		}
		if (ok)
		{
			PEnd.at(A.at(i).first) = M;
		}
	}

	cout << ret;

	return 0;
}

/*****/

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

	Main();

	return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<vector>
using namespace std;
int s(long long x){
	if(!x) return 0;
	return x%10 + s(x/10);
}

int main(){
	int K;
	cin >> K;
	long long n=1, d=1;
	cout << 1 << endl;
	K--;
	while(K--){
		if(s(n+10*d)*(n+d) > (n+10*d)*s(n+d)) d*= 10;
		// cout << "n+d=" << n+d << endl;
		// cout << "n+10*d=" <<n+10*d << endl; 
		n+=d;
		cout << n << endl;
		// cout << "-------------" << endl;
	}
}



Measured memory_bytes: 256
package main

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

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

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	pre := -1
	count := 0
	maxcount := 0
	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		if(pre < a){
			if(maxcount < count){
				maxcount = count
			}
			count = 0
		}else{
			count++
		}
		pre = a
	}
	if(maxcount < count){
		maxcount = count
	}
	fmt.Print(maxcount)
}

Measured memory_bytes: 2176
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
using namespace std;

using int64 = long long;
using int128 = __int128;

#define repeat(i, n) for (auto i = decltype(n)(); (i) < (n); (i)++)

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

  int deg[4] = {};
  repeat (i, 3) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    deg[a]++;
    deg[b]++;
  }
  sort(deg, deg + 4);

  if (deg[2] >= 2) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,f[1005][5],i,j,t;
	for(;scanf("%d",&n),n;)
	{
		for(i=0;i<=n;f[i][4]=f[i][1]*4+f[i][2]*9+f[i][3]*4,i++)
			for(j=0;j<4;j++)
				scanf("%d",&f[i][j]);
		for(i=t=0;i<n;i++)
		{
			for(j=1;j<5&&f[i][j]<=f[n][j-1];)
				j++;
			if(j==5)
				t=printf("%d\n",f[i][0]);
		}
		if(!t)
			puts("NA");
	}
	return 0;
}

Measured memory_bytes: 632
n,m=map(int,input().split())
h=list(map(int,input().split()))
road=[]
for i in range(m):
    road.append(list(map(int,input().split())))
tall=[1 for _ in range(n)]
for i in range(m):
    if h[road[i][0]-1]>h[road[i][1]-1]:
        tall[road[i][1]-1]=0
    elif h[road[i][0]-1]==h[road[i][1]-1]:
        tall[road[i][1]-1]=0
        tall[road[i][0]-1]=0
    else:
        tall[road[i][0]-1]=0
counter=0
for i in range(n):
    if tall[i] == 1:
        counter+=1
print(counter)

Measured memory_bytes: 31988
#include<stdio.h>

int main(){

    int N;
    scanf("%d", &N);

    int A[N];
    for (int i = 0; i < N; i++){
        scanf("%d", &A[i]);
    }

    int B[N];
    for (int i = 0; i < N; i++){
        scanf("%d", &B[i]);
    }

    int C[N-1];
    for (int i = 0; i < N-1; i++){
        scanf("%d", &C[i]);
    }

    int score = 0;

    for (int i = 0; i < N; i++){
        score += B[A[i]-1];

        if(i > 0 && A[i] == A[i-1] + 1){
            score += C[A[i-1]-1];
        }

        //printf("%d\n", score);
    }

    printf("%d", score);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	vector<int> n(3);
	cin >> n[0] >> n[1] >> n[2];
	int cnt5 = count(n.begin(), n.end(), 5);
	int cnt7 = count(n.begin(), n.end(), 7);
	if (cnt5 == 2 && cnt7 == 1) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    string s;
    cin >> s;
    string ans = "";
    rep(i, s.size())
    {
        if (s[i] == '0')
        {
            ans.push_back('0');
        }
        else if (s[i] == '1')
        {
            ans.push_back('1');
        }
        else
        {
            if (ans.size() > 0)
            {
                ans.erase(ans.end() - 1);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize "03"
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

signed main() {
	#ifdef LOCAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	IOS;
	int n;
	cin >> n;
	ld cur = 0;
	for(int i = 1; i <= n; i++){
		ld x;	cin >> x;
		if(cur == 0)
			cur = x;
		else
			cur = (cur*x)/(cur + x); 
	}	
	cout << setprecision(6) << fixed << cur;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    int b;
    int min = 0;
    for(int i = 0; i < n;i++){
        cin >> a[i];
    }
    for(int i = 0; i < n ; i++){
        b = 0;
        while(a[i]%2 != 1 && a[i] >= 2){
            a[i] = a[i]/2;
            b++;
        }
        if(i == 0){
            min = b;
        }
        if(min >= b){
            min = b;
        }
    }
    cout << min << endl;
}

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

#define pb            push_back
#define mp            make_pair
#define all(x)        x.begin(),x.end()
#define debug(X)      { cerr<<'\n'<<(#X)<<" = "<<(X)<<'\n'; }
//#define cerr if(0)cerr

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;


int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,k,h,sum=0;

    cin>>n>>k;
    while (n--) {
        cin >> h;
        if (h>=k)++sum;
    }
    cout<<sum<<'\n';
}



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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};

struct UF
{
  vector<int> par; // 親のインデックスを記憶する配列
  vector<int> sz; // サイズを記憶する。
  vector<int> rank;
  // 初期化
  UF(int n):par(n),sz(n),rank(n){
    for(int i = 0; i < n; i++){
      par[i] = i;sz[i] = 1;rank[i] = 0;
    }
  }
  // 親を求める
  int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
  }
  // xとyの属する集合を併合
  void merge(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if(rank[x] < rank[y]){
      par[x] = y;
      sz[y] += sz[x];
    }
    else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x] == rank[y])rank[x]++;
    }
  }
  // xとyが同じ集合ならtrue
  bool same(int x, int y) { return find(x) == find(y); }
  // 素の集合のサイズを求める
  int size(int n){return sz[find(n)];}
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;cin>>n>>m;
  UF uni(n+10);
  int lang[m+10]={};
  for(int i=0;i<n;i++){
    int k;cin>>k;
    for(int j=0;j<k;j++){
      int a;cin>>a;
      if(i==0)lang[a]=i+1;
      else{
	if(lang[a]){
	  uni.merge(i+1,lang[a]);
	}else{
	  lang[a]=i+1;
	}
      }
    }
  }
  bool ans=false;
  for(int i=1;i<=n;i++){
    if(uni.size(i)==n)ans=true;
  }
  YES(ans);
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>




typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)



ll fast_pow(ll x,ll n,ll mod){
    if (n==0) return 1;
    ll res=fast_pow(x*x %mod,n/2,mod);
    if (n&1) res=res*x%mod;
    return res;
}

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;



int main(){
    int n;
    cin>>n;
    map<string,int> mp;
    rep(i,n){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    ll ans=0;
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        int a=(*itr).second;
        ans+=(ll) a*(a-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11136
#include<iostream>
using namespace std;
int main(){
  while(1){
    int x,y,s,ans=0,a,b;
  cin>>x>>y>>s;
  if(x==0)break;
  for(a=1;a<s;a++)
    for(b=a;b<s;b++){
      int m=a*(100+y)/100+b*(100+y)/100;
      if(a*(100+x)/100+b*(100+x)/100==s&&ans<m)ans=m;
    }
  cout<<ans<<endl;
  }
  return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if (a % 2 == 0 || b % 2 == 0)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

for i in range(len(A)):
  if A[i] %2 == 0:
    if A[i] %3 != 0 and A[i] %5 != 0:
      print("DENIED")
      exit()
    else:
      pass
  else:
    pass
  
print("APPROVED")

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

n = int(input().strip())
xy = []
for i in range(n):
    xy.append([int(j) for j in input().strip().split()])

def dist(a, b):
    return ((a[0] - b[0])**2 + (a[1] - b[1])**2)**(1/2)

d = 0
for g in range(n):
    for h in range(g+1, n):
        d += dist(xy[g], xy[h])

       
print(2*d/n)
        

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  long long x,cnt=1,y;
  cin >> x;
  int ans=0;
  while(ans<x){
    ans+=1000;
  }
  cout << ans-x;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
 }
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
// gcd lcm
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
  ll n;
  cin>>n;
  string s;
  cin>>s;
  vll r(n+1),g(n+1),b(n+1);
  rep(i,n){
    if(s[i]=='R') r[i+1]++;
    if(s[i]=='G') g[i+1]++;
    if(s[i]=='B') b[i+1]++;
  }
  rep(i,n){
    r[i+1]+=r[i];
    g[i+1]+=g[i];
    b[i+1]+=b[i];
  }
  ll ans=0;
  for(int i=0;i<n;i++){
    for(int j=i+3;j<n;j++){
      if(s[i]==s[j]) continue;
      if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R')){
        ans+=g[j]-g[i];
        if((j-i)%2==0){
          if(s[j-(j-i)/2]=='G'){
            ans--;
          }
        }
      }
      if((s[i]=='G'&&s[j]=='B')||(s[i]=='B'&&s[j]=='G')){
        ans+=r[j]-r[i];
        if((j-i)%2==0){
          if(s[j-(j-i)/2]=='R'){
            ans--;
          }
        }
      }
      if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R')){
        ans+=b[j]-b[i];
        if((j-i)%2==0){
          if(s[j-(j-i)/2]=='B'){
            ans--;
          }
        }
      }
    }
  }
  COUT(ans);
}

Measured memory_bytes: 3736
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {


		String S = nextString();
		int revFlg=-1;
		int Q = nextInt();
		int T=0 ;
		int F=0;
		String C="";

		ArrayDeque<String> q = new ArrayDeque<>(Q+S.length());
		String[] s = toStringArray(S);
		for(int i=0;i<s.length;i++){
			q.add(s[i]);
		}
		for(int i=0;i<Q;i++){
			T=nextInt();
			if(T==2){
				F=nextInt();
				C=nextString();
			}
			if(T==1){
				revFlg*=-1;
			}else{
				if(F==1){
					if(revFlg==-1){
						q.addFirst(C);
					}else{
						q.add(C);
					}
				}else{
					if(revFlg==-1){
						q.add(C);
					}else{
						q.addFirst(C);
					}
				}
			}
			//System.out.println(i);
		}
		StringBuffer b = new StringBuffer(q.size()) ;
		if(revFlg==-1){
			while(!q.isEmpty()){
				b.append(q.poll());
			}
		}else{
			while(!q.isEmpty()){
				b.append(q.pollLast());
			}
		}


		System.out.println(b.toString());
	}



	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 74632
a,b=map(int,input().split())
if a <0 and b > 0:
    print('Zero')
    exit()
elif a>0 and b > 0:
    print('Positive')
    exit()
else:
    n = b-a+1
    if n%2 == 0:
        print('Positive')
    else:
        print('Negative')

Measured memory_bytes: 9124
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main()
{
    int a,b,k;
    while(cin>>a>>b>>k)
    {
        if(b-a+1<=2*k)
        {
            for(int i=a;i<=b;i++)
                cout<<i<<endl;
        }
        else
        {

            for(int i=0;i<k;i++)
                cout<<a+i<<endl;
            for(int i=b-k+1;i<=b;i++)
                cout<<i<<endl;
        }
    }
    return 0;
}


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

ll solve() {
    ll N, M;
    int a, b;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for ( int i = 0; i < M; i++ ) {
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> cs(N,-1);
    function<bool(int,int,int)> dfs = [&](int v, int p, int c) {
        if ( cs[v] != -1 ) {
            if ( cs[v] != c ) return false;
            else  return true;
        }
        cs[v] = c;
        for ( int u : G[v] ) {
            if ( u == p ) continue;
            if ( !dfs(u, v, 1-c) ) return false;
        }
        return true;
    };
    bool bi = dfs(0,-1,0);
    ll n1 = 0, n2 = 0;
    if ( bi ) {
        for ( int i = 0; i < N; i++ ) {
            if ( cs[i] == 0 ) n1++;
        }
    }
    n2 = N - n1;
    ll en;
    if ( bi ) en = n1 * n2;
    else en = n1 * (n1-1) / 2 + n2 * (n2-1) / 2;
    ll ans = en - M;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 6784
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        while ( true ) {
            int n = Integer.parseInt(br.readLine());

            if ( n < 3 || 1000 < n ) {
                break;
            }

            int sum = 0;
            int max = 0;
            int min = 1000;

            for ( int i = 0; i < n; i++) {
                int point = Integer.parseInt(br.readLine());

                if( max < point ) {
                    max = point;
                }
                if( point < min ) {
                    min = point;
                }
                sum += point;
            }

            sum -= max;
            sum -= min;

            int ave = sum / (n-2);

            System.out.println(ave);
        }
    }
}



Measured memory_bytes: 24404
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define vll vector<long long>
#define ll long long
#define pii pair<int,int>
const int mod=1e9+7;
int n,W;
ll solve(int i,int j,vector<vector<ll>> &dp,int* w,ll *v){
    if(dp[i][j]!=-1) return dp[i][j];
    if(j==0) return dp[i][j]=0;
    if(i>n-1) return 0;
    if(i==n-1){
        if(w[i]<=j) dp[i][j]=v[i];
        else dp[i][j]=0;
        return dp[i][j];
    }
    if(w[i]<=j){
        ll l=solve(i+1,j,dp,w,v);
        ll h=v[i]+solve(i+1,j-w[i],dp,w,v);
        dp[i][j]=h>l?h:l;
        //cout<<i<<" "<<j<<" "<<l<<" "<<v[i]<<" "<<h<<" "<<dp[i][j]<<"\n";
    }
    else
        dp[i][j]=solve(i+1,j,dp,w,v);
    //cout<<i<<" "<<j<<" "<<dp[i][j]<<"\n";
    return dp[i][j];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("inputf.txt","r",stdin);
    freopen("outputf.txt","w",stdout);
#endif

    cin>>n>>W;
    int w[n];
    ll v[n];
    for(int i=0;i<n;i++){
        cin>>w[i]>>v[i];
        //cout<<w[i]<<" "<<v[i]<<"\n";
    }
    vector<vector<ll>> dp(n,vector<ll>(W+1,-1));

    cout<<solve(0,W,dp,w,v);
    
    return 0;
}

Measured memory_bytes: 82288
# -*- coding: utf-8 -*-
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      a = l[i]
      b = l[j]
      c = l[k]      
      
      if a == b or b == c or c == a:
        continue
        
      if a + b > c:
        ans += 1

print(ans)

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

using std::cin;
using std::cout;
using std::endl;


void TorT()
{
  int n, a, b;

  cin >> n >> a >> b;
  if (n * a > b) cout << b << endl;
  else           cout << n * a << endl;
}


void cross9_9()
{
  int a, b;

  cin >> a >> b;
  if (a > 0 && a < 10 && b > 0 && b < 10) cout << a * b << endl;
  else cout << -1 << endl;
}


void calculate_circle()
{
  int r;

  cin >> r;
  cout << r * r << endl;
}


void SvsM()
{
  int hp, a;
  int atk_cnt, rest;

  cin >> hp >> a;
  atk_cnt = hp / a;
  if (hp % a) atk_cnt++;
  cout << atk_cnt << endl;
}


void Poor3()
{
  int a, b, c;

  cin >> a >> b >> c;
  if (a == b && b != c) cout << "Yes" << endl;
  else if (b == c && c != a) cout << "Yes" << endl;
  else if (c == a && a != b) cout << "Yes" << endl;
  else cout << "No" << endl;
}


void Algae()
{
  int r, d, x;
  
  cin >> r >> d >> x;
  for (int i = 0; i < 10; i++)
  {
    x = r * x - d;
    cout << x << endl;
  }
}


void cross81()
{
  int n;
  int flag = 0;

  cin >> n;
  for (int i = 1; i < 10; i++)
  {
    for (int j = 1; j < 10; j++)
    {
      if (n == i * j)
      {
        flag = 1;
        cout << "Yes" << endl;
        break;
      }
    }
    if (flag) break;
  }
  if(!flag) cout << "No" << endl;
}


void bite_eating()
{
  int n, l;
  std::vector<int> taste;
  int sum = 0;
  int diff = 100;

  cin >> n >> l;
  for (int i = 0; i < n; i++)
  {
    //taste[i] = l + i;
    taste.push_back(l + i);
    sum += taste[i];
  }
  for (int i = 0; i < n; i++)
  {
    if(std::abs(taste[i]) < std::abs(diff)) diff = taste[i];
  }
  cout << sum - diff << endl;
}


int main()
{
  //TorT();
  //cross9_9();
  //calculate_circle();
  //SvsM();
  //Poor3();
  //Algae();
  //cross81();
  bite_eating();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* nichijou */
template<class T,class U>
bool cmax(T & a, const U & b) {return a < b ? a = b, 1 : 0;}
template<class T,class U>
bool cmin(T & a, const U & b) {return b < a ? a = b, 1 : 0;}
/* data type */
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define F first
#define S second
/* STL container */
typedef vector<int> vi;
typedef vector<ll> vll;
#define SZ(a) ((int)(a).size())
#define ALL(a) begin(a), end(a)
#define CLR(a) (a).clear()
#define BK(a) ((a).back())
#define FT(a) ((a).front())
#define DB(a) (a).pop_back()
#define DF(a) (a).pop_front()
#define PB push_back
#define EB emplace_back
/* I gave you my heart and then you turned around. */
void _BG(const char * s) {cerr<<s<<endl;}
template<class T, class ... TT>
void _BG(const char * s,T a, TT...b)
{
    for (size_t c = 0; *s && (c || *s != ','); cerr << *s++)
        c += count(ALL("([{"),*s) - count(ALL(")]}"),*s);
    cerr << " = " << a;
    if (*s) {
        cerr << ", ";
        ++s;
    }
    _BG(s,b...);
}
#ifdef PR3PONY
#define BG(...) do { \
    cerr << __PRETTY_FUNCTION__ << ':' << __LINE__ << ": "; \
    _BG(#__VA_ARGS__,__VA_ARGS__); \
} while(0)
#else
#define BG(...)
#endif
/* Good Luck && Have Fun ! */
const int N = 11, M = 1024;
char s[M];
int g[N][M];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> s;
        for (int j = 0; j < m; ++j)
            g[i][j] = s[j] - '0' + g[i - 1][j];
    }
    int ans = INT_MAX;
    for (int c = 0; c < (1 << (n - 1)); ++c) {
        vector<int> sep = {0};
        for (int j = 0; j < n - 1; ++j)
            if (c >> j & 1)
                sep.push_back(j + 1);
        sep.push_back(n);
        vector<int> w(sep.size());
        int cur = sep.size() - 2;
        //BG(cur); for (int i : sep) BG(i);
        bool fail = 0;
        for (int j = 0; j < m && !fail; ++j) {
            bool add = 0;
            for (int i = 1; i < sep.size(); ++i) {
                int x = g[sep[i]][j] - g[sep[i - 1]][j];
                if (x > k) {
                    fail = true;
                    break;
                }
                w[i] += x;
                if (w[i] > k) {
                    add = true;
                }
            }
            //BG(j, add);
            if (add) {
                cur++;
                for (int i = 1; i < sep.size(); ++i) {
                    int x = g[sep[i]][j] - g[sep[i - 1]][j];
                    w[i] = x;
                }
            }
        }
        if (!fail)
            ans = min(ans, cur);
        //BG(fail, ans, cur);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from queue import *
from sys import stdin
input = stdin.readline

n, q = map(int, input().split())
link = [[]for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    link[a-1].append(b-1)
    link[b-1].append(a-1)

weight = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    weight[p-1] += x

unused = [1]*n
que = Queue()
que.put(0)
while que.qsize():
    m = que.get()
    unused[m] = 0
    for v in link[m]:
        if unused[v]:
            weight[v] += weight[m]
            que.put(v)
print(*weight)

Measured memory_bytes: 98320
def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod

N, M, K = map(int, input().split())

ans = 0

for i in range(1, M):
    ans += (i * (M-i) * N**2) % (10**9 + 7) 
for i in range(1, N):
    ans += (i * (N-i) * M**2) % (10**9 + 7)

ans *= comb(N*M-2 , K-2, 10**9+7)

print(int(ans % (10**9+7)))



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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<ll, ll> mpii;
typedef unordered_map<ll, ll> umpii;

#define pb(v) push_back(v)
#define all(v) v.begin(), v.end()
#define upb(v, key) (upper_bound(all(v), key) - v.begin())
#define lob(v, key) (lower_bound(all(v), key) - v.begin())

ll inf = 1e9;
ll INF = inf * 1ll * inf;
ll mod = 1e9 + 7;
double eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
ll dr[] = {-1, 0, 0, 1};
ll dc[] = {0, 1, -1, 0};

template <class TH>
void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; }
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a)
{
  while (*sdbg != ',')
    cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V)
{
  os << "[";
  for (auto vv : V)
    os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P)
{
  return os << "(" << P.st << "," << P.nd << ")";
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

/*...................................................*/

main()
{
  int n, i, k;
  cin >> n >> k;
  vector<int> a(n);
  for(i = 0; i < n; i++)
  cin >> a[i];
  vector<int> dp(n, inf * 2);
  dp[0] = 0;
  for(i = 1; i < n; i++)
  for(int j = 1; j <= k && i >= j; j++)
  dp[i] = min(dp[i - j] + abs(a[i] - a[i - j]), dp[i]);
  cout << dp[n - 1];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(void){
    int n, m;
    cin >> n >> m;
    
    vector <int> ma(51);
    vector <int> mb(51);
    for(int i=0; i<m; i++) cin >> ma[i] >> mb[i];
    
    //cout << ma[0] << " " << mb[0] << endl;

    vector <int> cnta(51);
    vector <int> cntb(51);
    for (int i=0; i<m; i++) {
        cnta[ma[i]]++; //cout << ma[i] << " ";
        cntb[mb[i]]++; //cout << mb[i] << endl;
    }
    //int ans = 0;
    
    
    for (int i=1; i<=n; i++) {
        int ans = cnta[i] + cntb[i];
        //cout << cnta[i] << " " << cntb[i] << endl;
        cout << ans << endl;
    }
    //cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256