akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

int main() {
    string S;
    int Q;
    int firstQuery, secondQuery;
    string thirdQuery;
    string First = "";
    string Last = "";
    cin>>S>>Q;
    bool reversing = false;
    REP(i, 0, Q){
        cin>>firstQuery;
        if(firstQuery == 1){//文字列反転
            reversing = !reversing;
        }else{//文字列追加
            cin>> secondQuery >> thirdQuery;
            if(secondQuery == 1){//通常時先頭に追加、反転時末尾に追加
                if(!reversing){
                    First = thirdQuery + First;
                } else {
                    Last.push_back(thirdQuery[0]);
                }
            }else{//通常時末尾に追加、反転時先頭に追加
                if(!reversing){
                    Last.push_back(thirdQuery[0]);
                }else{
                    First = thirdQuery + First;
                }
            }         
        }
    }
    if(reversing){
        reverse(S.begin(), S.end());
        reverse(First.begin(), First.end());
        reverse(Last.begin(), Last.end());
        S = Last + S + First;
    } else{
        S = First + S + Last;
    }
    cout << S << endl;
    
}

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

const int64_t MAXNODES = 100000;      // ノード数最大値
const int64_t INFTY = 1000000000;        // 辺の重みの最大値

typedef int Node;
struct WNode {
    Node node;
    int weight;
    WNode() {}
    WNode(Node n, int w) : node(n), weight(w) {}
    bool operator<(const WNode &n) const {
        return weight == n.weight ? node < n.node : weight > n.weight;
    }
    bool operator>(const WNode &e) const {
        return !(*this < e);
    }
};
struct Edge {
    Node from, to;
    Edge() {}
    Edge(Node f, Node t) : from(f), to(t) {}
    bool operator<(const Edge &e) const {
        return from == e.from ? to < e.to : from < e.from;
    }
    bool operator>(const Edge &e) const {
        return !(*this < e);
    }
};
struct WEdge {
    Edge edge;
    int weight;
    WEdge() {}
    WEdge(Node f, Node t, Node w = 0) : weight(w) {edge.from = f, edge.to = t;}
    WEdge(Edge e, int w) : weight(w) {edge = e;}
    bool operator<(const WEdge &e) const {
        return weight == e.weight ? edge > e.edge : weight > e.weight;
    }
    bool operator>(const WEdge &e) const {
        return !(*this < e);
    }
};

map<Node, vector<WEdge>> Edges;  // 隣接リスト
int64_t d[MAXNODES+1];                 // 各点における始点からの距離
bool check[MAXNODES+1];            // チェック済みかどうか判定
int n;                           // 頂点数

void dijkstra(Node p) {
    // 初期化
    for (int i = 1; i <= n; i++) {
        d[i] = INFTY * MAXNODES;
        check[i] = false;
    }
    d[p] = 0;
    priority_queue<WNode> que;
    WNode wn(p, d[p]);
    que.push(wn);

    int cnt = 0;
    while (cnt < n) {
        Node nd = que.top().node;
        que.pop();
        if (check[nd]) continue;
        for (auto &e : Edges[nd]) {
            Node to = e.edge.to;
            if (check[to]) continue;
            d[to] = min(d[to], d[nd] + e.weight);
            WNode wn(to, d[to]);
            que.push(wn);
        }
        check[nd] = true;
        cnt++;
    }
}

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

    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        WEdge e(u, v, w);
        Edges[u].push_back(e);
        WEdge e2(v, u, w);
        Edges[v].push_back(e2);
    }

    dijkstra(1);
    for (int i = 1; i <= n; i++) {
        cout << d[i] % 2 << endl;
    }

    return 0;
}


Measured memory_bytes: 13312
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)

	for sc.Scan() {
		s := strings.Split(sc.Text(), " ")
		a, _ := strconv.Atoi(s[0])
		op := s[1]
		b, _ := strconv.Atoi(s[2])

		switch op {
		case "+":
			fmt.Println(a + b)
		case "-":
			fmt.Println(a - b)
		case "*":
			fmt.Println(a * b)
		case "/":
			fmt.Println(a / b)
		case "?":
			return
		}
	}

}



Measured memory_bytes: 1096
def main():
    H, W = map( int, input().split())
    S = [ list( input()) for _ in range(H)]
    # if S[0][0] == "#":
    #     for i in range(H):
    #         for j in range(W):
    #             if S[i][j] == ".":
    #                 S[i][j] = "#"
    #             else:
    #                 S[i][j] = "."
    dp = [[10**5]*W for _ in range(H)]
    # if S[0][0] == "#":
    #     dp[0][0] = 1
    # else:
    #     dp[0][0] = 0
    dp[0][0] = 0
    for i in range(H):
        for j in range(W):
            if i > 0:
                if S[i-1][j] == S[i][j]:
                    if dp[i-1][j] < dp[i][j]:
                        dp[i][j] = dp[i-1][j]
                else:
                    if dp[i-1][j]+1 < dp[i][j]:
                        dp[i][j] = dp[i-1][j]+1
            if j > 0:
                if S[i][j-1] == S[i][j]:
                    if dp[i][j-1] < dp[i][j]:
                        dp[i][j] = dp[i][j-1]
                else:
                    if dp[i][j-1]+1 < dp[i][j]:
                        dp[i][j] = dp[i][j-1]+1
    #print(dp)
    ans = dp[H-1][W-1]
    ans //= 2
    if S[0][0] == "#" or S[H-1][W-1] == "#":
        ans += 1
    print(ans)
                
if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#import <bits/stdc++.h>
using namespace std;
 
int n;
int a[200005];
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	int tot = 0;
	for(int i = 0; i < n; i++) tot ^= a[i];
	for(int i = 0; i < n; i++) cout << (tot^a[i]) << " ";
	cout << endl;
}


Measured memory_bytes: 4396
using System;
public class Program {
  public static void Main(string[] args) {
    string[] tmp = Console.ReadLine().Split(' ');
    int A = int.Parse(tmp[0]);
    int B = int.Parse(tmp[1]);
    
    int max = A > B ? A : B;
    if(max*2 <= 16) {
      Console.WriteLine("Yay!");
    }
    else {
      Console.WriteLine(":(");
    }
  }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1; i < (n); i++)
using namespace std;
using ll = long long;
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int gcd_3(int x, int y, int z) {return gcd(gcd(x,y),z);}
int main(){
  int k;
  cin >> k;
  ll sum=0;
  rep(a,k+1){
    rep(b,k+1){
      rep(c,k+1){
          sum+= gcd_3(a,b,c);
      }
    }
  }
  cout << sum << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  string ans = "UNRESTORABLE";
  if(t.size() > s.size()) {
    ans = "UNRESTORABLE";
  } else {
    for(int i=0;i<s.size()-t.size()+1;i++) {
      bool match = true;
      string res = s;
      for(int j=0;j<t.size();j++) {
        if(s[i+j] != '?' && s[i+j] != t[j]) {
          match = false;
          break;
        }
        res[i+j] = t[j];
      }
      for(int k=0;k<res.size();k++) {
        if(res[k] == '?')
          res[k] = 'a';
      }
      if(match) {
        if(ans == "UNRESTORABLE")
          ans = res;
        else if(ans > res)
          ans = res;
      }
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    string a;
    cin>>a;
    if(a[0]==a[2])
        cout<<"Yes";
    else if(a[0]==a[1]==a[2])
        cout<<"Yes";
    else
        cout<<"No";





    return 0;
}

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

long long INF = 1e18;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b||b==c||c==a){
        if(a==b&&b==c&&c==a){
            cout <<"No"<< endl;
            return 0;
        }
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<double,int> P;

map<double,int> m;
int main() {
  int n;
  cin >> n;
  P a[n];
  for(int i=0; i<n; i++) {
    cin >> a[i].F;
    a[i].S=i;
    m[a[i].F]++;
  }
  sort(a,a+n);
  int d[n];
  memset(d,0,sizeof(d));
  int x=0;
  for(int i=0; i<n; i++) {
    if(i&&a[i-1].F!=a[i].F) x+=m[a[i-1].F];
    d[a[i].S]=x*3+m[a[i].F]-1;
  }
  for(int i=0; i<n; i++) cout << d[i] << endl;
  return 0;
}


Measured memory_bytes: 5260
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int n;
	cin>>n;
	ll l[n];
	rep(i,n){
		cin>>l[i];
	}
	int ans=0;
	sort(l,l+n);
	rep(i,n){
		REP(j,i+1,n){
			if(l[i]!=l[j]){
				REP(k,j+1,n){
					if(l[j]!=l[k]){
						if(l[i]+l[j]>l[k]){
							ans++;
						}
					}
				}
			}
		}
	}
	cout<<ans;
	re 0;
}

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

#define ll long long
#define M 1000000007
#define deb(x) cout<<#x<<" "<<x<<endl;
#define foi(a,b) for(int i=a;i<b;i++)
#define foj(a,b) for(int j=a;j<b;j++)
#define fod(a,b) for(int i=a;i>b;i--)
#define MAX  1e9
#define MIN -1e9
#define nl cout<<"\n";
#define show(arr,a,b) for(int i=a;i<b;i++) cout<<arr[i]<<" "; cout<<endl;
#define  mp(a,b) pair<ll,ll> p(a,b)
#define pb push_back
typedef pair<ll,ll> p1;
typedef vector<ll> vecd;
typedef vector<string> vecsd;
typedef map<ll,ll> mpd;
typedef set<ll> setd;
typedef multiset<ll> msetd;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n; cin>>n;
    ll arr[n];
    foi(0,n) cin>>arr[i];
    ll dp[n]={0};
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    foi(2,n){
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));        
    }
    cout<<dp[n-1]<<"\n";
    return 0;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  int X;
  cin >> X;
  cout << ((X==5 or X==7 or X==3)?"YES":"NO");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int m, d;
long long c, ac, cc;
int main(){
	scanf("%d", &m);
	rep(i,m){
		scanf("%d%lld", &d, &c);
		ac += c * d;
		cc += c;
	}
	printf("%lld\n", cc - 1 + (ac-1) / 9);
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
typedef pair<long, long> P;

int main(void){
    int a,p;
    cin >> a>>p;
    a *= 3;
    int sum = a+p;
    cout << sum/2<<endl;
    
}

Measured memory_bytes: 256
def main():
    import numpy as np
    K, N = map(int, input().split())
    # As = list(map(int, input().split()))
    As = np.array(list(map(int, input().split())))
    # As[-1] = K-As[-1]

    # print(As[1:]-As[:-1])
    new_A = As[1:]-As[:-1]
    # print(K-As[-1]+As[0])
    a = K-As[-1]+As[0]
    print(sum(new_A) + a - max(max(new_A), a))


if __name__ == '__main__':
    main()


Measured memory_bytes: 42772
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<LL,int> pii;
     
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=(int)(1e5)+5;
const LL INF=(LL)(1e18);
LL x[maxn],f[maxn];
bool ban[maxn];
priority_queue<pii,vector<pii>,greater<pii> > h[2];
int n,e,t;

// f[i] = x[i] + min{ f[j-1]-x[j-1]+t} t-2(x[i]-x[j])>=0

// f[i] = 3x[i] + min{ f[j-1]-x[j-1]-2x[j]} t-2(x[i]-x[j])<0

inline LL calc(int i,int ty) {
    if(ty==0) return f[i-1]-x[i-1]+t;
    else return f[i-1]-x[i-1]-2*x[i];
}

int main() {
    read(n);read(e);read(t);
    REP(i,1,n) read(x[i]);
    f[0]=0;x[0]=0;
    int ps=1;
    h[0].push(make_pair(calc(ps,0),ps));
    REP(i,1,n) {
        while(t-2*(x[i]-x[ps])<0) ban[ps]=1,h[1].push(make_pair(calc(ps,1),ps)),ps++;
        pii nowa=make_pair(INF,0),nowb=make_pair(INF,0);
        if(!h[0].empty()) nowa=h[0].top();
        while(!h[0].empty() && ban[nowa.second]) h[0].pop(),nowa=h[0].top();
        if(!h[1].empty()) nowb=h[1].top();
        f[i]=min(x[i]+nowa.first,3*x[i]+nowb.first);h[0].push(make_pair(calc(i+1,0),i+1));

    }
    printf("%lld\n",f[n]+e-x[n]);
    return 0;
}

Measured memory_bytes: 4468
// https://atcoder.jp/contests/abc064/tasks/abc064_d
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int N;
    string S;
    cin >> N >> S;
    int left = 0, x = 0;
    for (int i = 0; i < N; ++i)
    {
        if ('(' == S[i])
        {
            ++left;
        }
        else
        {
            if (left > 0) --left;
            else
            {
                ++x;
            }
            
        }
    }

    string ans;
    for (int i = 0; i < x; ++i)
    {
        ans.push_back('(');
    }
    ans.insert(ans.end(), S.begin(), S.end());
    for (int i = 0; i < left; ++i)
    {
        ans.push_back(')');
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;
using vvb=vector<vector<bool>>;
using vb= vector<bool>;
ll modpow(ll a,ll b,ll p){
	if(b==0) return 1;
	if(b%2==0){
		ll t=modpow(a,b/2,p);
		return t*t%p;
	}
	return a*(modpow(a,b-1,p))%p;
} 
//cout << fixed << setprecision(桁数);
//__builtin_popcount()
signed main(){
	ll n,k; cin>>n>>k;
	ll m=0;
	vl vec(n);
	rep(i,0,n){
		ll a; cin>>a;
		vec[i]=a;
		chmax(m,a);
	}
	ll l=0,r=m;
	while(r-l>1){
		ll mid=(l+r)/2;
		ll cnt=0;
		rep(i,0,n){
			cnt+=(vec[i]+mid-1)/mid-1;	
		}
		if(cnt<=k)r=mid;
		else l=mid;
	}
	cout<<r<<endl;
		
	return 0;
}


Measured memory_bytes: 4828
#include <iostream>

using namespace std;
 
int gcd(int x, int y)
{
	if (x % y == 0)
		return y;
	else
		return gcd(y, x % y);
}

int main()
{ 
	int a, b;

	while (cin >> a >> b)
	{
		int g = gcd(a, b);
		cout << g << " " << (a / g) * b << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func Max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func Min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

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

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()
	//連想配列
	L, R := make(map[int]int), make(map[int]int)

	for i := 0; i < N; i++ {
		tmp := nextInt()
		L[i-tmp]++
		R[i+tmp]++
	}

	//fmt.Println(L, R)
	ans := 0
	for k, v := range L {
		ans += R[k] * v
	}

	fmt.Println(ans)

}


Measured memory_bytes: 22492
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline-------------------------------------------
    N = int(input())
    d = list(map(int,input().split()))
    ans = 0
    for i in range(N):
        for j in range(i+1,N):
            ans += d[i]*d[j]
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 5680
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#include <set>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, n) cin >> l[i];

  sort(l.rbegin(), l.rend());
  int cnt = 0;
  rep(i, n) {
    for (int j = i + 1; j < n; ++j) {
      if (l[i] == l[j]) {
        continue;
      }
      for (int k = j + 1; k < n; ++k) {
        if (l[i] == l[k] || l[j] == l[k]) {
          continue;
        }
        if (l[i] < l[j] + l[k]) {
          cnt++;
        }
      }
    }
  }

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
bool di,p;
int n,ls,ans,x;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
    	scanf("%d",&x);
    	//printf("%d %d %d %d\n",x,ls,p,di);
    	if(i==1)
		{
			p=false;
			ls=x;
			ans++;
			continue;
		}
    	if(!p)
    	{
    		if(ls==x)continue;
    		else if(ls<x)
    		{
				p=true;
    			di=true;
    			ls=x;
			}
			else
			{
				p=true;
				di=false;
				ls=x;
			}
		}
		else
		{
			if(di)
			{
				if(x<ls)
				{
					p=false;
					ls=x;
					ans++;
					continue;
				}
				else
				{
					ls=x;
				}
			}	
			else
			{
				if(x>ls)
				{
					p=false;
					ls=x;
					ans++;
					continue;
				}
				else
				{
					ls=x;
				}
			}
		}
	}
	printf("%d",ans);
}


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

int main() {
    long n;
    cin >> n;
    long ans = n+1;
    for(long i=1; i*i<=n; i++){
        if(n%i==0){
            ans = min(ans, (n/i)+i-2);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
using namespace std;

int main() {
    char s[11], t[12];
    scanf("%s", s);
    scanf("%s", t);
    for (int i = 0; s[i] != '\0'; ++i) {
        if (s[i] != t[i]) {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 3700
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        c: String,
    }
    println!("{}", if c == 'a'.to_string()||c == 'e'.to_string() || c == 'i'.to_string() || c == 'o'.to_string() || c == 'u'.to_string() {"vowel"} else {"consonant"});
}


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

int main()
{

    int n, m;
    int ara[51] = {0};
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        ara[a]++;
        ara[b]++;
    }
    for(int i = 1; i <= n; i++)printf("%d\n", ara[i]);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
public static void main(String[] args) {

			Scanner keyboard = new Scanner(System.in);

			 int N = keyboard.nextInt();
			 int ans = 0;
			
			for (int a=1; a<=N; a++) {
				for(int b=1; b<=N; b++) {
					int B = gcd(a, b);
					for(int c=1; c<=N; c++) {
						int C =  gcd(B, c);
						ans += C;
					}
				}
			}			
		
		System.out.println(ans);
		keyboard.close();	
	}
	
	private static int gcd(int m, int n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
        }
}


Measured memory_bytes: 36056
import sys


n, Y = [int(_) for _ in input().split()]
x = -1
y = -1
z = -1
a = Y // 10000
for i in range(0, a+1):
    for j in range(0, n-i+1):
        if Y == 10000*i + 5000*j + 1000*(n-i-j):
            x = i
            y = j
            z = n-i-j
            print(x, y, z)
            sys.exit()
print(x, y, z)



Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String a = sc.next();
			String b = sc.next();
			String str = a + b;
			int num = Integer.parseInt(str);
			int sq = (int) Math.sqrt(num);
			if (sq * sq == num) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 39284
//bismillah....
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb2l(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
#define  mat vector<vector<ll>>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve(){
ll n;
cin>>n;
vll v(n);
ll avg=0;
fr(i,0,n)
cin>>v[i],avg+=v[i];
avg/=n;
ll avg2=avg+1;
ll avg3=avg-1;
ll ans1=0,ans2=0;
//avg=sqrt(avg);
ll ans=0;
fr(i,0,n){
    ll k=abs(avg-v[i]);
    k*=k;
    ans+=k;
    k=abs(avg2-v[i]);
    k*=k;
    ans1+=k;
    k=abs(avg3-v[i]);
    k*=k;
    ans2+=k;
}
cout<<min(ans,min(ans1,ans2));

}
int main(){
    ll t=1;
   // cin>>t;
    while(t--){
        solve();
        //cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
// Problem : F - Select Half
// Contest : AtCoder - AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

typedef long long ll;
const int INF=1<<30;

const int maxn=200000+10;
int a[maxn];
ll dp[maxn][3];

ll max(ll x,ll y,ll z){return max(max(x,y),z);}

int main()
{
	int n;cin>>n;
	rep(i,1,n) cin>>a[i];

	rep(i,0,n) rep(j,0,2) dp[i][j]=-(1ll<<60);
	dp[0][0]=0;
	dp[1][0]=a[1];
	dp[2][1]=a[2];
	dp[3][2]=a[3];
	rep(i,3,n){
		dp[i][0]=dp[i-2][0]+a[i];
		dp[i][1]=max(dp[i][1],dp[i-2][1]+a[i]);
		if(i>3) dp[i][1]=max(dp[i][1],dp[i-3][0]+a[i]);
		dp[i][2]=max(dp[i][2],dp[i-2][2]+a[i]);
		if(i>3) dp[i][2]=max(dp[i][2],dp[i-3][1]+a[i]);
		if(i>4) dp[i][2]=max(dp[i][2],dp[i-4][0]+a[i]);
	}
	if(n&1)cout<<max(dp[n-2][0],dp[n-1][1],dp[n][2])<<endl;
	else cout<<max(dp[n-1][0],dp[n][1])<<endl;
	// rep(j,0,2){
		// rep(i,1,n){
			// printf("%I64d%c",dp[i][j],i==n?'\n':' ');
		// }
	// }
	return 0;
}


Measured memory_bytes: 9064
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

vector<int> Z(string s) {
	vector<int> ret(s.size(), 0);
	ret[0] = s.size();
	int i = 1, j = 0;
	while (i < s.size()) {
		while (i + j < s.size() && s[j] == s[i + j]) { ++j; }
		ret[i] = j;
		if (j == 0) {
			++i;
			continue;
		}
		int k = 1;
		while (i + k < s.size() && k + ret[k] < j) {
			ret[i + k] = ret[k];
			++k;
		}
		i += k;
		j -= k;
	}
	return ret;
}

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

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		string t = s.substr(i, N);
		auto vec = Z(t);
		for (int j = 0; j < vec.size(); ++j) {
			if (vec[j] <= j) { ans = max(ans, vec[j]); }
		}
	}
	cout << ans << endl;

	return 0;
}


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

int main()
{
    int n, q;
    cin >> n;
    long long a[n];
    map<long long, long long> freq;
    long long sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
        if (freq.find(a[i]) == freq.end())
            freq.insert({a[i], 0});
        freq[a[i]]++;
    }

    cin >> q;
    for (int i = 0; i < q; i++)
    {
        long long b, c;
        cin >> b >> c;
        int num = freq[b];
        if (freq.find(c) == freq.end())
            freq.insert({c, 0});

        freq[c] += num;
        freq[b] = 0;

        sum = sum - num * b + num * c;
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 10144
class in{struct It{int it;const bool rev;explicit constexpr It(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(It& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const It i,n;public:explicit constexpr in(int n):i(0),n(n<0?0:n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const It& begin(){return i;}const It& end(){return n;}};

#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9;
vector<vector<int>> adj;
vector<int> num;
vector<pair<int, int>> range;
inline pair<int, int> upPair(const pair<int, int> p) { return make_pair(p.first - 1, p.second + 1);}
bool update(pair<int, int>& l, const pair<int, int>& r) {
    if(l.second < r.first || r.second < l.first) return false;
    bool ok = false;
    if(l.first <= r.first && r.second <= l.second) ok = true;
    if(r.first <= l.first && l.second <= r.second) ok = true;
    if(!ok) if((l.first & 1) == (r.first & 1)) ok = true;
    l.first = max(l.first, r.first);
    l.second = min(l.second, r.second);
    return ok;
}
bool dfs(int cur, int par) {
    auto& myRange = range[cur];
    if(num[cur] != INF) myRange = make_pair(num[cur], num[cur]);
    bool res = true;
    if(par != -1) res &= update(myRange, upPair(range[par]));
    pair<int, int> nRange = upPair(myRange);
    for(int nxt : adj[cur]) if(nxt != par) {
        res &= update(range[nxt], nRange);
        res &= dfs(nxt, cur);
        res &= update(myRange, upPair(range[nxt]));
    }
    return res;
}
void dfs2(int cur, int par) {
    if(num[cur] == INF) {
        num[cur] = range[cur].first;
    }
    pair<int, int> nRange = upPair(range[cur]);
    for(int nxt : adj[cur]) if(nxt != par) {
        update(range[nxt], nRange);
        dfs2(nxt, cur);
    }
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    adj.assign(n, vector<int>());
    for(int _ : in(n - 1)) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
    }
    num.assign(n, INF);
    int q;
    cin >> q;
    for(int _ : in(q)) {
        int v, p;
        cin >> v >> p;
        --v;
        num[v] = p;
    }
    range.assign(n, make_pair(-INF, INF));
    if(dfs(0, -1) == false) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes\n";
        dfs2(0, -1);
        for(int x : num) cout << x << '\n';
    }
    return 0;
}

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

constexpr int inf = 1001001001;
constexpr int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1};

int get_mandist(int val, int y, int x) {
    if (val == 0) return 0;
    else val--;
    return abs(y - val / 4) + abs(x - val % 4);
}

int get_sum_of_mandist(vector< vector< int > > vs) {
    int res = 0;
    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
            res += get_mandist(vs[i][j], i, j);
        }
    }

    return res;
}

inline bool is_inside(int y, int x) {
    return (0 <= y && y < 4) && (0 <= x && x < 4);
}

int cost_diff(const vector< vector< int > > &vs, int y, int x, int ny, int nx) {
    int now  = get_mandist(vs[y][x], y, x) + get_mandist(vs[ny][nx], ny, nx);
    int next = get_mandist(vs[y][x], ny, nx) + get_mandist(vs[ny][nx], y, x);

    return next - now;
}

int solve(vector< vector< int > > &vs, int y, int x) {
    struct data {
        int cost, score;
        int y, x;
        int pre;
        vector< vector< int > > vs;

        data() {}
        data(int cost, int score, vector< vector< int > > vs, int y, int x, int pre) : cost(cost), score(score), vs(vs), y(y), x(x), pre(pre) {}
    };

    auto c = [](const data &a, const data &b) { return a.cost > b.cost; };
    priority_queue< data, vector< data >, decltype(c)> pq{c};

    int res = 46;
    pq.emplace(get_sum_of_mandist(vs), 0, vs, y, x, -1);

    while (!pq.empty()) {
        auto p = pq.top();
        pq.pop();

        if (p.cost == 0) {
            res = min(res, p.score);
            continue;
        }

        if (res <= p.score + p.cost) {
            continue;
        }

        int y = p.y;
        int x = p.x;

        for (int i = 0; i < 4; ++i) {
            if (p.pre == i) continue;
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (!is_inside(ny, nx)) continue;

            swap(p.vs[y][x], p.vs[ny][nx]);
            int ncost = get_sum_of_mandist(p.vs);
            if (ncost + p.score + 1 < res) {
                pq.emplace(ncost, p.score + 1, p.vs, ny, nx, (i + 2) % 4);
            }
            swap(p.vs[y][x], p.vs[ny][nx]);
        }
    }

    return res;
}

int main() {
    int y, x;
    vector< vector< int > > vs(4);
    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
            int v;
            cin >> v;

            vs[i].emplace_back(v);

            if (v == 0) {
                y = i;
                x = j;
            }
        }
    }

    cout << solve(vs, y, x) << endl;;
}



Measured memory_bytes: 4828
// finish date: 2019/2/23

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;

//足し算
int add(int a, int b) {
    return (int) (((ll) a + b + bigmod) % bigmod);
}

int main() {
    int N;
    cin >> N;
    vvi a(N, vi(N));
    rep(i, N) rep(j, N) cin >> a[i][j];
    vvi dp(N, vi(1 << N, 0));

    rep(i, N) dp[0][1 << i] = a[0][i];
    vvi focus(N+1);
    rep(i, 1 << N) focus[__builtin_popcount(i)].push_back(i);


    rep(i, N - 1) {
        for(int j:focus[i+1]) {
            rep(k, N) {
                if (a[i + 1][k] && !(j & (1 << k))) {
                    dp[i + 1][j | (1 << k)] = (int) (((ll) dp[i + 1][j | (1 << k)] + dp[i][j] + bigmod) %
                                                     bigmod);//add(dp[i + 1][j | (1 << k)], dp[i][j]);
                }
            }
        }
    }
    cout << dp[N - 1][(1 << N) - 1] << endl;

    return 0;
}

Measured memory_bytes: 184828
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=3025;
const int inf=0x3f3f3f3f;
int n,m;
int w[maxn];
char str[maxn],str_[maxn];
ll l[maxn];
double dp[maxn][2*maxn];
double arr[maxn];
int main()
{
	int n;
	cin>>n;
    double ans=0;
    for(int i=1;i<=n;++i)
    cin>>arr[i];
    dp[1][3000+1]=arr[1];
	dp[1][3000-1]=1-arr[1];
    for(int i=2;i<=n;++i)
    {
        for(int j = 0;j<=3000+n;++j)
        {
            if(j)
			dp[i][j] += dp[i-1][j-1]*arr[i];
            dp[i][j] += dp[i-1][j+1]*(1-arr[i]);
        }
    }
    for(int i=3000+1;i<=3000+n;++i)
	ans+=dp[n][i];
    printf("%.9f\n",ans);
}



Measured memory_bytes: 144968
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main() {
    string S;
    cin >> S;
    int N = S.size();

    int i = 0;
    int ans = 0;
    while (i < N) {
        if (i == 0) {
            i++;
            continue;
        }
        if (S[i-1] != S[i]) {
            S = S.substr(0, i-1) + S.substr(i+1);
            N -= 2;
            i -= 1;
            ans += 2;
        } else {
            i++;
        }
    }
    printf("%d", ans);
}


Measured memory_bytes: 724
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a+b>c+d)
	{
		printf("Left");
		return 0;
	}
	if(a+b<c+d)
	{
		printf("Right");
		return 0;
	}
	if(a+b==c+d)
	{
		printf("Balanced");
		return 0;
	}
	return 0;
}

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

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

using namespace std;

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

    int A, B;
    cin >> A >> B;
    int cnt = 0;
    for (int i = A; i <= B; ++i) {
        if ((i / 10000 == i % 10) && ((i / 1000) % 10 == (i / 10) % 10)) ++cnt;
    }
    cout << cnt << '\n';
}

Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
  int n;
  string s;
  cin >> n >> s;
  string memo;
  int cnt = 1;
  memo = s.substr(0,1);
  rep(i,n-1){
    if(memo != s.substr(i+1,1)){
      cnt++;
      memo = s.substr(i+1,1);
    }
  }
  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,d,x,y,ans=0;
	scanf("%lld",&n);
	scanf("%d",&d);
	d*=d;
//	assert(n<=200000);
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&x,&y);
		ans+=(x*x+y*y<=d);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3796
N, L = list(map(int, input().split()))
stk = []
ans = []
for i in range(N):
  tmp = L + i
  stk.append(tmp)

for i in range(N):
  tmp1 = sum(stk)
  tmp = stk[i]
  stk[i] = 0
  tmp2 = sum(stk)
  stk[i] = tmp
  ans.append(abs(tmp1 - tmp2))

tmp = min(ans)

if tmp in stk:
  stk.remove(tmp)
  print(sum(stk))
else:
  stk.remove(-tmp)
  print(sum(stk))

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

int main() {
	string s;
	cin >> s;
	ll n = s.size();
	for (ll i = 0; i < n - 2; i++) {
		if (s[i] == s[i + 1] || s[i] == s[i + 2] || s[i + 1] == s[i + 2]) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	if (n == 2 && s[0] == s[1]) {
		cout << "1 2" << endl;
	} else {
		cout << "-1 -1" << endl;
	}
}

Measured memory_bytes: 3736
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m,p=map(int,input().split())
    E=[[] for _ in range(n)]
    R=[[] for _ in range(n)]
    edges=[]
    for _ in range(m):
        a,b,c=map(int,input().split())
        a-=1; b-=1
        E[a].append(b)
        R[b].append(a)
        edges.append((a,b,p-c))

    state=[0]*n

    def dfs(v):
        if(state[v]&1): return
        state[v]+=1
        for nv in E[v]: dfs(nv)
    dfs(0)

    def rdfs(v):
        if(state[v]&2): return
        state[v]+=2
        for nv in R[v]: rdfs(nv)
    rdfs(n-1)

    dist=[INF]*n
    dist[0]=0
    for k in range(n):
        for a,b,w in edges:
            if(state[a]!=3 or state[b]!=3): continue
            if(dist[b]>dist[a]+w):
                dist[b]=dist[a]+w
                if(k==n-1):
                    print(-1)
                    return
    print(max(-dist[-1],0))
resolve()

Measured memory_bytes: 61276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=0x3f3f3f3f;
const int N=2e5+20;
int mn[2][N][30],n,a[2][N],pos[N];
struct node{
    int x,l,r;
    bool operator<(const node &t)const{
        return x>t.x;
    }
};
void init(int v){
    for(int i=0;i<n;i++)	mn[v][i][0]=a[v][i];
    for(int j=1;(1<<j)<=n;j++)
        for(int i=0;(i+(1<<j)-1)<n;i++)
            mn[v][i][j]=min(mn[v][i][j-1],mn[v][i+(1<<(j-1))][j-1]);
}
int hp(int l,int r,int v){
    int k=0;
    while((1<<(k+1))<=r-l+1)	k++;
    return min(mn[v][l][k],mn[v][r-(1<<k)+1][k]);
}
int main(){
    int x;
	scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&x);
        pos[x]=i;a[i&1][i]=x;a[(i&1)^1][i]=inf;
    }
    init(0),init(1);
    priority_queue<node> q;
	x=hp(0,n-1,0);
	q.push({x,0,n-1});
    while(!q.empty()){
		node x=q.top();
    	q.pop();
        int v1=x.x,v2=hp(pos[x.x]+1,x.r,(pos[x.x]&1)^1);
        printf("%d %d ",v1,v2);
        v1=pos[v1],v2=pos[v2];
        if(x.l!=v1)	q.push({hp(x.l,v1-1,x.l&1),x.l,v1-1});
        if(v1+1!=v2)	q.push({hp(v1+1,v2-1,(v1+1)&1),v1+1,v2-1});
        if(v2!=x.r)	q.push({hp(v2+1,x.r,(v2+1)&1),v2+1,x.r});
    }
    return 0;
}

Measured memory_bytes: 51320
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> P;

int main() {
	int n, k; cin >> n >> k;
	vi a(30, 0);
	Loop(i, n) {
		string s; cin >> s;
		a[s[0] - 'A']++;
	}
	sort(a.begin(), a.end(), greater<int>());
	int ans = 0;
	while(1) {
		bool judge = true;
		Loop(i, k) {
			if (a[i] == 0) {
				judge = false;
				break;
			}
			else a[i]--;
		}
		if (!judge) break;
		ans++;
		sort(a.begin(), a.end(), greater<int>());
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        final int N = Integer.parseInt(sc.next());
        int ans = 0;
        int pre = N + 1;
        int[] ar = new int[N];
        for (int i = 0; i < N; i++) {
            ar[i] = N - i;
        }
        
        for (int i = 0; i < N; i++) {
            int p = Integer.parseInt(sc.next());
            if (p == 1) {
                ++ans;
                break;
            } else if (p <= ar[i] && p < pre) {
                ++ans;
                pre = p;
            }
        }
        
        out.println(ans);
        
        out.flush();
    }
}

Measured memory_bytes: 50944
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};


ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

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

int main(void){
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  ll XOR = 0;
  rep(i, N) XOR ^= A[i];
  set<ll> S;
  rep(i, N) S.insert((A[i] ^ (A[i] - 1)));
  //XORにA[i]をxorする
  int cnt = 0;
  for(int i = 30; i >= 0; i--){
    if((XOR >> i) & 1){
      if(S.count(pow_long(2, i+1)-1)){
        cnt++;
        XOR ^= pow_long(2, i+1)-1;
      }else{
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << cnt << endl;
}


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

#define int long long 

const int N = 1e5+10;
const int mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,d;
	cin >> n >> d;
	cout << (n-1)/(2*d + 1) + 1;
}



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

typedef pair<int, int> P;

int N, D, X[11][11];

int main(){
    cin >> N >> D;
    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++)    cin >> X[i][j];
    }

    vector<int> v;
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            int res = 0;
            for(int k=0;k<D;k++){
                res += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            v.push_back(res);
        }
    }

    int cnt = 0;
    for(int i=0;i<v.size();i++){
        for(int j=1;j*j<=v[i];j++){
            if((double)j == (double)v[i] / j){
                cnt++;
            }
        }
    }

    cout << cnt << endl;
}

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

int main() {
	char ch[27] = { 0 };
	cin >> ch ;


	int i = 0;
	while (ch[++i]) {
		for (int j = 0;ch[j] != '\0';j++) {
			if (i == j) continue;
			if (ch[i] == ch[j]) {
				cout << "no\n";
				return 0;
			}
		}
	}

	cout << "yes\n";

	return 0;
}

Measured memory_bytes: 256