akhauriyash/Code-Regression huggingface dataset:
def countInRangeUtil(pos, cnt, tight, num): 

	if pos == len(num): 

		if cnt == K: 
			return 1
		return 0

	if dp[pos][cnt][tight] != -1: 
		return dp[pos][cnt][tight] 

	ans = 0

	limit = 9 if tight else num[pos] 

	for dig in range(limit + 1): 
		currCnt = cnt 

		if dig != 0: 
			currCnt += 1

		currTight = tight 

		if dig < num[pos]: 
			currTight = 1

		ans += countInRangeUtil(pos + 1, currCnt, currTight, num) 

	dp[pos][cnt][tight] = ans 
	return dp[pos][cnt][tight] 

def countInRange(x): 
	global dp, K, M 

	num = [] 
	while x: 
		num.append(x % 10) 
		x //= 10

	num.reverse() 

	dp = [[[-1, -1] for i in range(M)] for j in range(M)] 
	return countInRangeUtil(0, 0, 0, num) 

n = int(input())
K = int(input())
dp = []
M = 100
print(countInRange(n) - countInRange(0)) 


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

int N;
int a[100010];
int main() {
	cin>>N;
	
	for(int i=0; i<N; i++){
		cin>>a[i];
	}
	
	int cnt = 0;
	int ind = 0;
	set<int> st;
	while(true){
		if(st.find(ind) != st.end()){
			cout<<-1<<endl;
			return 0;
		}
		st.insert(ind);
		
		ind = a[ind]-1;
		cnt++;
		if(ind == 1){
			cout<<cnt<<endl;
			return 0;
		}
	}
	
	return 0;
}

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

int main(){
                                                                     

    int k, t, i, m;

    
    cin >> k >> t;

    vector<int> a(t);


    for( i = 0 ; i < t ; i = i + 1 ){

         cin >> a.at(i);

         if( i == 0 ) m = a.at(i);

         else if( a.at(i) > m ) m = a.at(i);

         }


    cout << max( m - 1 - ( k - m ) , 0 ) << endl;


    return 0;

    }

Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
#define NIL  -1


bool prime_number(int x) {
	if (x == 1)return false;
	for (int i = 2; i*i <= x; i++) {
		if (x%i == 0)return false;
	}
	return true;
}

long long Pow(long long a, long long n) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}

map<int, int>mp;

int main() {
	cin.tie(0);
	cout.tie(0);

	
	ios::sync_with_stdio(false);
	

	int N;
	cin >> N;
	FOR(i, 0, N - 1) {
		int cur;
		cin >> cur;
		mp[cur]++;
	}
	FOR(i, 1, N + 1) {
		cout << mp[i] << endl;
	}


	
	return 0;
}


Measured memory_bytes: 13024
n,w=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
#[w,v]
#重さに対応するインデックスに価値を保存する
dp=[[0]*(w+1) for i in range(n+1)]
 
for i in range(n):
    for sum_w in range(1,w+1):
        if sum_w-l[i][0]>=0:
            dp[i+1][sum_w]=max(dp[i+1][sum_w],dp[i][sum_w-l[i][0]]+l[i][1])
        #i番目の品を入れる場合
    
        dp[i+1][sum_w]=max(dp[i][sum_w],dp[i+1][sum_w])
        #i番目の品を入れない場合
print(dp[-1][-1])

Measured memory_bytes: 120684
#include<iostream>
#include<cstdio>

int Q,A,B,C,D,K,U,L,R,mdl;

int main(){
	scanf("%d",&Q);
	while (Q--){
		scanf("%d%d%d%d",&A,&B,&C,&D);
		K=(std::max(A,B)-1)/(std::min(A,B)+1)+1;
		L=0,R=A;
		while (L<R){
			mdl=(L+R+1)>>1;
			int Bcnt=std::max(0,(mdl-1)/K);
			if (Bcnt>B||B-Bcnt>static_cast<long long>(A-mdl+1)*K) R=mdl-1;
			else L=mdl;
		}
		L=L+std::max(0,(L-1)/K);
		for (int i=C;i<=D;i++){
			if (i<=L) putchar(i%(K+1)?'A':'B');
			else putchar((A+B-i+1)%(K+1)?'B':'A');
		}
		putchar(10);
	}
}


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

int power(int n, int K){
  int p = 0;
  int num = n;
  while(num<K){
    p++;
    num*=2;
  }

  return p;

}

int main(){
  
  int N,K;
  cin >> N >> K;
  double Ans = 0;

  for(int i = 1; i <= N; i++){
    int x = power(i,K);
    double mom = pow(2,x);
    Ans += 1/(N*mom);
  }
  
  cout << setprecision(12);

  cout << Ans << endl;

}


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

int p[18][100000], v[100000], d[100000];
vector<int>E[100000];
int lca(int u, int v) {
	if (d[u] > d[v])swap(u, v);
	rep(i, 18) {
		if ((d[v] - d[u]) >> i & 1)v = p[i][v];
	}
	if (u == v)return u;
	for (int i = 17; i >= 0; i--) {
		if (p[i][u] != p[i][v]) {
			u = p[i][u]; v = p[i][v];
		}
	}
	return p[0][u];
}
int main() {
	int n; scanf("%d", &n);
	p[0][0] = -1;
	for (int i = 1; i < n; i++) {
		scanf("%d", &p[0][i]); p[0][i]--;
		E[p[0][i]].push_back(i);
	}
	int c = 0;
	queue<int>que;
	memset(d, -1, sizeof(d));
	d[0] = 0; que.push(0);
	while (!que.empty()) {
		int p = que.front(); que.pop();
		v[c++] = p;
		for (int v : E[p]) {
			if (d[v] == -1) {
				d[v] = d[p] + 1; que.push(v);
			}
		}
	}
	for (int i = 1; i < 18; i++) {
		rep(j, n) {
			if (p[i - 1][j] == -1)p[i][j] = -1;
			else p[i][j] = p[i - 1][p[i - 1][j]];
		}
	}
	ll sum = 0;
	rep(i, n - 1) {
		int u = lca(v[i], v[i + 1]);
		sum += d[v[i]] - d[u] + d[v[i + 1]] - d[u];
	}
	printf("%lld\n", sum);
}

Measured memory_bytes: 16548
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

n,k=map(int,input().split())
print(min(n%k,k-(n%k)))

Measured memory_bytes: 65004
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(a - c) <= d){
    cout << "Yes";
  }
  else if(abs(a - b) <= d && abs(b - c) <= d){
    cout << "Yes";
  }
  else cout << "No";
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.lang.Math;
public class Main {
  public static void main (String[]args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int t[] = new int[N+1];
    int xt[] = new int[N+1];
    int yt[] = new int[N+1];
    t[0]=0;
    xt[0]=0;
    yt[0]=0;
    for(int i = 1; i<=N; i++){
      t[i] = sc.nextInt();
      xt[i] = sc.nextInt();
      yt[i] = sc.nextInt();      
    }
    boolean can = true;
    int dt=0;
    int dist=0;
    for(int i = 0; i<=N; i++){
      if(i!=N) {
        dt = t[i+1] - t[i];
        dist = Math.abs(xt[i+1] - xt[i]) + Math.abs(yt[i+1] - yt[i]);
      if(dt < dist) can = false;
      if(dist %2 != dt %2) can = false;
      }
    }
    if(can)   System.out.println("Yes");
    else System.out.println("No");
  }
}


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

int main(){
	ll r,n;
	ll line =0;
	//std::ofstream writing_file;
  	//writing_file.open("vamp_cin.txt", std::ios::out);
	while(cin>>r>>n){
	//	line++;
		if(r==0)break;
		int xl[41],xr[41],h[41];
		int hh[41][41];
		memset(hh,0,sizeof(hh));
		for(int i=0;i<n;i++){
			cin>>xl[i+20]>>xr[i+20]>>h[i+20];
			for(int j=xl[i+20];j<xr[i+20];j++){
				hh[j+20][j+21]=max(h[i+20],hh[j+20][j+21]);
			}
		}
		int minh = 1e5;
		int minx = 0;
		double ans=1e5;
		double res=1e5;
		for(int i=20-r;i<20+r;i++){
			//minh = min(h[i+20]);
/*			if(minh >= hh[i][i+1]){
				if(minh == hh[i][i+1]){
					if(abs(20-i)<abs(minx-20)){
						minx = i;
					}
				}else{
					minx = i;
				}
				minh = hh[i][i+1];
			}*/
		//	cout<<"i i+1:"<<i<<" "<<i+1<<"hh:"<<hh[i][i+1]<<endl;
			if(i<20)res = min(res,hh[i][i+1] + r - sqrt(r*r - abs(i-19)*abs(i-19)));
			else res = min(res,hh[i][i+1] + r - sqrt(r*r - abs(i-20)*abs(i-20)));
		//	cout<<"res:"<<res<<endl;
			ans = min(ans,res);
		}
		for(int i=20-r;i<20+r;i++){
		//	cout<<"i i+1:"<<i<<" "<<i+1<<"hh:"<<hh[i][i+1]<<endl;
		}
//		minh = min(hh[minx-1],min(hh[minx+1],minh));
		/*if(minh>hh[minx-1][minx]&&minh<hh[minx+1][minx+2]){
			//minh = hh[minx-1][minx];
			minx-=1;
		}else if(minh > hh[minx+1][minx+2]&&minh<hh[minx-1][minx]){
			//minh=hh[minx+1][minx+2];
			minx+=1;
		}*/

		if(minx<20)minx+=1;
		//if(minx>20)minx-=1;
		//cout<<"minx"<<minx<<" minh:"<<minh<<endl;
		cout<<fixed;
		cout<<setprecision(4)<<ans<<endl;
		/*writing_file<<"line:"<<line<<endl;
		writing_file<<n<<" "<<r<<endl;
		for(int i=0;i<n;i++){
			writing_file<<xl[i+20]<<" "<<xr[i+20]<<" "<<h[i+20]<<endl;
		}+*/
	//	writing_file<<fixed;
	//	writing_file<<setprecision(4)<<res<<endl;
	}
}



Measured memory_bytes: 3248
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

struct card{
  ll count;
  ll value;

  card(ll a, ll b){
    count = a;
    value = b;
  }
};

int main() {
  ll n, m;
  cin >> n >> m;

  ll tmp, tmp1;
  vector<card> v;
  REP(i, n){
    cin >> tmp;
    v.push_back(card(1, tmp));
  }
  REP(i, m){
    cin >> tmp >> tmp1;
    v.push_back(card(tmp, tmp1));
  }
  sort(v.begin(), v.end(), [](card a, card b){
    return a.value > b.value;
  });

  ll ans = 0;
  for(auto iter : v){
    if (iter.count >= n){
      ans += iter.value * n;
      break;
    }
    n -= iter.count;
    ans += iter.value * iter.count;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6384
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int n, h, ht;
	int cnt = 1;
	cin >> n;
	vector<int> v;
	for (int i = 0; i < n; i++)
	{
		if (i == 0)
		{
			cin >> h;
			v.push_back(h);
			continue;
		}
		cin >> ht;
		v.push_back(ht);
	}
	int j, max = 0;
	for (int i = 1; i < n; i++)
	{
		for (j = 1; j < i; j++)
		{
			if (v[j] > max)max = v[j];
		}
		if (max <= v[i] && v[0] <= v[i])cnt++;
	}
	cout << cnt << endl;
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

bool isKaibun(string s){
    bool kaibun = true;
    int n = s.size();
    REP(i,n/2){
        if(s[i] != s[n-i-1]){
            kaibun = false;
            break;
        }
    }
    return kaibun;
}

int main(){
    string S;
    cin>>S;
    
    int n = S.size();

    if(isKaibun(S) && isKaibun(S.substr(0,(n-1)/2)) && isKaibun(S.substr((n+2)/2))){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lld long long int
#define faster ios_base::sync_with_stdio(false);
#define vi vector< lld >

using namespace std;

int main(){

  int a,b;
  cin>>a>>b;
  if(a > 8 || b> 8){cout<<":("<<endl;}
  else cout<<"Yay!"<<endl;

}

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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

long long GCD(long long a, long long b) {
    return (b % a == 0) ? a : GCD(b % a, a);
}
long long LCM(long long a, long long b) {
    return (a / GCD(a, b)) * b;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    long long A, B, C, D;
    cin >> A >> B >> C >> D;
    A--;

    long long c1 = B - (B/C + B/D - B/LCM(C,D));
    long long c2 = A - (A/C + A/D - A/LCM(C,D));
    
    cout << c1 - c2 << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split(" ");
			int a = Integer.parseInt(chr[0]);
			int b = Integer.parseInt(chr[1]);
			int c = Integer.parseInt(chr[2]);
			System.out.println(c>=a&&c<=b?"Yes":"No");

		}
	}
}


Measured memory_bytes: 25364
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;

	int ans = min(a, k);
	k -= a;
	if (k > 0) { k -= b; }
	if (k > 0) { ans -= k; }
	cout << ans << endl;

	return 0;
}


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

int main() {
    int N, H, W;
    cin >> N;
    cin >> H;
    cin >> W;

    int cnt=0;

    for(int i=0; i<N; i++){
        int a, b;
        cin >> a;
        cin >> b;
        if(a>=H && b>=W) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll a, b;

int main() {
	cin >> a >> b;
	rep(i, 10000) {
		if ((ll)((lldo)i * 0.08) == a && (ll)((lldo)i * 0.1) == b) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};
int main(){
  ll n, k; cin >> n >> k;
  string s; cin >> s;
  Vi x;
  x.pb(0);
  REP(i, n - 1){
    if(s[i + 1] != s[i]){
      x.pb(i + 1);
    }
  }
  REP(i, 4 * n){
    x.pb(n);
  }
  ll ans = 0;
  for(ll i = 0; x[i] < n; i++){
    (s[x[i]] == '0') ? chmax(ans, x[i + 2 * k] - x[i]) : chmax(ans, x[i + 2 * k + 1] - x[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 6640
from collections import deque

n = int(input())

adj = [0]*n # adjacent list
d = [-1]*n # distance from the source vertex
c = ['w']*n # the 'color' of each vertex

# receiving input (the structure of the graph)
for i in range(n):
    tmp = list(map( int, input().split() ) )
    adj[tmp[0]-1] = list(map(lambda x : x - 1, tmp[2:]))

# set the source vertex
s = 0
d[s] = 0
c[s] = 'g'


Q = deque()
Q.append(s)

while Q:
    u = Q.popleft()
    for v in adj[u]:
        if c[v] == 'w':
            c[v] = 'g'
            d[v] = d[u] + 1
            Q.append(v)
    c[u] = 'b'
    

for i in range(n):
    print(f'{i+1} {d[i]}')




Measured memory_bytes: 6012
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int MAX = 1e5+10;
const int MAX1 = 1e5+10;
const int INF = 1e9+10;


long long a[100];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    a[0] = 2;
    a[1] = 1;
    for(int i = 2;i <= n;i++){
        a[i] = a[i-1] + a[i-2];
    }
    cout << a[n];
}


/*
3 4
1 2
2 3
4 1
2 1
3
1 2
2 3
1 2

*/


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

int main (void)
{
	int dice[6];
	char com[100];
	int i,temp;
	
	for(i = 0 ; i < 100 ; i++)
	{
		com[i] = '\0';
	}
	
	scanf("%d %d %d %d %d %d",&dice[0],&dice[1],&dice[2],&dice[3],&dice[4],&dice[5]);
	scanf("%s",com);
	
	for(i = 0 ; com[i] != '\0' ; i++)
	{
		switch(com[i])
		{
			case 'N':
				temp = dice[0];
				dice[0] = dice[1];
				dice[1] = dice[5];
				dice[5] = dice[4];
				dice[4] = temp;
				break;
			case 'S':
				temp = dice[0];
				dice[0] = dice[4];
				dice[4] = dice[5];
				dice[5] = dice[1];
				dice[1] = temp;
				break;
			case 'E':
				temp = dice[0];
				dice[0] = dice[3];
				dice[3] = dice[5];
				dice[5] = dice[2];
				dice[2] = temp;
				break;
			case 'W':
				temp = dice[0];
				dice[0] = dice[2];
				dice[2] = dice[5];
				dice[5] = dice[3];
				dice[3] = temp;
				break;
		}
	}
	
	printf("%d\n",dice[0]);
	return 0;
}


Measured memory_bytes: 2144
def judge(jnum):
    res = 0
    if (jnum & 1) == 0:
        return False
    for k in range(1,jnum+1):
        if jnum % k == 0:
            res += 1
    if res == 8:
        return True
    else:
        return False

N = int(input())
num = 0
for i in range(1,N+1):
    if judge(i):
        num += 1
print(num)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7, INF = 1e9, MAXN = 1e9;
int n, k; vector<vector<int>>sum;

int f(int i, int j) {
	return sum[i][j] - sum[i - k][j] - sum[i][j - k] + sum[i - k][j - k];
}

int main() {
	cin >> n >> k;
	int t = 2 * k, s = 4 * k;
	sum.resize(s + 5, vector<int>(s + 5, 0));
	for (int i = 0, x, y; i < n; i++) {
		char c; cin >> x >> y >> c;
		x %= t, y %= t;
		if (c == 'B')x += k;
		x %= t;
		sum[x][y]++; sum[x + t][y]++; sum[x][y + t]++; sum[x + t][y + t]++;
	}
	for (int i = 1; i < s; i++)for (int j = 1; j < s; j++) {
		sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
	}
	int ans = 0;
	for (int i = 0; i < t; i++)for (int j = 0; j < t; j++) {
		ans = max(ans, f(i + k, j + k) + f(i + t, j + t));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 63104
n=int(input())
s=input()
c=s.count
a=c('R')*c('G')*c('B')
for i in range(n):
  for j in range(i+2,n,2):
    if s[i]!=s[i+j>>1]!=s[j]!=s[i]:
      a-=1
print(a)

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

int main(){
    int n, tmp, max=-10000000, min=10000000;
    long long sum=0;
    cin >> n;
    
    for(int i=0; i<n; i++){
        cin >> tmp;
        if(tmp > max) max = tmp;
        if(tmp < min) min = tmp;
        sum += tmp;
    }
    cout << min << " " << max << " " << sum << endl;

    return 0;
}


Measured memory_bytes: 3120
import java.util.Scanner;

public class Main{
	static long mod = 1000000007;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int ans = 0;
		for(int i = 0; i < S.length(); i++) {
			for(int j = i + 1; j < S.length() + 1; j++) {
				String subS = S.substring(i, j);
				boolean isATGC = true;
				for(int k = 0; k < subS.length(); k++) {
					char c = subS.charAt(k);
					if(c == 'A' || c == 'T' || c == 'G' || c == 'C') continue;
					isATGC = false;
				}
				if(isATGC) ans = Math.max(ans, subS.length());
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
import java.io.*
import java.util.*

var pw = PrintWriter(System.out)
fun solve(S: String){
    val one = S.count{ it == '1' }
    val zero = S.count{ it == '0' }
    pw.println(Math.min(one, zero)*2)
    pw.flush()
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val S = sc.next()
    solve(S)
}



Measured memory_bytes: 33712
import java.util.Scanner;

public class Main {
    public static void main(String...args){
        Scanner scanner=new Scanner(System.in);
        int N =scanner.nextInt();
        int M =scanner.nextInt();

        int[] penaltyCount=new int[N+1];
        int penalty=0;
        int win=0;

        for(int i=0; i<M; i++){
            int p=scanner.nextInt();
            String result=scanner.next();

            if(penaltyCount[p]==-1){
            continue;
            }
            if(result.equals("WA")){
                penaltyCount[p]++;
            }else{
                win++;
                penalty=penalty+penaltyCount[p];
                penaltyCount[p]=-1;
            }
        }
        System.out.println(win+" "+penalty);
    }
}






Measured memory_bytes: 62828
package main

import (
	"bufio"
	"fmt"
	"math"
	"math/rand"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int
var t float64

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	d := intScanner()
	c := intSliceScanner(26)
	s := make([][]int, d)
	for i := 0; i < d; i++ {
		s[i] = intSliceScanner(26)
	}
	best := -mod
	bestSchedule := make([]int, d)
	changeNum := 50
	for x := 0; x < 1; x++ {
		schedule := make([]int, d)
		for i := 0; i < d; i++ {
			schedule[i] = rand.Intn(26)
		}
		score := calcScore(schedule, c, s, d)
		t = float64(score) * 1.
		for y := 0; y < 100000; y++ {
			changes := make([]int, changeNum)
			pres := make([]int, changeNum)
			for i := 0; i < changeNum; i++ {
				changes[i] = rand.Intn(d)
				pres[i] = schedule[changes[i]]
				schedule[changes[i]] = rand.Intn(26)
			}
			nextScore := calcScore(schedule, c, s, d)
			if prob(score, nextScore) >= math.Abs(rand.Float64()) {
				score = nextScore
			} else {
				for i := 0; i < changeNum; i++ {
					schedule[changes[i]] = pres[i]
				}
			}
			if nextScore >= best {
				best = nextScore
				copy(bestSchedule, schedule)
			}
			t *= 0.999
			if (y+1)%400 == 0 && changeNum > 1 {
				changeNum--
			}
		}
	}
	for i := 0; i < d; i++ {
		fmt.Println(bestSchedule[i] + 1)
	}
}
func calcScore(schedule []int, c []int, s [][]int, d int) int {
	score := 0
	last := make([]int, 26)
	for i, v := range schedule {
		score += s[i][v]
		for j, _ := range last {
			last[j]++
		}
		last[v] = 0
		for j, v := range last {
			score -= c[j] * v
		}
	}
	return score
}
func prob(before int, after int) float64 {
	if before <= after {
		return 1.0
	}
	return math.Exp((float64(after) - float64(before)) / float64(t))
}


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(ll k,a,b;cin>>k>>a>>b;){
		if(b-a<2){
			cout<<1+k<<endl;
			continue;
		}

		ll x=a-1;
		if(x>k){
			cout<<1+k<<endl;
			continue;
		}

		if((k-x)%2)
			x++;
		ll y=k-x;
		cout<<1+x+(b-a)*(y/2)<<endl;
	}
}


Measured memory_bytes: 256
# 解説放送の解法

INF = 1001001001

N, M = map(int, input().split())
key = []
for i in range(M):
    a, b = map(int, input().split())
    s = 0
    for c in list(map(int, input().split())):
        c -= 1
        s |= 1 << c
    key.append((s, a))

dp = [INF] * (1 << N)
dp[0] = 0
for s in range(1 << N):
    for i in range(M):
        t = s | key[i][0]
        cost = dp[s] + key[i][1]
        dp[t] = min(dp[t], cost)

ans = dp[-1]
if ans == INF:
    ans = -1

print(ans)





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

int main(){
    char s[99];
    int i, len, count=0;
    scanf("%s", s);
    len = strlen(s);

    for (i = 1; i < len+1; i++)
    {
        if (i%2==1){
            if (s[i-1] == 'R' || s[i-1] == 'U' || s[i-1] == 'D'){
                count = count + 0;
            } else{
                count = count + 1;
            }
        } else if (i%2==0){
            if (s[i-1] == 'L' || s[i-1] == 'U' || s[i-1] == 'D'){
                count = count + 0;
            } else{
                count = count + 1;
            }
        }
    }

    if (count != 0){
        printf("No\n");
    } else{
        printf("Yes\n");
    }

    return 0;
}

Measured memory_bytes: 128
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    A,V =isRaw()
    B,W = isRaw()
    T = iRaw()
    dab = abs(A-B)
    dv = (V-W)
    if dab<=T*dv:
        print("YES")
    else:
        print("NO")



main()


Measured memory_bytes: 67424
#include<bits/stdc++.h>
#define rep(i,a,b) for(ll 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; }
//---------------------------------------------------------------------------------------------------
vector<ll> enumdiv(ll n) {
	vector<ll> S;
	for (ll i = 1; i*i <= n; i++) if (n%i == 0) { S.push_back(i); if (i*i != n) S.push_back(n / i); }
	sort(S.begin(), S.end());
	return S;
}
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/








ll N;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;

	ll ans = 0;
	auto ed = enumdiv(N);
	int n = ed.size();
	rep(i, 0, n - 1) {
		ll L = N / ed[i + 1] + 1;
		ll R = N / ed[i];

		if(L < R and N / (R - 1) == N % (R - 1)) ans += R - 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	    WordGraph root = new WordGraph();
		
		try {
			int lim = Integer.parseInt(in.readLine());
			
			for (int i = 0; i < lim; i++) {
				String[] param = in.readLine().split(" ");
				
				if (param[0].equals("insert")) {
					root.add(param[1]);
				} else {
					if (root.search(param[1]) == true) System.out.println("yes");
					else System.out.println("no");
				}
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

class WordGraph {
	private static final int A = 0;
	private static final int C = 1;
	private static final int G = 2;
	private static final int T = 3;
	
	private boolean set;
	private WordGraph[] wg = null;
	
	public WordGraph() {
		set = false;
		wg = new WordGraph[4];
	}
	
	public void add(String param) {
		if (param.length() == 0) {
			set = true;
			return;
		}
		char c = param.charAt(0);
		
		switch (c) {
		case 'A':
			if (wg[A] == null) wg[A] = new WordGraph();
			wg[A].add(param.substring(1));
			break;
		case 'C':
			if (wg[C] == null) wg[C] = new WordGraph();
			wg[C].add(param.substring(1));
			break;
		case 'G':
			if (wg[G] == null) wg[G] = new WordGraph();
			wg[G].add(param.substring(1));
			break;
		case 'T':
			if (wg[T] == null) wg[T] = new WordGraph();
			wg[T].add(param.substring(1));
			break;
		}
	}
	
	public boolean search(String param) {
		if (param.length() == 0) return set;
		char c = param.charAt(0);
		
		switch (c) {
		case 'A':
			if (wg[A] == null) return false;
			return wg[A].search(param.substring(1));
		case 'C':
			if (wg[C] == null)  return false;
			return wg[C].search(param.substring(1));
		case 'G':
			if (wg[G] == null)  return false;
			return wg[G].search(param.substring(1));
		case 'T':
			if (wg[T] == null)  return false;
			return wg[T].search(param.substring(1));
		}
		
		return false;
	}
}

Measured memory_bytes: 284432
#include <bits/stdc++.h>
#define int long long
using namespace std;
//string sort (s.begin(),s.end());

main() {
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);


       int n;
       cin>>n;

       map<int,int>mp;

       for(int i=0;i<n;i++)
       {
           int x;

          cin>>x;
          mp[x]++;
       }
       int a[n+10];
       int k=0;
       int b[n+10];
       int l=0;
         map<int, int>::iterator itr;
          for (itr = mp.begin(); itr != mp.end(); ++itr) {

             if(itr->second>=2)
             {
                 a[k++]=itr->first;
             }
             if(itr->second>=4)
             {
                 b[l++]=itr->first;
             }
          }
          sort(a,a+k);
          if(l==0)
          {
                if(k<2)
          {
              cout<<0<<endl;
          }
          else
          {
              cout<<a[k-1]*a[k-2]<<endl;
          }

          }
          else
          {
           if(k<2)
          {
              cout<<b[l-1]*b[l-1]<<endl;
          }
          else
          {
              cout<<max((b[l-1]*b[l-1]),(a[k-1]*a[k-2]))<<endl;

          }
          }





}



Measured memory_bytes: 9844
class TreeNode:
  def __init__(self, val):
    self.val = val
    self.left = None
    self.right = None

class Bst:
  def __init__(self):
    self.root = None

  def insert(self, val):
    node = TreeNode(val)
    if self.root is None: 
      self.root = node
      return

    cur_parent = None
    cur_root = self.root

    while cur_root is not None:
      cur_parent = cur_root
      if val > cur_root.val:
        cur_root = cur_root.right
      else:
        cur_root = cur_root.left

    if val > cur_parent.val:
      cur_parent.right = node
    else:
      cur_parent.left = node

  def find(self, val):
    cur_node = self.root

    while cur_node is not None:
      if cur_node.val == val:
        print("yes")
        return
      elif cur_node.val > val:
        cur_node = cur_node.left
      else:
        cur_node = cur_node.right

    print("no")
    return

  def print(self):
    self.inorder = []
    self.preorder = []
    self.inorder_dfs(self.root)
    self.preorder_dfs(self.root)

    print(" " + " ".join([ str(i) for i in self.inorder ]))
    print(" " + " ".join([ str(i) for i in self.preorder ]))

  def inorder_dfs(self, root):
    if not root: return

    self.inorder_dfs(root.left)
    self.inorder.append(root.val)
    self.inorder_dfs(root.right)

  def preorder_dfs(self, root):
    if not root: return

    self.preorder.append(root.val)
    self.preorder_dfs(root.left)
    self.preorder_dfs(root.right)


n = int(input())
bst = Bst()
for _ in range(n):
  ins = list(map(str, input().split()))
  order = ins[0]
  if order == "insert":
    val = int(ins[1])
    bst.insert(val)
  elif order == "find":
    val = int(ins[1])
    bst.find(val)
  elif order == "print":
    bst.print()






Measured memory_bytes: 121628
n, k = map(int, input().split())
A = tuple(map(int, input().split()))
ones = [0] * k.bit_length()
for a in A:
    for i in range(k.bit_length()):
        ones[i] += (a >> i) & 1

x = 0
for idx, one in enumerate(ones[::-1]):
    if n - one > one:
        xx = 2**(len(ones)-1-idx)
        if x + xx > k:
            continue
        else:
            x += xx
ans = 0
for a in A:
    ans += a ^ x
print(ans)

Measured memory_bytes: 20652
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    string s;
    cin >> s;
    cout << 'A' << char('R' + 'B' - s[1]) << "C\n";

    return 0;
}

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

int main(){
  ll n,p=1000000007;
  cin >> n;
  vector<ll> a(n);
  ll i,s,t;
  s=0;
  t=0;
  for(i=0;i<n;i++){
    cin >> a.at(i);
    s += a.at(i);
    s %= p;
    t += a.at(i)*a.at(i);
    t %= p;
  }
  s=s*s%p;
  if(s>=t){
    s -= t;
  }else{
    s=s-t+p;
  }
  if(s%2==0){
    cout << s/2 << endl;
  }else{
    cout << (s+p)/2 << endl;
  }
}

Measured memory_bytes: 4840
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <regex>

using namespace std;

using ull = unsigned long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vull = vector<ull>;
using vpii = vector<pii>;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rFOR(i,a,b) for(int i=(b);i>=(a);i--)
#define SORT(a) sort((a).begin(),(a).end());
#define rSORT(a) sort((a).rbegin(),(a).rend());
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;

//sankou
//vvi = vector<vector<int>>(20, vector<int>(10, 0));

//seiki
//#include <regex>
/*bubun*/
//regex_search("u32", regex("[0-9]"));      // true
/*kanzen*/
//regex_match("u32", regex("(i|u)\\d+"));   // true

int isP(int n) {
    if(n<=1) return 0;
    FOR(i,2,(int)sqrt(n)) {
        if(n%i==0) return 0;
    }
    return 1;
}

int main() {

    int N;
    cin >>N;
    vi a(N);
    FOR(i,0,N-1){
        cin >>a[i];
    }
    SORT(a);
    cout <<(a[N-1]-a[0]);

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 100005
#define INF 2147483647

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n;
ll data[1<<18],datb[1<<18];

void init(int n_){ //nのみ
	n=2;
	while(n<n_)n*=2;
}

//配列、木:0オリジン
//[a,b)にxを加算、節点k[l,r)
void add(int a,int b,ll x,int k,int l,int r){
	if(a<=l && r<=b){
		data[k] += x;
	}else if(l<b && a<r){
		datb[k] += (min(b,r)-max(a,l))*x;
		add(a,b,x,k*2+1,l,(l+r)/2);
		add(a,b,x,k*2+2,(l+r)/2,r);
	}
}

//[a,b)のsum 節点k[l,r)について調べる
ll sum(int a,int b,int k,int l,int r){
	if(b<=l || r<=a)return 0;
	else if(a<=l && r<=b){
		return data[k]*(r-l)+datb[k];
	}else{
		ll res = (ll)(min(b,r)-max(a,l))*data[k];
		res += sum(a,b,k*2+1,l,(l+r)/2);
		res += sum(a,b,k*2+2,(l+r)/2,r);
		return res;
	}
}

int main()
{
	int q;
	scanf("%d %d",&n,&q);
	init(n);
	int com,s,t;
	ll x;
	for(int i=0;i<q;i++){
		scanf("%d",&com);
		if(com==0){
			scanf("%d%d%lld",&s,&t,&x);
			add(s-1,t,x,0,0,n);
		}else{
			scanf("%d%d",&s,&t);
			printf("%lld\n",sum(s-1,t,0,0,n));
		}
	}
	return 0;
}



Measured memory_bytes: 5044
#include <bits/stdc++.h>
using namespace std;
 
#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define W while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007

  int main()
  {
   ll i,n,sum=0;
   cin>>n;
   for(i=1;i<=n;i++)
   {
       if(i%3==0||i%5==0)
       continue;
       else
       sum=sum+i;
   }
   cout<<sum;
  }

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <map>
#include <list>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <random>
#include <queue>
#include <fstream>
#include <iterator> // std::back_inserter
#include <chrono>
#include <string>
#include <stdio.h>
#include <iomanip>
#include <float.h>
#include <cassert>
#include <functional>

using namespace std;

int main(int argc, char *argv[])
{
    string a;
    cin >> a;

    int pa1=0,pa2=0;

    for(int i=0; i<a.size(); i++){
        if(i % 2 == 0){
            if(a[i] == '0'){
                pa1 += 1;
            }else{
                pa2 += 1;
            }
        }else{
            if(a[i] == '0'){
                pa2 += 1;
            }else{
                pa1 += 1;
            }
        }
    }

    int ans=0;
    
    if(pa1 > pa2) ans = pa2;
    else ans = pa1;

    cout << ans;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
#define int long long
//template
int pw(int n,int k){
  if(k<0)return pw(n,k+MOD-1);
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}
int f(int a){//最上位bitがa個目の全てのペア
  return pw(3,a-1);
}
int fm(int l){//x>=lのf(a),ただしaはlの最上位bit
  //cout<<"L:"<<l<<endl;
  string s;int cnt=0,res=0,now=0;
  while(l){
    if(l&1)s+="1";
    else s+="0",cnt++;
    l>>=1;
  }
  res=pw(2,cnt);
  for(char p:s){
    if(p=='0')res+=pw(3,now)*pw(2,--cnt)%MOD;res%=MOD;
    now++;
  }
  return res;
}
int FM(int r){//y<=r
  //cout<<"R:"<<r<<endl;
  string s;int cnt=0,res=0,now=0;
  while(r){
    if(r&1)s+="1",cnt++;
    else s+="0";
    r>>=1;
  }
  res=pw(2,cnt-1);
  for(char p:s){
    if(now==s.size()-1)continue;
    if(p=='1')res+=pw(2,--cnt-1)*pw(3,now)%MOD;res%=MOD;
    now++;
  }
  return res;
}
int fm2(string s){//x<=lのf(a)
  int cnt=0,res=0,now=0;
  for(char p:s)cnt+=(p=='0');
  res=pw(2,cnt);
  reverse(s.begin(),s.end());
  for(char p:s){
    if(p=='1')res+=pw(3,now)*pw(2,cnt+1)%MOD;
    else cnt--;
    now++;res%=MOD;
  }
  return res;
}
int FM2(string t){//y>=r
  int cnt=0,res=0,now=0;
  for(auto p:t)cnt+=(p=='1');
  reverse(t.begin(),t.end());
  res=pw(2,cnt);
  for(char p:t){
    if(p=='0')res+=pw(2,cnt+1)*pw(3,now)%MOD;
    else cnt--;
    now++;res%=MOD;
  }
  return res;
}
int super(int l,int r){
  string s,t;
  while(l){
    if(l&1)s+="1";
    else s+="0";
    l>>=1;
  }
  while(r){
    if(r&1)t+="1";
    else t+="0";
    r>>=1;
  }
  reverse(s.begin(),s.end());reverse(t.begin(),t.end());
  //cout<<s<<" "<<t<<endl;
  int N=s.size(),res=0;
  for(int i=1;i<N;i++){
    if(s[i]=='1'){
      if(t[i]=='1'){
        res+=FM2(t.substr(i+1,N-i-1));//sを0にした
      }
      else{
        res+=FM2(t.substr(i+1,N-i-1));//sを0にしてtはそのまま
        //cout<<res<<endl;
        res+=pw(3,N-i-1);//sを0にしてtを1にした
        //cout<<res<<endl;
        res+=fm2(s.substr(i+1,N-i-1));//sはそのままtを1にした
        res%=MOD;return res;//どれかを必ず行う
      }
    }
    else{
      if(t[i]=='1'){
        ;
      }
      else{
        res+=fm2(s.substr(i+1,N-i-1));//tを1にした
      }
    }
    res%=MOD;//cout<<res<<endl;
  }
  bool f=true;
  for(int i=0;i<N;i++)if(s[i]=='1'&&t[i]=='0')f=false;
  if(f)res++;
  return res;
}
//main
signed main(){
  int L,R,i;cin>>L>>R;if(L==R){cout<<1<<endl;return 0;}
  int ans=0,cnt=1;
  for(i=1;i<R;i*=2,cnt++){
    if(i>L)ans+=f(cnt);
    ans%=MOD;
  }
  if(i==R){
    ans+=fm(L);ans++;ans%=MOD;
    cout<<ans<<endl;
    return 0;
  }
  //cout<<ans<<endl;
  if(ans==0){
    bool f=true;
    for(int k=1;k<=L;k*=2)if(k==L)f=false;
    if(f)ans+=super(L-1,R+1);
  }
  //cout<<"NOW:"<<ans<<endl;
  ans-=f(cnt-1);ans+=MOD;ans%=MOD;
  ans+=fm(L);ans+=FM(R);ans%=MOD;
  cout<<ans<<endl;

}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
 
public class Program
{
    public void Proc() {
        Reader.IsDebug = false;
        // c が母音であるとき、vowel と、そうでないとき consonant と出力せよ。
        string inpt = Reader.ReadLine();
        string boin = "aiueo";
        if(boin.Contains(inpt[0])) {
            Console.WriteLine("vowel");
        } else {
            Console.WriteLine("consonant");
        }

    }


 
 
    public class Reader {
        public static bool IsDebug = true;
        private static System.IO.StringReader SReader;
        private static string InitText = @"




";
        public static string ReadLine() {
            if(IsDebug) {
                if(SReader == null) {
                    SReader = new System.IO.StringReader(InitText.Trim());
                }
                return SReader.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 2904
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())

L = [[-1 for j in range(N)] for i in range(N)]
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split())
        L[i][x-1] = y



ans = 0
for i in range(2**(N)):
    if len(str(bin(i))[2:]) < N:
        K = ["0"] * (N-len(str(bin(i))[2:])) + list(str(bin(i))[2:])
    else:
        K = list(str(bin(i))[2:])
    for j in range(N):
        
        flag = 1
        if K[j] == "0":
            pass
        else:
            for l in range(N):

                if L[j][l] == -1:
                    continue
                elif L[j][l] == 0:
                    if K[l] == "1":
                        flag = 0
                        break
                elif L[j][l] == 1:
                    if K[l] == "0":
                        flag = 0
                        break
        if flag == 0:
            break
        if j == N-1:
            ans = max(ans, K.count("1"))

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main()

{

    int A,B,C,D,t,z;
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    scanf("%d",&D);

    if(A<B){
        t=A;
    }
    else{
        t=B;
    }
    if(C<D){
        z=t+C;

    }
    else{
        z=t+D;
    }
    printf("%d\n",z);
    return 0;
}




Measured memory_bytes: 1696