akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int N = fs.nextInt();
        List<Integer> listA = new ArrayList<>();
        List<Integer> listB = new ArrayList<>();

        for (int i = 0; i < N; ++i) {
            listA.add((fs.nextInt()));
            listB.add((fs.nextInt()));
        }

        boolean flag = false;
        for (int i = 0; i <= N-3; ++i) {
            if (listA.get(i) == listB.get(i) && listA.get(i+1) == listB.get(i+1)
                    && listA.get(i+2) == listB.get(i+2)) {
                flag = true;
            }
        }

        if (flag) System.out.println("Yes");
        else System.out.println("No");


    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() { return Double.parseDouble(next());}
}




Measured memory_bytes: 32476
// slow 100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1e9+7;
const int E = 2.7e7;
int bo[E];
int main() {
	ll n;
	cin >> n;
	ll l = 1,r = 1;
	ll so = 0;
	bo[0] = 0;
	for(int i=1;i<E;i++) {
		bo[i] = bo[i/10]+1;
	}
	ll res = 0;
	for(;l<10000000;l++) {
		while(so < n) {so += bo[r];r++;
		}
		if(so == n) {res++;}
		so -= bo[l];
	}
	ll pot = 9e7;
	for(ll i=8;i<=n;i++) {
		ll se = (n/i) - n%i;
		if(!(n%i)) {
			res += pot-(n/i)+1;
			se -= i+1;
		}
		if(se > 0) {
			res += (se+i)/(i+1);
		}
		pot = pot*10%M;
	}
	res = ((res%M)+M)%M;
	cout << res << '\n';
}


Measured memory_bytes: 109056
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll b=0,s=0,n,c=0;
    cin>>n;
    ll a[n+10];
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i = n-1; i >= 0; i--)
    {
        if(c==0)
        {
            s += a[i];
            c=1;
        }
        else if(c==1)
        {
            b += a[i];
            c=0;
        }

    }
    cout<<s-b<<endl;

}


Measured memory_bytes: 256
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def read_floats():
    return list(map(float, input().strip().split(' ')))


def solve():
    """
    OPT[N][M] - from N coins having exactly M head
    OPT[N][M] = OPT[N-1][M]*(1-P[N])+OPT[N-1][M-1]*P[N]

    OPT[0][0] = 1
    OPT[i][0] = P[i]
    """
    N = read_int()
    P = read_floats()
    OPT = [
        [0]*(N+1) for _ in range(N+1)
    ]
    OPT[0][0] = 1
    for i in range(1, N+1):
        for j in range(N+1):
            OPT[i][j] = OPT[i-1][j]*(1-P[i-1])
            if j > 0:
                OPT[i][j] += OPT[i-1][j-1]*P[i-1]
    return sum(OPT[-1][(N+1)//2:])


if __name__ == '__main__':
    print(solve())


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

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; }

const long long INF = 1LL << 60;

int main() {
    int N;
    long long W, weight[110], value[110];
    long long dp[110][100100];

    cin >> N >> W;
    for (int i = 0; i < N; i++) {
        cin >> weight[i] >> value[i];
    }

    for (int i = 0; i < 110; i++) {
        for (int j = 0; j < 100100; j++) {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;
    for (int i = 0; i < N; i++) {
        for (int sum_v = 0; sum_v <= 100100; sum_v++) {
            if (sum_v - value[i] >= 0) {
                chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
            }
            chmin(dp[i + 1][sum_v], dp[i][sum_v]);
        }
    }

    long long res = 0;
    for (int sum_v = 0; sum_v < 100100; sum_v++) {
        if (dp[N][sum_v] <= W) res = sum_v;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 86400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;

bool pairCompare(const pair<int, int>& firstElof, const pair<int, int>& secondElof) {
    return firstElof.second > secondElof.second;
}

int main(void) {
    ll N, M;
    cin >> N >> M;

    vector<ll> A(N);
    for(int i=0;i<N;i++) {
        cin >> A.at(i);
    }

    vector<pair<ll, ll>> BC(M);
    ll b, c;
    for(ll i=0;i<M;i++) {
        cin >> BC.at(i).first >> BC.at(i).second;
    }

    sort(A.begin(), A.end());
    sort(BC.begin(), BC.end(), pairCompare);

    priority_queue<ll> Q;
    for(ll i=0;i<M;i++) {
        b = BC.at(i).first;
        c = BC.at(i).second;
        for(ll j=0;j<b;j++) {
            Q.push(c);
            if(Q.size()>N+2) break;
        }
    }

    ll i=0;
    while(!Q.empty() && i<N) {
        c = Q.top(); Q.pop();
        if(c>A.at(i)) { 
            A.at(i) = c;
            i++;
            continue;
        }
        else ;
    }

    ll ans = 0;
    for(int i=0;i<N;i++) {
        ans += A.at(i);
    }
    cout << ans << endl;

    return (0);
}


Measured memory_bytes: 4724
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>

using namespace std;

const int Maxn=60;

const long double g=9.8;
const long double eps= 1e-8;

int N; long double V,X,Y;

long double L[Maxn],B[Maxn],R[Maxn],T[Maxn];

long double Calcy(long double vy,long double t){return vy*t-0.5*g*t*t;}
long double Calcx(long double vx,long double t){return vx*t;}

int cmp(long double lb,long double ub,long double a)
{
  return a<lb+eps ? -1 : a>ub-eps ? 1 : 0;
}

bool Check(long double x,long double y) // ????????????(x,y) 
{
  long double a=0.25*g*g; long double b=g*y-V*V; long double c=x*x+y*y;
  long double delta= b*b-4*a*c;
  if(delta < 0 && delta > -eps) delta=0.0;
  else if(delta < 0) return 0;
  for(int op=-1;op<=1;op+=2)
  {
    long double t=sqrt((-b+sqrt(delta)*op)/(2.0*a));
    if(t<=0) continue;
    long double vx=x/t; long double vy=(y+0.5*g*t*t)/t; //?????????
    long double yt=Calcy(vy,X/vx); //???????¨?????????????
   	if(yt < Y-eps) continue;
   	bool ok=1;
   	for(int i=1;i<=N;i++)
   	{
   	  if(L[i] >= X) continue;
   	  if(R[i] == X && yt >= T[i] && B[i] >= Y){ok=0; break;}
   	  int yL=cmp(B[i],T[i],Calcy(vy,L[i]/vx));
   	  int yR=cmp(B[i],T[i],Calcy(vy,R[i]/vx));
   	  int xH=cmp(L[i],R[i],Calcx(vx,vy/g));
   	  int yH=cmp(B[i],T[i],Calcy(vy,vy/g));
   	  if( xH == 0 && yH >= 0 && yL<=0){ok=0; break;}
   	  if(yL * yR <=0){ok=0; break;}
   	}
   	if(ok) return 1;
  } 
  return 0;
}

int main()
{

  cin >> N >> V >> X >> Y;
  for(int i=1;i<=N;i++) cin >> L[i] >> B[i] >> R[i] >> T[i];

  for(int i=1;i<=N;i++) R[i]=min(R[i],X);

  bool ok=0;
  ok=Check(X,Y);

  for(int i=1;i<=N;i++) ok|=Check(L[i],T[i]);

  puts(ok ? "Yes" : "No");

  return 0;
}

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    import heapq
    mod=10**9+7
    N,M=MI()
    L=[[]for _ in range(M)]
    for i in range(N):
        #何日までに受ける必要があるかを気にしながら持つ
        a,b=MI()
        if a<=M:
            L[M-a].append(-b)
        
    ans=0
    hq=[]
    heapq.heapify(hq)
    
    for i in range(M-1,-1,-1):
        for bb in L[i]:
            heapq.heappush(hq,bb)
            
        if len(hq)!=0:
            temp=heapq.heappop(hq)
            ans+=-1*temp
        
    print(ans)
        
        

main()


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

int main(){
    int i,n;
    
    while (true)
    {
        cin>>i>>n;
        if ((i==0)&&(n==0))break;
        else {
            if(i>=n) cout<<n<<" "<<i<<endl;
            else cout<<i<<" "<<n<<endl;
        }
    }    
    return 0;
}


Measured memory_bytes: 3004
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
char s[N];int a[N],n,k;
int main(){
	scanf("%s%d",s+1,&k),n=strlen(s+1);
	fp(i,1,n)a[i]=(s[i]-'a');
	fp(i,1,n)if(a[i]&&k>=26-a[i])k-=26-a[i],s[i]='a';
	k%=26;
	s[n]+=k;
	printf("%s\n",s+1);
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin>>a>>b;
    cout << (max(a-2*b,0LL))<<endl;
    return 0;
}

Measured memory_bytes: 256
class Node:
  def __init__(self, num):
    self.key = num
    self.p = None
    self.left = None
    self.right = None

class BinarySearchTree:
  def __init__(self):
    self.root = None

  def insert(self, z):
    y = None
    x = self.root
    while x != None:
      y = x
      if z.key < x.key:
        x = x.left
      else:
        x = x.right
    z.p = y

    if y is None:
      self.root = z
    elif z.key < y.key:
      y.left = z
    else:
      y.right = z

def print_inorder(node):
  if node is None: return
  print_inorder(node.left)
  print(" {}".format(node.key), end="")
  print_inorder(node.right)

def print_preorder(node):
  if node is None: return
  print(" {}".format(node.key), end="")
  print_preorder(node.left)
  print_preorder(node.right)

def find(node, key):
  if node is None: return False
  if node.key == key: return True
  if key < node.key:
    return find(node.left, key)
  else:
    return find(node.right, key)

T = BinarySearchTree()
for i in range(int(input())):
  params = input().split()
  if params[0] == "insert":
    T.insert(Node(int(params[1])))
  if params[0] == "find":
    if find(T.root, int(params[1])):
      print("yes")
    else:
      print("no")
  if params[0] == "print":
    print_inorder(T.root)
    print("")
    print_preorder(T.root)
    print("")

Measured memory_bytes: 124492
n, m = map(int, input().split())
X = sorted([int(x) for x in input().split()])
Y = sorted([int(x) for x in input().split()])
mod = 1000000007

def diffSum(X): #Σ(X[j]-X[i]) 1<=i<j<=N
    l = len(X)
    Res = [(2*i-l+1)*X[i] for i in range(l)]
    return sum(Res)%mod

print(diffSum(X)*diffSum(Y)%mod)

Measured memory_bytes: 24456
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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 (b<a) { a=b; return 1; } return 0; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

int main() {
  SS(int,n)
  SV(ll,a,n)
  bool ok=true;
  for(ll i=n;i>0;i--)if(a[i-1]-1==a[i])a[i-1]-=1;
    rep(i,n-1)if(a[i]>a[i+1])ok=0;
    Yes(ok);
}


Measured memory_bytes: 1024
/**In the name of Allah, the Most Merciful, the Most Merciful.**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 9223372036854775806
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 2*acos(0.0)
#define EPS 1e-9
ll max(ll a,ll b) {if(a>b) return a; else return b;}
ll min(ll a,ll b) {if(a<b) return a; else return b;}

int main()
{
    string a,b;
    cin>>a>>b;
    int len=a.length();
    int cnt=0;
    for(int i=0;i<len;i++){
        if(a[i]!=b[i]) cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}




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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for(int i=0; i<N; i++) {
    cin >> v[i];
    v[i]--;
  }
  for(int i=0, next=v[0]; i<N; i++) {
    if(next==1) {
      cout << i+1 << endl;
      return 0;
    }
    next=v[next];
  }
  cout << -1 << endl;
}


Measured memory_bytes: 640
n, m = map(int, input().split())
l = [list(map(int,input().split())) for i in range(n)]

d = [0 for i in range(10**5)]

for i in range(n):
    d[l[i][0]-1] += l[i][1]

cnt = 0
for i in range(10**5):
    cnt += d[i]
    if cnt >= m:
        print(i+1)
        exit()

Measured memory_bytes: 30228
a, b = map(int, input().split())
ta = list(map(int, list(bin(a))[:1:-1]))
tb = list(map(int, list(bin(b))[:1:-1]))
S  = [0]*40
E  = [0]*40
for i in range(len(ta)):
    S[i]=ta[i]
for i in range(len(tb)):
    E[i]=tb[i]
sum=0
for i in range(1,40):
    odd =0
    sodd=0
    eodd=0
    m0=a%(2**(i+1))
    M0=b%(2**(i+1))
    m1=a//(2**(i+1))
    M1=b//(2**(i+1))
    if m1==M1:
        if(S[i]==0 and E[i]==1 and b%2==0):
            odd = 1
        elif(S[i]==1 and (b-a)%2==0):
            odd = 1
    else:
        if(S[i]==0 and E[i]==1 and b%2==0):
            odd = 1
        elif(S[i]==1 and E[i]==0 and a%2==1):
            odd = 1
        elif(S[i]==1 and E[i]==1):
            sodd = 1 if (a%2==1) else 0
            modd = 1 if (b%2==0) else 0
            odd = sodd^modd
    sum+=(2**i)*odd

if((a//4)!=(b//4)):
    if(a%4>1 and (b%4==0 or b%4==3)):
        sum+=1
    elif(a%4<=1 and (b%4==1 or b%4==2)):
        sum+=1
else:
    if((b-a)==1 or ((b-a)==2 and a%2==0)):
        sum+=1

print(sum)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int n,W,f[200010];
int main(){
	int x,y; 
	scanf("%d %d",&n,&W);
	for(int i=1;i<=200000;i++) f[i]=1e9+10;
	for(int i=1;i<=n;i++){
		scanf("%d %d",&x,&y);
		for(int i=200000;i>=y;i--){
			f[i]=min(f[i],f[i-y]+x);
		}
	}
	for(int i=200000;i>=0;i--){
		if(W>=f[i]){
			printf("%d",i);
			return 0;
		}
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()

const int x[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int y[] = {-1, 0, 1, -1, 1, -1, 0, 1};

int dfs(int i, int j, vector<vector<int> >& graph, vector<vector<int> >& visit, const int h, const int w){
    if(visit[i][j] == 1 || graph[i][j] == 0){
        return 0;
    }
    visit[i][j] = 1;
    rep(k, 8){
        int di = i + x[k];
        int dj = j + y[k];
        if(di < 0 || dj < 0 || di >= h || dj >= w){
            continue;
        }
        if(visit[di][dj] == 1){
            continue;
        }
        dfs(di, dj, graph, visit, h, w);
    }
    return 1;
}

int main() {

    while(true){
        int w, h;
        cin >> w >> h;
        if(w == 0 && h == 0){
            break;
        }
        vector<vector<int> > graph(h, vector<int>(w)); 
        rep(i, h){
            rep(j, w){
                cin >> graph[i][j];
            }
        }
        vector<vector<int> > visit(h, vector<int>(w));
        int ans = 0;
        rep(i, h){
            rep(j, w){
                ans += dfs(i, j, graph, visit, h, w);
            }
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3268
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<vector>
#define ll long long
using namespace std;
const int wa=1e9+7;
int N, a[100];
int main(void) {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 1; i < N; i++) {
		for (int i = 0; i < N; i++) {
			cout << a[i];
			if(i != N - 1)cout<< " ";
		}
		cout << endl;
		int v = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
			a[j + 1] = v;
		}

	}
	for (int i = 0; i < N; i++) {
		cout << a[i];
		if(i!=N-1)cout<<" ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0); 
	int N; long long K; cin >> N >> K;
	int A[200010] = {};  
	int D[64][200010] = {}; 
	for(int i = 0; i < N; i++){
		cin >> A[i]; A[i] --; 
		D[0][i] = A[i]; 
	}
	for(int i = 1; i <= 62; i++){
		for(int j = 0; j < N; j++){
			D[i][j] = D[i-1][D[i-1][j]]; 
		}
	}
	int ans = 0; 
	for(int i = 0; i <= 60; i++){
		if((K >> i) & 1){
			ans = D[i][ans]; 
		}
	}
	cout << ans + 1 << endl; 
}

Measured memory_bytes: 54440
main = do
    (a : b : c : d : _) <- getLine
    let x = read [a, b] :: Int
    let y = read [c, d] :: Int
    putStrLn $ solve x y

solve x y
    | 1 <= x && x <= 12 && 1 <= y && y <= 12 = "AMBIGUOUS"
    | 1 <= x && x <= 12 = "MMYY"
    | 1 <= y && y <= 12 = "YYMM"
    | otherwise = "NA"

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


int main() {
  int N,M;
  cin >> N >> M;
  vector<int> A(M);
  
  for(int i=0;i<M;i++){
    cin >> A.at(i);
  }

  int vac = 0;
  for(int i=0;i<M;i++){
    vac += A.at(i);
  }

  if(vac > N){
    cout << -1 << endl;
  }else{
    cout << N - vac << endl;
  }



  

}

  


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int i,j;
	int h,w;
	cin>>h>>w;
	VVI a(h,VI(w,inf));
	VVI b(h,VI(w,inf));
	VVI s(h,VI(w,0));
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			char c;
			cin>>c;
			if(c=='#') s[i][j]=1;
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(i==0&&j==0){
				if(s[i][j]==0) a[i][j]=0;
				else b[i][j]=1;
			}
			else if(i==0){
				if(s[i][j-1]==1&&s[i][j]==0) a[i][j]=b[i][j-1];
				if(s[i][j-1]==0&&s[i][j]==0) a[i][j]=a[i][j-1];
				if(s[i][j-1]==0&&s[i][j]==1) b[i][j]=a[i][j-1]+1;
				if(s[i][j-1]==1&&s[i][j]==1) b[i][j]=b[i][j-1];
			}
			else if(j==0){
				if(s[i-1][j]==1&&s[i][j]==0) a[i][j]=b[i-1][j];
				if(s[i-1][j]==0&&s[i][j]==0) a[i][j]=a[i-1][j];
				if(s[i-1][j]==0&&s[i][j]==1) b[i][j]=a[i-1][j]+1;
				if(s[i-1][j]==1&&s[i][j]==1) b[i][j]=b[i-1][j];
			}
			else {
				if(s[i-1][j]==1&&s[i][j]==0) chmin(a[i][j],b[i-1][j]);
				if(s[i-1][j]==0&&s[i][j]==0) chmin(a[i][j],a[i-1][j]);
				if(s[i-1][j]==0&&s[i][j]==1) chmin(b[i][j],a[i-1][j]+1);
				if(s[i-1][j]==1&&s[i][j]==1) chmin(b[i][j],b[i-1][j]);

				if(s[i][j-1]==1&&s[i][j]==0) chmin(a[i][j],b[i][j-1]);
				if(s[i][j-1]==0&&s[i][j]==0) chmin(a[i][j],a[i][j-1]);
				if(s[i][j-1]==0&&s[i][j]==1) chmin(b[i][j],a[i][j-1]+1);
				if(s[i][j-1]==1&&s[i][j]==1) chmin(b[i][j],b[i][j-1]);
			}
            //cout<<a[i][j]<<" "<<b[i][j]<<endl;
		}
        //cout<<endl;
        
	}
	cout<<min(a[h-1][w-1],b[h-1][w-1])<<endl;

}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvii = vector<vector<int> >;
using vvll =  vector<vector<ll> >;

const ll inf = 1LL << 60;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int l,r,d;cin>>l>>r>>d;
    int mini = (l+d-1) / d;
    int maxi = r/d;
    cout << maxi - mini + 1 << endl;
}

Measured memory_bytes: 3596
N=int(input())
H=list(map(int,input().strip().split()))

cnt=0
maxcnt=0
for n in range(N-1):
    if H[n]>=H[n+1]:
        cnt+=1
    else:
        maxcnt=max(maxcnt,cnt)
        cnt=0
if cnt!=0:
    maxcnt=max(maxcnt,cnt)
print(maxcnt)

Measured memory_bytes: 20504
def floor_sum(n, m, a, b):
    ans = 0
    if a >= m:
        ans += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        ans += n * (b // n)
        b %= m
    y_max = (a * n + b) // m
    x_max = y_max * m - b
    if y_max == 0: return ans
    ans += (n - (x_max + a - 1) // a) * y_max
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return ans

for _ in range(int(input())):
    n, m, a, b = map(int, input().split())
    print(floor_sum(n, m, a, b))

Measured memory_bytes: 9188
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N; cin >> N;
    vector<int> H;
    rep (i, 0, N) {
        int in; cin >> in;
        H.push_back(in);
    }

    int ans = 1, tmp_max = H[0];
    for (int i = 1; i < H.size(); ++i) {
        if (H[i] >= tmp_max) ++ans;
        tmp_max = max(tmp_max, H[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] n = in.nextString().toCharArray();
			int count = 0;
			for (int i = 0; i < n.length - 1; i++) {
				if (n[i] == n[i+1]) {
					count++;
					if (count == 2) {
						System.out.println("Yes");
						return;
					}
				} else {
					count = 0;
				}
			}
			System.out.println("No");
		}
	}

	static class ArrayUtils {
		public static Map<Integer, Integer> getCountMap(int[] array) {
			Map<Integer, Integer> map = new TreeMap<>();
			for (int x : array)
				map.merge(x, 1, Integer::sum);
			return map;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  
  cin >> N;
  
  if ((N%10==N/10%10 && N/10%10==N/100%10) || (N/10%10==N/100%10 && N/100%10==N/1000%10)) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }  
}

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

fct = {}

for i in range(2,int(m**(1/2))+10):
    if m%i==0:##合成数で割れることはない
        fct[i]=1
        m//=i
        while m%i==0:
            fct[i]+=1
            m//=i
if m>1:
    fct[m]=1
mod = 10**9+7
def h(a,b):
    res = 1
    for i in range(a+b-1,a-1,-1):
        res *= i
        res %= mod
    for i in range(1,b+1):
        res *= pow(i,mod-2,mod)
        res %= mod
    return res
ans = 1
for p in fct:
    ans *= h(n,fct[p])
    ans%=mod
print(ans)


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

int main() {
	int N , K;
  	cin >> N >> K;
  	int x;
  	int total = 0;
  	for(int i = 0; i < N; i++){
    	cin >> x;
      	if(2 * x < (K - x) * 2){
        	total += 2 * x;
        }else{
        	total += (K - x) * 2;
        }
    }
  	cout << total << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int read();
void chmin(int &x, int y) { x > y ? x = y : x; }

int n;
queue<int> q;
int vis[102];
struct Graph {
    int hd[102], nx[202], to[202], deg[202], cnt;
    void init() {
        cnt = 0;
        for (int i = 1; i <= n; ++i) hd[i] = deg[i] = 0;
    }
    void add(int f, int t) {
        nx[++cnt] = hd[f], hd[f] = cnt, ++deg[to[cnt] = t];
    }
    int fa[102];
    void getfa(int u) {
        for (int i = hd[u], v; i; i = nx[i])
            if ((v = to[i]) != fa[u]) fa[v] = u, getfa(v);
    }
    int topo() {
        int rt = 0;
        for (int i = 1; i <= n; ++i)
            if (vis[i] && !deg[i]) ++rt, q.push(i);
        while (!q.empty()) {
            int u = q.front();
            q.pop();
            for (int i = hd[u], v; i; i = nx[i])
                if (!(--deg[v = to[i]])) ++rt, q.push(v);
        }
        return rt;
    }
} A, B, G;

int res;
int work() {
    int rt = 0;
    for (int i = 1; i <= n; ++i) rt += (vis[i] = A.fa[i] != B.fa[i]);
    if (rt >= res) return n + 1;
    G.init();
    for (int i = 1; i <= n; ++i) {
        if (!vis[i]) {
            if (vis[A.fa[i]]) return n + 1;
            continue;
        }
        if (vis[A.fa[i]]) G.add(i, A.fa[i]);
        if (vis[B.fa[i]]) G.add(B.fa[i], i);
    }
    return G.topo() == rt ? rt : n + 1;
}

int main() {
    int T = read();
    while (T--) {
        res = (n = read()) + 1, A.init(), B.init();
        for (int i = 1, u, v; i < n; ++i)
            u = read(), v = read(), A.add(u, v), A.add(v, u);
        for (int i = 1, u, v; i < n; ++i)
            u = read(), v = read(), B.add(u, v), B.add(v, u);
        for (int i = 1; i <= n; ++i) {
            A.fa[i] = B.fa[i] = 0, A.getfa(i), B.getfa(i), chmin(res, work());
            if (A.deg[i] == 1)
                for (int j = 1; j <= n; ++j)
                    if (i != j) {
                        A.fa[j] = i, A.getfa(j), B.getfa(i);
                        A.fa[i] = B.fa[i] = 0, chmin(res, work() + 1);
                    }
        }
        printf("%d\n", res > n ? -1 : res);
    }
    return 0;
}
const int _SIZE = 1 << 22;
char ibuf[_SIZE], *iS = ibuf, *iT = ibuf;
#define gc                                                         \
    (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)), \
     (iS == iT ? EOF : *iS++) : *iS++)
int read() {
    int x = 0, f = 1;
    char c = gc;
    while (!isdigit(c)) f = (c == '-') ? -1 : f, c = gc;
    while (isdigit(c)) x = x * 10 + c - '0', c = gc;
    return x * f;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;
constexpr ll inf = 2e18;

inline auto f (ll n) -> ll
{
  return n < 2 ? 1 : n * f (n - 2);
}

inline auto count_trail_zero(ll n)
{
  stringstream ss;
  ss << f (n);
  auto s = ss.str ();
  size_t cnt = 0;
  FOR (ite, s.rbegin (), s.rend ())
  {
    if (* ite == '0') ++ cnt;
    else break;
  }
  return cnt;
}


inline auto solve (ll n) -> ll
{
  if (n == 0) return 0;
  if (n % 2 == 1) return 0;

  ll res = 0;
  for (ll i = 10; i <= 1e18; i *= 5)
  {
    res += n / i;
  }
  return res;
}


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

  ll n;
  cin >> n;

  cout << solve (n) << endl;
#ifdef DEBUG
  FOR (i, ll {}, 30)
  {
    cerr << "test: " << i << endl;
    auto expected = count_trail_zero (i);
    auto actual = solve (i);
    cerr << "  expect: " << expected << endl;
    cerr << "  actually: " << actual << endl;
    assert (expected == actual);
  }
#endif
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int n;
double x1,x2,x3,x4,ya1,y2,y3,y4;

int main() {
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> x1 >> ya1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		
		if (x1 > x2) {
			double tmp = x1;
			x1 = x2;
			x2 = tmp;
			tmp = ya1;
			ya1 = y2;
			y2 = tmp;
		}
		if (x3 > x4) {
			double tmp = x3;
			x3 = x4;
			x4 = tmp;
			tmp = y3;
			y3 = y4;
			y4 = tmp;
		}
		

		if (x1 == x2) {
			if (x3 == x4) cout << "YES" << endl;
			else cout << "NO" << endl;
		} else {
			if (x3 == x4) cout << "NO" << endl;
			else {
				if (abs((y2 - ya1) / (x2 - x1) - (y4 - y3) / (x4 - x3)) <= 0.00000000001)
					cout << "YES" << endl;
				else cout << "NO" << endl;
			}
		}
	}

	return 0;
}

/*@@@@@@@@@@@@@@@@@@@@@@@@@*/
/*@                       @*/
/*@ debug output erased ? @*/
/*@                       @*/
/*@@@@@@@@@@@@@@@@@@@@@@@@@*/

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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

int N, M, Q;
int a[50][4];

void solve() {
    cin >> N >> M >> Q;
    // cout << "Q: " << Q << "\n";
    for (int i = 0; i < Q; i++) {
        for (int j = 0; j < 4; j++) {
            cin >> a[i][j];
        }
        a[i][0]--; a[i][1]--;
    }
    
    string perm = string(N, 'o') + string(M - 1, 'x');
    int ans = 0;
    do {
        vector<int> arr(N);
        int cur = 0, pos = 0;
        for (char c : perm) {
            if (c == 'o'){
                arr[pos++] = cur;
            } else {
                cur++;
            }
        }
        int score = 0;
        for (int i = 0; i < Q; i++) {
            if (arr[a[i][1]] - arr[a[i][0]] == a[i][2]) {
                score += a[i][3];
            }
        }
        
        chmax(ans, score); 
    } while (next_permutation(perm.begin(), perm.end()));
    cout << ans;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 3624
N, Q = map(int, input().split())
S = input()
flag = True
R = [0]*N
a = 0
for i in range(N):
    s = S[i]
    if s == "A":
        flag = True
    elif s == "C" and flag:
        a += 1
        flag = False
    else:
        flag = False
    R[i] = a
for i in range(Q):
    l, r = map(int, input().split())
    print(R[r-1] - R[l-1])


Measured memory_bytes: 6108
#include<bits/stdc++.h>
using namespace std;
const long long maxn=2e5+5;
const long long inf=0x3f3f3f3f;
long long ans,u[maxn],v[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	long long n;
	cin>>n;
	for(long long i=1;i<n;i++)
		cin>>u[i]>>v[i];
	for(long long i=1;i<=n;i++)
		ans+=i*(n-i+1);
	for(long long i=1;i<=n-1;i++)
	{
		if(u[i]>v[i])
			swap(u[i],v[i]);
		ans-=u[i]*(n-v[i]+1);
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 6768
N,M = map(int,input().split())
PYlist = []
for i in range(M):
    PYlist_ele = list(map(int,input().split()))
    PYlist_ele.append(i+1)
    PYlist.append(PYlist_ele)
PYlist.sort()
check = 0
count = 0
P_id = []
for i in range(M):
    if check == PYlist[i][0]:
        count +=1
    else:
        count = 1
        check = PYlist[i][0]
    idup = '{:06}'.format(PYlist[i][0])
    iddown = '{:06}'.format(count)
    P_id.append([str(idup)+str(iddown),PYlist[i][2]])
P_id.sort(key=lambda x: x[1])
for ans in P_id:
    print(ans[0])

Measured memory_bytes: 46000
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > piii;
#define pb push_back
#define debug(x) cout << x << endl
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
#define PI acos(-1)
#define all(c) c.begin(), c.end()
#define SET(x, y) memset((x), y, sizeof(x))
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const LL INF64 = 1e18;

const int N = 1e5 + 5;

int main() {
	fastio;
	LL arr[5];
	LL ans = 0LL;
	LL lastmod = -1;
	LL idx = -1;
	for (int i = 0; i < 5; i++) {
		cin >> arr[i];
		if (arr[i] % 10 == 0)
			continue;
		if (lastmod == -1 || arr[i] % 10 < lastmod) {
			lastmod = arr[i] % 10;
			idx = i;
		}
	}
	for (int i = 0; i < 5; i++) {
		if (i != idx) {
			if (arr[i] % 10 == 0)
				ans = ans + arr[i];
			else ans = ans + (arr[i] + 10) / 10 * 10;
		} else ans = ans + arr[i];
	}
	
	cout << ans << endl;
	return 0;
}
		

Measured memory_bytes: 256
from collections import deque

N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]

tree = [[] for _ in range(N + 1)]
for i, (a, b) in enumerate(X):
    tree[a].append((b, i))
    tree[b].append((a, i))

visited = [False] * (N + 1)
visited[1] = True
color = [0] * (N - 1)
stack = deque()
stack.append((1, 0))
while stack:
    u, c = stack.popleft()
    tmp = 0
    for v, i in tree[u]:
        if visited[v]:
            continue
            
        tmp += 1
        if tmp == c:
            tmp += 1
            
        visited[v] = True
        color[i] = tmp
        stack.append((v, tmp))

print(max(color))
print(*color, sep="\n")


Measured memory_bytes: 113260
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
int Max(int &a,int b){return a=max(a,b);}
int Min(int &a,int b){return a=min(a,b);}
int n,A,B,stone[N];
 
signed main(){
  cin>>n>>A>>B;
  for(int i=0;i<n;i++) cin>>stone[i];
  sort(stone,stone+n);
 
  int ans = 0;
  if( A == B || stone[n-1]<=min(A,B)) for(int i=0;i<n;i++) ans ^= stone[i]%(A+1);
  else if( A > B ) ans = 1;
  else if(stone[n-1]-A > A || stone[n-2] > A || n == 1) ans = 0;
  else {
    int sum = 0;
    for(int i=0;i<n-1;i++) sum ^= stone[i];
    if(sum == 0) sum = A;
    int x = stone[n-1] - sum;
    ans = sum >= stone[n-1]-A && stone[n-1]-x <= A;
  }
  
  cout<<(ans? "Hanako":"Jiro")<<endl;
  return 0;
}

Measured memory_bytes: 3928
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
#define fi first
#define se second
#define pb push_back
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
const int maxn = 100005;

int main(){
// ios::sync_with_stdio(false), cin.tie(0);
int N, arr[maxn], cnt = 0;
cin >> N;
for(int i = 0; i < N; i++){
	int t; cin >> arr[i];	arr[i]--;
}

for(int i = 0; i < N - 1; i++){
	if(arr[i] == i){
		if(i + 1 < N && arr[i + 1] == i + 1)
			i++;
		cnt++;		
	}
}
int len = 0;
for(int i = N - 1; i >= 0; i--)
	if(arr[i] == i)	len++;
	else break;

if(arr[N - 1] == N - 1 && len&1)cnt++;
cout << cnt;

} 

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <cstring>
#define N 100000
using namespace std;

int main() {
  int x1,x2,y1,y2;
  int x3,x4,y3,y4;
  cin >> x1>>y1>>x2>>y2 ;
  x4=x1-(y2-y1);
  y4=y1+(x2-x1);
  x3=x2-(y2-y1);
  y3=y2+(x2-x1);
  cout<< x3 <<' '<< y3<<' ' << x4<<' ' << y4 <<endl;

  return 0;
}


Measured memory_bytes: 256
/**
*    created: 17.05.2020 21:11:32
**/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int inf =1000000000;
const double PI=3.14159265358979323846;

int main() {
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    //＜ab=x
    double x = (m * 6 - h * 30.0); //(h + (double)m / 60.0) * 30.0);
    //x = max(x, -x);
    //x = 2 * PI*x / 360;
    double ans =sqrt( a * a + b * b - 2.0 * a * b * cos(2.0*PI*( (double)m * 6.0 - ((double)floor(h) + (double)m / 60.0) * 30.0)/360.0));
    //cout << "x"<<x<< endl;
    //cout << ans << endl;
    cout <<fixed<<setprecision(11)<< ans << endl;
}

Measured memory_bytes: 4292
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
vector<int> g[3010];
int a[3010];
bool used[3010];
bool dfs(int x){
    used[x]=1;
    for(auto y:g[x]){
        if(used[y]) continue;
        if(a[y]>=a[x]) continue;
        if(!dfs(y)) return true;
    }
    return false;
}
int main()
{
	cin>>n;
    for(int i=0; i<n; i++) cin>>a[i];
    for(int i=0; i<n-1; i++){
        int x, y; cin>>x>>y; x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for(int r=0; r<n; r++){
        fill(used, used+n, 0);
        if(dfs(r)) cout<<r+1<<" ";
    }
    cout<<endl;
	return 0;
}

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

typedef long long ll;
typedef pair< int, int > PII;
typedef pair< ll, ll > PLL;

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define PI 3.14159265358979323846
#define INF 1000000006
#define LINF 1000000000000000006
#define DINF 1e300
#define FI first
#define SE second
#define X FI
#define Y SE
#define PB push_back
#define MP make_pair

const int N = 1e5 + 10;

ll n, ans, a[ N ];

void init() {
  cin >> n;
  for ( int i = 0 ; i < n ; ++i )
    cin >> a[ i ];
  sort( a, a + n );
}
bool check() {
  if ( n % 2 ) {
    int now = 2;
    if ( a[ 0 ] != 0 )
      return false;
    for ( int i = 1 ; i < n ; i += 2 ) {
      if ( a[ i ] == now && a[ i + 1 ] == now ) { 
        now += 2;
        continue;
      }
      return false;
    }
  }
  else {
    int now = 1;
    for ( int i = 0 ; i < n ; i += 2 ) {
      if ( a[ i ] == now && a[ i + 1 ] == now ) { 
        now += 2;
        continue;
      }
      return false;
    }
  }
  return true;
}
void solve() {
  if ( !check() ) {
    cout << "0" << endl;
    return;
  }
  if ( n % 2 ) 
    n -= 1;
  ans = 1;
  for ( int i = 0 ; i < n / 2 ; ++i ) {
    ans *= 2;
    ans %= ( ll )1e9 + 7;
  }
  cout << ans << endl;
}
int main() {
  IOS;
  int __ = 1;
  //cin >> __;
  while ( __-- ) {
    init();
    solve();
  }
  return 0;
}


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

int main(){
    int k,n;
    cin >> k >> n;
    int puntos[n],distancias[n],rta=0;
    for(int i=0;i<n;i++){
        cin >> puntos[i];
    }
    for(int i=0;i<n-1;i++){
        distancias[i]=puntos[i+1]-puntos[i];
    }
    distancias[n-1]=puntos[0]+(k-puntos[n-1]);
    sort(distancias,distancias+n);
    for(int i=0;i<n-1;i++){
        rta+=distancias[i];
    }
    cout << rta << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)2e9 + 7)
#define INF ((int)2e9)
#define INFLL ((LL)2e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (2 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 2, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 1) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL res = 2;
    LL sum = a;
    while(b){
        if(b&2)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

double exp(double a, LL b){
    double res = 1;
    double sum = a;
    while(b){
        if(b&1)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

PII operator+(const PII &a, const PII &b){
    return PII(a.first + b.first, a.second + b.second);
}

vector<vector<int> > xc(100001), yc(100001);

PII func(PII p){
    PII res(0, 0);
    if(!xc[p.first].empty()){
        vector<int> line = xc[p.first];
        xc[p.first].clear();
        ++res.first;
        for(auto &i:line){
            res = res + func(PII(p.first, i));
        }
    }
    if(!yc[p.second].empty()){
        vector<int> line = yc[p.second];
        yc[p.second].clear();
        ++res.second;
        for(auto &i:line){
            res = res + func(PII(i, p.second));
        }
    }
    return res;
}

signed  main(){
    int a, b;
    cin >> a >> b;
    cout << (a+b)%24 << endl;
    return 0;
}



Measured memory_bytes: 4992
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
 
using namespace std;
 
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
 
int main() {
    int n;
    string s;
    cin>>n>>s;
    if(n%2==1){
        cout<<"No"<<endl;
        return 0;
    }
    for(int i=0;i<s.size()/2;i++){
        if(s[i]!=s[i+s.size()/2]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


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

//#include <iostream>
//#include <string>
//using namespace std;


int main()
{
	int N;
	int AC = 0, WA = 0, TLE = 0, RE = 0;

	string s[110000];
	cin >> N;

	for (int i = 0; i < N; i++)
	{
		cin >> s[i];
	}

	for (int i = 0; i < N; i++)
	{
		//if (!strcmp(s[i], "WA"))
		if (!strcmp(s[i].c_str(), "AC"))AC++;
		if (!strcmp(s[i].c_str(), "WA"))WA++;
		if (!strcmp(s[i].c_str(), "TLE"))TLE++;
		if (!strcmp(s[i].c_str(), "RE"))RE++;
	}

		cout << "AC x " << AC << endl;
		cout << "WA x " << WA << endl;
		cout << "TLE x " << TLE << endl;
		cout << "RE x " << RE << endl;
}


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

int main() {
	int n;
	cin >> n;
	int c[n];

	rep (i, n) {
		char C;
		cin >> C;
		if (C == 'R') c[i] = 1;
		else c[i] = 0;
	}

    int d[n];
    memcpy(d, c, sizeof(c));
    sort(d, d+n, greater<>());
    int cnt = 0;
    rep (i, n) {
        if(c[i] != d[i]) cnt++;
    }

	cout << cnt/2 << endl;

	return 0;
}


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

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

    char input[4] = {'A', 'C', 'G', 'T'};
    char output[4] = {'T', 'G', 'C', 'A'};
    char a;
    
    cin >> a;
    for(int i = 0; i < 4; i++){
        if(input[i] == a){
            cout << output[i];
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,W;
  cin>>N>>W;
  VI A(N),B(N);
  rep(i,N) cin>>A[i]>>B[i];
  ll INF=100100100100;
  VVL dp(N+1,VL(100100,INF));
  dp[0][0]=0;
  rep(i,N){
    auto X=[&](int A,int B,int C){
      if(dp[i][B]+C<=W) dp[i+1][A]=min(dp[i+1][A],dp[i][B]+C);
    };
    rep(j,100100){
      if(dp[i][j]!=INF){
        X(j,j,0);
        X(j+B[i],j,A[i]);
      }
    }
  }
  int ans=0;
  rep(i,100100) if(dp[N][i]!=INF) ans=max(ans,i);
  cout<<ans<<endl;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  priority_queue<ll> que;
  REP(i,N){
    cin >> A[i];
    que.push(A[i]);
  }
  ll ans = 0;
  while(M>0){
    ll tmp = que.top();
    que.pop();
    tmp /= 2;
    M--;
    que.push(tmp);
    if(que.top()==0)break;
  }
  while(!que.empty()){
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2168