akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

ll fc(vector<int> &ld, vector<int> &c, int d){
  ll ret = 0;
  rep(i, 26){
    ret += (ll)c.at(i)*(d - ld.at(i));
  }
  return ret;
}

ll ret(vector<int> &c, vector<vector<int>> &s, vector<int> &ld, int t, int day, bool f, int &tt){
  ll ans = 0;
  tt = ld.at(t);
  ld.at(t) = day;
  ans += s.at(day).at(t);
  ans -= fc(ld, c, day);
  if(f == false)ld.at(t) = tt;
  return ans;
}

int main(){
  int D;
  cin >> D;
  vector<int> ld(26, -1);
  vector<int> c(26);
  rep(i, 26) cin >> c.at(i);
  vector<vector<int>> s(D, vector<int>(26));
  rep(i, D){
    rep(j, 26){
      int in;
      cin >> in;
      s.at(i).at(j) = in;
    }
  }
  int tt;
  rep(i, D){
    ll mx = -9e18;
    int jj = 0;
    if(i > D-1){
      rep(j, 26){
        rep(k, 26){
          ll r = ret(c, s, ld, j, i, true, tt);
          r += ret(c, s, ld, k, i+1, false, tt);
          if(r > mx){
            mx = r;
            jj = j;
          }
          ld.at(j) = tt;
        }
      }
    }else{
      rep(j, 26){
        ll r = ret(c, s, ld, j, i, false, tt);
        if(r > mx){
          mx = r;
          jj = j;
        }
      }
    }
    cout << jj+1 << endl;
    ret(c, s, ld, jj, i, true, tt);
  }
  return 0;
}

Measured memory_bytes: 3684
import * as fs from 'fs';
const input = fs.readFileSync("/dev/stdin", "utf8").split(/\n/);

// C - いっしょ

const N = +input[0];
const nums = input[1].split(' ').map(Number);
const goal = Math.round(nums.reduce((acc, cur) => {return acc + cur}) / nums.length);
let cost = 0;

if (!checkNums(nums, goal)) {
    nums.forEach(num => {
        cost += (num - goal) * (num - goal);
    });
}

console.log(cost);

function checkNums(nums: Array<number>, goal: number): boolean {
    let res = true;
    nums.forEach(num => {
        if (num !== goal) res = false;
    });
    return res;
}

Measured memory_bytes: 7372
N = int(input())
B = list(map(int,input().split()))
A = [0 for _ in range(N)]
A[0]=B[0]
for i in range(1,N-1):
    A[i]=min(B[i-1],B[i])
A[N-1]=B[N-2]
print(sum(A))

Measured memory_bytes: 61788
n = gets.to_i
ws = n.times.map { gets.chomp }

ans = 'Yes'

ans = 'No' if ws.uniq.count != ws.count

last = ws[0][-1]
ws[1..-1].each do |w|
  if w[0] != last
    ans = 'No'
    break
  end
  last = w[-1]
end

puts ans

Measured memory_bytes: 3836
import sys, collections
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = I()
    A = LI()

    cnt = collections.Counter(A)
    A = list(set(A))
    A.sort()
    A_max = A[-1]
    divisible = [False] * (A_max + 1)

    for i in A:
        for j in range(2 * i, A_max+1, i):
            divisible[j] = True

    ans = 0
    for i in A:
        tmp = 0
        if not divisible[i] and cnt[i] == 1:
            tmp += 1
        ans += tmp

        
    print(ans)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 45296
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define INF 9223372036854775807 / 2
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair


using namespace std;

std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

struct uf_tree {
	std::vector<int> parent;
	int __size;
	uf_tree(int size_) : parent(size_, -1), __size(size_) {}
	void unite(int x, int y) {
		if ((x = find(x)) != (y = find(y))) {
			if (parent[y] < parent[x]) std::swap(x, y);
			parent[x] += parent[y];
			parent[y] = x;
			__size--;
		}
	}
	bool is_same(int x, int y) { return find(x) == find(y); }
	int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
	int size(int x) { return -parent[find(x)]; }
	int size() { return __size; }
};

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

	uf_tree uf(1000000);

	rep(i, N) {
		int K;
		cin >> K;
		rep(j, K) {
			int L;
			cin >> L;
			uf.unite(i + 1, L + 100001);
		}
	}

	int root = uf.find(1);
	bool isOK = true;
	//違う親のヤツがいたらNG
	rep(i, N) {
		int other = uf.find(i + 1);
		if (root != other) {
			isOK = false;
			break;
		}
	}
	if (isOK) {
		cout << "YES\n";
	}
	else {
		cout << "NO\n";
	}


	return 0;
}

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

using namespace std;

int main() {
  string S;
  long long K;
  cin >> S >> K;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == '1') {
      if (i + 1 == K) {
        cout << S[i] << endl;
        break;
      }
    } else {
      cout << S[i] << endl;
      break;
    }
  }

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 256
h, w = map(int, input().rsplit())
S = [list(input().rstrip()) for _ in range(h)]
U = [[0] * w for _ in range(h)]
D = [[0] * w for _ in range(h)]
L = [[0] * w for _ in range(h)]
R = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if j == 0:
            if S[i][j] == ".":
                L[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            L[i][j] += 1 + L[i][j - 1]
for i in range(h):
    for j in range(w):
        if i == 0:
            if S[i][j] == ".":
                U[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            U[i][j] += 1 + U[i - 1][j]
for i in range(h - 1, -1, -1):
    for j in range(w - 1, -1, -1):
        if j == w - 1:
            if S[i][j] == ".":
                R[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            R[i][j] += 1 + R[i][j + 1]
for i in range(h - 1, -1, -1):
    for j in range(w - 1, -1, -1):
        if i == h - 1:
            if S[i][j] == ".":
                D[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            D[i][j] += 1 + D[i + 1][j]
ans = 0
for i in range(h):
    for j in range(w):
        temp = D[i][j] + U[i][j] + L[i][j] + R[i][j] - 3
        ans = max(temp, ans)
print(ans)


Measured memory_bytes: 309896
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
  int N, ans=1;
  cin >> N;
  string S[N];
  vector <string> str;
  for(int i=0; i<N; i++) cin >> S[i];
  for(int i=0; i<N; i++) str.push_back(S[i]);
  sort(str.begin(), str.end());
  for(int i=0; i<N-1; i++){
    if(str[i] != str[i+1]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 17816
#include <stdio.h>
#include <stdlib.h>

typedef struct {
  int pos;
  int val;
} Val;

int main()
{
  int i, j, k, n, m, q, v;
  char buf[32];
  fscanf(stdin, "%d", &n);
  Val *a = (Val*)malloc(sizeof(Val)*n);
  int alen=0;
  fscanf(stdin, "%d", &v);
  a[alen].pos=0;
  a[alen++].val=v;
  for (i=1; i<n; i++) {
    fscanf(stdin, "%d", &v);
    if (a[alen-1].val<v) {
      a[alen].pos = i;
      a[alen++].val = v;
    }
  }
  int begin, end, mid;
  fscanf(stdin, "%d\n", &q);
  for (i=0; i<q; i++) {
    fgets(buf, 32, stdin);
    k = atoi(buf);
    begin=0;
    end=alen-1;
    while (begin<=end) {
      mid=(begin+end)/2;
      if (a[mid].val==k) {
	int b = a[mid].pos;
	if (b==0) {
	  putc_unlocked('0', stdout);
	} else {
	  if (b<0) {
	    putc_unlocked('-', stdout);
	    b=-b;
	  }
	  for (j=1; j*10<=b; j*=10);
	  for (;j>0; j/=10) {
	    putc_unlocked('0'+b/j, stdout);
	    b %= j;
	  }
	}
	putc_unlocked('\n', stdout);

        goto next;
      }
      if (a[mid].val>=k) {
        end = mid - 1;
      } else begin = mid + 1;
    }
    if (begin>=alen) {
      int b = n;
      if (b==0) {
	putc_unlocked('0', stdout);
      } else {
	if (b<0) {
	  putc_unlocked('-', stdout);
	  b=-b;
	}
	for (j=1; j*10<=b; j*=10);
	for (;j>0; j/=10) {
	  putc_unlocked('0'+b/j, stdout);
	  b %= j;
	}
      }
      putc_unlocked('\n', stdout);
    } else {
      int b = a[begin].pos;
      if (b==0) {
	putc_unlocked('0', stdout);
      } else {
	if (b<0) {
	  putc_unlocked('-', stdout);
	  b=-b;
	}
	for (j=1; j*10<=b; j*=10);
	for (;j>0; j/=10) {
	  putc_unlocked('0'+b/j, stdout);
	  b %= j;
	}
      }
      putc_unlocked('\n', stdout);
    }
  next:
    ;
  }
  
  return 0;
}



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

int main(){
	int s;
	cin >> s;
	
	int num1 = s/100;
	int num2 = s%100;

	if(1 <= num1 && num1 <= 12){
		if(1 <= num2 && num2 <= 12){
			cout << "AMBIGUOUS" << endl;
		}else{
			cout << "MMYY" << endl;
		}
	}else if(1 <= num2 && num2 <= 12){
		cout << "YYMM" << endl;
	}else{
		cout << "NA" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int x[n+5],k[n+5];
	for(int i=1;i<=n;i++)  cin>>x[i],k[i]=x[i];
	sort(k+1,k+n+1);
	int ave1=k[n/2],ave2=k[n/2+1];
	for(int i=1;i<=n;i++){
		if(x[i]<=ave1)  cout<<ave2<<endl;
		else  cout<<ave1<<endl;
	}
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b,k;
    bool flag=true;
    scanf("%lld%lld%lld",&a,&b,&k);
    for(int i=0;i<k;i++)
    {
        if(flag)
        {
            if(a&1)
            {
                a--;
                b+=a/2;
                a/=2;
            }
            else
            {
                b+=a/2;
                a/=2;
            }
            flag=!flag;
        }
        else
        {
            if(b&1)
            {
                b--;
                a+=b/2;
                b/=2;
            }
            else
            {
                a+=b/2;
                b/=2;
            }
            flag=!flag;
        }
    }
    printf("%lld %lld\n",a,b);
}


Measured memory_bytes: 256
int main(void){
 double r = 0;
 double s = 0;
 double l = 0;
 double pai = 3.141592653589;
      
 scanf("%lf",&r);
 s = r * r * pai;
 l = 2 * r * pai;
      
 printf("%f %f\n", s,l);
 return 0;
}

Measured memory_bytes: 648
// D - Decrease (Contestant ver.)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	ll K;
	cin >> K;

	cout << 50 << endl;

	for (int i=0; i < 50 - (K % 50); i++) {
		if (i != 0) cout << " ";
		cout << 49 + (K/50) - (K%50);
	}

	for (int i=0; i < K % 50; i++) {
		cout << " " << 100 + (K/50) - (K%50);
	}

	cout << endl;

	return 0;
}

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

int main(){
  int n, x;
  cin >> n >> x;
  int ans = 0;
  vector<int> a(n);
  for( int i = 0 ; i < n ; ++i ) cin >> a.at(i);
  sort(a.begin(), a.end());
  for( int i = 0; i < n; ++i ){
    if(a.at(i) <= x){
      x -= a.at(i);
      ans++;
    }
  }
  if(x>0 && n == ans) ans--;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def resolve():
    import sys
    import collections
    sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
    to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
    print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

    # 入力を整数に変換して受け取る
    def input_int():
        return int(input())

    def map_int_input():
        return map(int, input())

    MII = map_int_input

    def MII_split():
        return map(int, input().split())

    def MII_to_index():
        return map(to_index, input())

    def MII_split_to_index():
        return map(to_index, input().split())

    # 入力全てを整数に変換したものの配列を受け取る
    def list_int_inputs():
        return list(map(int, input()))

    LII = list_int_inputs

    def LII_split():
        return list(map(int, input().split()))

    # 2次元リスト化
    def LII_2D(rows_number):
        return [LII() for _ in range(rows_number)]

    def LII_split_2D(rows_number):
        return [LII_split() for _ in range(rows_number)]

    def prime_factorize(n):
        a = []
        while n % 2 == 0:
            a.append(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.append(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.append(n)
        return a

    N = input_int()
    c = collections.Counter(prime_factorize(N))
    ans = 0
    # print(c)
    for _, value in c.items():
        for i in range(41):
            if value > i:
                value -= i + 1
                ans += 1
            else:
                break
    print(ans)
    
resolve()

Measured memory_bytes: 9508
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    long long int a,b,n,m;
    int i,c=0,d=0;
    cin>>a>>b;
    n=min(a,b);
    m=max(a,b);
    for (i=n+1;i<m;i++)
    {
        if (abs(a-i)==abs(b-i))
        {
            cout<<i<<endl;
            return 0;
        }
    }

    cout<<"IMPOSSIBLE"<<endl;



}


Measured memory_bytes: 3620
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

vi ansv, v;
int n, ans, cnt;
string m;

void rec(int c, int sum){
	if(sum > n) return;
	if(c == m.size()){
		if(sum > ans){
			ans = sum, cnt = 0;
			ansv = v;
		}
		if(ans == sum) cnt++;
		return;
	}
	rep(i, m.size() - c){
		int d = atoi(m.substr(c, i + 1).c_str());
		v.pb(d);
		rec(c + i + 1, sum + d);
		v.pop_back();
	}
}
int main(){
	while(cin >> n >> m, n){
		v.clear();
		ans = cnt = 0;
		rec(0, 0);
		
		if(cnt == 0) cout << "error" << endl;
		else if(cnt > 1) cout << "rejected" << endl;
		else{
			cout << ans << " ";
			rep(i, ansv.size()) cout << ansv[i] << (i==ansv.size()-1?"\n":" ");
		}
	}
	return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <string.h>

using namespace std;
#define ll long long int

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

	ll n,a,b;
	cin>>n>>a>>b;
	ll ai=n-a;
	ll bi=b-1;
	if(abs(a-b)%2==0){
		ai=min(ai,bi);
		ai=min(abs(a-b)/2,ai);
		cout<<ai<<endl;
	}
	else{
		ll ax=a+abs(b-a)/2;
		ll bx=n-b+1+abs(a-b)/2;
		cout<<min(min(ai,bi),min(ax,bx))<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
program main
  implicit none
  integer :: n, i
  character(100) :: s
  read (*, *) s
  n = len_trim(s)
  if (is_palindrome(trim(s)) .and. is_palindrome(s(1:(n - 1) / 2)) .and. is_palindrome(s((n + 3) / 2:n))) then
    write (*, "(a)") "Yes"
  else
    write (*, "(a)") "No"
  end if

  contains

  logical function is_palindrome(str)
    character(*) :: str
    integer :: n, i
    n = len(str)
    is_palindrome = .true.
    do i = 1, n / 2
      if (str(i:i) /= str(n - i + 1:n - i + 1)) is_palindrome = .false.
    end do
  end function is_palindrome
end program main


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;
typedef double D;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }





int main() {
	map<int, vci > rank;
	
	int s, t;
	while (1) {
		scanf("%d,%d", &s, &t);
		if (s==0 && t==0) break;
		
		rank[t].pb(s);
	}
	
	int all = 0;
	FOR(it, rank) all++;
	
	while (cin>>s) {
		int ans = 1;
		FOR(it, rank) {
			vci f = (*it).second;
			bool is = false;
			for_(i, 0, (int)f.sz) if (f[i]==s) is = true;
			if (is) break;
			ans++;
		}
		cout << all - ans + 1 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=5010;
int k,q,a[maxn],d[maxn];
int n,x,m;
ll sum,ans;
int b[maxn];
ll F(ll A) {
	if (A<0) return 0;
	return A/k+1;
}
int main() {
//	freopen("1.txt","r",stdin);
	read(k); read(q);
	for (int i=0;i<k;i++) read(a[i]);
	while (q--) {
		read(n); read(x); read(m);
		x%=m;
		for (int i=0;i<k;i++) d[i]=a[i]%m;
		d[k]=d[0];
		
		ans=0;
		for (int i=0;i<k;i++) {
			if (!d[i]) {
				//d[i]->d[i+1]
				//0<=i+?k<n
				ans+=F(n-i-2);
			//	printf("%lld\n",n-i-1);
			}
		}
		//printf("%lld\n",ans);
		sum=x;
		for (int i=0;i<k;i++) {
			// 0<=i+?k<n-1
			sum+=(ll)F(n-i-2)*d[i];
		}
		//printf("sum=%lld\n",sum);
		ans+=sum/m-x/m;
		printf("%lld\n",n-1-ans);
	}
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include <vector>
#include<map>
#include<algorithm>
#include<iomanip>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
const ll MOD = 1e9 + 7;

int main() {
	int n, y;
	cin >> n >> y;
	int a = -1, b = -1, c = -1;
	rep(i, n + 1) {
		rep(j, n - i + 1) {
			int k = n - i - j;
			if (10000 * i + 5000 * j + 1000 * k == y) {
				a = i;
				b = j;
				c = k;
				break;
			}
		}
		if (a != -1) break;
	}
	cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define endl "\n"
#define ff first
#define ss second
#define inp(a) int a; cin>>a;
#define inpa(a,n) vector<int>a(n); FOR(i,0,n-1) cin>>a[i];
#define PI 3.141592653589793238
#define QUICK ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vec(x) vector<x>
#define pii pair<int,int>
#define mem(a,b) memset(a, b, sizeof a)
#define FOR(i,j,n) for(int i= j; i<=n; i++)
#define srt(a); sort(a.begin(), a.end())
#define CASE int t; cin>>t; while(t--)
#define setBits(n) __builtin_popcountll(n)
#define prec(n) fixed<<setprecision(n)
#define print(x) for(auto c : x) cout << c << " ";
#define dbg(x) cerr << #x << " :: "<< x << endl;
#define dbg2(x,y) cerr << #x << " :: "<<x <<"\t" << #y << " :: "<<y <<endl;
#define upcase(s)  transform(s.begin(), s.end(), s.begin(), ::toupper)
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define int ll
const int INF = 1e9 + 7;
const int SIZE = 1e5 + 5;
const int MOD = 1e9 + 7; 
//////////// template ends here //////////////////////////

int wt[101];
int p[101];
int dp[101][SIZE];

int topdown(int n, int w){

	if(n <= 0 || w <= 0)
		return 0;
	if(dp[n][w] != -1)
		return dp[n][w];

		int s1 = topdown(n-1, w), s2 = 0;
		if(w - wt[n] >= 0 )
			s2 = topdown(n-1, w-wt[n]) + p[n] ;
	

	return dp[n][w] = max(s1, s2);
}

void solve(){	
	
	inp(n); inp(w);

	FOR(i,1,n)
		cin>>wt[i] >> p[i];
	memset(dp, -1, sizeof(dp));

    cout << topdown(n,w);	
}



int32_t main(){
	#ifndef ONLINE_JUDGE 
		freopen ("input.txt","r",stdin);
		freopen ("output.txt","w",stdout);
	#endif	
	QUICK;
	
	solve();
	printclock;
}

Measured memory_bytes: 82676
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
template <typename Mnd> struct segment_tree {
    int sz;
    vector<Mnd> data;
    function<Mnd(Mnd, Mnd)> f;
    Mnd e;
    //サイズだけ指定して初期化
    segment_tree(int _sz, function<Mnd(Mnd, Mnd)> _f, Mnd _e) : f(_f), e(_e) {
        sz = 1;
        while(sz < _sz)
            sz <<= 1;
        data.assign(sz * 2, e);
    }
    //参照渡しなので代入とかもできる
    Mnd &operator[](const int &k) { return data[k + sz]; }
    //木を構築 O(n)
    void build() {
        for(int i = sz - 1; i > 0; i--)
            data[i] = f(data[2 * i], data[2 * i + 1]);
    }
    //更新しつつ木を再構築 O(log n)
    void update(int k, Mnd x) {
        data[k += sz] = x;
        while(k >>= 1)
            data[k] = f(data[2 * k], data[2 * k + 1]);
    }
    //[a,b)でのクエリに答える　O(log n)
    Mnd query(int a, int b) const {
        Mnd l = e, r = e;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1)
                l = f(l, data[a++]);
            if(b & 1)
                r = f(r, data[--b]);
        }
        return f(l, r);
    }
};
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    segment_tree<int> seg(
        600001, [](int a, int b) { return max(a, b); }, 0);
    for(int i = 0; i < n; i++) {
        int tmp = seg.query(max(0, a[i] - k), a[i] + k + 1) + 1;
        ans = max(ans, tmp);
        seg.update(a[i], max(seg[a[i]], tmp));
    }
    cout << ans << endl;
}


Measured memory_bytes: 12764
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <functional>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
	deque<int> dq;
    int i;
    int x; 
    bool fr = true;
    for(i = 0; i < n; i++) {
		cin >> x;
		if(fr) {
			dq.push_back(x);
		}
		else {
			dq.push_front(x);
		}
		fr = !fr;
	}
	if(fr) {
		for(i = 0; i < n; i++) {
			cout << dq[i] << " ";
		}
	}
	else {
		for(i = n - 1; i >= 0; i--) {
			cout << dq[i] << " ";
		}
	}
	
	
    return 0;
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};


int main() {
    ll x, y; cin >> x >> y;
    ll now = x;
    int ans = 0;
    while (now <= y) {
        ans++;
        now *= 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
#define N 100

void draw(int, int *);

int main(){

  int n, a[N], v;
  int i, j;

  scanf("%d",&n);

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

  draw(n, a);

  for(i = 1; i < n; i++){

    v = a[i];
    j = i - 1;

    while(j >= 0 && a[j] > v){
      a[j + 1] = a[j];
      j--;

    }

    a[j + 1] = v;

    draw(n, a);

  }

  return 0;
}

void draw(int n, int *a){

  int i;

  for(i = 0; i < n; i++){
    printf("%d",a[i]);

    if(i != n - 1) printf(" ");

  }
 
  printf("\n");
  
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
//#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long n){
    map<Pii,int> ma;
    REP(i,1,n+1){
        int a=i,b;
        b=i%10;
        while(a>=10){
            a/=10;
        }
        ma[mp(b,a)]++;
    }
    
    int ans=0;
    REP(i,1,10){
        REP(j,1,10){
            ans += ma[mp(i,j)]*ma[mp(j,i)];
        }
    }
    cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
mp = []
for _ in range(h):
  lst = list(map(int, input().split()))
  cum = []
  acc = 0
  for i in lst:
    if i == 0:
      acc += 1
    else:
      acc = 0
    cum.append(acc)
  mp.append(cum)
mp.append([-1] * w)

ans = 0
for x in range(w):
  score_stack = []
  ind_stack = []
  for y in range(h + 1):
#    print(score_stack, ind_stack)
    score = mp[y][x]
    if score_stack == []:
      score_stack.append(score)
      ind_stack.append(y)
    else:
      last_score = score_stack[-1]
      if last_score < score:
        score_stack.append(score)
        ind_stack.append(y)

      elif last_score == score:
        continue

      else:
        while score_stack != [] and score_stack[-1] >= score:
          last_score = score_stack.pop()
          last_ind = ind_stack.pop()
#          print(last_score, last_ind, ans)
          ans = max(ans, min(y - last_ind, last_score) ** 2)
        
        score_stack.append(score)
        ind_stack.append(last_ind)
print(ans)



Measured memory_bytes: 52584
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int Q;
	scanf("%d",&Q);
	for(int i=0;i<Q;i++) {
		int c,a,n;
		scanf("%d %d %d",&c,&a,&n);
		int can=min(c,min(a,n));
		c-=can,a-=can,n-=can;
		int cca=min(c/2,a);
		c-=cca*2,a-=cca;
		int ccc=c/3;
		printf("%d\n",can+cca+ccc);
	}
}

Measured memory_bytes: 1028
// In the name of Allah. Ya ali!
#include<bits/stdc++.h>
#define double long double
#define debug(x)  cerr << #x << " = " << x << endl
typedef long long ll;
const ll MAX_N = 3e5+100;
const ll MOD = 1e9+7;
using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    cout << n-k+1;
    return 0;
}


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


typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
/*--------------------------------------------*/

int main(){
  //cout.precision(10);
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a,b,c;
  cin >> a >> b >> c;
  
  if(a+b+c>=22) cout << "bust" << endl;
  else cout << "win" << endl;
  


}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;

int main() {
	string s;
	cin >> s;
	if (s == "ARC")cout << "ABC" << endl;
	else cout << "ARC" << endl;
	return 0;

}

Measured memory_bytes: 3624
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
char m[99][2],z,y;int main(){int s,n;while(1){cin>>s;if(s==0)break;rep(i,s)cin>>m[i][0]>>m[i][1];cin>>n;rep(i,n){cin>>z;y=z;rep(j,s)if(m[j][0]==z)y=m[j][1];cout<<y;}cout<<endl;}return 0;}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--;)
#define int long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int maxn=1e3+5;
int n,m,a[maxn],b[maxn];
string k[maxn];
int f[maxn][maxn];
int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
queue<pair<int,int>>T;
queue<int>times;
int HH=0,ans=0;
int32_t main()
{
    IOS;
    cin>>n>>m;
    int mu=0;
    fu(i,0,n-1)
    {
        cin>>k[i];
        fu(j,0,m-1)
        if(k[i][j]=='#') {
            T.push({i, j});
            times.push(0);
        }
    }
    while(!T.empty() && !times.empty())
    {
        auto t=T.front();
        auto tt=times.front();
        ans=max(ans,tt);
        T.pop();
        times.pop();
        if(f[t.first][t.second])continue;
        f[t.first][t.second]=1;
        fu(i,0,3)
        {
            auto p=t;
            int x=p.first+dir[i][0],y=p.second+dir[i][1];
            if(x>=0 && y>=0 && x<=n-1 && y<=m-1)
            {
                int hh=tt;
                if(k[x][y]=='.') {
                    mu++;
                    k[x][y]='#';
                    T.push({x,y});
                    times.push(++hh);
                }
            }
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 33732
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int (i) = (N)-1; (i) >= 0; (i)--)
#define REP(i, N) for(int (i) = 0; (i) < (int)(N); (i)++)
 #include <iomanip>
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }


struct req {
	int a,b,c,d;
};
int n,m,q;

ll ans = 0;
int A[55];

void go(int curr, int last, const vector<req>& r) {
	if(curr == n) {
		ll cans = 0;
		REP(i, r.size()) {
			if(A[r[i].b]-A[r[i].a] == r[i].c)
				cans += r[i].d;
		}
		ans = max(ans, cans);
		return;
	}
	for(int k = last; k <= m; k++) {
		A[curr] = k;
		go(curr+1, k, r);
	}
}

void solve(istream& cin, ostream& cout) {
	cin >> n>>m>>q;
	vector<req> R(q);
	REP(i, q) {
		cin >>R[i].a>>R[i].b>>R[i].c>>R[i].d;
		R[i].a--;R[i].b--;
	}
	go(0, 1, R);
	cout <<ans<<endl;
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


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

int top, N[1000];

void push(int x)
{
  top++;
  N[top] = x;
}

int pop()
{
  top--;
  return N[top+1];
}

int main()
{

  char n[100];
  int a, b, top=0;

  while(scanf("%s", n) != EOF){
    if(n[0] == '+'){
      a = pop();
      b = pop();
      push(a+b);
    }
    else if(n[0] == '-'){
      a = pop();
      b = pop();
      push(b-a);
    }
    else if(n[0] == '*'){
      a = pop();
      b = pop();
      push(a*b);
    }
    else push(atoi(n));
  }
  printf("%d\n", pop());

  return 0;
}

Measured memory_bytes: 552
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=2e5+10;
const int mod=1e9+7;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n,x,y,c[N],w[N],st[N],mn[N],pre[N],suf[N],top=0;
vector<int> E[N],adj[N];
bool vis[N];
void dfs(int u) {
    vis[u]=1;st[++top]=c[u];
    for(int v:E[u]) if(!vis[v]) dfs(v);
}
bool cmp(int a,int b) {
    return w[a]<w[b];
}
int fac[N],inv[N],ifac[N];
void adde(int u,int v) {
    //cerr<<u<<" "<<v<<endl;
    E[u].pb(v),E[v].pb(u);
}
set<pii> s;
int main() {
    cin>>n>>x>>y;
    for(int i=1;i<=n;i++) c[i]=gi(),w[i]=gi(),adj[c[i]].pb(i);
    for(int i=1;i<=n;i++) sort(adj[i].begin(),adj[i].end(),cmp);
    for(int i=1;i<=n;i++)
        if(!adj[i].empty()) mn[i]=w[adj[i][0]];
        else mn[i]=inf;
    pre[0]=inf;for(int i=1;i<=n;i++) pre[i]=min(pre[i-1],mn[i]);
    suf[n+1]=inf;for(int i=n;i;i--) suf[i]=min(suf[i+1],mn[i]);
    for(int i=1;i<=n;i++) {
        int j=0;
        while(j+1<int(adj[i].size())&&(w[adj[i][0]]+w[adj[i][j+1]]<=x||min(pre[i-1],suf[i+1])+w[adj[i][j+1]]<=y)) j++;
        for(int k=0;k<j;k++) adde(adj[i][k],adj[i][k+1]);
    }
    for(int i=1;i<=n;i++) if(mn[i]!=inf) s.insert(mp(mn[i],i));
    for(int i=1;i<=n;i++)
        if(mn[i]!=inf) {
            set<pii>::iterator it;
            if(mn[i]+mn[i]<=y) it=s.lower_bound(mp(mn[i],i));
            else it=s.lower_bound(mp(y-mn[i],inf));
            if(it!=s.begin()) --it,adde(adj[i][0],adj[it->se][0]);
        }
    fac[0]=1;for(int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
    inv[1]=1;for(int i=2;i<=n;i++) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
    ifac[0]=1;for(int i=1;i<=n;i++) ifac[i]=1ll*ifac[i-1]*inv[i]%mod;
    int ans=1;
    for(int i=1;i<=n;i++)
        if(!vis[i]) {
            top=0;dfs(i);sort(st+1,st+top+1);ans=1ll*ans*fac[top]%mod;
            for(int j=1,k=1;j<=top;j=k+1) {
                while(k<top&&st[j]==st[k+1]) k++;
                ans=1ll*ans*ifac[k-j+1]%mod;
            }
        }
    printf("%d\n",ans);
    return 0;
}


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

typedef long long ll;

const int MAX_N = 5e5;

int bit[MAX_N + 1], n;

int sum(int i) {
    int s = 0;
    while (i > 0) {
        s += bit[i];
        i -= i & -i;
    }
    return s;
}

void add(int i, int x) {
    while (i <= n) {
        bit[i] += x;
        i += i & -i;
        //cout << i << " ";
    }
    //cout << endl;
}

int main() {
    int Q;
    cin >> n >> Q;
    vector<int> c(n), b(n, -1), l(Q), r(Q);
    vector<vector<int>> ls(n);
    map<pair<int, int>, int> ans;
    rep(i, n) {
        cin >> c[i];
        c[i]--;
    }
    rep(i, Q) {
        cin >> l[i] >> r[i];
        l[i]--;
        r[i]--;
        ls[r[i]].push_back(l[i]);
    }
    rep(i, n) {
        add(i + 1, 1);
        if (b[c[i]] > -1) add(b[c[i]] + 1, -1);
        b[c[i]] = i;
        rep(j, ls[i].size()) {
            ans[make_pair(ls[i][j], i)] = sum(i + 1) - sum(ls[i][j]);
        }
    }
    rep(i, Q) {
        cout << ans[make_pair(l[i], r[i])] << "\n";
    }
}

Measured memory_bytes: 65572
X = []
Y = []
L = []
N = int(input())
for i in range(N):
   x, y, l = map(int, input().split())
   X.append(x)
   Y.append(y)
   L.append(l)
maxL = max(L)
for cx in range(0, 101):
    for cy in range(0, 101):
        for h in range(maxL, maxL+101):
            flag = True
            for i, l in enumerate(L):
                if l != max(h - abs(X[i] - cx) - abs(Y[i] -cy), 0):
                    flag = False
                    break
            if flag:
                print(cx, cy, h)
                exit()

Measured memory_bytes: 46828
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    int ans = 0;
    sort(ALL(v));
    rep(i,n-2){
        REP(j,i+1,n-1){
            int num = v[i]+v[j];
            auto Iter = lower_bound(ALL(v),num);
            ans += max(0,(int)(Iter-v.begin())-(j+1));
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# Date [ 2020-09-26 21:00:13 ]
# Problem [ a.py ]
# Author Koki_tkg

import sys

def read_str(): return sys.stdin.readline().strip()
def read_int(): return int(sys.stdin.readline().strip())
def read_ints(): return map(int, sys.stdin.readline().strip().split())
def read_str_split(): return list(sys.stdin.readline().strip())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))

def Main():
    k = read_int()
    print('ACL' * k)

if __name__ == '__main__':
    Main()


Measured memory_bytes: 9168
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

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

		while (true) {
			final int n = sc.nextInt();
			final int m = sc.nextInt();
			
			if(n == 0 && m == 0){
				break;
			}
			
			boolean[][] is_friend = new boolean[n][n];
			
			for(int i = 0; i < m; i++){
				int one = sc.nextInt() - 1;
				int two = sc.nextInt() - 1;
				
				is_friend[one][two] = is_friend[two][one] = true;
			}
			
			boolean[] one_visited = new boolean[n];
			boolean[] two_visited = new boolean[n];
			
			for(int i = 1; i < n; i++){
				if(!one_visited[i] && is_friend[0][i]){
					one_visited[i] = true;
					two_visited[i] = true;
				}
			}
			
			for(int i = 1; i < n; i++){
				if(one_visited[i]){
					for(int j = 1; j < n; j++){
						if(!two_visited[j] && is_friend[i][j]){
							two_visited[j] = true;
						}
					}
				}
			}
			
			int count = 0;
			for(boolean b : two_visited){
				if(b){
					count++;
				}
			}
			
			System.out.println(count);
		}
	}

}

Measured memory_bytes: 13000
// Problem : D - Chat in a Circle
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
    int f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

inline LL gl()
{
    LL f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

const int INF = 0x3f3f3f3f, N = 200003, M = N << 1;

int n, m;
int a[N];

int main()
{
    //File("");
    n = gi();
    for (int i = 1; i <= n; i+=1) a[i] = gi();
    sort(a + 1, a + 1 + n); reverse(a + 1, a + 1 + n);
    LL ans = a[1], cnt = 2;
    for (int i = 2; i <= n; i+=1)
    {
    	if (cnt < n) ans += a[i], ++cnt;
    	if (cnt < n) ans += a[i], ++cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4364
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int a; cin >> a;
	cout << a + a * a + a * a * a << "\n";
	
	return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=5e3+50;
const int mod=1e9+7;
int n;
bool judge(string s){
    string x;
    for(int i=s.size()-1;i>=0;i--){
        x+=s[i];
    }
    if(x==s)
        return true;
    return false;
}
bool check(string s){
    string a,b;
    for(int i=0;i<(s.size()-1)/2;i++){
        a+=s[i];
    }
    for(int i=(s.size()+3)/2-1;i<s.size();i++){
        b+=s[i];
    }
    if(judge(s)&&judge(a)&&judge(b))
        return true;
    return false;
}
int main()
{
    string s;
    cin>>s;
    if(check(s))
        cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[100000];
  rep(i,n) cin>>a[i];
  if(a[0]!=0){cout<<0<<endl;return 0;}
  sort(a,a+n);
  if(a[1]==0){cout<<0<<endl;return 0;}
  int now=1,cnt=0,prev=1;
  int ans=1;
  repi(i,1,n){
    //cout<<cnt<<endl;
    if(a[i]==now) cnt++;
    else{
      if(a[i]!=(now+1)){cout<<0<<endl;return 0;}
      else{
	//	cout<<"?"<<endl;
	rep(j,cnt){
	  ans*=prev;
	  ans%=998244353;
	}
      }
      prev=cnt;
      cnt=1;
      now++;
    }
  }
  rep(j,cnt){
    // cout<<ans<<endl;
    ans*=prev;
    ans%=998244353;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
// clang-format on

int n;
int dp[MAX_N + 1], h[MAX_N + 1];

void solve()
{
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for (int i = 2; i < n; i++) {
    dp[i] =
        min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]));
  }
  cout << dp[n - 1] << endl;
}

int main(void)
{
  cin >> n;
  REP(i, n) cin >> h[i];
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define debug 1

int main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	string s;
	cin>>s;
	long l=s.length();
	for(long i=0;i<l;++i)
		printf("x");
	return 0;
}


Measured memory_bytes: 256