akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
//union by size + path having
class UnionFind{
    public:
    vector<long long> par; // 各元の親を表す配列
    vector<long long> siz; // 素集合のサイズを表す配列(1 で初期化)


    // Constructor
    UnionFind(long long sz_) : par(sz_), siz(sz_,1LL){
        for (long long i = 0; i < sz_; ++i)
        par[i] = i; // 初期では親は自分自身
    }
    void init(long long sz_){
        par.resize(sz_);
        siz.assign(sz_,1LL); // resize だとなぜか初期化されなかった
        for (long long i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    // Member Function


    // Find
    long long root(long long x){ // 根の検索
        while (par[x] != x){
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }
    // 結合(Unite, Merge)
    bool merge(long long x, long long y){
        x = root(x);
        y = root(y);
        if (x == y){
            return false;
        }
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]){
            swap(x, y);
        }
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }


    // 連結判定(つながっているときはture,つながっていなければfalse)
    bool issame(long long x, long long y){ 
        return root(x) == root(y);
    }


    // 素集合のサイズ
    long long size(long long x){ 
        return siz[root(x)];
    }
};
int main(){
    int n,m;
    int ans=0;
    cin >>n>>m;
    vector<pair<int,int>>path(m);
    int a,b;
    rep(i,m){
        cin>>path[i].F>>path[i].S;
        path[i].F--;
        path[i].S--;
    }
    UnionFind dis(n);
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            if(i!=j){
                dis.merge(path[j].F,path[j].S);
               // cout<<".";
            }
        }
        ans+=dis.merge(path[i].F,path[i].S);
       // cout<<ans<<endl;
        dis.init(n);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c;
    cin>>a>>b>>c;
    if(a+b>=c-1) cout<<b+c<<endl;
    else cout<<2*b+a+1<<endl;
}

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

int a[10],b[10],c[10];

void initial()
{
	for(int i=0;i<10;i++)
	{
		b[i]=-1;
        c[i]=-1;
	}
}
bool judge()
{
  int p=0,q=0,i;
  initial();
  b[0]=a[0];
  for(i=1;i<10;i++)
  {
	  if(a[i]>b[p])b[++p]=a[i];
	  else if(q==0)c[q++]=a[i];
	  else if(a[i]>c[q-1])c[q++]=a[i];
	  else 
	  {
		  return false;
		  break;
	  }
  }
  if(i==10)
	  return true;
}

int main()
{
	int num;
	cin>>num;
	while(num--)
	{
		for(int i=0;i<10;i++)
			cin>>a[i];
		puts(judge()?"YES":"NO");
	}
return 0;
}

Measured memory_bytes: 1116
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

ll h, w;
vs s;
string ch = ".#";
vvll dp;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  cin >> h >> w;
  s.resize(h);
  rep(i, h){
    cin >> s[i];
  }
  dp.resize(h, vll(w, INF));
  {
    char pre = '.';
    ll c = 0;
    rep(i, h){
      if(s[i][0] != pre){
        pre = s[i][0];
        c++;
      }
      dp[i][0] = c;
    }
  }
  {
    char pre = '.';
    ll c = 0;
    rep(i, w){
      if(s[0][i] != pre){
        pre = s[0][i];
        c++;
      }
      dp[0][i] = c;
    }
  }
  repr(i, 1, h)repr(j, 1, w){
    if(s[i][j] == s[i-1][j]){
      chmin(dp[i][j], dp[i-1][j]);
    }else{
      chmin(dp[i][j], dp[i-1][j]+1);
    }
    if(s[i][j] == s[i][j-1]){
      chmin(dp[i][j], dp[i][j-1]);
    }else{
      chmin(dp[i][j], dp[i][j-1]+1);
    }
  }
  print((dp[h-1][w-1]+1)/2);
  //print(dp);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

int main(){
   int n,x;
   cin>>n>>x;

   vector<int> a(n);
   rep(i,n){
      cin>>a[i];
      a[i]-=x;
      a[i]=abs(a[i]);
   }
   int ans=a[0];
   rep(i,n){
      ans=gcd(ans,a[i]);
   }
   cout<<ans;

   return 0;
}


Measured memory_bytes: 3788
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,p;
	while(1){
		cin>>n>>p;
		if(n==0 && p==0)break;
		int dt[n];
		int cop=p;
		int counta=0;
		rep(i,n)dt[i]=0;
		int ans;
		while(1){
			counta=counta%n;
			if(cop!=0){
				dt[counta]++;
				cop--;
			}else{
				int judge=0;
				rep(i,n){
					if(i!=counta)if(dt[i]==0)judge++;
				}
				if(judge==n-1){
					ans=counta;
					break;
				}else{
					cop=dt[counta];
					dt[counta]=0;
				}
			}
			counta++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

class Magatro
{

    static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        int Q = int.Parse(s[0]);
        for(int i = 0; i < Q; i++)
        {
            string S = Console.ReadLine();
            Console.WriteLine(S);
            Console.WriteLine(S);
        }
    }
}


Measured memory_bytes: 2776
n,w = map(int,input().split(" "))
pack = []

for _ in range(n):
    x,y = map(int,input().split(" "))
    pack.append([x/y,x,y])

pack.sort()
pp = pack[::-1]

sum = 0
for ele in pp:
    if w-ele[2] > 0:
        sum += ele[1]
        w = w - ele[2]
    else:
        sum += ele[0]*w
        break

print(sum)



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

using namespace std;

bool vis[200009];
int main()
{
   long long  n, k;
   cin >> n >> k;
   
   vector<long long> a(n+1);
   for(int i = 0; i < n; i++) {
       cin >> a[i];
       a[i]--;
   }
   
   vector<long long> path;
   vector<long long> pos(n+1);
   int i = 0;
   while(1) {
       
       if(vis[i] == true) break;
       pos[i] = path.size();
       path.push_back(i);
       vis[i] = true; 
       i = a[i];
   }
   
   long long cyclestart = pos[i];
   long long cyclelen = (int)path.size()-cyclestart;
   
   if(k <= path.size()-1) {
       cout << path[k]+1 << endl;
       return 0;
   }
   
   else {
       
       k -=  cyclestart;
       k %= cyclelen;
       cout << path[cyclestart+k]+1 << endl;
   }
   return 0;
}

Measured memory_bytes: 8696
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(long long N, std::vector<long long> x, std::vector<long long> y) {
  auto X = x;
  auto Y = y;
  rep(i, N) {
    X[i] = x[i] + y[i];
    Y[i] = x[i] - y[i];
  }
  auto A = X;
  auto B = Y;
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  cout << max(abs(A.front()-A.back()), abs(B.front()- B.back())) << endl;
}

signed main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> x(N);
  std::vector<long long> y(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &x[i]);
    scanf("%lld", &y[i]);
  }
  solve(N, std::move(x), std::move(y));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 12780
/*
 * Author : Sadi
 * Thu 02/07/2020
 * 19:51:28.70
 */
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int n, t;
    cin >> n >> t;
    set<pii> s;
    int count = 0;
    for(int i = 0; i < n; ++i) {
        int cost, time;
        cin >> cost >> time;
        if(time > t) count++;
        if(time <= t) s.insert({cost, time});
    }
    if(count == n) {
        cout << "TLE" << endl;
    }
    else {
        cout << s.begin()->fi << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

/*
Ctrl+@ でコンソールを開け、以下で実行。
g++ d.cpp
./a.out

サンプルのダウンロードは oj d URL
テストは oj t
*/

Measured memory_bytes: 3632
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, l int
	fmt.Scan(&n, &l)
	s := make([]string, n)
	for i, _ := range s {
		fmt.Scan(&s[i])
	}
	sort.Strings(s)
	var res string
	for _, t := range s {
		res += t
	}

	fmt.Println(res)
}


Measured memory_bytes: 1280
#include <iostream>
using namespace std;
void swap(int *x, int *y)
{
	int tmp = *x;
	*x = *y;
	*y = tmp;
}

void sort(int date[], int n)
{
	int k = n-1;
	while(k>=0){
		int i,j;
		for (i=1, j=-1; i <=k; i++)
			if(date[i-1] < date[i]) {
				j = i-1;
				swap(&date[i], &date[j]);
			}
		k = j;
	}
}

int main(void)
{
	int n[5];
	while(cin >> n[0]){
		for(int i = 1; i < 5; i++){
			cin >> n[i];
		}
		sort(n, 5);
		for(int i=0; i<5; i++){
			cout << n[i];
			if(i!=4) cout << " "; 
		}
		cout << endl;
	}
	return(0);
}

Measured memory_bytes: 536
#include<bits/stdc++.h>
typedef long long ll;
#define sz(x) int(x.size())
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
 
ll gcd(ll a, ll b){
    if(b == 0) return a;
 
    return gcd(b, a%b);
}
ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}
int main(void){
    int N; cin >> N;
    vector<string> s(N);
    int t[N];
    for (int i = 0; i < N; i++)
    {
        cin >> s[i] >> t[i];
    }
    string X; cin >> X;
    int a = 0;
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if(a == 1) ans += t[i];
        if(s[i] == X){
            a = 1;
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

int main() {
    int n, m, x; cin >> n >> m >> x;
    ll ans = INF;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    rep(i, n) {
        cin >> c[i];
        rep(j, m) cin >> a[i][j];
    }
    rep(i, (1<<n)) {
        ll tmp = 0;
        ll sum[m] = {0};
        rep(j, n) {
            if(i & (1<<j)) {
                tmp += c[j];
                rep(k, m) sum[k] += a[j][k];
            }
        }
        bool fl = 0;
        rep(j, m) if(sum[j] < x) fl = 1;
        if(fl) continue;
        chmin(ans, tmp);
    }
    cout << (ans == INF ? -1 : ans) << endl;
}


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

int main(){
  int n,i,j,c;
  int *A;

  scanf("%d",&n);
  c = n;
  A = (int *)malloc(sizeof(int) * n);
  for(i = 0;i < n;i++)
    scanf("%d",&A[i]);

  for(i = 0;i < n;i++)
    for(j = 2;j <= sqrt(A[i]);j++)
      if(A[i] % j == 0){
        c--;
        break;
      }

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

        free(A);
      return 0;
    }


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

int main() {
  string S;
  cin >> S;
  int N = 0;
  
  for (int i = 0; i < 4; i++) {
    if ( S.at(i) == '+' ) {
      N = N + 1;
    }
    else {
      N = N - 1;
    }
  }
  
  cout << N << endl;
      
}


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

int main(){
    string sa, sb, sc;
    cin >> sa >> sb >> sc;

    char ch = sa[0], winner;
    int a=1, b=0, c=0;
    while(true){
        if(ch == 'a'){
            if(a == sa.size()){
                winner = 'A';
                break;
            }
            ch = sa[a++];
        }else if(ch == 'b'){
            if(b == sb.size()){
                winner = 'B';
                break;
            }
            ch = sb[b++];
        }else{
            if(c == sc.size()){
                winner = 'C';
                break;
            }
            ch = sc[c++];
        }
    }
    cout << winner << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int a, b, k;
    cin >> a >> b >> k;
    set<int> st;
    fore(i,a,min(a+k, b+1)) {
        st.insert(i);
    }
    fore(i,max(a, b-k+1),b+1) {
        st.insert(i);
    }
    for (auto &x : st) cout << x << endl;
}


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

int main() {

    int n;
    cin >> n;
	int ok = 0;
	int a;
	for(int i=0;i<n;i++){
		cin >> a;
		if(a%2==0 && (a%3!=0 && a%5!=0)){
			ok++;
		}
	}
	if(ok!=0){
		cout << "DENIED" << endl;
	}else{
		cout << "APPROVED" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e14;
const ll mod = 1e9+7;
// __uint128_t


ll N, M;
ll MAX = 1e5+5;
vector<ll> DP(MAX), DP2(MAX);
vector<vector<ll>> G(MAX);


int dfs(ll x, ll p){
    ll res = 1;
    for(auto v : G[x]){
        if(v == p) continue;
        res *= (dfs(v, x)+1);
        res %= M;
    }
    DP[x] = res;
    return DP[x];
}

void dfs2(ll x, ll p = -1){
    vector<ll> pt;
    for(auto v : G[x]) if(v != p) pt.push_back(v);
    vector<ll> Acc1, Acc2; Acc1.push_back(1); Acc2.push_back(1);
    for(auto v : pt){
        if(v == p) continue;
        Acc1.push_back(DP[v]+1);
        Acc2.push_back(DP[v]+1);
    }Acc1.push_back(1); Acc2.push_back(1);

    for(int i = 0; i < Acc1.size()-1; i++) {Acc1[i+1] *= Acc1[i]; Acc1[i+1] %=M;}
    for(int i = Acc2.size()-1; i > 0; i--) {Acc2[i-1] *= Acc2[i]; Acc2[i-1] %=M;}

    for(int i = 0; i < pt.size(); i++){
        ll idx = i+1;
        ll v = pt[i];
        DP2[v] = (((Acc1[idx-1] * Acc2[idx+1])%M) * DP2[x])%M + 1;
    }
    for(auto v : G[x]){
        if(p != v)dfs2(v, x);
    }
}

int main(){
    cin >> N >> M;
    DP.resize(N);
    DP2.resize(N);
    G.resize(N);
    for(int i = 0; i < N-1; i++){
        ll a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0, -1);
    DP2[0] = 1;

    dfs2(0);

    for(int i = 0; i < N; i++) cout << (DP[i]*DP2[i])%M << endl;

}

Measured memory_bytes: 29952
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	int n;
	while(cin>>n){
		int cnt=0;
		for(int a=0;a<=9;a++)
			for(int b=0;b<=9;b++)
				for(int c=0;c<=9;c++){
					if(a+b+c>n)break;
					if(n-(a+b+c)>9)continue;
					cnt++;
				}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N;
char S[5123];

int main() {

	scanf("%d%s", &N, S);


	int ans = 0;
	for (int i = 1; i < N; ++i) {
		int c = 0;
		for (int j = 0; j < N - i; ++j) {
			if (S[j] == S[j + i]) {
				++c;
				c = min(i, c);
			}
			else {
				c = 0;
			}
			ans = max(ans, c);
		}
	}

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

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Policy;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            //MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        // a+x = b*n
        // x = b*n-a

        int[] aa = new int[n];
        int[] bb = new int[n];
        for(int i=0; i<n; i++) {
            var spl = input.ReadLine().Split(' ');
            aa[i] = int.Parse(spl[0]);
            bb[i] = int.Parse(spl[1]);
        }

        long y = 0;
        for(int j = 0; j<n; j++) {
            int i = n-j-1;
            long a = aa[i];
            long b = bb[i];

            a += y;

            var c = b - (a % b);
            if(c == b) c = 0;

            y+=c;
        }

        return y;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        if(n == 0) return ret;
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 46636
import java.util.*;

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

    int N = sc.nextInt();

    int[] H = new int[N];
    int sum = 0;

    for(int i=0;i<N;i++){
      H[i] = sc.nextInt();
    }

    int anxis = H[0];
    for(int i=0;i<N;i++){
      if(anxis <= H[i]){
        anxis = H[i];
        sum+=1;
      }
    }
    System.out.println(sum);
  }
}

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

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

def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LS(): return input().split()
def I(): return int(input())
def F(): return float(input())
def S(): return input()


def main():
    n = I()
    a = [S() for _ in range(n)]
    def sn(s):
        r = 0
        for i in range(len(s)):
            c = ord(s[i]) - 96
            r = r*27+c
        return r

    def ns(n):
        r = ''
        while n > 0:
            r = chr(n%27+96) + r
            n //= 27
        return r

    for i in range(1,6):
        ss = set()
        for s in a:
            sl = len(s)
            for j in range(sl-i+1):
                ss.add(sn(s[j:j+i]))
        if len(ss) >= 26**i:
            continue
        for ia in itertools.product(range(1,27), repeat=i):
            t = 0
            for ti in ia:
                t = t*27+ti
            if t not in ss:
                return ns(t)
    return ''


print(main())

Measured memory_bytes: 49680
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class C
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = Scanner.Scan<int>();
            var A = Scanner.ScanEnumerable<long>().ToArray();
            var p = (int)1e9 + 7;
            var agg = CumulativeItems(A, p).ToArray();
            var sum = agg[N];
            var answer = 0L;
            for (var i = 1; i < N; i++)
            {
                answer += (A[i - 1] * (sum - agg[i] + p) % p) % p;
                // Console.WriteLine((A[i - 1] % p * (sum - agg[i]) % p) % p);
                answer %= p;
            }

            Console.WriteLine(answer % p);
        }

        public static IEnumerable<long> CumulativeItems(IEnumerable<long> items, int mod)
        {
            var arr = items.ToArray();
            var ret = new long[arr.Length + 1];
            for (var i = 0; i < arr.Length; i++) ret[i + 1] = (arr[i] + ret[i]) % mod;
            return ret;
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


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

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

	int start = max(a,c);
	int end = min(b,d);

	if(start >= end){
		cout << 0 << "\n";
	}else{
		cout << end - start << "\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

using pii = pair<int, int>;

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<pii> is(N);
    for (auto& x : is) cin >> x.fst >> x.snd;
    sort(is.begin(), is.end());
    vector<int> pre(N);
    pre[0] = is[0].snd;
    for (int i = 1; i < N; i++) pre[i] = min(pre[i - 1], is[i].snd);
    vector<int> suf(N);
    suf[N - 1] = is[N - 1].snd;
    for (int i = N - 2; i >= 0; i--) suf[i] = min(suf[i + 1], is[i].snd);
    int res = 0;
    auto len = [&](int a, int b) {
      return max(0, b - a + 1);
    };
    for (int i = 0; i < N - 1; i++) {
      auto x = is[i], y = is[N - 1];
      chmax(res, len(x.fst, pre[i]) + len(y.fst, suf[i + 1]));
      if (i > 0) {
        chmax(res, len(x.fst, x.snd) + len(y.fst, min(suf[i + 1], pre[i - 1])));
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			(3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
template<class T> void chmax(T &a, const T &b){if(a<b)a=b;}
template<class T> void chmin(T &a, const T &b){if(a>b)a=b;}
void YN(bool b){cout<<(b?"YES":"NO")<<endl;}
void Yn(bool b){cout<<(b?"Yes":"No")<<endl;}
void yn(bool b){cout<<(b?"yes":"no")<<endl;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,n;
	cin>>a>>b>>c;
	cout<<min(c,b)<<" "<<max(0,b+c-a)<<endl;

}



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

int main(){
    int64_t t1,t2,a1,a2,b1,b2 ;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2 ;

    int64_t check1 = t1 * (a1-b1) ;
    int64_t check2 = t2 * (a2-b2) ;
    if (check1 + check2 == 0)
    {
        cout << "infinity" << endl ;
        return 0 ;
    }
    if ((check1 > 0 && check2 >0)||(check1 < 0 && check2 < 0))
    {
        cout << 0 << endl ;
        return 0 ;
    }
    if (check1 < 0)
    {
        check1 *= -1 ;
        check2 *= -1 ;
    }
    if (check1 + check2 > 0)
    {
        cout << 0 << endl;
        return 0;
    }
    
    int64_t ans = check1 / ((check2 + check1)*(-1)) * 2 ;
    int64_t p = check1 % ((check2 + check1)*(-1)) ;
    if (p != 0)
    {
        ans += 1;
    }
    
    cout << ans << endl ;
    
    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i=(a) ; i<=(b) ; ++i)
#define mp make_pair
#define pii pair<int, int>
#define PB push_back
#define F first
#define S second
#define Task ""
using namespace std;


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(Task".inp", "r", stdin);
    //freopen(Task".out", "w", stdout);
    int k, a, b;
    cin >> k >> a >> b;
    if(a>=b || (k<(a-1))) return cout << (k+1), 0;
    int cur=k-(a-1);
    long long ans=1ll*(cur/2)*(b-a)+a;
    if(cur&1) ++ans;
    ans=max(ans, k+1ll);
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

typedef long long ll;
typedef vector<int> vi;

int main(){
	ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    
    for(ll i = 0; i < n; i++)
        b[i] = a[i];
    
    sort(a.begin(), a.end());
    ll max = a[n-1], sec;
    sec = max;
    for(ll i = n-1; 0 <= i; i--){
        if(a[i] != max){
            sec = a[i];
            break;
        }
    }
    if(max == a[n-2]){
        for(ll i = 0; i < n; i++){
            cout << max << endl;
        }
        return 0; 
    }
    if(max == sec){
        for(ll i = 0; i < n; i++){
            cout << max << endl;
        }
        return 0;
    }
    for(ll i = 0; i < n; i++){
        if(b[i] == max)
            cout << sec << endl;
        else
            cout << max << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 4736
#include<stdio.h>

int main(){
        int n;
        scanf("%d", &n);
        char s[n+1];
        scanf("%s", s);

        int ans = 0;
        for(int i=0; i<10; i++) for(int j=0; j<10; j++) for(int k=0; k<10; k++){
                int oki=0;
                for(int l=0; l<n; l++){
                        if(oki==0 && s[l]-'0'==i) oki++;
                        else if(oki==1 && s[l]-'0'==j) oki++;
                        else if(oki==2 && s[l]-'0'==k) oki++;
                }
                if(oki==3) ans++;
        }

        printf("%d\n", ans);
        return 0;
}

Measured memory_bytes: 128
let hash = Hashtbl.create 32;;

let update x =
  if Hashtbl.mem hash x then
    Hashtbl.replace hash x ((Hashtbl.find hash x)+1)
  else
    Hashtbl.add hash x 1
;;

let max_len  max s =
  let len = String.length s in
  if len > (fst max) then (len, s) else max
;;

let () =
  let s = read_line ()
          |> Str.split (Str.regexp " ") and
      max = ref (0, "") and
      freq = ref (0, "")
  in
  List.iter (fun x -> max := max_len (!max) x;update x) s;
  Hashtbl.iter (fun key value -> if value > (fst (!freq)) then freq := (value, key)) hash;
  Printf.printf "%s %s\n" (snd (!freq)) (snd (!max))
;;

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  string s; cin >> s;
  int n = SZ(s);
  for(int i = n-2; i >= 2; i-=2) {
    string ss = s.substr(0, i);
    if(ss.substr(0, SZ(ss)/2) == ss.substr(SZ(ss)/2, SZ(ss)/2)) {
      cout << ss.size() << endl;
      return 0;
    }
  }
}


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

using namespace std;

typedef long long int64;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  void unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x != y) {
      if(data[x] > data[y]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

queue < int > que[200001];
unordered_map< int, bool > v[100000];
bool visited[100000];
int N, M;
unordered_map< int, vector< int > > g[100001];
vector< pair< int, int > > graph[100000];

void dfs(queue< int >& q, int idx, const int cc)
{
  if(v[idx][cc]) {
    return;
  }
  v[idx][cc] = true;
  if(!visited[idx]) {
    visited[idx] = true;
    q.push(idx);
  }
  for(auto to : g[idx][cc]) {
    dfs(q, to, cc);
  }
}

int main()
{
  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    int p, q, c;
    cin >> p >> q >> c;
    --p, --q;
    g[p][c].push_back(q);
    g[q][c].push_back(p);
    graph[p].push_back({q, c});
    graph[q].push_back({p, c});
  }

  que[0].push(0);
  v[0][0]++;
  visited[0] = true;
  for(int i = 0; !que[i].empty(); i++) {
    while(!que[i].empty()) {
      int p = que[i].front();
      if(p == N - 1) {
        cout << i << endl;
        return (0);
      }
      for(auto to : graph[p]) dfs(que[i + 1], to.first, to.second);
      que[i].pop();
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 207104
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n, m;
    cin >> n >> m;

    vector<vector<int>> edge(n);
    for (int i =0 ; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    int ans = 0;

    auto dfs = [n, &ans, edge](auto dfs, int cur, int par, vector<bool> &visited) -> void {
        visited[cur] = true;

        bool all_visited = true;
        for (int i = 0; i < n; i++) {
            if (!visited[i]) {
                all_visited = false;
            }
        }

        if (all_visited) ans++;

        for (int ch : edge[cur]) {
            if (ch == par) continue;
            if (visited[ch]) continue;
            dfs(dfs, ch, cur, visited);
        }

        visited[cur] = false;
    };

    vector<bool> visited(n);
    dfs(dfs, 0, -1, visited);

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
def func(i,x,s,new):
    if i==x:
        count=0
        #print(i,x,s,new+[s[-1]])
        new+=s[-1]
        li=new.split("+")
        for j in li:
            count+=int(j)

        return count

    #print(i,x,s,new)
    return func(i,x+1,s,new+s[x-1]+"+") + func(i,x+1,s,new+s[x-1])

new=""
S=input()
print(func(len(S),1,S,new))


Measured memory_bytes: 38768
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
#define all(v) v.begin(), v.end()

int main(){
  ll Q,H,S,D,N;
  cin >> Q>>H>>S>>D>>N;
  if(N%2==0){
    cout << (N/2)*min(min(8*Q,4*H),min(2*S,D)) << endl;
  }else{
    cout << (N/2)*min(min(8*Q,4*H),min(2*S,D))+min(min(4*Q,2*H),S) << endl;
  }
       
    
  

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using ll = long long;
#define ull unsigned ll
#define endl "\n"
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(),(v).end()
#define mst(a,b) memset(a,b,sizeof(a))
#define pi pair<int,int>
#define pl pair<ll, ll>
#define ppi pair<int, pii>
#define mt make_tuple
#define eb emplace_back
using namespace std;

const ll N = 5e5 + 5, mod = 1e9 + 7;
const ll inf = 1e18;

bool cmp(const pair<ll, ll> &a, const pair<ll, ll> &b){
    if(a.F == b.F) return a.S < b.S;
    return a.F > b.F;
}
ll power(ll x, ll p){
    ll r = 1ll;
    x = x % mod;
    while(p > 0){
        if(p & 1) r = (r * x) % mod;
        p = p >> 1;
        x = (x * x) % mod;
    }
    return r;
}
int n, q;
vi color, fen, freq;
void update(int i, int add){
    while(i <= n){
        fen[i] += add;
        i += i & (-i);
    }
}
int query(int i){
    int s = 0;
    while(i > 0){
        s += fen[i];
        i -= i & (-i);
    }
    return s;
}
int sum(int l, int r){
    return query(r) - query(l - 1);
}
void solve(){
    cin >> n >> q;
    color.resize(n + 1);
    fen.resize(n + 1);
    freq.resize(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> color[i];
    }
    int l, r;
    vector<pair<int, pair<int, int>>> Q;
    for(int i = 0; i < q; i++){
        cin >> l >> r;
        Q.pb({l, {r, i}});
    }
    sort(all(Q));
    int j = n;
    vector<int> v(q);
    for(int i = q - 1; i >= 0; i--){
        int l = Q[i].F;
        int r = Q[i].S.F;
        while(j >= l){
            int c = color[j];
            if(freq[c] > 0){
                update(freq[c], -1);
            }
            freq[c] = j;
            update(freq[c], 1);
            j--;
        }
        v[Q[i].S.S] = sum(l, r);
    }
    for(int i : v){
        cout << i << " ";
    }
    cout << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);//cout.tie(0);
    /*#ifndef ONLINE_JUDGE
        freopen("Input.txt", "r", stdin);
    #endif*/
    //freopen("running_on_fumes_chapter_1_input (1).txt", "r", stdin);
    //freopen("Output.txt", "w", stdout);
    int t = 1, p;
    //cin >> t;
    for(p = 1; p <= t; p++){
        //cout << "Case #" << p << ": ";
        solve();
    }
    return 0;
}



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

int main(){
  int k,x,ans;
  cin >> k >> x;
  int miB,maB;
  miB = 0; maB = 0;
  miB = x - k+1;
  maB = x + k -1;
  for(int i = miB;i <= maB;i++){
    cout << i << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define maxn 110
using namespace std;
int n,d[maxn];
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&d[i]);
	sort(d+1,d+(n+1));
	printf("%d\n",d[n]-d[1]);
	return 0;
}

Measured memory_bytes: 128
object Main extends App {
  val sc = new java.util.Scanner(System.in)
//  val l = List.fill(3)(sc.nextInt)
  val x, y = sc.nextInt

  val group = Map(
    1 -> Seq(1, 3, 5, 7, 8, 10, 12),
    2 -> Seq(4, 6, 9, 11),
    3 -> Seq(2)
  )

  val ans = if (group.find(_._2.contains(x)) == group.find(_._2.contains(y))) "Yes" else "No"
  println(ans)
}

Measured memory_bytes: 25792
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
count = 0
left = 0
for i in range(n):
    if b[i] + left - a[i] >= 0:
        count += a[i]
        left = b[i] + left - a[i]
        if left > b[i]:
            left = b[i]
    else:
        count += b[i] + left
        left = 0

count += min(left, a[n])
print(count)

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

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

  if (A>=K) {
    cout << A-K << " " << B << endl;
    return 0;
  }
  if (A < K && B >= K-A) {
    cout << 0 << " " << B - (K-A) << endl;
    return 0;
  }
  if (A < K && B < K-A) {
    cout << 0 << " " << 0 << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
#endif

  int n;
  cin>>n;
  bool flag=0;
  while(n>0)
  {
    if(n%10==7)
    {
      flag=1;
      break;
    }
    n/=10;
  }
  if(flag)
  {
    cout<<"Yes"<<endl;
  }
  else
    cout<<"No"<<endl;
  return 0;
}

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

int main() {
    int n; cin >> n;
    map<string, int> ma;
    string s;
    for(int i=0; i<n; i++) {
        cin >> s;
        ma[s]++;
    }
    for(auto ss: {"AC", "WA", "TLE", "RE"}) cout << ss << " x " << ma[ss] << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n,m,q;cin>>n>>m>>q;
    vector<vector<ll> >st(n);
    rep(i,m){
        ll l,r;cin>>l>>r;
        l--;r--;
        st[l].pb(r);
    }
    rep(i,n){
        sort(all(st[i]));
    }
    rep(i,q){
        ll cnt=0;
        ll p,pp;cin>>p>>pp;
        p--;pp--;
        rep(j,n){
            if(j>=p&&j<=pp){
                auto itr=upper_bound(all(st[j]),pp);
                cnt+=(itr-st[j].begin());
            }
        }
        cout<<cnt<<endl;
    }
}

Measured memory_bytes: 3456
// "include" {{{
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <deque>
    #include <list>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #include <cstring>
    #include <iomanip>
    #include <tuple>
    // }}}
    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 pii pair<int,int> 
    #define int long long
    #define setout(n,x) setw(n) << setfill(x)
    #define Fixed fixed << setprecision(10)
    const int INF = 0x3f3f3f3f;
    const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
    const long long mod = 1000000007;
     
    signed main(){
    	cin.tie(0);
    	ios::sync_with_stdio(false);
    	string s;
    	cin >> s;
    	int n = s.size();
    	int g = 0,p = 0,sum = 0;
    	rep(i,n){
    		if(s[i] == 'g'){
    			if(g > p){
    				++p;
    				++sum;
    			}
    			else ++g;
    		}
    		else{
    			if(g > p) ++p;
    			else{
    				++g;
    				--sum;
    			}
    		}
    	}
    	cout << sum << '\n';
    	return 0;
    }

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    int a[n+1],b[n+1];
    for(i=1;i<=n;i++)
        b[i]=0;
    a[1]=0;
    for(i=2;i<=n;i++)
        cin>>a[i];
    for(i=1;i<=n;i++)
        b[a[i]]++;
    for(i=1;i<=n;i++)
        cout<<b[i]<<endl;
    return 0;
}


Measured memory_bytes: 5152
import java.io.InputStreamReader
import java.io.BufferedReader

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))

  val ref = "ATGC"
  val s = br.readLine().toCharArray()
  var max = 0;
  for(i in 0 until s.size) {
    if(!ref.contains(s[i]))
      continue
    
    var cnt = 0;
    for(j in i until s.size) {
      if(!ref.contains(s[j]))
        break

      max = Math.max(max, ++cnt)
    }
  }

  val ans = max
  println(ans)
}

Measured memory_bytes: 31392