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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

int main(void)
{
    int N;
    cin >> N;
    ll result = 0;
    REP(i, N) {
        int a;
        cin >> a;
        while (a % 2 == 0) {
            ++result;
            a /= 2;
        }
    }
    cout << result << endl;
    return 0;
}


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

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

	int max = 0;
	map<string, int> m;
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		if (m.find(s) == m.end()) {
			m[s] = 1;
			if (max < 1) {
				max = 1;
			}
		}
		else {
			++m[s];
			if (max < m[s]) {
				max = m[s];
			}
		}
	}

	for (auto& i : m) {
		if (i.second == max) {
			cout << i.first << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 25216
#include <stdio.h>
#include <string.h>
 
int main(){
	
	char S[100];
	int k;
	scanf("%d", &k);
	scanf("%s", &S);
	for(int i = 0; i < strlen(S); i++){
	}
	if( k > 100 ||  k < 1){
		return 1;
	}
	if (k >= strlen(S)){
		printf("%s", S);
	}else if (k < strlen(S)){
		for( int i =0; i < k; i++){
			printf("%c", S[i]);
		}
		printf("...");
	}
	return 0;
}

Measured memory_bytes: 1736
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
#import copy
h,w = map(int, input().split())
s = []
cnt=0
for i in range(h):
    t = list(input().strip())
    cnt+=t.count('.')
    s.append(t)
#print(h,w,s)
def sol(h,w,s,start):
    import queue
    #import numpy as np
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    px=start[0]
    py=start[1]
    #sco=np.array([[-1 for _ in range(w)] for x in range(h)])
    sco = [[-1 for _ in range(w)] for x in range(h)]
    sco[py][px]=0
    a=queue.Queue()
    a.put([px, py])
    #print(sco)
    while not a.empty():
        px, py = a.get()
        if px==w-1 and py==h-1:
            #print(sco)
            #print(cnt,sco[py][px])
            return cnt-sco[h-1][w-1]-1
        for i in range(4):
            nx=px+dx[i]
            ny=py+dy[i]
            #print(nx,ny)
            if 0<=nx<w and 0<=ny<h and s[ny][nx]!="#" and sco[ny][nx]==-1:
                sco[ny][nx]=sco[py][px]+1
                a.put([nx,ny])
    return -1

print(sol(h,w,s,[0,0]))


Measured memory_bytes: 3952
fun main(args:Array<String>){
    val (k,x) = readLine()!!.split(" ").map{it.toInt()}
    var flg = true
    for(i in x - k + 1 .. x + k - 1){
        if(flg) print(i)
        else print(" " + i)
        flg = false
    }
    println()
}


Measured memory_bytes: 37640
#include <bits/stdc++.h>
	using namespace std;
	#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
	typedef long long ll;
	#define fi first
	#define se second
	#define sc scanf
	#define pr printf
	#define pb push_back
	const ll inf = 1e18;
	const int nax = 2e6 + 7;
	ll mod;
	int n , q;
	using namespace std;
	ll exp(ll a , ll b){
		if(b == 0)	return 1;
		int x = b % 2 == 0 ?   ((exp(a , b/2)%mod)*(exp(a , b / 2)%mod))%mod :  (a%mod*exp(a , b - 1) % mod)%mod;
		return x;
	}
	ll tree[nax];
	ll arr[nax];
	int marked[nax];
	void build(ll tl , ll tr , ll pos){
		if(tl == tr)
		{
			tree[pos] = arr[tl];
			return ;
		}
		ll mid = tl + (tr - tl)/2;
		build(tl , mid , 2 * pos);
		build(mid + 1 , tr , 2 * pos + 1);
		tree[pos] = min(tree[2*pos] , tree[2*pos+1]);
	}
	void update(ll l , ll r , ll val , ll tl , ll tr , ll pos){
		if(l > r)
			return ;
		if(tl == l && tr == r){
			tree[pos] = val;
			marked[pos] = 1;
			return ;
		}
		ll mid = tl + (tr - tl)/2;
		if(marked[pos]){
			tree[2 * pos] = tree[pos];
			tree[2*pos + 1] = tree[pos];
			marked[pos*2] = marked[pos*2 + 1] = 1;
			marked[pos] = 0;
		}
		update(l , min(r , mid),val ,  tl , mid , 2 * pos );
		update(max(l , mid + 1), r , val , mid + 1 , tr , 2 * pos + 1);
		tree[pos] = min(tree[2*pos] , tree[2*pos+1]);
	}
	ll query(ll l ,ll  r,  ll tl , ll tr , ll pos){
		if(l > r)	
			return inf;
		if(tl == l && tr == r)
			return tree[pos];
		ll mid = tl + (tr - tl)/2;
		if(marked[pos]){
			tree[2 * pos] = tree[pos];
			tree[2*pos + 1] = tree[pos];
			marked[pos*2] = marked[pos*2 + 1] = 1;
			marked[pos] = 0;	
		}
		return min(query(l , min(r , mid) , tl , mid , 2*pos) , query(max(l , mid + 1), r , mid + 1 , tr , 2*pos + 1));	
	}
	int main(int argc,char ** argv){
		dhoom;

		cin >> n >> q;
		ll x = pow(2LL , 31LL) - 1;
	//	cout << "HEY" << endl;
		//cout << x << endl;
		for(int i = 1 ; i <= n ; i++)
			arr[i] = x;
		//cout << "building" << endl;
		build(1 , n , 1);
		//cout << " hi " << endl;
		for(int i = 0 ; i < q ; i++){
			ll a , b , c , d;
			cin >> a;
			if(a == 0){
					cin >> b >> c >> d;
					update(b+1 , c+1 , d , 1 , n , 1);
			}
			else
			{
					cin >> b >> c;
					cout << query(b + 1,c + 1 , 1 , n , 1) << endl;
			}
		}
		return 0;
	}



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

ll num[60], numm[60];
ll solve(ll lev, ll pos)
{
    if (pos == 0)
        return 0;
    if (lev == 0)
        return 1;
    if (pos >= numm[lev - 1] + 2)
        return solve(lev - 1, pos - numm[lev - 1] - 2) + num[lev - 1] + 1;
    else
        return solve(lev - 1, pos - 1);
}

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

    ll n, x;
    cin >> n >> x;
    num[0] = 1;
    numm[0] = 1;
    REP(i, n, 1)
    {
        num[i] = 2 * num[i - 1] + 1;
        numm[i] = 2 * numm[i - 1] + 3;
    }
    cout << solve(n, x) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<algorithm>
#include<map>
#include<math.h>
using namespace std;

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    int num, tmp;
    num = 0;
    for (int i = 0; i < N; i++){
        map<char, int> c1, c2;
        tmp = 0;
        for (int j = 0; j < N; j++){
            if (j <= i)c1[S[j]] = 1;
            else c2[S[j]] = 1;
        }
        for (int k = 0; k < 26; k++){
            if (c1['a' + k] == 1 && c2['a' + k] == 1) tmp++;
            num = max(num, tmp);
        }
    }

    cout << num;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define int long long
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, A, B, C, D;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> A >> B >> C >> D;
  B -= A;
  N--;
  // 0 -(n)-> B
  for (int n=0; n<=N; n++) {
    long long lo = 1LL*(N-n)*C - 1LL*D*n,
              hi = 1LL*(N-n)*D - 1LL*C*n;
    if (lo <= B && B <= hi) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int A,B;
	char op;
	cin>>A>>op>>B;
	if((A>=1&&A<=10^9) &&(B>=1&&B<=10^9))
	if(op=='+')
	cout<<A+B;
	if(op=='-')
	cout<<A-B;
	
		return 0;
		
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
signed main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a<b&&c>b&&a<c){
    cout<<"Yes\n";
  }
  else{
    cout<<"No\n";
  }
  return(0);
}



Measured memory_bytes: 3076
#include <stdio.h>
int isprime(int n){
  for(int i = 2 ; i*i<=n ;i++){
    if(n%i==0)return 0;
}
 return 1;
}
int main(){
  int number[10000+2]={0};
  int n ,i , fir ,sec;
  for(i=2 ; i<10000 ;i++){
    number[i] = isprime(i);
  }
  while(scanf("%d" ,&n)){
    if(n==0)break;
    fir = 0 ,sec = 0;
    for(i=n ;i>3 ;i--){
      if(number[i] && number[i-2]){
        fir = i-2;
        sec = i;
        break;
      }
    }
    printf("%d %d\n" ,fir ,sec);
  }
  return 0;
}

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

int main(){
  int N; cin>>N;
  int cnt[9] = {};
  for(int i=0;i<N;i++){
    int a; cin>>a;
    a /= 400;
    if(a >= 8) a = 8;
    cnt[a]++;
  }
  int mn = 0;
  for(int i=0;i<=7;i++){
    if(cnt[i]) mn++;
  }
  int mx = 0;
  if(mn == 0){
    mn = 1;
    mx = cnt[8];
  }
  else mx = mn + cnt[8];
  cout<<mn<<" "<<mx<<endl;
  return 0;
}


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

using namespace std;

#define N 600000
#define ls (x<<1)
#define rs (x<<1|1)

int n,m,x,a[N],stk[N],f[N],L[N],R[N];
bool seg[N<<2];

void ins(int x,int y){
	if (!R[x]){R[x]=y; L[y]=x; return;}
	int z=R[x]; R[x]=y; L[z]=y; L[y]=x; R[y]=z;
}

void upd(int x){
	seg[x]=seg[ls]|seg[rs];
}

void clr(int x,int l,int r,int L,int R){
	if (!seg[x]||L>R) return;
	if (l==r){seg[x]=0; return;}
	int mid=(l+r)>>1;
	if (L<=mid) clr(ls,l,mid,L,R);
	if (R>mid) clr(rs,mid+1,r,L,R);
	upd(x);
}

void add(int x,int l,int r,int t){
	if (l==r){seg[x]=1; return;}
	int mid=(l+r)>>1;
	if (t<=mid) add(ls,l,mid,t);
	else add(rs,mid+1,r,t);
	upd(x);
}

int fd(int x,int l,int r,int R){
	if (!seg[x]) return 0;
	if (l==r) return l;
	int mid=(l+r)>>1,t=0;
	if (R>mid) t=fd(rs,mid+1,r,R);
	return t?t:fd(ls,l,mid,R);
}

int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i){scanf("%d",&x); a[x]=i;}
	add(1,0,n,0);
	for (int i=1;i<=n;++i){
		ins(fd(1,0,n,a[i]+m-1),a[i]);
		clr(1,0,n,a[i],a[i]+m-1);
		add(1,0,n,a[i]);
	}
	for (int i=R[0],j=1;j<=n;i=R[i],++j) f[i]=j;
	for (int i=1;i<=n;++i) printf("%d\n",f[i]);
	
	return 0;
}
			

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

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

    int cnt_max = 0;
    int cnt = 0;
    rep(i, n - 1) {
        if(h[i] >= h[i + 1])
            cnt++;
        else {
            cnt_max = max(cnt, cnt_max);
            cnt = 0;
        }
    }
    cnt_max = max(cnt, cnt_max);

    cout << cnt_max << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MAX_SIZE 200005
using namespace std;
int n;
char s[MAX_SIZE];
int jin[MAX_SIZE], dian[MAX_SIZE];
int main() {
	cin >> n; 
	for(int i = 1; i <= n; i++) {
		cin >> s[i];
		dian[i] = dian[i - 1];
		jin[i] = jin[i - 1];
		if(s[i] == '.') dian[i]++;
		else jin[i]++;
	}
	int minn = 1e9;
	for(int i = 0; i <= n; i++) {
		int left, right;
		left = jin[i];
		right = dian[n] - dian[i];
		minn = min(minn, left + right);
	}
	cout << minn << endl;
	return 0;
}

Measured memory_bytes: 2048
import math

a,b,c=map(int,input().split())

print(a*b*math.sin(math.radians(c))/2)

print((a**2+b**2-2*a*b*math.cos(math.radians(c)))**(1/2)+a+b)

print(a*b*math.sin(math.radians(c))/a)


Measured memory_bytes: 5712
X = int(input())
A = 1
while True:
    if X > A ** 5:
        S = X - A ** 5
        B = S ** (1 / 5) * (-1)
    else:
        S = A ** 5 - X
        B = S ** (1 / 5)
    if A ** 5 - int(B) ** 5 == X:
        break
    A += 1
print(A, int(B))


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

int main (){
    string S;
    int ans = 1;
    int temp = 0;
    cin >> S;
    
    if (S == "SSS")ans = 0;
    else if(S == "RRR")ans = 3;
    else if(S == "RRS" || S == "SRR")ans = 2;
    
    
    
    cout << ans << endl;

}

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

long gcd(long a, long b) {
	while (b) swap(a %= b, b);
	return a;
}
int main() {
	int x = 1;
	long a, b;
	cin >> a >> b;
	auto c = gcd(a, b);
	for (int p = 2; p <= c / p; p++) {
		if (c%p == 0) x++;
		while (c%p == 0) c /= p;
	}
	if (c > 1) x++;
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

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

	nums := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&nums[i])
	}

	var pre int
	cnts := make([]int, 0)
	cnti := 0
	for i := 0; i < n; i++ {
		if i == 0 {
			cnts = append(cnts, 0)
		}
		if i > 0 {
			if pre < nums[i] {
				pre = nums[i]
				cnts = append(cnts, 0)
				continue
			} else {
				cnti = len(cnts) - 1
				cnts[cnti]++
			}
		}
		pre = nums[i]
	}

	var max int
	for _, n := range cnts {
		if n > max {
			max = n
		}
	}

	fmt.Println(max)
}


Measured memory_bytes: 6400
//ABC131A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	string s;
	cin >> s;
	for(int i=1;i<s.size();i++){
		if(s.at(i-1) == s.at(i)){
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

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

    int N;
    cin >> N;
    vi a(N), b(N), A(N), B(N);
    rep(i, N)cin >> a[i];
    rep(i, N)cin >> b[i];

    int ans = 0;

    for (int i = 0; i < 29; ++i) {
        rep(j, N) {
            A[j] = a[j] % (1 << (i + 1));
            B[j] = b[j] % (1 << (i + 1));
        }
        sort(all(A));
        sort(all(B));
        int l = 0, r = 0, L = 0, R = 0;
        
        int bit = 0;
        for (int j = N - 1; j >= 0; --j) {
            while (l < N && A[j] + B[l] < (1ll << i))l++;
            while (r < N && A[j] + B[r] < 2*(1ll << i))r++;
            while (L < N && A[j] + B[L] < 3*(1ll << i))L++;
            while (R < N && A[j] + B[R] < 4*(1ll << i))R++;

            bit ^= (r - l + R - L) % 2;
        }
        if (bit)ans |= 1 << i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3456
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<29)
#define LLINF (1LL<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
typedef pair<int, int> P;

int main() {
    int k, n, a[200000];
    cin >> k >> n;
    for (int i = 0; i < n; i++)cin >> a[i];
    int MAX = 0;
    MAX = max(MAX, a[0] + k - a[n - 1]);
    for (int i = 1; i < n; i++)MAX = max(MAX, a[i] - a[i - 1]);
    cout << k - MAX;
    return 0;
}


Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

public class Main {
    static ArrayList<LinkedList<TupleInt>> graph;
    static int n;
    static int q, k;
    static long[] distances;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        graph = new ArrayList<>();
        for (int i = 0; i <= n; i++) {
            graph.add(new LinkedList<TupleInt>());
        }
        for (int i = 0; i < n - 1; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            graph.get(a).add(new TupleInt(b, c));
            graph.get(b).add(new TupleInt(a, c));
        }
        q = sc.nextInt();
        k = sc.nextInt();
        // distances from k
        distances = new long[n + 1];
        dfs();
        for (int i = 0; i < q; i++) {
            long dkx = distances[sc.nextInt()];
            long dky = distances[sc.nextInt()];
            System.out.println(dkx + dky);
        }
    }

    // distance from a to b
    static void dfs() {
        boolean[] visited = new boolean[n + 1];
        Stack<TupleLong> stack = new Stack<>();
        visited[k] = true;
        stack.push(new TupleLong(k, 0));
        while(!stack.isEmpty()) {
            TupleLong t = stack.pop();
            LinkedList<TupleInt> edges = graph.get(t.x);
            for (TupleInt edge : edges) {
                if (!visited[edge.x]) {
                    distances[edge.x] = t.y + edge.y;
                    visited[edge.x] = true;
                    stack.push(new TupleLong(edge.x, t.y + edge.y));
                }
            }
        }
    }

    static class TupleInt {
        final int x;
        final int y;
        TupleInt(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    static class TupleLong {
        final int x;
        final long y;
        TupleLong(int x, long y) {
            this.x = x;
            this.y = y;
        }
    }
}


Measured memory_bytes: 171652
#include<iostream>  
using namespace std;
int a[200005];
int main()
{
	int n, count1, count2;
	while (cin >> n)
	{
		int flag = 0;
		count1 = count2 = 0;
		for (int i = 0; i<n; i++)
		{
			cin >> a[i];
			if (a[i] % 4 == 0)
				count1++;
			if (a[i] % 2 != 0)
				count2++;
		}
		if (count2 == count1 + 1 && count2 + count1 == n)    
			flag = 1;
		if (count1 >= count2)      
			flag = 1;
		if (flag)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main() {
	int n, m, a, b, cnt[51] = {};
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		cnt[a]++;
		cnt[b]++;
	}
	for (int i = 1; i <= n; i++) {
		cout << cnt[i] << endl;
	}
	return 0;
}

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

using namespace std;

struct Test {
    int a, b, c, r;
    Test() {}
    Test(int aa, int bb, int cc, int rr) : a(aa), b(bb), c(cc), r(rr) {}
};

bool operator < (const Test &t1, const Test &t2) {
    return t1.r > t2.r;
}

int main() {
    while(true) {
        int a, b, c, n;
        cin >> a >> b >> c >> n;
        if(!a && !b && !c) break;

        vector<int> parts(a+b+c+1, 2);
        vector<Test> tests;

        while(n--) {
            int i, j, k, r;
            cin >> i >> j >> k >> r;
            tests.push_back(Test(i, j, k, r));
        }

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

        for(int i = 0; i < tests.size(); ++i) {
            int pa, pb, pc;
            pa = tests[i].a;
            pb = tests[i].b;
            pc = tests[i].c;
            if(tests[i].r == 1) {
                parts[tests[i].a] = parts[tests[i].b] = parts[tests[i].c] = 1;
            }
            else {
                int cnt = 0;
                if(parts[pa] == 1) ++cnt;
                if(parts[pb] == 1) ++cnt;
                if(parts[pc] == 1) ++cnt;
                if(cnt == 2) {
                    if(parts[pa] == 2) parts[pa] = 0;
                    if(parts[pb] == 2) parts[pb] = 0;
                    if(parts[pc] == 2) parts[pc] = 0;
                }
            }
        }

        for(int i = 1; i < parts.size(); ++i) {
            cout << parts[i] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main()
{
  int a,b,i,j;
  while(1)
       {
  scanf("%d%d",&a,&b);
  if(a==0&&b==0)
  break;
 
  for(i=1;i<=a;i++)
    {
      for(j=1;j<=b;j++)
    {
      if(j%2==1)
        {
          if(i%2==1)printf("#");
          else printf(".");
        }
      else
        {
              if(i%2==1)printf(".");
          else printf("#");
        }
    }
      printf("\n");
    }
  printf("\n");
     
       }
  return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

using namespace std;
const int MX = 1e6;
const int inf = 1e9;
//const int mod = 1e9+7;
using ll = long long;
const int mod = 1000000007;

signed main(){
    int a[5];
    rep(i,5) {
        cin >> a[i];
        if(a[i]==0) cout << i+1 << endl;
    }
    


    return 0;
}


Measured memory_bytes: 3560
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
  int n;
  cin>>n;
  int x0 = 0;
  int y0 = 0;
  int t0 = 0;
  bool flag = true;
  for(int i = 0; i < n; i++){
    int t,x,y;
    cin>>t>>x>>y;
    if(t-t0<abs(x0-x)+abs(y0-y)||(abs(x0-x)+abs(y0-y))%2!=(t-t0)%2){
      flag = false;
    }
    else{
      x0 = x;
      y0 = y;
      t0 = t;
    }
  }
  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}




Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <numeric>
#include <set>
#include <queue>
#include <vector>

using namespace std;

constexpr static int MOD = 998244353;
constexpr static int MAXN = 310;

int64_t dp[MAXN][MAXN][MAXN]; // [i][added][sum]

vector <int> get_cnt(const string& s) {
    vector <int> r;
    int prv = -1;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0') {
            r.push_back(i - prv - 1);
            prv = i;
        }
    }
    r.push_back(s.size() - prv - 1);
    return r;
}

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

    string s;
    int k;
    cin >> s >> k;

    vector <int> r = get_cnt(s);
    int n = r.size();
    /*
    cout << n;
    for (int i : r)
        cout << " " << i;
    cout << endl;
    */
    int rsum = accumulate(r.begin(), r.end(), 0);
    if (k > rsum)
        k = rsum;

    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= k; j++) {
            for (int l = 0; l <= j; l++) {
                // decrease r[i - 1] by m
                for (int m = 0; m <= r[i - 1] && l + m <= j; m++)
                    dp[i][j][l] += dp[i - 1][j][l + m];
                // increase r[i - 1] by m
                for (int m = 1; m <= j && m <= l; m++)
                    dp[i][j][l] += dp[i - 1][j - m][l - m];
                dp[i][j][l] %= MOD;
                // cout << i << " " << j << " " << l << " " << dp[i][j][l] << endl;
            }
        }
    }
    int64_t total = 0;
    for (int j = 0; j <= k; j++)
        total += dp[n][j][0];
    total %= MOD;
    cout << total << endl;
}


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

int main(){
    int n,k;
    string s;
    cin >> n >> s >> k;
    for(int i = 0 ; i < n ; ++i){
        if(s[i] != s[k-1])
            cout << '*';
        else
            cout << s[i];
    }
    cout << endl;

}

Measured memory_bytes: 256
N, T = map(int, raw_input().split())
n = []
t = []
for _ in range(N):
    x, y = map(int, raw_input().split())
    n.append(x)
    t.append(y)

if min(t) >= T:
    print 'TLE'
else:
    min_index = 1001
    for i in range(N):
        if n[i] < min_index and T >= t[i]:
            min_index = n[i]

    print min_index


Measured memory_bytes: 2568
#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;

int main()
{
  ll N;
  ll cnt(0);
  cin >> N;
  ll div;
  ll remain;
  
  for(int i=1; i < N ; ++i)
  {
  	if(N % i == 0)
    {
      cnt += N / i - 1;
    }
    else
    {
      cnt += N / i;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3632
def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    P = list(map(int, input().split()))

    ok = 1
    flg = 1
    pair = -1
    for i in range(N):
        if P[i] != i+1:
            if flg:
                if P[P[i]-1] == i+1:
                    flg = 0
                    pair = P[i]-1
                else:
                    ok = 0
                    break
            else:
                if i == pair:
                    continue
                ok = 0
                break

    if ok:
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
/*
        Author: Prokash
                CSE48, JU

*/

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

typedef long long ll;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int ara[2005];
int main()
{
    FAST;
    ll n,x;
    cin>>n>>x;
    vector<ll>cont,g;
   // ll mn=INT_MAX;
    ll ans=0;
    bool flag=true;
    while(n--)
    {
        ll in;
        cin>>in;
        cont.push_back(in);
    }
    cont.push_back(x);
    for(ll i=0;i+1<cont.size();i++)
    {
        g.push_back(abs(cont[i]-cont[i+1]));
    }
    ans=g[0];
    for(ll i=1;i<g.size();i++)
    {
        ans=__gcd(ans,g[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2548
N=int(input().strip())
D=[]
for i in range(N):
    d=list(map(int,input().strip().split()))
    D.append(d)

ans=0

for i in range(N-2):
    if D[i][0]==D[i][1] and D[i+1][0]==D[i+1][1] and D[i+2][0]==D[i+2][1]:
        ans+=1

if ans==0:
    print("No")

else:
    print("Yes")

Measured memory_bytes: 9172
#include <cstdio>

int main()
{
  int n;
  scanf("%d", &n);
  if (n == 1)
  {
    puts("Hello World");
  }
  else
  {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", a + b);
  }
  return 0;
}

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

int main() {
    int nums[5] = {};
    for(int i = 0; i < 5; i++) {
        cin >> nums[i];
    }

    int min_num = 10;
    int min_index = 10;

    for(int i = 0; i < 5; i++) {
        int num = nums[i] % 10;
        if(num && num < min_num) {
            min_num = num;
            min_index = i;
        }
    }

    int sum = 0;
    for(int i = 0; i < 5; i++) {
        if(i == min_index) {
            sum += nums[min_index];
        } else {
            sum += int(ceil(float(nums[i])/10)*10);
        }
    }

    cout << sum << endl;
}


Measured memory_bytes: 888
/*
  AtCoder Beginner Contest 090
  D - Remainder Reminder
*/

#include<iostream>
using namespace std;

long long N, K;

int main() {
  scanf("%d%d", &N, &K);

  long long cnt = 0;
  for (long long b = K + 1; b <= N; ++b) {
    long long n = N / b;
    long long k = N % b;

    cnt += n * (b - K);
    if (K <= k) cnt += k - K + 1;
    if (K == 0) cnt -= 1;
  }

  printf("%lld\n", cnt);
  return 0;
}

Measured memory_bytes: 256
n = int(input())
s = 0
a = 0
b = 0
c = 0
for i in range(n):
    bo = input()
    if bo[0]=='B' and bo[-1]=='A':
        s+=1
    elif bo[0]=='B':
        b+=1
    elif bo[-1]=='A':
        a+=1
    
    for i in range(len(bo)-1):
        if bo[i]=='A' and bo[i+1]=='B':
            c+=1

c+=min(a,b)
k = min(a,b)
a = a-k
b = b-k
if s!=0:
    s = s-1
    c+=s
    if a!=0 or b!=0 or k!=0:
        c+=1
    
print(c)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string n;
cin >> n;
string ans="No";
rep(i,3){
    if(n[i]=='7'){
        ans = "Yes";
    }
}
cout << ans << endl;
//system("pause");
return 0;
}


Measured memory_bytes: 3656
nf = int(input())
hf = list(map(int, input().split()))

h = [hf[0]]
for i in range(1, nf):
    if hf[i] == hf[i - 1]:
        continue
    else:
        h.append(hf[i])
n = len(h)

if n == 1:
    print('Yes')
elif n == 2:
    if h[1] - h[0] >= -1:
        print('Yes')
    else:
        print('No')
else:
    if h[1] - h[0] < -1:
        print('No')
    else:
        for i in range(1, n - 1):
            if h[i] <= h[i + 1]:
                continue
            elif h[i + 1] - h[i] == -1:
                if h[i] - h[i - 1] >= 1:
                    h[i] -= 1
                    continue
                else:
                    print('No')
                    break
            else:
                print('No')
                break
        else:
            print('Yes')

Measured memory_bytes: 90484
#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)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main()
{
  int n;
  cin >> n;
  int num = 0;
  rep(i, n) {
    int x;
    cin >> x;
    if (x!=i+1) num++;
  }
  if (num<=2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline
sys.setrecursionlimit(200010)
n = int(input())
info = [list(map(int, input().split())) for i in range(n)]

v = 100000
graph = [[] for i in range(v*2)]
for i in range(n):
    x = info[i][0] - 1
    y = (info[i][1] - 1) + v
    graph[x].append(y)
    graph[y].append(x)

def dfs(pos):
    if visited[pos]:
        return
    visited[pos] = True
    cnt[pos//v] += 1
    for i in graph[pos]:
        dfs(i)
    return

visited = [False] * (v*2)
cnt = [0]*2
ans = 0
for i in range(v*2):
    cnt[0] = 0
    cnt[1] = 0
    dfs(i)
    ans += cnt[0]*cnt[1]
print(ans - n)


Measured memory_bytes: 104908
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;

int main(){
    ll n,m,r; cin>>n>>m>>r;
    vector<ll> v(r);
    REP(i,r)cin>>v[i], v[i]--;
    vector<vector<ll>> g(n,vector<ll> (n, 10000000));
    REP(i,n)g[i][i]=0;
    REP(i,m){
        ll a,b,c; cin>>a>>b>>c;
        a--; b--;
        g[a][b]=c;
        g[b][a]=c;
    }
    REP(k,n)REP(i,n)REP(j,n){
        g[i][j]=min(g[i][j], g[i][k]+g[k][j]);
    }
    ll ans=1e16;
    sort(ALL(v));
    do {
        ll preans=0;
        FOR(i,1,r){
            preans+=g[v[i-1]][v[i]];
        }
        ans=min(preans, ans);
    }while(next_permutation(ALL(v)));
    cout<< ans <<endl;
    return 0;
}


Measured memory_bytes: 3912
#include<stdio.h>

int main(void){
    long k;
    int n;
    scanf("%ld %d",&k,&n);
    long a[n];
    for(int i = 0;i < n;i++)scanf("%ld",&a[i]);
    long dif[n];
    for(int i = 0;i < n-1;i++)dif[i] = a[i+1] - a[i];
    dif[n-1] = a[0] + k - a[n-1];
    long maxdif = 0;
    for(int i = 0;i < n;i++)maxdif = (maxdif>dif[i]?maxdif:dif[i]);
    printf("%ld",k-maxdif);
    return 0;
}

Measured memory_bytes: 3328
N,u,v=map(int, input().split())
G=[[] for _ in range(N)]

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



from collections import deque

q=deque([])
q.append((v-1,0))
done1=[-1]*N

while q:
    now, dist = q.popleft()
    done1[now]=dist
    for i in G[now]:
        if done1[i]!=-1:
            continue
        q.append((i,dist+1))

q=deque([])
q.append((u-1,0))
done2=[-1]*N

while q:
    now, dist = q.popleft()
    done2[now]=dist
    for i in G[now]:
        if done2[i]!=-1:
            continue
        q.append((i,dist+1))

goal=0
for i in range(N):
    if done1[i]>done2[i]:
        goal=max(goal, done1[i])

ans=goal-1
#print(goal, done1[u-1], done2[v-1])
#print(done1, done2)
print(ans)

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

int a[100000] = {0};

int main(void)
{
    int n;
    cin >> n;
    
    long long sum = 0;
    for (size_t i = 0; (i + 1)*2 < n; ++i)
    {
        cin >> a[i*2];
        sum += a[i*2];
        cin >> a[i*2 +1];
        sum -= a[i*2 +1];
    }

    cin >> a[n-1];
    sum += a[n-1];

    long x_i = ((long)sum) >> 1;
    for (size_t i = 0; i < n; i++)
    {
        cout << (x_i * 2) << " ";
        x_i = a[i] - x_i;
    }

    cout << endl; 
    return 0;   
}

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

struct UnionFind {
  int n;
  vector<int> par, depth;

  UnionFind(int n) {
    par.resize(n);
    depth.resize(n);
    rep(i, n) par[i]=i;
  }
  
  int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
  }
  
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return ;
    if (depth[x] < depth[y]) par[x] = y;
    else {
      par[y] = x;
      if (depth[x] == depth[y]) depth[x]++;
    }
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

int main() {
  int n,m; cin>>n>>m;
  vector<int> p(n);
  rep(i, n) {
    cin>>p[i];
    p[i]--;
  }
  UnionFind uf(n);
  rep(i, m) {
    int a,b; cin>>a>>b;
    a--; b--;
    uf.unite(a, b);
  }

  int ans=0;
  rep(i, n) ans+=uf.same(i, p[i]);
  cout<<ans<<endl;
}


Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    int cnt=0;
    int mcnt=0;
    for(int i=0;i<n-1;i++){
        if(h[i]<h[i+1]){
            if(cnt>mcnt){mcnt=cnt;}
            cnt=0;
        }
        else{cnt++;}
    }
    if(cnt>mcnt){mcnt=cnt;}
    cout<<mcnt<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <string>
#include <iostream>
#include <vector>

using namespace std;

bool is_prime(int n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: return true;
    } // n > 2 が保証された

    if(n%2 == 0) return false;

    // 上で i=2 相当は調べたので、i=3から奇数のみ調べる
    for(unsigned i=3;i*i<=n;i+=2){
        if(n%i == 0) return false;
    }

    return true;
}

int main(){
  int X;
  cin >> X;
  bool flag = true;
  
  while(flag){
    flag = !is_prime(X);
    X += 1;
  }
  
  cout << X-1 << endl;

  return 0;
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
    string A;
    cin >> A;

    ll a = A.size();

    ll ans = a * (a - 1) / 2 + 1;

    vector<int> c(30, 0);
    rep(i, a) {
        int j = A[i] - 'a';
        c[j]++;
    }

    for (int i : c) {
        ans -= (ll)i * (i - 1) / 2;
    }

    cout << ans << endl;
}

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


int main() {
  int N, S, sum, ans = 0;
  cin >> N;
  while (N > 0) {
    sum = 0;
    S = N;
    while (S > 0) {
      S /= 10;
      sum++;
    }
    if (sum % 2 == 1) {
      ans++;
    }
    N--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
K = int(input())

b = K % 50
a = K // 50
	
list = [0] * 50
j = 0

while (j <= 49 - b) :
	list[j] = 49 + a - b
	j += 1

while (j <= 49):
	list[j] = 2 * 50 + a - b
	j += 1

list = map(str, list)
print('50')
print(' '.join(list))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int a;
  cin >> a;
  for(int i = a; i >= 0; i--){
    int tmp = sqrt(i);
    if(tmp * tmp == i){
      cout << i << endl;
      return 0;
    }
  }
  
}


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

int dfs(const vector<vector<int>>& Graph, vector<int>& pre, vector<int>& low, int from, int to, int now) {
	int ans = 0;
	pre[to] = now;
	low[to] = now;
	for (int u : Graph[to]) {
		if (u == from) continue;
		if (pre[u] == -1) {
			ans += dfs(Graph, pre, low, to, u, now + 1);
			if (low[u] == pre[u]) ans++;
		}
		low[to] = min(low[to], low[u]);
	}
	return ans;
};

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> Graph(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		Graph[a - 1].push_back(b - 1);
		Graph[b - 1].push_back(a - 1);
	}
	vector<int> pre(N, -1), low(N, -1);
	cout << dfs(Graph, pre, low, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
# 2020/03/22
# AtCoder Beginner Contest 159 - D

# Input
n = int(input())
a = list(map(int,input().split()))
acntl = [0] * (n + 1)
anl = [0] * (n + 1)

# Count
for i in range(n):
    acntl[a[i]] = acntl[a[i]] + 1

# Calc Combination
for i in range(n + 1):
    anl[i] = acntl[i] * (acntl[i] - 1) // 2
    anl[0] = anl[0] + anl[i]

# Output
for i in range(n):
    ans = anl[0] - anl[a[i]] + ((acntl[a[i]] - 1) * max(0, acntl[a[i]] - 2)) // 2
    print(ans)


Measured memory_bytes: 26140
#include <bits/stdc++.h>
typedef long long ll;
#define vstroku() to_string()
#define vchislo() to_ulong()
#define gcd(x,y) __builtin_gcd(x,y)
#define numberof1(x) __builtin_popcount(x)
#define povsemelementam(i,mnozh) for(auto i: mnozh)
#define podotrezok(i,j) substr(i-1,j) // like prefix sum, (i,j)=s[j]-s[i-1]
#define pb push_back
#define pf push_front
#define popf pop_front
#define popb pop_back 
#define pii pair <int, int>
#define F first
#define S second
#define mipletsplay ios_base::sync_with_stdio(0); cin.tie(0); 


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 3e5;
const ll INF = 1e9;
const ll kek=998244353;

int main() {
mipletsplay;
int n;
cin>>n;
vector <int> p(n);
for (int i=0;i<n;i++)
cin>>p[i];
int cnt=0;
for (int i=1;i<n-1;i++)
{
if ((p[i]>=p[i-1]&&p[i]<=p[i+1])||(p[i]<=p[i-1]&&p[i]>=p[i+1]))    
cnt++;
}
cout<<cnt;}

Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

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

  if(a + b > c + d)cout << "Left";
  else if(a + b == c + d) cout << "Balanced";
  else cout << "Right";

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#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 rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 2e5+5;
int N, h[MAX], a[MAX];
ll b[MAX];

void update(int i, ll v) {
    for(; i <= N; i += i&-i)
        b[i] = max(b[i], v);
}

ll query(int i) {
    ll ans = 0;
    for(; i; i -= i&-i)
        ans = max(ans, b[i]);
    return ans;
}

int main(int argc, char ** argv) {
    scanf("%d", &N);
    REP(i, 1, N) scanf("%d", &h[i]);
    REP(i, 1, N) scanf("%d", &a[i]);
    REP(i, 1, N) update(h[i], query(h[i]-1)+a[i]);
    printf("%lld\n", query(N));
	return 0;
}


Measured memory_bytes: 3328
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


n = inp()
Alist = inpl()
Blist = inpl()
Clist = inpl()

ans = 0

for i in range(len(Alist)-1):
    if Alist[i+1] == Alist[i]+1:
        ans += Clist[Alist[i]-1]
ans += sum(Blist)

print(ans)

Measured memory_bytes: 12512
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    XYZ = [list(map(int, input().split())) for _ in range(n)]

    res = 0
    for pattern in product([0, 1], repeat=3):
        op = [1 if p == 0 else -1 for p in pattern]
        tmp = [0] * n
        for i in range(n):
            tmp[i] = sum([o * num for o, num in zip(op, XYZ[i])])
        tmp.sort(reverse=True)
        res = max(res, sum(tmp[:m]))
    print(res)


if __name__ == '__main__':
    resolve()


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> cnt(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        cnt[a]++, cnt[b]++;
    }
    rep(i, N) {
        if(cnt[i] % 2) {
            cout << "NO" << '\n';
            return 0;
        }
    }
    cout << "YES" << '\n';
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int x = scanner.nextInt();
		int y = scanner.nextInt();
		
		while (x != 0 || y != 0) {
			if (x > y) {
				int buf = x;
				x = y;
				y = buf;
			}
			
			System.out.println(x + " " + y);
			x = scanner.nextInt();
			y = scanner.nextInt();
		}
	}
}



Measured memory_bytes: 36728
#include<bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, ans;
long long gcd(long long a, long long b){
    if(a < b) swap(a,b);
    while(b){
        a %= b;
        swap(a,b);
    }
    return a;
}
int main(){
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    e = c*d/gcd(c,d); 
    a--;
    ans = b - (b/c + b/d - b/e) - (a - (a/c + a/d - a/e));
    printf("%lld\n", ans);
}

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

#define eb emplace_back

template<int SZ> struct Dinic{//SZ = N+1
	typedef int F;struct EDGE{int to,rev;F flow,cap;};
	int lev[SZ],n,s,t;vector<EDGE> E;vector<int> G[SZ];
	vector<int>::iterator cur[SZ];
	void addedge(int u,int v,F cap,bool GH=false){int id=E.size();
		E.eb((EDGE){v,id+1,0,cap});G[u].eb(id);//GH:Undirected
		E.eb((EDGE){u,id,0,GH?cap:0});G[v].eb(id+1);}
	bool bfs(){
		for(int i=0;i<=n;i++)lev[i]=-1;queue<int> q;q.push(s);lev[s]=0;
		while(!q.empty()){int u=q.front();q.pop();
			for(int i:G[u]){auto &e=E[i];int v=e.to;
				if(lev[v]<0&&e.flow<e.cap)    q.push(v),lev[v]=lev[u]+1;}
		}return lev[t]>=0;}
	F dfs(int u,F flow){
		if(u==t)	return flow;
		for(;cur[u]!=G[u].end();cur[u]++){auto &e=E[*cur[u]];int v=e.to;
			if(e.flow<e.cap&&lev[u]+1==lev[v]){
				F df=dfs(v,min(flow,e.cap-e.flow));
				if(df>0){e.flow+=df;E[e.rev].flow-=df;return df;}
			}}return 0;}
	F maxflow(int n_,int s_,int t_){
		n=n_;s=s_;t=t_;F flow=0;
		while(bfs()){
			for(int i=0;i<=n;i++)	cur[i]=G[i].begin();
			while(F df=dfs(s,numeric_limits<F>::max()))	flow+=df;
		}return flow;}
};

void fail(){
	cout<<"No\n";
	exit(0);
}
void ok(){
	cout<<"Yes\n";
	exit(0);
}

vector<int> e[100001];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	Dinic<100001> D;
	int n,m;
	cin>>n>>m;
	for(int i=1,u,v;i<=m;i++){
		cin>>u>>v;
		e[u].emplace_back(v);
		e[v].emplace_back(u);
		D.addedge(u,v,1,1);
	}
	for(int i=1;i<=n;i++)
		if(e[i].size()&1)
			fail();
	vector<int> d4;
	for(int i=1;i<=n;i++)
		if(e[i].size()>=6)
			ok();
	for(int i=1;i<=n;i++)
		if(e[i].size()==4)
			d4.emplace_back(i);
	if(d4.size()>=3)
		ok();
	else if(d4.size()==2){
		if(D.maxflow(n,d4[0],d4[1])==2)
			ok();
		else
			fail();
	}
	else
		fail();
}


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

#define NIL -1

typedef struct Node {
	int parent = NIL;
	int sibling = NIL;
	int left = NIL;
	int right = NIL;
	int degree = 0;
	int depth = 0;
	int height = 0;
	string type;
}tree;

int dphi(vector<tree>& t, int Id, int dep)
{
	int h1 = 0, h2 = 0, heig = 0;
	if (t[Id].left != NIL) h1 = dphi(t, t[Id].left, dep + 1) + 1;
	if (t[Id].right != NIL) h2 = dphi(t, t[Id].right, dep + 1) + 1;
	t[Id].depth = dep;
	heig = max(h1, h2);
	t[Id].height = heig;
	
	return heig;
}

void print(vector<tree>& t)
{
	for (int i = 0; i < t.size(); i++)
	{
		cout << "node " << i << ": parent = " << t[i].parent;
		cout << ", sibling = " << t[i].sibling << ", degree = " << t[i].degree;
		cout << ", depth = " << t[i].depth << ", height = " << t[i].height;
		cout << ", " << t[i].type << endl;
	}
}

int main(void)
{
	int N, i;
	cin >> N;
	vector<tree> t(N);

	for (i = 0; i < N; i++)
	{
		int Id = 0;
		cin >> Id;
		cin >> t[Id].left >> t[Id].right;

		if (t[Id].left != NIL)
		{
			t[t[Id].left].parent = Id;
			t[t[Id].left].sibling = t[Id].right;
			t[Id].degree++;
		}
		if (t[Id].right != NIL)
		{
			t[t[Id].right].parent = Id;
			t[t[Id].right].sibling = t[Id].left;
			t[Id].degree++;
		}

	}
	int root = NIL;
	for (i = 0; i < N; i++)
	{
		if (t[i].parent == NIL) {
			root = i;
			t[i].type = "root";
		}
		else if (t[i].left == NIL && t[i].right == NIL) {
			t[i].type = "leaf";
		}
		else {
			t[i].type = "internal node";
		}
	}

	dphi(t, root, 0);

	print(t);

	return 0;
}


Measured memory_bytes: 3188