akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, a, b = LI()
    if a & 1 == b & 1:
        print((b - a) // 2)
    else:
        print(min((b - a + 1) // 2 + a - 1, ((n - a) - (n - b) + 1) // 2 + n - b))
    return


#main
if __name__ == '__main__':
    solve()


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

int main(){
  int card[15];
  int tmp;
  char komma;
  int i, j;
  int flag, flag2, flag3;

  while(cin>>tmp){
    for(i=0; i<15; i++) card[i]=0;
    card[tmp]++;
    for(i=0; i<4; i++){
      cin>>komma>>tmp;
      card[tmp]++;
    }

    flag=0;
    for(i=0; i<15; i++)
      if(card[i]==4) flag=1;
    if(flag){
      printf("four card\n"); continue;
    }
    flag2=0; flag3=0;
    for(i=0; i<15; i++){
      if(card[i]==3) flag=1;
      else if(flag2 && card[i]==2) flag3=1;
      else if(card[i]==2) flag2=1;
    }
    if(flag && flag2){
      printf("full house\n"); continue;
    } else if(flag){
      printf("three card\n"); continue;
    } else if(flag3){
      printf("two pair\n"); continue;
    } else if(flag2){
      printf("one pair\n"); continue;
    }
    if(card[1]=1) card[14]=1;
    for(i=10; i>0; i--){
      tmp=1;
      for(j=0; j<5; j++){
        tmp*=card[i+j];
      }
      if(tmp==1){
        printf("straight\n"); break;
      }
    }
    if(tmp==1) continue;
    printf("null\n");
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = 1LL<<55;
const Int mod = (1e9)+7;
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  set<int> S;
  
  int q;
  cin>>q;
  while(q--){
    int cmd, num;
    cin>>cmd>>num;
    if(cmd == 0){
      S.insert(num);
      cout<<S.size()<<endl;
    }

    if(cmd == 1){
      cout<<S.count(num)<<endl;
    }
    
    if(cmd == 2){
      S.erase(num);
    }

    if(cmd == 3){
      int l = num, r;
      cin>>r;
      auto start = S.lower_bound(l);
      //auto last= S.upper_bound(r);
      for(auto it = start; it != S.end() && *it <= r; it++) cout<<*it<<endl;
    }
  }
  return 0;
}



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

using namespace std;

int main()
{
    int N, M;
    vector<int> A, B;
    cin >> N;
    for(int i = 0; i < N; ++i)
    {
        int Num; cin >> Num;
        A.push_back(Num);
    }
    
    cin >> M;
    for(int i = 0; i < M; ++i)
    {
        int Num; cin >> Num;
        B.push_back(Num);
    }
    
    cout << (A < B) << endl;
    
    return 0;
}


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

using namespace std;

int main() {
	long long int n, d;

	cin >> n >> d;

	int ans = 0;
	for (int i = 0; i < n; i++) {
		long long int x, y;
		cin >> x >> y;

		if (x*x + y*y <= d*d)
			ans++;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3632
using System;
using System.Linq;

class p{
  static void Main(){
    int n = int.Parse(Console.ReadLine());
    string s = Console.ReadLine();
    int tmp = 0, ans = 0;
    for(int k = 0; k < n; k++){
      if(s[k] == 'I') tmp++;
      if(s[k] == 'D') tmp--;
      if(tmp > ans) ans = tmp;
    }
    Console.WriteLine(ans);
   }
}

Measured memory_bytes: 13140
import math

a,b,n,m = map(int,input().split())

if n > 12.0:
    n -= 12.0


n_angle = n * 30.0 + m * 0.5
m_angle = m * 6.0
angle = 0.0

if n_angle < m_angle:
    if (m_angle - n_angle) < 360.0 - (m_angle - n_angle):
        angle = m_angle - n_angle
    else:
        angle = 360.0 - (m_angle - n_angle)
else:
    if (n_angle - m_angle) < 360.0 - (n_angle - m_angle):
        angle = n_angle - m_angle
    else:
        angle = 360.0 - (n_angle - m_angle)
    
ans = a*a + b*b - 2.0*a*b*(math.cos(math.radians(angle)))
print(math.sqrt(ans))



Measured memory_bytes: 9584
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>
#include <cmath>
#include <map>
#include <tuple>
#include <complex>

#define MOD 1000000007

using namespace std;

typedef long long ll;

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<string> vs;

typedef pair<ll, ll> pll;
typedef pair<int, int> pi;

typedef vector<pll> vpl;
typedef vector<pi> vpi;
typedef vector<vs> vvs;

typedef vector<pll> vvpl;
typedef vector<vpi> vvpi;

typedef queue<ll> ql;
typedef queue<int> qi;
typedef queue<pll> qpl;
typedef queue<pi> qpi;

template <typename T>
void printv(const vector<T>& v) {
    for (const auto& e : v) cout << e << " ";
    cout << endl;
}

template <typename T>
void printvv(const vector<T>& vv) {
    for (const auto& v : vv) {
        for (const auto& e : v) cout << e << " ";
        cout << endl;
    }
}

template <typename T, typename U>
void printp(const pair<T, U>& p) {
    cout << p.first << " " << p.second << endl;
}

template <typename T>
void printvp(const vector<pair<T, T>>& vp) {
    for (const auto& p : vp) cout << p.first << " " << p.second << endl;
}

template <typename T>
void printvvp(const vector<vector<pair<T, T>>>& vvp) {
    for (int i = 0; i < vvp.size(); ++i) {
        for (int j = 0; j < vvp[i].size(); ++j) {
            printf("[%d][%d] %d, %d\n", i, j, vvp[i][j].first, vvp[i][j].second);
        }
    }
}

const int COLORLESS = -1;

void dfs(const vvpi& graph, vi& colors, const int node_index, const int color) {
    // cout << "node_index: " << node_index << ", color: " << color << endl;
    if (colors[node_index] != COLORLESS) return;
    colors[node_index] = color;

    for (const auto node : graph[node_index]) {
        if (node.first == node_index) continue;
        if (node.second) dfs(graph, colors, node.first, 1 - color);
        else             dfs(graph, colors, node.first, color);
    }
}

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

    vvpi graph(N);
    for (int i = 0; i < (N-1); ++i) {
        int u, v, w; cin >> u >> v >> w;
        graph[u-1].push_back(make_pair(v-1, w & 1));
        graph[v-1].push_back(make_pair(u-1, w & 1));
    }

    vi colors(N);
    for (int i = 0; i < N; ++i) colors[i] = COLORLESS;

    // printvvp(graph);

    dfs(graph, colors, 0, 0);
    for (const auto& c : colors) cout << c << endl;

    return 0;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int a, b; cin >> a >> b;
	cout << a / b << " " << a % b << " " << (double)a / (double)b << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}



Measured memory_bytes: 3272
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m = readInts()
print((n-1) * (m-1))


Measured memory_bytes: 10220
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int r;
    cin >> r;
    if (r < 1200) cout << "ABC" << endl;
    else if (r < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;


    return 0;
}

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

  #define vi vector<int>
  #define all(v) v.begin(),v.end()
  #define ll long long int
  #define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
  #define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}

  const ll MOD=1e9+7;

  void solve(){
     int x,n;
     cin >> x >> n;
     map<int,int> mp;
     int ans=INT_MAX;
     int o = x;
     for(int i=0;i<n;i++){
        int a;cin >> a;
        mp[a]++;
     }
     for(int i=-100;i<=200;i++){
        if(abs(i-x)<ans && !mp[i])o=i,ans=abs(i-x);
     }
     cout << o;
  }


  int main(){
    IOS
       solve();
       cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 3856
N,M = map(int,input().split())
R = [set([]) for _ in range(N)]
for i in range(M):
  a,b = map(int,input().split())
  a-=1;b-=1
  R[a].add(b)
  R[b].add(a)
#print(R)
for i in range(1,N-1):
  if 0 in R[i] and N-1 in R[i]:
    print("POSSIBLE")
    exit()
print("IMPOSSIBLE")

Measured memory_bytes: 73608
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#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 ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    ll d = abs(a - b);
    bool ok = true;
    if (w >= v) ok = false;
    else {
        ok = (d <= t * (v - w));
    }
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 3632
x,y = map(int,input().split())

count = 0
for cnt_tsuru in range(x+1):
    cnt_kame = x - cnt_tsuru
    if y == 2 * cnt_tsuru + 4 * cnt_kame:
        count += 1
if count != 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9112
N, K = map(int, input().split())
V = list(map(int, input().split()))

max_value = 0
for l in range(K + 1):
	for r in range(K + 1):
		if K < l + r or N < l + r:
			break
		hand = sorted(V[:l] + V[N - r:])
		for d in range(min(len(hand), K - l - r)):
			hand[d] = max(0, hand[d])
		max_value = max(max_value, sum(hand))
		#print(max_value, l, r, hand)
print(max_value)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>
#include <cmath>

#define MOD 1000000007

using namespace std;

typedef long long ll;

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;

typedef pair<ll, ll> pll;
typedef pair<int, int> pi;

typedef vector<pll> vpl;
typedef vector<pi> vpi;

typedef queue<ll> ql;
typedef queue<int> qi;

template <class T>
void printv(vector<T> vc)
{
    for (auto e : vc)
        cout << e << " ";
    cout << endl;
}

template <class T>
void printvv(vector<T> vvc)
{
    for (auto vc : vvc)
    {
        for (auto e : vc)
            cout << e << " ";
        cout << endl;
    }
}

template <class T>
void printvp(vector<pair<T, T>> vp)
{
    for (auto pT : vp)
        cout << pT.first << " " << pT.second << endl;
}

int main() {
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    for (int i = 0; i <= a; ++i) {
        for (int j = 0; j <= b; ++j) {
            for (int k = 0; k <= c; ++k) {
                if (i*500 + j*100 + k*50 == x) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    vector<char> m(s.size());
    for(int i=0; i<s.size(); i++) m.at(i) = s.at(i);
    sort(m.begin(), m.end());
    
    if(m.at(0) == m.at(1) && m.at(2) == m.at(3) && m.at(1) != m.at(2)) puts("Yes");
    else puts("No");
}

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

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

}

Measured memory_bytes: 256
<?php
error_reporting(0);
//Request Question
function getq($get_word=null){
	if($get_word===null){
		return str_replace("\n","",fgets(STDIN));
	}else if($get_word===1){
		return explode(" ",str_replace("\n","",fgets(STDIN)));
	}
}

/*		START		*/
$word=array();
$blue_card=getq();
$bule_list=array();
//取得
for ($i=0; $i < $blue_card; $i++) { 
	$bule_list[$i] = getq();
	if(!array_search($bule_list[$i],$word)){
		array_push($word,$bule_list[$i]);
	}
}
$red_card=getq();
$red_list=array();
for ($i=0; $i < $red_card; $i++) { 
	$red_list[$i] = getq();
	if(!array_search($red_list[$i],$word)){
		array_push($word,$red_list[$i]);
	}
}
$cost=array();

for ($i=0; $i < count($word); $i++) { 
	$b=array_count_values($bule_list);
	$bc=$b[$word[$i]];
	$r=array_count_values($red_list);
	$rc=$r[$word[$i]];
	$cost[$i]=$bc-$rc;
}
array_push($cost, 0);

echo max($cost)."\n";
?>

Measured memory_bytes: 4856
#include<iostream>
main(){
int n,i,A,B,C,f;
for(std::cin>>n;n-->0;puts(f?"NO":"YES"))
 for(B=C=f=i=0;i<10;i++){
  std::cin>>A;
  if(B<A)B=A;
  else if(C<A) C=A;
  else f=1;
 }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli i,a[2],b[2],turn=1;
    cin>>a[0]>>a[1]>>b[0]>>b[1];
    
    swap(b[1],a[0]);
    swap(b[0],a[1]);
    while(1)
    {
        if(turn==1)
        {
            turn=2;
            a[1]-=b[0];
            if(a[1]<=0)
            {
                cout<<"Yes";
                return 0;
            }
        }
        else
        {
            turn=1;
            b[1]-=a[0];
            if(b[1]<=0)
            {
                cout<<"No";
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3636
n = input()
a = [ raw_input().split() for _ in range(n)]
taro = 0
hanako = 0
for i in a:
    b = sorted(i)
    if i != b :
        taro += 3
    elif i[0] != i[1] :
        hanako += 3
    else :
        taro += 1
        hanako += 1
print taro,hanako

Measured memory_bytes: 6448
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }


struct UnionFind{
    vector<int> par;
    vector<int> sizes;
    UnionFind(int n):par(n),sizes(n,1){ rep(i,n)par[i]=i; }

    //find root of x
    int find(int x){
        if(x!=par[x]) par[x] = find(par[x]);
        return par[x];
    }

    void unite(int x,int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(int x,int y){ return find(x) == find(y); }
    int size(int x){ return sizes[find(x)]; }
};

int main(void){
    int n,m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i,m){
        int x,y,z;
        cin >> x >> y >> z;
        x--,y--;
        uf.unite(x,y);
    }
    set<int> roots;
    rep(i,n){
        roots.insert(uf.find(i));
    }
    cout << roots.size() << endl;
    return 0;
}


Measured memory_bytes: 5760
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
flag1 = 1
flag2 = 0
w = 0
h = 0
for i in range(n-1):
    flag2 = 1
    if a[i] == a[i+1] and flag1:
        w = a[i]
        a.pop(i+1)
        flag1 = 0
        flag2 = 0
    if a[i] == a[i+1] and flag2:
        h = a[i]
        break
if w == 0 or h == 0:
    ans = 0
else:
    ans = int(h*w)
print(ans)

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

const int N = 1e5 + 5;

int fa[N], val[N];

inline int getf(int x) {
  if (x == fa[x]) return x;
  else {
    getf(fa[x]);
    val[x] += val[fa[x]];
    fa[x] = fa[fa[x]];
    return fa[x];
  }
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i ++) fa[i] = i;
  for (int a, b, l, r, d; m; m --) {
    scanf("%d%d%d", &l, &r, &d);
    a = getf(l); b = getf(r);
    if (a == b) {
      if (val[r] - val[l] != d) return puts("No"), 0;
    }
    else {
      d += val[l] - val[r];
      fa[b] = a;
      val[b] += d;
    }
  }
  puts("Yes");
  return 0;
}


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

const int N=1e5+5;

typedef long long ll;
ll a[N],b[N];
int main()
{
int n;
cin>>n;
for(int i=0;i<n+1;i++)
    cin>>a[i];
for(int i=0;i<n;i++)
    cin>>b[i];
    ll lol=0;
    for(int i=0;i<n;i++){
        if(a[i]>b[i]){
            a[i]-=b[i];
            lol+=b[i];
            b[i]=0;
        }else{
        lol+=a[i];


        b[i]-=a[i];
         a[i]=0;
        }
        if(a[i+1]>b[i]){
            a[i+1]-=b[i];
            lol+=b[i];
            b[i]=0;
        }else{
            lol+=a[i+1];


        b[i]-=a[i+1];
          a[i+1]=0;
        }


    }
    cout<<lol;
   return 0;
}


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

using namespace std;

int main(){

  int T_1,T_2;
  int R_1,R_2;

  cin >> T_1;
  cin >> T_2;
  cin >> R_1;
  cin >> R_2;

  if(R_1 != -1 && R_2 != -1){
    if(R_1 > R_2)
      cout << "Alice" << endl;
    else if(R_1 < R_2)
      cout << "Bob" << endl;
    else if(R_1 == R_2)
      cout << "Draw" << endl;
  }
  else{
    if(T_1 < T_2)
      cout << "Alice" << endl;
    else if(T_1 > T_2)
      cout << "Bob" << endl;
    else if(T_1 == T_2)
      cout << "Draw" << endl;
  }
    
}



Measured memory_bytes: 3092
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
const long long INF = 1LL << 60;
typedef vector<ll> Array;

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

ll dp[1000011][2];
string n;
ll find(ll d, ll flag) {
	if (d == -1&&flag==0) return 0;
	if (d == -1 && flag == 1)return 1;
	if (dp[d][flag] != -1)return dp[d][flag];
	ll ret = INF;
	ll num = n[n.size() - d - 1] - '0';
	if (flag == 0) {
		chmin(ret, find(d - 1, 0) + num);
		chmin(ret, find(d - 1, 1) + 1 + num);
	}
	else {
		chmin(ret, find(d - 1, 1) + 10-num-1);
		chmin(ret, find(d - 1, 0) + 10 - num);
	}
	return dp[d][flag] = ret;
}

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

	cin >> n;
	n.insert(n.begin(), '0');
	REP(i, n.size() + 1)REP(j, 2)dp[i][j] = -1;

	cout << find(n.size() - 1, 0) << endl;

	return 0;
}

Measured memory_bytes: 63900
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
ctr = Counter(A)
lctr = sorted(list(ctr.items()),reverse=True)

ans = 0
for k,_ in lctr:
    beki = 2**(len(bin(k))-2)
    a = beki-k
    if a == k:
        ans += ctr[k]//2
    else:
        tmp = min(ctr[k], ctr[a])
        ans += tmp
        ctr[a] -= tmp
print(ans)

Measured memory_bytes: 70436
#include <iostream>
#include <functional>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main() {
	int n, c, x;
	int d[500][500];
	int t[3][30];
	cin >> n >> c;
	for (int i = 0; i < c; i++)for (int j = 0; j < c; j++)cin >> d[i][j];
	for (int i = 0; i < n; i++)for (int j = 0; j < n; j++) {
		cin >> x;
		t[(i + j) % 3][x-1]++;
	}
	long long ret = 1<<30;
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < c; j++) {
			if (i != j) {
				for (int k = 0; k < c; k++) {
					if (i != k && j != k) {
						int tt = 0;
						for (int l = 0; l < c; l++)tt += d[l][i] * t[0][l];
						for (int l = 0; l < c; l++)tt += d[l][j] * t[1][l];
						for (int l = 0; l < c; l++)tt += d[l][k] * t[2][l];
						if (ret > tt)ret = tt;
					}
				}
			}
		}
	}
	cout << ret << endl;
	return 0;
}

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

int main()
{
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<vector<int> > Dist(N, vector<int>(N, 0));
  vector<int> ans(N, 0);
  for (int i = 0; i < N-1; i++)
  {
    for (int j = i+1; j < N; j++)
    {
      int direct = j - i;
      int toX = abs(X-1-i);
      int fromY = abs(Y-1-j);
      int indirect = toX+fromY+1;
      Dist.at(i).at(j) = min(direct, indirect);
      ans.at(Dist.at(i).at(j))++;
    }
  }
  for (int i = 1; i < N; i++)
  {
    cout << ans.at(i) << endl;
  }
}


Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;



int main(){
	ll N;
	cin >> N;
	vector<ll> B(N,0);
	for(ll i=0;i<N-1;i++){
		cin>>B[i+1]
	;}
	ll sum=B[1]+B[N-1];
	for(ll i=1;i<N-1;i++){
		sum+=min(B[i],B[i+1])
	;}
	cout<<sum<<endl;
return 0;
}  



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

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s=="SSS"){
        cout<<0;
    }else if(s=="RSS" || s=="SRS" || s=="SSR" || s=="RSR"){
        cout<<1;
    }else if(s=="RRS" || s=="SRR"){
        cout<<2;
    }else {
        cout<<3;
    }
}


Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.IO;

namespace AtCoderPractice
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var N = cin.ReadInt;
            var X = cin.ReadInt;
            var D = 0;
            var L = cin.ReadIntArray(N);

            // 2回目の以降の処理
            for (int i = 0; i < N; i++)
            {
                D = D + L[i];

                if (D <= X)
                {
                    if (i == N - 1)
                    {
                        Console.WriteLine(i + 2);
                        break;
                    }

                    continue;
                }
                else
                {
                    Console.WriteLine(i + 1);
                    break;
                }
            }
        }
    }

    public class ConsoleInput
    {
        private readonly TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;

        public ConsoleInput(TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }

        public string ReadLine
        {
            get { return _stream.ReadLine(); }
        }

        public int ReadInt
        {
            get { return int.Parse(Read); }
        }

        public long ReadLong
        {
            get { return long.Parse(Read); }
        }

        public double ReadDouble
        {
            get { return double.Parse(Read); }
        }

        public string[] ReadStrArray(long N)
        {
            var ret = new string[N];
            for (long i = 0; i < N; ++i) ret[i] = Read;
            return ret;
        }

        public int[] ReadIntArray(long N)
        {
            var ret = new int[N];
            for (long i = 0; i < N; ++i) ret[i] = ReadInt;
            return ret;
        }

        public long[] ReadLongArray(long N)
        {
            var ret = new long[N];
            for (long i = 0; i < N; ++i) ret[i] = ReadLong;
            return ret;
        }
    }
}

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

int main(){
    int m, d;
    scanf("%d%d", &m, &d);
    int cnt = 0;
    for (int i = 1; i <= m; ++ i){
        for (int j = 1; j <= d; ++ j){
            int x = j % 10, y = j / 10;
            if (x >= 2 && y >= 2 && x * y == i){
                ++ cnt;
            }
        }
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 100000

typedef long long ll;
typedef pair<int,int> P;

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

struct edge{
    int to,cost;
    edge(int t,int c){
        to = t;
        cost = c;
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<edge>> e(N+1);
    int ans[N+1];
    int d[N+1];
    for(int i = 0; i < N+1; i++) d[i] = INF_INT;
    for(int i = 0; i < M; i++){
        int a,b;
        cin >> a >> b;
        e[a].emplace_back(edge(b,1));
        e[b].emplace_back(edge(a,1));
    }
    priority_queue<pair<P,int>,vector<pair<P,int>>,greater<pair<P,int>>> q; 
    q.push(make_pair(make_pair(0,1),1));
    d[1] = 0;
    while(!q.empty()){
        pair<P,int> a = q.top();
        q.pop();
        P p = a.first;
        if(p.first > d[p.second]) continue;
        else ans[p.second] = a.second;
        for(auto e : e[p.second]){
            int to = e.to;
            int cost = e.cost;
            if(d[p.second] + cost < d[to]){
                q.push(make_pair(make_pair(d[p.second] + cost,to),p.second));
                d[to] = d[p.second] + cost;
            }
        }
    }
    cout << "Yes" << endl;
    for(int i = 2; i <= N; i++){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 14072
#include <cstdio>
#include <algorithm>
#define N 302 
using namespace std;

int n , m , a[N][N] , p[N] , ans = 123456789;
int vis[N];
bool ban[N];

int main()
{
	scanf("%d %d" , &n , &m);
	for(int i = 1 ; i <= n ; i ++)
	{
		p[i] = 1;
		for(int j = 1 ; j <= m ; j ++)
			scanf("%d" , &a[i][j]);
		vis[ a[i][p[i]] ]++;
	}
	for(int i = 1 ; i <= m ; i ++)
	{
		for(int j = 1 ; j <= n ; j ++)
			while(ban[ a[j][p[j]] ] ) 
				vis[ a[j][p[j]] ]-- , vis[ a[j][++p[j]] ]++;

		int s = 1;
		for(int j = 1 ; j <= m ; j ++)
			if(vis[j] > vis[s]) s = j;
		ans = min(ans , vis[s]);
		ban[s] = 1;
	}
	printf("%d\n" , ans);
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
const int mod=1e9+7;

int main(){
	int d, n;
	cin >> d >> n;
	if(n<100)
		cout << (int)pow(100,d)*n << endl;
	else
		cout << (int)pow(100,d)*(n+1) << endl;
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
h = [int(i) for i in input().split()]

dp = [float('inf')] * N
dp[0] = 0
for i in range(N) :
    for j in range(i + 1, min(i + 1 + K, N)) :
        dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))
        
print(dp[-1])

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

using namespace std;

int main(){
    // card array
    string partition_ = "####################\n";
    int N_b = 4, N_floor = 3,N_room = 10;

    int n_info;
    cin >> n_info;

    vector<vector<vector<int>>> info_array(N_b,vector<vector<int>>(N_floor,vector<int>(N_room,0)));

    int b,f,r,v;
    for(int i = 0; i < n_info;i++){
        cin >> b >> f >> r >> v ;
        info_array[b-1][f-1][r-1] += v;
    }
    for (int bb = 0;bb < N_b;bb ++){
        for(int floor =0;floor < N_floor;floor ++){
            for(int room = 0;room < N_room;room ++){
                cout << " " << info_array[bb][floor][room];
            }
            cout << "\n";
        }
        if(bb < 3) cout << partition_;
    }


    return 0;   
}


Measured memory_bytes: 3168
import java.util.*;
import java.math.BigDecimal;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long h = sc.nextLong();
        long w = sc.nextLong();
        long ans;
        if(h == 1 || w == 1){
          System.out.println(1);
          return;
        }
        if(h % 2 == 1 && w % 2 == 1){
          ans = h * w / 2 + 1;
        }else{
          ans = h * w / 2;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35680
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define REP(i, a) for (int i(0), _##i(a); i < _##i; ++i)
#define FOR(i, a, b) for (int i(a), _##i(b); i <= _##i; ++i)

#ifdef LOCAL
#define _NTH_ARG(_1, _2, _3, _4, _5, _6, N, ...) N
#define _FE_1(_CALL, x) _CALL(x)
#define _FE_2(_CALL, x, ...) _CALL(x) _FE_1(_CALL, __VA_ARGS__)
#define _FE_3(_CALL, x, ...) _CALL(x) _FE_2(_CALL, __VA_ARGS__)
#define _FE_4(_CALL, x, ...) _CALL(x) _FE_3(_CALL, __VA_ARGS__)
#define _FE_5(_CALL, x, ...) _CALL(x) _FE_4(_CALL, __VA_ARGS__)
#define _FE_6(_CALL, x, ...) _CALL(x) _FE_5(_CALL, __VA_ARGS__)
#define FOR_EACH_MACRO(MACRO, ...)                                             \
  _NTH_ARG(__VA_ARGS__, _FE_6, _FE_5, _FE_4, _FE_3, _FE_2, _FE_1)              \
  (MACRO, __VA_ARGS__)
#define watch(x) cerr << "\033[1;32m" #x " = \033[1;34m" << (x) << "\033[0m; ";
#define debug(...)                                                             \
  cerr << "\033[2;31mLine " << __LINE__ << ": \033[0m";                        \
  FOR_EACH_MACRO(watch, __VA_ARGS__)                                           \
  cerr << endl
#else
#define debug(...)
#endif

using namespace std;

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

template <class T, class = decltype(begin(declval<T>())),
          class = enable_if_t<!is_same<T, string>::value>>
ostream &operator<<(ostream &os, const T &c) {
  os << '[';
  for (auto it = begin(c); it != end(c); ++it)
    os << (it == begin(c) ? "" : ", ") << *it;
  return os << ']';
}
using ll = long long;

void solve() {
  int n;
  cin >> n;
  vector<vector<int>> adj(n);

  const int MOD = 1e9 + 7;

  REP(i, n - 1) {
    int u, v;
    cin >> u >> v, --u, --v;
    adj[u].EB(v);
    adj[v].EB(u);
  }

  vector<vector<int>> dp(n, vector<int>(2, -1));
  
  function<int(int, int, int)> dfs = [&](int u, int p, int c) -> int {
    int &res = dp[u][c];
    if (res != -1) return res;
    res = 1;
    for (int v : adj[u]) {
      if (v == p)
        continue;
      int c1 = dfs(v, u, 0);
      int c2 = dfs(v, u, 1);
      int cur = 0;
      if (c == 0) {
        cur = (c1 + c2) % MOD;
      } else if (c == 1) {
        cur = c1 % MOD;
      } 
      res = (1ll * res * cur) % MOD;
    }
    return res;
  };

  int ans = (dfs(0, -1, 0) + dfs(0, -1, 1)) % MOD;
  cout << ans << "\n";
}

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

  int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
}


Measured memory_bytes: 20992
#include<stdio.h>
int main()
{
	int a, b, c;
	scanf("%d%d%d",&a,&b,&c);
	if((a==b&&a!=c&&b!=c)||(c==b&&c!=a&&b!=a)||(a==c&&a!=b&&c!=b))
	printf("Yes");
	else
	printf("No");

	return 0;
}


Measured memory_bytes: 128
def main():
    n, k = map(int, input().split())
    d = [0] * k
    a = [0] * k
    ans = [i for i in range(1, n +1)]
    A = set()
    for i in range(k):
        d[i] = int(input())
        A |= set(map(int, input().split()))
    for i in A:
        ans.remove(i)
    print(len(ans))


if __name__ == '__main__':
    main()

Measured memory_bytes: 9200
n, k = map(int, input().split())
h = []
diff = 10**9
for i in range(n):
  h.append(int(input()))
h.sort()
for i in range(n-k+1):
  hmin = h[i]
  hmax = h[i+k-1]
  diff = min(diff, hmax-hmin)
print(diff)

Measured memory_bytes: 7384
# include <bits/stdc++.h>
using namespace std;
#define int long long int
#define prDouble(x) cout<<fixed<<setprecision(10)<<x;
//without fixed flag: 1.23e+09
//with fixed flag: 1230000000.00000
// 5 decimals due to setprecision (5)
double memo[3005][3005];
// memo[i][x]=probability of getting >=x heads in first i coin tosses
double bottom(double pr[], int i, int x)
{
	//base case
	if (x == 0) return 1; //prob(no. of heads=1)=0
	if (i == 0) return 0; //zero elements are there hence prob is 0
	//self work
	double &ans = memo[i][x];
	if (ans > -0.9) return ans;
	return ans = pr[i] * bottom(pr, i - 1, x - 1) + (1 - pr[i]) * bottom(pr, i - 1, x);
}
int32_t main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n;
	cin >> n;
	double pr[n + 1];//1 based indexing used
	memset(memo, -1, sizeof(memo));
	for (int i = 1; i <= n; i++)
	{
		cin >> pr[i];
	}
	prDouble(bottom(pr, n, (n + 1) / 2));
}
// 5
// 0.42 0.01 0.42 0.99 0.42
// 0.3821815872

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

int main() 
{
    long long int n,d;
    cin>>n>>d;
    int cnt=0;
    while(n>0)
    {
        n-=(1+2*d);
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


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

int len=0;
void solve()
{
	stack<char>s;
	char c;
	int x=0;
	while(true)
	{
		c=getchar();
		if(c=='.')
		{
			if(len==0)break;
			if(x==0)cout<<"yes"<<endl;
			else cout<<"no"<<endl;		
			len=0;
			x=0;
			while(!s.empty())
			{
				s.pop();
			}
			continue;	
		}
		if(c=='\n')continue;
		len++;
		
		if(c=='(')
		{
			x++;
			s.push(c);
		}
		else if(c=='[')
		{
			x++;
			s.push(c);
		}
		else if(c==')')
		{
			x++;
			while(!s.empty())
			{
				if(s.top()=='(')
				{
					x-=2;
					s.pop();
					break;
				}
				s.pop();
			}
		}
		else if(c==']')
		{
			x++;
			while(!s.empty())
			{
				if(s.top()=='[')
				{
					x-=2;
					s.pop();
					break;
				}
				s.pop();
			}
		}
		else
		{
			s.push(c);
		}
	}
}

int main()
{
	solve();
	return 0;
}


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


number, length = map(int, input().split())
lst = []
for n in range(number):
    s = input()
    #print(s)
    lst.append(s)
    #print(lst)

lst.sort()
moji = ""
for n in lst:
    moji += n
print(moji)

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

int main() {
	// your code goes here
	int N; cin>>N;
	int p[N+2];
	for(int i=1;i<=N;i++) {
		cin>>p[i];
	}
	
	int cnt = 0, minVal,maxVal;
	for(int i=2;i<N;i++) {
		minVal = min(min(p[i-1], p[i]), p[i+1]);
		maxVal = max(max(p[i-1], p[i]), p[i+1]);
		if(p[i] > minVal and p[i]< maxVal) cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 256
x, n = map(int, input().split())
if n == 0:
    print(x)

else:
    p = list(map(int, input().split()))
    cnt = 0
    if x not in p:
        print(x)
    else:
        while True:
            cnt += 1
            if x - cnt not in p:
                print(x - cnt)
                break
            if x + cnt not in p:
                print(x + cnt)
                break

Measured memory_bytes: 9128
#include<stdio.h>

int bubblesort(int A[], int N){
	int flag = 1;
	int i,count = 0,j,x;
	for(i = 0; flag; i++){
		flag = 0;
		for(j =  N - 1; j >= i + 1; j--){
			if(A[j] < A[j - 1]){
				x = A[j];
				A[j] = A[j - 1];
				A[j - 1] = x;
				flag = 1;
				count++;
			}
		}
	}
	return count;
}

int main(void){
	int A[100];
	int N,count = 0,i,j;
	
	scanf("%d",&N);
	for(i = 0;i < N;i++){
		scanf("%d",&A[i]);
	}
	count = bubblesort(A,N);
	
	for(i = 0; i < N; i++){
		if(i > 0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
	printf("%d\n",count);
	
	return 0;

}

Measured memory_bytes: 604
X = str(input())

Tn = 0
Sn = 0
Nagasa = len(X)

for i in range (0, Nagasa):
	if X[i] == 'T':
		if Sn == 0:
			Tn+=1
		else:
			Sn-=1
	else:
		Sn+=1

print(2*Tn)		

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

int main() {
  int A, B;
  cin >> A >> B;
  int ans;
  
  for(int i=A; i<=B; i++){
    int I, j;
    I = i;
    j = 0;
    int l;
    rep(r, 5){
      l = I%10;
      rep(k, 4-r){
        l *= 10;
      }
      j += l;
      I /= 10;
    }
    if(i==j){
	  ans += 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n,k = map(int,ipt().split())
    v = [int(i) for i in ipt().split()]
    rv = v[::-1]
    ma = 0
    for ai in range(n+1):
        for bi in range(n-ai+1):
            d = k-ai-bi
            if d < 0:
                continue
            vs = v[:ai:]+rv[:bi:]
            vs.sort(reverse=True)
            for i in range(min(ai+bi,d)):
                if vs[-1] >= 0:
                    break
                else:
                    vs.pop()
            nm = sum(vs)
            if ma < nm:
                ma = nm

    print(ma)



    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 75612
// Vicfred
// https://atcoder.jp/contests/abc157/tasks/abc157_a
// implementation
use std::io;

fn main() {
    let mut n = String::new();

    io::stdin()
        .read_line(&mut n)
        .unwrap();

    let n: i64 = n.trim().parse().unwrap();
    
    println!("{}", (n+1)/2);
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll N,K,a,b,ans=0;
  cin>>N>>K;
  for(ll i=K;i<=N+1;i++){
  a=(2*N-i+1)*i/2;
  b=(i-1)*i/2;
  ans+=a-b+1;
  }
  cout<<ans%1000000007<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n'

using namespace std;

long long a, b;

int main(){
    cin >> a >> b;

    if(a < 0 && b > 0){
        cout << "Zero";
    } else if(a < 0 && b < 0){
        if((abs(abs(a) - abs(b)) + 1) % 2 == 0){
            cout << "Positive";
        } else{
            cout << "Negative";  
        }
    } else if(a > 0 && b > 0){
        cout << "Positive";
    }






}

//g++ -std=c++14 comp.cpp -o b; ./b.exe

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        ll A, B, C; cin >> A >> B >> C;
        rep(i, 1000000) {
            if(A % 2 or B % 2 or C % 2) {
                cout << i << endl;
                return 0;
            }
            ll a = A, b = B, c = C;
            A = b / 2 + c / 2;
            B = a / 2 + c / 2;
            C = a / 2 + b / 2;
        }
        cout << -1 << endl;
        return 0;
    }
};

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


Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
way = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    way[a-1].append(b-1)
    way[b-1].append(a-1)
ans = 0
for i in range(n):
    ans += 1
    for j in range(len(way[i])):
        if h[i] <= h[way[i][j]]:
            ans -= 1
            break
print(ans)

Measured memory_bytes: 29480
import           Control.Arrow ((&&&))
import           Data.List

solve :: [Int] -> [Int]
solve xs = let nl  = map (head &&& length) $ group $ sort xs
               nl' = sortBy (\a b -> compare (snd b) (snd a)) nl
               lm  = snd $ head nl'
               nlm = map fst $ takeWhile (\(_, l) -> l == lm) nl'
           in  nlm

main :: IO ()
main = getContents >>= mapM_ print . solve . map read . lines

Measured memory_bytes: 4104
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        h: [usize; n],
        ab: [[usize; 2]; m],
    }

    let mut good_flg = vec![true; n];
    for i in 0..m {
        let a = ab[i][0] - 1;
        let b = ab[i][1] - 1;
        if h[a] <= h[b] {
            good_flg[a] = false;
        }
        if h[b] <= h[a] {
            good_flg[b] = false;
        }
    }
    let mut ans = 0;
    for i in 0..n {
        if good_flg[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


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

cnt=0

for i in range(k):
	if b>a:
		break
	b*=2
	cnt+=1
for i in range(k-cnt):
	c*=2

if a<b<c:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 9176
#!/usr/bin/env python

import bisect

def main():
    N = int(input())
    A = list(map(int, input().split(" ")))
    B = list(map(int, input().split(" ")))
    C = list(map(int, input().split(" ")))

    A.sort()
    B.sort()
    C.sort()

    cnt = 0
    for b in B:
        a_index = bisect.bisect_left(A, b)
        c_index = bisect.bisect_right(C, b)
        cnt += a_index * (N - c_index)
    print(cnt)

if __name__ == '__main__':
    main()





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

int main() {
  vector<vector<int>> b(3, vector<int>(3));
  for(int i=0; i<3; i++) {
    for(int j=0; j<3; j++) {
      cin >> b[i][j];
    }
  }
  
  int n, number;
  cin >> n;
  
  for (int i=0; i<n; i++) {
    cin >> number;
    for(int j=0; j<3; j++) {
      for(int k=0; k<3; k++) {
        if(number == b[j][k]) {
          b[j][k] = 0;
        }
      }
    }
  }
  
  if(b[0][0] == b[1][0] && b[1][0] == b[2][0]) cout << "Yes" << endl;
  else if(b[0][1] == b[1][1] && b[1][1] == b[2][1]) cout << "Yes" << endl;
  else if(b[0][2] == b[1][2] && b[1][2] == b[2][2]) cout << "Yes" << endl;
  else if(b[0][0] == b[0][1] && b[0][1] == b[0][2]) cout << "Yes" << endl;
  else if(b[1][0] == b[1][1] && b[1][1] == b[1][2]) cout << "Yes" << endl;
  else if(b[2][0] == b[2][1] && b[2][1] == b[2][2]) cout << "Yes" << endl;
  else if(b[0][0] == b[1][1] && b[1][1] == b[2][2]) cout << "Yes" << endl;
  else if(b[0][2] == b[1][1] && b[1][1] == b[2][0]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

signed main(){
	vector<int> a(3);
	for(auto &e : a)cin >> e;
	sort(ALL(a));
	cout << a[0] + a[1] << endl;


	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <numeric>
#include <malloc.h>
using namespace std;

int main()
{
	int N;
	cin>>N;
	vector<int> A;
	A.resize(N);
	for(int i=0; i<N; i++)
	{
		cin>>A[i];
	}
	int g = __gcd(A[0],A[1]);
	for(int i=2; i<N; i++)
	{
		g = __gcd(g,A[i]);
	}
	cout<<g<<endl;
	return 0;
}

Measured memory_bytes: 640
N,Y=map(int,input().split(" "))
ans=0
a=(-1)
for i in range(N+1):
    for j in range(N-i+1):
        if i*10000+j*5000+(N-i-j)*1000==Y:
            print(i,j,N-i-j)
            ans=1
            exit()
if ans==0:
    print(a,a,a)

Measured memory_bytes: 3060
N,M=map(int, input().split())
A=list(map(int, input().split()))

sum_A = sum(A)
SA = sorted(A,reverse=True)
cnt  = 0
f = 0
ck = 1/(4 * M)
for i in range(0,N):
    if SA[i]/sum_A < ck:
        break
    else:
        cnt +=1
        if cnt == M:
            f = 1
            break
if f == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064