akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


void solve(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N), B(N);
    REP(i,N) cin >> A[i] >> B[i];
    ll ans = 0;
    REP(i,N){
        bool ok = true;
        REP(j,30) if(!(K >> j & 1) && (A[i] >> j & 1)){
            ok = false;
            break;
        }
        if(ok) ans += B[i];
    }

    REP(i,30){
        if(K >> i & 1){
            ll c = K & ~(1LL << i);
            c |= (1LL << i) - 1;
            ll tmp = 0;
            REP(j,N){
                bool ok = true;
                REP(k,30){
                    if(!(c >> k & 1) && (A[j] >> k & 1)){
                        ok = false;
                        break;
                    }
                }
                if(ok) tmp += B[j];
            }
            chmax(ans, tmp);
        }
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}

Measured memory_bytes: 1024
X, N = list(map(int, input().split()))
P = list(map(int, input().split()))

P = set(P)

diff = float('INF')
ans = None
for i in range(0, 102):
    if i in P:
        continue
    d = abs(X - i)
    if d < diff:
        diff = d
        ans = i

print(ans)

Measured memory_bytes: 9108
# -*- coding:utf-8 -*-

def solve():
    K, S = list(map(int, input().split()))

    ans = 0
    for x in range(K+1):
        for y in range(K+1):
            if x+y > S:
                break
            if S-x-y <= K:
                ans += 1
    print(ans)



if __name__ == "__main__":
    solve()


Measured memory_bytes: 3064
from sys import stdin
input = stdin.readline

def main():
    X, K, D = map(int, input().rstrip().split())
    X = abs(X)
    c = X // D
    if c < K:   
        X = X % D
        K = K - c
        K = K % 2
    ans = X - (D * K)
    print(abs(ans))
if __name__ == "__main__":
    main()
    


Measured memory_bytes: 61692
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1000000007,inv2=500000004;
inline int kpow(int a,int b)
{
	int s=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1)s=1ll*s*a%mod;
	return s;
}
inline void add(int &x,int y){(x+=y)>=mod?x-=mod:0;}
int n,a[200020],cnt[200020],inv[200020],D[200020],s,ans,cnt0[200020],lp[200020],rp[200020];
struct BIT
{
	int sum[200020];
	inline void ins(int p,int w){while(p<=n)add(sum[p],w),p+=p&-p;}
	inline int query(int p)
	{
		int s=0;
		while(p)add(s,sum[p]),p-=p&-p;
		return s;
	}
}t1,t2,t3;
int main()
{
	scanf("%d",&n);
	inv[1]=1;
	for(int i=2;i<=n;++i)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	for(int i=1;i<=n;++i)scanf("%d",&a[i]),++cnt[a[i]];
	s=1;
	for(int i=n;i;--i)cnt[i]+=cnt[i+1];
	for(int i=1;i<=n;++i)
	{
		cnt[i]-=(n-i);
		s=1ll*s*cnt[i]%mod;
		if(cnt[i]<=0)
		{
			printf("0");
			return 0;
		}
	}
	D[0]=1;
	for(int i=1;i<=n;++i)
	{
		D[i]=1ll*(cnt[i]-1)*inv[cnt[i]]%mod;
		if(!D[i])cnt0[i]=cnt0[i-1]+1,D[i]=D[i-1];
		else cnt0[i]=cnt0[i-1],D[i]=1ll*D[i]*D[i-1]%mod;
	//	printf("%d %d %d\n",cnt[i],D[i],cnt0[i]);
	}
	lp[0]=1;
	for(int i=1;i<=n;++i)
	{
		if(cnt0[i]!=cnt0[i-1])lp[i]=i;
		else lp[i]=lp[i-1];
	}
	for(int i=n;i;--i)
	{
		if(cnt0[i]!=cnt0[i+1])rp[i]=i;
		else rp[i]=rp[i+1];
	}
	for(int i=1;i<=n;++i)
	{
		int dv=kpow(D[a[i]],mod-2);
		ans=(ans+1ll*D[a[i]]*(t1.query(a[i])+mod-t1.query(lp[a[i]]-1)))%mod;
		ans=(ans+(t3.query(n)-t3.query(a[i]))*2-1ll*dv*(t2.query(rp[a[i]])+mod-t2.query(a[i])))%mod;
		t1.ins(a[i],dv);
		t2.ins(a[i],D[a[i]]);
		t3.ins(a[i],1);
	}
	ans=1ll*ans*s%mod*inv2%mod;
	if(ans<0)ans+=mod;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 7936
w,h,n = map(int,input().split())
p = [list(map(int,input().split())) for i in range(n)]

xmin,xmax,ymin,ymax = 0,w,0,h

for x,y,a in p:
    if a == 1:
        if x > xmin:
            xmin = x

    elif a == 2:
        if x < xmax:
            xmax = x

    elif a == 3:
        if y > ymin:
            ymin = y

    elif a == 4:
        if y < ymax:
            ymax = y

if xmax-xmin < 0 or ymax-ymin < 0:
    print(0)
else:
    print((xmax-xmin) * (ymax-ymin))


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

int main() {
    string s;
    cin >> s;
    int counter = 700;
    if (s[0] == 'o') counter += 100;
    if (s[1] == 'o') counter += 100;
    if (s[2] == 'o') counter += 100;
    cout << counter << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b,c;
        if(a==1){
            System.out.println("Hello World");
        }else{
            b=sc.nextInt();
            c=sc.nextInt();
            System.out.println(b+c);
        }
    }
}


Measured memory_bytes: 22484
#include <iostream>
using namespace std;
int main(void){
    
    string S;
    cin>>S;
    int count=0,S_end=S.size()-1;
    
    for(int i=0; i<S.size()/2; i++){
        if(S[i] !=S[S_end-i]){
            count++;
        }
    }
    
    cout<<count<<endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  ll n,t; cin >> n >> t;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll sum=n*t;
  for(int i=1;i<n;i++){
    if(a[i]-a[i-1]<t) sum-=t-(a[i]-a[i-1]);
  }
  cout << sum << endl;
}

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

int main(){
  int n; cin >> n;
  int R[n];
  for(int i=0; i<n; i++) cin >> R[i];
  int Rmax[n];
  Rmax[n-1] = 0;
  int ans = R[1] - R[0];
  for(int i=n-2; i>=0; i--){
    Rmax[i] = max(Rmax[i+1], R[i+1]);
    ans = max(ans, Rmax[i] - R[i]);
  }
  cout << ans << endl;
}


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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;


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

	int a; cin>>a;
	string s ; cin>>s;

	if(a >=3200){
		writeln(s);
	}else {
		writeln("red");
	}
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
      int a,b;
      cin>>a>>b;
    if(a==b)printf("Draw\n");
    else if((a==1&&b!=1)|| a>b&&b!=1)printf("Alice\n");
    else if((b==1&&a!=1)|| b>a&&a!=1)printf("Bob\n");
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int num1, num2;

    for (num1=1;num1<10;num1++) {
        for (num2=1; num2<10; num2++) {
            printf("%dx%d=%d\n", num1, num2, num1*num2);
        }
    }

    return(0);
}

Measured memory_bytes: 924
l=list(map(int,input().split()))
l+=list(map(int,input().split()))
l+=list(map(int,input().split()))

n=int(input())

ans_list=[False]*9

for i in range(n):
  num=int(input())
  if num in l:
    index=l.index(num)
    ans_list[index]=True
    
if ans_list[0] and ans_list[1] and ans_list[2]:
  print("Yes")
elif ans_list[0] and ans_list[3] and ans_list[6]:
  print("Yes")
elif ans_list[3] and ans_list[4] and ans_list[5]:
  print("Yes")
elif ans_list[6] and ans_list[7] and ans_list[8]:
  print("Yes")
elif ans_list[1] and ans_list[4] and ans_list[7]:
  print("Yes")
elif ans_list[2] and ans_list[5] and ans_list[8]:
  print("Yes")
elif ans_list[0] and ans_list[4] and ans_list[8]:
  print("Yes")
elif ans_list[2] and ans_list[4] and ans_list[6]:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 9248
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
l = LIST()
l.sort()
if l[-1] < sum(l) - l[-1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 5156
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

typedef pair<int, int> P;

int main() {
	int p, q;
	while (cin >> p >> q) {
		vector<P> v;
		while (p % q) {
			p *= 10;
			P rq = P(p % q, p / q);
			if (find(v.begin(), v.end(), rq) != v.end())
				break;
			v.push_back(rq);
			p %= q;
		}
		int start = find(v.begin(), v.end(), P(p % q, p / q)) - v.begin();
		for (int i = 0; i < v.size(); i++)
			cout << v[i].second;
		cout << endl;
		if (p % q) {
			for (int i = 0; i < v.size(); i++)
				cout << (i >= start ? "^" : " " );
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1204
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
struct data{
    int a,b,c;
};

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
#define MAXSIZE 200000
int list[MAXSIZE];
int tail;

void Init(void){
    tail=0;
}
int Top(void){
    return 0;
}

int Next(int pos){
    if(pos<tail-1){
        return pos+1;
    }else{
        return -1;
    }
}
int Count(void){
    return tail;
}

int Item(int pos){
    if((pos>=0)&&(pos<tail)){
        return list[pos];
    }else{
        return 0;
    }
}
void Add(int value){
    if(tail<MAXSIZE){
        list[tail]=value;
        tail++;
    }
}
void Delete(int pos){
    if((pos>=0)&&(pos<tail)){
        int i;
        for(i=pos;i<tail-1;i++){
            list[i]=list[i+1];
        }
        tail--;
    }
}

int main(){
    int N,D,X;
    scanf("%d%d%d",&N,&D,&X);
    int chil[N];
    int sum=0;
    rep(i,N){
        scanf("%d",&chil[i]);
    }
    rep(i,N){
        int cnt=0;
        int temp=0;
        while(temp<=D){
            temp=cnt*chil[i]+1;
            cnt++;
        }
        sum+=cnt-1;
    }
    printf("%d",sum+X);
}


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

int main(void){
    string S;
    int K;
    cin >> S >> K;
    for(int i = 0; i < S.size();i++){
        char C = S[i];
        int todo = 'z' - C + 1;
        if(C == 'a')continue;
        if(K >= todo){
            S[i] = 'a';
            K -= todo;
        }
    }
    K %= 26;
    for(int i = S.size()-1; i>=0;i--){
        if(K > 0){
            char C = S[i];
            C += K;
            S[i] = C;
            K = 0;      
        }
    }
    cout << S << endl;
    
}


Measured memory_bytes: 512
#include <cstring>
#include <iostream>
#include <set>

using namespace std;

struct key_type
{
	char str[13];
	bool operator < (const key_type& obj) const {
		return strcmp(this->str, obj.str) < 0;
	}
};

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

	int n;
	char command[7];
	key_type key;
	set<key_type> dictionary;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> command >> key.str;
		if (command[0] == 'i') {
			dictionary.insert(key);
		}
		else {
			cout << (dictionary.count(key) ? "yes" : "no") << '\n';
		}
	}

	return 0;
}

Measured memory_bytes: 18412
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

#define Pi 3.14159265                   

int main()
{
   FAST/**/
   
   ll n;
   cin>>n;
   
   ll arr[n+1];
   rep(n-1)
        cin>>arr[i+1];
   ll sum[n+1];
   memset(sum,0,sizeof(sum));
   for(ll i=1;i<n;i++)
        sum[arr[i]]++;
   for(ll i=1;i<=n;i++)
        cout<<sum[i]<<"\n";
   
   return 0;        
}  
  
   

Measured memory_bytes: 6776
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); ++i)
#define repf(i, from, to) for (int i = (from); i < (to); ++i)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int n;
  cin >> n;
  V<V<int>> field(2, V<int>(n, 0));
  rep(i, 2) {
    rep(j, n) {
      cin >> field[i][j];
    }
  }

  int max_candy = 0;
  rep(to_buttom_i, n) {
    int current_i = 0;
    int current_j = 0;
    int candy_count = 0;

    rep(i, n + 1) {
      candy_count += field[current_i][current_j];

      if(current_i == 1 && current_j == n - 1) {
        break;
      }

      if(i == to_buttom_i) {
        current_i++;
      } else {
        current_j++;
      }
    }

    max_candy = max(max_candy, candy_count);
  }

  cout << max_candy << endl;
}

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

int main()
{
        char str[100];
        int i = 0, j = 0, flag, cnt = 0;

        while ( scanf( "%s", str ) == 1 ) {
                i = 0;
                flag = 0;
                j = 0;
                i = strlen( str );

                while ( j <= i - (j+1) ) {
                        if ( str[j] != str[i-(j+1)] ) {
                                flag = 1;
                                break;
                        }
                        j++;
                }

                if ( flag == 0 ) {
                        cnt++;
                }
        }

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

        return 0;
}



Measured memory_bytes: 2080
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

const double rate = 380000;

int main(){
	int n;
	cin >> n;
	double ans = 0;
	for(int i=0; i<n; i++){
		double a;
		string s;
		cin >> a >> s;
		if(s == "JPY"){
			ans += a;
		}else{
			ans += a*rate;
		}
	}
	cout << fixed << setprecision(10);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long long int (i) = 0; (i) < (int) (n); (i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;
#include <stdio.h>

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    long ans = 0;
    vector<pair<ll, pair<int, int> > > h;
    rep(i, n) {
        int a,b;
        cin >> a >> b;
        h.push_back(make_pair(a + b, make_pair(a,b)));
    }

    sort(ALL(h));
    reverse(ALL(h));

    rep(i, h.size()) {
        if (i % 2 == 0) {
            ans += h[i].second.first;
        } else {
            ans -= h[i].second.second;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2420
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long ll;
const ll N=2020,mo=1e9+7;

ll f[N<<1][N],g[N<<1];

int n,m,k;

int main()
{
	cin>>n>>m>>k;
	int v=n%(k-1),u=m%(k-1); 
	ll ans=0;
	fo(i,0,k-1)f[1][i]=1;
	fo(i,1,k-1)if(i%(k-1)==v)++ans; 
	fo(i,2,n+m){
		g[0]=f[i-1][0];
		fo(l,1,n)g[l]=(g[l-1]+f[i-1][l])%mo;
		fo(l,0,n)if(l-k<0)f[i][l]=g[l];else f[i][l]=(g[l]-g[l-k]+mo)%mo;
		fo(l,1,n)if(l%(k-1)==v&&(k-1)*i+1-l<=m)ans=(ans+f[i][l]-f[i-1][l]+mo)%mo;
	}
	cout<<ans;
}

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

int p;
string str;

int Term();
int Factor();
int Elem();
int Digit();

int Term() {
  int a = Factor();
  while (str[p] == '+' || str[p] == '-') {
    char c = str[p];
    p++; // read [+-]
    int b = Factor();
    if (c == '+') {
      a = a + b;
    } else {
      a = a - b;
    }
  }
  return a;
}

int Factor() {
  int a = Elem();
  while (str[p] == '*' || str[p] == '/') {
    char c = str[p];
    p++; // read [*/]
    int b = Elem();
    if (c == '*') {
      a = a * b;
    } else {
      a = a / b;
    }
  }
  return a;
}

int Elem() {
  if (str[p] == '(') {
    p++; // read (
    int a = Term();
    p++; // read )
    return a;
  } else {
    int a = 0;
    while (isdigit(str[p])) {
      int b = Digit();
      a = 10 * a + b;
    }
    return a;
  }
}

int Digit() {
  int a = str[p] - '0';
  p++; // read [0-9]
  return a;
};

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> str;
    p = 0;
    cout << Term() << endl;
  }
}

Measured memory_bytes: 1208
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000009
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	H := nextInt()
	_ = nextInt()
	for i := 0; i < H; i++ {
		s := nextLine()
		fmt.Println(s)
		fmt.Println(s)
	}
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 32128
#include <stdio.h>

using namespace std;

int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if((x >= r && x <= W-r) && (y >= r && y <= H-r))
		printf("Yes\n");
	else{
		printf("No\n");
	}
}



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

int main() {
  int n;
  cin>>n;
  vector<double> v;
  for(int i=0;i<n;i++){
    int s;
    cin>>s;
    v.push_back(s);
    

  }
  sort(v.begin(),v.end());
  for(int i=1;i<n;i++)v[i]=(v[i]+v[i-1])/2;
  cout<<v[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=100001;
struct num
{
	int yuan,appear;
	num() {yuan=appear=0;}
}con[MAXN];
int tot=1,ans=0,arr[MAXN];
inline bool CMP(int a,int b)
{
	return a<b;
}
inline int read()
{
	int 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*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	int n=read();
	for(int i=1;i<=n;++i) arr[i]=read();
	sort(arr+1,arr+n+1,CMP);
	con[1].yuan=arr[1];con[1].appear=1;
	for(int i=2;i<=n;++i)
		if(arr[i]==arr[i-1]) ++con[tot].appear;
		else {con[++tot].yuan=arr[i];con[tot].appear=1;}
	for(int i=1;i<=tot;++i)
		if(con[i].appear>con[i].yuan) ans+=(con[i].appear-con[i].yuan);
		else if(con[i].appear<con[i].yuan) ans+=con[i].appear;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define M 1000000007
int main()
{
    IOS
    map<char,ll> Hash;
    ll n; cin>>n;
    string str; cin>>str;
    for(ll i=0;i<n;i++) Hash[str[i]]++;
    ll ans = 1;
    for(auto it = Hash.begin();it != Hash.end();it++)
    {
        ans = (ans*(it->second + 1))%M;
    }
    cout<<(ans-1)%M<<endl;
    return 0;
}

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

int main ()
{
	int ret = 1;
	int n;
	long k;
	int a[200000];
	long b[200000];

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

	for (long j=k; j>0; j--) {
#if 1
		if (b[ret-1] != INT_MAX) {
			j = j % (b[ret-1] - j);
			//cout << endl << " -- k= " << j << " : " << (b[ret-1] - j) << endl;
			if (j == 0) break;
		}
#endif
		b[ret-1] = j;
		ret = a[ret-1];
		//cout << " " << ret;
	}
	//cout << endl;

	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 5980
while True:
  x, op, y = input().split()
  x = int(x)
  y = int(y)

  if op == "?":
    break
  elif op == "+":
    print(x + y)
  elif op == "-":
    print(x - y)   
  elif op == "*":
    print(x * y) 
  elif op == "/":
    print(x // y) 
 


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

int gcd(int x, int y){
    if (x < y){ swap(x, y); }
    while(x%y != 0){
        int tmp = 0;
        tmp = x;
        x = y;
        y = tmp%y;
    }
    return y;
}

int main(){
    int x, y;
    cin >> x >> y;
    cout << gcd(x, y) << endl;
}


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

using namespace std;

typedef long long ll;
const ll inf = 0x3f3f3f3f;
#define case(i) "Case #" << i << ": "
 
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
    out << '(' << p.first << ", " << p.second << ')';
    return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
    ll l = v.size();
    for (ll i = 0; i < l - 1; i++) out << v[i] << ' ';
    if (l > 0) out << v[l - 1];
    return out;
}

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

    int n;
    cin >> n;
    map<int, int> s;
    vector<int> a(n);

    unordered_set<int> us;

    int mx = -1;

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

        mx = max(mx, a[i]);
    }

    for(ll x: a) {
        if(us.find(x) != us.end()) continue;

        for(int i = 2; x * i <= mx; ++i) {
            if(s.find(x * i) != s.end()) {
                us.insert(x * i);
            }
        }
    }


    int cnt(0);
    for(int x: a) {
        if(us.find(x) == us.end()) {
            if(s[x] == 1) cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 21464
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u)  {
  int v;
  color[u] = GRAY;
  d[u] =++tt;
  for (v = 0; v < n; v++)  {
    if (M[u][v] == 0)
      continue;
    if (color[v] == WHITE) { 
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs()  {
  int u;
  for (u = 0; u < n; u++)  
    color[u] = WHITE;
  tt = 0;
  
  for (u = 0; u < n; u++)  {
    if (color[u] == WHITE) 
      dfs_visit(u);
  }
  for (u = 0; u < n; u++)  {
    printf("%d %d %d\n", u + 1, d[u], f[u]);
  }
}
 
int main(void)  {
  int u, v, k, i, j;
  
  scanf("%d", &n);
  for(i = 0; i < n; i++)  {
    for (j = 0; j < n; j++)  {
      M[i][j] = 0;
    }
  }
  
  for (i = 0; i < n; i++)  {
    scanf("%d %d", &u, &k);
    u--;
    for (j = 0; j < k; j++)  {
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }
  dfs();

  return 0;
}
     

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
int f(int n){
  if(n%2==0){
    return n/2;
  }else{
    return n*3+1;
  }
}

int main() {
  int s;cin>>s;
  set<int> se;
  int before=s;
  se.insert(s);
  int ans;
  FOR(i,2,1000000){
    int beforeSize=se.size();
    int cur=f(before);
    se.insert(cur);
    if(beforeSize==se.size()){
      ans=i;
      break;
    }
    before=cur;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
const ll mod = 1000000007;

int main()
{
  int h, w, k; cin >> h >> w >> k;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vector<vector<int>> d(h, vector<int>(w, 0));

  rep(i, h) rep(j, w) {
    if (s[i][j] == '1') d[i][j] = 1;
  }
  rep(i, h) {
    for (int j=1; j<w; j++) {
      d[i][j] += d[i][j-1];
    }
  }
  rep(j, w) {
    for (int i=1; i<h; i++) {
      d[i][j] += d[i-1][j];
    }
  }

  ll ans = 1001001001;
  for (int bits=0; bits<1<<(h-1); bits++) {
    ll tmp = __builtin_popcountll(bits);
    int r = 0;
    int l = 0;
    while (r < w) {
      int t = 0;
      int b = 0;
      bool flg = false;
      while (t < h) {
        while (((bits>>b)&1) == 0 && b < h-1) b++;
        int x = 0;
        if (t == 0) {
          if (l == 0) x = d[b][r];
          else x = d[b][r] - d[b][l-1];
        } else {
          if (l == 0) x = d[b][r] - d[t-1][r];
          else x = d[b][r] - d[t-1][r] - d[b][l-1] + d[t-1][l-1];
        }
        if (x > k) {
          flg = true;
          break;
        }
        t = b+1;
        b = t;
      }
      if (flg) {
        tmp++;
        if (r == l) {
          tmp = 1001001001;
          break;
        }
        l = r;
      } else {
        r++;
      }
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
int a[200005],b[200005],c[200005],d[200005],n,ans;
int main(){
	read(n);
	for(int i=1;i<=n;i++)
		read(a[i]);
	for(int i=1;i<=n;i++)
		read(b[i]);
	for(int i=0;i<=29;i++) {
		int s1=0,s2=0,sum=0;
		for(int j=1;j<=n;j++)
			s1^=(a[j]>>i)&1,s2^=(b[j]>>i)&1;
		sum=(s1+s2)*n%2;
		if(i==0) {
			ans+=sum;
			continue;
		}
		for(int j=1;j<=n;j++)
			c[j]=a[j]&((1<<i)-1);
		for(int j=1;j<=n;j++)
			d[j]=b[j]&((1<<i)-1);
		sort(c+1,c+n+1);
		sort(d+1,d+n+1);
		int r=n;
		for(int j=1;j<=n;j++) {
			while(d[r]+c[j]>=(1<<i))
				r--;
			sum^=(n-r)&1;
		}
		ans+=sum<<i;
	}
	printf("%d",ans);
}


Measured memory_bytes: 3328
#include <stdio.h>
int main(void){
    int A, B, C, D = 0;
    scanf("%ld %ld %ld %ld", &A, &B, &C, &D);
    if(A + B > C + D){
        printf("Left\n");
    }else if(A + B < C + D){
        printf("Right\n");
    }else {
        printf("Balanced\n");
    }
    return 0;
}

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

using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long
#define pb push_back
#define pll pair<ll,ll>
#define ff first
#define ss second
#define N 2000001
#define M 1000000007
#define INF 1000000000000000


int main()
{
  ll n;
  cin>>n;
  string s;
  cin>>s;
  ll r=0,w=0;
  ll i,j;
  for(i=0;i<n;i++)
  {
  	if(s[i]=='R')r++;
  	else w++;
  }
  ll ans=0;
  for(i=0;i<r;i++)
  {
      //cout<<i<<endl;
  		if(s[i]=='W')ans++;
  }
  cout<<ans;

}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  int d[k];
  int a;
   int t[n];
   int q=0;
  for(int i=1; i<=n; i++){
    t[i] = i;
    } 
  for(int i=0; i<k; i++){
    cin >> d[i];
    for(int j=0; j<d[i]; j++){
      cin >> a;
      for(int i=1; i<=n; i++){
        if(a == i){
          t[i] = 0;
        }
      }
        }
  }
  int ans=0;
  for(int i=1; i<=n; i++){
    if(t[i] !=0){
      ans = ans + 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3584
l,x;main(m,n,a){for(;;){scanf("%d",&l);if(!l)exit(0);for(a=1,x=-1;a<13;a++){scanf("%d%d",&m,&n);l-=m-n;l<1&&x<0?x=a:0;}x>0?printf("%d\n",x):puts("NA");}}

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

int H, W, N;

int main() {
	cin >> H >> W >> N;
	queue<int> a;
	vector<vector<int>> t(H+1, vector<int>(W+1));
	for(int i = 1; i <= N; i++) {
		int inp; cin >> inp;
		for(int j = 1; j <= inp; j++) {
			a.push(i);
		}
	}

	int i = 0;
	while(!a.empty()) {
		i++;
		for(int j = 1; j <=W; j++) {
			t[i][j] = a.front();
			a.pop();
		}
		if(a.empty()) break;
		i++;
		for(int j = W; j >= 1; j--) {
			t[i][j] = a.front();
			a.pop();
		}
	}

	for(int i = 1; i <= H; i++) {
		for(int j = 1; j <= W; j++) {
			cout << t[i][j] << " ";
		}
		cout << endl;
	}
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...)); }
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }

template<int MOD>
struct ModInt {
	static const int kMod = MOD;
	unsigned x;
	ModInt() :x(0) {}
	ModInt(signed x_) { x_ %= MOD; if (x_ < 0)x_ += MOD; x = x_; }
	ModInt(signed long long x_) { x_ %= MOD; if (x_ < 0)x_ += MOD; x = x_; }
	int get()const { return (int)x; }
	ModInt &operator+=(ModInt m) { if ((x += m.x) >= MOD)x -= MOD; return *this; }
	ModInt &operator-=(ModInt m) { if ((x += MOD - m.x) >= MOD)x -= MOD; return *this; }
	ModInt &operator*=(ModInt m) { x = (unsigned long long)x*m.x%MOD; return *this; }
	ModInt &operator/=(ModInt m) { return *this *= m.inverse(); }
	ModInt operator+(ModInt m)const { return ModInt(*this) += m; }
	ModInt operator-(ModInt m)const { return ModInt(*this) -= m; }
	ModInt operator*(ModInt m)const { return ModInt(*this) *= m; }
	ModInt operator/(ModInt m)const { return ModInt(*this) /= m; }
	ModInt operator-()const { return ModInt(MOD - (signed)x); }
	bool operator==(ModInt m)const { return x == m.x; }
	bool operator!=(ModInt m)const { return x != m.x; }
	ModInt inverse()const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		if (u < 0)u += MOD;
		return ModInt(u);
	}
};
template<int MOD>
ostream &operator<<(ostream &os, const ModInt<MOD> &m) { return os << m.x; }
template<int MOD>
istream &operator>>(istream &is, ModInt<MOD> &m) { signed long long s; is >> s; m = ModInt<MOD>(s); return is; };

template<int MOD>
ModInt<MOD> pow(ModInt<MOD> a, unsigned long long k) {
	ModInt<MOD> r = 1;
	while (k) {
		if (k & 1)r *= a;
		a *= a;
		k >>= 1;
	}
	return r;
}

using mint = ModInt<MOD>;


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

	int N; cin >> N;
	vector<int> A(N); rep(i, 0, N) {
		cin >> A[i];
	}

	vector<mint> P(N + 1);
	rep(i, 1, N) {
		P[i + 1] += P[i];
		P[i + 1] += mint(1) / (i + 1);
	}
	mint ans = 0;
	rep(i, 0, N) {
		ans += (P[N - i] + P[i + 1] + 1) * A[i];
	}

	rep(i, 0, N) {
		ans *= i + 1;
	}
	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N);
  vector<int> D(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }for(int i=0;i<N;i++){
    cin>>B[i];
  }
  int X=0;
  int Y;
  long long ANS=0;
  for(int i=0;i<30;i++){
    Y=0;
    X+=(1<<i);
    for(int j=0;j<N;j++){
      C[j]=(A[j]&X);
      D[j]=(B[j]&X);
    }
    sort(D.begin(),D.end());
    for(int j=0;j<N;j++){
      if(C[j]&(1<<i)){
        Y+=N;
        Y+=lower_bound(D.begin(),D.end(),(1<<(i+1))-C[j])-D.begin();
        Y-=lower_bound(D.begin(),D.end(),(1<<(i+1))+(1<<i)-C[j])-D.begin();
      }else{
        Y+=lower_bound(D.begin(),D.end(),(1<<(i+1))-C[j])-D.begin();
        Y-=lower_bound(D.begin(),D.end(),(1<<i)-C[j])-D.begin();
      }
    }
    if(Y&1){
      ANS+=(1<<i);
    }
  }
  cout<<ANS<<"\n";
}

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

int main(){
    string s;
    cin >> s;
    s += "T";
    int x, y;
    cin >> x >> y;
    vector<bool> dpx(16001, false);
    vector<bool> dpy(16001, false);
    int N = (int)s.size();
    
    bool hori = true;
    bool first = true;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (s[i] == 'F') {
            cnt++;
            continue;
        }
        if (s[i] == 'T' && first == true) {
            dpx[8000+cnt] = true;
            dpy[8000] = true;
            first = false;
            hori = !hori;
            cnt = 0;
            continue;
        }
        if (hori) {
            vector<bool> dp(16001, false);
            for (int j = 0; j < 16001; j++) {
                if (j-cnt >= 0 && dpx[j-cnt]) dp[j] = true;
                if (j+cnt <= 16000 && dpx[j+cnt]) dp[j] = true;
            }
            dpx = dp;
            cnt = 0;
            hori = false;
        }
        else if (!hori){
            vector<bool> dp(16001, false);
            for (int j = 0; j < 16001; j++) {
                if (j-cnt >= 0 && dpy[j-cnt]) dp[j] = true;
                if (j+cnt <= 16000 && dpy[j+cnt]) dp[j] = true;
            }
            dpy = dp;
            cnt = 0;
            hori = true;
        }
    }
    cout << ((dpx[8000+x] && dpy[8000+y]) ? "Yes" : "No") << endl;
    
    return 0;
}

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

using namespace std;

int n, a, b;
long long k;
long long res = 0;
const long long mod = 998244353;
int fact[300005];
int fpow[300005];

int get(int n, int k)
{
	if (k == 1) return n;
	if (k == 0) return 1;
	int cur = get(n, k/2);
	if (k % 2 == 1)
	{
		return (((1ll*cur*cur)%mod)*n)%mod;
	}
	else
	{
		return (1ll*cur*cur)%mod;
	}
}

void init()
{
	fact[0] = 1;
	for (int i = 1; i <= 300000; i++)
	{
		fact[i] = (1ll*fact[i-1]*i)%mod;
	}
	for (int i = 0; i <= 300000; i++)
	{
		fpow[i] = get(fact[i], mod-2);
	}
}

int getres(int n, int k)
{
	if (n < k) return 0;
	return ((1ll*fact[n]*fpow[k])%mod)*fpow[n-k]%mod;
}

void in()
{
	cin >> n >> a >> b >> k;
}

void solve()
{
	init();
	for (int i = 0; i <= n; i++)
	{
		if (1ll*i * a <= k)
		{
			if ((k - 1ll*i*a)%b == 0)
			{
				long long j = (k - 1ll*i*a)/b;
				res += (1ll*getres(n, i)*getres(n, j))%mod;
				res %= mod;
			}
		}
	}
}

void out()
{
	cout << res;
}

signed main()
{
	in();
	solve();
	out();
}

Measured memory_bytes: 2560
#!/usr/bin/env python3
import sys


def solve(N: int):
    print(str(N).count("2"))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << 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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

class RMQ {
private:
    vector<ll> val;
    int N;
public:
    RMQ(int n, ll init);
    void update(int i, int x);
    ll find(int r, int l, int fn, int fr, int fl);
    ~RMQ();
};

RMQ::RMQ(int n, ll init) {
    N = n;
    val.resize(2*N-1, init);
}

void RMQ::update(int i, int x) {
    i += N-1;
    val[i] = x;
    while (i > 0) {
        i = (i-1)/2;
        val[i] = min(val[i*2+1], val[i*2+2]);
    }
}

ll RMQ::find(int a, int b, int k, int l, int r) {
    // [a, b)のクエリ
    // ノードk(区間[a, b)担当)が答える
    if (b <= l || r <= a) return LINF; // 区間がかぶらなければLINF
    if (a <= l && r <= b) return val[k]; // 区間が完全にかぶっていればval[k]
    else {
        // 一部だけかぶる場合は左右の子に委託する
        ll c1 = find(a, b, 2*k+1, l, (l+r)/2);
        ll c2 = find(a, b, 2*k+2, (l+r)/2, r);
        return min(c1, c2);
    }
}

RMQ::~RMQ() {
}

int main(int argc, char const *argv[]) {
    int n,m; cin>>n>>m;
    string s; cin>>s;
    int N = 1;
    while (N<(n+1)) N*=2;
    RMQ dp(N,INF);
    dp.update(n,0);
    vector<int> ans(n+1,INF);
    ans[n] = 0;
    for (int i = n-1; i >= 0; --i) {
        if (s[i]=='1') continue;
        int cost = dp.find(i, min(n+1,i+m+1),0,0,N)+1;
        dp.update(i,cost);
        ans[i] = cost;
    }
    // print(ans);
    if (ans[0]>=INF) {
        cout << -1 << '\n';
        return 0;
    }

    vector<int> id;
    id.push_back(0);
    int x = ans[0];
    rep(i,n) {
        if (ans[i]!=ans[i+1] && x>ans[i+1]) {
            id.push_back(i+1);
            x = ans[i+1];
        }
    }
    // print(id);
    rep(i,id.size()-1) {
        cout << id[i+1]-id[i] << ' ';
    }
    cout << '\n';

    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define forN(N) if(N >= 0)for(size_t i = 0;i < N;++i)
typedef unsigned long long ul ;

int main() {
  ul D;
  vector<int>c;
  vector<int>last;
  vector<int>best;
  vector<vector<int>>s;
  cin >> D;
  forN(26){
    int t;
    cin >> t;
    c.push_back(t);
    last.push_back(-1);
  }
  forN(D){
    vector<int> tv;
    int maxI = -1;
    int maxN = -1;
    for(int j = 0;j < 26;++j){
      int t;
      cin >> t;
      tv.push_back(t);
      int nnn = (t + (c[j] * (i - last[j])));
      //cout << nnn << ",";
      if(maxN < nnn){
		maxN = nnn;
        maxI = j;
      }
    }
    cout << (maxI + 1) << endl;
    last[maxI] = i;
    s.push_back(tv);
    best.push_back(maxI);
  }
}


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

int main() {
    int N;
    cin >> N;
    int num[100100] = {};
    long long sum = 0;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        num[A]++;
        sum += A;
    }

    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        long long B, C;
        cin >> B >> C;
        sum -= B * num[B];
        sum += C * num[B];
        num[C] += num[B];
        num[B] = 0;
        cout << sum << endl;
    }
}

Measured memory_bytes: 4020
import numpy as np
N,D= list(map(int, input().split()))
A = []
ans = 0

for i in range(N):
    x = np.array(list(map(int, input().split())))
    A.append(x)
    
for i in range(N):
    for j in range(i+1,N):
        dist = np.linalg.norm(A[i]-A[j])
        if dist == int(dist):
            ans += 1

print(ans)

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

typedef long long ll;
ll M = 1e9 + 7;
ll n, ans = 1, c[150];
string s;
int main()
{
	ll i;
	cin >> n >> s;
	for (i = 0; i < n; i++) c[s[i]]++;
	for (i = 'a'; i <= 'z'; i++) ans = ans * (c[i] + 1) % M;
    cout << ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
	int time=0;
	int i,m,s,a;
	
	for( i=0 ; i<4 ; i++){
	
	scanf("%d",&a);
	
	time+=a;
	}
	
	m=time/60;
	s=time%60;
	
	printf("%d\n",m);
	printf("%d\n",s);
	
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin>>N;
    int t=0,x=0,y=0,nx,ny,nt,dx,dy,dt;
    bool ok=true;
    rep(i,N)
    {
        cin>>nt>>nx>>ny;
        dx=nx-x;
        dy=ny-y;
        dt=nt-t;
        if(!(dt>= dx+dy and (dt%2)==(dx+dy)%2))
        ok=false;
    }
    cout<<(ok?"Yes":"No");
    return 0;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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

int main(){

    int x, n;
    cin >> x >> n;
    vector<bool> p(101, false);
    for(int i = 0; i < n; i++){
        int v;
        cin >> v;
        p[v] = true;
    }
    int l, r;
    l = r = x;
    int dl, dr;
    dl = dr = 0;
    for(int i = x; i >= -100; i--){
        if(p[i] == false){
            l = i;
            break;
        } 
        dl++;
    }
    for(int i = x; i <= 200; i++){
        if(p[i] == false){
            r = i;
            break;
        } 
        dr++;
    }
    if(dl <= dr) cout << l << endl;
    else cout << r << endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int len = s.length();
    // dp[i]：i桁目まで見た時のmod 2019
    long[] dp = new long[len + 1];
    // mod iの個数
    long[] r = new long[2019];
    long[] f = new long[len];
    f[0] = 1;
    for(int i = 1; i < len; i++) {
      f[i] = (f[i - 1] * 10) % 2019;
    }
    for(int i = len - 1; i >= 0; i--) {
      int t = len - i;
      int d = Integer.parseInt(String.valueOf(s.charAt(i)));
      dp[t] = (dp[t - 1] + (f[t - 1] * d)) % 2019;
      r[(int)dp[t]]++;
    }
    long ans = r[0];
    for(int i = 0; i < 2019; i++) {
      long t = r[i];
      ans += ((t * (t - 1)) / 2);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 52932
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			int n = Integer.parseInt(br.readLine());

			if(n == 0){
				break;
			}

			Point2D input[] = new Point2D[n];

			for(int i = 0; i < n; i++){
				String[] tmpArray = br.readLine().split(",");

				double x = Double.parseDouble(tmpArray[0]);
				double y = Double.parseDouble(tmpArray[1]);

				input[i] = new Point2D.Double(x, y);
			}

			Convex convex = new Convex(input);

			System.out.println(n - convex.getSize());
		}
	}

	static void printPointAsInt(Point2D point){
		System.out.println((int)point.getX()+" "+(int)point.getY());
	}

}

class Convex {
	//並び順は一番左から時計回り
	Point2D points[];

	Convex(Point2D[] points){

		//x座標で整列
		Arrays.sort(points, (p1, p2) ->(p1.getX() == p2.getX() ?
				(p1.getY() == p2.getY() ? 0 : (p1.getY() > p2.getY() ? 1 : -1)) :
					(p1.getX() > p2.getX() ? 1 : -1))
				);

		ArrayList<Point2D> upper = new ArrayList<Point2D>();
		ArrayList<Point2D> lower = new ArrayList<Point2D>();

		//この2点が上の凸包にあるとする
		upper.add(points[0]);
		upper.add(points[1]);

		for(int i = 2; i < points.length; i++){
			upper.add(points[i]);

			//最後の3点が左回りなら最後から2番目の点を削除
			while(upper.size() >= 3 && crossProduct(upper.get(upper.size() - 3), upper.get(upper.size() - 2), upper.get(upper.size() - 1)) > 0){
				upper.remove(upper.size() - 2);
			}
		}

		//この2点が下の凸包にあるとする
		lower.add(points[0]);
		lower.add(points[1]);

		for(int i = 2; i < points.length; i++){
			lower.add(points[i]);

			//最後の3点が左回りなら最後から2番目の点を削除
			while(lower.size() >= 3 && crossProduct(lower.get(lower.size() - 3), lower.get(lower.size() - 2), lower.get(lower.size() - 1)) < 0){
				lower.remove(lower.size() - 2);
			}
		}

		this.points = new Point2D[upper.size() + lower.size() - 2];

		//upperとlowerを合成した配列を作る
		for(int i = 0; i < upper.size(); i++){
			this.points[i] = upper.get(i);
		}

		for(int i = 0; i < lower.size() - 2; i++){
			this.points[i + upper.size()] = lower.get(lower.size() - i - 2);
		}

	}

	//正なら左回り、負なら右回り、0なら共線
	private double crossProduct(Point2D p1, Point2D p2, Point2D p3){
		return (p2.getX() - p1.getX())*(p3.getY() - p1.getY()) - (p2.getY() - p1.getY())*(p3.getX() - p1.getX());
	}

	//頂点数を返す
	int getSize(){
		return points.length;
	}

	//一番下（y座標が同じなら左）にある頂点のインデックスを返す
	//AOJ CGL4A用
	int searchBottom(){
		int index = 0;
		double x = points[0].getX();
		double y = points[0].getY();

		for(int i = 1; i < points.length; i++){
			if(points[i].getY() < y || (points[i].getY() == y && points[i].getX() < x)){
				index = i;
				x = points[i].getX();
				y = points[i].getY();
			}
		}

		return index;
	}

}


Measured memory_bytes: 30188