akhauriyash/Code-Regression huggingface dataset:
import java.util.*

fun simple(a: Int, b: Int, x: List<Long>, L: Long): Int {
    var res = 0
    var v = a
    while (v < b) {
        v = x.indexOfLast { it <= x[v] + L }
        res++
    }

    return res
}

fun main(args: Array<String>) {
    val M = readLine()!!.toInt()
    var N = 1
    while (N <= M) N *= 2
    val x = readLine()!!.split(" ").map{it.toLong()}
    val L = readLine()!!.toLong()

    // solve
    val Q = readLine()!!.toInt()
    val a = Array(Q) { 0 }
    val b = Array(Q) { 0 }
    for (i in a.indices) {
        val (A, B) = readLine()!!.split(" ").map { it.toInt() }
        a[i] = Math.min(A, B) - 1
        b[i] = Math.max(A, B) - 1
    }


    // check
//    val A = ArrayList<Int>()
//    val B = ArrayList<Int>()
//    for (i in 0 until M) for (j in i + 1 until M) {
//        A.add(i)
//        B.add(j)
//    }
//    val a = A.toTypedArray()
//    val b = B.toTypedArray()

    solve(a, b, x, N, L)
}

private fun solve(
    a: Array<Int>,
    b: Array<Int>,
    x: List<Long>,
    N: Int,
    L: Long
) {
    val mp = TreeMap<Long, Int>()
    x.forEachIndexed { index, l -> mp[l] = index }

    val doubling = Array(N) { Array(20) { x.size - 1 } }

    for (i in x.indices) {
        var value = mp.floorEntry(x[i] + L).value
        if (value == i) {
            value = x.size - 1
        }
        doubling[i][0] = value
    }

    for (k in 1 until 20) {
        for (i in doubling.indices) {
            doubling[i][k] = doubling[doubling[i][k - 1]][k - 1]
        }
    }

    fun findNext(s: Int, t: Int): Pair<Int, Int> {
        var k = doubling[s].indexOfFirst { it >= t }
        if (k > 0) k--

        return Pair(doubling[s][k], 1 shl k)
    }

    for (l in a.indices) {
        var res = 0

        var v = a[l]
        while (v < b[l]) {
            val p = findNext(v, b[l])
            v = p.first
            res += p.second
        }

        // solve
        println(res)

        // check
//        val res2 = simple(a[l], b[l], x, L)
//        if (res != res2) {
//            println("${a[l]} ${b[l]}, $res $res2")
//        }
    }
}


Measured memory_bytes: 158004
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long t = sc.nextLong();
    long[] a = new long[n];
    long cnt = 0;
    long min = 1000000001;
    long max = 0;
    for(int i=0;i<n;i++){
      a[i]=sc.nextLong();
      if(a[i]-min>max){
        max = a[i]-min;
        cnt=1;
      }else if(a[i]-min==max){
        cnt++;
      }
      min = Math.min(a[i],min);
    }
    System.out.println(cnt);
  }
}

Measured memory_bytes: 52776
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>
#include <unordered_set>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n; cin >> n;
    string s; cin >> s;

    ll ans = 0;
    unordered_set<ll> d1, d2, d3;
    REP(i, n) {
        ll c = s[i] - '0';
        for (ll j : d2) {
            d3.insert(j * 10 + c);
        }
        for (ll j : d1) {
            d2.insert(j * 10 + c);
        }
        d1.insert(c);
    }
    cout << d3.size() << endl;
    
}

Measured memory_bytes: 384
function main(input) {
  const nums = input
    .trim()
    .split(/\s/)
    .map(str => Number(str));

  console.log(
    nums[0] !== 0 && nums[0] === nums[1] && nums[0] === nums[2] ? "Yes" : "No"
  );
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    List<int>[] G;
    int[] color;
    int[] us;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int M = int.Parse(str[1]);
        G = new List<int>[N];
        for(int i=0;i<N;i++){
            G[i] = new List<int>();
        }
        for(int i=0;i<M;i++){
            str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]) - 1;
            int b = int.Parse(str[1]) - 1;
            G[a].Add(b);
            G[b].Add(a);
        }
        int Q = int.Parse(Console.ReadLine());
        int[] V = new int[Q];
        int[] D = new int[Q];
        int[] C = new int[Q];
        for(int i=0;i<Q;i++){
            str = Console.ReadLine().Split(' ');
            V[i] = int.Parse(str[0])-1;
            D[i] = int.Parse(str[1]);
            C[i] = int.Parse(str[2]);
        }
        color = new int[N];
        us = new int[N];
        for(int i=0;i<N;i++){
            us[i] = -1;
        }
        for(int i=Q-1;i>=0;i--){
            if(us[V[i]] < D[i]){
                dfs(V[i],D[i],C[i]);
            }
        }
        for(int i=0;i<N;i++){
            sb.Append(color[i]+"\n");
        }
    }
    void dfs(int v,int d,int c){
        us[v] = d;
        if(color[v] == 0){
            color[v] = c;
        }
        if(d != 0){
            for(int i=0;i<G[v].Count;i++){
                int t = G[v][i];
                if(us[t] < d-1){
                    dfs(t,d-1,c);
                }
            }
        }
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp(a,b) make_pair(a,b)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*y/gcd(x,y);
}

int main(){
    ll N; cin>>N;
  ll ans=0;
  rep(i,N){
  	ll a,b; cin>>a>>b;
    ans+=b;
    ans-=a;
    ans++;
  }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;

const int MOD = 1e9 + 7;

const int N = 1000005;
vi fact_table(N);

void init(){
  for(int i=2;i<N;i++){
    if (fact_table[i] != 0) continue;
    for(int j=i;j<N;j+=i){
      fact_table[j] = i;
    }
  }
}

map<int, int> getFact(int n){
  map<int, int> fact_mp;
  while(n > 1){
    fact_mp[fact_table[n]]++;
    n /= fact_table[n];
  }
  return fact_mp;
}

ll mpow(ll a, ll n){
  ll p = 1;
  while (n){
    if (n & 1) p = (p * a) % MOD;
    a = (a*a) % MOD;
    n >>= 1;
  }
  return p;
}

ll inv(ll a){
  return mpow(a, MOD - 2);
}

int main() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];

  init();

  map<int, int> fact_list;
  rep(i, n){
    map<int, int> fl = getFact(a[i]);
    // cout << a[i] << ": ";
    for(auto p: fl){
      // printf("(%d,%d)", p.first, p.second);
      fact_list[p.first] = max(fact_list[p.first], p.second);
    }
    // cout << endl;
  }

  ll w_lcm = 1;
  for(auto p: fact_list){
    w_lcm *= mpow(p.first, p.second);
    w_lcm %= MOD;
  }
  

  // cout << w_lcm << endl;
  ll ans = 0;
  rep(i, n){
    // cout << a[i] << " " << inv(a[i]) << endl;
    ans += w_lcm * inv(a[i]);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  
  int black_num = 0;
  vector<vector<char>> maze(H, vector<char>(W, ' '));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> maze.at(i).at(j);
      if (maze.at(i).at(j) == '#') black_num++;
    }
  }
  
  vector<vector<int>> count(H, vector<int>(W, -1));
  count.at(0).at(0) = 1;
  
  queue<pair<int, int>> que;
  que.push(pair<int, int>(0, 0));
  
  int dx[] = {1, -1, 0, 0};
  int dy[] = {0, 0, 1, -1};
  
  while(!que.empty()) {
    pair<int, int> pos = que.front();
    que.pop();
    
    if (pos.first == H - 1 && pos.second == W - 1) {
      cout << H * W - black_num - count.at(pos.first).at(pos.second) << endl;
      return 0;
    }
    
    for (int i = 0; i < 4; i++) {
      int nx = pos.first + dx[i];
      int ny = pos.second + dy[i];
      
      if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if (maze.at(nx).at(ny) == '#') continue;
      if (count.at(nx).at(ny) != -1) continue;
      
      count.at(nx).at(ny) = count.at(pos.first).at(pos.second) + 1;
      que.push(pair<int, int>(nx, ny));
    }
  }
  
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter

def ep(*params):
    print(*params,file=sys.stderr)

(N,P) = list(map(int,input().split()))
S = input().rstrip()

if 10%P == 0:
    ans = 0
    for i in range(N):
        if int(S[i])%P == 0:
            ans += i+1
    print(ans)
    sys.exit()

ans = 0
d = [0]*(N+1)
cnt = [0]*P
ten = 1

for i in range(N-1,-1,-1):
    a = int(S[i]) * ten % P
    d[i] = (d[i+1]+a) % P
    ten *= 10
    ten %= P

#ep(d)

for i in range(N,-1,-1):
    ans += cnt[d[i]]
    cnt[d[i]] += 1;
    #ep(i,ans,cnt)
#ep(cnt)
print(ans)

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

int main () {
  int N,K,H,d,A;
  cin >> N >> K;
  H=0;
  vector<int> C(N);
  for (int i=0; i<N; i++) {
    C.at(i)=1;
  }
  for (int i=0; i<K; i++) {
    cin >> d;
    for (int j=0; j<d; j++) {
      cin >> A;
      C.at(A-1)=0;
    }
  }
  for (int i=0; i<N; i++) {
    H+=C.at(i);
  }
  cout << H << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
//No change above here

const ll maxi = 302;
ll mod = (1e9 + 7);

//function for power
ll power(ll x, ll n) {
	ll res = 1;
	x %= mod;
	while (n) {
		if (n & 1)
			res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}

ll sum_digits(ll n)
{
	ll ret=0;
	while (n)
	{
		ret += n % 10;
		n /= 10;
	}
	return ret;
}

ll dir[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll p, q;
bool valid(ll i, ll j) { return i >= 1 && i <= p && j >= 1 && j <= q; }

//declare needed things here



int main()
{
	IOS;
	ll ans,y, t,n,m;
	
		cin >> n;
		m = 1000 - (n % 1000);
		cout << ((m==1000)?0:m) << endl;
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>

using namespace std;

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

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

  int res = 0;
  REP(i, N) {
    int a;
    cin >> a;
    res += a - 1;
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define repp(i,j,k) for(int i=j;i>=k;i--)
#define llrep(i,j,k) for(long long int i=j;i<(long long int)k;i++)
#define Sort(x) sort(x.begin(),x.end()); 
#define vi vector<int>
#define vvi vector<vector<int>> 
#define ll long long
int mod=1e9+7;
const int INF = 1e9;

using namespace std;



int main(void) {
	int ans;
	string c;
	stack<int> s;
	while (cin >> c) {
		if (c == "+" || c == "*" || c == "-") {

			int x, y;
			x = s.top();
			s.pop();
			y = s.top();
			s.pop();

			if (c == "+") s.push(x + y);
			else if (c == "*") s.push(x*y);
			else if (c == "-")s.push(y - x);
		}
		else {
			s.push(stoi(c));
		}
	}

	cout << s.top() << endl;

	return 0;
}

Measured memory_bytes: 3216
N = int(input())
town = list(map(int,input().split(" ")))
town_before = sum(town)
brave = list(map(int,input().split(" ")))
for i in range(N):
    if town[i] < brave[i]:
        brave[i] -= town[i]
        town[i] = 0
        if town[i + 1] < brave[i]:
            town[i + 1] = 0
        else:
            town[i + 1] -= brave[i]
    else:
        town[i] -= brave[i]
print(town_before - sum(town))

Measured memory_bytes: 18624
#include <iostream>

using namespace std;

int main() {
	int data[5];
	while (cin >> data[0]) {
		if (data[0] == 0) {
			break;
		}
		cin >> data[1] >> data[2] >> data[3] >> data[4];
		int jan[3] = {0};
		for (int i = 0; i < 5; i++) {
			jan[data[i]-1]++;
		}
		if ((jan[0] > 0 && jan[1] > 0 && jan[2] > 0) || jan[0] == 5 || jan[1] == 5 || jan[2] == 5) {
			for (int i = 0; i < 5; i++) {
				cout << 3 << endl;
			}
		} else if (jan[0] == 0) {
			for (int i = 0; i < 5; i++) {
				if (data[i] == 2) {
					cout << 1 << endl;
				} else {
					cout << 2 << endl;
				}
			}
		} else if (jan[1] == 0) {
			for (int i = 0; i < 5; i++) {
				if (data[i] == 3) {
					cout << 1 << endl;
				} else {
					cout << 2 << endl;
				}
			}
		} else if (jan[2] == 0) {
			for (int i = 0; i < 5; i++) {
				if (data[i] == 1) {
					cout << 1 << endl;
				} else {
					cout << 2 << endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int64_t N,K;
    cin >> N >> K;
    vector<int64_t> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    for(int i=0; i<N-K; i++)
    {
        if(A.at(i)<A.at(i+K))
        {
        cout << "Yes" << endl;
        }
        else
        {
        cout <<"No" << endl; 
        }
    }
}

Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N; cin >> N;
  vector<pair<int, int>> data(N);
  
  for(int i = 0; i < N; i++){
    cin >> data.at(i).first;
    data.at(i).second = i+1;
  }
  
  sort(data.begin(), data.end());
  
  int maxnum = data.at(N-1).second;
  
  for(int i = 0; i < N; i++){
    if(i+1 == maxnum) cout << data.at(N-2).first << endl;
    else cout << data.at(N-1).first << endl;
  }
}

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

int main(){
    int n,m;
    cin>>n>>m;
    int a[100][100]={{}};
    int b[100]={};
    
    int sum=0;
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin>>a[i][j];
        }
    }
    for(int j=0; j<m; j++) cin>>b[j];
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            sum+=a[i][j]*b[j];
        }
        cout<<sum<<endl;
        sum=0;
    }
    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int a[maxn],n,k;
int dp[maxn];		//dp[i]´ú±í´Ó0µ½iËùÐèµÄ²½Êý

int main() {
	cin>>n>>k;
	for(int i = 1 ;i <= n;i++) cin>>a[i];
	
	dp[1] = 0;
	dp[2] = abs(a[1] - a[2]);
	for(int i = 3;i <= n;i++) {
		int ans=  1e9+10;
		for(int j = 1;j <= k && i-j >= 1;j++) {		//Ã¶¾ÙÃ¿Ò»²½ 
			ans = min(ans,dp[i-j] + abs(a[i-j] - a[i]));
		}
		dp[i] = ans;
	}
	cout<<dp[n];
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

using P = pair<int, int>;

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

    vector<P> value(N);
    for (int i = 0; i < N; i++) {
        int num = 0;
        int mini = 0;
        string s;
        cin >> s;
        for (const char c : s) {
            if (c == '(') {
                num++;
            } else {
                num--;
            }
            mini = min(num, mini);
        }
        value[i] = make_pair(mini, num);
    }
    int sum = 0;
    vector<P> evil;
    for (int i = 0; i < N; i++) {
        if (value[i].first >= 0) {
            sum += value[i].second;
        } else {
            evil.push_back(value[i]);
        }
    }
    vector<P> plus;
    vector<P> minus;
    for (const P& p : evil) {
        if (p.second >= 0) {
            plus.push_back(p);
        } else {
            minus.push_back(p);
        }
    }

    sort(plus.begin(), plus.end(), greater<P>{});
    sort(minus.begin(), minus.end(), [](const P& p1, const P& p2) { return p1.first - p1.second < p2.first - p2.second; });
    for (const P& p : plus) {
        if (p.first + sum < 0) {
            cout << "No" << endl;
            return 0;
        } else {
            sum += p.second;
        }
    }
    for (const P& p : minus) {
        if (p.first + sum < 0) {
            cout << "No" << endl;
            return 0;
        } else {
            sum += p.second;
        }
    }
    if (sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3204
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.array;

  int n;
  rd(n);

  auto a = readln.split.map!((s) => (s == "T" ? 1 : 0)).array;
  int f(int x, int y) {
    return (x - y <= 0);
  }
  //
  auto t = f(a[0], a[1]);
  foreach (i; 2 .. n) {
    t = f(t, a[i]);
  }
  if (t) {
    writeln("T");
  } else {
    writeln("F");
  }

}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}



Measured memory_bytes: 4568
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N), B(N), C(M), D(M);
    rep(i, N) { cin >> A[i] >> B[i]; }
    rep(i, M) { cin >> C[i] >> D[i]; }
    vector<int> res(N);
    rep(i, N) {
        int mi = INF;
        for(int j = M - 1; j >= 0; j--) {
            if(abs(A[i] - C[j]) + abs(B[i] - D[j]) <= mi) {
                mi = abs(A[i] - C[j]) + abs(B[i] - D[j]);
                res[i] = j + 1;
            }
        }
    }
    rep(i, N) cout << res[i] << endl;
    return 0;
}

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

    using namespace std;

    int main() {
      string S;

      cin >> S;

      for (int i = 1; i < 4; i++) {
        if (S[i] == S[i - 1]) {
          cout << "Bad" << endl;

          return 0;
        }
      }

      cout << "Good" << endl;

      return 0;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n; 
  cin >> n;

  int s1,s2,s3,s4;
  
  s1 = n / 1000;
  s2 = (n / 100) % 10;
  s3 = (n / 10) % 10;
  s4 = n % 10;

  if ((s2 == s3) && (s1 == s2 || s3 == s4)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;

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

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

const long long INF = 1LL << 60;
long long h[100010];
long long dp[100010];


long long rec(int i) {
    // DP の値が更新されていたらそのままリターン
    if (dp[i] < INF) {
        return dp[i];
    }
    // 足場0のコストは0
    if (i == 0) {
        return 0;
    }
    long long res = INF;
    chainge_min(res, rec(i - 1) + abs(h[i] - h[i - 1]));
    if (i > 1) {
        chainge_min(res, rec(i - 2) + abs(h[i] - h[i -2]));
    }
    // 結果をメモしながら返す
    return dp[i] = res;
}

int main(void) {
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> h[i];
    }
    // 初期化 (最小化問題なので INF で初期化)
    for (int i = 0; i < 100010; ++i) {
        dp[i] = INF;
    }
    cout << rec(N - 1) << endl;
    return 0;
}

Measured memory_bytes: 6528
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n, a; cin >> n >> a;
    cout << n * n - a << endl;
}


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

using namespace std;


int main(){
	int N;
	cin>>N;
	vector<int> vec;
	
	for(int i=0;i<100000;i++){
		vec.push_back(0);
	}
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		vec[a]++;
		if(a-1>=0)vec[a-1]++;
		if(a+1<100000)vec[a+1]++;
	}
	sort(vec.begin(),vec.end(),greater<int>());
	
	cout<<vec[0]<<endl;
	
	return 0;
}

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

#include <bits/stdc++.h>

using namespace std;

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

void d_err() {
    cerr << endl;
}

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

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

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

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

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

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

    vi A(3);
    REP(i, 3) cin >> A[i];
    
    sort(ALL(A));
    
    int ans = 0;
    REP(i, 2) {
        ans += A[i+1] - A[i];
    }
    
    print(ans);
}


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

using namespace std;

using int64 = long long;

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

  int n;
  cin >> n;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }
  
  int ans = 0;
  vector<int64> current;
  int current_sign = 0;
  for (int64 x : xs) {
    if (current.size() == 0) {
      current.push_back(x);
    } else {
      if (current_sign > 0) {
        if (current.back() > x) {
          ans++;
          current.clear();
          current_sign = 0;
        }
        current.push_back(x);
      } else if (current_sign < 0) {
        if (current.back() < x) {
          ans++;
          current.clear();
          current_sign = 0;
        }
        current.push_back(x);
      } else {
        if (current.back() < x) current_sign = 1;
        else if (current.back() > x) current_sign = -1;
        current.push_back(x);
      }
    }
  }
  ans++;
  cout << ans << endl;
}


Measured memory_bytes: 2168
/*******************************
 * written by Koki Riho
 * Rih0z https://github.com/Rih0z
 *******************************/

#include<iostream>
#include<map>
#include<vector>
#include<string>
#include<numeric>
#include<algorithm>

#define DEBUG false
#define FOR(i , a, b) for(size_t i = a ; i < b ; i++ )
#define REP(i,b) FOR(i , 0 , b)
#define RFOR(i,a,b) for(size_t i = a-1 ; i >= b ; i--)
#define RREP(i,a) RFOR(i,a,0)



typedef long long ll;
using namespace std;

int scanInt(void);
string scanString(void);

void scanLlArr(ll *a , int n);
void scanCharArr(char *string);

void printInt(int p);
void printLlArr(ll *a);
void printCharArr(char *string);


void perSum(ll *a , ll *sum ,int n);

/*************Global variable  **************/
int N ;
char str[26];
string S , T ;
std::map<char,int> M ;
/*******************************/

int main(){
  if (DEBUG){
    std::printf("******debug mode********\n");
  }
  cin >> S >> T ;

  REP(i,S.length()){
  if (DEBUG){
    std::printf("******debug********\n");
    cout << S << endl;
    std::printf("******debug********\n");
  }
  if(S.compare(T)==0  ){
    cout << "Yes" << endl;
    return 0 ;
  }
  S = S.substr(1)+S[0] ;
  }
  cout << "No" << endl;
  return 0 ;
}

//各地点までの部分和を計算する
void perSum(ll *a , ll *sum ,int n){
  int i ;
  sum[0] = a[0];
  for(i = 1 ; i < n ; i++){
    sum[i] = a[i] + sum[i-1];
  }

}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	long long int a,b,c;
	scanf("%lld %lld %lld",&a,&b,&c);

	if(a==b && a!=c)
		printf("Yes\n");
	else if(b==c && b!=a)
		printf("Yes\n");
	else if(a==c && a!=b)
		printf("Yes\n");
        else
		printf("No\n");

	return 0;
}


Measured memory_bytes: 128
/*--ILRS-- sr4saurabh  */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define popb pop_back
#define mp make_pair
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define sz size 
#define len length 
#define se second 
//const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=10000000+6;
#define M_PI           3.14159265358979323846
//--------------------------------------------


//--------------------------------------------





//============================================
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
       freopen ("INPUT.txt" , "r" , stdin);
       freopen ("OUTPUT.txt", "w" , stdout);
    #endif

	//THE WATER WAS DEEP, I DROWNED AND THEN CAME FLOATING UP,DEAD!!

      double x, k , d;
      cin>>x>>k>>d;	

      double dist = abs(x);
      double moves = floor(dist/d);
      double ans = 0;
      if(moves >= k)
      {
          ans = abs(dist - k*d);
      }
      else
      {
        if(((ll)(k - moves)&1ll))
          ans = abs(dist - d*(moves+1));
        else
          ans = abs(dist - d*moves);
        //ans = min(abs(dist - d*moves) , abs(dist - d*(moves+1)));
        //ans = min(abs(dist - d*(moves-1)) , ans);
      }

      cout<<(ll)ans;
	














return 0;
}

Measured memory_bytes: 3740
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
  /*
    .......
    ..#....
    .......
    .#.....
    .......
  */
  rep(y,ty-sy) cout << "U";
  rep(x,tx-sx) cout << "R";
  rep(y,ty-sy) cout << "D";
  rep(x,tx-sx+1) cout << "L";
  rep(y,ty-sy+1) cout << "U";
  rep(x,tx-sx+1) cout << "R";
  cout << "DR";
  rep(y,ty-sy+1) cout << "D";
  rep(x,tx-sx+1) cout << "L";
  cout << "U";

  return 0;
}


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);
		sc.nextLine();//not use
		String input = sc.nextLine();
		int listI[] = splitStringToArrayOfInt(input);
		int count = 1;
		for(int i = 1 ; i < listI.length ; i++) {
			for(int j = 0 ; j < i ; j++) {
				if(listI[j] <= listI[i] && j == (i-1)) {
					count++;
				}else if(listI[i] < listI[j]) {
					break;
				}
			}
		}
		System.out.println(count);
	}
	
	private static int[] splitStringToArrayOfInt(String input) {
		return Arrays.stream(input.split(" ")).filter(s -> !s.isEmpty()).mapToInt(Integer::parseInt).toArray();
	}
}


Measured memory_bytes: 28740
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int count = 0;
        int[] ar = new int[N+1];
        for (int i = 1; i < N+1; i++) {
            ar[i] = sc.nextInt();
        }
        for (int i = 1; i < N+1; i++) {
            int P = ar[i];
            if (i == P) {
                i++;
                count++;
            }
        }
        System.out.println(count);
    }    
}


Measured memory_bytes: 59400
#include<stdio.h>
main(){
  int n,w,wa[100];
  int a,b;
  int i,temp;

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

  for(i=1;i<=w;i++)
    wa[i]=i;

  for(i=0;i<n;i++){
    scanf("%d,%d",&a,&b);
    temp=wa[a];
    wa[a]=wa[b];
    wa[b]=temp;
  }

  for(i=1;i<=w;i++)
    printf("%d\n",wa[i]);

  return 0;
}

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

#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)

using ll = long long;
#define INF 1e9




int main(){
  char c;
  cin >> c;
  if(c == 'a' || c=='e' || c=='i' || c=='o' || c=='u'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }



  return 0;
}


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

//for(i=0;i<N;i++)

int main() {
	long T,i,j,N,M,Q,K,flag,counti,maxm,minm,sum;
	cin>>i;
	if(i>=30){
	    cout<<"Yes"<<endl;
	}
	else{
	    cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3632
m, n = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
diff = 10000
d = {}
if n == 0:
  print(m)
else:
  for a in arr:
    if diff > abs(m - a):
      diff = abs(m - a)
    d[a] = 1
  n = 0
  while True:
    if d.get(m + n, 0) == 0 and d.get(m  - n, 0) == 0:
      print(min((m  - n, m  + n )))
      break
    if d.get(m  + n, 0) == 0:
      print(m + n)
      break
    elif d.get(m - n, 0) == 0:
      print(m - n)
      break
    n += 1

Measured memory_bytes: 9236
N,D = map(int,input().split())
count,limit = 0, D//(1.4141)
for _ in range(N):
  a,b = map(int, input().split())
  if abs(a)<=limit or abs(b)<=limit:
    d = ((a**2)+(b**2))**0.5
    if d<=D:
      count += 1
print(count)

Measured memory_bytes: 9644
#include<stdio.h>
#include<iostream>
using namespace std;

int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	int num=1;
	for(int i=1;i<=n;i++)
	{
		num*=2;
		while(num*2>num+k&&i<n)
		{
			num+=k;
			i++;
		}
	}
	printf("%d",num);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
/*
*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
*    ▀▀       ▀▀▀▀▀▀    ▀     ▀▀▀▀▀▀      ▀    ▀
*   ▀  ▀      ▀         ▀     ▀            ▀  ▀
*  ▀    ▀     ▀ ▀ ▀     ▀     ▀ ▀ ▀         ▀
* ▀ ▀▀▀▀ ▀    ▀         ▀     ▀             ▀
*▀        ▀   ▀         ▀     ▀             ▀
*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
*/
using namespace std;
void afify()
{
	ios::sync_with_stdio(0);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
#define ll long long
#define ld long double
#define mk make_pair
#define loop(i,intial,n)  for(int i=int(intial);i<n;i++)
#define loopn(j,n) for(int j=int(n-1);j>=0;j--)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(v) v.begin(),v.end()
///////////////////////////////////////
#define SCD(a) scanf("%d",&a)
#define SCD2(a,b) scanf("%d %d",&a,&b)
#define SCLL(a) scanf("%lld",&a)
#define SCLL2(a,b) scanf("%lld %lld",&a,&b)
#define PRD(a) printf("%d\n",a)
#define PRLL(a) printf("%lld\n",a)
///////////////////////////////////////
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <vi> vvi;
typedef vector <vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<vpii> vvpii;
typedef stringstream ss;
const ll oo = (ll) 10e9 + 7;
const double EPS = 1e-4;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//ifstream ifs("input.txt");
//ofstream ofs("output.txt");
int main()
{
	afify();
	ll a, b, c;
	cin >> a >> b >> c;
	a *= 100;
	b *= 10;
	a += b;
	a += c;
	if (a % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}



	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int x, a; cin >> x >> a;
	if (x < a)cout << 0 << endl;
	else cout << 10 << endl;
}

Measured memory_bytes: 256
from collections import deque

que = deque()
t = 0
seat = [0] * 17
score = []
while que or t < 500:
  if t % 5 == 0 and t < 500:
    i = t // 5
    que.append([t, 5 if i % 5 == 1 else 2, 17 * (i % 2) + 3 * (i % 3) + 19])
  
  for i in range(17):
    if seat[i]:
      seat[i] -= 1

  while que:
    need_space = que[0][1]
    for i in range(18 - need_space):
      if not any(seat[i:i+need_space]):
        for j in range(i, i + need_space):
          seat[j] = que[0][2]
        score.append(t - que[0][0])
        que.popleft()
        break
    else:
      break
  t += 1

while True:
  try:
    print(score[int(input())])
  except EOFError:
    break



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

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

ll lcm(ll a, ll b){
	return a/gcd(a, b)*b;
}

// 素因数分解
vector<pll> prime_factor(ll n){
	vector<pll> res;
	for(ll i=2; i*i<=n; ++i){
		if(n%i!=0){
			continue;
		}
		int num=0;
		while(n%i==0){
			++num;
			n/=i;
		}
		res.push_back(pii(i, num));
	}
	if(n!=1){
		res.push_back(pii(n, 1));
	}
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	ll a, b;
	cin>>a>>b;
	vector<pll> c=prime_factor(a);
	vector<pll> d=prime_factor(b);
	sort(ALL(c));
	sort(ALL(d));
	int idx=0, n=d.size();
	ll ans=1;
	for(auto &x : c){
		while(idx<n && d[idx].first<x.first){
			++idx;
		}
		if(idx<n && d[idx].first==x.first){
			++ans;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000)
INF = 1<<32


def solve(N: int, A: "List[int]"):
    ans = 1
    t = 1
    for i in range(N):
        t *= 3
        if A[i]%2 == 0:
            ans *= 2
        
    print(t-ans)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    for (int i=1; i<10; i++) {
        for (int j=1; j<10; j++) {
            cout << i << 'x' << j << '=' << i*j << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1116
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

using edge = pii;
using Graph = vector<vector<edge>>;
const int max_n = 1e5+10;

int n;
vector<int> color(max_n, -1);
Graph G(max_n, vector<edge>());

void dfs(int n){
    for(auto e: G[n]){
       int to = e.first, dist = e.second;
        if(color[to] == -1){
            if(dist % 2 == 1) color[n] == 1 ? color[to] = 0 : color[to] = 1;
            else color[n] == 1 ? color[to] = 1 : color[to] = 0;
            dfs(to);
        }
    }
}

int main(){
    cin >> n;
    rep(i, n-1){
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        G[u].push_back(edge(v, w));
        G[v].push_back(edge(u, w));
    }

    color[0] = 0;
    dfs(0);

    rep(i, n)
        cout << color[i] << ln;
}


Measured memory_bytes: 7296
import sys
import numpy as np
import math
N,D = list(map(int, input().split()))

s = 0

for i in range(N):

    X = list(map(int, input().split()))
    if X[0] > D or X[1] > D:
        continue
    c = math.sqrt(X[0] * X[0] + X[1] * X[1])
    if c <= D:
        s = s + 1
print(s)

Measured memory_bytes: 27112
N, K = map(int, input().split())
res = (N - 1) * (N - 2) // 2 - K

if res < 0:
    print(-1)
else:
    ans = []
    for i in range(2, N + 1):
        ans.append([1, i])

    cnt = 0
    for i in range(2, N):
        if cnt == res:
            break

        for j in range(i + 1, N + 1):
            if cnt == res:
                break
            ans.append([i, j])
            cnt += 1

    print(len(ans))
    for v in ans:
        print(*v)


Measured memory_bytes: 74676
N,Q = map(int,input().split())
BIT = [0]*(N+1)

def BIT_query(idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

def BIT_update(idx,x):
    while idx <= N:
        BIT[idx] += x
        idx += idx&(-idx)
    return

c = [-1]+list(map(int,input().split()))
lastAppeared = [-1]*(N+1)
ans = [0]*Q
queries = []
for q in range(Q):
    l,r = map(int,input().split())
    queries.append((l,r,q))
queries.sort(key = lambda x:x[1])

curR = 0
for i in range(Q):
    l,r,q = queries[i]
    while curR < r:
        curR += 1
        new = c[curR]
        last = lastAppeared[new]
        if last != -1:
            BIT_update(last,-1)
        lastAppeared[new] = curR
        BIT_update(curR,1)
    ans[q] = BIT_query(r)-BIT_query(l-1)
for i in range(Q):
    print(ans[i])

Measured memory_bytes: 179980
package main

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

type Tuple struct {
	A int
	B int
}

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	L := make(SortInterFace, N)
	for i := 0; i < N; i++ {
		A := sc.NextInt()
		B := sc.NextInt()
		L[i] = Tuple{A, B}
	}
	sort.Sort(L)

	totalA := 0
	totalB := 0

	for i := 0; i < N; i++ {
		if i%2 == 0 {
			totalA += L[i].A
		} else {
			totalB += L[i].B
		}
	}

	fmt.Println(totalA - totalB)

}

type SortInterFace []Tuple

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return (s[i].A + s[i].B) > s[j].A+s[j].B
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

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

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 6144
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

void Q1() {

	double r;
	double PI = 3.141592653589;
	cin >> r;

	printf("%lf %lf\n", PI*r*r, 2 * r*PI);

}

void Q2() {
	int a, b;
	string op;

	while (true)
	{
		cin >> a >> op >> b;
		if (op == "?") { break; }
		else if (op == "+") {
			cout << a + b << endl;
		}
		else if (op == "-") {
			cout << a - b << endl;
		}
		else if (op == "*") {
			cout << a * b << endl;
		}
		else if (op == "/"){
			cout << a / b << endl;
		}
	}
	
}

void Q3() {
	int x; cin >> x;
	int sum = 0;
	vector<int> a;
	a.resize(x);

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

	}

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

	cout << a[0] << " " << a[x - 1] << " " << sum << endl;
}

void Q4() {

	while (true)
	{
		int a, b;
		cin >> a >> b;

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

		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				cout << "#";
				if (j == b - 1) {
					cout << "\n";
					break;
				}
			}
		}

		cout << "\n";
	}
}

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

Measured memory_bytes: 1128
#include "bits/stdc++.h"
using namespace std;

struct root {
	int cost;
	int from;
	int to;
};

int Par[100000], Rank[100000];

void init(int N) {
	for (int i = 0; i < N; i++) {
		Par[i] = i;
		Rank[i] = 0;
	}
}

int Root(int N) {
	if (Par[N] == N) return N;
	return Par[N] = Root(Par[N]);
}

void unite(int A, int B) {
	A = Root(A), B = Root(B);
	if (Rank[A] < Rank[B]) Par[A] = B;
	else {
		Par[B] = A;
		if (Rank[A] == Rank[B]) Rank[A]++;
	}
}

bool same(int A, int B) {
	return Root(A) == Root(B);
}

int main() {
	int N;
	long long ans = 0;
	static pair<int, int> X[100000], Y[100000];
	cin >> N;
	init(N);
	for (int i = 0; i < N; i++) {
		cin >> X[i].first >> Y[i].first;
		X[i].second = i, Y[i].second = i;
	}
	sort(X, X + N);
	sort(Y, Y + N);
	vector<root> V;
	for (int i = 0; i < N - 1; i++) {
		root r;
		r.from = X[i].second;
		r.to = X[i + 1].second;
		r.cost = X[i + 1].first - X[i].first;
		V.push_back(r);
	}
	for (int i = 0; i < N - 1; i++) {
		root r;
		r.from = Y[i].second;
		r.to = Y[i + 1].second;
		r.cost = Y[i + 1].first - Y[i].first;
		V.push_back(r);
	}
	sort(V.begin(), V.end(), [&](root R1, root R2) {return R1.cost < R2.cost; });
	for (root R : V) {
		if (same(R.from, R.to)) continue;
		ans += R.cost;
		unite(R.from, R.to);
	}
	cout << ans;
}

Measured memory_bytes: 7156
#include<bits/stdc++.h>
using namespace std;
int n,a[100001],b,c,m,k,sum,minn=1e8;
char s[100001];
int main()
{
	string w;
	cin>>w;
	int len=w.length();
	cout<<w[0]<<len-2<<w[len-1]<<endl;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int,input().split()))
S = sum(L)
ans = float('inf')
for i in range(N):
  t = 0
  for j in range(i):
    t += L[j]
  k = S-t
  if abs(k-t) <= ans:
    ans = abs(k-t)
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>

using namespace std;

class DisjointSet{
    public:
        vector<int> rank, p;
    
    DisjointSet(){}
    DisjointSet(int size){
        rank.resize(size, 0);
        p.resize(size, 0);
        for(int i = 0; i < size; i++) makeSet(i);
    }
    
    void makeSet(int x){
        p[x] = x;
        rank[x] = 0;
    }
    
    bool same(int x, int y){
        return findSet(x) == findSet(y);
    }
    
    void unite(int x, int y){
        link(findSet(x), findSet(y));
    }
    
    void link(int x, int y){
        if(rank[x] > rank[y]){
            p[y] = x;
        }
        else{
            p[x] = y;
            if(rank[x] == rank[y]) rank[y]++;
        }
    }
    
    int findSet(int x){
        if(x != p[x]){
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

int main(){
    int n, a, b, q;
    int t;
    
    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);
    
    for(int i = 0; i < q; i++){
        cin >> t >> a >> b;
        if(t == 0) ds.unite(a, b);
        else if(t == 1){
            if(ds.same(a, b)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3176
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
const int maxn = 2e5+100;
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b,n;
    cin>>a>>b>>n;
    ll ans;
    if(n>=b)
    ans=(b-1)*a/b;
    else {
    	ans=n*a/b;
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>


int main(void)
{
  int n;
  int a;
  int min = 1000000;
  int max = -1000000;
  long long sum = 0;
  
  scanf("%d", &n);
  
  while( n ){
    scanf("%d", &a);
    if( min > a ) min = a;
    if( max < a ) max = a;
    
    sum += a;
    
    n--;
  }
  
  printf("%d %d %lld\n", min, max, sum);
  
  return 0;
  
}

Measured memory_bytes: 600