akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    def __init__(self, N):
        # 親の場合は -{その集合のサイズ}
        self.parent = [-1 for _ in range(N)]

    def root(self, A):
        if self.parent[A] < 0:
            return A
        self.parent[A] = self.root(self.parent[A])
        return self.parent[A]

    def size(self, A):
        return -self.parent[self.root(A)]

    def connect(self, A, B):
        A = self.root(A)
        B = self.root(B)

        if A == B:
            return False

        if self.size(A) < self.size(B):
            A, B = B, A

        self.parent[A] += self.parent[B]
        self.parent[B] = A
        return True


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

A = []
B = []
for _ in range(M):
    a_i, b_i = map(int, input().split())
    A.append(a_i)
    B.append(b_i)

uni = UnionFind(N)
v = N * (N - 1) // 2
ans_list = [v]
for i in reversed(range(1, M)):
    a_i = A[i] - 1
    b_i = B[i] - 1
    if uni.root(a_i) != uni.root(b_i):
        v -= uni.size(a_i) * uni.size(b_i)
        uni.connect(a_i, b_i)
    ans_list.append(v)

ans_list = reversed(ans_list)
for i, ans in enumerate(ans_list):
    print(ans)

Measured memory_bytes: 18232
package main

import "fmt"

func main() {
	var s string
	var m int

	for {
		fmt.Scan(&s)
		if s == "-" {
			break
		}
		fmt.Scan(&m)
		for i := 0; i < m; i++ {
			var h int
			fmt.Scan(&h)
			s = s[h:] + s[:h]
		}
		fmt.Println(s)
	}
}


Measured memory_bytes: 1112
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		String S = sc.next();

		int count = 0;
		for(int i=0 ; i<S.length()/2; i++) {
			if(S.substring(i, i+1).equals(S.substring(S.length()-i-1,S.length()-i))) {
				continue;
			} else {
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 22740
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	int tmp = 0;
	int tmp2 = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
		if (tmp < a[i]) {
			tmp2 = tmp;
			tmp = a[i];
		}
		else if (tmp2 < a[i]) {
			tmp2 = a[i];
		}
	}
	int counter = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == tmp) counter++;
	}
	if (counter == 1) {
		for (int i = 0; i < n; i++) {
			if (a[i] == tmp) {
				cout << tmp2 << endl;
			}
			else {
				cout << tmp << endl;
			}
		}
	}
	else {
		for (int i = 0; i < n; i++) {
			cout << tmp << endl;
		}
	}

	return 0;
}

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

int main()
{
    long long K;
    cin >> K;

    long long ans = 0;
    for (long long i = 1; i <= K; i++)
    {
        for (long long j = 1; j <= K; j++)
        {
            for (long long k = 1; k <= K; k++)
            {
                ans += gcd(gcd(i, j), k);
            }
        }
    }
    cout << ans << endl;
}


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

result = set()
wr = {}
c_cnt = 0
w_cnt = 0
for i in range(m):
    p, s = input().split()
    if (p in result):
        continue

    if (s == 'AC'):
        result.add(p)
        w_cnt = wr.get(p, 0) + w_cnt
    else:
        wr[p] = wr.get(p, 0) + 1

print('{} {}'.format(len(result), w_cnt))


Measured memory_bytes: 14052
S = ["A","B","C","D","E"]
while True:
    L = []
    a,p = map(int,input().split())
    if a == 0:
        break
    L.append(a+p)
    for i in range(4):
        a,p = map(int,input().split())
        L.append(a+p)
    m = max(L)
    s = L.index(m)
    print(S[s],m)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=n-1;i > m;i--)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define RS(n) sort(n.begin(), n.end());reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
int main(){
  lli A,B,C=INF,D=0,E=0,F=INF,G=INF,H=0,N,M,K,S;
  cin >> A >> B;
  C=A-1;D=B;A--;
  if(C%2==0)C--;
  if((C+1)%4==0)C=0;
  else C=1;
  if(A%2==0)C=C^A;
  if(D%2==0)D--;
  if((D+1)%4==0)D=0;
  else D=1;
  if(B%2==0)D=D^B;
  D=D^C;
  Out(D);
}

Measured memory_bytes: 384
#include <stdio.h>
#define N 101

int main(){

  int u,k,i,j,v,n;
  int a[N][N];
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      a[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      a[u-1][v-1]=1;
    }
  }
  
  for(i=0;i<n;i++){
    for(j=0;j<n-1;j++){
      printf("%d ",a[i][j]);
    }
    printf("%d\n",a[i][n-1]);
  }

  return 0;

}
  

Measured memory_bytes: 2676
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
	string s;
	int k;
	vector<string> sub;
	cin >> s >> k;
	for(int i = 0;i < s.length();++i){
		for(int j = 1;j <= k;++j){
			sub.push_back(s.substr(i, j));
		}
	}
	sort(sub.begin(), sub.end());
	vector<string>::iterator it = unique(sub.begin(), sub.end());
	sub.erase(it, sub.end());
	cout << sub[k - 1] << endl;
	return 0;
}


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

using namespace std;
using ll = long long;

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

int main() {
  int n;
  cin >> n;
  cout << (ll)n * (n - 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, x, n) for(int i = x; i < (int)(n); i++)
#define ALL(n) begin(n), end(n)
//struct cww{cww(){ios::sync_with_stdio(false);cin.tie(nullptr);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
const double PI = acos(-1);

int main() {
  int a, b, h, m;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &h);
  scanf("%d", &m);

  double x1 = a * sin(PI * (h + m / 60.0) / 6.0);
  double y1 = a * cos(PI * (h + m / 60.0) / 6.0);
  double x2 = b * sin(PI * m / 30.0);
  double y2 = b * cos(PI * m / 30.0);

  double d = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));

  printf("%.12lf\n", d);
  return 0;
}


Measured memory_bytes: 4188
#include <iostream>
#include <string>

using namespace std;

char s[100010] = {};

int main()
{
	long long i = 0, j = 0, ans = 0;
	for (i = 0; i < 100010; i++)
	{
		s[i] = getchar();
		if (s[i] == '\n') break;
	}
	i--;
	while (i != j && i > j)
	{
		if (s[j] == s[i])
		{
			i--;
			j++;
		}
		else if(s[j] != 'x' && s[i] != 'x')
		{
			ans = -1;
			break;
		}
		else
		{
			if (s[j] == 'x')
			{
				j++;
				ans++;
			}
			else if (s[i] == 'x')
			{
				i--;
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
package main

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

func main() {
	sc := NewScanner(os.Stdin)
	S := sc.Next()
	var ans int = 10000000
	var cnt int = 0
	for i, s := range S {
		if i%2 == 0 && s == '1' {
			cnt++
		}
		if i%2 == 1 && s == '0' {
			cnt++
		}
	}
	ans = min(ans, cnt)
	cnt = 0
	for i, s := range S {
		if i%2 == 1 && s == '1' {
			cnt++
		}
		if i%2 == 0 && s == '0' {
			cnt++
		}
	}
	ans = min(ans, cnt)
	fmt.Println(ans)
}

func vmin(v []int) int {
	mn := math.MaxInt32
	for i := 0; i < len(v); i++ {
		mn = min(mn, v[i])
	}
	return mn
}

func gcd(x, y int) int {
	if y > 0 {
		return gcd(y, x%y)
	}
	return x
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

func max64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// scanner
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner(r io.Reader) *Scanner {
	rdr := bufio.NewReaderSize(r, 1024)
	return &Scanner{r: rdr}
}

func (s *Scanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		line, isp, err := s.r.ReadLine()
		if err != nil {
			os.Exit(1)
		}
		s.buf = append(s.buf, line...)
		if !isp {
			break
		}
	}
}

func (s *Scanner) NextInt64() int64 {
	i, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextInt() int {
	i, err := strconv.Atoi(s.Next())
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextFloat64() float64 {
	i, err := strconv.ParseFloat(s.Next(), 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	next := string(s.buf[start:s.p])
	s.p++
	return next
}

func (s *Scanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define lli long long int
using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int a, arr[20002]; cin>>a;
	
	int num=0, cur=1;
	for(int i=0; i<a; i++){
		int b; cin>>b;
		if(b==cur){
			num++;
			cur++;
		}
	}
	
	if(num) cout<<a-num<<endl;
	else cout<<"-1"<<endl;

	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <queue>

using namespace std;

int main(){
    int temp;
    priority_queue<int, vector<int>, greater<int>> que;
    for(int i = 0; i < 3; i++){
        cin >> temp;
        que.push(temp);
    }
    
    int ans = 1;
    for(int i = 0; i < 2; i++){
        temp = que.top();
        que.pop();
        ans *= temp;
    }
    ans /= 2;
    
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

def dfs(GF,group,gn,i):
    size = 1
    group[i]=gn
    for node in GF[i]:
        if group[node]==-1:
            group[node]=gn
            size+=dfs(GF,group,gn,node)
    return size

def main():
    from sys import stdin
    n,m,k = map(int,stdin.readline().rstrip().split())
    F=[]
    for _ in range(m):
        F.append(list(map(int,stdin.readline().rstrip().split())))
    GF = [[] for _ in range(n+1)]
    for a,b in F:
        GF[a].append(b)
        GF[b].append(a)
    
    B=[]
    for _ in range(k):
        B.append(list(map(int,stdin.readline().rstrip().split())))
    GB = [[] for _ in range(n+1)]
    for a,b in B:
        GB[a].append(b)
        GB[b].append(a)    

    U = []
    group= [-1]*(n+1)
    gn = 0

    for i in range(1,n+1):
        if group[i] == -1:
            sz = dfs(GF,group,gn,i)
            gn+=1
            U.append(sz)
    
    for i in range(1,n+1):
        g = group[i]
        ans = U[g]-1-len(GF[i])

        for b in GB[i]:
            if group[b]==g:
                ans-=1
        print(ans,end=" ")
main()

Measured memory_bytes: 93000
#include<stdio.h>

void square(int *p,int num,int n){
	int i,sum=0;
	int *newp;
	for(i=0;i<num;i++){
		sum+=*(p+i);
	}
	if(sum==n){
		printf("%d",*p);
		for(i=1;i<num;i++){
			printf(" %d",*(p+i));
		}
		printf("\n");
	}else{
		newp=(int *)malloc(sizeof(int)*(num+1));
		for(i=0;i<num;i++){
			*(newp+i)=*(p+i);
		}
		for(i=(*(p+num-1)>n-sum)?n-sum:*(p+num-1);i>0;i--){
			*(newp+num)=i;
			square(newp,num+1,n);
		}
		free(newp);
	}
}

int main(){
	int n,i,p,j;
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++){
			p=n-i;
			square(&p,1,n);
		}
		scanf("%d",&n);
	}
	return 0;
}

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


int main()
{

    long long a,b,c,d,x,y,p,q;
    cin>>a>>b>>c>>d;
    x=a*c;
    y=a*d;
    p=b*c;
    q=b*d;
    cout<<max(x,max(y,max(p,q)))<<endl;

    return 0;
}


Measured memory_bytes: 3628
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N, X;
    cin >> N >> X;

    int ans = 1;
    ll c = 0;
    REP(i, N) {
        int l; cin >> l;
        c += l;
        if (c > X) break;
        ans++;
    }

    print(ans);

}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
using namespace std;
int main(){
    int a[5], b[5], m=10, ans=0;
    for(int i=0; i<5;++i){
        cin >> a[i];
        if(a[i]%10==0)b[i]=a[i];
        else{
            b[i] = a[i]+(10-a[i]%10); 
            m = min(m,a[i]%10);
        } 
        ans += b[i]; 
    }   
    ans += m - 10;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
long long item_value[3000][3000];
long long dp[3000][3000][4];
int main(){
  int R;
  int C;
  int K;
  cin >>R >> C >> K;
  for(int i = 0; i < K; i++){
    int r;
    int c;
    long long v;
    cin >> r >> c >> v;
    item_value[r - 1][c - 1] = v;
  }

  for(int i = 0; i < R; i++){
    for(int j = 0; j < C; j++){
      for(int k = 0; k < 4; k++){
        dp[i][j][k] = LLONG_MIN;
      }
    }
  }

  dp[0][0][0] = 0;
  for(int i = 0; i < C; i++){
    if(i != 0){
      for(int j = 0; j < 4; j++){
        dp[0][i][j] = dp[0][i - 1][j];
      }
    }
    if(item_value[0][i] > 0){
      for(int j = 3; j > 0; j--){
        if(dp[0][i][j - 1] != LLONG_MIN){
          dp[0][i][j] = max(dp[0][i][j], dp[0][i][j - 1] + item_value[0][i]);
        }
      }
    }
  }

  for(int i = 1; i < R; i++){
    for(int j = 0; j < C; j++){
      long long max_prev_dp = LLONG_MIN;
      for(int k = 0; k < 4; k++){
        max_prev_dp = max(max_prev_dp, dp[i - 1][j][k]);
      }
      //cout << i << " " << j << " " << max_prev_dp << endl;

      for(int k = 0; k < 4; k++){
        if(k == 0){
          dp[i][j][k] = max_prev_dp;
        }
        if(j != 0 && dp[i][j - 1][k] != LLONG_MIN){
          dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k]);
        }
      }
      if(item_value[i][j] > 0){
        for(int k = 3; k > 0; k--){
          if(dp[i][j][k - 1] != LLONG_MIN){
            dp[i][j][k] = max(dp[i][j][k], dp[i][j][k - 1] + item_value[i][j]);
          }
        }
      }
    }
  }

  long long ans = 0;
  for(int i = 0; i < 4; i++){
    ans = max(ans, dp[R - 1][C - 1][i]);
  }
  /*
  for(int i = 0; i < R; i++){
    for(int j = 0; j < C; j++){
      cout << dp[i][j][2] << " ";
    }
    cout << endl;
  } 
  */
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;

int main() {
	ll a, b, k;
  	cin >> a >> b >> k;
  	ll x = min(a, k);
  	a -= x;
  	k -= x;
  	x = min(b, k);
  	b -= x;
  	k -= x;
  	cout << a << " " << b << "\n";
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		InputReader r = new InputReader(System.in);
		char[] arr = r.next().toCharArray();
		boolean north = false, east = false, south = false, west = false;
		for (int i = 0; i < arr.length; i++) {
			if (arr[i] == 'N') {
				north = true;
			} else if (arr[i] == 'S') {
				south = true;
			} else if (arr[i] == 'E') {
				east = true;
			} else {
				west = true;
			}
		}
		if (!(north ^ south) && !(east ^ west))
			System.out.println("Yes");
		else
			System.out.println("No");
	}

	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}

		public InputReader(FileReader stream) {
			reader = new BufferedReader(stream);
			tokenizer = null;
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

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

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


Measured memory_bytes: 7636
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m;
vector<ll> h;
vector<vector<ll>>v;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    v.resize(n);
    h.resize(n);
    rep(i,n)cin>>h[i];
    rep(i,m){
        ll temp,temp1;
        cin>>temp>>temp1;
        temp--;
        temp1--;
        v[temp].push_back(temp1);
        v[temp1].push_back(temp);
    }
    int ans=0;
    rep(i,n){
        bool check=false;
        rep(j,v[i].size()){
            if(h[i]<=h[v[i][j]])check=true;
        }
        if(!check)ans++;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 9772
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define p pair<string,int>
int N;
vector<p> a, b;
int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        string S;
        int P;
        cin >> S >> P;
        a.push_back({S, -P});
        b.push_back({S, -P});
    }
    sort(a.begin(), a.end());
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(a[i] == b[j]) cout << j + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  char we[6];
  scanf("%6s",we);
  if (we[0] == 'S') {
    puts("Cloudy");
  } else if (we[0] == 'R') {
    puts("Sunny");
  } else {
    puts("Rainy");
  }
  return 0;
}

Measured memory_bytes: 1644
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int LEN = 0;

	void doIt() {
		System.out.println((sc.nextInt() + sc.nextInt() + sc.nextInt() > 21)?"bust":"win");
	}

	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 21844
N = int(input())
A = []
A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))
root = []
rtcnt = 0
for i in range(N):
    rtcnt += A[1][i]
rtcnt += A[0][0]
root.append(rtcnt)
for i in range(1, N):
    rtcnt = root[i - 1]
    rtcnt -= A[1][i - 1]
    rtcnt += A[0][i]
    root.append(rtcnt)
print(max(root))


Measured memory_bytes: 3064
t = int(input())
for _ in range(t):
    n, a, b, c, d = map(int, input().split())

    dp = {0:0, 1:d}

    def find_cost(x):
        ls = [a, b, c]
        ss = [2, 3, 5]
        cost = d * x
        for l, s in zip(ls, ss):
            if x in dp:
                return dp[x]
            div, mod = divmod(x,s)
            tmp = mod * d + l
            cost = min(cost, tmp + find_cost(div))
            if mod == 0:
                continue
            tmp = (s - mod)*d + l
            cost = min(cost, tmp + find_cost(div+1))
        dp[x] = cost
        return cost
    print(find_cost(n))

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

using namespace std;

int main(){
  
  string g;
  int y,m,d;
  
  while(1){
	cin >> g >> y >> m >> d;
	
	if(g == "#")
	  break;
	
    if(y > 31 || (y == 31 and m > 4))
	  printf("? %d %d %d\n",y-30,m,d);
	else
	  printf("HEISEI %d %d %d\n",y,m,d);
  }
}
		  



Measured memory_bytes: 3224
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define ll long long
#define uint unsigned int
#define c_double static_cast<double>
using namespace std;

void problem_A() {
	string S;
	cin >> S;

	for (unsigned int i = 0; i < S.size() - 1; i++) {
		if (S.at(i) == S.at(i + 1)) {
			cout << "Bad" << endl;
			return;
		}
	}
	cout << "Good" << endl;
	return;
}
int main() {
	problem_A();
}

Measured memory_bytes: 256
from collections import Counter


def main():
    n = int(input())
    c = [input()]
    for _ in range(n - 1):
        now = input()
        if now != c[-1]:
            c.append(now)
    mod = 10 ** 9 + 7
    memo = Counter(c)
    # memo[i] := 色がiであるような石jについてのdp[j]の値の合計値（適宜更新する）
    for k in memo.keys():
        memo[k] = 0
    dp = [0 for _ in range(2 * 10 ** 5 + 10)]
    dp[0] = 1
    for i in range(len(c)):
        dp[i + 1] += memo[c[i]] + dp[i]
        # それ以前のdp[i]通りに加えて，c[i] -- (0 <= j < i and c[i] == c[j])間の
        # memo[c[i]]通りの区間の両端を定めることができるから，この遷移式が成り立つ．
        memo[c[i]] += dp[i]
        dp[i + 1] %= mod
        memo[c[i]] %= mod
    print(dp[len(c)])


if __name__ == '__main__':
    main()


Measured memory_bytes: 40136
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>

using namespace std;

template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vector<T>>;
using ll = long long;
using ld = long double;

#define REP(i, s, e) for (ll i = (s); i < (e); ++i)

int main()
{
    cin.tie(0);
    
    int N; cin >> N;
    vec<int> t(N);
    REP(i, 0, N) 
    {
        int a; cin >> a;
        t[a - 1] = i + 1;
    }
    
    REP(i, 0, N)
    {
        cout << t[i] << " ";
    }
    
    return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		std::vector<int> num;
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (; x; x /= 10) {
			num.push_back(x % 10);
		}
		while (!num.empty()) {
			putchar(num.back() ^ '0');
			num.pop_back();
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 100005, INF = 0x3f3f3f3f;

int n, a[N], cnt[15], xs[1 << 15], bitcnt[1 << 15], f[1 << 15];

int main() {
	read(n);
	for (int i = 0; i < n - 1; ++i) {
		int u, v, w;
		read(u), read(v), read(w);
		a[u] ^= w, a[v] ^= w;
	}
	for (int i = 0; i < n; ++i) {
		if (a[i]) {
			++cnt[a[i] - 1];
		}
	}
	int ans = 0, mask = 0;
	for (int i = 0; i < 15; ++i) {
		ans += cnt[i] >> 1;
		mask |= (cnt[i] & 1) << i;
	}
	for (int S = 0; S < (1 << 15); ++S) {
		xs[S] = bitcnt[S] = 0;
		for (int i = 0; i < 15; ++i) {
			if (S >> i & 1) {
				xs[S] ^= i + 1;
				++bitcnt[S];
			}
		}
	}
	f[0] = 0;
	for (int S = 1; S < (1 << 15); ++S) {
		f[S] = INF;
		for (int T = S; T; T = (T - 1) & S) {
			if (xs[T] == 0) {
				f[S] = std::min(f[S], f[S ^ T] + bitcnt[T] - 1);
			}
		}
	}
	print(f[mask] + ans);
}


Measured memory_bytes: 5164
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {

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

  static class CSlimes {

    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int n = in.nextInt();
      char[] s = in.next().toCharArray();
      int ans = 0;
      char last = '0';
      for (int i = 0; i < n; ++i) {
        if (s[i] != last) {
          ++ans;
        }
        last = s[i];
      }
      out.println(ans);
    }

  }

  static interface FastInput {

  }

  static class InputReader implements FastInput {

    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer;
    private int bytesRead;

    public InputReader(InputStream is) {
      din = new DataInputStream(is);
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
    }

    public InputReader(String file_name) throws IOException {
      din = new DataInputStream(new FileInputStream(file_name));
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
    }

    public String next() {
      StringBuilder sb = new StringBuilder();
      byte c = read();
      while (c <= ' ') {
        c = read();
      }
      while (isEmptySpace(c)) {
        sb.append((char) c);
        c = read();
      }
      return sb.toString();
    }

    private boolean isEmptySpace(byte c) {
      return c != ' ' && c != '\n' && c != '\t' && c != '\r';
    }

    public int nextInt() {
      int ret = 0;
      byte c = read();
      while (c <= ' ') {
        c = read();
      }
      boolean neg = (c == '-');
      if (neg) {
        c = read();
      }
      do {
        ret = ret * 10 + c - '0';
      } while ((c = read()) >= '0' && c <= '9');

      if (neg) {
        return -ret;
      }
      return ret;
    }

    private void fillBuffer() {
      try {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
      } catch (IOException e) {
        throw new RuntimeException("trying to read from null input, verify constraints ");
      }
      if (bytesRead == -1) {
        buffer[0] = -1;
      }
    }

    private byte read() {
      if (bufferPointer == bytesRead) {
        fillBuffer();
      }
      return buffer[bufferPointer++];
    }

  }
}



Measured memory_bytes: 23380
import math

N = int(input())

cors = []
for i in range(N):

    xy = input().split()
    cors.append(xy)

sumnum = 0

n = 0
for i in range(N):

    for j in range(i,N):
        if i == j:
            continue
        else:
            n = n+1
            #print("i="+str(i) +"j="+str(j))
            xi = int(cors[i][0])
            xj = int(cors[j][0])
            yi = int(cors[i][1])
            yj = int(cors[j][1])
            sumnum = sumnum + math.sqrt((xj-xi)*(xj-xi)+(yj-yi)*(yj-yi))
print(sumnum/n*(N-1))


Measured memory_bytes: 3064
using System;
using System.ComponentModel.DataAnnotations;
using System.Runtime.InteropServices;

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = Console.ReadLine();

			var ans = 0;
			foreach (var c in n)
			{
				ans += c - '0';
				ans %= 9;
			}

			if (ans % 9 == 0)
			{
				Console.WriteLine("Yes");
			}
			else
			{
				Console.WriteLine("No");
			}
		}
	}
}


Measured memory_bytes: 26536
"""
keyword: 二分探索

初めにLをソートして、a<b<cとしてa,bを決めたとき、a+b>cとなるようなcの個数を計算する
cの最大値を求めるには二分探索が高速
さらに、二分探索の探索範囲の左端は、前のループで求めたcの最大値で十分である（∵前のループのa+b <= 今ループのa+b）ことを考慮すれば、さらに高速化できる

pythonでTLE, pypyでAC
"""

import sys
sys.setrecursionlimit(10**6)

n = int(input())
L = list(map(int, input().split()))

L.sort()
ans = 0

for i in range(n-2):
    l_prev = 0 # 前のループで求めたcの最大値を覚えておく
    for j in range(i+1,n-1):
        ab = L[i]+L[j]
        if not l_prev:
            l = j; r = n
        else:
            l = l_prev; r = n
        while l+1 < r:
            c = (l+r)//2
            if L[c] < ab:
                l = c
            else:
                r = c
        ans += l-j
        l_prev = l
        
print(ans)

Measured memory_bytes: 42476
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    #endif
    // int T;cin>>T;while(T--) 
    {
        int n;
        cin>>n;
        ll a[n];
        ifr(i, 0, n) cin>>a[i];
        sort(a, a+n, greater<ll>());
        ll sum = a[0];
        ll x = n-2, j = 0;
        while(x>0) {
            sum += 1ll * (x>=2?2:x) * a[++j];
            x-=2;
        }
        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 5100
using System;

namespace ITP1_2_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split(' ');
            int a = int.Parse(strs[0]);
            int b = int.Parse(strs[1]);
            if (a > b) Console.WriteLine("a > b");
            else if (a < b) Console.WriteLine("a < b");
            else Console.WriteLine("a == b");
        }
    }
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 10007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
ll powMod(ll a, ll b) {
    ll ans = 1;
    while (b > 0) {
        if (b & 1) ans = (ans * a) % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return ans % MOD;
}
int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    ll res = 0;
    cin >> n >> k;
    vector<int> div(k + 1, 0);

    for (int i = k; i >= 1; i--) {
        div[i] = powMod(k / i, n);
        for (int j = i * 2; j <= k; j += i) {
            div[i] -= div[j];
            div[i] %= MOD;
        }
    }

    for (ll i = 1; i <= k; i++) {
        res += (i * div[i]);
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int W, H, N;
    cin >> W >> H >> N;
    ll X[N], Y[N];
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i];
    }
    ll ans = 0;
    for (int i = 1; i < N; i++) {
        ll dx = X[i] - X[i - 1];
        ll dy = Y[i] - Y[i - 1];
        if (dx * dy >= 0) {
            dx = abs(dx);
            dy = abs(dy);
            ans += max(dx, dy);
        } else {
            ans += abs(dx) + abs(dy);
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3084
# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    n, k = map(int, args[0].split())
    A = np.array(sorted(map(int, args[1].split())))
    N = A[A < 0]
    P = A[0 < A]

    count = 0
    left, right = -10**18, 10**18
    while left+1 < right:
        x = (left+right)//2
        count = 0

        if k <= len(N)*len(P):
            count += (len(P)-np.searchsorted(P, -(-x//N), side='left')).sum()

        elif (n*(n-1) - len(N)*(len(N)-1) - len(P)*(len(P)-1))//2 < k:
            for D in (-(N[::-1]), P):
                count += np.searchsorted(D, x//D, side='right').sum()
                count -= len(D[D*D <= x])
            count //= 2
            count += (n*(n-1) - len(N)*(len(N)-1) - len(P)*(len(P)-1))//2

        else:
            right = 0
            break

        if count < k:
            left = x
        else:
            right = x

    return str(right)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 34096
#include<time.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

template<typename ...Ts>
void show(Ts... ts){
  cout<<"#:";
  auto print=[](auto v){cout<<v<<" ";};
  initializer_list<int>{(void(print(ts)),0)...};
  cout<<endl;
}

int main(void){
    int ans=0,k=0;
    vi a(3,0);
    
    rep(i,3){
        cin>>a[i];
    }
    cin>>k;
    sort(all(a));
    rep(i,k)a[2]*=2;
    rep(i,3){ans+=a[i];}
    cout<<ans;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	h2 -= h1;
	m2 -= m1;
	while(h2 > 0){
		m2 += 60;
		h2--;
	}
	cout << m2-k << endl;

	return 0;
}


Measured memory_bytes: 3584
from sys import stdin
a = stdin.readline().strip()
ans = 0
n = len(a)
plus = n-1
b = [a[0]]
for i in xrange(1,n):
    b.append('')
    b.append(a[i])
    
total = 1<<plus
#print b,total
for i in xrange(total):
    x = ''
    c = list(b)
    #print "mask",i,c
    for j in xrange(n-1):
        if i & (1<<j):
            c[2*j+1] = '+'
    #print c            
    #print ''.join(c)
    ans += eval(''.join(c))
print ans 

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;

const string YES = "Yes";
const string NO = "No";

void solve()
{
  string w;
  cin >> w;
  vector<int> cnt(26, 0);
  for(auto c:w) {
    cnt[c-'a']++;
  }
  for (int i=0; i<26; i++) {
    if (cnt[i]%2==1) {
      cout << NO << endl;
      return;
    }
  }
  cout << YES << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
//________
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__ )
#define show(x) cerr << #x << ':' << (x) << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
const int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
#define Size 1000111
#define INF  0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define NIL -1
//________

int N, Q;
int a[10006];

bool search(int k){
   int i = 0;
   a[N] = k;
   while(a[i] != k)++i;
   return(i != N);
}

signed main()
{
   FAST();
   cin >> N;
   rep(i, N)cin >> a[i];

   int cnt = 0;

   cin >> Q;
   while(Q--){
      int n;
      cin >> n;
      if(search(n))++cnt;
   }
   outl(cnt);
}




Measured memory_bytes: 3208
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

void main() {
    long A, B;
    int K;

    readf("%d %d %d", &A, &B, &K);

    char[] x = format("%09d", A).dup.reverse;
    char[] y = format("%09d", B).dup.reverse;
    //writeln([x, y]);
    long ans = 0;
    void calc(int i, int[] borrow, char[] ret, int k) {
        if (i == 9) {
            auto s = ret.dup;
            s.reverse;
            ans = max(ans, s.to!long);
            return;
        }
        int c = cast(int)(x[i] - '0'),
            d = cast(int)(y[i] - '0');
        if (borrow[i] && k < K) {
            if (c >= d) {
                calc(i + 1, borrow, ret ~ (c - d).to!string, k + 1);
            } else {
                borrow[i + 1] = 1;
                calc(i + 1, borrow, ret ~ (10 + c - d).to!string, k + 1);
            }
        }
        if (c - borrow[i] >= d) {
            ret ~= (c - d - borrow[i]).to!string;
            calc(i + 1, borrow, ret, k);
        } else {
            borrow[i + 1] = 1;
            ret ~= (10 + c - d - borrow[i]).to!string;
            calc(i + 1, borrow, ret, k);
        }
    }

    calc(0, new int[9], new char[0], 0);
    writeln(ans);

}

Measured memory_bytes: 1088
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

ll gcd(ll a, ll b) {
    if(b == 0) return a;
    return gcd(b,a%b);
}
 
ll lcm(ll a, ll b) {
    ll g = gcd(a,b);
    return a / g * b;   // Be careful not to overflow
}


vector<int> pp;
void preparePrime( int maxp )
{
    int i;
    vector<int> a(maxp+1);
    for(i=2; i<=maxp; i++) {
        int k=i+i;
        while(k<=maxp) {
            a[k]=1;
            k+=i;
        }
    }
    for(i=2; i<=maxp; i++) {
        if(a[i]==0) pp.push_back( i );
    }
    return;
}

void decompositPrime( ll a, vector<pair<ll,ll> >& vv )
{
    preparePrime( (int)sqrt((double)a)+1 );

    int i;
    for(i=0; i<(int)pp.size(); i++) {
        int count = 0;
        while(a % pp[i] == 0 ) {
            a /= pp[i];
            count ++;
        }
        if(count>0) vv.push_back( make_pair( pp[i], count ) );
        if (a==1) break;
    }
    if(a>1) {
        vv.push_back( make_pair( a, 1 ) );
    }

    return;
}


void solve()
{
    ll n;
    scanf("%lld", &n);

    vector<pair<ll, ll> > vv;
    decompositPrime(n, vv);

    ll ans = 0;
    int i;
    for (i = 0; i < (int)vv.size(); i++) {
        ll tmp=vv[i].second;
        int s = 0;
        int k;
        for (k = 1; k < 100; k++) {
            s += k;
            if (s > tmp)
                break;
        }
        ans+=(k - 1);

    }
    printf("%lld\n", ans);

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


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

int main() {
  int n;
  int count = 0;
  cin >> n;

  vector<int> p(n);
  rep(i, n) {
     cin >> p.at(i);
  }

  rep2(i, 1, n - 1) {
    if (p.at(i - 1) < p.at(i) && p.at(i) < p.at(i + 1) || p.at(i - 1) > p.at(i) && p.at(i) > p.at(i + 1)) {
      count++;
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll H,A;
    cin>>H>>A;
    cout << H/A + (H%A>0) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int s,d,m,k;
vector<int> A[100];
vector<int> B[100];
int dp[301];

int main(){
  while( scanf("%d %d %d",&s,&d,&m) != EOF){
    for(int i=0;i<s;i++){
      scanf("%d",&k);
      A[i].resize(k);
      B[i].resize(k);
      for(int j=0;j<k;j++)
        scanf("%d %d",&A[i][j],&B[i][j]);
    }
    for(int i=0;i<=m;i++)dp[i]=-1e9;
    dp[0]=0;
    
    for(int i=0;i<d;i++){
      scanf("%d",&k);
      for(int j=0;j<(int)A[k].size();j++){
        int a=A[k][j],b=B[k][j];
        for(int l=m;l>=b;l--){
          dp[l]=max(dp[l],dp[l-b]+a);
        }
      }
    }

    int ans=0;
    for(int i=0;i<=m;i++)
      if(dp[ans]<dp[i])ans=i;
    cout<<dp[ans]<<' '<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1292
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
b = inpl()
res = 0
for i in range(n):
    if b[i] < a[i]:
        res += b[i]
    elif b[i] == a[i]:
        res += a[i]
    else:
        res += a[i]
        b[i] -= a[i]
        if b[i] < a[i+1]:
            res += b[i]
            a[i+1] -= b[i]
        else:
            res += a[i+1]
            a[i+1] = 0
print(res)

Measured memory_bytes: 103820
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

using edge = pair<int, long long>;
vector< vector<edge> > G(100000, vector<edge>());

void dfs(vector<int> &color, int curr) {
    for (auto nxt : G[curr]) {
        if (color[nxt.first] != -1) continue;
        if (nxt.second % 2 == 0) color[nxt.first] = color[curr];
        else color[nxt.first] = 1 - color[curr];
        dfs(color, nxt.first);
    }
    return;
}

int main() {
    int N; cin >> N;
    for (int i = 0; i < N - 1; i++) {
        int u, v; cin >> u >> v;
        long long w; cin >> w;
        u--; v--;
        G[u].push_back(make_pair(v, w));
        G[v].push_back(make_pair(u, w));
    }

    vector<int> color(N, -1);
    for (int i = 0; i < N; i++) {
        if (color[i] == -1) {
            color[i] = 0;
            dfs(color, i);
        }
    }
    
    for (int i = 0; i < N; i++) cout << color[i] << endl;
}


Measured memory_bytes: 9856
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String S = in.nextLine();
        String T = in.nextLine();
      int A = 0;

for (int count = 0; count < S.length(); count++){
 if(S.charAt(count) == T.charAt(count)){
  A = A +1 ;
 }
}

System.out.println(S.length()-A);
        }
    }

Measured memory_bytes: 42436