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


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

  string s;
  cin>>s;
  int n = s.size();
  
  int numNode = 0;
  for(int i=0;i<n;i++) if(isalpha(s[i])) numNode++;

  
  vector<int> win(26, 0);
  int sumWin = 0;
  for(int i=0;i<numNode;i++){
    string s;
    int num;
    cin>>s>>num;
    sumWin += num;
    win[s[0] - 'a'] = num;
  }

  int valid = 1;
  int idx = 0;
  assert(s[0]=='[');
  
  function<P()> dfs = [&](){
    if(isalpha(s[idx])) {
      int i = idx++;
      return P(win[s[i] - 'a'], 0);
    }
    
    if(s[idx] == '['){
      idx++;
      auto l = dfs();
      assert(s[idx] == '-');
      idx++;

      auto r = dfs();
      assert(s[idx] == ']');
      idx++;
      if(l.first == l.second) return P(r.first, r.second + 1);
      if(r.first == r.second) return P(l.first, l.second + 1);
      valid = 0;
      return P(0, 0);
    }
    assert(0);
    return P(0, 0);
  };
  
  auto winner = dfs();
  valid &= (winner.first == winner.second);
  assert(idx == n);
  cout<<(valid? "Yes":"No")<<endl;
  
  return 0;
}



Measured memory_bytes: 3248
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  int L[N];
  REP(i,N)cin>>L[i];
  sort(L,L+N);
  lint ans=0;
  REP(i,N)REP(j,N)if(i!=j){
    int l=upper_bound(L,L+N,max(L[i]-L[j],L[j]-L[i])) - L;
    int r=lower_bound(L,L+N,L[i]+L[j]) - L;
    ans+=r-l;
    if(L[l]<=L[i])ans--;
    if(L[l]<=L[j])ans--;

    // cerr<< L[i]<<" "<<L[j]<< " "<<l<<" "<<r<<" "<<ans<<endl;
  }
  cout<<ans/6<<endl;
  return 0;
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O #-}

import Control.Monad
import Data.List
import qualified Data.Map.Strict as M

main = do
    n <- readLn :: IO Int
    bs <- foldl' (\ma k -> M.insertWith(+)k 1 ma) M.empty <$> replicateM n getLine :: IO(M.Map String Int)
    m <- readLn :: IO Int
    rs <- foldl' (\ma k -> M.insertWith(+)k 1 ma) M.empty <$> replicateM m getLine :: IO(M.Map String Int)
    --
    print.last .sort.(:) 0.map snd.M.toList$ M.mapWithKey (f rs) bs
    --
    return ()
    --
    where f rs k a = case M.lookup k rs of
                        Just n -> a-n
                        Nothing -> a


Measured memory_bytes: 636
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, X] = string_to_int(inputs[0])
    L = string_to_int(inputs[1])

    step = 0
    count = 1
    for i in range(1, N + 1):
        step += L[i - 1]

        if step <= X:
            count += 1
        else:
            break
    return count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n, m, a;
  cin >> n >> m;
  vl broken(n+1, 0);
  rep(i, m) {
    cin >> a;
    broken[a] = 1;
  }
  vl f(n+1);
  f[0]=1;
  f[1]=1-broken[1];
  rep(i, n-1) {
    if(!broken[i]) f[i+2] += f[i];
    if(!broken[i+1]) f[i+2] += f[i+1];
    f[i+2] %= MOD;
  }
  cout << f[n] << newl;
  return 0;
}

Measured memory_bytes: 1920
count = 0
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())
x = int(raw_input())

costs = [0, 0, 0]

for num_a in xrange(a + 1):
    costs[0] = num_a * 500

    for num_b in xrange(b + 1):
        costs[1] = num_b * 100

        for num_c in xrange(c + 1):
            costs[2] = num_c * 50
            if sum(costs) == x:
                count += 1

print count


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(v) v.begin(), v.end()
using i64 = int64_t;
using P = pair<i64,i64>;


int main(){
    int N;
    while(cin >> N, N != 0){
        string S;
        vector<int> timeTable(24*60*60, 0);

        rep(i,N){
            rep(k,2){
                cin >> S;
                int h = stoi(S.substr(0,2));
                int m = stoi(S.substr(3,2));
                int s = stoi(S.substr(6,2));

                s += m*60 + h*60*60;

                int stamp = (k == 0 ? 1 : -1);
                timeTable[s] += stamp;
            }
        }
        for(int i = 1; i < 24*60*60; i++){
            timeTable[i] += timeTable[i-1];
        }

        cout << *max_element(all(timeTable)) << endl;
    }
}



Measured memory_bytes: 3344
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
    int n,i,max;
    double d[101];
    while(scanf("%d",&n)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            d[i]=log(i)/log(2);
        }
        max=1;
        for(i=2;i<=n;i++)
        {
            if(d[i]>d[max]&&(int)d[i]==d[i])
                max=i;
        }
        printf("%d\n",max);
    }
    return 0;
}


Measured memory_bytes: 128
import collections
c = collections.Counter

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

v_odd = v[::2]
v_eve = v[1::2]

c1 = c(v_odd).most_common(2)
c2 = c(v_eve).most_common(2)

if len(c1) == 1 and len(c2) == 1:
    if c1[0][0] != c2[0][0]:
        ans = 0
    else:
        ans = int(N/2)
else:
    if c1[0] != c2[0]:
        ans = N - c1[0][1] - c2[0][1]
    else:
        if c1[1][1] >= c2[1][1]:
            ans = N - c1[1][1] - c2[0][1]
        else:
            ans = N - c1[0][1] - c2[1][1]

print(ans)

Measured memory_bytes: 15972
n,k=map(int,input().split())
r,s,p=map(int,input().split())
a=list(input())
ans1=[]

ans=0
for i in range(n):
  x=a[i]
  if i-k>=0:
    if x==a[i-k]:
      if ans1[i-k]==0:
        if x=='r':
          ans1.append(p)
        elif x=='p':
          ans1.append(s)
        else:
          ans1.append(r)
          
      else:
        ans1.append(0)
    else:
      if x=='r':
          ans1.append(p)
      elif x=='p':
          ans1.append(s)
      else:
          ans1.append(r)
  else:
    if x=='r':
          ans1.append(p)
     
    elif x=='p':
          ans1.append(s)
        
    else:
          ans1.append(r)

print(sum(ans1))

Measured memory_bytes: 10628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

struct Dice{
private:
	static const int _roll[4][6], _turn[2][6];
public:
	vector<int> value;
	// 1-6 : top, near, right, left, far, bottom 

	Dice(){
		value.resize(6);
		for (int i = 0; i < 6; ++i) value[i] = i;
	}

	void roll(int dir){ // N, E, W, S
		vector<int> nxt(6);
		for (int i = 0; i < 6; ++i){
			nxt[i] = value[_roll[dir][i]];
		}
		value = nxt;
	}

	void turn(int dir){ // L, R
		vector<int> nxt(6);
		for (int i = 0; i < 6; ++i){
			nxt[i] = value[_turn[dir][i]];
		}
		value = nxt;
	}

	int &operator[](int i){
		return value[i];
	}
};

const int Dice::_roll[4][6] = {
	{ 1, 5, 2, 3, 0, 4 }, // North
	{ 3, 1, 0, 5, 4, 2 }, // East
	{ 2, 1, 5, 0, 4, 3 }, // West
	{ 4, 0, 2, 3, 5, 1 }, // South
};

const int Dice::_turn[2][6] = {
	{ 0, 3, 1, 4, 2, 5 }, // Left
	{ 0, 2, 4, 1, 3, 5 }, // Right
};

typedef pair<int, int> P;

int main(){	
	int n;

	int rdir[] = { 0, 3, 1, 2, 0 };
	int dx[] = { 0, 1, -1, 0};
	int dy[] = { 1, 0, 0, -1};
	while (cin >> n, n){
		P field[300][300];

		while (n--){
			int t, f;
			cin >> t >> f;
			Dice d;
			for (int i = 0; i < 6; ++i) d[i] = i + 1;
			if (d[2] == t || d[3] == t) d.turn(0);
			while (d[0] != t) d.roll(0);
			while (d[1] != f) d.turn(0);

			P pos = {150, 150};
			while (1){
				P dir = {-1, -1};
				for (int i = 1; i <= 4; ++i){
					int nx = pos.first + dx[rdir[i]], ny = pos.second + dy[rdir[i]];
					if(d[i] >= 4 && field[pos.second][pos.first].first > field[ny][nx].first) dir = max(dir, make_pair(d[i], rdir[i]));
				}
				if (dir.second < 0) break;
				d.roll(dir.second);
				pos.first += dx[dir.second];
				pos.second += dy[dir.second];
			}
			++field[pos.second][pos.first].first;
			field[pos.second][pos.first].second = d[0];
		}
		int cnt[7] = {};
		for (auto &pp : field)for (auto &p : pp){
			++cnt[p.second];
		}
		for (int i = 0; i < 6; i++) cout << (i ? " " : "") << cnt[i + 1];
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1912
#include<iostream>
#include <climits>

int main(){

    int n;
    std::cin >> n;
    int mx = INT_MIN, mn = INT_MAX;
    long long sum = 0;
    for(int i = 0; i < n; ++i){
        int a;
        std::cin >> a;
        mx = std::max(mx, a);
        mn = std::min(mn, a);
        sum += a;
    }

    std::cout << mn << " " << mx << " " << sum << std::endl;

    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORS(i, m, n) for (int i = m; i <= n; i++)
#define BIT(n) (1LL << (n))
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    cout << ((N == 3 || N == 5 || N == 7) ? "YES" : "NO") << "\n";
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp2
{
    public class Program
    {

        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            int after = 0;

            int index = 0;
            while (index<S.Length)
            {
                char c = S[index];
                after++;
                index++;
                if (index == S.Length) break;
                while (S[index] == c)
                {
                    index++;
                if (index == S.Length) break;
                }
            }

            Console.WriteLine(after);
            Console.ReadLine();
        }
    }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int a,b;cin>>a>>b;
    int res=0;
    for(int i=a;i<=b;i++){
        string s=to_string(i),rs=s;
        reverse(rs.begin(),rs.end());
        if(s==rs) res++;
    }
    cout<<res<<endl;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[200010];
vector<ll> V[200010];
bool U[200010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    REP(i, N) {
        cin >> A[i];
    }
    REP(i, N) {
        if (V[A[i]].size() == 0)
            V[A[i]].push_back(-1);
    }
    REP(i, N) {
        V[A[i]].push_back(i);
    }

    vector<ll> v;
    v.push_back(N);
    ll index = N - 1;
    ll cnt = 1;
    do {
        ll n = A[index];
        ll nxt = (lower_bound(V[n].begin(), V[n].end(), index) - V[n].begin()) - 1;
        if (nxt == 0) {
            cnt++;
            nxt = V[n].size() - 1;
            v.push_back(V[n][nxt]);
        }
        index = V[n][nxt] - 1;
    } while (index >= 0);
    ll s = v[(cnt - (K % cnt)) % cnt];
    //cout << cnt << " " << s << endl;
    deque<ll> ans;
    FOR(i, N, s) {
        ll n = A[i];
        if (U[n]) {
            while (!ans.empty()) {
                ll m = ans.back();
                ans.pop_back();
                U[m] = false;
                if (m == n)
                    break;
            }
 
            continue;
        }
        U[n] = true;
        ans.push_back(n);
    }

    while (!ans.empty()) {
        ll n = ans.front();
        ans.pop_front();
        cout << n << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 17396
#include<stdio.h>
int main()
{
  int a,b,c,tmp;

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

  if(a > b)
    {
      tmp = a;
      a = b;
      b = tmp;
    }
  if(b > c)
    {
      tmp = b;
      b = c;
      c = tmp;
    }
  if(a > b)
    {
      tmp = a;
      a = b;
      b = tmp;
    }

  printf("%d %d %d\n",a,b,c);

  return 0;
}

Measured memory_bytes: 1752
a,b=map(int,input().split())
ans=0
if a-b>=0:
    ans+=a
    a-=1
    if a-b>=0:
        ans+=a
    else:
        ans+=b

else:
    ans+=b
    b-=1
    if b-a>=0:
        ans+=b
    else:
        ans+=a
print(ans)

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

int main() {
	int n, k, x[101];
	cin >> n >> k;
	for(int i=0;i<n;i++) cin >> x[i];


	int sum=0;
	for(int i=0;i<n;i++) {
		sum += 2 * min(x[i],k-x[i]);
	}

	cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#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)
 
typedef long long ll;
#define INF 1e9
 
 
int main(){
  int N, K;
  cin >> N >> K;
  ll cnt = 0;
  if(K%2){
    for(int i = K; i <= N; i+=K){
      cnt++; // I== j== k のとき
      cnt += 3*((i-1)/K); // i == j の時
      cnt += 3*((i-1)/K); // j==k の時
      ll box = (i-1)/K-1;
      cnt += 6* (box*(box+1)/2);
    }
  }
  else{
    for(int i = K/2; i <= N; i+=K/2){
      cnt++; // i== j== k のとき
      cnt += 3 * ((i-K/2)/K); // i==j の時
      cnt += 3 * ((i-K/2)/K); // j==k のとき
      ll box = (i-K/2)/K -1;
      cnt += 6*(box*(box+1)/2);
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define BE(x) (x).begin(), (x).end()

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    int ans = 1, f = 0;
    for (int i = 1; i < n; i++) {
        if (f == 0) {
            if (a[i-1] < a[i]) f = 1;
            if (a[i-1] > a[i]) f = 2;
        }
        if (f == 1) {
            if (a[i-1] > a[i]) ans++, f = 0;
        }
        if (f == 2) {
            if (a[i-1] < a[i]) ans++, f = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3724
N, M = gets.split(' ').map(&:to_i)
A = gets.split(' ').map(&:to_i)
grids = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

numbers = []
A.each do |n|
  numbers.push([n, grids[n]])
end
numbers.sort_by!{|a| [a[1], -a[0]]}

dp = Array.new(N+1)
dp[0] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
1.upto(N) do |ma|
  numbers.each do |i|
    next if ma < i[1]
    if dp[ma - i[1]] != nil
      cand = [0] * 10
      1.upto(9) do |l|
        cand[l] = dp[ma - i[1]][l]
      end
      cand[i[0]] = cand[i[0]] + 1
 	  if dp[ma] == nil
        dp[ma] = cand
      else
        mx = true
        mx = false if dp[ma].inject(:+) > cand.inject(:+)
        9.downto(1) do |j|
          next if dp[ma][j] == cand[j]
          if dp[ma][j] > cand[j]
            mx = false
            break
          end
          if dp[ma][j] < cand[j]
            break
          end
        end
        dp[ma] = cand if mx
      end
    end
  end
end
ans = ""
9.downto(1) do |i|
  ans = ans + i.to_s * dp[N][i]
end
puts ans

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

int main()
{
  string S;
  cin >> S;
  
  int count = 0;
  for(int i = 0; i < S.size(); i++)
  {
    if(S.at(i) == '1')
      count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,j,n,d[50],sum;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&d[i]);
	}
	sum=0;
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			sum=sum+(d[i]*d[j]);
		}
	}
	printf("%d\n",sum);
}

Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

int dx[]={-1,0,1,1,1,0,-1,-1},dy[]={-1,-1,-1,0,1,1,1,0};
int get_num(vs &f,int y,int x,int d,char move){
	int ret=0;
	int cy=y+dy[d];
	int cx=x+dx[d];
	int flipped=0;
	while(cy>=0&&cx>=0&&cy<8&&cx<8&&f[cy][cx]!=move&&f[cy][cx]!='.'){
		cy+=dy[d];
		cx+=dx[d];
		flipped++;
	}
	if(cy>=0&&cx>=0&&cy<8&&cx<8&&f[cy][cx]!='.'){
		ret+=flipped;
	}
	return ret;
}

void flip(vs &f,int y,int x,char move){
	f[y][x]=move;
	REP(d,8){
		if(get_num(f,y,x,d,move)){
			int cy=y+dy[d];
			int cx=x+dx[d];
			while(cy>=0&&cx>=0&&cy<8&&cx<8&&f[cy][cx]!=move&&f[cy][cx]!='.'){
				f[cy][cx]=move;
				cy+=dy[d];
				cx+=dx[d];
			}
		}
	}
}

char moves[]={'o','x'};
int main(){
	vs f(8);
	REP(i,8){
		cin>>f[i];
	}
	int changed=2;
	int move_i=0;
	while(changed){
		changed--;
		pii best_pos;
		int best_num=0;
		REP(i,8){
			REP(j,8){
				if(f[i][j]=='.'){
					int num=0;
					REP(d,8){
						num+=get_num(f,i,j,d,moves[move_i]);
					}
					if(num){
						changed=2;
					}
					if(num>best_num){
						best_num=num;
						best_pos=make_pair(i,j);
					}else if(num==best_num){
						if(move_i==1){
							best_num=num;
							best_pos=make_pair(i,j);
						}
					}
				}
			}
		}
		if(changed==2){
			flip(f,best_pos.first,best_pos.second,moves[move_i]);
		}
		move_i=(move_i+1)%2;
	}
	REP(i,8){
		cout<<f[i]<<endl;
	}
}

Measured memory_bytes: 1188
from sys import stdin 

def main():

	n = int(input())

	h_vals = []

	for lines in range(n):
		h = list(map(int, input().split()))
		h_vals.append(h)

	L = [ [0 for _ in range(n + 1)] for _ in range(3) ]


	for cur_day in range(1, n + 1):
		for val in range(3):
			cur_max = 0
			other_vals = [0, 1, 2]
			other_vals.remove(val)
			for other_val in other_vals:
				cur_max = max(L[other_val][cur_day - 1] + h_vals[cur_day - 1][other_val], cur_max)
			L[val][cur_day] = cur_max

	print(max(L[0][n], L[1][n], L[2][n]))









if __name__ == '__main__':
	main()



Measured memory_bytes: 42268
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
using namespace boost::multiprecision;

int main() {
  cpp_dec_float_100 a, b, c;
  cin >> a >> b >> c;
  cout << ((sqrt(a) + sqrt(b) < sqrt(c)) ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 512
N,M=map(int,input().split())


ac = 0
wa = 0
aclist = {}
walist = {}

count_WA=0
for i in range(N):
    aclist[i + 1] = 0
    walist[i + 1] = 0

for i in range(M):
    a,b=input().split()
    a=int(a)
    if aclist[a] == 1:
        continue
    elif b == 'WA':
        walist[a] += 1
    elif b == 'AC':
        aclist[a] += 1
        ac += 1
        wa += walist[a]




print(ac,wa,sep=" ")


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

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    vector<int> B(n);
    vector<int> C(n-1);
    rep(i,n){
        int a;
        cin >> a;
        a--;
        A.at(i) = a;
    }
    rep(i,n) cin >> B.at(i);
    rep(i,n-1) cin >> C.at(i);
    int ans = 0;
    rep(i,n){
        ans += B.at(A.at(i));
        if(i == n-1 || A.at(i) == n-1) continue;
        if(A.at(i) + 1 == A.at(i+1)) ans += C.at(A.at(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  string s;
  cin >> s;
  int cnt[26] = {};
  for (char c: s) {
    cnt[c - 'a']++;
  }
  for (int i : cnt) {
    if (i & 1) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 100000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;
const ll MAXN = 1e18;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	int x,y,z;
	cin >> x >> y >> z;
	int suma = (x-z)/(y+z);
	cout << suma << endl;
	return 0;
}



Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include <cstdlib>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include <assert.h>
#include<map>
#include<set>
#include<bitset>
#include <iomanip>
#include<stack>
#include <unordered_map>
#include<cmath>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define INF 0x7f7f7f7f //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.14159265358979323846264338327950254
#define pb push_back
#define ll long long
#define debug cout << "debug\n";
#define STDIN freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);
#define scai(x) scanf("%d", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define scaf(x) scanf("%lf", &x)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define For(m,n) for (int i = m;  i < n; i++)
#define PII pair<int,int>
#define PLL pair<long, long>
#define ft first
#define sd second
#define pb push_back
const int maxn=333333,mod=1000000009;
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){char ch=getchar();int x=0,f=0;while(ch<'0'||ch>'9')f|=ch=='-',ch=getchar();while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();return f?-x:x;} 

const int N = 1e5 + 10;
int h[N], e[N<<1], ne[N<<1], idx;

int n, m;
int height[N];
int cnt;
void add(int a, int b)
{
    e[idx] = b;
    ne[idx] = h[a];
    h[a] = idx++;
}

bool dfs(int x)
{
    for (int i = h[x]; i != -1; i = ne[i])
    {
        int j = e[i];
        // if (x == 6)
        // {
        //     cout << "h " << height[j] << " " << height[x] << endl;
        // }
        if (height[j] >= height[x]) return false;
    }
    // cout << x << endl;
    return true;
}
int main()
{
    // STDIN
    cin >> n >> m;
    memset(h, -1, sizeof h);
    for (int i = 1; i <= n; i++) scanf("%d", &height[i]);
    while (m--)
    {
        int a, b; cin >> a >> b;
        add(a, b);
        add(b, a);
    }
    for (int i = 1; i <= n; i++)
    {
        if(dfs(i)) cnt++;
    }
    cout << cnt << endl;
}

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

using ll = long long;
using pint = pair<int, int>;

const ll INF = 1e12;
const ll MOD = 1e9 + 7;

ll N;

int main()
{
    vector<ll> v(5);
    cin >> N;
    for (int i = 0; i < 5; ++i)
    {
        cin >> v[i];
    }
    ll bottle = *min_element(v.begin(), v.end());
    ll result = 5 + (N + bottle - 1) / bottle - 1;
    cout << result << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3


# Union find
class UnionFind:
    def __init__(self, N):
        self.N = N
        self.parent = list(range(N))

    def root(self, x):
        path_to_root = []
        while self.parent[x] != x:
            path_to_root.append(x)
            x = self.parent[x]
        for node in path_to_root:
            self.parent[node] = x  # パス圧縮
        return x

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        self.parent[self.root(x)] = self.root(y)

    def __str__(self):
        groups = {}
        for x in range(self.N):
            root = self.root(x)
            if root in groups.keys():
                groups[root].append(x)
            else:
                groups[root] = [x]
        result = ""
        for root in groups.keys():
            result += str(groups[root]) + "\n"
        return result


# Kruscal法: 最小全域木
# num_vertices: int
# edges=(vertex1, vertex2, weight): List[int, int, int]
# edgesについて破壊的
def kruskal(num_vertices, edges):
    total_weight = 0
    edges.sort(key=lambda e: e[2])
    u = UnionFind(num_vertices)
    for e in edges:
        x = e[0]
        y = e[1]
        weight = e[2]
        if u.same(x, y):
            continue
        u.unite(x, y)
        total_weight += weight
    return total_weight


n = int(input())
edges = []
for i in range(n):
    row = list(map(int, input().split()))
    for j in range(i, n):
        if row[j] != -1:
            edges.append([i, j, row[j]])
print(kruskal(n, edges))



Measured memory_bytes: 6144
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    vector<int> nxt(n); iota(nxt.begin(), nxt.end(), 1);
    while (m--) {
        int l, r; cin >> l >> r; l--; r--;
        chmax(nxt[l], r + 1);
    }
    for (int i = 1; i < n; i++) chmax(nxt[i], nxt[i - 1]);
    vector<long long> dp(n + 1), acc_max(n + 1);
    for (int i = 0; i < n; i++) {
        chmax(dp[nxt[i]], acc_max[i] + a[i]);
        chmax(acc_max[i + 1], max(acc_max[i], dp[i + 1]));
    }
    cout << dp[n] << endl;
    return 0;
}


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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> p;

int main(){
	char dif = 'A' - 'a';
	vector<string> S(3);
	rep(i,3){
		cin>>S[i];
		string s = S[i];
		char k = s[0]+dif;
		cout<<k;
	  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        Tree tree[] = new Tree[n+1];
        for(int i=0; i<n+1; i++) {
            tree[i] = new Tree();
            tree[i].value = 0;
            tree[i].tree = new Tree();
        }

        for(int i=0; i<n-1; i++) {
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            tree[b].tree = tree[a];
        }

        for(int i=0; i<q; i++) {
            int p = Integer.parseInt(sc.next());
            int x = Integer.parseInt(sc.next());
            tree[p].value += x;
        }

        for(int i=0; i<n; i++) {
            if (tree[i+1].tree != null)
                tree[i+1].value += tree[i+1].tree.value;
            System.out.print(tree[i+1].value);
            if(i+1 < n)
                System.out.print(" ");
            else
                System.out.println();
        }
    }
}

class Tree {
    int value = 0;
    Tree tree;

    public Tree(){}
}


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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const int N = 100010;

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

int fx[]={1,-1,0,0};
int fy[]={0,0,-1,1};

int main(){
    ll Q = lin(), H = lin(), S = lin(), D = lin();
    D = min(D, min(S * 2ll, min(H * 4ll, Q * 8ll)));
    S = min(S, min(H * 2ll, Q * 4ll));
    H = min(H, Q * 2ll);
    ll n = lin();
    ll ans = 1ll * (n / 2ll) * D + ((n & 1ll) ? S : 0);
    printf("%lld\n", ans);
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (a, p) = input!(u64, u64);

    println!("{}", (3 * a + p) / 2);
}

fn main() {
    solve();
}


Measured memory_bytes: 4352
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    for i in range(N-1):
        if A[i] < 0:
            A[i] *= -1
            A[i+1] *= -1
    a_sum =sum(A)

    aa = list(map(abs, A))
    return max(a_sum, sum(aa) - 2*min(aa))


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 16704
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int Z = sc.nextInt();

        int tmp;

        tmp = X;
        X = Y;
        Y = tmp;

        tmp = X;
        X = Z;
        Z = tmp;
        System.out.println(X + " " + Y + " " + Z);
    }
}

Measured memory_bytes: 39388
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define gmid ((l+r) >> 1)
#define ll long long
using namespace std;

int main()
{
     int ans=0,a,b,s;
     cin>>a>>b;
     s=max(a,b)*10;
     for(int i=s;i<=100000;++i)
       {
       	   if((i*8)/100==a&&i/10==b)
       	     {
       	     	  ans=i;
       	     	  break;
			 }
	   }
	 if(ans!=0)  
	 cout<<ans<<endl;  
	 else cout<<-1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int a, b;
    cin >> a >> b;
    int ans = a*b;
    if(ans%2 == 1) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

int d[101][200001];

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

  ll n, k; cin >> n >> k;
  rep(i, n) cin >> d[0][i], --d[0][i];

  rep(i, 100) rep(j, n) d[i+1][j] = d[i][d[i][j]];

  int now = 0;
  rep(i, 61) if (k & (1LL << i)) now = d[i][now];

  cout << now+1 << endl;
}


Measured memory_bytes: 82560
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <string>
#include <map>
using namespace std;
typedef long long ll;

int main(){
  int k,a,b;
  cin >> k >> a >> b;
  bool ok = false;
  for(int i=a; i<b+1; i++){
    if(i%k==0 and ok ==false ){
      cout << "OK" << endl;
      ok = true;
    }
  }

  if(!ok){
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  int N; ll K; cin >> N >> K;
  vector<pair<int,int>> arr(N);
  rep(i,N) cin >> arr[i].first >> arr[i].second;
  sort(arr.begin(), arr.end());
  ll sum = 0; int i = 0;
  while(sum < K) {
    sum += arr[i].second;
    ++i;
  }
  cout << arr[i-1].first << endl;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M, ans;
vector <int> Graph[55];

bool visited[55];
int DFS(int i, int j){
  fill(visited, visited + N + 1, false);
  visited[i] = true;
  queue <int> que; que.push(i);

  while (!que.empty()){
    int Q = que.front(); que.pop();

    for (int next : Graph[Q]){
      if (Q == i && next == j) continue;
      if (Q == j && next == i) continue;
      if (visited[next]) continue;
      que.push(next);
      visited[next] = true;
    }
  }

  for (int i = 1; i <= N; i++){
    if (!visited[i]){
      ans++; return 0;
    }
  }
  return 0;
}


int main(){
  cin >> N >> M;
  for (int i = 0; i < M; i++){
    int A, B; cin >> A >> B;
    Graph[A].push_back(B);
    Graph[B].push_back(A);
  }

  for (int i = 1; i <= N; i++){
    for (int j : Graph[i]){
      if (i < j) DFS(i, j);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3604
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

int n,k;
ll a[1001];
vector<ll> cnd;

int main(){
    cin >> n >> k;
    REP(i,n){
        cin >> a[i+1];
        a[i+1] += a[i];
    }
    REP(i,n+1){
        FOR(j,i+1,n+1){
            cnd.pb(a[j]-a[i]);
        }
    }

    int ncnd = n * (n-1) / 2;
    sort(cnd.begin(),cnd.end());

    ll mx = cnd[cnd.size()-1];
    //cerr << mx << endl;
    int g = log2(mx)+2;

    vector<pair<ll,ll>> cnd2;
    for (auto vi: cnd){
        cnd2.eb( (1LL<<g)&vi, vi );
    }
    sort(cnd2.begin(),cnd2.end());

    ll ret = 0;
    const pair<ll,ll> comper = mp(1,0);
    while(g >= 0){
        auto lb = lower_bound(cnd2.begin(),cnd2.end(), comper);
        auto ds = distance(cnd2.begin(), lb);
        int ok = cnd2.size() - ds;

        if (ok >= k){
            ret |= (1LL << g);
            vector<pair<ll,ll>> cnd3;
            for (auto vi:cnd2){
                if (vi.first) cnd3.pb(vi);
            }
            cnd2 = cnd3;
        }

        g--;
        if (g < 0) break;

        vector<pair<ll,ll>> cnd3;
        for (auto vi:cnd2){
            cnd3.eb( (1LL<<g)&vi.second, vi.second );
        }
        cnd2 = cnd3;
        sort(cnd2.begin(),cnd2.end());

    }

    cout << ret << endl;
}

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

int main() {
 int n, next, count;
  vector<int> button(100000);
  vector<bool> pushed(100000, false);
  
  cin >> n;
  rep(i, n)
    cin >> button.at(i);
  
  next = button.at(0);
  count = 1;
  while(1){
    if(next == 2)
      break;
  	else if(pushed.at(next - 1)){
    	count = -1;
      	break;
    }
    pushed.at(next - 1) = true;
    next = button.at(next - 1);
    count++;
  }
  
  cout << count << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


int parent(int i)
{
	return i / 2;
}

int left(int i)
{
	return 2 * i;
}

int right(int i)
{
	return 2 * i + 1;
}


int main()
{
	int H, i;
	
	cin >> H;
	int A[H + 1];
	for (i=1; i<=H; i++) cin >> A[i];
	
	for (i=1; i<=H; i++)
	{
		cout << "node " << i << ": key = " << A[i] << ", ";
		if (parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
		if (left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
		if (right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
		cout << endl;
	}
	
	return 0;
}


void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}


double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define F first
#define S second
#define random(x) (rand()%x)
const int maxn=100005,INF=0x3f3f3f3f,mod=1000000007;
struct QES{
	int v,d,c;
	QES(){}
	QES(int x,int y,int z){
		v=x;d=y;c=z;
	}
}qes[maxn];
int n,m,q,vis[maxn],col[maxn];
vi eg[maxn];

int dfs(QES nd){
	//printf("(%d %d %d)\n",nd.v,nd.d,nd.c);
	if(col[nd.v]==0) col[nd.v]=nd.c;
	if(nd.d==0){
		return 0;
	}
	for(int i=0;i<eg[nd.v].size();i++){
		if(vis[eg[nd.v][i]]<nd.d-1){
			vis[eg[nd.v][i]]=nd.d-1;
			dfs(QES(eg[nd.v][i],nd.d-1,nd.c));
		}
	}
}
int main(){
	int t1,t2;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d",&t1,&t2);
		eg[t1].push_back(t2);
		eg[t2].push_back(t1);
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf("%d%d%d",&qes[i].v,&qes[i].d,&qes[i].c);
	}
	memset(vis,-1,sizeof(vis));
	for(int i=q-1;i>=0;i--){
		if(vis[qes[i].v]<qes[i].d){
			vis[qes[i].v]=qes[i].d;
			dfs(qes[i]);
		}
	}
	for(int i=1;i<=n;i++){
		printf("%d\n",col[i]);
	}
	return 0;
}


Measured memory_bytes: 8440
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	for(int i=0;i<a.size();i++){
		if(a[i]!=b[i]){
			cout<<"No";
			return 0;
		}
	} 
	cout<<"Yes";
return 0;
}



Measured memory_bytes: 3596
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
s = [0] * (N+1)

for i in range(N):
    s[i+1] = s[i] + A[i]
    s[i+1] %= K
s.reverse()
for i in range(N+1):
    s[i] += (i%K)
    s[i] %= K

d = {}
ans = 0
for i in range(N+1):
    if s[i] not in d:
        d[s[i]] = 0
    if i >= K:
        d[s[i-K]] -= 1
    ans += d[s[i]]
    d[s[i]] += 1

print(ans)

Measured memory_bytes: 111496
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int max(int a,int b){return (a>b ? a:b);}
int min(int a,int b){return (a<b ? a:b);}
int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
//qsort(配列, 長さ, sizeof(int), compare_int);
double BS(int array[],int len,int target);

int A,B,C;

int main(){
    scanf("%d%d%d",&A,&B,&C);
    if((A == B) && (A == C)){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}





double BS(int array[],int len,int target){ //(配列,長さ,見つける値)
    int low,mid,high;

    low = 0;
    high = len-1;

    int mark;

    while(low <= high){
        mid = (low + high) / 2;
        if(array[mid] == target){
            mark = 0;
            break;
        }else if(array[mid] < target){
            low = mid + 1;
            mark = 1;
        }else{
            high = mid - 1;
            mark = -1;
        }
    }
    if(mark == 0){
        return mid; //配列の何番目か（０から）
    }else if(mark == 1){
        return (double)mid + 0.5;//なかったらどこのあいだか
    }else{
        return (double)mid - 0.5;
    }
}

Measured memory_bytes: 128
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int x;
	scan(x);
	prin(!x);
	return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int k, a, b;
    cin >> k >> a >> b;
    if(a%k == 0){
        cout <<"OK\n";
        return 0;
    }
    int temp = a/k;
    temp++;
    temp *= k;
    if(temp <= b)
        cout << "OK\n";
    else
        cout << "NG\n";
    return 0;
}


Measured memory_bytes: 3616