akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
    using namespace std;
    using ll = long long;
     
    int main(){
        int n,d,a;
        cin >> n >> d >> a;
        vector<ll> bit(n+1,0);
        vector<pair<int,int>> monsters;
        for(int i = 0;i<n;++i){
            int x,h;
            cin >> x >> h;
            h = (h+a-1)/a;//reduce the health of monster by a 'h' times
            monsters.emplace_back(x,h);
        }
        
        auto update = [&](int idx,int val){
            ++idx;
            while(idx <= n){
                bit[idx] += val;
                idx += (idx & (-idx));
            }
        };
        
        auto updateRange = [&] (int l,int r,int val){
            update(l,val);
            update(r+1,-val);
        };
        
        auto read = [&](int idx){
            ++idx;
            int sum = 0;
            while(idx > 0){
                sum += bit[idx];
                idx -= (idx &(-idx));
            }
            return sum;
        };
        
        auto sum = [&](int l,int r){
            return read(r) - read(l-1);
        };
        
        long long ans = 0;
        sort(monsters.begin(),monsters.end());
        for(int i = 0;i<n;++i)
        {
            update(i,monsters[i].second);
            update(i+1,-monsters[i].second);
        }
        for(int i = 0;i<n;++i){
           // update(i,monsters[i].second);
            int health = read(i);
           // cout << health <<"\n";
            if(health <= 0)
                continue;
            int l = i;
            int r = n-1;
            int ok = -1;
            //find the ending point of covered in the range x[i] to x[i]+2*d-1
            while(l <= r){
                int mid = l+(r-l)/2;
                if(monsters[mid].first <= (ll)monsters[i].first + 2*d){
                    ok = mid;
                    l = mid+1;
                }
                else{
                    r = mid-1;
                }
            }
            assert(ok!=-1);
            updateRange(i,ok,-health);
            ans += health;
        }
        cout << ans <<"\n";
        return 0;
    }

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int MAX = 2e5;

vector<int> G[MAX], d, cnt(2);

void dfs(int u) {
  for (int v: G[u]) {
    if (d[v] != -1) continue;
    d[v] = d[u] + 1;
    cnt[d[v] % 2]++;
    dfs(v);
  }
}

int main() {
  int n;
  cin >> n;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }

  d.resize(n, -1);
  d[0] = 0;
  cnt[0]++;
  dfs(0);

  if (cnt[0] > n / 3 && cnt[1] > n / 3) {
    vector<int> res(3, 0);
    rep(i, n) {
      if (d[i] % 2 == 0) {
        if (res[1] < (n + 2) / 3) {
          cout << res[1] * 3 + 1;
          res[1]++;
        }
        else {
          cout << res[0] * 3 + 3;
          res[0]++;
        }
      }
      else {
        if (res[2] < (n + 1) / 3) {
          cout << res[2] * 3 + 2;
          res[2]++;
        }
        else {
          cout << res[0] * 3 + 3;
          res[0]++;
        }
      }
      if (i == n - 1) cout << endl;
      else cout << " ";
    }
  }
  else if (cnt[0] <= n / 3) {
    vector<int> res(3, 0);
    rep(i, n) {
      if (d[i] % 2 == 0) {
        cout << res[0] * 3 + 3;
        res[0]++;
      }
      else {
        if (res[1] < (n + 2) / 3) {
          cout << res[1] * 3 + 1;
          res[1]++;
        }
        else if (res[2] < (n + 1) / 3) {
          cout << res[2] * 3 + 2;
          res[2]++;
        }
        else {
          cout << res[0] * 3 + 3;
          res[0]++;
        }
      }
      if (i == n - 1) cout << endl;
      else cout << " ";
    }
  }
  else {
    vector<int> res(3, 0);
    rep(i, n) {
      if (d[i] % 2 == 1) {
        cout << res[0] * 3 + 3;
        res[0]++;
      }
      else {
        if (res[1] < (n + 2) / 3) {
          cout << res[1] * 3 + 1;
          res[1]++;
        }
        else if (res[2] < (n + 1) / 3) {
          cout << res[2] * 3 + 2;
          res[2]++;
        }
        else {
          cout << res[0] * 3 + 3;
          res[0]++;
        }
      }
      if (i == n - 1) cout << endl;
      else cout << " ";
    }
  }


  
  return 0;
}


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

int main(){
	int a,b,c,cho=0,his=0;
	while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){
		if(a*a+b*b==c*c) cho++;
		else if(a==b) his++;
	}
	cout<<cho<<endl<<his<<endl;
	return 0;
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = std::int64_t;
using vint = std::vector<int>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    int a, b;
    cin >> a >> b;

    int ans = 0;
    if (a >= b) {
        ans += a;
        --a;
    }
    else {
        ans += b;
        --b;
    }

    if (a >= b) {
        ans += a;
        --a;
    }
    else {
        ans += b;
        --b;
    }

    cout << ans << endl;

}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
a, b, c, d = input()
n = 4
answer = ''

for i in range(2 ** (n - 1)):
    ops = ['+', '+', '+']
    for j in range(n - 1):
        if (i >> j) & 1:
            ops[j] = '-'
    if eval(a + ops[0] + b + ops[1] + c + ops[2] + d) == 7:
        print(a+ops[0]+b+ops[1]+c+ops[2]+d+'=7')
        break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };

};

int a,b,c,d,i,n,m,e,k,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
long long o[2][2010][2222];
long long l[2221][2222];
long long s[1];
long long x,y,z,mod=998244353,hf=(mod+1)/2;

//string r,r1;
char r[361];
vector<int> v[1];
P u[1];
queue<int> q;
//set<int> s[2];
//stack<int> s;
map<int,int> p;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng()
bool as(P a,P b)
{
  return a.x<b.x;
}

long long f(int i,int n,int m)
{
  if(m<0) return 0;
  if(n==0) return 1;
  if(m==0) return 0;
  
  if(o[i][n][m]>=0) return o[i][n][m];
  if(i)
  {
    return o[i][n][m]=(f(0,n-1,m)*2+f(1,n,m-1))%mod;
  }
  else
  {
    return o[i][n][m]=(f(i,n-1,m)+f(1,n,m-1))%mod;
  }
}

long long g(int n,int m)
{
  if(m<0) return 0;
  if(n==0) return 1;
  if(m==0) return 0;
  
  if(l[n][m]>=0) return l[n][m];
  return l[n][m]=(g(n-1,m)+g(n,m-1))%mod;
}

int main()
{
  memset(o,-1,sizeof(o));
  memset(l,-1,sizeof(l));
  scanf("%d %d",&b,&a);
  for(int t=2;t<=b*2;t++)
  {
    x=0;
    int p=t/2;
      c=max(min(b,t-1)-p,0);
      //printf("#%d\n",c);
    for(int i=0;i<=a;i++)
    {
      //printf("$%lld\n",f(1,i,c));
      if(t%2) x+=f(1,i,c)*g(a-i,b-c*2)%mod,x%=mod;
      else
      {
        x+=f(1,i,c)*g(a-i,b-c*2-1)%mod,x%=mod;
        if(i<a) x+=f(1,i,c)*g(a-i-1,b-c*2-1)%mod,x%=mod;
      }
    }
    printf("%lld\n",x);
    //if(t%2==0)
    
  }
  //printf("%lld",x);
}



Measured memory_bytes: 108800
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll a, b;
  cin >> a >> b;

  ll num = 0;
  if(b <= 9)
    num = 10*a + b;
  else if(b <= 99)
    num = 100*a + b;
  else
    num = 1000*a + b;

  ll q = 1;
  while(q*q < num) q++;

  if(q*q == num)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>


using  namespace std;

int h,w;
int main(){
  
  while(true){
    cin>>h>>w;
    if(h==0&&w==0) break; 

    for(int i=0;i<h;++i){
      if(i==0||i==h-1){
        for(int j=0;j<w;++j){
          if(j==w-1) {
            cout<<"#"<<endl;
          }else{
            cout<<"#";
          }
        }
      }else{
        for(int j=0;j<w;++j){
          if(j==0) {
            cout<<"#";
          }else  if(j==w-1){
            cout<<"#"<<endl;
          }else{
            cout<<".";
          }
        }
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 1152
from bisect import bisect_right

N,M,K = map(int,input().split())

A = list(map(int,input().split()))
B = list(map(int,input().split()))

for i in range(1,len(A)):
    A[i] += A[i-1]

for i in range(1,len(B)):
    B[i] += B[i-1]

A = [0] + A
B = [0] + B

ans = 0
for i in range(len(A)):
    if K - A[i] > 0:
        ans = max(ans,i + bisect_right(B,K - A[i]) - 1)

for i in range(len(B)):
    if K - B[i] > 0:
        ans = max(ans,i + bisect_right(A,K - B[i]) - 1)

print(ans)


Measured memory_bytes: 40588
package main

import "fmt"
import "container/heap"

type SegmentTree struct {
	dat []int
	n   int
}

var stEven SegmentTree
var stOdd SegmentTree

var intMax int
var maxN int

func stInit(nn int) SegmentTree {
	n := 1
	for n < nn {
		n *= 2
	}
	dat := make([]int, 2*n-1)
	for i := 0; i < 2*n-1; i++ {
		dat[i] = intMax
	}
	return SegmentTree{dat, n}
}

func (st *SegmentTree) update(k, a int) {
	k += (st.n - 1)
	st.dat[k] = a
	for k > 0 {
		k = (k - 1) / 2
		if st.dat[k*2+1] < st.dat[k*2+2] {
			st.dat[k] = st.dat[k*2+1]
		} else {
			st.dat[k] = st.dat[k*2+2]
		}
	}
}

func (st *SegmentTree) query(a, b, k, l, r int) int {
	if (r <= a) || (b <= l) {
		return intMax
	}
	if (a <= l) && (r <= b) {
		return st.dat[k]
	}
	vl := st.query(a, b, k*2+1, l, (l+r)/2)
	vr := st.query(a, b, k*2+2, (l+r)/2, r)
	if vl < vr {
		return vl
	}
	return vr
}

func wrapQuery(t string, a, b, k, l int) int {
	var ret int
	if t == "even" {
		if a%2 == 0 {
			ret = stEven.query(a, b, k, l, stEven.n)
		} else {
			ret = stOdd.query(a, b, k, l, stOdd.n)
		}
	} else {
		if a%2 == 0 {
			ret = stOdd.query(a, b, k, l, stOdd.n)
		} else {
			ret = stEven.query(a, b, k, l, stEven.n)
		}
	}
	return ret
}

type Item struct {
	min   int
	i     int
	left  int
	right int
}

type PriorityQueue []*Item

func (pq PriorityQueue) Len() int {
	return len(pq)
}
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].min < pq[j].min
}
func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}
func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Item))
}
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	x := old[n-1]
	*pq = old[0 : n-1]
	return x
}
func main() {
	intMax = 200001
	maxN = 1 << 17
	var n int
	fmt.Scan(&n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	stEven = stInit(n)
	stOdd = stInit(n)
	h := make(map[int]int)
	for i, v := range arr {
		h[v] = i
		if i%2 == 0 {
			stEven.update(i, v)
		} else {
			stOdd.update(i, v)
		}
	}
	q := make([]int, n)
	pq := &PriorityQueue{}
	heap.Init(pq)
	x := wrapQuery("even", 0, n, 0, 0)
	heap.Push(pq, &Item{x, h[x], 0, n})
	ii := 0
	for pq.Len() != 0 {
		item := heap.Pop(pq).(*Item)
		q[ii] = item.min
		ii++
		q1 := wrapQuery("odd", item.i, item.right, 0, 0)
		j := h[q1]
		q[ii] = q1
		ii++
		if item.i-item.left > 1 {
			x0 := wrapQuery("even", item.left, item.i, 0, 0)
			heap.Push(pq, &Item{x0, h[x0], item.left, item.i})
		}
		if j-(item.i+1) > 1 {
			x1 := wrapQuery("even", item.i+1, j, 0, 0)
			heap.Push(pq, &Item{x1, h[x1], item.i + 1, j})
		}
		if item.right-(j+1) > 1 {
			x2 := wrapQuery("even", j+1, item.right, 0, 0)
			heap.Push(pq, &Item{x2, h[x2], j + 1, item.right})
		}
	}
	for i := 0; i < n-1; i++ {
		fmt.Printf("%d ", q[i])
	}
	fmt.Println(q[n-1])
}


Measured memory_bytes: 27008
#include<iostream>
#include<cmath>
#include<cstring>
#include<deque>
#include<set>
using namespace std;
bool cmp(int a,int b){
	if(a==b)
	return 1;
	return 0;
}
int main(){
    int a,b,c;
    int k=0;
    cin>>a>>b>>c;
    if(cmp(a,b))
    k++;
     if(cmp(a,c))
    k++;
    if(cmp(b,c))
    k++;
    if(k==1)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;

   
	
    
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define M 1046527
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1+(key%(M-1)); }

int find(char str[]){
    long long key,i,h;
    key=getKey(str);
    for(i=0;;i++){
        h=(h1(key)+i*h2(key))%M;
        if(strcmp(H[h],str)==0) return 1;
        else if(strlen(H[h])==0) return 0;
    }return 0;
}

int insert(char str[]){
    long long key,i,h;
    key=getKey(str);
    for(i=0;;i++){
        h=(h1(key)+i*h2(key))%M;
        if(strcmp(H[h],str)==0) return 1;
        else if(strlen(H[h])==0){
            strcpy(H[h],str);
            return 0;
        }
    }return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	    scanf("%s %s", com, str);
	
	    if ( com[0] == 'i' ){
	        insert(str);
	    } 
        else {
	        if (find(str)){
		        printf("yes\n");
	        } 
            else {
		        printf("no\n");
	        }
	    }
    }

    return 0;
}



Measured memory_bytes: 16100
#include <bits/stdc++.h>
#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 999999999
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  int N, K;
  cin >> N >> K;
  char a[50];
  cin >> a;
  K = K-1;
  if(a[K] == 'A'){
    a[K] = 'a';
  }
  if(a[K] == 'B'){
    a[K] = 'b';
  }
  if(a[K] == 'C'){
    a[K] = 'c';
  }
  printf("%s",a);

  return 0;
}

Measured memory_bytes: 256
n,k,q=map(int,input().split())
a=[]
[a.append(int(input())-1) for _ in range(q)]
i=[k-q]*n

for l in range(q):
    i[a[l]] += 1

for l in range(n):
    if i[l] <= 0:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 10528
import java.util.*;

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

    while(sc.hasNext()){
      String s = sc.next();
      String[] ss = s.split("iwi");

      if(ss.length != 2){
        System.out.println(3);
        continue;
      }

      String left = ss[0];
      int n = ss[0].length();
      String right = "";
      int m = ss[1].length();

      for(int i=0;i<m;i++){
        char ch = ss[1].charAt(i);
        char to = ' ';
        switch(ch){
        case '(':
          to = ')';
          break;
        case ')':
          to = '(';
          break;
        case '[':
          to = ']';
          break;
        case ']':
          to = '[';
          break;
        case '{':
          to = '}';
          break;
        case '}':
          to = '{';
          break;
        }

        right += to;
      }

      right = new StringBuilder(right).reverse().toString();

      int[][] dp = new int[n+2][m+2];
      for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
          if(left.charAt(i-1) == right.charAt(j-1)){
            dp[i][j] = Math.max(dp[i-1][j-1]+1,Math.max(dp[i-1][j],dp[i][j-1]));
          }
          else{
            dp[i][j] = Math.max(dp[i-1][j],dp[i][j-1]);
          }
        }
      }

      System.out.println(dp[n][m]*2+3);
    }
  }

}

Measured memory_bytes: 12000
#include <iostream>

using namespace std;

typedef long long ll;

const int MAX_N = 1e5 + 10;

int main(int argc, char const *argv[])
{
    int n;
    ll h[MAX_N];

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

    bool tf = true;

    for (int i = n-1; i > 0 && tf; --i) {
        if (h[i]<h[i-1]) {
            if (h[i-1]-h[i]>1) {
                tf = false;
            }
            else h[i-1]--;
        }
    }

    
    for (int i = 0; i < n-1 && tf; ++i) {
        if (h[i]>h[i+1]) {
            tf = false;
        }
    }

    if (tf) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim() {
    int u, minv;
    int d[MAX], p[MAX], color[MAX];  // dは重みが最小の辺の重み，pはMSTにおける頂点の親を，colorは訪問状態を記録

    for (int i = 0; i < n; i++) {
        d[i] = INFTY;      // 重みは十分に大きい数で初期化
        p[i] = -1;         // 親を初期化
        color[i] = WHITE;  // 訪問してないということで初期化
    }

    d[0] = 0;

    while (1) {
        minv = INFTY;
        u = -1;  // 最小の重みを持つ頂点
        for (int i = 0; i < n; i++) {
            if (minv > d[i] && color[i] != BLACK) {  // d[i]が最小の重みより小さく，iをまだ通ったことがなければ
                u = i;        // 頂点を更新する
                minv = d[i];  // 最小値を更新する
            }
        }
        if (u == -1) {  // 最小値が更新されないときは終了
            break;
        }
        color[u] = BLACK;  // 最小値を持つ頂点を訪問済みにする
        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK & M[u][v] != INFTY) {  // vが訪問済みでなく，uからvに行く重みが更新されているとき
                if (d[v] > M[u][v]) {  // vの最小の重みがuからvへ行くときの重みより大きい時
                    d[v] = M[u][v];  // 最初の重みを更新
                    p[v] = u;  // 頂点の親を変更する
                    color[v] = GRAY;  // vを通ったことにする
                }
            }
        }
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        if (p[i] != -1) {  // MSTにおける頂点の親が-1でなけれが
            sum += M[i][p[i]];  // iからp[i]までの重みをsumに加算する
        }
    }
    return sum;
}

int main() {
    cin >> n;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int e;
            cin >> e;
            M[i][j] = (e == -1) ? INFTY : e;
        }
    }

    cout << prim() << endl;

    return 0;
}


Measured memory_bytes: 3116
#include <string>
#include <queue>
#include <iostream>
using namespace std;
int main()
{
    int n,q,i;
    cin >> n >> q;
    char name[n][10];
    int time[n];
    int sumtime=0,Time;
    queue<int> Q;
    for(i=0;i<n;i++)
    {
        cin >> name[i];
        //while(name[i]!=' ')
        //  cin >> name[i];
        cin >> time[i];
        Q.push(i);
        Q.push(time[i]);
    }
    while(!Q.empty())
    {
        i = Q.front();
        Q.pop();
        Time = Q.front();
        Q.pop();
        if(Time <= q)
        {
            sumtime += Time;
            cout << name[i] << ' ' <<sumtime << endl;
        }
        else    {
                    sumtime += q;
                    time[i] -= q;
                    Q.push(i);
                    Q.push(time[i]);
                }
    }
    return 0;
}


Measured memory_bytes: 4032
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI2(N, K);
  if (K > (N - 1) * (N - 2) / 2) {
    print(-1);
  } else {
    print((N) * (N - 1) / 2 - K);
    for (int i = 1; i <= N - 1; ++i) {
      for (int j = i + 1; j <= N; ++j) {
        if (i != 1 && K > 0) {
          K--;
        } else {
          cout << i << " " << j << endl;
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

using namespace std;
class hitachi2020_a {
public:
	void solve(std::istream& in, std::ostream& out) {
	    string s;
	    in >> s;

	    if((s.length() > 1) && ((s == "hi") || (s == "hihi") || (s == "hihihi") || (s == "hihihihi") || (s == "hihihihihi")))
	        out << "Yes";
        else
            out << "No";
	}
};


int main() {
	hitachi2020_a solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxs 202020
#define mme(i,j) memset(i,j,sizeof(i))
using namespace std;

int main()
{
   long long n,m;
   while(~scanf("%lld%lld",&n,&m))
   {
      long long int tmp = abs(n-m);
       if(tmp<=1)
            puts("Brown");
       else
            puts("Alice");
   }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

killed = 0
reserved_power = 0

if N == 1:
    battle = B[0] - A[0]
    if battle >= 0:
        killed += A[0]
        reserved_power = battle
        killed += min(reserved_power, A[1])
    else:
        killed += B[0]
    print(killed)
    exit()

for i in range(N):

    if i == 0:
        battle = B[i] - A[i]
        if battle >= 0:
            reserved_power = battle
            killed += A[i]
        else:
            reserved_power = 0
            killed += B[i]

    elif i == N - 1:
        other_monster = A[i] - reserved_power
        if other_monster <= 0:
            reserved_power = B[i]
            killed += A[i]
            killed += min(reserved_power, A[i+1])
        else:
            killed += reserved_power
            battle = B[i] - other_monster - A[i+1]
            if battle >= 0:
                killed += other_monster + A[i+1]
            else:
                killed += B[i]

    else:
        other_monster = A[i] - reserved_power

        if other_monster <= 0:
            reserved_power = B[i]
            killed += A[i]
        else:
            killed += reserved_power
            battle = B[i] - other_monster

            if battle >= 0:
                reserved_power = battle
                killed += other_monster
            else:
                reserved_power = 0
                killed += B[i]

print(killed)

Measured memory_bytes: 19776
#include <stdio.h>
#include <stdlib.h>
int bw(const void *a, const void *b)
{
	return *(int*)b - *(int*)a;
}
int main() {
	int n, a[111], ans = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	qsort(a, n, sizeof(int), bw);
	for (int i = 0; i < n; i++)
	{
		ans += (i % 2) ? (-a[i]) : (a[i]);
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll h,w; cin >> h >> w;
    string s[h];
    rep(i,h)cin >> s[i];
    vector<Pll> start;
    rep(i,h)rep(j,w)if(s[i][j] == '.')start.emplace_back(Pll(i,j));

    ll dx[4] = {0,0,1,-1};
    ll dy[4] = {1,-1,0,0};
    ll ans = 0;
    for(auto st : start){
        queue<Pll> que;
        vector<vector<ll>> is_moved(h,vector<ll>(w,0));
        is_moved[st.first][st.second] = 1;
        que.push(st);
        ll max_ = 0;
        while (que.size())
        {
            Pll t = que.front();que.pop();
            ll x = t.first, y = t.second;
            rep(i,4){
                ll nx = x + dx[i];
                ll ny = y + dy[i];
                if(0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] == '.' && is_moved[nx][ny] == 0){
                    is_moved[nx][ny] = is_moved[x][y] + 1;
                    max_ = max(max_, is_moved[nx][ny]);
                    que.push({nx,ny});
                }
            }
        }
        ans = max(ans, max_);
    }

    cout << ans-1 << endl;
}

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

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

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

typedef pair<int, int> pii;

int N, M;
vector<int> code(16);
vector<int> sig(20000);
int score[20005][256];
int val[20005][256];

int main(){
	while(cin >> N >> M and N + M){
		REP(i, M) code[i] = 0;
		REP(i, N) sig[i] = 0;
		REP(i, N+1) REP(j, 256) score[i][j] = INF;
		score[0][128] = 0;
		val[0][128] = 128;
		REP(i, M) cin >> code[i];
		REP(i, N) cin >> sig[i];
		REP(i, N) REP(j, 256){
			if(score[i][j] == INF) continue;
			REP(k, M){
				int tmp = min(255, max(0, val[i][j] + code[k]));
				if(score[i+1][tmp] > score[i][val[i][j]] + (sig[i] - tmp) * (sig[i] - tmp)) {
					score[i+1][tmp] = score[i][val[i][j]] + (sig[i] - tmp) * (sig[i] - tmp);
					val[i+1][tmp] = tmp;
				}
			}
		}
		int minim = INF;
		REP(i, 256) chmin(minim, score[N][i]);
		cout << minim << endl;
	}			
	return 0;
}

Measured memory_bytes: 43192
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;



int main() {
	string s; cin >> s;
	map<char, char> m;
	m['A'] = 'T'; m['T'] = 'A'; m['C'] = 'G'; m['G'] = 'C';
	for (int i = 0; i < (int)s.size(); i++) cout << m[s[i]];
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(void){
	int n;
	scanf("%d",&n);
	int a[n];
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	
	int kisuu=0;
	int ni=0;
	int yon=0;
	for(int i=0;i<n;i++){
		if(a[i]%4==0){yon++;}
		else if(a[i]%2==0){ni++;}
		else{kisuu++;}
	}
	int answer=1;
	if(n%2!=0&&(n-ni+1)/2<kisuu){answer=0;}
	if(n%2==0&&(n-ni)/2<kisuu){answer=0;}
	
	if(answer==1){
		printf("Yes");
	}else{printf("No");}
	return 0;
} 

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << "\n"
constexpr int mod = 1000000007;
using namespace std;
int d, c[30], l[30], s[400][30];
signed main() {
	cin >> d;
	for1(i, 26)cin >> c[i];
	for1(i, d)for1(j, 26)cin >> s[i][j];
	for1(i, d) {
		int p = 0, k = -mod;
		for1(j, 26) {
			int kj = s[i][j] + c[j] * (i - l[j]) * 2.68 + c[j] * 13.5;
			if (kj > k) { p = j; k = kj; }
			else if (kj == k && c[j] > c[p])p = j;
		}
		puts(p); l[p] = i;
	}
}

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

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

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

  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  int odd = 0, div2 = 0, div4 = 0;
  rep(i, n) {
    if(a[i]%4 != 0 && a[i]%2 == 0) div2++;
    if(a[i]%4 == 0) div4++;
    if(a[i]&1) odd++;
  }
  if(odd == 0) {
    cout << "Yes" << '\n';
    return 0;
  }

  int foundDiv2 = 0;
  if(div2 == 0) foundDiv2++;
  cout << (div4+foundDiv2 >= odd ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
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;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

vector<vector<int>> ans;

void dfs(int d, int bef, vector<int> &v, int n, int m) {
    if(d == n) {
        ans.emplace_back(v);
        return;
    }
    for(int i = bef; i <= m; i++) {
        v[d] = i;
        dfs(d + 1, i, v, n, m);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> a(q), b(q), c(q), d(q);
    for(int i = 0; i < q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    vector<int> v(n, 1);
    dfs(0, 1, v, n, m);
    ll res = 0;
    for(const auto &A : ans) {
        ll tmp = 0;
        for(int i = 0; i < q; i++) {
            if(A[b[i] - 1] - A[a[i] - 1] == c[i]) {
                tmp += d[i];
            }
        }
        chmax(res, tmp);
    }
    print(res);
}

Measured memory_bytes: 9828
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long k = sc.nextLong();
      int[] arr = new int[n+1];
      for(int i = 1; i <= n; i++)
        arr[i] = sc.nextInt();

      int fast = 1;
      int slow = 1;
      long moves = 0;
      while(true) {
        fast = arr[arr[fast]];
        slow = arr[slow];
        moves++;
        if(fast == slow) break;
      }

      fast = 1;
      while(fast != slow && k > 0) {
        fast = arr[fast];
        slow = arr[slow];
        k--;
      }

      k %= moves;
      while(k > 0) {
        fast = arr[fast];
        k--;
      }
      System.out.println(fast);
  }
}


Measured memory_bytes: 50152
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define N 100005
#define mod 1000000007
 
 
int main() 
{
    int x,a,b,f[26]={};
    
    string s;
    cin>>s;
    
    
    for(a=0;s[a];a++)
    f[s[a]-'a']++;
    
    for(a=0;a<26;a++)
    {
        if(!f[a])
        {
        cout<<char(a+97)<<endl;
        return 0;
        }
    }
    cout<<"None"<<endl;
    return 0;
}

Measured memory_bytes: 512
n = gets.chomp.to_i

def maxnum(n)
  (Math.log(3*n+1)/Math.log(4.0)).ceil
  # (Math.log(3*n/2.0+1)/Math.log(10.0)).to_i
end

# print(maxnum(n))

def minnum(n)
  (Math.log(3*n/2.0+1)/Math.log(4.0)).ceil
end
#
def count(input_num,sum)
  # p [input_num,sum]
  if input_num>0
    ketasu = 2*maxnum(input_num)-2
    sum += 10 ** ketasu
    count(input_num-2**ketasu,sum)
  elsif input_num < 0
    ketasu = 2*minnum(input_num.abs)-1
    sum += 10 ** ketasu
    count(input_num+2**ketasu,sum)
  else
    return sum
  end
end


puts count(n,0)


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define print(x) cout<<(x)<<'\n'
using ll=long long;
using pl=pair<ll,ll>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vs=vector<string>;
 
void solve() {
    ll n;
    cin >> n;
    vl num(4);
    rng(i,0,4){
        num[3-i] = n % 10;
        n /= 10;
    }
    int len = 3;
    vector<char> op(len);
    for(int bit=0; bit < (1<<(len)); bit++) {
        ll res = num[0];
        rng(j,0,len) {
            if(bit & (1<<j)) {
                op[j] = '+';
                res += num[j+1];
            }else{
                op[j] = '-';
                res -= num[j+1];
            }
        }
        if(res == 7) {
            break;
        }
    }
    cout << num[0];
    rng(i,0,3){
        cout << op[i] << num[i+1];
    }
    cout << "=7" << '\n';
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 3656
import itertools

N, M, X = map(int, input().split())
C = []
A = []
for i in range(N):
    x = [int(i) for i in input().split()]
    c, a = x[0], x[1:]
    C.append(c)
    A.append(a)
over = 1000000000
ans = over
for Z in itertools.product(range(0, 2), repeat=N):
    ctotal = 0
    atotal = [0] * M
    for i in range(N):
        if Z[i] == 1:
            ctotal += C[i]
            for j in range(A[i].__len__()):
                atotal[j] += A[i][j]
    ok = True
    for a in atotal:
        if a < X:
            ok = False
    if ok:
        ans = min(ans, ctotal)

if ans == over:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 68508
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
ll a[N];
int32_t main(){
    ll n,m;
    cin >> n >> m;
    for (int i=1;i<=2*n;i++){
        cin >> a[i];
    }
    sort(a+1,a+2*n+1);
    ll l=-1,r=n;
    while(r-l>1){
        ll mid=(r+l)/2;
        ll p1=0,ma=0;
        for (int i=1;i<=mid;i++){
            ll z=2*mid-i+1;
            if (a[z]+a[i]>=m) p1=1;
            ma=max(ma,a[z]+a[i]);
        }
        if (p1){
            r=mid;
            continue;
        }
        ll t=2*mid+2*n;
        t/=2;
        for (int j=2*mid+1;j<=t;j++){
            ll z=2*n-j+2*mid+1;
            if (a[z]+a[j]<m) p1=1;
            ma=max(ma,(a[z]+a[j])%m);
        }
        if (!p1) r=mid;
        else l=mid;
    }
    ll mid=r;
    ll ma=0;
    for (int i=1;i<=mid;i++){
        ll z=2*mid-i+1;
        ma=max(ma,a[z]+a[i]);
    }
    ll t=2*mid+2*n;
    t/=2;
    for (int j=2*mid+1;j<=t;j++){
        ll z=2*n-j+2*mid+1;
        ma=max(ma,(a[z]+a[j])%m);
    }
    cout << ma << endl;
}


Measured memory_bytes: 1792
import scala.io.StdIn.{readInt, readLine};
import scala.collection.mutable.PriorityQueue;

object Main {
    def main(args: Array[String]): Unit = {
        val n = readInt;
        val ig = new IntGraph(n);
        for (i <- (0 until n)) {
            val line = readLine.split(" ").map(_.toInt);
            val src = line(0);
            val dstNum = line(1);
            for (j <- (0 until dstNum)) {
                val dst = 2 + (2 * j);
                val cost = 2 + (2 * j) + 1;
                ig.add(src, line(dst), line(cost));
            }
        }
        ig.shortestPath(0).zipWithIndex.foreach { e => println("%d %d".format(e._2, e._1))};
    }
}

class IntGraph(size: Int) {
    val m: Array[List[(Int, Int)]] = new Array[List[(Int, Int)]](size).map(e => Nil);
    def add(src: Int, dst: Int, cost: Int): Unit = m(src) = (dst, cost) :: m(src);
    def shortestPath(start: Int): Array[Int] = {
        val stat = new Array[Int](size); // 0: 未追加, 1: 追加済み
        val dist = new Array[Int](size).map( e => Int.MaxValue);
        val pq = new PriorityQueue[(Int, Int)]()(Ordering.by((e: (Int, Int)) => e._2).reverse);
        var cnt = 0;
        
        dist(start) = 0;
        pq.enqueue((start, dist(start)));
        while (cnt < size && pq.isEmpty == false) {
            val (src, srcCost) = pq.dequeue;
            if (stat(src) != 1) {
                stat(src) = 1;
                cnt += 1;
                for ((dstIdx, dstCost) <- m(src)) {
                    val newCost = dstCost + srcCost;
                    if (stat(dstIdx) != 1 && newCost < dist(dstIdx)) {
                        dist(dstIdx) = newCost;
                        pq.enqueue((dstIdx, newCost));
                    }
                }
            }
        }
        dist;
    }
}


Measured memory_bytes: 181888
def main():
    N = int(input())
    s = input()
    #0 sheep 1 wolf
    for i in [[0,0],[0,1],[1,0],[1,1]]:
        t = i[:]
        for j in s[1:]:
            if t[-1] == 0:
                if j == 'o':
                    t.append(t[-2])
                else:
                    t.append(1-t[-2])
            elif j == 'o':
                t.append(1-t[-2])
            else:
                t.append(t[-2])
        if t[-1] == t[0]:
            if s[0] == 'o' and t[0] == 0 and t[1] != t[-2]:
                continue
            if s[0] == 'o' and t[0] == 1 and t[1] == t[-2]:
                continue
            if s[0] == 'x' and t[0] == 0 and t[1] == t[-2]:
                continue
            if s[0] == 'x' and t[0] == 1 and t[1] != t[-2]:
                continue
            print(''.join(['S' if i == 0 else 'W' for i in t[:-1]]))
            return
    print(-1)
    return
main()


Measured memory_bytes: 11304
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;
const int MAX_N=50;
int N,D[MAX_N],V;
vector<int> G[MAX_N*2],rG[MAX_N*2];
bool used[MAX_N*2];
int scccmp[MAX_N*2];
vector<int> vs;
void add_edge(int s,int t){
	G[s].push_back(t);
	rG[t].push_back(s);
}
void dfs(int v){
	used[v]=true;
	for(auto e:G[v]){
		if(!used[e]){
			dfs(e);
		}
	}
	vs.push_back(v);
}
void dfs2(int v,int k){
	used[v]=true;
	scccmp[v]=k;
	for(auto e:rG[v]){
		if(!used[e]){
			dfs2(e,k);
		}
	}
}
void scc(){
	int V=N*2;
	memset(used,false,sizeof(used));
	vs.clear();
	REP(i,V){
		if(!used[i]){
			dfs(i);
		}
	}
	reverse(vs.begin(),vs.end());
	memset(used,false,sizeof(used));
	int k=0;
	for(auto v:vs){
		if(!used[v]){
			dfs2(v,k);
			k++;
		}
	}
}
int tmdif(int t1,int t2){
	int d=abs(t1-t2);
	return min(d,24-d);
}
bool C(int x){
	REP(i,N){
		REP(j,N){
			if(i==j)continue;
			REP(a,2)REP(b,2){
				int t1=(a==0 ? D[i] : 24-D[i]),t2=(b==0 ? D[j] : 24-D[j]);
				if(tmdif(t1,t2)<x){
					add_edge(i+a*N,j+(1-b)*N);
					add_edge(j+b*N,i+(1-a)*N);
				}
			}
		}
	}
	scc();
	REP(i,N){
		if(scccmp[i]==scccmp[i+N]){
			return false;
		}
	}
	return true;
}
int main(){
	cin>>N;
	V=N*2;
	REP(i,N)cin>>D[i];
	int md=13;
	REP(i,N)md=min(md,D[i]);
	int ans=0;
	FOR(i,1,md+1){
		if(C(i)){
			ans=i;
		}
	}
	cout<<ans<<endl;
}

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

int main(void) {
  string S;
  string hi = "hi";
  cin >> S;
  bool ans = S.length() % 2 == 0;
  for (int i = 0; i < S.length(); i++) {
    ans &= S[i] == hi[i % 2];
  }
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#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,n,m) for(int i = (n); i < (m); i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#pragma endregion

//UnionFind
class UnionFind {
private:
    vector<int> par;
public:
    UnionFind(int n) {
        par = vector<int>(n, -1);
    }

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (size(rx) < size(ry)) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    int N, M; cin >> N >> M;
    vector<int> p(N);
    UnionFind uni(N);
    REP(i, N) cin >> p[i];
    REP(i, M) {
        int x, y; cin >> x >> y;
        x--; y--;
        uni.unite(x, y);
    }
    int ans = 0;
    REP(i, N) {
        if (uni.same(p[i]-1, i)) ans++;
    }
    cout << ans << endl;
    getchar(); getchar();
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char a[100]={0},k[4]={"ABC"},b[4]={0};
    int n,i,j,s=0;
    scanf("%d",&n);
    getchar();
    for(i = 0;i < n;i++)
        scanf("%c",&a[i]);
    for(i = 0;i < n-2;i++)
    {
        for(j = 0;j < 3;j++)
            b[j] = a[i+j];
        b[j]=0;
        if(strcmp(b,k) == 0) s++;
    }
    printf("%d\n",s);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(true){
            int a=scan.nextInt();
            int b=scan.nextInt();
            if(a == 0)break;
            for(int j=0;j<a;j++){
                for(int k=0;k<b;k++){
                    System.out.printf("#");
                }
                System.out.println("");
            }
            System.out.println("");
        }

        scan.close();
        return;
    }
}


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

int main() {
	int W, H, N;
	cin >> W >> H >> N;
	vector<vector<int>> data(W, vector<int>(H));
	for (int i = 0; i < N; ++i) {
		int x, y, a;
		cin >> x >> y >> a;
		x--; y--;
		if (1 == a) {
			for (int j = 0; j < W; ++j) {
				for (int k = 0; k < H; ++k) {
					if (j <= x) {
						data[j][k] = 1;
					}
				}
			}
		}
		else if (2 == a) {
			for (int j = 0; j < W; ++j) {
				for (int k = 0; k < H; ++k) {
					if (j > x) {
						data[j][k] = 1;
					}
				}
			}
		}
		else if (3 == a) {
			for (int j = 0; j < W; ++j) {
				for (int k = 0; k < H; ++k) {
					if (k <= y) {
						data[j][k] = 1;
					}
				}
			}
		}
		else {
			for (int j = 0; j < W; ++j) {
				for (int k = 0; k < H; ++k) {
					if (k > y) {
						data[j][k] = 1;
					}
				}
			}
		}
	}
	int ans = 0;
	for (int j = 0; j < W; ++j) {
		for (int k = 0; k < H; ++k) {
			if (0 == data[j][k]) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
    int i,n;
  	cin>>n;
  	int s[4]={0,0,0,0};
  	string str[n];
    
	for(i=0;i<n;i++)
      cin>>str[i];
  
  	for(i=0;i<n;i++)
    {
      if(str[i]=="AC")
         s[0]++;
      if(str[i]=="WA")
         s[1]++;
      if(str[i]=="TLE")
         s[2]++;
      if(str[i]=="RE")
         s[3]++;
     }
     cout<<"AC x "<<s[0]<<endl;
     cout<<"WA x "<<s[1]<<endl;
     cout<<"TLE x "<<s[2]<<endl;
     cout<<"RE x "<<s[3]<<endl;
         
	return 0;
}






Measured memory_bytes: 6780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
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;
}

signed main()
{
  int L;
  cin >> L;
  int N,M;
  int num;//L-1の前から2番目のビットを格納、ここまでは2進数でエッジを張れば良い
  REP(i,20)
    if((L-1)&(1<<i)) num = i;
  num--;
  num = max(0LL,num);//L>=2なので
  if(L==(1<<(num+2)))
    num++;
  N = 1 + (num+1);//ノード数は確定
  M = 0;//追加本数
  int now = ((1<<(num+1)) -1);//現在表現できる数を格納
  int ans[60][3];
  int res = (L-1)-now;//足りない分
  int tmp;
  while(res>0){
    REP(i,20)
      if(res&(1<<i)) tmp = i;
    tmp--;
    ans[M][0] = tmp +2;
    ans[M][1] = N;
    ans[M][2] = now + 1;
    M++;
    now += (1<<(tmp+1));
    res = (L-1)-now;
  }
  cout<<N<<" "<<2*(num+1)+M<<endl;
  REP(i,num+1){
    cout<<i+1<<" "<<i+2<<" "<<0<<endl;
    cout<<i+1<<" "<<i+2<<" "<<(1<<i)<<endl;
  }
  REP(i,M)
    cout<<ans[i][0]<<" "<<ans[i][1]<<" "<<ans[i][2]<<endl;
}


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

namespace ConsoleApplication6
{

    class Program
    {
        static void Main(string[] args)
        {
            var D = c2i(RL());
            var cnt =D % 1000;
            if (cnt != 0) cnt = 1000 - cnt;


            Console.WriteLine(cnt);
            Console.ReadLine();

        }

        static IEnumerable<int> RL2IE() { return spr(RL()).Select(x => (int)c2i(x)); }
        static string RL() { return Console.ReadLine().Trim(); }
        static IEnumerable<string> spr(string s) { return s.Split(' '); }
        static Int64 c2i(string c) { return Int64.Parse(c); }
        //static double c2d(string c) { return double.Parse(c); }
        static string bool2ret(bool b) { return b ? "Yes" : "No"; }
    }
}


Measured memory_bytes: 27536
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        A: i64,
        B: i64,
        _C:i64,
        K:i64,
    }

    let mut ans = 0;
    let mut rest = K;
    // Aを使いきって終わり
    if rest <= A {
        ans += rest;
        println!("{}", ans);
        return;
    }

    rest -= A;
    ans += A;

    // Bを使いきって終わり
    if rest <= B {
        println!("{}", ans);
        return;
    }

    rest -= B;

    // やむを得ずCを使う
    ans -= rest;

    println!("{}", ans);
}


Measured memory_bytes: 2156