akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

template <typename T>
ostream& operator <<(ostream& ostr, const vector<T>& a) {
	ostr << "(";
	for (size_t i = 0; i < a.size(); ++i) {
		if (i) {
			ostr << ", ";
		}
		ostr << a[i];
	}
	ostr << ")";
	return ostr;
}

const int mod = 1000000007;

long long pw(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1ll) {
			res = res * a % mod;
		}
		b >>= 1;
		a = a * a % mod;
	}
	return res;
}

int main() {
	int n = nxt();
	vector<int> a(n);
	vector<int> b(n);
	for (int i = 0; i < n; ++i) {
		a[i] = nxt();
	}
	for (int j = 0; j < n; ++j) {
		b[j] = nxt();
	}
	int x = 0;
	for (int y : a) {
		x ^= y;
	}
	a.push_back(x);
	x = 0;
	for (int y : b) {
		x ^= y;
	}
	b.push_back(x);

	auto ar = a, br = b;
	sort(all(ar));
	sort(all(br));
	if (ar != br) {
		puts("-1");
		return 0;
	}

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i] != b[i]) {
			++ans;
		}
	}

	vector<int> ids;
	for (int i = 0; i < n; ++i) {
		if (a[i] != b[i]) {
			ids.push_back(i);
		}
	}
	ids.push_back(n);

	vector<int> cols;
	for (int i : ids) {
		cols.push_back(a[i]);
		cols.push_back(b[i]);
	}
	sort(all(cols));
	cols.resize(unique(all(cols)) - cols.begin());
	int sz = cols.size();

	vector<vector<int>> ed(sz);
	for (int i : ids) {
		int fr = lower_bound(all(cols), a[i]) - cols.begin();
		int to = lower_bound(all(cols), b[i]) - cols.begin();
		ed[fr].push_back(to);
		ed[to].push_back(fr);
	}

	vector<char> used(sz);
	for (int i = 0; i < sz; ++i) {
		if (!used[i]) {
			++ans;
			used[i] = 1;
			vector<int> st = {i};
			while (!st.empty()) {
				int v = st.back();
				st.pop_back();
				for (int u : ed[v]) {
					if (used[u]) {
						continue;
					}
					used[u] = 1;
					st.push_back(u);
				}
			}
		}
	}

	ans -= 1;

	printf("%d\n", ans);

	return 0;
}

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

int main(){
    int W, a, b; cin >> W >> a >> b;
    if(a <= b) cout << max(0,b-W-a);
    else cout << max(0,a-W-b);
}

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

int main() {
  int k;
  cin >> k;
  int prev_a = 7 % k;
  if (prev_a == 0) {
    cout << 1 << endl;
  }
  else {    
    bool done = false;
    for (int i = 2; i <= k; ++i) {
      int curr_a = (prev_a*10 + 7) %k;
      if (curr_a == 0) {
        done = true;
        cout << i << endl;
        break;
      }
      else {
        prev_a = curr_a;
      }
    }
    if (!done) {
      cout << -1 << endl;
    }
  }
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
	static long X;
	static int m=0;
	static long a=100;
	static boolean n=true;
	public static void main(String[]args) {
		Scanner sc=new Scanner(System.in);
		X=sc.nextLong();
		while(X>a) {
			m=m+1;
			a=a/100+a;
		}
		System.out.println(m);
	}
}


Measured memory_bytes: 35820
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll k, a, b;
    cin >> k >> a >> b;
    ll ans = b / k - (a - 1) / k;
    cout << (ans ? "OK" : "NG");
    return 0;
}


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

int main(void)
{
        int n;
        std::cin >> n;
        std::string s;
        std::cin >> s;
        for(auto& c: s){
                std::cout << static_cast<char>((c - 'A' + n) % 26 + 'A');
        }
        std::cout << std::endl;
        return 0;
}

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

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

using namespace std;

void make_map(vector<long> &sum, unordered_map<long, int> &map)
{
	int size = (int)sum.size();
	for(int i=1; i<size; i++){
		for(int j=0; i+j<size; j++){
			if (map.count(sum[i+j]-sum[j]) == 0){
				map.insert(make_pair(sum[i+j]-sum[j], 1));
			}else{
				map[sum[i+j]-sum[j]]++;
			}
		}
	}
	return;
}

int main(void)
{
	int N, M;
	while(cin >> N >> M, N > 0){
		unordered_map<long, int> h_map;
		unordered_map<long, int> w_map;
		vector<long> h_sum;
		vector<long> w_sum;
		long result = 0;
		//hの累積和配列を作成
		h_sum.push_back(0);
		rep(i, N){
			int h;
			cin >> h;
			h_sum.push_back(h_sum.back() + h);
		}
		//h_mapの構成
		make_map(h_sum, h_map);
		//wの累積和配列を作成
		w_sum.push_back(0);
		rep(i, M){
			int w;
			cin >> w;
			w_sum.push_back(w_sum.back() + w);
		}
		//w_mapの構成
		make_map(w_sum, w_map);

		//h_mapのイテレータを回して，同じキー値をもつw_mapの要素数だけresultを加算
		for(auto itr = h_map.begin(); itr != h_map.end(); itr++){
			result += (*itr).second * w_map[(*itr).first];
		}

		//出力
		cout << result << endl;
	}
	return 0;
}


Measured memory_bytes: 31892
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

#define POS(i,j) ((i)*n+(j))

void run(void){
  int a,b;
  scanf("%d%d",&a,&b);
  const int n=100;
  char *board=(char *)malloc(sizeof(char)*n*n);
  int i,j;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      board[POS(i,j)]=(i<n/2?'.':'#');
    }
  }
  int k=0;
  for(i=0;k<b-1;i+=2){
    for(j=0;k<b-1 && j<n;j+=2,k++){
      board[POS(i,j)]='#';
    }
  }
  for(k=0,i=n-1;k<a-1;i-=2){
    for(j=0;k<a-1 && j<n;j+=2,k++){
      board[POS(i,j)]='.';
    }
  }
  printf("%d %d\n",n,n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%c",board[POS(i,j)]);
    }
    printf("\n");
  }
  return;
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
#include <queue>
#include <cstdio>
#include <vector>

using namespace std;
typedef long long int ll;

int main(){
    vector<priority_queue<int>> v;
    int n, q, c, t, x;
    scanf("%d %d", &n ,&q);
    for(int i = 0; i < n; i++){
        v.push_back(priority_queue<int>());
    }
    for(int i = 0; i < q; i++){
        scanf("%d %d", &c, &t);
        switch(c){
            case 0:
                scanf("%d", &x);
                v.at(t).push(x);
                break;
            case 1:
                if(v.at(t).empty()) break;
                printf("%d\n", v.at(t).top());
                break;
            case 2:
                if(v.at(t).empty()) break;
                v.at(t).pop();
                break;
        }
    }
    return 0;
}



Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793
int dx[] = {0,1,-1,0,1,-1,1,-1};
int dy[] = {1,0,0,-1,1,-1,-1,1};

int main(){
    string n;
    cin >> n;
    for(auto c: n){
        if(c == '1')
            cout << '9';
        else
            cout << '1';
    }
    cout << '\n';
}


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

int main(){
  int n,q;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }
  vector<int> a_num(100000,0);
  ll sum=0;
  rep(i,n){
    a_num[a[i]-1]++;
    sum+=a[i];
  }
  //sort(a.begin(), a.end());
  //ll sum = accumulate(a.begin(), a.end(), 0);
  
  cin >> q;
  rep(i,q){
    int b,c;
    cin >> b >> c;
    sum += a_num[b-1] * (c-b);
    cout << sum << endl;

    a_num[c-1] += a_num[b-1];
    a_num[b-1] = 0;
  }
  return 0;
}


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

int A[2000000];

int largest = 0;

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

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

void maxHeapify(int i, int H){
  int b;
  int l = left(i);
  int r = right(i);
  if(l <= H && A[l] > A[i])
    largest = l;
  else{
    largest = i;
  }
  if(r<=H && A[r] > A[largest]){
    largest = r;
  }

  if(largest != i){
    b = A[i];
    A[i] = A[largest];
    A[largest] = b;
    maxHeapify(largest, H);
  }
}


int main(){

  int i, cnt= 1, Max;
  char C[8];

  while(scanf("%s", C)==1){
    if(C[0] == 'i'){
      scanf("%d", &A[cnt]);
      i=cnt;
      while(i > 1 && A[i/2] < A[i]){
        Max = A[i/2];
        A[i/2] = A[i];
        A[i] = Max;
        i = i/2;
      }
      cnt++;
    }
    else if(strncmp(C, "ex", 2) == 0){
      printf("%d\n",A[1]);
      A[1] = A[--cnt];
      maxHeapify(1, cnt);
    }
    else break;
  }
  return 0;
}


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

int main() {
  int N,M,Z=0;
  int64_t K;
  cin>>N>>M>>K;
  vector<int64_t> p(N+1);
  vector<int64_t> q(M+1);
  for(int i=0;i<N;i++){
    int64_t a;
    cin>>a;
    p.at(i+1)=p.at(i)+a;
  }
  for(int i=0;i<M;i++){
    int64_t a;
    cin>>a;
    q.at(i+1)=q.at(i)+a;
  }
  for(int i=0;i<=N;i++){
    int64_t b=K-p.at(i);
    if(b<0){
      break;
    }
    if(q.at(M)<=b){
      Z=max(Z,i+M);
    }
    else{
      int c=lower_bound(q.begin(),q.end(),b+1)-q.begin();
      Z=max(Z,c+i-1);
    }
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 6420
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void BubbleSort(int A[],int n, char *p);
void SelectionSort(int A[],int n, char *p);

int main(){
	int *A, *B, n, i;
	char m1[37]="",m2[37]="",*p1,*p2;
	scanf("%d", &n);
	A = (int *)malloc(sizeof(int)*n);
	B = (int *)malloc(sizeof(int)*n);
	p1 = m1; p2 = m2;
	for (i = 0; i < n; ++i) {
		scanf("%1s%d", p1+i,A + i);
		*(B + i) = *(A + i);
		*(p2 + i) = *(p1 + i);
	}
	BubbleSort(A, n,p1);
	if (strcmp(p1, p1) == 0)printf("Stable\n");
	else printf("Not stable\n");
	SelectionSort(B, n,p2);
	if (strcmp(p1, p2) == 0)printf("Stable\n");
	else printf("Not stable\n");
	free(A);
	free(B);
	return 0;
}

void BubbleSort(int A[], int n, char *p)
{
	int i, j, tmp;
	char ctmp[2];
	for (i = 0; i < n; i++) {
		for (j = 1; j < n; j++) {
			if (*(A + j - 1) > *(A + j)) {
				tmp = *(A + j); *(A + j) = *(A + j - 1); *(A + j - 1) = tmp;
				ctmp[0] = *(p + j); *(p + j) = *(p + j - 1); *(p + j - 1) = ctmp[0];
			}
		}
	}
	for (i = 0; i < n; i++) printf("%c%d%c", p[i], A[i], i < n - 1 ? ' ' : '\n');
}

void SelectionSort(int A[],int n, char *p)
{
	int i,j,iMin,iTmp,tmp;
	char ctmp[2];
	for (i = 0; i < n - 1; i++) {
		iMin = iTmp = i;
		for (j = i; j < n; j++) {
			if (*(A + iMin) > *(A + j)) {
				iMin = j;
			}
		}
		if (iTmp != iMin) {
			tmp = *(A + i); *(A + i) = *(A + iMin); *(A + iMin) = tmp;
			ctmp[0] = *(p + i); *(p + i) = *(p + iMin); *(p + iMin) = ctmp[0];
		}
	}
	for (i = 0; i < n; i++) printf("%c%d%c", p[i], A[i], i < n - 1 ? ' ' : '\n');
	
}

Measured memory_bytes: 616
let input=require("fs").readFileSync("/dev/stdin","utf8");
let arr = input.split(" ");
let w = arr[0] - 0;
let h = arr[1] - 0;
let x = arr[2] - 0;
let y = arr[3] - 0;
let r = arr[4] - 0;
if (x - r >= 0 && x + r <= w && y + r <= h && y - r >= 0) {
    console.log("Yes");
} else {
    console.log("No");
}


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

using namespace std;

// pの表す整数を設定できるか
bool judge(string s, int p) {
	char pass[3] = {
		'0' + p / 100, '0' + (p % 100) / 10, '0' + (p % 10)
	};
	int ptr = 0;
	for (int i = 0; i < s.length(); ++i)
		if (s[i] == pass[ptr] && ++ptr == 3)
				return true;
	return false;
}

signed main() {
	int n; cin >> n;
	string s; cin >> s;
	int ans = 0;
	for (int i = 0; i < 1000; ++i)
		if (judge(s, i))
			++ans;
	cout << ans << endl;
	return 0;
}

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

long long gcd(long long a, long long b){
  if(a > b){
    swap(a, b);
  }
  if(b % a == 0){
    return a;
  }
  b -= a;
  return gcd(a, b);
}

int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  long long g;
  for(int i = 1; i < N; i++){
    g = gcd(A.at(i - 1), A.at(i));
    A.at(i) = g;
  }
  cout << g << endl;
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int a, b; cin >> a >> b;
    if (a + b < 10) out(a + b);
    else out("error");
}



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

int main()
{
 

    int n;
    cin>>n;

    vector<int> A1(n);
    vector<int> A2(n);
    for (int i = 0; i < n; i++)
        cin>>A1.at(i);
  
    for (int i = 0; i < n; i++)
        cin>>A2.at(i);
int index;
long sum;
long max_wk=0;
for(index=0;index<n;index++){
    sum=0;
    for(int i=0;i<n;i++){
        if(i<index)
            sum+=A1.at(i);
        else if(i==index)
            sum+=A1.at(i)+A2.at(i);
        else
            sum+=A2.at(i);
    }
    max_wk=max(max_wk,sum);
}  
    cout<<max_wk<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define ff first
#define ar array
#define ss second
#define ll long long int
#define mem(x) memset(x,0,sizeof(x))
#define setbits(x)  __builtin_popcount(x)
#define ull unsigned long long int
#define all(c) (c).begin(),(c).end()
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define db double
#define endl "\n"
#define  fbo(x) find_by_order(x)
#define  ook(x) order_of_key(x)
 
using namespace __gnu_pbds;
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair<ll,ll > iil;
typedef pair<ll,int> li;
typedef pair<int,int> ii;
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    os1;
typedef tree<int, null_type, greater<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    os2;

inline void fast()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
const ll pi=31;
const ll MOD[2] = {1187278649, 1149736019};//for double hashing
const ll mod=(ll)(1e9)+7;
ll pmod(ll x,ll n){
  ll r=1;
  while(n>0)
  {
    if(n&1LL)
      r=(r*x)%mod;
    x=(x*x)%mod;
    n=n/2;
    n%=mod;
  }
  return r;
}
ll pMod(ll x,ll n,ll mod)
{ ll r=1;
  while(n>0)
  {
    if(n&1LL)
      r=(r*x)%mod;
    x=(x*x)%mod;
    n=n/2;
    n%=mod;
  }
  return r;
 
}
 
//think recursively also;
const int mxn=1e5;
int n,m;
vector<int>adj[mxn+1];
int ind[mxn+1];
int dp[mxn+1];
void solve()
{ 
  cin>>n>>m;
  for(int i=1;i<=m;i++)
  {
     int a,b;
     cin>>a>>b;
     adj[a].pb(b);
     ind[b]+=1;
   //  adj[b].pb(a);
  }
  queue<int>q;
  for(int i=1;i<=n;i++){
    if(ind[i]==0)
      q.push(i);
  }
  while(!q.empty())
  {
     int u=q.front();
     q.pop();
     for(auto it:adj[u])
      { 
          ind[it]-=1;
          if(ind[it]==0)
          {
           dp[it]=dp[u]+1;
           q.push(it);
          }
        }
  }
  int mx=0;
  for(int i=1;i<=n;i++)
  {
    mx=max(mx,dp[i]);
  }
  cout<<mx<<endl;

  
}
int main()
{
  fast();
   // int t;
   // cin>>t;
   // for(int casee=1;casee<=t;casee++)
  {//cout<<"Case #"<<casee<<": ";
    solve();
  }
 
 
 
}

Measured memory_bytes: 9908
# -*- coding: utf-8 -*-
# モジュールのインポート
import math

# 標準入力を取得
N, D = list(map(int, input().split()))
X, Y = [], []
for n in range(N):
    X_n, Y_n = list(map(int, input().split()))
    X.append(X_n)
    Y.append(Y_n)

# 求解処理


def get_distance(p: int, q: int) -> float:
    return math.sqrt(math.pow(p, 2) + math.pow(q, 2))


ans = 0
for n in range(N):
    distance = get_distance(X[n], Y[n])
    if distance <= D:
        ans += 1

# 結果出力
print(ans)


Measured memory_bytes: 24992
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Stream;

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

        while(true){
            int a = sc.nextInt();
            int b = sc.nextInt();

            if (a == 0 && b == 0) break;

            for(int i=1; i<=a; i++){
                for(int j=1; j<=b; j++){
                    if(i%2==0 && j%2==0){
                        System.out.print("#");
                    } else if(i%2!=0 && j%2!=0){
                        System.out.print("#");
                    } else if(i%2==0 && j%2 !=0){
                        System.out.print(".");
                    } else {
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using llint = long long;
using vint = vector<int>;

int main () {
    int n; cin >> n;
    vector<char> s(n);
    bool four = false;
    rep (i, n) {
        cin >> s.at(i);
        if (s.at(i) == 'Y') four = true;
    }
    if (four == true) cout << "Four\n";
    else cout << "Three\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H, W, K; cin>>H>>W>>K;
  string mat[H];
  for(int i = 0; i < H; ++i) {
    cin>>mat[i];
  }
  int n = 1<<(H + W);
  int ans = 0;
  for(int i = 0; i < n; ++i){
    int row = i >> W; int col = i & ((1 <<W) - 1);
    int cnt = 0;
    for(int j = 0; j < H; ++j) {
      for(int k  = 0; k < W; ++k) {
        if((1 << j) & row) continue;
        if((1 << k) & col) continue;
        if(mat[j][k] == '#') ++cnt;
      }
    }
    if(cnt == K) ++ans;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
    int n;
    int a[100010];
    int b[100010];
    long long int ans = 0;

    cin >> n;

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

    for (int i = n; i >= 0; i--) {
        if (i == 0) continue;
        if (b[i-1] > a[i]) {
            b[i-1] -= a[i];
            ans += a[i];
            a[i] = 0;
        }
        else {
            a[i] -= b[i-1];
            ans += b[i-1];
            b[i-1] = 0;
        }
        if (a[i-1] > b[i-1]) {
            a[i-1] -= b[i-1];
            ans += b[i-1];
            b[i-1] = 0;
        }
        else {
            b[i-1] -= a[i-1];
            ans += a[i-1];
            a[i-1] = 0;
        }
    }

    cout << ans << endl;
}


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

int main()
{
    ll d,g;
    cin >> d >> g;
    int p[10],c[10];
    ll ans = 10000000000;
    for( int i = 0; i < d; ++i )
    {
        cin >> p[i] >> c[i];
    }

    for( int i = 0; i < (1<<d); ++i )
    {
        ll sum = 0,keep = -1, count = 0;
        for( int j = 0; j < d; ++j )
        {
            if( i & (1<<j) )
            {
                count = count + p[j];
                sum = sum + 100*(j+1)*p[j]+c[j];
            }
            else
            {
                keep = j;
            }
        }

        if( sum < g )
        {
            int s = 100*(keep+1);
            int n = ( g - sum + s - 1 ) / s;
            if( n >= p[keep] )
            {
                continue;
            }
            count = count + n;
        }
        ans = min(ans,count);
    }
    cout << ans << endl;
    return 0;
}



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


int main() {

  string S;
  cin >> S;

  if(S.at(2)==S.at(3)&&S.at(4)==S.at(5)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;


  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <string>
using namespace std;
 
long long int gcd(long long int a, long long int b) { 
   if (b == 0) 
      return a; 
   return gcd(b, a % b);  
} 
int main() {
 
	//数字
	long long int A,B;
  cin >> A >> B;
  long long int d=1;
  d=gcd(A,B);
  long long int q= A/d*B;
  cout << q << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

ll mygcd(ll a, ll b)
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return mygcd(b, a % b);
    }
}

signed main()
{
    int n;
    cin >> n;
    map<int, int> as;
    rep(i, n)
    {
        int a;
        cin >> a;
        as[a]++;
    }
    ll ans = 0;
    for (auto &i : as)
    {
        if (i.first <= i.second)
        {
            ans += i.second - i.first;
        }
        else
        {
            ans += i.second;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8104
package main

import (
	"fmt"
	//"bufio"
)

func main() {
	//make関数で、サイズを指定してスライス作成
	a := make([][]int, 3)
	for i := range a {
		a[i] = make([]int, 3)
	}
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			fmt.Scan(&a[i][j])
		}
	}
	//fmt.Println(a)

	var n int
	fmt.Scan(&n)

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

	for _, b := range t {
		for i := 0; i < 3; i++ {
			for j := 0; j < 3; j++ {
				if a[i][j] == b {
					a[i][j] = 0
				}
			}
		}
	}

	ans := "No"
	for i := 0; i < 3; i++ {
		if a[i][0]+a[i][1]+a[i][2] == 0 {
			ans = "Yes"
			break
		} else if a[0][i]+a[1][i]+a[2][i] == 0 {
			ans = "Yes"
			break
		}
	}
	if a[0][0]+a[1][1]+a[2][2] == 0 {
		ans = "Yes"
	} else if a[2][0]+a[1][1]+a[0][2] == 0 {
		ans = "Yes"
	}

	fmt.Println(ans)

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define pub push_back 
#define pob pop_back 
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#include<iomanip>
#include<cmath>
using namespace std ;
int main()
{
	int a , b , c ;
	cin >> a >> b >> c ;
	int ans = max(0 , (b+c)-a) ;
	cout << ans << endl ;
	return 0 ;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int n, m, l, r;

Int fact[1080000];
Int revfact[1080000];
Int rev[1080000];

void init(){
    Int m = MOD;
    fact[0] = 1;
    revfact[0] = 1;
    rev[0] = 0;
    rev[1] = 1;
    for(int i = 1;i < 1080000;i++){
        fact[i] = fact[i-1] * i % m;
        if(i>1)rev[i] = MOD / i * (MOD-rev[MOD % i]) % MOD;
        revfact[i] = revfact[i-1] * rev[i] % MOD;
    }
}

Int nCk(Int n, Int k){
    if(n < k)return 0;
    return fact[n] * revfact[n-k] % MOD * revfact[k] % MOD;
}



Int solve2(Int n, Int m, Int r, Int b, Int a){
    Int res = 0;
    for(Int i = 0;i <= n-m;i++){
        Int rest = r - m * a - i * (b+1);
        if(rest < 0)break;
        Int tmp = nCk(rest + n, n) * nCk(n, m) % MOD * nCk(n-m, i) % MOD;
        if(i % 2)tmp *= -1;
        res += tmp;res %= MOD;
    }
    if(res < 0)res += MOD;

    return res;
}

Int solve(Int n, Int m, Int r){
    Int res = nCk(r + n, n);
    for(int i = 0;i <= r;i++){
        res -= (solve2(n, m, r, i, i+1) - solve2(n, m, r, i-1, i+1)) % MOD;res %= MOD;
    }
    if(res < 0)res += MOD;
    return res;
}

int main(){
    init();
    cin >> n >> m >> l >> r;
    Int res = solve(n, m, r);
    if(l)res -= solve(n, m, l-1);
    res %= MOD;
    if(res < 0)res += MOD;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 25600
import java.util.*;

public class Main {

	static int[] nums;
	
	public static boolean checker (int a, int b, int c) {
		return (a + 1 == b && b == c - 1) || (a == b && b == c);
	}
	
	public static boolean solve (boolean[] check, int cnt) {

		if (cnt <= 3) {
			for (int i = 0; i < nums.length; i++) {
				if (check[i]) continue;
				for (int j = i + 1; j < nums.length; j++) {
					if (check[j]) continue;
					for (int k = j + 1; k < nums.length; k++) {
						if (check[k]) continue;
						if (!checker(nums[i],nums[j],nums[k])) continue;
//						System.out.print("{" + nums[i] + "," + nums[j] + "," + nums[k] + "}");
						check[i] = (check[j] = (check[k] = true));
						if (solve(check,cnt + 1)) return true;
//						System.out.println();
						check[i] = (check[j] = (check[k] = false));

					}
				}
			}
		} else {
			int temp = -1;
			for (int i = 0; i < nums.length; i++) {
				if (!check[i]) {
					if (temp == -1) {
						temp = nums[i];
					} else {
//						System.out.println("{" + temp + "," + nums[i] + "}");
						return temp == nums[i];
					}
				}
			}
		}

		return false;

	}

	public static void main (String[] args) {

		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {
			String str = sc.nextLine();
			ArrayList<Integer> list = new ArrayList<Integer>();
			main:
			for (int i = 1; i < 10; i++) {

				String temp = str + i;

				int[] seq = new int[10];
				for (int j = 0; j < temp.length(); j++)
					seq[temp.charAt(j) - '0']++;

				for (int j = 1; j < 10; j++)
					if (seq[j] > 4) continue main;

				char[] c = (temp).toCharArray();
				Arrays.sort(c);
				nums = new int[c.length];
				for (int j = 0; j < c.length; j++) {
					nums[j] = c[j] - '0';
				}
				if (solve(new boolean[c.length],0)) list.add(i);
			}

			if (list.size() >= 2) {
				System.out.print(list.get(0));
				for (int i = 1; i < list.size(); i++)
					System.out.print(" " + list.get(i));
				System.out.println();
			} else if (list.size() == 1) {
				System.out.println(list.get(0));
			} else {
				System.out.println(0);
			}

		}

	}

}

Measured memory_bytes: 12000
#include <stdio.h>

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int res = 0;
    int n;

    scanf ( "%d", &n );
    if ( !( n ) ) break ;

    for ( n /= 4; n--; )
    {
      int d;

      scanf ( "%d", &d );
      res += d;
    }

    printf ( "%d\n", res );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;


int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    vector<ll> SA(N+1, 0);
    REP(i, N) SA[i+1] = SA[i]+A[i];
    vector<ll> B(N);
    REP(i, N) cin >> B[i];
    reverse(ALL(B));
    vector<ll> SB(N+1, 0);
    REP(i, N) SB[i+1] = SB[i]+B[i];

    ll res = 0;
    REP(i, N) {
        chmax(res, SA[i+1] + SB[N-i]);
    }
    cout << res << "\n";
}


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

const int N = 1e5 + 10;

struct BIT {
    int c[N << 1];
    int n;
    void init(int sz = 0) {
        n = sz;
        for (int i = 0; i <= n; ++i) c[i] = 0;
    }
    void add(int x, int v = 1) {
        if (!x) return;
        while (x <= n) {
            c[x] += v;
            x += x & -x;
        }
    }
    int get(int x) {
        int ans = 0;
        while (x) {
            ans += c[x];
            x -= x & -x;
        }
        return ans;
    }
} bt;

int a[N], n;
int val[N], tot;

bool check(int mid) {
    ll res = 0;
    static int b[N];
    // cerr << "mid = " << mid << endl;
    // for (int i = 1; i <= n; ++i) {
        // cerr << b[i] << " ";
    // }
    for (int i = 1; i <= n; ++i) {
        b[i] = a[i] <= mid ? 1 : -1;
    }
    for (int i = 1; i <= n; ++i) {
        b[i] += b[i - 1];
    }
    bt.init(n << 1);
    bt.add(n);
    // cerr << endl;
    for (int i = 1; i <= n; ++i) {
        res += bt.get(b[i] + n - 1);
        bt.add(b[i] + n);
    }
    // cerr << res << endl;
    return res * 2 > (ll)n*(n+1)/2;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        val[i] = a[i];
    }
    sort(val + 1, val + n + 1);
    tot = unique(val + 1, val + n + 1) - val - 1;
    for (int i = 1; i <= n; i++) {
        a[i] = lower_bound(val + 1, val + tot + 1, a[i]) - val;
    }
    int l = 1, r = tot, ans = 0;
    while (l <= r) {
        // cerr << l << " " << r << endl;
        int mid = (l + r) >> 1;
        if (check(mid)) r = mid - 1, ans = mid;
        else l = mid + 1;
    }
    cout << val[ans] << endl;
    return 0;
}

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

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

  long long day=0;
  for(int i=0;i<M;i++){
    int a;
    cin >> a;
    day += a;
  }
  if(day<=N){
    cout << N-day << endl;
  }
  else{
    cout << "-1" << endl;
  }
}


Measured memory_bytes: 3636
def func(s, c, d = 1)
  t = '*' * (s.size - 1)
  k = 0

  (s.size - 1).times do |i|
    if s[i] == c then
      t[i] = c
    elsif s[i + 1] == c then
      t[i] = c
    else
      t[i] = s[i]
      k += 1
    end
  end

  return (k == 0) ? d : func(t, c, d + 1)
end

def main(argv)
  s = gets.chomp
  n = s.size

  m = 1e+9.to_i
  'abcdefghijklmnopqrstuvwxyz'.split('').each do |c|
    if s != (c * n) then
      m = [func(s, c), m].min
    else
      m = 0
    end
  end
  puts m.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
// #define fore(i,a) for(auto &i:a)
// #define all(x) (x).begin(),(x).end()
// #pragma GCC optimize ("-O3")
// using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
// typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
// 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; }

using namespace std;

int main(void)
{
  string s;
  cin>>s;
  int n=s.length()-1;
  int sum=0;
  
  rep(bit,0,(1<<n)){
    int sum=s[0]-'0';
    rep(i,0,n){
      if(bit&(1<<i)){
        sum+=(s[i+1]-'0');
      }
      else{
        sum-=(s[i+1]-'0');
      }
    }
    
    if(sum==7){
      string result;
      result.push_back(s[0]);
      rep(i,0,n){
        if(bit&(1<<i)) result.push_back('+');
        else result.push_back('-');
        result.push_back(s[i+1]);
      }
      cout<<result<<"=7"<<endl;
      return 0;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
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; }
//#define int long long

void solve() {
    int n, X; cin >> n >> X;
    vector<ll> x(n), sum(n + 1, 0LL);
    rep(i, n) {
        cin >> x[i];
        sum[i + 1] = sum[i] + x[i];
    }
    ul ans = (1LL<<63)-1;
    for(int y = 1; y <= (n + 1) / 2; ++y) {
        ul res = (ul)X * (n + y);
        res += (ul)sum[n] * 5ULL;
        for(int i = 2; n - i * y > 0; ++i) {
            res += (ul)sum[n - i * y] * 2ULL;
        }
        chmin(ans, res);
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 3456
#パラメータの取得
S = input()
Q = int(input())
cnt = 0   #反転回数カウンタ
head = ''
tail = ''

#処理実体処理
for i in range(Q):
  tmp = str(input())
  #Q各行の値を、T, F, Cに基づいて処理
  if tmp[0] == '1':
    cnt += 1
  else:
    T, F, C = tmp.split(' ')
    if cnt % 2 == 1:
      if F == '1':
        tail = tail + C
      else:
        head = C + head
    else:
      if F == '1':
        head = C + head
      else:
        tail = tail + C
    #cnt = 0
  #print('head=',head)
  #print('tail=',tail)

#print('cnt=',cnt)
if cnt % 2 == 0:
  ans = head + S + tail
else:
  ans = tail[::-1] + S[::-1] + head[::-1]
print(ans)


Measured memory_bytes: 4396
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define itn int
bool dbg = false;
string S;
int K;

void solve() {
    /*
    int ans = 0;
    int N = SZ(S);
    int t = 0;
    bool flag2 = false;
    bool SAME = true;
    FOR(i, 0, N - 1) {
        if (S[i] != S[i + 1])
            SAME = false;
    }
    FOR(i, 0, N - 1) {
        if (S[i] == S[i + 1]) {
            if (i == N - 2) {
                flag2 = true;
            }
            t++;
            i++;
        }
    }
    bool flag = false;
    if (N >= 3) {
        if (S[1] == S[0]) {
            FOR(i, 2, N) {
                if (S[i] != S[0]) {
                    if (i % 2 == 0) {
                        flag = true;
                        break;
                    }
                }
            }
        }
    }
    ans += t * K;
    //cout << ans << endl;
    if (S[0] == S[N - 1]) {
        if (flag || flag2) {
        } else {
            ans += K - 1;
        }
    }
    if (SAME) {
        ans = (K * N) / 2;
    }
    cout << ans << endl;
    */


    int N = SZ(S);
    itn ans = 0;
    int k = K / 2;
    int t = 0;
    if (K <= 4) {
        string s;
        FOR(i, 0, K) {
            s += S;
        }
        int t = 0;
        FOR(i, 0, SZ(s) - 1) {
            if (s[i] == s[i + 1]) {
                t++;
                i++;
            }
        }
        cout << t << endl;
        return;
    }
    if (K % 2 == 0) {
        string s = S + S + S;
        FOR(i, 0, SZ(S) - 1) {
            if (S[i] == S[i + 1]) {
                t++;
                i++;
            }
        }
        int t2 = 0;
        FOR(i, 0, SZ(s) - 1) {
            if (s[i] == s[i + 1]) {
                t2++;
                i++;
            }
        }
        int x = t2 - t;
        t = 0;
        s = S + S;
        FOR(i, 0, SZ(s) - 1) {
            if (s[i] == s[i + 1]) {
                t++;
                i++;
            }
        }
        cout << x * (k - 1) + t << endl;
        return;
    } else {
        string s = S + S + S;
        FOR(i, 0, SZ(S) - 1) {
            if (S[i] == S[i + 1]) {
                t++;
                i++;
            }
        }
        int t2 = 0;
        FOR(i, 0, SZ(s) - 1) {
            if (s[i] == s[i + 1]) {
                t2++;
                i++;
            }
        }
        int x = t2 - t;
        cout << x * k + t << endl;
        return;
    }
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> S >> K;
    solve();
    return 0;
}


Measured memory_bytes: 256
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
w=10**7
for i in range(m):
    x,y,c=map(int,input().split())
    w=min(A[x-1]+B[y-1]-c,w)
A=sorted(A)
B=sorted(B)
for i in range(min(a,b)):
    w=min(w,A[i]+B[i])
print(w)

Measured memory_bytes: 18684
#include<stdio.h>

int main(void)
{
  int A[3][3] , B[10] , C[3][3] , N;
  int i , j , k;
  
  for( i=0 ; i<3 ; i++ ){
    for( j=0 ; j<3 ; j++ ){
      scanf( "%d" , &A[i][j] );
      C[i][j] = 0;
    }
  }
  scanf( "%d" , &N );
  for( i=0 ; i<N ; i++ ){
    B[i] = -1;
    scanf( "%d" , &B[i] );
  }
  
  for( k=0 ; k<N ; k++ ){
    for( i=0 ; i<3 ; i++ ){
      for( j=0 ; j<3 ; j++ ){
        if( B[k] == A[i][j] ) C[i][j]=1;
      }
    }
  }
  
  if( C[0][0] + C[0][1] + C[0][2] == 3 ) printf( "Yes" );
  else if( C[1][0] + C[1][1] + C[1][2] == 3 ) printf( "Yes" );
  else if( C[2][0] + C[2][1] + C[2][2] == 3 ) printf( "Yes" );
  else if( C[0][0] + C[1][0] + C[2][0] == 3 ) printf( "Yes" );
  else if( C[0][1] + C[1][1] + C[2][1] == 3 ) printf( "Yes" );
  else if( C[0][2] + C[1][2] + C[2][2] == 3 ) printf( "Yes" );
  else if( C[0][0] + C[1][1] + C[2][2] == 3 ) printf( "Yes" );
  else if( C[0][2] + C[1][1] + C[2][0] == 3 ) printf( "Yes" );
  else printf( "No" );
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
long long pw[32];
void get_pw(){
	pw[0]=1;
	REP(i,1,32){
		pw[i]=pw[i-1]*2;
	}
	re;
}
int main(){
	int n;
	cin>>n;
	ll a[n];
	bool used[n];
	map<ll,pair<vector<int>,int> > m;
	rep(i,n){
		cin>>a[i];
		m[a[i]].se++;
	}
	sort(a,a+n);
	fill(used,0);
	int i=0;
	foreach(itr,m){
		rep(j,itr->se.se){
			itr->se.fi.pb(i);
			i++;
		}
		itr->se.se=0;
	}
	get_pw();
	int ans=0;
	ford(i,n-1){
		if(!used[i]){
			REP(j,1,32){
				if(a[i]>=pw[j-1]&&a[i]<pw[j]){
					if(!m[pw[j]-a[i]].fi.empty()){
						if(m[pw[j]-a[i]].fi.size()!=m[pw[j]-a[i]].se){
							if(!used[m[pw[j]-a[i]].fi[m[pw[j]-a[i]].se]]){
								if(m[pw[j]-a[i]].fi[m[pw[j]-a[i]].se]!=i){
									ans++;
									used[i]=1;
									used[m[pw[j]-a[i]].fi[m[pw[j]-a[i]].se]]=1;
									m[pw[j]-a[i]].se++;
									break;
								}
							}
						}
					}
				}
			}
		} 
	}
	cout<<ans<<endl;
	re 0;
}

Measured memory_bytes: 39424
n = gets.to_i
dp = Array.new(n + 1, n)
dp[1] = 1

c6 = 1
c9 = 1
n.times do |i|
  y = i + 1
  if y == 6 * c6
    dp[y] = 1
    c6 *= 6
  end
  if y == 9 * c9
    dp[y] = 1
    c9 *= 9
  end

  res = [dp[y]]
  res << dp[y - c9] + dp[c9]
  res << dp[y - c6] + dp[c6]
  res << dp[y - 1] + dp[1]
  dp[y] = res.min
end
puts dp[n]

Measured memory_bytes: 15816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

void solve(long long N, vector<long long> H){
	ll res = 0, now = 0;
	repn(i, N-1) {
		if (H[i] <= H[i-1]) now++; else now = 0;
		res = max(res, now);
	}
	cout << res << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> H(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&H[i]);
	}
	solve(N, H);
	return 0;
}



Measured memory_bytes: 1792
/*数组有没有开小
有没有开long long
会不会爆long long
初始化（多组数据，一定要记得把数组清零！！！）
时刻小心数组/容器是否为空
最后容器中剩余是否需要加入答案 
位运算结果的数组，要开2倍。位运算时注意结果的范围可能大于两个数的范围
要考虑边界情况(n=0?n=1?n=最大值?) 
注意变量名(尤其注意:n,n2 i,j)
开bool时注意取值不能为0~2
*/
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define fi first
#define se second
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

const int N=2e5+5;
ll n,k,s,ans,x,a[N];
map<ll,int>m;

int main()
{
	n=read();k=read();
	++m[(n+1)%k];a[0]=(n+1)%k;
	rep(i,1,n){
		s=(s+read())%k;x=(s+n-i+1)%k;a[i]=x;
		if(i>=k)--m[a[i-k]];
		ans+=m[x];//cout<<x<<' '<<m[x]<<endl;
		++m[x];
	}cout<<ans;
	return 0; 
}

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

typedef long long ll;

int main() {
    ll n, k;
    cin >> n >> k;
    unordered_map<int, int> val;
    unordered_map<int, int> parent;
    vector<vector<int>> tree(n + 1);
    int u, v;
    for (int i = 0; i < n - 1; i++) {
        cin >> u >> v;
        tree[u].push_back(v);
        parent[v] = u;
    }
    int j, x;
    for (int i = 0; i < k; i++) {
        cin >> j >> x;
        val[j] += x;
    }
    int root = -1;
    for (int i = 1; i <= n; i++) {
        if (parent.find(i) == parent.end()) {
            root = i;
            break;
        }
    }
    queue<int> q;
    q.push(root);
    while (!q.empty()) {
        u = q.front();
        q.pop();
        for (auto v : tree[u]) {
            q.push(v);
            val[v] += val[u];
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << val[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 29896
#include<cstdio>
int main()
{
    int a,b,c,d,sum,tem;
    while(~scanf("%d%d%d%d",&a,&b,&c,&d))
    {
        if(a<=b)
            tem=a;
        else
            tem=b;
        if(c<=d)
            sum=c;
        else
            sum=d;
        sum+=tem;
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int p10[8];
string s[12];
vector<char> chars;
int ad[26];
bool ngZero[26];

int dfs(int dep, int used, int s = 0) {
	if (dep == chars.size()) {
		return s == 0;
	}
	
	int i;
	int ret = 0;
	rep(i, 10) {
		if ((used >> i) & 1) continue;
		if (i == 0 && ngZero[chars[dep] - 'A']) continue;
		int res = dfs(dep + 1, used + (1 << i), s + i * ad[chars[dep] - 'A']);
		ret += res;
	}
	return ret;
}

int main() {
	int i, j;
	p10[0] = 1;
	rep(i, 7) p10[i + 1] = p10[i] * 10;
		
	while (cin >> n) {
		if (!n) break;
		rep(i, n) cin >> s[i];
		
		chars.clear();
		rep(i, 26) ad[i] = 0;
		rep(i, 26) ngZero[i] = false;
		
		rep(i, n) {
			rep(j, s[i].length()) {
				chars.push_back(s[i][j]);
			}
		}
		sort(chars.begin(), chars.end());
		chars.erase(unique(chars.begin(), chars.end()), chars.end());
		
		//cout << "Chars: "; rep(i, chars.size()) cout << chars[i]; cout << endl;
		//rep(i, 26) { cout << (char)('A' + i) << "| ad = " << ad[i] << ", ngZero = " << ngZero[i] << endl; }
		rep(i, n) {
			int len = s[i].length();
			rep(j, len) {
				if (i < n - 1) ad[s[i][j] - 'A'] += p10[len - 1 - j];
				else ad[s[i][j] - 'A'] -= p10[len - 1 - j];
				if (j == 0 && len >= 2) ngZero[s[i][j] - 'A'] = true;
			}
		}
		
		int res = dfs(0, 0);
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 3008
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=s.length();
    int m=count(be(s),'1');
    cout << n-abs(n-m*2) <<endl;
    return 0;
}


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

int main(){
  int n, m, x, a, c1 = 0, c2 = 0;
  cin >> n >> m >> x;
  rep(i, m) {
    cin >> a;
    if(a < x) c1++;
    else c2++;
  }
  cout << min(c1, c2) << endl;
}	

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

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


Measured memory_bytes: 256
N, M = map(int, input().split())
BrokenSteps = [int(input()) for _ in range(M)]
 
MOD = 1000000007
 
# DPテーブル
dp = [0]*(N+1)
dp[0] = 1
if 1 not in BrokenSteps:  # 1段目が壊れている場合もあるので注意
    dp[1] = 1

steps = list(range(2, N+1))  # 0,1段目は計算済みなので2段目以降
NoBrokenSteps = list(set(steps) - set(BrokenSteps))
    
for i in NoBrokenSteps:
    dp[i] = (dp[i - 1] + dp[i - 2]) % MOD
        
print(dp[-1])

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

using ll = long long; 

int main() {
  int N, R;
  cin >> N >> R;

  int IR;
  if (N < 10) {
    IR = R + 100 * (10 - N);
  }
  else {
    IR = R;
  }
  cout << IR << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007

const ll INF=100000;

int main(){
  string s,t;
  cin  >> s;
  ll ans=0,resa,resz;
  ll flga=false,flgz=false;
  rep(i,s.size()){
    if(s[i]=='A'){
      if(!flga)resa=i;
      flga=true;
    }
    if(s[s.size()-i-1]=='Z'){
      if(!flgz)resz=s.size()-i-1;
      flgz=true;
    }
  }

  cout << resz-resa+1 << endl;
}


Measured memory_bytes: 640