akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)

const int N = 102;

int dp[N][N][N+N];
int n, m;
char s[N][N];

int f(int i, int j, int k) {
  int& ret = dp[i][j][k];
  if(ret != -1) return ret;
  if(i == n && j == m) {
    if((s[n][m] == '#') ^ (k&1)) {
      if(k) ret = 0;
      else ret = 1;
    } else {
      ret = 0;
    }
    return ret;
  }
  ret = 1e8;
  if(i != n) {
    if((s[i][j] == '#') ^ (k&1)) {
      if(k) ret = min(ret, f(i+1, j, k-1));
      ret = min(ret, 1 + f(i+1, j, k+1));
    } else {
      ret = min(ret, f(i+1, j, k));
    }
  }
  if(j != m) {
    if((s[i][j] == '#') ^ (k&1)) {
      if(k) ret = min(ret, f(i, j+1, k-1));
      ret = min(ret, 1 + f(i, j+1, k+1));
    } else {
      ret = min(ret, f(i, j+1, k));
    }
  }
  return ret;
}
int main(int argc, char const *argv[])
{
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  scanf("%d %d", &n, &m);
  for(int i = 1; i <= n; ++i) {
    scanf("%s", s[i]+1);
  }
  memset(dp, -1, sizeof dp);
  printf("%d\n", f(1, 1, 0));
  return 0;
}

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

int32_t main()
{
    int n;cin>>n;

    string str;
    cin>>str;

    int ans=0;
    for(int i=0;i<n;i++){
        if(str[i]=='A'){
            i++;
            if(str[i] && str[i]=='B'){
                i++;
                if(str[i] && str[i]=='C'){
                    ans++;
                }
                else
                    i=i-2;
            }
            else
            {
                i--;
            }
        }
    }

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

Measured memory_bytes: 3632
S = input()
n, m = 0, 1
s = []
patern = 0
for i in range(len(S)):
    s.append(S[i])
while n + m < len(s):
    if s[n] is 'x':
        if s[-m] is not 'x':
            s.append('x')
            patern += 1
    else:
        if s[-m] is 'x':
            n -= 1
            patern += 1
        elif s[-m] is not s[n]:
            patern = -1
            break
    n += 1
    m += 1
if patern != -1:
    print(patern)
else:
    print(patern)


Measured memory_bytes: 4724
#include <iostream>
#include <vector>
#include <algorithm>
#define AvoidMinus(a) ((a) < 0 ? 0 : (a))
using namespace std;

bool compare(pair<int, int>former, pair<int, int>latter){
    return former.second < latter.second;
}

int main(void){
    int H, N, Abuf, Bbuf;
    vector<pair<int, int>> AB;
    cin >> H >> N;
    for(int i=0; i<N; i++){
        cin >> Abuf >> Bbuf;
        AB.push_back(pair<int, int>(Abuf, Bbuf));
    }

    vector<int> dp(H+1,0);
    for(int i=1; i<H+1; i++){
        for(int j=0; j<N; j++){
            if(dp[i]==0){
                dp[i]=dp[AvoidMinus(i-AB[j].first)]+AB[j].second;
            }else{
                dp[i]=min(dp[i], dp[AvoidMinus(i-AB[j].first)]+AB[j].second);
            }
        }
    }

    cout << dp[H] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
#define MOD 1000000007
#define PI 3.14159265358979323846
using namespace std;
typedef long long ll;



int main(void) {
	double a, b, h, m; cin >> a >> b >> h >> m;
	double l, s;
	l = PI * h / 6 + PI * m / 360;
	s = PI * m / 30;
	double lx, ly,sx,sy;
	lx = a * cos(l);
	ly = a * sin(l);
	sx = b * cos(s);
	sy = b * sin(s);
	double ans = (lx - sx)*(lx - sx) + (ly - sy)*(ly - sy);
	ans = sqrt(ans);
	printf("%.10f", ans);
	return 0;
}


Measured memory_bytes: 4152
#include <iostream>
#include <vector>
int main(){
    using namespace std;
    int n,i,a;
    vector<int> v;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a;
        v.push_back(a);
    }
    for(i=0;i<n;i++){
        cout << v[n-1-i];
        if(i!=n-1){
            cout << " ";
        }
    }
    cout << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N, K; scanf("%d %d", &N, &K);
  vector<int> freqs(2 * 1e5 + 5, 0);
  int a;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a);
    ++freqs[a];
  }
  sort(freqs.begin(), freqs.end(), greater<int>());
  int ans = N;
  for (int i = 0; i < K; ++i) {
    ans -= freqs[i];
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1024
//
//AtCoder Beginner Contest 147
//B - Palindrome-philia
//

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define reAll(x) (x).rbegin(),(x).rend()

using ll = long long;

const double PI = 3.14159265358979323846;
const int MOD = 1000000007;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
    string s;

    cin >> s;

    int result = 0;

    int len = s.size();

    rep(i,len/2){
        if (s[i] != s[len-i-1]) result++;
    }

    cout << result << endl;
    
    return 0;
}


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

int main() {
	string s; int flag = 0, tc, a, b, i;
	cin >> a >> b;
	getline(cin, s);
	getline(cin, s);
	for (i = 0; i < a; i++)if (s[i] == '-')flag = 1;
	if (s[i] != '-')flag = 1;
	for (i++; i < a+1+b; i++)if (s[i] == '-')flag = 1;
	cout << (flag ? "No\n" : "Yes\n");
}

Measured memory_bytes: 256
X,N = map(int,input().split())
if N==0:
    print(X)
    exit()
P = [int(i) for i in input().split()]

ans = X+10
tmp = []
P2 = [int(i) for i in range(-200,200)]
P3 = list(set(P2)-set(P))
P3.sort()
P3[::-1]
for i in P3:
    if ans > abs(X-i):
        ans = abs(X-i)
        tmp.append(i)
print(max(tmp))

Measured memory_bytes: 9272
program count_order
    implicit none
    integer(4):: n, i, t, pl, ql
    integer(4), allocatable:: p(:), q(:)
    integer(4), parameter:: bi(8) = [1, 2, 6, 24, 120, 720, 5040, 40320]

    read*, n
    allocate(p(n), q(n))
    read*, p(:)
    read*, q(:)
    pl = 0

    do i = 1, n-1
        where(p(i+1:) > p(i))
            p(i+1:) = p(i+1:) - 1
        end where
        p(i) = p(i) * bi(n-i)
    end do

    do i = 1, n-1
        where( q(i+1:) > q(i))
            q(i+1:) = q(i+1:) - 1
        end where
        q(i) = q(i) * bi(n-i)
    end do

    print*, abs(sum(p-q))
end program count_order

Measured memory_bytes: 256
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;


#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  ll               long long
#define  vi               std::vector<int>
#define  pb               push_back
#define  MAX              100007
#define  End              return 0;
#define                   pi acos(-1)
ll bb[100000];

int main () {
    ll aa[4][4];
    for(ll i=1; i<=3; i++){
        for(ll j=1; j<=3; j++)
            cin>>aa[i][j];
    }
    ll n,t;
    cin>>t;
    while(t--){
        cin>>n;
        bb[n]=1;
    }
    bool f=true;

    if(bb[aa[1][1]]+bb[aa[1][2]]+bb[aa[1][3]]==3)
        f=false;
    if(bb[aa[2][1]]+bb[aa[2][2]]+bb[aa[2][3]]==3)
        f=false;
    if(bb[aa[3][1]]+bb[aa[3][2]]+bb[aa[3][3]]==3)
        f=false;
    if(bb[aa[1][1]]+bb[aa[2][2]]+bb[aa[3][3]]==3)
        f=false;
    if(bb[aa[3][1]]+bb[aa[2][2]]+bb[aa[1][3]]==3)
        f=false;
    if(bb[aa[1][1]]+bb[aa[2][1]]+bb[aa[3][1]]==3)
        f=false;
    if(bb[aa[1][2]]+bb[aa[2][2]]+bb[aa[3][2]]==3)
        f=false;
    if(bb[aa[1][3]]+bb[aa[2][3]]+bb[aa[3][3]]==3)
        f=false;

    if(f)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    End;
}
/* pray for me
All is well
*/





Measured memory_bytes: 256
package main
 
import (
  "fmt"
  "math"
)

func max(nums ...int) int {
    if len(nums) == 0 {
        panic("funciton max() requires at least one argument.")
    }
    res := nums[0]
    for i := 0; i < len(nums); i++ {
        res = int(math.Max(float64(res), float64(nums[i])))
    }
    return res
}

func main() {
  var n,w int
  fmt.Scan(&n,&w)
  
  weight := make([]int, n)
  price := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&weight[i])
    fmt.Scan(&price[i])
  }
  
  //N×Wの配列
  //N番目までの荷物を使い、容量Wに詰めた時の価値の最大値を格納
  dp := make([][]int, n+1)
  for i := 0; i < n+1; i++ {
    dp[i] = make([]int, w+1)
    if i==0 {
      dp[0][i] = 0
    }
  }

  //詰める荷物の番号を増やしていく
  for i := 1; i <= n; i++ {   
      //容量を増やしていく
    for j := 0; j <= w; j++ {
      //i番目の荷物が容量jに収まらない場合、j-1の時と価値の最大値は同じ
      if weight[i-1] > j {
        dp[i][j] = dp[i-1][j]
      } else { 
        //i番目の荷物が容量jに収まる場合、価値を評価する
        dp[i][j] = max(dp[i-1][j-weight[i-1]]+price[i-1],dp[i-1][j])
      }
    }
  }
  
  ans := 0
  for i := 1; i <= n; i++ {
    for j := 1; j <= w; j++ {
      if dp[i][j] > ans {
      ans = dp[i][j]
      }
    }
  }
  fmt.Println(ans)
}

Measured memory_bytes: 81792
#include <stdio.h>

int main(void)
{
	long long int n, k, i, ans=0, max, min;
	int mod = 1000000007;
	
	scanf("%lld%lld", &n, &k);
	
	for (i = k; i <= n + 1; i++) {
		max = i * (2 * n - i + 1) / 2;
		min = i * (i - 1) / 2;
		ans += max - min + 1;
		ans = ans % mod;
	}

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

Measured memory_bytes: 1728
// 物极必反

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 5e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 998244353;
const long long INF = 1e18 + 9;
const int SM = 3e3 + 5;
const int logN = 22, BL = 400;
const long double EPS = 1e-14;
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug(){
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main(){
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n, a, b; cin >> n >> a >> b;

    string s; cin >> s;

    long long passed = 0, overseas = 0;
    for(long long i = 0; i < n; i++){
        if(s[i] == 'a'){
            if(passed < a + b){
                passed++;
                cout << "Yes\n";
            }
            else {
                cout << "No\n";
            }
        }
        else if(s[i] == 'b'){
            if(overseas < b && passed < a + b){
                passed++;
                overseas++;
                cout << "Yes\n";
            }
            else {
                cout << "No\n";
            }
        }
        else {
            cout << "No\n";
        }
    }

    return 0;
}


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

int main()
{
  string s;

  cin >> s;
  if (s[2] == s[3] && s[4] == s[5])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

bool block[6][110][110];
bool visit[110][110];

int main(){
	int w, h;
	int xs, ys, xg, yg;
	int n, c, d, x, y;
	while(scanf("%d%d%d%d%d%d%d", &w, &h, &xs, &ys, &xg, &yg, &n) == 7){
		memset(block, 0, sizeof block);
		memset(visit, 0, sizeof visit);

		for(int i = 0; i < n; ++i){
			scanf("%d%d%d%d", &c, &d, &x, &y);
			
			int dx, dy;
			if(d){ dx = 2; dy = 4; }
			else{  dy = 2; dx = 4; }

			for(int j = 0; j < dy; ++j)
			for(int k = 0; k < dx; ++k){
				block[c][y + j][x + k] = true;
			}
		}

		for(c = 5; c > 1 && !block[c][ys][xs]; --c);

		if(c){
			queue<int> q;
			q.push(ys << 16 | xs);
			visit[ys][xs] = true;
			while(!q.empty()){
				y = q.front() >> 16;
				x = q.front() & 0xffff;
				q.pop();

				for(int dy = -1; dy <= 1; ++dy)
				for(int dx = -1; dx <= 1; ++dx){
					if(block[c][y+dy][x+dx] && !visit[y+dy][x+dx]){
						visit[y+dy][x+dx] = true;
						q.push(y+dy << 16 | x+dx);
					}
				}
			}
		}

		puts(visit[yg][xg] ? "OK" : "NG");
	}
}

Measured memory_bytes: 1108
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<climits>
#include<cstdlib>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
#define ULL unsigned long long
LL read(){
	LL f=1,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f*x;
}
#define MAXN 200005
#define INF 0x3f3f3f3f
int main(){
	LL X=read(),Y=read();
	puts(fabs(X-Y)>1?"Alice":"Brown");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";} cout << endl;
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


#define MAX_AA  (ll)1e18;
#define MIN_AA  (ll)-1e18;


int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a;
    rep(i, n){ ll tmp; cin >> tmp; a.push_back(tmp);}
    sort(a.begin(), a.end());
    //
    ll l = -1e18-1;
    ll r = 1e18+1;
    while(abs(r-l) > 1){
        //二分探索によりxより小さいものがk個以上ある最大のxを求める。
        ll sum = 0;
        ll mid = (l+r)/2;
        for (int i = 0; i < n; i++)
        {
            int tl = -1;
            int tr = n;
            if (a[i] >= 0){
                while(abs(tl-tr) > 1){
                    //tmid が正の時 T 側
                    int tmid = (tl + tr)/2;
                    if (a[i]*a[tmid] <= mid) tl = tmid;
                    else tr = tmid;
                }
                sum += tl+1;
                if (i<=tl) sum--;
            } else {
                while(abs(tl-tr) > 1){
                    int tmid = (tl + tr)/2;
                    if (a[i]*a[tmid] <= mid) tr = tmid;
                    else tl = tmid;
                }
                sum += n-tr;
                if (tr<=i) sum--;
            }
        }
        sum /= 2;
        //cout << sum << endl;
        if (sum >= k){
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << r << endl;
}


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

vector<int> checkex(string str){
  vector<int> exist(26, false);
  for(int i = 0; i < str.size(); i++){
    exist[str[i] - 'a'] = true;
  }
  return exist;
}

bool includeall(vector<int>& exist){
  for(int i = 0; i < exist.size(); i++){
    if(exist[i] == false) return false;
  }
  return true;
}

int main(void){
  string str; cin >> str;
  vector<int> exist = checkex(str);

  if(str == "zyxwvutsrqponmlkjihgfedcba"){
    cout << -1 << endl;
    return 0;
  }

  if(includeall(exist)){
    char mi = str[str.size()-1];
    char ma = mi;
    char prev = str[str.size()-1];
    int idx;
    exist[prev-'a'] = false;
    for(idx = str.size()-2; idx >= 0; idx--){
      if(prev < str[idx]){
        prev = str[idx];
        exist[prev-'a'] = false;
      }else{
        break;
      }
    }
    for(int i = 0; i < exist.size(); i++){
      if(exist[i] == true) continue;
      char c = (char)(i + 'a');
      if(c > str[idx]){
        cout << str.substr(0, idx) << c << endl;
        break;
      }
    }

  }else{
    for(int i = 0; i < exist.size(); i++){
      if(exist[i] == false){
        cout << str << (char)(i+'a') << endl;
        break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n,a,d,dmin=100;
 
  cin >> n;
  
  for(int i=0;i<n;i++){
    cin >> a;
    d=0;
    while(a%2==0){
      a/=2;
      d++;
    }
    if(d<dmin)dmin=d;
  }
  cout << dmin << endl;
}

Measured memory_bytes: 256
n,W=map(int, input().split())
w=[0]*n
v=[0]*n
for i in range(n):
    x,y=map(int, input().split())
    w[i]=x
    v[i]=y
dp=[[0 for i in range(W+1)] for j in range(n+1)]
for i in range(n):
    for j in range(W+1):
        if j<w[i]:
            dp[i+1][j]=dp[i][j]
        else:
            dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i])
print(dp[n][W])

Measured memory_bytes: 171912
#include<stdio.h>
#define MAX 10000
#define NIL -1
struct node{
  int p,lc,rs;
};
struct node T[MAX];
int n;
void pre(int);
void in(int);
void post(int);
int main(){
  int i,id,lc,rs,z;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&id,&lc,&rs);
    T[id].lc=lc;T[id].rs=rs;
    if(rs!=NIL)T[rs].p=id;
    if(lc!=NIL)T[lc].p=id;
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL)z=i;
  }
  printf("Preorder\n");
  pre(z);
  printf("\n");
  printf("Inorder\n");
  in(z);
  printf("\n");
  printf("Postorder\n");
  post(z);
  printf("\n");
 
  return 0;
}

void pre(int x){
  if(x==NIL)return 0;
  printf(" %d",x);
  pre(T[x].lc);
  pre(T[x].rs);
  
}
void in(int x){
   if(x==NIL)return 0;
   in(T[x].lc);
   printf(" %d",x);
   in(T[x].rs);
}
void post(int x){
   if(x==NIL)return 0;
   post(T[x].lc);post(T[x].rs);
    printf(" %d",x);
}



Measured memory_bytes: 2112
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int a[110];
int main()
{
	int n,out=0;cin>>n;rep(i,n) cin>>a[i];sort(a,a+n);reverse(a,a+n);
	rep(i,n){
		if(i%2==0) out+=a[i];else out-=a[i];
	}
	cout<<out<<endl;
}


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

using namespace std;
int a[110000];
int main() {
	int n;
	cin >> n;
	for(int i = 0;i < n; i ++){
		cin >> a[i];
	}
	int gcd = a[0];
	for(int i = 1;i < n; i++){
		gcd = __gcd(gcd, a[i]);
		if(gcd == 1) break; // once 1 occurs, the answer must be 1
	}
	cout << gcd << endl;
	return 0;
}

Measured memory_bytes: 3992
import math

def max_heapify(A, i):
    l = 2*i
    r = 2*i + 1
    if ( l <= H ) and ( A[l] > A[i]):
        largest = l
    else:
        largest = i
    if (r <= H ) and ( A[r] > A[largest]):
        largest = r
        
    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        max_heapify(A, largest)
        
        
def build_max_heap(A):
    for i in range(math.floor(len(A)-1), 0, -1):
        max_heapify(A, i)
        
H = int(input())
A = [None] + list(map(int, input().split()))
build_max_heap(A)

for a in A[1:]:
    print(f" {a}", end="")
print("")


Measured memory_bytes: 63772
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int n, x;
    while(cin >> n >> x){
        if(n == 0 && x == 0){
            break;
        }else{
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            for(int k = j + 1; k <= n; k++){
                if(i + j + k == x){
                    cnt++;
                }
            }
        }
    }cout << cnt << endl;
        }
    }
    
return 0;
}

Measured memory_bytes: 3084
#include<iostream>
using namespace std;
int main()
{
	int n,ans=0;
	cin>>n;
	int p[n];
	for(int i=0;i<n;i++)
	{
		cin>>p[i];
	}
	for(int i=1;i<n-1;i++)
	{
		if(p[i-1]<p[i]&&p[i+1]>p[i]||p[i-1]>p[i]&&p[i+1]<p[i])
		{
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,N,K,ans=0;
  cin>>N>>K;
  if(N-1<=K){
    print(modncr(N*2-1,N));
    return 0;
  }
  rep(i,K+1){
    //N-i box N boll 1<=;
    ans=(ans+modncr(N,i)*modncr(N-1,i)%mod)%mod;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll n,q;vector<ll>a[200010];
ll cnt[200010],ans[200010];

void dep(ll now){
	if(now!=0&&a[now].size()==1){
		return;
	}
	for(ll i=0;i<a[now].size();i++){
		ll next=a[now][i];
		if(ans[next]!=-1){
			continue;
		}
		ans[next]=ans[now]+cnt[next];
		dep(next);
	}
}
int main() {
	ll n,q;
	cin>>n>>q;
	for(ll i=0;i<n;i++){
		ans[i]=-1;
	}
	for(ll i=0;i<n-1;i++){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	for(ll i=0;i<q;i++){
		ll x,y;
		cin>>x>>y;
		x--;
		cnt[x]+=y;
	}
	ans[0]=cnt[0];
	dep(0);
	for(ll i=0;i<n;i++){
		cout << ans[i]<<" ";
	}
	// your code goes here
	return 0;
}

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

long long a;
double b;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>a>>b;
	cout<<a * int(b * 100 + 1e-8) / 100<<endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<bool>S(14,true);
  vector<bool>H(14,true);
  vector<bool>C(14,true);
  vector<bool>D(14,true);
  S[0] = false;H[0] = false;C[0] = false;D[0] = false;
  for(int i = 0;i < n;i++){
    char x;int a;
    cin >> x >> a;
    if(x == 'S') S[a] = false;
    if(x == 'H') H[a] = false;
    if(x == 'C') C[a] = false;
    if(x == 'D') D[a] = false;
  }
  for(int i = 1;i <= 13;i++){
    if(S[i]){
      cout << "S " << i << endl;
    }
  }
  for(int i = 1;i <= 13;i++){
    if(H[i]){
      cout << "H " << i << endl;
    }
  }
  for(int i = 1;i <= 13;i++){
    if(C[i]){
      cout << "C " << i << endl;
    }
  }
  for(int i = 1;i <= 13;i++){
    if(D[i]){
      cout << "D " << i << endl;
    }
  }
}



Measured memory_bytes: 3096
#include<iostream>
#include<unordered_map>
#include<cstdio>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>
#define int long long
using namespace std;

int a[100][7];
signed main() {
	int b, c; scanf("%lld%lld", &b, &c);
	for (int d = 0; d < 50; d++) {
		for (int e = 0; e < 7; e++) {
			a[d][e] = (d + 1) * 7 + e - 6;
		}
	}
	int ans = 0;
	//それぞれの列
	for (int i = 0; i <= 4; i++) {
		for (int j = 0;j<=b-3; j++) {
			if (a[j + 1][i + 1] * 9 % 11 == c) {
				ans += (b - j - 3) / 11 + 1;
				break;
			}
		}
	}
	cout << ans << endl;
}

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

string s,t;
bool cht = 0,chm=0;

int main(){
  int i,j,l;
  cin >> s >> t;

  i = s.length();
  l = t.length();
  while(cht==0&&i>=l){
    for(j=1;j<=l;j++){
      if(s[i-j]!=t[l-j]&&s[i-j]!='?'){
	chm++;
	continue;
      }
      //      cout << s[i-j] << t[l-j] << endl;
    }
    if(chm==0){
      for(j=1;j<=l;j++){
	s[i-j]=t[l-j];
	//	cout << s[i-j];
      }
      cht++;
    }
    chm = 0;
    i--;
  }
  if(cht==1){
    for(i=0;i<s.length();i++)if(s[i]=='?')s[i]='a';
    cout << s << endl;
  }
  else cout <<"UNRESTORABLE"<<endl;
  return 0;
}


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



int main() {
    int64_t n,m,k;
    cin >> n >> m >> k;
    vector<int64_t> v1(n);
    vector<int64_t> v2(m);
    rep(i,n){
        cin >> v1[i];
    }
    rep(i,m){
        cin >> v2[i];
    }
    int64_t ans=0;
    vector<int64_t> tot1(n+1);
    vector<int64_t> tot2(m+1);
    tot1[0]=0;
    tot2[0]=0;
    rep(i,n){
        tot1[i+1]=v1[i]+tot1[i];
    }
    rep(i,m){
        tot2[i+1]=v2[i]+tot2[i];

    }
    rep(i,n+1){
        int64_t x=k-tot1[i];
        if(x<0) break;
        if(x==0){
            ans=max(ans,i);
            break;
        }
        int ok=-1;
        int ng=m+1;
        
        while(ok+1!=ng){
            int mid=(ok+ng)/2;
            if(tot2[mid]>x) ng=mid;
            else ok=mid;
            if(ok+1==ng){
                ans=max(ans,i+ok);
                break;
            }
        }
        
        
    }
    cout << ans << endl;
    
}

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

namespace ABC131B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var n = input[0];
            var l = input[1];

            var apples = Enumerable.Range(l, n);
            var min = apples.OrderBy(x => x * x).First();

            Console.WriteLine(apples.Sum() - min);
        }
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<cstdio>
#include<cstring>
#include<climits>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
int n,sum,a[105],ans,p,q;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);sum+=a[i];
	}
	int res=sum/n,rm=sum/n+1,rs=sum/n-1;
	//printf("%d\n",rm);
	for(int i=1;i<=n;i++)
	{
		ans+=(a[i]-res)*(a[i]-res);
		p+=(a[i]-rm)*(a[i]-rm);
		q+=(a[i]-rs)*(a[i]-rs);
	}
	printf("%d",min(ans,min(p,q)));
}

Measured memory_bytes: 256
li=[0]*8
o=0
n,*a=map(int,open(0).read().split())
for i in a:
  if i>=3200:
    o+=1  
  else:
    li[i//400]=1

#全員3200以上==(sum(li)==0)> 1,min(o,8)
#全員3200未満==(o==0)> sum(li),min(sum(li)+o,8)
#それ以外>sum(li)
if sum(li)==0:
  print(1,min(o,8))
else:
  print(sum(li),(sum(li)+o))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie();
	cout.tie();
	cin >> a;
	while(a>=10){
		b=a%10;
		if(b==7){
			cout << "Yes" << endl;
			return 0;
		}
		a/=10;
	}
	if(a==7){
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
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;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

ll ll_isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 2;
    if(x%2 == 0) return 2;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return i;
    return 0;
}








int main(){
    ll n;
    cin >> n;
    ll x = n;
    

    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            x = min(x,i+(n/i)-2);
        }
    }
    cout << x << endl;
}

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

using namespace std;

#define ll long long

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

	vector < ll > x(N), y(N), h(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> h[i];
	}

	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			ll height = 0;
			for (int k = 0; k < N; k++) {
				if (h[k] != 0) {
					height =
					    h[k] + abs(x[k] - i) + abs(y[k] -
								       j);
					break;
				}
			}
			if (height <= 0) {
				continue;
			}
			bool isValid = true;

			for (int k = 0; k < N; k++) {
				ll hh =
				    max(height - abs(x[k] - i) - abs(y[k] - j),
					0LL);
				if (hh != h[k]) {
					isValid = false;
					break;
				}
			}
			if (isValid) {
				cout << i << " " << j << " " << height << endl;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int fc[100001], in[100001];
vector<vector<int>> adj;
int pwmd(int a, int n)
{
	if (!n)
		return 1;
	int pt = pwmd(a, n / 2);
	pt *= pt, pt %= mod;
	if (n & 1)
		pt *= a, pt %= mod;
	return pt;
}


int32_t main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;

	if((a+b)>k)
		cout<<k<<endl;
	else
	{
		int ans=a;
		int diff=(k-(a+b));
		ans-=diff;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3648
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import Counter

def main():
    N = II()
    SP = []
    for i in range(1, N + 1):
        s, p = LS()
        p = int(p)
        SP.append([s + '{:06}'.format(100 - p), i])
    SP.sort()
    for _, id in SP:
        print(id)
    return

main()

Measured memory_bytes: 3316
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iomanip>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;
	
int n;
vector<int> d;

bool check() {
	int mx = 0;
	bool ans = true;
	rep(i, n) {
		mx = max(d[i]+i, mx);
		if (mx <= i)return false;
		if (mx >= n - 1)return true;
	}
	return false;
}

int main()
{
	cin >> n;
	d.resize(n);

	rep(i, n) {
		cin >> d[i];
		d[i] /= 10;
	}
	bool ans1 = check();
	reverse(d.begin(), d.end());
	bool ans2 = check();
	if (ans1 && ans2)cout << "yes" << endl;
	else cout << "no" << endl;
	return 0;
}

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

int main() {
  long double L;
  cin >> L;
  long double ans = pow(L / 3, 3);
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
const long long mod = 1e9+7;

pair<long long,long long> dfs(vector< vector<int> > &G, int v, int p){
  pair<long long,long long> ret(1,1);
  for(size_t i = 0; i < G[v].size(); ++i){
    int v_ = G[v][i];
    if(v_ == p) continue;
    pair<long long,long long> ret_ = dfs(G,v_,v);
    ret.first *= (ret_.first+ret_.second)%mod;
    ret.first %= mod;
    ret.second *= ret_.first;
    ret.second %= mod;
  }
  return ret;
}

int main(){
  int N;
  cin >> N;
  vector< vector<int> > G(N);
  for(int i = 0; i < N-1; ++i){
    int x, y;
    cin >> x >> y;
    --x;--y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  pair<long long,long long> ans = dfs(G,0,-1);
  cout << (ans.first+ans.second)%mod << endl;
}


Measured memory_bytes: 12672
W,H,x,y,r=map(int,input().split())

if y-r<0 or y+r>H:
  print("No")
  


elif x-r<0 or x+r>W:
  print("No")

elif y-r>=0 and y+r<=H:
    print("Yes")

elif x-r>=0 and x+r<=W:
    print("Yes")


 

    



Measured memory_bytes: 5596
N = int(input())
low = [0] * N;  up = [0] * N;
for i in range(N):
    low[i], up[i] = [int(x) for x in input().split()]

low.sort()
up.sort(reverse = True)

if N % 2 == 0:
    k = N // 2
    ans = 0
    l1 = low[k - 1]
    l2 = low[k]
    u1 = up[k - 1]
    u2 = up[k]
    ans = u1 + u2 - l1 - l2 + 1
else:
    k = (N - 1) // 2
    l = low[k]
    u = up[k]
    ans = u - l + 1

print(ans)

Measured memory_bytes: 25516
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i, j;
	long long int a[300005];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	int b[300005][62];
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < 62; j++)
		{
			b[i][j] = (int)(a[i] % 2);
			a[i] /= 2;
		}
	}
	long long int ans = 0;
	long long int c0, c1, q = 1;
	long long int p = 1000000007;
	for (j = 0; j < 62; j++)
	{
		c0 = c1 = 0;
		for (i = 0; i < n; i++)
		{
			if (b[i][j] == 0)c0++;
			else c1++;
		}
		ans = (ans + q * c0 % p * c1 % p) % p;
		q = q * 2 % p;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 75136
import collections

N = int(input())

def f(n) :
  if n < 2 :
    return 1
  else :
    return n * f(n-2)

def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

def prime_factorize(n):
  a = []
  while n % 2 == 0:
    a.append(2)
    n //= 2
  f = 3
  while f * f <= n:
    if n % f == 0:
      a.append(f)
      n //= f
    else:
      f += 2
  if n != 1:
    a.append(n)
  return a

if N % 2 != 0 :
  print(0)
else :
  # result = factorization(N)
  result = 0
  tmp = N//5
  # while True : 
  # tmp = collections.Counter(prime_factorize(N))
  # result += tmp[5]
  while True :
    if tmp == 0 :
      break
    result += (tmp//2)
    tmp = tmp//5
  # print(f(N))
  # cnt = 10
  # result = N//cnt
  # cnt *= 10
  # while True :
    # digit = N//cnt
    # if digit == 0 :
    #   break
    # result += digit
    # tmp = cnt
    # while True :
    #   x = tmp // 2
    #   if x == 0 :
    #     break
    #   result += (N//(x))-(N//tmp)
    #   tmp = x
    # cnt *= 10
  # if N >= 50 :
  #   result += (N//50)-(N//100)
  print(result)
  # print(tmp)

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

int main(){
  	int A, B, C, X;
  	cin >> A >> B >> C >> X;
  	int counter = 0;
  	for (int i=0;i<A+1;i++){
      	for(int j=0;j<B+1;j++){
          	for(int k=0;k<C+1;k++){
              	if(i*500+j*100+k*50 == X) counter++;
            }
        }
    }
  	cout << counter << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>

using namespace std;

int main(){
   int n, i, count1, count2, counta = 0, countb = 0;
   string s, a = "";

   cin >> n;
   cin >> s;

   i = 0;
   count1 = 0;
   count2 = 0; 
   while(i != n){
      while(i != n && s[i] == '(' ){
         count1++;
         i++;
      }

      while(i != n && s[i] == ')'){
         count2++;
         i++;
      }

      if(count1 < count2){
         counta += count2 - count1;
         count1 = 0;
         count2 = 0; 
      }
   }
   
   i = n - 1;
   count1 = 0;
   count2 = 0; 
   while(i != -1){
      while(i != -1 && s[i] == ')' ){
         count1++;
         i--;
      }

      while(i != -1 && s[i] == '('){
         count2++;
         i--;
      }

      if(count1 < count2){
         countb += count2 - count1;
         count1 = 0;
         count2 = 0; 
      }
   }

   for(int j = 0; j < counta; j++) a += '(';
   a += s;
   for(int j = 0; j < countb; j++) a += ')';

   cout << a << endl;
}

Measured memory_bytes: 3636
N,M = list(map(int, input().split(' ')))
Xs = list(map(int, input().split(' ')))

Xs.sort()
L=[]
for i in range(M-1):
  L.append(Xs[i+1]-Xs[i])
  
L.sort()
result = sum(L[:1-N]) if N>1 else sum(L)

print(result)

Measured memory_bytes: 13968
#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<int, int> P;
typedef pair<ll, ll> PL;
const int MOD = 1e9+7;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

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

    int n, m;
    cin >> n >> m;
    vector<P> ans;
    if (n % 2) {
        for (int l = 1, r = n - 1; l < r; l++, r--) {
            ans.emplace_back(l, r);
        }
    } else {
        bool flag = false;
        for (int l = 1, r = n - 1; l < r; l++, r--) {
            if (!flag && r - l <= n / 2) {
                --r;
                flag = true;
            }
            ans.emplace_back(l, r);
        }
    }
    rep(i, m) {
        printf("%d %d\n", ans[i].first, ans[i].second);
    }

    return 0;
}

Measured memory_bytes: 4280
N = int(input())
listA = [int(input()) for i in range(N)]
count = 0

for x in range(N):
    check = listA[x]
    count += check // 2
    if x != N - 1 and check % 2 != 0:
        if listA[x + 1] > 0:
            count += 1
            listA[x + 1] -= 1
print(count)


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

using namespace std;


typedef long long ll;


int main( )
{
    int a,b,t;


    scanf("%d %d %d",&a,&b,&t);

    int sum=0;
    int j=1;
    for(int i=a;i<=t+0.5;i++)
    {
        if(i==a*j)
        {
            sum+=b;
            j++;
        }
    }

    printf("%d\n",sum);
    return 0;

}


Measured memory_bytes: 256
n=int( input())
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split() )
c=[[a[i],b[i],a[i]+b[i]] for i in range(n)]
c.sort(reverse=True,key=lambda x:x[2])
tsum=sum(c[i*2][0] for i in range((n+1)//2))
asum=sum(c[i*2+1][1] for i in range(n//2))
print( tsum- asum )

Measured memory_bytes: 63448
#include <iostream>

using namespace std;

double dp[305][305][305];
int N;

double dfs(int i, int j, int k)
{
	if (i == 0 && j == 0 && k == 0) {
		return 0.0;
	}
	if (dp[i][j][k] > 0) {
		return dp[i][j][k];
	}

	int m = i + j + k;
	double ret = 1.0 * N / m;
	if (i > 0) {
		ret += 1.0 * i / m * dfs(i - 1, j, k);
	}
	if (j > 0) {
		ret += 1.0 * j / m * dfs(i + 1, j - 1, k);
	}
	if (k > 0) {
		ret += 1.0 * k / m * dfs(i, j + 1, k - 1);
	}
	dp[i][j][k] = ret;

	return ret;
}

int main(int argc, char *argv[])
{
	int one = 0, two = 0, three = 0;

	cin >> N;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		if (a == 1) {
			one++;
		} else if (a == 2) {
			two++;
		} else if (a == 3) {
			three++;
		}
	}

	dfs(one, two, three);

	printf("%.9lf\n", dp[one][two][three]);

	return 0;
}

Measured memory_bytes: 219392
for _ in [0] * int(raw_input()):
  h, m = map(int, raw_input().split(':'))
  x = abs(h*60 - m*11)
  if x>360: x = 720 - x
  if x<60:
    print 'alert'
  elif 180<=x:
    print 'safe'
  else:
    print 'warning'

Measured memory_bytes: 4200
//BISMILLAHIR RAHMANIR RAHIM
//SOTO MEAW
//SOTO SONDESH
#include<bits/stdc++.h>

#define ls ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define __ <<" "<<
#define loop(m,n) for(m=0;m<n;m++)
#define rloop(m,n) for(m=n-1;m>=0;m--)
#define case(z) "Case " << z++ << ": "
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define newline cout<<endl
#define quit return 0

using namespace std;

int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool miillerTest(int d, int n)
{
    int a = 2 + rand() % (n - 4);
    int x = power(a, d, n);
    if (x == 1  || x == n-1)
       return true;
    while (d != n-1)
    {
        x = (x * x) % n;
        d *= 2;
        if (x == 1)      return false;
        if (x == n-1)    return true;
    }
    return false;
}
bool isprime(int n, int k)
{
    if (n <= 1 || n == 4)  return false;
    if (n <= 3) return true;
    int d = n - 1;
    while (d % 2 == 0)
        d /= 2;
    for (int i = 0; i < k; i++)
         if (!miillerTest(d, n))
              return false;
    return true;
}
int main()
{
    ls
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //ll int t,l=1;cin>>t;while(t>0){
        ll int a,b,c,d,sum=1;
        cin >> a >> b >> c >> d ;
        sum=b*d;
        if(sum<a*d) sum=a*d;
        if(sum<a*c) sum=a*c;
        if(sum<b*c) sum=b*c;
        cout << sum ;
    //t--;}
    quit;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <set>
using namespace std;
typedef long long int ll;

class UnionFind{
public:
	vector<int> par,num;

	int find(int v){
		return (par[v]==v)? v: (par[v]=find(par[v]));
	}
	explicit UnionFind(int N):par(N),num(N,1){
		iota(par.begin(),par.end(),0);
	}
	void unite(int u,int v){
		u=find(u),v=find(v);
		if(u==v)return ;
		if(num[u]<num[v])swap(u,v);
		num[u] += num[v];
		par[v] = u;
	}
	bool same(int u,int v){
		return find(u) == find(v);
	}
	bool ispar(int v){
		return v=find(v);
	}
	int size(int v){
		return num[find(v)];
	}
};

int main(){
	int n,m; cin >> n >> m;
	vector<int> v[m];
	for(int i=0;i<n;i++){
		int k; cin >> k;
		for(int j=0;j<k;j++){
			int l; cin >> l;
			v[l-1].push_back(i);
		}
	}
	UnionFind uf(n);
	for(int i=0;i<m;i++){
		for(int j=1;j<v[i].size();j++){
			uf.unite(v[i][0],v[i][j]);
		}
	}
	set<int> par;
	for(int i=0;i<n;i++){
		par.insert(uf.find(i));
	}
	if(par.size()==1){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
}

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

int main() {
	vector<string> day={"SUN","MON","TUE","WED","THU","FRI","SAT"};
	string s;
	cin>>s;
	rep(i,7){
		if(s==day[i]){
			cout<<7-i<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,tmp,s =0;
  scanf("%d" ,&n);
  tmp =n;
  while(tmp> 0){
    s += tmp%10;
    tmp /= 10;
  }
  if(n%s==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;
int f[1001000],X,Y;
long long ans,n;
char S[1001000];
map<int,int>mp;
signed main(){
	scanf("%lld%s",&n,S+1);
	X=1;
	int base=233,inv=7204522363551799129;
	for(int i=1;i<=n;i++){
		if(S[i]=='+')f[i]=f[i-1]+X;
		if(S[i]=='-')f[i]=f[i-1]-X;
		if(S[i]=='<')f[i]=f[i-1],X=X*base;
		if(S[i]=='>')f[i]=f[i-1],X=X*inv;
		mp[f[i]]++;		
	}
	X=1,Y=0;
	for(int i=1;i<=n;i++){
		ans=ans+mp[f[n]*X+Y];
		if(S[i]=='+')Y=Y+X;
		if(S[i]=='-')Y=Y-X;
		if(S[i]=='<')X=X*base;
		if(S[i]=='>')X=X*inv;
		mp[f[i]]--;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 37064