akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  string s;
  cin >> s;
  int n;
  cin >> n;
  int answerl=s[0]-'0';
  REP(i,s.size()/2)
    if(s[i*2+1]=='+') answerl+=(s[i*2+2]-'0');
    else answerl*=(s[i*2+2]-'0');
  int answerm=0;
  vector<int> adds;
  adds.push_back(s[0]-'0');
  REP(i,s.size()/2)
    if(s[i*2+1]=='+') adds.push_back(s[i*2+2]-'0');
    else adds[adds.size()-1]*=(s[i*2+2]-'0');
  REP(i,adds.size()) answerm+=adds[i];
  string ans="IMLU";
  int ansnum=0;
  if(n==answerm) ansnum+=1;
  if(n==answerl) ansnum+=2;
  cout << ans[ansnum] << endl;
  return 0;
}

Measured memory_bytes: 3228
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353
using namespace std;
typedef pair<llint, llint> P;

struct BIT{
	int size;
	vector<llint> bit;
	BIT(){size = 0;}
	BIT(int s){
		size = s;
		bit.resize(size+1);
		init();
	}
	void init(){
		for(int i = 1; i <= size; i++) bit[i] = 0;
	}
	llint query(int i){
		i++;
		llint ret = 0;
		while(i > 0){
			ret += bit[i];
			i -= i&(-i);
		}
		return ret;
	}
	void add(int i, llint x){
		i++;
		while(i <= size){
			bit[i] += x;
			i += i&(-i);
		}
	}
};

llint n;
llint a[100005], sum[100005];
P p[100005];
BIT bit(100005);
llint L;

bool check(llint m)
{
	for(int i = 1; i <= n; i++){
		sum[i] = sum[i-1];
		if(a[i] >= m) sum[i]++;
		else sum[i]--;
	}
	for(int i = 0; i <= n; i++) p[i] = P(sum[i], i);
	sort(p, p+n+1);
	
	llint ret = 0;
	bit.init();
	for(int i = 0; i <= n; i++){
		ret += bit.query(p[i].second);
		bit.add(p[i].second, 1);
	}
	return ret >= L;
}

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	L = n*(n+1)/2;
	L = (L+1)/2;
	
	llint ub = 1e9+7, lb = 0, mid;
	while(ub-lb>1){
		mid = (ub+lb)/2;
		if(check(mid)) lb = mid;
		else ub = mid;
	}
	cout << lb << endl;
	
	return 0;
}


Measured memory_bytes: 4096
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

#include<unistd.h>
struct Buffer{
    enum { chunk = 1 << 16 };
    int idx;
    char buf[chunk];
    Buffer(){ init(); }
    void init(){ idx = 0; read(0, buf, chunk); }
    void check(){ if(idx == chunk){ init(); } }
    int next(){
        static char notDigits[256] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1, 0,0,0,0,0,0,0,0,0,0,};
        int ret = 0, sign = 1;
        while(check(), notDigits[(int)buf[idx]]){ idx++; }
        if(check(), buf[idx] == '-'){ sign = -1; idx++; }
        while(check(), !notDigits[(int)buf[idx]]){ ret = ret * 10 + buf[idx++] - '0'; }
        return sign * ret;
    }
};
struct FastInput {
    Buffer buf;
    template <class T>
    FastInput& operator >> (T& num) { num = buf.next(); return *this; }
    void tie(int){ }
    template <class S, class T>
    friend FastInput& operator >> (FastInput& in, pair<S, T>& p){ return in >> p.first >> p.second; }
    template <class T>
    friend FastInput& operator >> (FastInput& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
};
FastInput fin;
#define cin fin

int accs[512][512];
int main(){
    int n, m, q;
    cin >> n >> m >> q;
    // vector<vector<int>> accs(n, vector<int>(n));
    for(int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        // l--; r--;
        accs[0][r]++;
        accs[l + 1][r]--;
        // for(int i = 0; i <= l; i++){
        //     accs[i][r]++;
        // }
    }
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            accs[i + 1][j] += accs[i][j];
            accs[i][j] += accs[i][j - 1];
            // if(i + 1 < n){ accs[i + 1][j] += accs[i][j]; }
            // if(j){ accs[i][j] += accs[i][j - 1]; }
        }
    }
    // for(int j = 0; j < n; j++){
    //     for(int i = 1; i < n; i++){
    //         accs[i][j] += accs[i - 1][j];
    //     }
    // }
    // for(int i = 0; i < n; i++){
    //     for(int j = 1; j < n; j++){
    //         accs[i][j] += accs[i][j - 1];
    //     }
    // }
    for(int i = 0; i < q; i++){
        int p, q;
        cin >> p >> q;
        // p--; q--;
        cout << accs[p][q] << '\n';
    }
}


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

int main() {
	int N;
	cin >> N;
	vector<int>h(N);
	int i;
	for (i = 0; i < N; i++) {
		cin >> h[i];
	}

	int cost = 0;
	vector<int>c(N);
	c[0] = 0;	
	c[1] = abs(h[1]-h[0]);
	
	for (i = 1; i < N - 1; i++) {
		c[i + 1] = min(c[i] + abs(h[i + 1] - h[i]), c[i - 1] + abs(h[i + 1] - h[i - 1]));		
	}

	cout << c[N - 1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define maxn 51
#define m_p make_pair 
int main(){
	int n;
	cin>>n;
	int x[maxn],y[maxn];
	for (int i=0;i<n;i++) cin>>x[i]>>y[i];
	map<pii,int> mp;
	map<pii,int>::iterator it;
	
	for (int i=0;i<n;i++)
		for (int j=0;j<i;j++){
			int dx=x[i]-x[j];
			int dy=y[i]-y[j];
			mp[m_p(dx,dy)]++;
			mp[m_p(-dx,-dy)]++;
		}
	int mx=0;
	for (it=mp.begin();it!=mp.end();it++)
		mx=max(mx,it->second);
	printf("%d\n",n-mx);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    string temp;
    string ring;
    string target;
    int ans=0;
    int N;

    cin >> target;
    cin >> N;

    for(int i=0; i<N; ++i) {
        cin >> temp;
        ring=temp+temp;
        for(int j=0; j<(int)(ring.size()-target.size()); ++j) {
            if(ring.substr(j,target.size())==target) {
                ++ans;
                break;
            }
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3196
//this library has many things needed for arrays, the asterisc means we get everything is inside, the dot says where is is inside, you need the ; to tell the line has ended, like in C
import java.util.*;

//the name of the main function has to be the same name of the program
//what public class mean in java: it means that other function scan also access the class. What happens if we dont make it public? Well, it stil works, but it will be visivle to code only in the same package
public class Main {
	//this is a method, it tells that it will execute the things that are inside, it takes string as args when we execute the program, it is optional. What if instead we use int? It does not work, it has to be String[] args
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);	
      	int N = sc.nextInt();
      	int A = sc.nextInt();
        if (A >= N%500){
        	System.out.println("Yes");
        }
      	else{
          	System.out.println("No");
        }
    
	}
}



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

int main(void){
    int n;
    cin>>n;
    int array[n];
    rep(i, n){
        cin>>array[i];
    }
    int ans=0;
    for(int i=1;i<n-1;i++){
        if((array[i-1]<array[i] and array[i]<array[i+1]) or (array[i-1]>array[i] and array[i]>array[i+1])){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define PI 3.14159265358979323844
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define mp make_pair
#define inf  10737418240000
#define pb push_back
#define int long long int 
#define forr(i,a,b) for (int i= a; i <b; ++i)
    using namespace std; 
   int weight[1000]; 
   int price[1000];
   int dp[200][100005];
    signed main(){ 
     int n;cin>>n;
     memset(dp , -1 , sizeof dp);
     int W;cin>>W;
     int totalprice=0;
    forr(i,1,n+1){cin>>weight[i];cin>>price[i];totalprice+=price[i];}
    forr(i,1,totalprice+1)dp[1][i]=inf;
    dp[1][0]=0;
    dp[1][price[1]]=weight[1];
   forr(i,2,n+1){
       forr(j,0,totalprice+1){
           dp[i][j]=dp[i-1][j];
           if(price[i]<=j){
               dp[i][j]=min(dp[i][j] , dp[i-1][j-price[i]] + weight[i]);
           }
       }
   }
    int final=-1000;
forr(j,1,totalprice+1) {
if(dp[n][j]<=W && dp[n][j]!=-1  && dp[n][j]!=inf) final=max(final,j);}
     cout<<final;}
    
    
    
        
        
        
       


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


using namespace std;

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

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

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

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

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

//!!!問題をちゃんと読む!!!
//!!!問題をちゃんと読め!!!
//!!!問題は読みましたか？!!!
int wwa[2000000], bwa[2000000];

signed main() {
	int N;
	cin >> N;
	vector<int> V, C;
	rep(i, N) {
		int t;
		cin >> t;
		V.push_back(t);
	}
	rep(i, N) {
		int t;
		cin >> t;
		C.push_back(t);
	}
	vector<int> res;
	rep(i, N) {
		int o = V[i] - C[i];
		res.push_back(o);
	}
	sort(res.begin(), res.end());
	int ans = 0;
	rep(i, N) {
		if (res[i] >= 0) {
			ans += res[i];
		}
	}
	cout << ans << "\n";

	return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int sum=0;
    int N,M;
    cin>>N>>M;
    vint A(N);rep(i,N)cin>>A[i];
    vint cnt(N);
    for(int i=0;;i+=M){
        int ma=-1,mi=LLONG_MAX;
        for(int j=0;j<M;j++){
            chmax(ma,A[(i+j)%N]);
            chmin(mi,A[(i+j)%N]);
            cnt[(i+j)%N]++;
        }
        sum+=ma-mi;
        if(count(all(cnt),cnt[0])==N)break;
    }
    cout<<sum<<endl;
    return 0;
}

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

int main(){
  char dna[]={'A','C','G','T'};
  string str;
  int i,j;
  size_t size;
  int r[10];
  int r_max=0;
  int flag;
  
  cin >> str;
  size=str.length();
  for(i=0;i<10;i++){
    r[i]=0;
  }
  
  for(i=0;i<size;i++){
    r[i]=0;
    flag=1;
    for(j=0;(i+j)<size;j++){
      if(flag && (str[i+j]=='A' || str[i+j]=='C' || str[i+j]=='G' || str[i+j]=='T')){
        r[i]++;
      }
      else{
        flag=0;
      }
    }
  }
  
  for(i=0;i<size;i++){
    if(r[i]>r_max){
      r_max=r[i];
    }
  }
  
  cout << r_max;
  
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll A,K;
	while(cin>>A) {
		VI T(5);
		T[0]=A;
		RANGE(i, 1, 5) cin>>T[i];
		cin>>K;
		string ans = "Yay!";
		REP(i, 5) REP(j, 5) if(abs(T[i]-T[j])>K) ans = ":(";
		cout<<ans<<endl;
	}
	
	return 0;
}


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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;
#define ret() return 0;

bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

class CumulativeSum {
    vector<ll> numbers;
    vector<ll> sums;

public:
    CumulativeSum(int n) {
        numbers.resize(n);
        sums.resize(n);
    }

    void set(int i, ll value) {
        numbers[i] = value;
    }

    ll getSum(int i) {
        if (i == -1) return 0;
        if (i == sums.size()) return 0;
        return sums[i];
    }

    ll getSectionSum(int start, int end) {
        return getSum(end) - getSum(start - 1);
    }

    void calculate() {
        for (int i = 0; i < numbers.size(); i++) {
            sums[i] = getSum(i - 1) + numbers[i];
        }
    }

};


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

    string s;
    cin >> s;

    CumulativeSum rsum(n), lsum(n);

    for (int i = 0; i < n - 1; i++) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            lsum.set(i, 1);
        }
    }

    for (int i = 1; i < n; i++) {
        if (s[i] == 'C' && s[i - 1] == 'A') {
            rsum.set(i, 1);
        }
    }

    rsum.calculate();
    lsum.calculate();

    rep(i, q) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        //         return getSum(end) - getSum(start - 1);


        ll rs = rsum.getSum(r);
        ll ls = lsum.getSum(l - 1);

        ll now = rs - ls;

        cout << now << endl;

    }


}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;

#define max_n 1e5+10
int n,m;
vector<vector<int>> g(max_n);
vector<int> v;
vector<bool> used(max_n,false); 

 
void dfs(int u){
	if(used[u]) return;
	used[u] = true;
	for(int i: g[u]) dfs(i);
	//帰りがけ順で追加
	v.pb(u);
}

void tsort(){
	for(int i = 0; i < n; i++) dfs(i);
	reverse(v.begin(), v.end());
}
  
int main(){
    
    cin>>n>>m;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        g[a].pb(b);
    }
    tsort();
    reverse(v.begin(), v.end());

    vector<int> dp(n, 0);
	int ans = 0;
	for(int i: v){
		for(int u : g[i]){
			dp[i] = max(dp[i], dp[u] + 1);
		}
		ans = max(ans, dp[i]);
	}

    cout<<ans<<endl;

    
    return 0;
}

Measured memory_bytes: 8696
N,M = map(int,input().split())
PY=[list(map(int,input().split()))+[0] for _ in range(M)]
sort_PY=sorted(PY,key=lambda x:x[1])
c={}
for i in range(M):
    p=sort_PY[i][0]
    if(p in c):
        c[p]+=1
    else:
        c[p]=1
    sort_PY[i][2]=c[p]
for p,y,z in PY:
    print(str(p).zfill(6)+str(z).zfill(6))

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

using lli = long long;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
using Double = long double;
template<typename T>
using Vector = vector<vector<T>>;
template<typename T>
using Prior = priority_queue<T>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;

#define IOS() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define X first
#define Y second
#define Push push_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()

void solve() {
	string s;
	cin >> s;
	int sz = s.size();

	int L = -1, R = -1;
	for (int i = 1; i < sz; ++i) {
		if (s[i] == s[i - 1]) {
			L = i, R = i + 1;
			break;
		}
	}

	for (int i = 2; i < sz; ++i) {
		if (s[i] == s[i - 2]) {
			L = i - 1, R = i + 1;
			break;
		}
	}

	cout << L << " " << R << "\n";
}

int main() {
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	map<char,char>mp;
	map<char,char>mp2;
	for(int i=0;i<s.size();i++)
	{
		if(mp[s[i]]==0)
			mp[s[i]]=t[i];
		else if(mp[s[i]]!=t[i])
		{
			cout<<"No";
			return 0;
		}
	}
		for(int i=0;i<s.size();i++)
	{
		if(mp2[t[i]]==0)
			mp2[t[i]]=s[i];
		else if(mp2[t[i]]!=s[i])
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

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

typedef struct{
	int num[6];
}saikoro;

int num_1,num_2;
saikoro s_1;

void set_s_num(int *a){
	int i;
	for(i=0;i<6;i++){
		s_1.num[i]=a[i];
	}
}

void n(saikoro *a){
	int tmp;
	tmp=a->num[4];
	a->num[4]=a->num[0];
	a->num[0]=a->num[1];
	a->num[1]=a->num[5];
	a->num[5]=tmp;
}

void s(saikoro *a){
	int tmp;
	tmp=a->num[1];
	a->num[1]=a->num[0];
	a->num[0]=a->num[4];
	a->num[4]=a->num[5];
	a->num[5]=tmp;
}

void e(saikoro *a){
	int tmp;
	tmp=a->num[2];
	a->num[2]=a->num[0];
	a->num[0]=a->num[3];
	a->num[3]=a->num[5];
	a->num[5]=tmp;
}

void w(saikoro *a){
	int tmp;
	tmp=a->num[3];
	a->num[3]=a->num[0];
	a->num[0]=a->num[2];
	a->num[2]=a->num[5];
	a->num[5]=tmp;
}

int main(){
	int i,j,k,nt,slen,num[6],f_br;
	char input[128];
	
	fgets(input,sizeof input,stdin);
	sscanf(input,"%d %d %d %d %d %d",&num[0],&num[1]
		,&num[2],&num[3],&num[4],&num[5]);
	
	fgets(input,sizeof input,stdin);
	sscanf(input,"%d",&nt);
	
	for(i=0;i<nt;i++){
		f_br=0;
		set_s_num(num);
		fgets(input,sizeof input,stdin);
		sscanf(input,"%d %d",&num_1,&num_2);
		
		for(j=0;j<4;j++){
			for(k=0;k<4;k++){
				
				if(num_1==s_1.num[0]&&num_2==s_1.num[1]){
					printf("%d\n",s_1.num[2]);
					f_br=1;
				}else if(num_1==s_1.num[1]&&num_2==s_1.num[2]){
					printf("%d\n",s_1.num[0]);
					f_br=1;
				}
				
				if(f_br==1){
					break;
				}
				
				e(&s_1);
			}
			
			if(f_br==1){
					break;
				}
			n(&s_1);
		}
		  
	}
	
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	int a[3];
	REP(i,3) cin >> a[i];/*cin >> a[0] >> a[1] >> a[2]*/
	sort(a,a+3);/*??????*/
	cout << a[0] << " " << a[1] << " " << a[2] << endl;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
int n,m,a[105],sum,num;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	double x=sum/(4.0*m);
	for(int j=-1;j<=n;j++)
	{
		if(a[j]>=x)
		num++;
	}
	if(num>=m)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;

    int ret = 0;
    for (int i = 1; i <= n; i++) {
        int ans = 0;
        int temp = i;
        while(temp) {
            ans += temp % 10;
            temp /= 10;
        }

        if (ans >= a && ans <= b)   ret += i;
    }

    cout << ret << endl;
    return 0;
}

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

typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll x;
    cin >> x;
    ll ans = 2 * (x / 11);

    
     if( x % 11 > 6 )
        ans += 2;
    else if(x % 11 <= 6 && x%11!=0)
        ans += 1;
    cout << ans;
}
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n,m=0,t;
  cin >> n;
  t=n;
  while(t>0){
    m+=t%10;
    t/=10;
  }
  if(n%m==0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3560
n,w=map(int,input().split())
W=[]
V=[]
for i in range(n):
   a,b=map(int,input().split())
   W.append(a)
   V.append(b)
v=sum(V)

def knapsack2(n,w):
    dp=[[10**9]*(v+1) for i in range(n+1)]
    
    dp[0][0]=0
    
    for i in range(n):
        for j in range(v+1):
            if j-V[i]<0:
                dp[i+1][j]=dp[i][j]
            else:
                dp[i+1][j]=min(dp[i][j],dp[i][j-V[i]]+W[i])
    r=0
    for j in range(v+1):
        if dp[n][j]<=w:
            r=max(r,j)
    
    return r
print(knapsack2(n,w))

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

int main() {
  ll n,k,r,s,p;
  string t;
  cin >> n >> k >> r >> s >> p;
  cin >> t;

  vector<string> t2(k);

  rep(i,t.length()){
    t2[i%k] += t[i];
  }

  rep(j,k){
    rep(i,t2[j].length()){
      if (i>0){
        if (t2[j][i-1] == t2[j][i]) t2[j].replace(i,1,"z");
      }
    }
  }

  ll ans = 0;
  rep(j,k){
    rep(i,t2[j].length()){
        if (t2[j][i] =='r') ans += p;
        else if (t2[j][i] =='p') ans += s;
        else if (t2[j][i] =='s') ans += r;
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const int mod = (int)1e9+7;
#define pb push_back
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n;
	cin >> n;
	set<pair<int,int>> st;
	vector<lli> dist1, dist2;
	for(int i=0; i<n; i++){
		int a, b;
		cin >> a >> b;
		if(st.find(make_pair(a, b))!= st.end()) continue;
		st.insert(make_pair(a,b));
		dist1.push_back(((lli)a+(lli)b));
		dist2.push_back(((lli)a-(lli)b));
	}
	sort(dist1.begin(), dist1.end());
	sort(dist2.begin(), dist2.end());
	cout << max(dist1.back()-dist1[0],abs (-dist2.back()+dist2[0])) ;
	return 0;
}

Measured memory_bytes: 15716
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
ll INF = 1000000007;


/***************/
 #define amin main
/***************/

ll exp(ll x, ll n)
{if(n==0) return 1;if(n==1) return x%INF;if(n%2==0) return exp((x*x)%INF,n/2); else return(x*exp((x*x)%INF,n/2))%INF;}


int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,i;
	ll n,x;
	
	cin>>x>>n;
	ll arr[n];
	ll mini = INF;
	ll ans = INF;
	ll vis[105]={0};
	for(i=0;i<n;i++)
		{
			cin>>arr[i];
			vis[arr[i]]=1;
		}
	for(i=0;i<=102;i++)
	{
		if(vis[i]==0)
		{
			ll k = abs(i-x);
			if(k<=mini)
				{
					if(k<mini)
					ans = i;


			mini = k;
			}

		}
	}
	//cout<<mini<<endl;
	cout<<ans<<endl;
	


	
	

	
	


	
	return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define F first
#define S second
#define pi acos(-1)
using ll = long long;
using namespace std;
using namespace __gnu_pbds;
using vl = vector<ll>;
using pll =  pair<ll,ll>;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


ll power(ll x,ll y){
    ll res = 1;
    while(y){
        if(y&1)
            res = (res*x)%md;
        x = (x*x)%md;
        y = y/2;
    }
    return res;
}

void solve(){
    int n;
    cin>>n;
    vl a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }

    ll ans = mod;
    for(int i=-100;i<=100;i++){
        ll tot = 0;
        for(int j=0;j<n;j++){
            tot += (a[j] - i) * (a[j] - i);;
        }
        ans = min(ans,tot);
    }
    cout<<ans<<endl;
}
 
int main()
{
    
   

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //int n; cin>>n; for (int i = 0; i < n; ++i)
    solve();
    return 0;
}


Measured memory_bytes: 256
s = input()
k = int(input())
L = len(s)
se = set([])
def subs(l):
    for i in range(L-l+1):
        se.add(s[i:i+l])
for i in range(1,6):
    subs(i)
# print(se)
print(sorted(se)[k-1])

Measured memory_bytes: 10568
MAX =150000
prime = Array.new(MAX,true)
primes = Array.new
prime[0]=prime[1]=false
(2..MAX).each do |i|
  if prime[i]
    primes <<i
    (i+i).step(MAX,i) do |j|
      prime[j]=false
    end
  end
end
loop do
  n,p= gets.split.map(&:to_i)
  break if n==-1 && p == -1
  arr=primes.select{|x| x>n}.take(p+1)
  ans=[]
  (0...arr.size).each do |i|
    (i...arr.size).each do |j|
      ans << arr[i]+arr[j]
    end
  end
  ans.sort!
  p ans[p-1]
end

Measured memory_bytes: 9500
import java.util.Scanner;

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

		int Ss = Integer.parseInt(S.replaceAll("/", ""));


		if (Ss > 20190430) {
			System.out.println("TBD");
		} else {
			System.out.println("Heisei");
		}
	}
}

Measured memory_bytes: 22996
import numpy as np
import copy
H,W,K = map(int,input().split())
C = []
for i in range(H):
    array = []
    temp = input()
    #白：０　黒：１
    array = [1 if i == '#' else 0 for i in temp]
    C.append(array)

C = np.array(C)
ans = 0
for i in range(2 ** H):
    for j in range(2 ** W):
        temp = copy.deepcopy(C)
        temp = temp.T
        for k in range(W):
            if((j>>k)&1):
                #j列目を削除する
                temp[k] = [0 for l in range(H)]
        temp = temp.T
        for k in range(H):
            if((i>>k)&1):
                #i行目を削除する
                temp[k] = [0 for m in range(W)]
    
        if sum(temp.flatten()) == K :
            ans = ans+1

print(ans)

Measured memory_bytes: 27224
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 7;
const int INF = 1e18 + 7;
const int MOD = 1000 * 1000 * 1000 + 7;
int mod(int n) {
    return (n % MOD + MOD) % MOD;
}   
int n, m;
int S, T;
struct Edge {
    int v, c;
};  
int dist[2][N];
int dp[2][N];
vector <Edge> g[N];
void work(int S, int *dist, int *dp) {
    set <pair <int, int> > ms;
    for (int i = 1; i <= n; ++i) {
        dist[i] = INF;
    }   
    dist[S] = 0;
    dp[S] = 1;
    ms.insert({0, S});
    while (ms.size()) {
        int u = ms.begin()->second; ms.erase(ms.begin());
        for (auto e : g[u]) {
            if (dist[u] + e.c < dist[e.v]) {
                ms.erase({dist[e.v], e.v});
                dist[e.v] = dist[u] + e.c;
                dp[e.v] = dp[u];
                ms.insert({dist[e.v], e.v});
            }   
            else if (dist[u] + e.c == dist[e.v]) {
                dp[e.v] = mod(dp[e.v] + dp[u]);
            }   
        }   
    }   
}   
struct Ed {
    int u, v, c;
};  
vector <Ed> ed;
bool check(int x, int y, int c) {
    if (y < x) swap(x, y);
    return y < x + c;
}   
int D;
bool mem(int t, int u, int v, int c) {
    return dist[t][u] + c == dist[t][v] && dist[t][v] + dist[t ^ 1][v] == D;
}
int f(int n) {
    n = mod(n);
    return mod(n * n);
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n >> m >> S >> T;
    for (int i = 0; i < m; ++i) {
        int u, v, c;
        cin >> u >> v >> c;
        g[u].push_back({v, c});
        g[v].push_back({u, c});
        ed.push_back({u, v, c});
    }   
    work(S, dist[0], dp[0]); work(T, dist[1], dp[1]);
    D = dist[0][T];
    int ans = mod(dp[0][T] * dp[0][T]);
    for (int i = 1; i <= n; ++i) {
        if (dist[0][i] + dist[1][i] == D && dist[0][i] == dist[1][i]) {
            ans = mod(ans - f(dp[0][i] * dp[1][i]));
        }   
    }   
    for (auto e : ed) {
        if (mem(0, e.u, e.v, e.c) && mem(1, e.v, e.u, e.c)) {
            if (check(dist[0][e.u], dist[1][e.v], e.c)) {
                ans = mod(ans - f(dp[0][e.u] * dp[1][e.v]));
            }   
        }
        else if (mem(1, e.u, e.v, e.c) && mem(0, e.v, e.u, e.c)) {
            if (check(dist[1][e.u], dist[0][e.v], e.c)) {
                ans = mod(ans - f(dp[1][e.u] * dp[0][e.v]));
            }   
        }   
    }   
    cout << ans << '\n';
}   

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

int main()
{
    int a,b,c[3];
    cin>>a>>b;
    c[0]=a+b;
    c[1]=a*b;
    c[2]=a-b;
    sort(c,c+3);
    cout<<c[2]<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
const ll MOD=1000000007;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define range(i) (i).begin(),(i).end()
#define rrange(i) (i).rbegin(),(i).rend()
inline ll gcd(ll a, ll b) {return b?gcd(b, a%b):a;}
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans*(b&1?a:1);
}
inline constexpr int modpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
template<class T> inline bool chmax(T& a,T b) {if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b) {if(a>b){a=b;return 1;} return 0;}
const ll LINF=0x1fffffffffffffff;

struct unionfind{
    vector<ll> d;
    unionfind(ll x):d(x,-1){}
    ll root(ll x) {return d[x]<0?x:d[x]=root(d[x]);}
    ll size(ll x) {return -d[root(x)];};
    bool unite(ll x,ll y) {x=root(x),y=root(y); if(x!=y){if(d[x]>d[y])swap(x,y);d[x]+=d[y];d[y]=x;}return x!=y;}
    bool find(ll x,ll y) {return root(x)==root(y);}
};
int main(){
    ll n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    vector<ll> l(q),r(q),rui(n);
    rep(i,0,q) cin>>l[i]>>r[i];
    rep(i,0,n-1){
        if(s[i]-'A')continue;
        if(s[i+1]-'C')continue;
        rep(j,i+1,n) rui[j]++;
    }
    rep(i,0,q){
        cout<<rui[r[i]-1]-rui[l[i]-1]<<"\n";
    }
}




Measured memory_bytes: 3456
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int modpow(int a, int p) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int halfP = p / 2;
		int half = modpow(a, halfP);
		return half * half % mod;
	}
	else {
	
		return a * modpow(a, p - 1) % mod;
	}
}

int comb(int a, int b) {
	if (b > a - b) return comb(a, a - b);


	int ansMul = 1;
	int ansDiv = 1;
	for (int i = 0; i < b; i++)
	{
		ansMul *= (a - i);
		ansDiv *= (i + 1);
		ansMul %= mod;
		ansDiv %= mod;
	}
	
	int ans = ansMul * modpow(ansDiv, mod - 2) % mod;

	return ans;
}

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

	int N, M, K;
	cin >> N >> M >> K;

	int ret = 0;
	REP(i, N) {
		int d = 1LL * i*(i + 1) / 2 % mod;
		d = d * M%mod*M%mod;
		ret += d;
	}
	REP(i, M) {
		int d = 1LL * i*(i + 1) / 2 % mod;
		d = d * N%mod*N%mod;
		ret += d;
	}

	cout << ret % mod*comb(N*M - 2, K - 2) % mod << endl;

	return 0;
}



Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int c[1000001];
void f(int n,int a,int b){
	if(n<0)return;
	if((a>>n-1&1)==(b>>n-1&1)){
		f(n-1,a,b);
		c[0]--;
		f(n-1,c[c[0]]^(1<<n-1),b^(1<<n-1));
		c[++c[0]]=b;
	}
	else{
		if(n==1)c[++c[0]]=a,c[++c[0]]=b;
		else{
			f(n-1,a,a^1);
			f(n-1,a^1^(1<<n-1),b);
		}
	}
}
int main(){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	int z=0;
	for(int i=0;i<n;i++)
		if((a^b)>>i&1)z^=1;
	if(z==0){
		printf("NO\n");
		return 0;
	}
	f(n,a,b);
	printf("YES\n");
	for(int i=1;i<=c[0];i++)
		printf("%d%c",c[i],i==c[0]?'\n':' ');
}

Measured memory_bytes: 2236
a = list(input())
for i in range(4):
    a[i] = int(a[i])

n = 3

for i in range(2 ** n):
    sym = ["-"] * n
    for j in range(n):
        if (i >> j) & 1:
            sym[j] = "+"

    cal = "{}{}{}{}{}{}{}".format(a[0], sym[0], a[1], sym[1], a[2], sym[2], a[3])
    ans = eval(cal)
    if ans == 7:
        print("{}={}".format(cal, eval(cal)))
        break

Measured memory_bytes: 3064
// Date: 2020-01-25

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

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int n;
int x[N], cnt[N];

int main() {
	FIO;
	cin >> n;
	int mxval = 0;
	rep(i, 1, n) cin >> x[i], mxval = max(mxval, x[i]);
	for(int i = 1; i <= n; i += 2) cnt[x[i]]++;
	pii mx1(0, 0), se1(0, 0), mx2(0, 0), se2(0, 0);
	rep(i, 1, mxval) {
		if(cnt[i] >= mx1.fi) {
			se1 = mx1;
			mx1.fi = cnt[i];
			mx1.se = i;
		} else if(cnt[i] > se1.fi) {
			se1.fi = cnt[i];
			se1.se = i;
		}
	}
	mem(cnt, 0);
	for(int i = 2; i <= n; i += 2) cnt[x[i]]++;
	rep(i, 1, mxval) {
		if(cnt[i] >= mx2.fi) {
			se2 = mx2;
			mx2.fi = cnt[i];
			mx2.se = i;
		} else if(cnt[i] > se2.fi) {
			se2.fi = cnt[i];
			se2.se = i;
		}
	}
	int ans;
	if(mx1.se != mx2.se) ans = n-mx1.fi-mx2.fi;
	else ans = min(n-mx1.fi-se2.fi, n-se1.fi-mx2.fi);
	cout << ans;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
  	char s[3];
  	for (int i = 0; i < 3; i++) {
     	cin >> s[i];
      	for (int j = 0; j < i; j++) {
          	if (s[i] != s[j]) {
              	cout << "Yes" << endl;
              	return 0;
            }
        }
    }
  	cout << "No" << endl;
  
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)                                 //g++ template.cpp -o template.exe
#define zeroes(x) memset(x,0,sizeof(x))                                        //all elements to 0  |  \
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;







bool sortbysec(const pair<int,int> &a,                         //sorting of elements wrt second
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 

bool sortinrev(const pair<int,int> &a,                   //sorting in descending wrt first 
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 
bool sortinrevsec(const pair<int,int> &a,                  //sorting in dsc wrt second
               const pair<int,int> &b) 
{ 
       return (a.second > b.second); 
} 




int main()
{
  ll n,k,v;
  string yy="Yes",n2="No";
   cin>>n>>k;

   vector<ll>a;
for(ll i=0;i<n;i++)
{

    cin>>v;
    a.push_back(v);
  }


for(ll i=k;i<n;i++){
    if(a[i]>a[i-k])
        cout<<yy<<endl;
    else
        cout<<n2<<endl;
}
  return 0;
}

Measured memory_bytes: 5344
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	cout << t << s;
	return 0;
}

Measured memory_bytes: 256
import math
A = input()
B = input()
if len(A)>len(B):
  print("GREATER")
elif len(A)<len(B):
  print("LESS")
else:
  while 1:
    if int(A[0])>int(B[0]):
      print("GREATER")
      break
    elif int(A[0])<int(B[0]):
      print("LESS")
      break
    else:
      if len(A)!=1:
        A = A[1:]
        B = B[1:]
      else:
        if int(A)>int(B):
          print("GREATER")
          break
        elif int(A)<int(B):
          print("LESS")
          break
        else:
          print("EQUAL")
          break

Measured memory_bytes: 62100
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

MOD = 10**9+7

def main():
    N,K = map(int, readline().split())

    gcd_cnt = [0] * (K+1)

    for i in range(K,1,-1):
        gcd_cnt[i] = pow(K // i, N, MOD)
        x = 2
        while i * x <= K:
            gcd_cnt[i] -= gcd_cnt[i*x]
            gcd_cnt[i] %= MOD
            x += 1

    #print(gcd_cnt)

    ans = pow(K,N,MOD)
    for i in range(2,K+1):
        ans += ((gcd_cnt[i] % MOD) * (i-1)) % MOD
        ans %= MOD
    
    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
	int n; cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p.at(i);
	}
	int ans = 1, m = 200010;
	for (int i = 1; i < n; i++) {
		m = min(m, p.at(i - 1));
		if (p.at(i) <= m) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll mod=1e9+7;

int main()
{
    fast();
    ll n,k;
    cin>>n>>k;

    ll arr[n];
    for(ll i=0;i<n;i++)
        cin>>arr[i];


    ll dp[n]={0};
    for(ll i=1;i<n;i++)
        dp[i]=LLONG_MAX;

    for(ll i=1;i<n;i++)
    {
        for(ll j=1;j<=k;j++)
        {
            ll pos=i-j;
            if(pos<0)
                break;
            dp[i] = min (dp[i], dp[pos]+abs(arr[i]-arr[pos]) );
        }
    }
    cout<<dp[n-1];
}



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

#define f first
#define s second
#define p pair<int,int>
#define pb push_back
#define ll long long
#define db double

const int inf=1e9+10;

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    int n,ans=0,ans1=-1,t;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        ans=0;
        int per=i;
        while(per%2==0&&per)
        {
            ans++;
            per/=2;
        }
        if(ans>ans1)
        {
            ans1=ans;
            t=i;
        }
    }
    cout<<t<<endl;
    return 0;
}

Measured memory_bytes: 256
def inc(t):
	n=len(t)
	if n==1:
		if t[0] <9:
			t[0]+=1
		else : t=[1,0]
		return t
	if all(t[i]==9 for i in range(n)):
		t = [1]
		t.extend([0]*n)
		return t
	for i in range(n-1,-1,-1):
		if i==0 or t[i]-t[i-1]<1:
			if t[i]<9:
				t[i]+=1
				for j in range(i+1,n):
					t[j] = max(0,t[j-1]-1)
				return t
			
	

k=int(input())
t = [0]

for i in range(k):
	t = inc(t)
print("".join([str(i) for i in t]))


Measured memory_bytes: 3064
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	a = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	if min(al) == 0:
		return 0
	ret = 1
	for v in al:
		ret *= v
		if ret > 10**18:
			return -1
	return ret
		
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 84604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n); i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)	
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define REVSORT(c) SORT(c);REVERSE(c)
#define ALL(x) (x).begin(),(x).end()
#define LOOP while(true)
#define INF 1e9
const long long MOD = 1000000007;
typedef long long ll;

int main(void){
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	int ans = min(A, B) + min(C, D);
	cout << ans << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> n;
	//vector<ll>	aa(n);
	//for(i=0;i<n;i++) cin >> aa[i];
	ans = n % 1000;
	if (ans!=0) ans = 1000 - ans;
	cout << ans << endl;
	return 0;
}


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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    try {
        ll cnt = 0;
        rep(i, n) {
            string s; cin >> s;
            if (s == "A") ++cnt;
            else --cnt;
            if (cnt < 0) throw 1;
        }
        if (cnt != 0) throw 1;
        cout << "YES" << endl;
    }
    catch (int err) {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3312