akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
int e[111][111],d[111];
int used[111];
signed main(){
  int n;
  cin>>n;
  int INF=1LL<<55LL;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      e[i][j]=INF;
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      e[u][v]=min(e[u][v],c);
    }
  }
  memset(used,0,sizeof(used));
  for(int i=0;i<n;i++) d[i]=INF;
  d[0]=0;
  while(1){
    int u=-1;
    for(int i=0;i<n;i++){
      if(used[i]) continue;
      if(d[i]==INF) continue;
      if(u<0||d[i]<d[u]) u=i;
    }
    if(u<0) break;
    used[u]=1;
    for(int i=0;i<n;i++){
      d[i]=min(d[i],d[u]+e[u][i]);
    }
  }
  for(int i=0;i<n;i++) cout<<i<<" "<<d[i]<<endl;
  return 0;
}

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

int a[8];
bool flag[8];
double ans = 0;
double m;
double x[8], y[8];
int N;

int fact(int n) {
    if (n == 1) return 1;
    return n * fact(n - 1);
}

double norm(double x1, double y1, double x2, double y2) {
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

void perm(int n) {
    if (n == N) {
        for (int i = 0; i < N - 1; i++) {
            ans += norm(x[a[i]], y[a[i]], x[a[i + 1]], y[a[i + 1]]) / m;
        }
        return;
    }
    for (int i = 0; i < N; i++) {
        if (flag[i]) continue;
        a[n] = i;
        flag[i] = true;
        perm(n + 1);
        flag[i] = false;
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
        flag[i] = false;
    }
    m = fact(N);
    perm(0);
    printf("%0.9f\n", ans);
    return 0;
}

Measured memory_bytes: 256
import sys


def input() -> str:
    return sys.stdin.readline().rstrip("\r\n")


def main():
    def min_dest(a, b):
        return min(b-a, abs(x-a)+1+abs(y-b))

    n, x, y = map(int, input().split())
    x, y = x-1, y-1
    ans = [0] * (n-1)

    for i in range(n):
        for j in range(i+1, n):
            ans[min_dest(i, j)-1] += 1
    for a in ans:
        print(a)


if __name__ == "__main__":

    main()


Measured memory_bytes: 3444
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def main():
    N, M = map(int, input().split())
    S = input()
    T = input()

    L = lcm(N, M)
    ln = L//N
    lm = L//M
    n = {1+i*ln: s for i, s in enumerate(S)}
    m = {1+i*lm: t for i, t in enumerate(T)}
    
    for k in set(n.keys()).intersection(set(m.keys())):
        if n[k] != m[k]:
            return -1

    return L

print(main())

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

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) xの絶対値

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

main(){
    int ans=0,n=in(),l,r;
    for (int i=0;i<n;i++){
    cin >> l >> r;
    ans+=(r-l+1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
bool dp[81][81][12801]={0};
int main(){
    int h,w,A[80][80],B[80][80];
    cin>>h>>w;
    rep(i,h)rep(j,w) cin>>A[i][j];
    rep(i,h)rep(j,w) cin>>B[i][j];
    rep(i,h)rep(j,w){
        if(!i&&!j){
            dp[i][j][6400+A[i][j]-B[i][j]]=1;
            dp[i][j][6400-A[i][j]+B[i][j]]=1;
        }
        if(i){
            rep(k,12801)if(dp[i-1][j][k]){
                if(abs(k+A[i][j]-B[i][j]-6400)<=6400) dp[i][j][k+A[i][j]-B[i][j]]=1;
                if(abs(k-A[i][j]+B[i][j]-6400)<=6400) dp[i][j][k-A[i][j]+B[i][j]]=1;
            }
        }
        if(j){
            rep(k,12801)if(dp[i][j-1][k]){
                if(abs(k+A[i][j]-B[i][j]-6400)<=6400) dp[i][j][k+A[i][j]-B[i][j]]=1;
                if(abs(k-A[i][j]+B[i][j]-6400)<=6400) dp[i][j][k-A[i][j]+B[i][j]]=1;
            }
        }
    }
    int ans=6400;
    rep(i,12801) if(dp[h-1][w-1][i]) ans=min(ans,abs(i-6400));
    cout<<ans<<"\n";
}


Measured memory_bytes: 81664
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!

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

    string to_string(const string& s) { return '"' + s + '"'; }
    void debug_out() { cout << endl; }
    template <typename Head, typename... Tail>
    void debug_out(Head H, Tail... T) { cout << " " << to_string(H); debug_out(T...); }
    #ifdef LOCAL
        #define debug(...) cout << "#" << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
    #else
        #define debug(...) 3;
    #endif

    #define fast_io ios_base::sync_with_stdio(false); \
                    cin.tie(nullptr); cout.tie(nullptr);
    using ld = long double;  using ui = uint_fast32_t;
    using ll = int_fast64_t; using ul = uint_fast64_t;

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

const int N = 1e5 + 5;
int n, a[N];

void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    int cn = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[a[i]] == i) ++cn;
    }
    cout << cn / 2 << '\n';
}

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

int main() {
    fast_io; int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; ++i) solve();
}

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

using namespace std;

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

  int H,W,A,B; cin>>H>>W>>A>>B;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if ((i < B and j < A) or (i >= B and j >= A)) {
        cout << 1;
      } else {
        cout << 0;
      }
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);    
    long long a,b,k;
    cin>>a>>b>>k;
    if(a-k<0){
        cout<<0;
        cout<<" ";
        if(b+a-k<0){
            cout<<0;
            return 0;
        }
        cout<< b+a-k;
        return 0;
    }
    cout<<a-k<<" "<<b;
}

Measured memory_bytes: 256
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.09.07 16:03:58
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

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

int main() {
    vector<P> vec;
    int n, a;
    scanf("%d", &n);
    rep(i, n) {
        scanf("%d", &a);
        vec.pb(mp(i, a));
    }

    sort(vec.begin(), vec.end(), [](const P a, const P b) {
        if (a.sc != b.sc)
            return a.sc > b.sc;
        else
            return a.fr > b.fr;
    });

    int mi, ma, si, sa;
    mi = vec[0].fr;
    ma = vec[0].sc;
    si = vec[1].fr;
    sa = vec[1].sc;

    rep(i, n) {
        if (i == mi) {
            printf("%d\n", sa);
        } else {
            printf("%d\n", ma);
        }
    }

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 3312
#include <fstream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <bitset>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <set>
#include <complex>
#include <cstring>

using namespace std;

const int SIZE = 1 << 10;

int pointer = SIZE;
char buffer[SIZE];

char Advance() {
    if (pointer == SIZE) {
        fread(buffer, 1, SIZE, stdin);
        pointer = 0;
    }
    return buffer[pointer++];
}

int Read() {
    int answer = 0;
    char ch = Advance();
    while (!isdigit(ch))
        ch = Advance();
    while (isdigit(ch)) {
        answer = answer * 10 + ch - '0';
        ch = Advance();
    }
    return answer;
}

const int MAXN = 8000;

char s[1 + MAXN + 1], sum[1 + MAXN];
bool dp[2][1 + 2 * MAXN];
vector<int> here[2];

int line[4] = {1, 0, -1, 0};
int column[4] = {0, 1, 0, -1};

bool Ok(int p, int need, int start) {
    memset(dp, false, sizeof(dp));
    int now = 0, before = 1;
    dp[now][start + MAXN] = true;
    for (auto &it : here[p]) {
        swap(now, before);
        memset(dp[now], false, sizeof(dp[now]));
        for (int i = 0; i <= 2 * MAXN; i++) {
            if (i + it >= 0 && i + it <= 2 * MAXN && dp[before][i])
                dp[now][i + it] = true;
            if (i - it >= 0 && i - it <= 2 * MAXN && dp[before][i])
                dp[now][i - it] = true;
        }
    }
    return dp[now][need + MAXN];
}

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    int x, y;
    scanf("%s%d%d", s + 1, &x, &y);
    int n = strlen(s + 1), l = 0, which = 0, start = 0;
    n++;
    s[n] = 'T';
    bool first = true;
    for (int i = 1; i <= n; i++) {
        if (s[i] == 'F')
            l++;
        else {
            if (first) {
                start = l;
                first = false;
            }
            else
                if (l)
                    here[which].push_back(l);
            which ^= 1;
            l = 0;
        }
    }
    if (Ok(0, x, start) && Ok(1, y, 0))
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	int N, K; cin >> N >> K;
	vector<int> x(N);
	REP(i,N) cin >> x[i];

	int l = 0;
	int r = K-1;

	int ans = 1 << 30;
	REP(i,N-K+1){

		ans = min(ans, abs(x[r]-x[l])+abs(x[l]));
		ans = min(ans, abs(x[r]-x[l])+abs(x[r]));

		l++;
		r++;
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b;
    cin >> a >> b;
    string s = "";
    if (a <= b) {
        REP(i, 0, b) {
            s += to_string(a);
        }
    } else {
        REP(i, 0, a) {
            s += to_string(b);
        }
    }
    cout << s << endl;
}


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

int main(){
    int x,y,w,h,r;
    cin >> w >> h >> x >> y >> r;
    
    if((x<=w-r)&&(x>=r)&&(y<=h-r)&&(y>=r )) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 3096
using System;
using System.Collections.Generic;

class Program {
    static void Main (string[] args) {
        string[] input1 = Console.ReadLine ().Split (' ');
        int T_HP = int.Parse (input1[0]);
        int T_AT = int.Parse (input1[1]);
        int A_HP = int.Parse (input1[2]);
        int A_AT = int.Parse (input1[3]);

        while (T_HP > 0 && A_HP > 0) {
            A_HP -= T_AT;
            if (A_HP > 0) {
                T_HP -= A_AT;
            }
        }

        if (T_HP <= 0) {
            Console.WriteLine ("No");
        } else {
            Console.WriteLine ("Yes");
        }

    }
}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;



using Matrix = vector<vector<number>>;

void warshall_floyd(int V, Matrix &g) {
    rep(k, V) {
        rep(i, V) {
            rep(j, V) {
                if (g[i][k] == INF || g[k][j] == INF) continue;
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
}



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


    Matrix G(10, vll(10));
    rep(i,10){
        rep(j,10) cin >> G[i][j];
    }

    warshall_floyd(10, G);

    ll ans = 0;

    int a;

    rep(i,H){
        rep(j,W){
            cin >> a;
            if(a == -1) continue;
            ans += G[a][1];
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
N = int(input())
A = [int(input()) for i in range(N)]
ans = 0
for i in range(N):
    tmp = A[i]
    ans += (tmp // 2)
    if i < N -1 and tmp % 2 and A[i + 1] > 0:
        ans += 1
        A[i + 1] -= 1
print(ans)

Measured memory_bytes: 12908
#include "bits/stdc++.h"

using namespace std;

template <typename T>
struct BIT
{
	int N;
	vector<T> bit;

	BIT(int X)
	{
		bit = vector<T>(X+1, 0);
		N = X+1;
	}

	void chmax(int idx, T w)
	{
		for (int x = idx; x <= N; x += x & -x)
		{
			bit[x] = max(bit[x], w);
		}
	}

	T getmax(int idx)
	{
		T res = 0;
		for (int x = idx; x > 0; x -= x & -x) res = max(res, bit[x]);
		return res;
	}
};

void solve()
{
	int N;
	cin >> N;
	vector<long> hs(N);
	BIT<long> bit(N);
	for (int i = 0; i < N; i++) cin >> hs[i];
	long ans = 0;
	for (int i = 0; i < N; i++)
	{
		long a, res;
		cin >> a;
		res = a+bit.getmax(hs[i]-1);
		ans = max(ans, res);
		bit.chmax(hs[i], res);
	}
	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>

int main(){
  int num_g,num_p;
  num_g = 0;
  num_p = 0;
  int ret;
  char s;
  while(1){
    ret = scanf("%c",&s);
    if(s == '\n' || ret == EOF) break;
    if(s == 'g') num_g++;
    else if(s == 'p') num_p++;
  }
  int answer = (num_g - num_p) / 2;
  printf("%d\n", answer);
  return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;

namespace Contest
{
    class Program
    {
        public void Solve()
        {
            var sc = new Scanner();
            string S = sc.Next();
            int a = 0;
            int b = 0;
            int c = 0;
            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] == 'a') a++;
                else if (S[i] == 'b') b++;
                else if (S[i] == 'c') c++;
            }
            int max = new int[] { a, b, c }.Max();
            int min = new int[] { a, b, c }.Min();
            if (max - min <= 1)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }

        static void Main(string[] args) => new Program().Solve();
    }

    class Scanner
    {
        private char _separator = ' ';
        private StreamReader _stream = new StreamReader(Console.OpenStandardInput());
        private int _pos = 0;
        private string[] _line = new string[0];
        public string Next()
        {
            if (_pos >= _line.Length)
            {
                _line = _stream.ReadLine().Split(_separator);
                _pos = 0;
            }
            return _line[_pos++];
        }
        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public string[] Array()
        {
            if (_pos >= _line.Length)
                _line = _stream.ReadLine().Split(_separator);
            _pos = _line.Length;
            return _line;
        }
        public int[] IntArray()
        {
            var arr = Array();
            var res = new int[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                res[i] = int.Parse(arr[i]);
            }
            return res;
        }
        public long[] LongArray()
        {
            var arr = Array();
            var res = new long[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                res[i] = long.Parse(arr[i]);
            }
            return res;
        }
        public double[] DoubleArray()
        {
            var arr = Array();
            var res = new double[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                res[i] = double.Parse(arr[i]);
            }
            return res;
        }
    }
}


Measured memory_bytes: 13792
import sys

x1, y1, x2, y2 = map(int, sys.stdin.readline().split())

def main():
    x3 = x2 + (y1 - y2)
    y3 = y2 - (x1 - x2)
    x4 = x1 + (y1 - y2)
    y4 = y1 - (x1 - x2)
    return x3, y3, x4, y4

if __name__ == '__main__':
    ans = main()
    print(*ans, sep=' ')

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

int main(){
    int r;
    cin >> r;
    r*=2;

    double ans = r*3.14159265358979;

    printf("%.9f\n", ans);

    return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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

int dp[2222222];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<int>> a(N,vector<int>(N));
    REP(i,N) REP(j,N) cin >> a[i][j];
    dp[0] = 1;
    for(int S=1;S<(1<<N);++S){
        int i = __builtin_popcount(S);
        REP(j,N) if(1 & (S >> j) && a[i-1][j] == 1) dp[S] = (dp[S] + dp[S^(1 << j)]) % MOD;
    }
    ll ans = dp[(1<<N)-1];
    cout << ans << endl;
}


Measured memory_bytes: 8448
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n, x, y int
	fmt.Scan(&n)
	xy := make([][]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x, &y)
		xy[i] = make([]int, 2)
		xy[i][0] = x
		xy[i][1] = y
	}
	c := make(map[string]int)
	var m int
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i != j {
				c[strconv.Itoa(xy[i][0]-xy[j][0])+","+strconv.Itoa(xy[i][1]-xy[j][1])]++
				if m < c[strconv.Itoa(xy[i][0]-xy[j][0])+","+strconv.Itoa(xy[i][1]-xy[j][1])] {
					m = c[strconv.Itoa(xy[i][0]-xy[j][0])+","+strconv.Itoa(xy[i][1]-xy[j][1])]
				}
		  }
		}
	}
	fmt.Println(n - m)
}


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

int main()
{
  int N, M, Q;
  cin >> N >> M >> Q;
  int L, R, p, q;
  vector<vector<int>> start(N + 1, vector<int>(0));
  vector<vector<int>> end(N + 1, vector<int>(0));
  vector<vector<int>> dp(N + 1, vector<int>(N + 1, 0));
  for (int i = 0; i < M; ++i)
  {
    cin >> L >> R;
    start.at(L - 1).push_back(R - 1);
    end.at(R - 1).push_back(L - 1);
    if (L == 1 && R == 1)
    {
      dp.at(0).at(0) += 1;
    }
  }

  for (int i = 0; i < N; ++i)
  {
    for (int j = i; j < N; ++j)
    {
      // cout << "i" << i << j;
      int dec = 0, inc = 0;
      for (int k = 0; k < start.at(i).size(); ++k)
      {
        if (start.at(i).at(k) <= j)
        {
          dec += 1;
        }
      }
      for (int k = 0; k < end.at(j + 1).size(); ++k)
      {
        if (end.at(j + 1).at(k) >= i)
        {
          inc += 1;
        }
      }
      dp.at(i + 1).at(j) = max(0, dp.at(i).at(j) - dec);
      dp.at(i).at(j + 1) = max(0, dp.at(i).at(j) + inc);
      // cout << "inc" << inc << dec << endl;
    }
  }
  for (int i = 0; i < Q; ++i)
  {
    cin >> p >> q;
    cout << dp.at(p - 1).at(q - 1) << endl;
  }
  // for (int i = 0; i < N; ++i)
  // {
  //   for (int j = 0; j < N; ++j)
  //   {
  //     cout << dp.at(i).at(j);
  //   }
  //   cout << endl;
  // }
}


Measured memory_bytes: 4480
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

//static const long long MOD = 1000000007;

int main() {
    long long K, X;

    // input
    cin >> K >> X;

    // process
    for (long long i = 0; i < K; i++) {
        if (X - (K - i - 1) >= -1000000) {
            cout << X - (K - i - 1);
            cout << " ";
        }
    }
    for (long long i = 1; i < K; i++) {
        if (X + i >= -1000000) {
            cout << X + i;
            cout << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 256
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n+1) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
constexpr int MOD = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
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;}

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

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

    int n;
    int sum = 0,res = 0;
    cin >> n;
    vector<int> t(n);
    vector<string> s(n);

    rep(i,n){
        cin >> s[i] >> t[i];
        sum += t[i];
    }
    string x;
    cin >> x;

    rep(i,n){
        res += t[i];
        if(x == s[i]) break;
    }

    cout << sum - res << '\n';

    return 0;
}


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

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

    ll temp_n = n;
    vector <ll> monster, hero;
    n += 1;
    while (n--){
        ll no;
        cin >> no;
        monster.push_back(no);
    }

    while (temp_n--){
        ll no;
        cin >> no;
        hero.push_back(no);
    }

    ll count=0;
    for (ll i=0; i<hero.size(); i++){
        ll Min = min (hero[i], monster[i]);
        if ( hero[i] == Min){
            hero[i] -= Min;
            monster[i] -= Min;
            count += Min;
        }
        else {
            count += Min;
            hero[i] -= Min;
            monster[i] -= Min;
            if ( monster[i+1] - hero[i] >= 0){
                count += hero[i];
                monster[i+1] -= hero[i];
            }
            
            else {
                count += monster[i+1];
                monster[i+1] = 0;
            }
        }
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 2548
#include "bits/stdc++.h"
#include <set>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int n, m;
	cin >> n >> m;
	vector<int>h(n);
	vector<bool>good(n, true);

	rep(i, n) {
		cin >> h[i];
	}
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		if (h[a] >= h[b])good[b] = false;
		if (h[b] >= h[a])good[a] = false;
	}
	int ans = 0;
	rep(i, n) {
		if (good[i])ans++;
	}
	print(ans);
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P, P> PP;
constexpr ll MOD = ll(1e9 + 7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int V, E, root;
    cin >> V >> E >> root;
    vector<vector<P> > g(V);
    for(int i=0;i<E;i++){
        ll s, t, d;
        cin >> s >> t >> d;
        g[s].push_back({t, d});
    }
    vector<ll> dist(V, IINF);
    vector<bool> visited(V, false);
    dist[root] = 0;
    visited[root] = true;
    int cnt = 0;
    bool update = true, neg = false;
    while(update){
        update = false;
        for(int i=0;i<V;i++){
            for(auto e : g[i]){
                ll u = e.first, d = e.second;
                if(dist[u] > dist[i] + d){
                    if(visited[i]){
                        visited[u] = true;
                        dist[u] = dist[i] + d;
                        update = true;
                    }
                }
            }
        }
        cnt++;
        if(cnt > V && update){
            neg = true;
            break;
        }
    }
    if(neg){
        cout << "NEGATIVE CYCLE" << endl;
    }
    else{
        for(int i=0;i<V;i++){
            if(visited[i]){
                cout << dist[i] << endl;
            }
            else{
                cout << "INF" << endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3120
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
const int mm=1e6;
ll d[mm];
int main()
{
	int i,n,m,s,l;
	cin>>n;
	 s=0;
	for(i=0;i<n;i++)
	{
		cin>>d[i];
		if(d[i]%2==0)
		{
			if(d[i]%3!=0&&d[i]%5!=0)
			s=1;
		}
	}
	if(s)
	printf("DENIED\n");
	else
	printf("APPROVED\n");






}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() { cin.tie(nullptr); ios_base::sync_with_stdio(false); }
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

int N, M;
vector<int> G[100100];
int dp[1000100];

int slv(int u)
{
  int &ret = dp[u];
  if(~ret) { return ret; }
  ret = 0;
  for (int nxt : G[u]) {
    chmax(ret, slv(nxt) + 1);
  }
  return ret;
}

signed main()
{
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int s, t;
    cin >> s >> t;
    --s, --t;
    G[s].push_back(t);
  }

  memset(dp, -1, sizeof(dp));
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    chmax(ans, slv(i));
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl;
#define mod 1000000007
#define pb push_back
#define endl '\n'



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

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

}

Measured memory_bytes: 256
s = input()

if s == 'SAT':
    print(1)
elif s == 'FRI':
    print(2)
elif s == 'THU':
    print(3)
elif s == 'WED':
    print(4)
elif s == 'TUE':
    print(5)
elif s == 'MON':
    print(6)
elif s == 'SUN':
    print(7)

Measured memory_bytes: 38384
//
// Created by 李青坪 on 2018/11/24.
//

#include <cstdio>
#include <vector>
#include <algorithm>
#define MAXN 100000
using namespace std;

struct Node{
    int id;
    int w;
};

int n;
int d[MAXN];
bool visited[MAXN];
vector<Node> graph[MAXN];

void getFarestX(int cur){
    visited[cur] = true;
    vector<Node>::iterator it;
    for (it = graph[cur].begin(); it != graph[cur].end(); ++it){
        if (!visited[(*it).id]){
            d[(*it).id] = d[cur] + (*it).w;
            getFarestX((*it).id);
        }
    }
}

pair<int, int> getDiameter(int cur){
    fill(visited, visited+n, false);
    d[cur] = 0;
    getFarestX(cur);
    int maxX = d[0];
    int maxXIndex = 0;
    for (int i = 1; i < n; ++i) {
        if (d[i] > maxX){
            maxX = d[i];
            maxXIndex = i;
        }
    }
    return make_pair(maxX, maxXIndex);
}

int main(){
    scanf("%d", &n);
    int s, t, w;
    Node node;
    for (int i = 0; i < n-1; ++i) {
        scanf("%d %d %d", &s, &t, &w);
        node.id = t;
        node.w = w;
        graph[s].push_back(node);
        node.id = s;
        node.w = w;
        graph[t].push_back(node);
    }
    pair<int, int > x = getDiameter(0);
    pair<int, int> result = getDiameter(x.second);
    printf("%d\n", result.first);
}
/*
10
0 1 7
0 2 5
0 3 8
1 4 3
1 5 9
3 6 2
3 7 5
7 8 3
7 9 1
 */


Measured memory_bytes: 11828
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

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; }

int main() {
  int a, b;
  cin >> a >> b;
  int ans = a+b;
  chmax(ans, a-b);
  chmax(ans, a*b);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
// データ構造の応用 : 面積計算
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>

using namespace std;

const int MAX_N = 10000;
const int MAX_Q = 500;

int main(void)
{

    int n, q, count = 0;
    int ary_N[MAX_N], ary_Q[MAX_Q];

    scanf("%d", &n);

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

    scanf("%d", &q);

    for(int i = 0; i < q; i++)
    {
        scanf("%d", &ary_Q[i]);
    }

    for(int i = 0; i < q; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if( ary_Q[i] == ary_N[j] )
            {
                count++;
                // 1つ見つかれば処理終了
                break;
            }
        }
    }

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

    return 0;
}



Measured memory_bytes: 3204
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def r_sort(a) a.sort{|a,b|b<=>a} end

n = inp[0]
a = [0]+inp
t = na(n+1,false)
ans = []
((n/2+1)..n).each do |i|
  if(1 == a[i])
    t[i] = true
    ans.push(i)
  end
end
(1..(n/2)).reverse_each do |i|
  d = i*(n/i)
  c = false
  while d > 0
    c ^= t[d]
    if(d != i)
      d -= i
      next
    end
    if(c != (a[i]==1))
      t[i] = true
      ans.push(i)
    end
    d -= i
  end
end
puts ans.size
puts ans.join(" ") if(ans.size > 0)

Measured memory_bytes: 24652
#include <iostream>

using namespace std;
int main()
{
	string s;
	cin >> s;

	char c = s[0];
	if ('A' <= c && c <= 'Z')
	{
		cout << "A" << endl;
	}
	else if ('a' <= c && c <= 'z')
	{
		cout << "a" << endl;
	}
}

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

int main() {
  int n;
  long cnt = 0;
  cin >> n;
  vector<long> an(5,0);
  string name;
  rep(i, n) {
    cin >> name;
    if (name[0] == 'M') an[0]++;
    else if (name[0] == 'A') an[1]++;
    else if (name[0] == 'R') an[2]++;
    else if (name[0] == 'C') an[3]++;
    else if (name[0] == 'H') an[4]++;
  }
  for (int i=0; i<3; i++) {
    for (int j=i+1; j<4; j++) {
      for (int k=j+1; k<5; k++) {
        cnt += an[i] * an[j] * an[k];
      }
    }
  }
  cout << cnt;
}


Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;

void main(){
    while(true){
	auto s = readln();
	if(stdin.eof()) break;
	real w = to!real(chomp(s));

	if(w <= 48.0) writeln("light fly");
	else if(w <= 51.0) writeln("fly");
	else if(w <= 54.0) writeln("bantam");
	else if(w <= 57.0) writeln("feather");
	else if(w <= 60.0) writeln("light");
	else if(w <= 64.0) writeln("light welter");
	else if(w <= 69.0) writeln("welter");
	else if(w <= 75.0) writeln("light middle");
	else if(w <= 81.0) writeln("middle");
	else if(w <= 91.0) writeln("light heavy");
	else writeln("heavy");
    }
}

Measured memory_bytes: 2424
#include <stdio.h>

int main()
{
	int i, N, K, a[101];
	scanf("%d %d", &N, &K);
	for (i = 1; i <= N; i++) scanf("%d", &(a[i]));
	
	int j;
	char dp[200001] = {};
	for (i = 0; i < K; i++) {
		if (dp[i] == 0) for (j = 1; j <= N; j++) dp[i+a[j]] = 1;
	}
	if (dp[K] == 1) printf("First\n");
	else printf("Second\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1856
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <math.h> 
#include <iomanip>
#include <string.h>
#include <vector>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N = 2e5 + 5;

 
int vis[N];


int32_t  main() {

	IOS;

	

	int  n;
	
	cin >> n;

	vector<int>  v(n);

	bool flag = false;
	for (int i = 0; i < n; i++) {

		 
		cin >> v[i];
	
		if (v[i] == 0) {
			flag = true;
		}

	}

	if (flag) {
		cout << "0" << endl;
	}
	else {
		int ans = v[0];
		 
		
		for (int i = 1; i < n; i++) {

			if (v[i] > 1000000000000000000 / ans) {
				ans = -1;
					break;
			 }


			ans *= v[i];
		}

		cout << ans << endl;
		
	}
	 


}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
struct Node{
	int p,l,r;
} T[25];
void preP(int u){
	if(u==-1) return;
	printf(" %d",u);
	preP(T[u].l);
	preP(T[u].r);
}
void inP(int u){
	if(u==-1) return;
	inP(T[u].l);
	printf(" %d",u);
	inP(T[u].r);
}
void postP(int u){
	if(u==-1) return;
	postP(T[u].l);
	postP(T[u].r);
	printf(" %d",u);
}
int main()
{
	int n,l,r,in; 
	cin>>n;
	for(int i=0;i<n;i++) T[i].p = -1;
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&in,&l,&r);
		T[in].l = l;
		T[in].r = r;
		T[l].p = T[r].p = in;
	}
	int root;
	for(int i=0;i<n;i++)
		if(T[i].p==-1) root = i,i=n;
	printf("Preorder\n");
	preP(root);
	printf("\nInorder\n");
	inP(root);
	printf("\nPostorder\n");
	postP(root);
	cout<<endl;
	return 0;
}



Measured memory_bytes: 3228
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         UNIQUE(v)                   v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;
//int dx[]={0,0,1,-1,1,1,-1,-1};
//int dy[]={1,-1,0,0,1,-1,1,-1};

#define lim 500000+5

int col[lim],k=550,cnt[lim],sum=0,ans[lim];

struct node{
    int l,r,ind;
}q[lim];

bool comp( const node a , const node b ){
	ll tmp = a.l / k;
    if(tmp != b.l / k)
        return a.l < b.l;
    if(tmp & 1)
        return a.r < b.r;
    return a.r > b.r;
}


void add(int pos){
    cnt[col[pos]]++;
    if(cnt[col[pos]]==1) sum++;
}

void remove(int pos){
    if(cnt[col[pos]]==1) sum--;
    cnt[col[pos]]--;
}

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout); 
    int n,Q;
    sf(n),sf(Q);
    for(int i=0;i<n;i++){
        sf(col[i]);
    }  
    for(int i=0;i<Q;i++){
        sf(q[i].l);
        sf(q[i].r);
        q[i].l--,q[i].r--;
        q[i].ind = i;
    }
    sort(q,q+Q,comp);
    int l=0,r=-1;
    for(int i=0;i<Q;i++){
        while ( l > q[i].l ) add( --l );
		while ( r < q[i].r ) add( ++r );
		while ( l < q[i].l ) remove( l++ );
		while ( r > q[i].r ) remove( r-- );
		ans[q[i].ind] = sum;
    }
    for(int i=0;i<Q;i++){
        pf(ans[i]);
    }
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    int s[13]={0},h[13]={0},c[13]={0},d[13]={0};
    for(int i=0; i<n; ++i){
        char a; int b;
        cin>>a>>b;
        b--;
        if(a=='S')s[b]++;
        if(a=='H')h[b]++;
        if(a=='C')c[b]++;
        if(a=='D')d[b]++;
    }
    for(int i=0; i<13; ++i){
        if(s[i]==0)cout<<"S "<<i+1<<endl;
    }
    for(int i=0; i<13; ++i){
        if(h[i]==0)cout<<"H "<<i+1<<endl;
    }
    for(int i=0; i<13; ++i){
        if(c[i]==0)cout<<"C "<<i+1<<endl;
    }
    for(int i=0; i<13; ++i){
        if(d[i]==0)cout<<"D "<<i+1<<endl;
    }
    return 0;
}


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

int main(){
  ll a,b; cin>>a>>b;
  if(a*b<=0) cout<<"Zero"<<endl;
  else if(a>0) cout<<"Positive"<<endl;
  else{
    if((b-a-1)%2) cout<<"Negative"<<endl;
    else cout<<"Positive"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  string tmp[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string S; cin>>S;
  for(int i=0;i<7;i++){
    if(tmp[i] == S){
      cout<<7-i<<endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
#include <ctime>
#include <bitset>
using namespace std;
#define pb push_back
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define ansn() printf("%d\n",ans)
#define lansn() printf("%lld\n",ans)
#define r0(i,n) for(int i=0;i<(n);++i)
#define r1(i,e) for(int i=1;i<=e;++i)
#define rn(i,e) for(int i=e;i>=1;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define lowbit(a) (a&(-a))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pll pair<long long,long long>
#define mp(aa,bb) make_pair(aa,bb)
#define lrt rt<<1
#define rrt rt<<1|1
#define X first
#define Y second
#define PI (acos(-1.0))
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007 ;
const double eps=1e-9;
const int inf=0x3f3f3f3f;
//const ll infl = 10000000000000000;
const int maxn=  1e6+10;
const int maxm = 2e5+10;
//Pretests passed
int in(int &ret)
{
    char c;
    int sgn ;
    if(c=getchar(),c==EOF)return -1;
    while(c!='-'&&(c<'0'||c>'9'))c=getchar();
    sgn = (c=='-')?-1:1;
    ret = (c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9')ret = ret*10+(c-'0');
    ret *=sgn;
    return 1;
}

int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL
    int n;
    sd(n);
    int tt = 0, xx = 0,yy = 0;
    bool ok = 1;
    while(n--)
    {
        int t,x,y;
        sddd(t,x,y);
        int tmp = t - tt;
        int ab = abs(xx-x) + abs(yy-y);
        if(ab>tmp)ok = 0;
        if((ab%2)!=(tmp%2))ok = 0;
        if(!ok)break;
    }
    puts(ok?"Yes":"No");
    return 0;

}


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

int main() {
	vector<string> hand(3);
	for(int i = 0; i < 3; i++) cin >> hand.at(i);

	int turn = 0;
	while(true) {
		if(hand.at(turn) == "") break;
		char next = hand.at(turn).at(0);
		hand.at(turn) = hand.at(turn).substr(1, hand.at(turn).size());
		switch(next) {
			case 'a': turn = 0; break;
			case 'b': turn = 1; break;
			case 'c': turn = 2; break;
			default: break;
		}
	}

	switch(turn) {
		case 0: cout << "A" << endl; break;
		case 1: cout << "B" << endl; break;
		case 2: cout << "C" << endl; break;
		default: break;
	}
}

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

int main(){
    string s;
    cin >> s;
    if (s.size()==2){
        if (s.at(0)==s.at(1)){
            cout << 1 << " " << 2 << endl;
        } else {
            cout << -1 << " " << -1 << endl;
        }
        return 0;
    }
    for (int i=0; i<s.size()-2; i++){
        if (s.at(i)==s.at(i+1) || s.at(i+1)==s.at(i+2) || s.at(i+2)==s.at(i)){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}

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

int main ()
{
    int n;
    ll ans=0,m=0;
    cin>>n;
    ll a[n+10];
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=1;i<n;i++)
    {
        if(a[i]>a[m])
            m=i;
        else
            ans+=a[m]-a[i];
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5144