akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

 
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  
  vector<int> b(9,0);
  
  rep(i,n){
    if(a.at(i) <= 399){
      b.at(0) ++;
    }else if(a.at(i) <= 799){
      b.at(1) ++;
    }else if(a.at(i) <= 1199){
      b.at(2) ++;
    }else if(a.at(i) <= 1599){
      b.at(3) ++;
    }else if(a.at(i) <= 1999){
      b.at(4) ++;
    }else if(a.at(i) <= 2399){
      b.at(5) ++;
    }else if(a.at(i) <= 2799){
      b.at(6) ++;
    }else if(a.at(i) <= 3199){
      b.at(7) ++;
    }else{
      b.at(8) ++;
    }
  }
  int m = 0,M = 0;
  rep(i,9){
    if(i < 8){
      if(b.at(i) > 0){
        m ++;
        M ++;
      }
    }else{
      M += b.at(i);
    }
  }
  
  if(m == 0) cout << 1 << " " << M << endl; 
  else cout << m << " " << M << endl;

  
  return 0;
}



Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s:String = read();
    let t:String = read();
    let s = format!("{}{}", s, s);
    if s.contains(&t) {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 2132
<?php

$n = (int)fgets(STDIN);
$a = array_map('intval', explode(' ',trim(fgets(STDIN))));
sort($a);
$mul = 1;
for ($i=0; $i<$n; $i++) {
  $keta = log10($mul)+log10($a[$i]);
  if ($keta>=18.1) {
    echo -1;
    exit;
  }
  $mul *= $a[$i];
  if ($mul > 1000000000000000000) {
    echo -1;
    exit;
  }
}  
echo $mul;

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

long long gcd(long long m, long long n) {
    return n != 0 ? gcd(n, m % n) : m;
}

long long lcm(long long m, long long n) {
    return m * n / gcd(m, n);
}

int main() {
    int n, m;
    string s, t;
    cin >> n >> m >> s >> t;

    long long l = lcm(n, m);
    map<int, int> x;
    for (int i = 0; i < n; i++) {
        x[i * (l / n) + 1] = i;
    }
    int y;
    for (int i = 0; i < m; i++) {
        y = i * (l / m) + 1;
        if (x.count(y) > 0) {
            if (s[x[y]] != t[i]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << l << endl;
}


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

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}


#define T first
#define M first.first
#define D first.second
#define h second.first
#define m second.second
#define e second.second
#define p second.first


int cal(pair<int,pair<int,int>> a, pair<int,pair<int,int>>  b){
	return b.T - a.T;
}

int change(pair<pair<int,int>,pair<int,int>> in){
	int res = 0, con = 0;
	int days[12] = {31,28,31,30,31,30,  31,31,30,31,30,31};
	
	for(int i = 0; i < in.M; i++){
		con += days[i];
	}
	
	res = (con + in.D - 1) * 24 * 60 + in.h * 60 + in.m;
	
	return res;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	const int MAX = 1000;
	
	while(true){
		int n;
		int ans = 0;
		vector<vector<pair<int,pair<int,int>>>> in(MAX);
		
		cin>>n;
		
		if(!n) break;
		
		
		for(int i = 0; i < n; i++){
			string a, b, c, d;
			
			cin>>a>>b>>c>>d;
			
			in[stoi(d)].push_back({change({{stoi(a.substr(0,2)), stoi(a.substr(3,2))},{stoi(b.substr(0,2)), stoi(b.substr(3,2))}}), {stoi(d) == 0, c == "I"}});
		}

		
		for(int i = 1; i < MAX && i <= 10; i++){
			bool flag = false;
			int temp = 0;
			
			for(int j = 0, k = 0; j < in[0].size() && k < in[i].size(); j += 2){
				for(; k < in[i].size(); k++){
					if(in[i][k].T <= in[0][j].T) {
						flag = in[i][k].e;
					} else break;
				}
				
				for(; k < in[i].size(); k++){
					if(in[i][k].T <= in[0][j+1].T) {
						flag = in[i][k].e;
						if(flag == false) {
							temp += cal(max(in[0][j], in[i][k-1]), in[i][k]);
						}
					} else break;
				}
				
				if(flag){
					temp += cal(max(in[0][j], in[i][k-1]), in[0][j+1]);
				}
			}
			
			ans = max(ans, temp);
		}
		
		
		cout<<ans<<endl;
	}
	
	
	
	return 0;
}


Measured memory_bytes: 3272
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = [S() for _ in range(n)]
    t = 0
    f = False
    for c in a:
        if c == 'A':
            t += 1
        elif t > 0:
            f = True
            t -= 1
        else:
            f = False
            break
    if t == 0 and f:
        return 'YES'


    return 'NO'


print(main())




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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	int s, w; cin >> s >> w;
	if(w>=s){
		cout << "unsafe" << endl;
		return 0;
	}else{
		cout << "safe" << endl;
	}
	return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define PER(a,b,c) for(int a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
using namespace std;
const int MAXN=1e6+5;
int n,m,t;
int v[MAXN];
char s[MAXN];
int main(){
    cin>>s+1;
    if(s[3]==s[4]&&s[5]==s[6])cout<<"Yes";
    else cout<<"No";
}

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

int main() {
	// your code goes here
	long long n, k;
	int num;
	long long ans=0;
	vector<int> a;
	cin >> n >> k;
	for(int i = 0;i<n;i++){
		cin >> num;
		a.push_back(num);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(a[i]>a[j]){
				if(i<j){
					ans+=((k*(k+1))/2)%1000000007;
				}else{
					ans+=(((k-1)*k)/2)%1000000007;
				}
				ans=ans%1000000007;
			}
		}
	}
	cout << ans%1000000007<< endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <random>

#include <fstream>
#include <vector>
#include <algorithm>

#define ll long long int

using namespace std;

bool isPrime(ll n)
{
    if(n == 1)
    {
        return false;
    }
    for(ll i = 2; i*i <= n; i++)
    {
        if(n % i == 0)
        {
            return false;
        }
    }
    
    return true;
}

int main(void)
{
    
    ll d, tmp;
    deque<ll> c, s, res, typ(26, 0);
    
    cin >> d;
    
    for(int i = 0; i < 26; i++)
    {
        cin >> tmp;
        c.push_back(tmp);
    }
    
    for(ll i = 0; i < d; i++)
    {
        for(ll j = 0; j < 26; j++)
        {
            cin >> tmp;
            s.push_back(tmp);
        }
    }
    
    for(ll i = 0; i < d; i++)
    {
        ll key = 0;
        for(ll j = 1; j < 26; j++)
        {
            if(s[26*i+j] > s[26*i+key])
            {
                key = j;
            }
        }
        res.push_back(key+1);
    }
    
    for(ll i = 0; i < d; i++)
    {
        cout << res[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

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

    vector<long long> a(n);
    for(long long i = 0; i < n; i++){
        cin >> a[i];
    }

    sort(a.begin(), a.end());

    long long count_live = 1;

    long long sum = a[0];
    for(long long i = 0; i < n-1; i++){
        if(a[i+1] <= 2*sum){
            sum += a[i+1];
            count_live++;
        }
        else{
            count_live = 1;
            sum += a[i+1];

        }
        //printf("sum %lld count_live %lld\n", sum, count_live);
    }

    cout << count_live << endl;
    return 0;
}

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

int main(){
    char s[200001];
    scanf("%s",s);
    int i,d=0;
    char t[200001],v[200001][2];
    strcpy(t,"");
    for(int i=0;i<200001;i++){
        v[i][0]=s[i];
        v[i][1]='\0';
    }
    char u[200001]="";
    for(i=0;i<200001;i++){
        strcat(u,v[i]);
        if(s[i]=='\0'){
            break;
        }
        else if(strcmp(t,u)!=0){
            d++;
            strcpy(t,u);
            strcpy(u,"");
        }
    }
    printf("%d",d);
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
vector<vector<ll>> graph(1000000);
vector<ll> res(1000000);
vector<bool> seen(1000000);
ll v;
long long mod = 1000000007;
long long power(long long m,long long n){
    long long res = 1;
    if(n > 0){
        res = power(m,n / 2);
        if(n % 2 == 0){
            res = (res * res) % mod;
        }
        else{
            res = (((res * res) % mod) * m) % mod;
        }
    }
    return res;
}
void dfs(int p){
    ll size = 0;
    size = graph[p].size();
    seen[p] = true;
    //res[p] += size - 1;
    /*if(p != 0)*/res[p]++;
    for(int i = 0;i < size;i++){
        ll memo = 0;
        memo = graph[p][i];
        if(seen[memo])continue;
        res[p]++;
        //res[memo] = res[p] + 1;
        dfs(memo);
    }
    res[p]--;
}
int main(){
  ll k;
  cin >> v >> k;
  if(k == 1){
    if(v == 1)cout << k << endl;
    else cout << 0 << endl;
    return 0;
  }
  ll e = 0;
  e = v - 1;
  for(int i = 0;i < e;i++){
    int a,b;
    cin >> a >> b;
    a--,b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  dfs(0);
  //for(int i = 0;i < v;i++)cout << res[i] << endl;
  vector<ll> fac(1000000);
  fac[0] = 1;
  for(int i = 1;i < fac.size();i++)fac[i] = fac[i - 1] * i,fac[i] %= mod;
  ll ans = 0;
  ans = 1;
  ans *= k;
  //cout << ans << endl;
  for(int i = 0;i < v;i++){
    if(res[i] == 0)continue;
    if(i == 0){
      if(k - 1 - res[i] < 0){
        ans *= 0;
        continue;
      }
      ans *= fac[k - 1],ans %= mod;
      ans *= power(fac[k - 1 - res[i]],mod-2);
    }
    else{
      if(k - 2 - res[i] < 0){
        ans *= 0;
        continue;
      }
      ans *= fac[k - 2],ans %= mod;
      ans *= power(fac[k - 2 - res[i]],mod-2);
    }
    ans %= mod;
    //cout << i << " " << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 46080
#include<stdio.h>
int main(){
  int i,idx,k,work,n=3;
  int data[n];
  scanf("%d %d %d",&data[0],&data[1],&data[2]);
  for(i=0;i<n;i++){
    idx=i;
    for(k=i+1;k<n;k++){
      if(data[k]<data[idx]){
        idx=k;
      }
    }
    work=data[i];
    data[i]=data[idx];
    data[idx]=work;
  }
  printf("%d %d %d\n",data[0],data[1],data[2]);
  return 0;
}

Measured memory_bytes: 2692
// By Atul Rathore

#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define f(n) for(int i=0;i<n;i++)
#define p(x) cout<<x<<"\n";
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
 

int main()
{
	fastio;
	int k,a,b;
	cin>>k>>a>>b;
	int dif=b-a+1;
	if(dif>k || (a%k)==0 || (b%k)==0 || (b%k)<(a%k))cout<<"OK";
	else cout<<"NG";
	
	
	
}


Measured memory_bytes: 3604
#include<stdio.h>
#include<stdlib.h>
int main(void){
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(abs(a-c) <= d) printf("Yes\n");
    else if(abs(a-b) <= d && abs(b-c) <= d) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

int main()
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max({ a * c,a * d,b * c,b * d }) << endl;
}


Measured memory_bytes: 3672
#include<iostream>
using namespace std;
int main(){
    int n,r,cards[4][13]={{},{},{},{}};
    char s;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s>>r;
        if(s=='S')cards[0][r-1]=1;
        else if(s=='H')cards[1][r-1]=1;
        else if(s=='C')cards[2][r-1]=1;
        else if(s=='D')cards[3][r-1]=1;
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            if(cards[i][j]==0){
                if(i==0)s='S';
                else if(i==1)s='H';
                else if(i==2)s='C';
                else if(i==3)s='D';
                cout<<s<<' '<<j+1<<endl;
            }
            
        }
    }
    return 0;
}


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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	int cnt = 0;
	char c = s[0];
	for(int i = 1; i < s.length(); ++i){
		if(c != s[i]){
			++cnt;
			c = s[i];
		}
	}
	cout << cnt << '\n';
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	vector<ll> s(N);
	REP(i, N){
		cin >> s[i];
	}
	bool flag = false;
	ll res = 0;
	ll mi = LLONG_MAX/3;
	REP(i, N){
		res += s[i];
		if(s[i]%10!=0){
			flag = true;
			mi = min(s[i], mi);
		}
	}
	if(res%10!=0){
		cout << res << endl;
	}else if(flag){
		cout << res - mi << endl;
	}else{
		cout << 0 << endl;
	}
    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    t = list(map(int,input().split(' ')))
    m = int(input())
    d = []
    for i in range(m):
        d.append(list(map(int,input().split(' '))))
    s = sum(t)
    for i,j in d:
        print(s-t[i-1]+j)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.lang.Math.pow
import java.lang.Math.sqrt

fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    var x = mutableListOf<Double>()
    var y = mutableListOf<Double>()
    for (i in 0 until n){
        var tmp = readLine()!!.split(" ").map { it.toDouble()}
        x.add(tmp[0])
        y.add(tmp[1])
    }
    var sum = 0.0
    for (i in 0 until n-1){
        for (j in i+1 until n){
            sum += sqrt(pow(x[i] - x[j], 2.0) + pow(y[i] - y[j] , 2.0))
        }
    }
    println(sum * 2 / n)
}

Measured memory_bytes: 38304
"use strict";

const main = arg => {
    const inputList = arg.trim().split("\n");
    // 回答を記述
    const S = inputList[0].split("");
    const T = inputList[1].split("");

    let sum = 0;

    for (let i = 0; i < S.length; i++) {
        if (S[i] !== T[i]) {
            sum++;
        }
    }

    console.log(sum)

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 36472
import javax.swing.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] h1 = reader.readLine().split(" ");
        int N = Integer.parseInt(h1[0]);
        int K = Integer.parseInt(h1[1]);
        String[] list = reader.readLine().split(" ");
        int[] a = new int[N];
        for(int h=0;h<N;h++){
            a[h] =Integer.parseInt(list[h]);
        }
        int[] dp =new int[N];
        dp[0] = 0;
        dp[1] = Math.abs(a[1]-a[0]);
        for(int i=2;i<N;i++){
            int min = Integer.MAX_VALUE;
            for(int a1 = Math.max(0,i-K);a1<i;a1++){
                if(dp[a1]+Math.abs(a[i]-a[a1])<min){
                    min = dp[a1]+Math.abs(a[i]-a[a1]);
                }
            }
            dp[i] =min;
        }
        System.out.println(dp[N-1]);
    }
}



Measured memory_bytes: 34020
import java.util.Scanner;

public class Main {

    private void solveA(Scanner sc) {
        int n = sc.nextInt();
        String s = sc.next();
        String t = sc.next();

        int min = 0;
        for (int i = 1; i <= n; i++) {
            String check = t.substring(0, i);
            if (s.endsWith(check)) {
                min = i;
            }
        }
        System.out.println(n * 2 - min);
    }

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


Measured memory_bytes: 9804
#include<vector>
#include<algorithm>
#include<iostream>
#include<cinttypes>
#include<numeric>
#include<iomanip>
using ui = std::uint32_t;
using ul = std::uint64_t;

using dl = long double;



int main(){

	ul nCm[51][51]{};

	for( ui i{};i<51;++i )
		for( ui j{}; j <= i; ++j )
		{
			if( j == 0 || i == j )
				nCm[i][j] = 1;
			else
				nCm[i][j] = nCm[i - 1][j - 1] + nCm[i - 1][j];
		}
	/*
	for( ui i{};i<51;++i )
	{
		for( ui j{}; j <= i; ++j )
			std::cout << nCm[i][j] << " ";
		
		std::cout << "\n";
	}*/


	ui n, a, b;
	std::cin >> n >> a >> b;

	std::vector<ul> vs( n );
	for( auto&e : vs )
		std::cin >> e;


	std::sort( std::begin( vs ), std::end( vs ), std::greater<>{} );


	//	std::cout <<"c: "<< contains << "\n";
	const ul least_packed = std::accumulate( std::begin( vs ), std::begin( vs ) + a, ul{} );

	auto mean = dl{ 1 }* least_packed / a;

	const ui max_c_ = std::count( std::begin( vs ), std::end( vs ), vs[0] );
	const ui min_c_ = std::count( std::begin( vs ), std::end( vs ), vs[a - 1] );
	const ui req_min_c = std::count( std::begin( vs ), std::begin( vs ) + a, vs[a - 1] );
	//const auto x = a <= max_c_ ? max_c_ : min_c_;
	

	
	ul ans{};
	if( a <= max_c_ )
		for( ui i{ a }; i <= std::min( b, max_c_ ); ++i )
		{
			const auto v = nCm[max_c_][i];
			//std::cout << "v:" << v << "\n";
			ans += v;
		}
	else
		ans = nCm[min_c_][req_min_c];

	std::cout << std::setprecision( 16 ) << std::fixed;
	std::cout << mean << "\n";
	std::cout << ans << "\n";

 	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n;
	cin >> n;
	int max = -INF;
	int ans = 0;

	REPR(i, n){
		int current = i;
		int count = 0;
		while (1){
			if (current % 2 == 0 and current != 0){
				current /= 2;
				count++;
			}
			else break;
		}

		if (max < count){
			max = count;
			ans = i;
		}

	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

// 1 - indexed
template <typename T>
struct BIT
{
   vector<T> bit;

   BIT(int sz) : bit(sz + 1, 0) {}

   // sum of [1, k]
   T sum(int k)
   {
      T res = 0;
      for (int x = k; x > 0; x -= x & -x)
         res += bit[x];
      return res;
   }

   void add(int k, T w)
   {
      for (int x = k; x < bit.size(); x += x & -x)
         bit[x] += w;
   }

   // sum of [x, y)
   T getSum(int x, int y)
   {
      return sum(y - 1) - sum(x - 1);
   }

   // find an index i s.t. a[1] + a[2] + ⋯ + a[x] ≧ w
   T lower_bound(T w)
   {
      if (w <= 0)
         return 0;

      T x = 0;
      int p = 1, N = bit.size();

      while (2 * p <= N)
         p *= 2;

      for (T k = p; k > 0; k /= 2)
      {
         if (x + k <= N && bit[x + k] < w)
         {
            w -= bit[x + k];
            x += k;
         }
      }

      return x + 1;
   }
};

int main()
{

   int N, Q;
   cin >> N >> Q;
   vector<int> c(N + 1);
   for (int i = 0; i < N; i++)
   {
      cin >> c[i + 1];
   }

   vector<vector<pair<int, int>>> queries(N + 1, vector<pair<int, int>>());

   for (int i = 0; i < Q; i++)
   {
      int l, r;
      cin >> l >> r;
      queries[l].emplace_back(r, i);
   }

   for (int i = 1; i <= N; i++)
   {
      sort(queries[i].begin(), queries[i].end());
   }

   vector<priority_queue<int, vector<int>, greater<int>>> pos(N + 1);

   for (int i = 1; i <= N; i++)
   {
      pos[c[i]].push(i);
   }

   BIT<int> bit(N + 1);

   for (int i = 1; i <= N; i++)
   {
      if (pos[i].empty())
         continue;
      bit.add(pos[i].top(), 1);
      pos[i].pop();
   }

   vector<int> ans(Q);

   for (int l = 1; l <= N; l++)
   {
      for (auto q : queries[l])
      { // 左端がlのクエリ
         int R = q.first + 1, ind = q.second;
         ans[ind] = bit.getSum(l, R);
      }

      bit.add(l, -1);
      if (pos[c[l]].empty())
         continue;

      int nxt = pos[c[l]].top();
      pos[c[l]].pop();
      bit.add(nxt, 1);
   }

   for (int i = 0; i < Q; i++)
   {
      cout << ans[i] << "\n";
   }
}

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

int main() {
	int n;
	ll ans = 0;
	cin >> n;
	std::map<string, ll> map;
	rep(i, n){
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		map[s]++;
	}
	for (auto p : map){
		auto value = p.second;
		if (value > 1) ans += value*(value-1)/2;
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    int max_num = 0;
    rep(i, n) {
        if ( s[i] == 'I' ) {
            ++cnt;
        }
        else {
            --cnt;
        }
        max_num = max(max_num, cnt);
    }
    cout << max_num << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 2e5 + 5;



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

    return 0;
}


Measured memory_bytes: 3692
#include<stdio.h>
int main(void)
{
	int n,a,x;
	scanf("%d %d %d",&n,&a,&x);
	n=x-n;
	if(n<=0) printf("0\n");
	else if(n<=a) printf("%d\n",n);
	else printf("NA\n");
	return 0;
}


Measured memory_bytes: 2740
import java.util.Scanner
import kotlin.system.exitProcess

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val n = scn.nextInt()
	var la = IntArray(n){scn.nextInt()}
	val lb = IntArray(n){scn.nextInt()}
	val ordB = lb.indices.sortedBy { lb[it] }
	la = IntArray(n){la[ordB[it]]}
	lb.sort()
	val aSrt = la.sorted().toIntArray()
	if (ordB.indices.any{aSrt[it]>lb[it]}) ans(false)
	val ordA = la.indices.sortedBy { la[it] }
	var k = 0
	var cnt = 0
	while(true){
		k = ordA[k]
		cnt++
		if (k==0) break
	}
	if (cnt!=n) ans(true)
	ans((0 until n-1).any{lb[it]>=aSrt[it+1]})
}

fun ans(ans: Boolean){
	println(if (ans) "Yes" else "No")
	exitProcess(0)
}

Measured memory_bytes: 117016
#include <unistd.h>
#include <vector>

#define N 1000000
const int mod = 998244353;

int n;
int A[N+1];

char ibuf[1600100];
char *ibufe = ibuf-1;

void readall(){
  int k, t = 0;
  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;
}

int read_uint(){
  int x=0;
  while(*(++ibufe) <'0');
  do {
    x *= 10;
    x += *ibufe-'0';
  } while(*(++ibufe) >='0');
  return x;
}

char buf[20];
char *bufe = buf;

void write_uintll(long long int x){
  int i;
  static char tmp[14];
  if(x==0){
    *bufe++ = '0';
    *bufe++ = '\n';
    return;
  }

  for(i=0; x; i++){
    tmp[i] = '0' + x % 10;
    x /= 10;
  }
  for(i--; i >= 0; i--){
    *bufe++ = tmp[i];
  }
  *bufe++ = '\n';
}

void writeall(){
  int k, t = 0;
  while((k=write(STDOUT_FILENO, buf+t, bufe-buf-t))>0) t += k;
}


/*
\sum_{i<j} lcm(Ai,Aj)
\sum_{i<j} Ai Aj / gcd(Ai,Aj)
\sum_{d} 1/d \sum_{i<j: gcd(Ai, Aj) = d} Ai Aj

f(d) = \sum_{i,j: gcd(Ai, Aj) = d} Ai Aj
F(d) = \sum_{i,j: d | gcd(Ai, Aj)} Ai Aj
F(d) = \sum_{i,j: d | Ai, d | Aj)} Ai Aj
F(d) = (\sum_{i: d | Ai} Ai)^2
\sum_{d} 1/d \sum_{n: d|n} m(n/d) F(n)
\sum_{n} F(n) \sum_{d: d|n} 1/d m(n/d)
\sum_{n} F(n)/n \sum_{d: d|n} n/d m(n/d)
\sum_{n} F(n)/n \sum_{d: d|n} d m(d)
\sum_{d: d|n} d m(d) = \sum_{d: p|d|n} d m(d) + \sum_{d: d|n/p^k} d m(d)
= \sum_{d: d|n/p^k} pd m(pd) + \sum_{d: d|n/p^k} d m(d)
= \sum_{d: d|n/p^k} d m(d) - pd m(d)
=(1-p0)(1-p1)...(1-pm)
*/

int inv[N+1];
int phi[N+1];

int main(){
  int r, s;

  inv[1] = 1;
  for(int i=2;i<=N;i++) inv[i] = (long long) (mod - mod/i) * inv[mod%i] % mod;
  phi[1] = 1;
  for(int i=2;i<=N;i++){
    if(!phi[i]){
      phi[i] = mod+1-i;
      for(int j=2*i;j<=N;j+=i){
        if(phi[j]) phi[j] = (long long) phi[j] * (mod+1-i) % mod;
        else phi[j] = mod+1-i;
      }
    }
    phi[i] = (long long) phi[i] * inv[i] % mod;
  }
  
  readall();
  n = read_uint();
  s = 0;
  for(int i=0;i<n;i++){
    int x = read_uint();
    A[x]++;
    s += x;
    if(s >= mod) s -= mod;
  }

  for(int i=1;i<=N;i++){
    A[i] = (long long) i * A[i] % mod;
  }
  for(int i=1;i<=N;i++){
    for(int j=2*i;j<=N;j+=i){
      A[i] += A[j];
      if(A[i] >= mod) A[i] -= mod;
    }
  }

  r = mod-s;
  for(int i=1;i<=N;i++){
    r = (r + (long long) A[i] * A[i] % mod * phi[i]) % mod;
  }

  write_uintll(r&1?(r+mod)/2:r/2);
  writeall();

  return 0;
}


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

public class Main {
	
	public static void main(String[] agrs) throws IOException{
		
		InputStreamReader inputStreamReader = new InputStreamReader(System.in);
		BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
		
		String input = bufferedReader.readLine();
		char[] inputArray = input.toCharArray();
		int lengthOfInput = input.length();
				
		char first = inputArray[0];
		boolean condition1 = (first == 'A');
		
		int numberOfC = 0;
		int cAt = 0;
		boolean condition2 = false;
		
		for (int a = 2; a <= lengthOfInput - 2; a++) {
			if(inputArray[a] == 'C') {
				
				if(numberOfC == 0) {
					condition2 = true;
					cAt = a;
					
					numberOfC++;
				}else {
					condition2 = false;
					break;
				}
			}
		}
		
		boolean condition3 = false;
		
		for(int a = 0; a < lengthOfInput; a++) {
			if(a != 0 && a != cAt) {
				condition3 = Character.isLowerCase(inputArray[a]);
				if(!condition3) {
					break;
				}
			}
		}
		
		if(condition1 && condition2 && condition3) {
			print("AC");
		}else {
			print("WA");
		}
	}
	
	public static void print(String string) {
		System.out.println(string);
	}
	
}


Measured memory_bytes: 22612
import bisect

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

L.sort()
cnt = 0

for i in range(N):
    for j in range(i + 1, N):
        idx = bisect.bisect_left(L, L[i] + L[j])
        cnt += max(0, idx - (j + 1))


print(cnt)

Measured memory_bytes: 3188
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
int main() {
	int n, i, f=0, j;
	int A[10001] = {};
	fscanf(stdin, "%d", &n);
	while (n--) fscanf(stdin, "%d", &i), A[i]++;

	for (i = 0; i < 10001; i++) {
		for (j = 0; j < A[i]; j++) {
			if (f) printf(" ");
			fprintf(stdout, "%d", i),f=1;
		}
	}
	puts("");
	return 0;
}

Measured memory_bytes: 668
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
ll N;
  cin>>N;
  string S;
  cin>>S;
  ll ans=0;
  for(ll i=0;i<N-1;i++) {
    set<char> s;
for(ll j=0;j<=i;j++) {
  s.insert(S[j]);
}
    
    ll count=0;
    for(ll h=i+1;h<N;h++) {
      if(s.count(S[h])) {
        s.erase(S[h]);
        count++;
      }
         }
         
         ans=max(ans,count);
         }
         
         cout<<ans<<endl;
         }
         

      
      


  
  
  
  


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a) begin(a),end(a)
#define FOR(x,val,to) for(int x=(val);x<int((to));++x)
#define FORE(x,val,to) for(auto x=(val);x<=(to);++x)
#define FORR(x,arr) for(auto &x: arr)
#define FORS(x,plus,arr) for(auto x = begin(arr)+(plus); x != end(arr); ++x)
#define FORREV(x,plus,arr) for(auto x = (arr).rbegin()+(plus); x !=(arr).rend(); ++x)
#define REE(s_) {cout<<s_<<'\n';exit(0);}
#define GET(arr) for(auto &i: (arr)) sc(i)
#define whatis(x) cerr << #x << " is " << (x) << endl;
#define e1 first
#define e2 second
#define INF 0x7f7f7f7f
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<std::string> vs;
typedef int64_t ll;
typedef uint64_t ull;
#define umap unordered_map
#define uset unordered_set
using namespace std;
using namespace __gnu_pbds;

#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
template<class L, class R> ostream& operator<<(ostream &os, map<L, R> P) { for(auto const &vv: P)os<<"("<<vv.first<<","<<vv.second<<")"; return os; }
template<class T> ostream& operator<<(ostream &os, set<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) { os<<"("<<P.first<<","<<P.second<<")"; return os; }
inline int fstoi(const string &str){auto it=str.begin();bool neg=0;int num=0;if(*it=='-')neg=1;else num=*it-'0';++it;while(it<str.end()) num=num*10+(*it++-'0');if(neg)num*=-1;return num;}
inline void getch(char &x){while(x = getchar_unlocked(), x < 33){;}}
inline void getstr(string &str){str.clear(); char cur;while(cur=getchar_unlocked(),cur<33){;}while(cur>32){str+=cur;cur=getchar_unlocked();}}
template<typename T> inline bool sc(T &num){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){if(c == EOF) return false;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; return true;}template<typename T, typename ...Args> inline void sc(T &num, Args &...args){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; sc(args...); }
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //s.find_by_order(), s.order_of_key() <- works like lower_bound
template<typename T> using ordered_map = tree<T, int, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 1000001

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll n,k;
    sc(n,k);
    if(k == 0){
        REE(n*n)
    }
    ll res = 0;
    FORE(b,k+1,n){
        /* whatis(res) */
        ll ilcyk = n/b;
        ll whcyk = b-k;
        res += ilcyk*whcyk;
        if(n%b){
            res += max(0l,n%b-k+1);
        }
    }
    cout << res << '\n';
}



Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input()) / 50

count = 0

a = 0
while a <= A:
  b = 0
  while b <= B:
    r = X - 10*a - 2*b
    if r >= 0 and r <= C:
      count += 1
    b += 1
  a += 1

print(count)

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

bool is_SPRP(uint32_t n, uint32_t a) {
  uint32_t d = n - 1, s = 0;
  while ((d & 1) == 0) {
    ++s;
    d >>= 1;
  }
  uint64_t cur = 1, pw = d;
  while (pw) {
    if (pw & 1) {
      cur = (cur * a) % n;
    }
    a = ((uint64_t)a * a) % n;
    pw >>= 1;
  }
  if (cur == 1) {
    return true;
  }
  for (uint32_t r = 0; r < s; r++) {
    if (cur == n - 1) {
      return true;
    }
    cur = (cur * cur) % n;
  }
  return false;
}

bool is_prime(uint32_t x) {
  if (x <= 1) return false;
  if (x < 1ULL << 32) {
    uint32_t bases[] = {2, 7, 61};
    for (uint32_t i = 0; i < sizeof(bases) / sizeof(bases[0]); ++i) {
      if (x != bases[i] && !is_SPRP(x, bases[i])) {
        return false;
      }
    }
    return true;
  }
}

int p[1000000];

int main() {
  int n;
  for (int i = 0; i < 1000000; ++i) {
    p[i] = is_prime(i);
  }
  for (int i = 1; i < 1000000; ++i) {
    p[i] += p[i - 1];
  }
  while (cin >> n) {
    cout << p[n] << endl;
  }
}

Measured memory_bytes: 6908
import bisect

N, K = map(int, input().split())
A = list(map(int, input().split()))

d = {}
for i, a in enumerate(A):
    if a in d:
        d[a].append(i)
    else:
        d[a] = [i]

loop_cnt = 0
sp = []
p = 0
fp = 1
top = A[0]
while True:
    loop_cnt += 1
    while fp < N:
        np = bisect.bisect_left(d[top], fp)
        if np < len(d[top]):
            p = d[top][np] + 1
            fp = p+1
            if p < N:
                top = A[p]
        else:
            break
    if p >= N:
        break
    top = A[p]
    sp.append(p)
    fp = 0

k = K % loop_cnt - 1
if k == -1:
    exit()
p = sp[k]
s = []
while p < N:
    top = A[p]
    while True:
        np = bisect.bisect_left(d[top], p+1)
        if np < len(d[top]):
            p = d[top][np] + 1
            if p < N:
                top = A[p]
        else:
            break
    if p < N:
        s.append(top)
        p += 1

print(' '.join(map(str, s)))


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

int n; ll A[55],sum;
inline bool check(ll x)
{
	if(x<0) return 0;
	ll al=0;
	for(int i=1;i<=n;i++)
	{
		ll sp=A[i]+x-n;
		if(sp<0) al+=0;
		else 
		{
			if(x-sp/(n+1)-1>=al) al+=sp/(n+1)+1;
			else return 0;
		}
	}
	return 1;
}
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&A[i]);
	for(int i=1;i<=n;i++) sum+=A[i];
	for(int i=n*n-n;i>=0;i--)
	{
		if(check(sum-1ll*i))
		{
			printf("%lld\n",sum-1ll*i);
			return 0;
		}
	}
	assert(0);
	return 0;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
ans = 0
ans_list = []

for i in range(n-1): #range(0)はエラーではない
    if h[i] >= h[i+1]:
        ans += 1
    else:
        ans_list.append(ans)
        ans = 0
ans_list.append(ans)
print(max(ans_list))

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

int main(){
    int h,w;
    cin>>h>>w;

    vector<vector<char>> a(h+2,vector<char>(w+2));
    for(int i=1; i<h+1; i++){
        for(int j=1; j<w+1; j++){
            cin>>a[i][j];
        }
    }

    for(int j=0; j<w+2; j++){
        a[0][j]='#';
        a[h+1][j]='#';
    }

    for(int i=1; i<h+1; i++){
        a[i][0]='#';
        a[i][w+1]='#';
    }

    for(int i=0; i<h+2; i++){
        for(int j=0; j<w+2; j++){
            cout<<a[i][j];
            if(j==w+1){
                cout<<endl;
            }   
        }
    }
}

Measured memory_bytes: 256
a=1
while a==1:
    h,w=map(int,input().split())
    if h==0 and w==0:
        break
    i=1
    while i<h+1:
        if i==1 or i==h:
            print('#'*w)
        else:
            print('#'+'.'*(w-2)+'#')
        i+=1
    print('\n', end="")


Measured memory_bytes: 5616
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    ll k; cin >> k;
    vector <ll> ps;
    REP(i, n){
        ll p; cin >> p;
        ps.push_back(p);
    }
    sort(ps.begin(), ps.end());
    ll ans = 0;
    REP(i, k){
        ans += ps[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	// int T;
	// cin>>T;
	// // cin.ignore(); must be there when using getline(cin, s)
	// while(T--)
	// {
		int n, ans;
		cin>>n;
		int div = n/1000;
		if(n%1000 == 0){
			ans = 0;
		}
		else{
			ans = n%1000;
			ans = 1000-ans;
		}
		cout<<ans<<endl;

	// }
	return 0;
}


Measured memory_bytes: 3644
"use strict";

const Main = args => {
  const input = args.trim().split(" ").map(e => e - 0);
  const N = input[0];
  const K = input[1];

  console.log(K * Math.pow(K - 1, N - 1));
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

vector<vector<int> > DP(1000,vector<int>(1000));

void init(int n,int m){
    rep(i,n){
        rep(j,m){DP[i][j]=-1;}
    }
}

int LCS(char a[],char b[],int n,int m){
    if(n<0||m<0)return 0;
    if(DP[n][m]!=-1)return DP[n][m];
    if(a[n]==b[m])return DP[n][m]=1+LCS(a,b,n-1,m-1);
    return DP[n][m]=max(LCS(a,b,n-1,m),LCS(a,b,n,m-1));
}

int main(){
    int q;cin>>q;
    char s[1001],t[1001];
    rep(i,q){
        cin>>s>>t;
        int n=strlen(s),m=strlen(t);
        init(n,m);
        int ans=LCS(s,t,n-1,m-1);
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 6644
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) throws IOException {
        List<String> lines = readLines();
        List<Integer> Ls = Arrays.stream(lines.get(0).split(" "))
                .map((l) -> Integer.parseInt(l))
                .collect(Collectors.toList());

        int W = Ls.get(0);
        int H = Ls.get(1);
        int x = Ls.get(2);
        int y = Ls.get(3);

        System.out.println(String.format("%f %d", ((double)W*H)/2.0, (2*x == W && 2*y == H) ? 1 : 0));
    }

    public static List<String> readLines() throws IOException {
        InputStream in = System.in;
        InputStreamReader reader = new InputStreamReader(in, "utf-8");
        BufferedReader br = new BufferedReader(reader);

        List<String> retList = new ArrayList<>();
        String line = br.readLine();
        while (line != null && !line.isEmpty()) {
            retList.add(line);
            line = br.readLine();
        }

        reader.close();
        br.close();
        return retList;
    }
}


Measured memory_bytes: 26708
n,y = map(int, input().strip().split())
a_x, a_y, a_z = -1, -1, -1
for xi in range(n + 1):
  for yi in range(n - xi + 1):
    zi = n - xi - yi
    if 10000*xi + 5000*yi + 1000*zi == y:
      a_x = xi
      a_y = yi
      a_z = zi
      break
 
print(a_x, a_y, a_z)

Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int main(void){
    long long K,X,i;
    cin>>K>>X;
    for(i=X-K+1;i<X+K;i++){
        cout<<i;
        if(i<X+K-1){
            cout<<" ";
        }
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
typedef long long ll;
using namespace std;

int main() {
    int A, B, K;
    cin >> A >> B >> K;

    for (int i = 0; i < K; ++i) {
        if (i % 2 == 0) {
            if (A % 2 == 1) {
                B += (A - 1) / 2;
                A = (A - 1) /2;
            } else {
                B += A / 2;
                A = A / 2;
            }
        } else {
            if (B % 2 == 1) {
                A += (B - 1) / 2;
                B = (B - 1) / 2;
            } else {
                A += B / 2;
                B = B / 2;
            }
        }
    }

    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/abc127/tasks/abc127_b

import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int D = sc.nextInt();
        int x = sc.nextInt();
        sc.close();
        for (int i=0;i<10;i++){
            x = r*x-D;
            System.out.println(x);
        }
    }
}

Measured memory_bytes: 22740
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n = ii()
A = iil()
ans = [0]*n
for i,item in enumerate(A):
    ans[item-1] = i+1

for i in ans:
    print(i,end=' ')

Measured memory_bytes: 14000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;

int main() {
    int n; cin >> n;
    vector<int> a(n + 2);
    a[0] = 0; a[n + 1] = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    int all = 0;
    for (int i = 0; i <= n; i++) {
        all += abs(a[i] - a[i + 1]);
    }
    for (int i = 1; i <= n; i++) {
        int sum = all - (abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1])) + abs(a[i - 1] - a[i + 1]);
        printf("%d\n", sum);
    }
    return 0;
}

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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

signed main(){
	string str;
	
	while(true){
		cin >> str;
		if(str == "0")break;
		int a = 0, b = 0;
		for(int i = 1; i < str.size(); i++){
			if(str[i] == 'A') a++;
			else b++;
		}
		if(a < b)b++;
		else a++;
		cout << a << " " << b << endl;
	}
	return 0;
}




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

int main() {
    int N,Q,x;
    cin >> N;
    map<int,int> A;

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

    cin >> Q;
    for(int i = 0; i < Q;i++){
        int a,b;
        cin >> a >> b;
        sum = sum + (b-a) * A[a];
        A[b] += A[a];
        A[a] = 0;
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 7468
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i <= n; i++)
#define int long long
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<29;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}

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

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

    bool isSame(int x, int y) {
        return root(x) == root(y);
    }

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

signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> A(m), B(m);
    for (int i = 0; i < m; i++) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }
    reverse(all(A));
    reverse(all(B));

    UnionFind uf(n);
    vector<int> N(m, 0);

    for (int i = 0; i < m; i++) {
        int a = A[i], b = B[i];
        if(uf.isSame(a, b)) continue;
        N[i] = uf.size(a) * uf.size(b);
        uf.unite(a, b);
    }

    reverse(all(N));
    int ans = 0;

    for (int i = 0; i < m; i++) {
        ans += N[i];
        cout << ans << endl;
    }
    return 0;
}

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

  int h,w,i,j;
  char a[101][101];

  scanf("%d %d",&h,&w);

  for(i	= 0; i < h; i++) scanf("%s",a[i]);

  for(i	= 0; i < w+2; i++) printf("#");
  printf("\n");

  for(i	= 0; i < h; i++) printf("#%s#\n",a[i]);

  for(i = 0; i < w+2; i++) printf("#");
  printf("\n");

  return 0;

}





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


int main(){
  int k,x;
  cin >>k >>x;
  int sum =k*500;
  if(sum>= x)cout <<"Yes"<<endl;
  else cout <<"No"<<endl;

}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] sunuke = new int[n];
		Arrays.fill(sunuke, 1);
		
		for (int i = 0; i < k; i++) {
			int d = sc.nextInt();
			for (int j = 0; j < d; j++) {
				int a = sc.nextInt();
				a--;
				sunuke[a] = 0;
			}
		}
		
		int ans = 0;
		for (int i : sunuke)
			ans += i;
		System.out.println(ans);
	}
}


Measured memory_bytes: 37628
def main():
    n = int(input())
    for i in range(1, n + 1):
        if i % 3 == 0:
            print(" ", end="")
            print(i, end="")
        elif "3" in str(i):
            print(" ", end="")
            print(i, end="")
    print()


if __name__ == '__main__':
    main()



Measured memory_bytes: 6248