akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <iomanip>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
 
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=1e5 + 5;
const int M=1e5 + 5;

vector <int> v[N];
bool vis[N]; 
int clr[N];
bool ok = true;
ll sz=0,bps=0,ups=0;

void dfs(int s, int c)
{
    vis[s]=true;
    sz++;
    clr[s]=c;
    for(int i=0;i<v[s].size();i++){
        int x = v[s][i];
        if(!vis[x]){
            dfs(x,(c+1)%2);
        }
        else{
            if(clr[s]==clr[x]) ok = false;
        }
    }
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    int n,m,i,j;
    cin>>n>>m;
    for(i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    } 
    ll lone=0,bp=0,ubp=0;
    for(i=1;i<=n;i++){
        vis[i]=false;
        clr[i]=-1;
    }
    for(i=1;i<=n;i++){
        if(v[i].size() == 0) lone++;
    }

    for(i=1;i<=n;i++){
        if(v[i].size() == 0) continue;
        if(!vis[i]){
            ok=true;
            dfs(i,0);
            if(ok){
                bp++;
                bps+=sz;
                sz=0;
            }
            else{
                ubp++;
                ups+=sz;
                sz=0;
            }
        }
    }
    ll ans = 0;
    ans += bp*(2*bp + ubp) + lone*bps;
    ans += ubp*(ubp + bp) + lone*ups;
    ans += lone*(n);
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 10112
N = int(input())
A = [int(_) for _ in input().split()]

N_map = {}

for i in range(1, N+1):
    N_map[i] = 0

for i in A:
    if i in N_map:
        N_map[i] += 1

for i in N_map.values():
    print(i)


Measured memory_bytes: 38924
#include<stdio.h>
#include<math.h>
#include<string.h>
int main(){
  int n,d[10],r[60],i,j;
  char s[60][30];
  double e[60],eps=0.000000001;
  while(scanf("%d",&n),n){
  for(i=0;i<n;i++){
    r[i]=i;
    scanf("%s",s[i]);
    for(j=1;j<10;j++)scanf("%d",&d[j]);
    e[i]=1.0*(d[7]*d[8]*d[9]-d[1])/(d[2]+d[3]+d[4]+(d[5]+d[6])*d[9]);
    for(j=i;j;j--){
	if(e[r[j-1]]+eps<e[i]||
	   fabs(e[r[j-1]]-e[i])<eps&&strcmp(s[r[j-1]],s[i])>0)r[j]=r[j-1];
	else break;
    }
    r[j]=i;
  }
  for(i=0;i<n;i++)printf("%s\n",s[r[i]]);
  printf("#\n");
  }
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
int main(){
unsigned long long int ans=0,a,b,c;
cin>>a>>b>>c;
while(c>=1&&a>=1){
    ans++;
    c--;
    a--;
}

while(b>=1&&c>=1){
    b--;
    c--;
    ans=ans+2;
}

while(b>=1){
    b--;
    ans++;
}
if(c>=1){
    ans++;
}
cout<<ans;
return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

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

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

    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double x = (h * 60 + m) / 720 * 2 * PI;
    double y = m / 60 * 2 * PI;

    cout << fixed << setprecision(10);
    cout << sqrt(a * a + b * b - 2 * a * b * cos(x - y)) << endl;

    return 0;
}

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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;


int H,W,T;
string s[10];

int main(){
  string s;
  cin>>s;
  for(int i(0);i<int(s.size())-1;i++){
    if(s[i] == 'A' && s[i+1] == 'C') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
using P = pair<int,int>;

int main(){
    int a; cin >> a;
    int ans = a + pow(a,2) + pow(a,3);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4040
W, H, N = map(int, input().split())

x_min = y_min = 0
x_max = W
y_max = H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        x_min = max(x_min, x)
    elif a == 2:
        x_max = min(x_max, x)
    elif a == 3:
        y_min = max(y_min, y)
    else:
        y_max = min(y_max, y)
print(max(x_max - x_min, 0) * max(y_max - y_min, 0))


Measured memory_bytes: 3060
// myfirstatcoder.cpp : アプリケーションのエントリ ポイントを定義します。

#include "bits/stdc++.h"
#define rep(i,cc,n) for(int i=cc;i<(n);++i)
#define drep(i,cc,n) for(int i=cc;i>(n);--i)
#define llrep(i,cc,n) for(long long i=cc;i<(n);++i)
using namespace std;
using ll = long long;

int Permutation(int N, vector<int> a, vector<int> b)
{
	int count = 0;

	// one_case = {0,1,2,3,...n-1} とする
	vector<int> node(N);
	iota(node.begin(), node.end(), 0);

	// 頂点と辺の探索 → 辺の元：a[i]  辺の先：b[i]
	vector<vector<int>> list(N, vector<int>(N));
	for (int i = 0;i < a.size();++i)
	{
		--a[i];
		--b[i];
		list[a[i]][b[i]] = 1;
		list[b[i]][a[i]] = 1;
	}

	do // 順列の最後になるまで one_case を並び替えながらループ O(N!)
	{
		int load = 1;
		rep(i,1,N)
			if (list[node[i - 1]][node[i]] == 0)
				load = 0;
		if (load)
			++count;
	} while (next_permutation(node.begin() + 1, node.end()));
	return count;
}

int main()
{
	int N,M;
	cin >> N >> M;
	vector<int> a(M), b(M);
	vector<vector<int>> side(M);
	rep(i, 0, M)
	{
		cin >> a[i] >> b[i];
	}

	cout << Permutation(N,a,b) << endl;
	
	return 0;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  string s;
  cin >> s;

  bool ok = false;
  for (int i = 0; ! ok && i < s.size() - 1; i++)
    ok = (s[i] == 'A' && s[i + 1] == 'C');

  if (ok) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#include <atcoder/dsu>
#include <cstdio>

using namespace std;
using namespace atcoder;

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    dsu d(n);

    for(int i; i < m; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        d.merge(a - 1, b - 1);
    }
    int ans = d.groups().size() - 1;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 8268
#include<iostream>
using namespace std;
#define int long long
int n,cnt,i;
int t[18];
main(){
    cin>>n;
    while(n>0){
        t[i]=n%10;
        n/=10;
        i++;
    }
    for(int j=0;j<i-1;j++){
        if(t[j]==9)continue;
        else{
            t[j]=9;
            t[j+1]--;
        }
    }
    for(int j=0;j<i;j++)cnt+=t[j];
    cout<<cnt<<endl;
}

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

using namespace std;
long long m = 1, num = 1;
int k;
long double chet(long long x){
    int sum = 0;
    while(x > 0){
        sum += (x % 10);
        x /= 10;
    }
    return sum;
}
int main(){
    cin >> k;
    for(int i = 1; i <= k; i++){
        cout << num << '\n';
        long long f = num + m, s = num + m * 10;
        if(f / chet(f) <= s / chet(s)){
            num = f;
        }
        else{
            m *= 10;
            num = s;
        }
    }
}


Measured memory_bytes: 256
//ProblemC

//#define USE_STDIO
#define USE_LOG
//#define FILE_ERR

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#ifndef debug
#define debug(...)
#endif // !LOG

#ifndef REDIRECT_STDIO
#define REDIRECT_STDIO {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
#endif // REDIRECT_STDIO

//include
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>

using namespace std;

//int
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;

//pair
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

//vector
template<typename T> using vt = std::vector<T>;
template<typename T> using vvt = vt<vt<T>>;
template<typename T> using vvvt = vt<vvt<T>>;
using vi = vt<int>;
using vvi = vvt<int>;
using vvvi = vvvt<int>;
using vl = vt<ll>;
using vvl = vvt<ll>;
using vvvl = vvvt<ll>;
using vb = vt<bool>;
using vpii = vt<pii>;

static inline void Solve();

int main(int argc, char* argv[]) {
	REDIRECT_STDIO;

	Solve();
	return 0;
}


vvvi gen_ps(const vt<string>& grid) {
	const int h = grid.size();
	const int w = grid[0].size();

	vvvi ans {vvi(h), vvi(w)};
	vvi &ps1 = ans[0];
	for(int i = 0; i < h; i++) {
		ps1[i].push_back(0);
		for(int j = 0; j < w && i + j < h; j++) {
			ps1[i].push_back(ps1[i].back() + (grid[i+j][j] == '#' ? 1 : 0));
		}
	}

	vvi &ps2 = ans[1];
	for(int j = 0; j < w; j++) {
		ps2[j].push_back(0);
		for(int i = 0; i < h && i + j < w; i++) {
			ps2[j].push_back(ps2[j].back() + (grid[i][i+j] == '#' ? 1 : 0));
		}
	}

	return ans;
}

int cnt(const vvvi& pps, int i, int j, int d) {
	if(i >= j && i - j >= (int)pps[0].size()) return 0;
	if(i <= j && j - i >= (int)pps[1].size()) return 0;

	const auto& ps = i >= j ? pps[0][i-j] : pps[1][j-i];
	int s = i >= j ? j : i;
	int e = s + d;

	if(s <= 0) s = 0;
	if(e >= (int)ps.size()) e = ps.size() - 1;
	return ps[e] - ps[s];
}

//ProblemC
void Solve() {
	int h, w; 
	cin >> h >> w;
	vt<string> grid(h);
	for(int i = 0; i < h; i++) cin >> grid[i];

	auto ps1 = gen_ps(grid);
	ll ans = 0;
	for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) {
		if(grid[i][j] != '#') continue;
		for(int d = 1; i + d < h && j + d < w; d++) {
			if(grid[i+d][j+d] != '#') continue;
			ans += cnt(ps1, i - d, j + d, d + 1);
			ans += cnt(ps1, i + d, j - d, d + 1);
		}
	}

	vt<string> gridt = grid;
	for(int i = 0; i < h; i++)  {
		std::reverse(gridt[i].begin(), gridt[i].end());
	}
	auto ps2 = gen_ps(gridt);
	for(int i = 0; i < h; i++) for(int j = 0; j < w; j++)  {
		if(gridt[i][j] != '#') continue;
		for(int d = 1; i + d < h && j + d < w; d++) {
			if(gridt[i+d][j+d] != '#') continue;
			ans += cnt(ps2, i - d + 1, j + d + 1, d - 1);
			ans += cnt(ps2, i + d + 1, j - d + 1, d - 1);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n,dif;
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		int x=read();
		if(x!=i)dif++;
	}
	if(dif==0||dif==2){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	return 0;
}


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

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

	int ans = 0;
	string s;
	cin>>s;
	string temp = "";
	for(int i=0;i<s.length();i++){
			temp += (i % 2 == 0) ? 'g' : 'p';
	}
	ans = s.length() /  2;
	for(int i=0;i<s.length();i++){
			if(s[i] == 'p' && temp[i] == 'g'){
					ans--;
			}
			else if(s[i] == 'p' && temp[i] == 'p')
				ans--;
	}
	
	cout<<ans<<endl;
}



Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int N = 3005;
const int mod = (int) 1e9 + 7;

int n;
string s;
int pref[N];
int npref[N];

// > : dp[i][j] += dp[i - 1][k], k >= j
// < : dp[i][j] += dp[i - 1][k], k < j

int sum(int x, int y) {
  if (y < x) return 0;
  int ans = pref[y] - (x > 0 ? pref[x - 1] : 0);
  return (ans + mod) % mod;
}

int main() {
  cin >> n >> s;
  fill(pref + 1, pref + n + 1, 1);
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= i + 1; j++) {
      if (s[i - 1] == '>') {
        npref[j] = sum(j, n);
      } else {
        npref[j] = pref[j - 1];
      }
    }
    for (int j = 1; j <= n; j++) {
      pref[j] = (npref[j] + pref[j - 1]) % mod;
    }
  }
  cout << pref[n] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int q;
unsigned long long lim;
ll solve (ll x, ll y){
    if(x==y){return 2*(x-1);}
    else{
        ll p = x*y;
        ll a = sqrt(p);
        ll b = p/a;
        if (a*b>=p){b--;}

        ll res = b + (a-1);
        res--;
        return res;
    }
}
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lim=1;
    for(int i=1;i<=18;i++)lim*=10;lim*=2;
    cin>>q;
    for(int cases=1;cases<=q;cases++){
        ll a,b;cin>>a>>b;
        ll ans = solve(a,b);
        cout<<ans<<newl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
using namespace std;
typedef long long int ll;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s,t; cin >> s >> t;
    int res=0;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i])res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 3836
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int a;
	cin>>a;
	int ans=0;
	ans=a+a*a+a*a*a;
	cout<<ans<<endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


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

int main(){
  ll h, n;
  cin >> h >> n;
  ll sum = 0;
  ll tmp;
  for(ll i=0; i<n; i++){
  	cin >> tmp;
    sum += tmp;
  }
  if(sum < h){
  	cout << "No" << endl;
  }else{
  	cout << "Yes" << endl;
  }
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

    vector<int> X(N);

    int sum = 0;
    REP(i,N){
        cin >> X[i];
        sum += X[i];
    }
    int A = sum / N;
    int B = sum / N + 1;
    
    ll ans1 = 0;
    ll ans2 = 0;
    REP(i, N){
        ans1 += (X[i] - A) * (X[i] - A);
        ans2 += (X[i] - B) * (X[i] - B);
    }
    cout << min(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

template<typename Monoid,typename F>
class SegmentTree{
private:
    int sz;
    vector<Monoid> seg;
    const F op;
    const Monoid e;
public:
    SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){
        sz = 1;
        while(sz<=n) sz <<= 1;
        seg.assign(2*sz,e);
    }
    void set(int k, const Monoid &x){
        seg[k+sz] = x;
    }
    void build(){
        for(int i=sz-1;i>0;i--){
            seg[i] = op(seg[2*i],seg[2*i+1]);
        }
    }
    void update(int k,const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k>>=1){
            seg[k] = op(seg[2*k],seg[2*k+1]);
        }
    }
    Monoid query(int l,int r){
        Monoid L = e,R = e;
        for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){
            if(l&1) L = op(L,seg[l++]);
            if(r&1) R = op(seg[--r],R);
        }
        return op(L,R);
    }
    Monoid operator[](const int &k)const{
        return seg[k+sz];
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vec<int> C(N);
    for(int i=0;i<N;i++){
        cin >> C[i];
        C[i]--;
    }
    vec<int> ne(N,N),pos(N,N);
    for(int i=N-1;i>=0;i--){
        ne[i] = pos[C[i]];
        pos[C[i]] = i;
    }
    vvec<pair<int,int>> Q(N);
    for(int i=0;i<M;i++){
        int l,r;
        cin >> l >> r;
        l--; r--;
        Q[l].emplace_back(r,i);
    }
    SegmentTree seg(N+1,[](int a,int b){return a+b;},0);
    for(int i=0;i<N;i++) seg.set(pos[C[i]],1);
    seg.build();
    vec<int> ans(M);
    for(int l=0;l<N;l++){
        for(auto& [r,id]:Q[l]){
            ans[id] = seg.query(l,r+1);
        }
        seg.update(l,0);
        seg.update(ne[l],1);
    }
    for(auto& x:ans) cout << x << "\n";
}


Measured memory_bytes: 37360
#include<bits/stdc++.h>
using namespace std;
#define task "atcoderd"
#define lwb lower_bound
#define upb upper_bound
#define ar array
#define fi first
#define se second
#define ALL(v) (v).begin(), (v).end()
typedef long double ld;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> pii;

int dd[1000005];
void solve()
{
    int k;
    cin>>k;
    ll sum=0,cnt=0;
    while(1)
    {
        sum=(sum*10+7)%k;
        ++cnt;
        if(dd[sum])
        {
            cout<<-1;
            return;
        }
        dd[sum]=1;
        if(sum==0) break;
    }
    cout<<cnt;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    solve();
}







Measured memory_bytes: 7524
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int a,b,ans=0;
	scanf("%d",&a);
	while(a--){
		scanf("%d",&b);
		while(!(b&1)){
			b>>=1;
			++ans;
		}
	}
	printf("%d",ans);
	return 0;
}

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

using namespace std;

int p[100001];

int main () {
	int n;
	cin >> n;
	string a, b;
	cin >> b >> a;     
	a = a + '#' + b;
	for (int i = 1;i < a.size ();i ++) {
		int j = p[i - 1];
		while (j > 0 && a[i] != a[j]) {
			j = p[j - 1];
		}
		if (a[i] == a[j]) j ++;
		p[i] = j;
		//cout << p[i] << ' '; 
	}
	cout << n * 2 - p[a.size () - 1];
	return 0;
}

Measured memory_bytes: 256
# for #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion
class union_find:
    def __init__(self, n):
        self.n = n
        self.rank = [0]*n
        self.parent = [int(j) for j in range(n)]
    
    def union(self,i,j):
        i = self.find(i)
        j = self.find(j)
        if self.rank[i] == self.rank[j]:
            self.parent[i] = j
            self.rank[j] += 1

        elif self.rank[i] > self.rank[j]:
            self.parent[j] = i
        else:
            self.parent[i] = j

    def find(self, i):
        temp = i
        if self.parent[temp] != temp:
            self.parent[temp] = self.find(self.parent[temp])
        return self.parent[temp]
from math import log2, ceil
from collections import deque, Counter as CC, defaultdict as dd
MOD = int(1e9+7)
def main():
# Enter your code here. Read input from STDIN. Print output to STDOUT
    # for t in range(int(input())):
        
        # n = int(input())
        x,k,d = [int(j) for j in input().split()]
        x = abs(x)
        n = (x//d)
        if(k<n):
            ans = x-k*d
        else:
            k = k-n
            a = x-n*d
            if(k%2):
                ans = d-a
            else:
                ans = a
        print(ans)













        



if __name__ == "__main__":
    main()

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

int main(){
  int n,m;
  bool exist=false;
  cin>>n>>m;
  char a[50][50],b[50][50];
  REP(i,n){
    REP(j,n){
    cin>>a[i][j];}
  }
  REP(i,m){
    REP(j,m){
    cin>>b[i][j];}
  }
  for (int i = 0; i < n; i++)
  {
    /* code */
    for (int j = 0; j < n; j++)
    {
      /* code */
      if (i+m-1>=n||j+m-1>=n)
      {
        /* code */
        continue;
      }

      bool copy=true;
      for (int x = 0; x < m; x++)
      {
        /* code */
        for (int y = 0; y < m; y++)
        {
          /* code */
          if (a[i+x][j+y]!=b[x][y])
          {
            /* code */
            copy=false;
          }
          
        }
        
      }
      if (copy)
      {
        /* code */
        exist=true;
      }
       
    }

  }
    if (exist)
    {
      /* code */
      cout<<"Yes"<<endl;
    }
    else
    {
      cout<<"No"<<endl;
    }
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int H, W;
char a[110][110];
bool b[110];
bool c[110];
vector<string> ans;


bool judge(int x){
	rep(i, 0, H)
		if(a[i][x] == '#') return false;
	return true;
}


void solve(){
	rep(i, 0, H)
		if(all_of(RNG(a[i], 0, W), [](char c){ return c == '.'; })) b[i] = true;
	rep(i, 0, W)
		if(judge(i)) c[i] = true;
	rep(i, 0, H){
		if(b[i]) continue;
		rep(j, 0, W){
			if(c[j]) continue;
			cout << a[i][j];
		}
		cout << endl;
	}
}


signed main(){
	cin >> H >> W;
	rep(i, 0, H)
		rep(j, 0, W) cin >> a[i][j];

	solve();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <cmath>
#include <bitset>

using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
  ll N,X,T;
  cin >> N >> X >> T;

  if(N%X==0){
    cout << T*N/X << endl;
  }else{
    cout << T*(N/X+1) << endl;
  }
  
}

Measured memory_bytes: 3676
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
    int sum=0;
    char a[6];
    cin>>a;
    for(int i=0;i<6;i++)
    {
        if(a[i]=='1')sum++;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 764
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

template<typename T> bool chmin(T& a, const T& b) {
    if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
    if (a < b) return a = b, true; else return false;
}

// End of template.


int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a;
        cin >> a;
        n -= a;
    }

    print(max(n, -1));

    return 0;
}



Measured memory_bytes: 3644
import java.util.Scanner;

/**
 * Created by shoya on 2017/04/11.
 */

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

        UFT uft = new UFT(n);
        for (int i = 0; i < q; i++){
            int com = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            if (com == 0)
                uft.unite(x, y);
            else{
                if(uft.same(x, y))
                    System.out.println(1);
                else
                    System.out.println(0);
            }
            //uft.print();
            //System.out.println();
        }
    }

    private static class UFT {
        int size;
        int rootsOfNodes[];

        UFT(int n){
            size = n;
            int i = 1;
            while (i < n) i *= 2;
            rootsOfNodes = new int[n];
            for (int j = 0; j < n; j++)
                rootsOfNodes[j] = j;
        }

        private int depth(int node, int depth){
            if (node == rootsOfNodes[node])
                return depth;
            return depth(rootsOfNodes[node], depth + 1);
        }

        void unite(int x, int y){
            int lower;
            int root;
            if (depth(x, 0) > depth(y, 0)) {
                lower = x;
                root = root(y);
            }
            else {
                lower = y;
                root = root(x);
            }
            while(lower != rootsOfNodes[lower]){
                int next = rootsOfNodes[lower];
                rootsOfNodes[lower] = root;
                lower = next;
            }
            rootsOfNodes[lower] = root;
        }

        private int root(int node) {
            if (node == rootsOfNodes[node])
                return node;
            return root(rootsOfNodes[node]);
        }

        boolean same(int x, int y){
            return root(x) == root(y);
        }

        void print(){
            for (int i = 0; i < size; i++)
                System.out.printf("%d <-- Root -- %d\n", rootsOfNodes[i], i);
        }

    }
}

Measured memory_bytes: 99104
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, h: "List[int]"):
    INF = 10000000000
    dp = [INF]* (N+1)
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    for i in range(2,N):
        for t in range(1,K+1):
            if(i-t >= 0):
                dp[i] = min(dp[i], dp[i-t]+abs(h[i]-h[i-t]))
        # print(dp)
    print(dp[N-1])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 53404
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc144/tasks/abc144_e>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,K; cin >> N >> K;
    vector<ll> A(N),F(N);
    
    for(auto& in:A) cin >> in;
    for(auto& in:F) cin >> in;

    sort(A.begin(),A.end());
    sort(F.rbegin(),F.rend());

    //　二分探索
    auto ok = [&](ll m){
        ll leftK = K;
        for(int i = 0; i < N;i++){
            ll Lower = m/F[i];
            leftK -= max(0LL,A[i]-Lower);
            if(leftK < 0) break;
        }
        return leftK >= 0;
    };
    
    
    ll l = -1, r = LINF;
    while((r-l)>1){
        ll m = (l+r)/2;
        if(ok(m)) r = m;
        else l = m;
    }
    res = r;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 3328
n,k=map(int,input().split())
x=[0]*n
y=[0]*n
a=[]
for i in range(n):
  x[i],y[i]=map(int,input().split())
  a.append((x[i],y[i]))
ans=4*(10**18)
x.sort()
y.sort()
for i in range(n-1):
  for j in range(i+1,n):
    for l in range(n-1):
      for m in range(l+1,n):
        L=x[i]
        R=x[j]
        D=y[l]
        U=y[m]
        if L==R or U==D:
          continue
        cnt=0
        for s in a:
          if L<=s[0]<=R and D<=s[1]<=U:
            cnt+=1
        if cnt>=k:
          ans=min(ans,(R-L)*(U-D))
print(ans)

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

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

  int cnt_e = 0, cnt_w = 0;
  for (char c : S)
    if (c == 'E') cnt_e++;

  int ans = 1001001001;

  for (int i = 0; i < N; ++i) {
    if (S.at(i) == 'E') cnt_e--;
    ans = min(ans, cnt_e + cnt_w);
    if (S.at(i) == 'W') cnt_w++;
  }

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


Measured memory_bytes: 3872
#include <iostream>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <cstdio>
#include <string>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
    int n,m,u,v;
    cin>>n>>m;
    map<int,map<int,int> >arr;
    for(int i = 1; i <= m; i++){
        cin>>u>>v;
        arr[u][v];
        arr[v][u];
    }
    for(int i = 2; i < n; i++){
        if(arr[1].find(i) != arr[1].end() && arr[n].find(i) != arr[n].end()){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 37760
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int main()
{
	#define int long long
	int n;
	cin >> n;
	double a[n];
	double ans = 0;
	for(int i = 0; i < n; i++)
	cin >> a[i];
	sort(a,a+n);
	ans += (a[0]+a[1])/2;
	for(int i = 2; i < n; i++)
	{
		ans = (ans+a[i])/2;
	}
	cout << setprecision(10) << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int vis[2005];
int main()
{

    double a,b;
    //char s[5];
    scanf("%lf%lf",&a,&b);
    double x=a*12.5,y=b*10;
    int c=(int)(x+0.5),d=(int)(y+0.5);
    int e=(int)(x+13),f=(int)(y+10.5);
    //printf("%d %d %d %d\n",c,d,e,f);
    for(int i=c;i<e;i++)vis[i]=1;
    bool ff=0;
    for(int i=d;i<f;i++)
    {
        if(vis[i])
        {
            f=1;
            printf("%d\n",i);
            return 0;
        }
    }
    printf("-1\n");
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std; 
int main() {
    string s; cin >> s;
    int n   ; cin >> n;
    string m;
    int a, b;
    string rep;
    for (int i = 0; i < n; i++)
    {
        cin >> m ;
        if(m == "print"){
            cin >> a >> b;
            cout << s.substr(a,b-a+1) << endl;
        }else if(m == "replace"){
            cin >> a >> b >> rep;
            s = s.replace(a,b-a+1,rep);
        }else if(m == "reverse"){
            cin >> a >> b ;
            reverse(s.begin()+a,s.begin()+b+1);
        }
    }
    
    return 0;
}


Measured memory_bytes: 3228
#include <cmath>
#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
    int n, k;
    double ans = 0;
    scanf("%d %d", &n, &k);

    for(int i=1; i<=n; i++)
    {
        if(k < i)
        {
            ans +=1;
            continue;
        }
        double p = ceil(log2(double(k)/double(i)));
        ans += pow(0.5, p);
    }
    ans /= n;

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N,A,B,C,D;
	cin >> N;
	A = N % 10; /*1桁目 */
	B = N % 100 - A;/* 2桁目 */
  	C = N % 1000 - A -10*B; /* 3桁目 */
  	D = N - A - 10*B - 100*C; /* 4桁目 */
  	if (B==C&&(A==B||C==D)){
  		cout << "Yes" << endl;
  	} else {
  		cout << "No" << endl;
  	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, n;
  in(n);
  a = n / 500;
  b = n % 500;
  b = b / 5;
  b = b * 5;
  a = a * 1000;
  out(a + b);
  memi;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-12;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> K;
	vector<long long int>dp(K + 10001, MOD*MOD);
	dp[0] = 0;
	cin >> N;
	while (N--) {
		cin >> L >> R;
		for (int i = L; i <= K+10000; i++) {
			dp[i] = min(dp[i], dp[i - L] + R);
		}
	}
	long long int ans = MOD * MOD;
	for (int i = K; i <= K + 10000; i++)ans = min(ans, dp[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
 
int main() {
	int n, now;
	scanf("%d", &n);
	now = 7 % n;
	for (int i = 1; i <= n; i++) {
		if (now == 0) {
			printf("%d\n", i);
			return 0;
		}
		now = (now * 10 + 7) % n;
	}
	printf("-1\n");
}

Measured memory_bytes: 1704
def split(n, a, b, used, ai, ans, width):
    # print(n, a, b, used, ai, ans, width)
    # print(*(f'{c:5d}' for c in ans))
    # print(*(f'{c:05b}' for c in ans))
    if width == 2:
        ans[ai] = a
        ans[ai + 1] = b
        return
    x = a ^ b
    y = x & -x  # Rightmost Bit where is different a and b
    l = y.bit_length() - 1
    used.append(l)
    i = 0
    for i in range(n):
        if i not in used:
            break
    la, lb = a, a ^ (1 << i)
    ra, rb = lb ^ y, b
    width >>= 1
    split(n, la, lb, used, ai, ans, width)
    split(n, ra, rb, used, ai + width, ans, width)
    used.pop()


def solve(n, a, b):
    if bin(a).count('1') % 2 == bin(b).count('1') % 2:
        print('NO')
        return
    used = []
    ans = [0] * (1 << n)
    split(n, a, b, used, 0, ans, 1 << n)
    print('YES')
    print(*ans)


n, a, b = list(map(int, input().split()))
solve(n, a, b)


Measured memory_bytes: 11364
import java.util.*;
import java.io.*;

class Main {

	void solve() {
		
		out.println(isPalindrome(instr())==true ? "Yes" : "No");
		
	}
	
	static boolean isPalindrome (String s) {
		int n = s.length();
		for (int i=0; i<n/2; i++) {
			if (s.charAt(i)!=s.charAt(n-i-1)) {return false;}
		}
		return true;
	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}
	
	public String instr() {
		return in.next();
	}

	public char inchar() {
		return in.next().charAt(0);
	}
	
	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

}

Measured memory_bytes: 21716
/*******************
  Ankit Sahu
  SRMIST Chennai
 ***********************/

#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define mp make_pair
#define mt make_tuple
#define gcd(a,b) (_gcd((a),(b)))
#define lcm(a,b) ((a*b)/gcd(a,b))
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forr(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pr pair<ll,ll>
#define vp vector<pr>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    cout << fixed;
    string a,b;
    cin>>a>>b;
    bool flag=true;
    for(int i=0;i<a.length();i++){
    	if(a[i]!=b[i]){
    		flag=false;
    		break;
		}
	}
	
	if(flag==false or ((b.length()-1)!=a.length())) cout<<"No";
	else cout<<"Yes";


	return 0;
}






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


using namespace std;


using ll = long long;
mt19937 mt(736);


void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n;

	cin >> n;

	vector<int> arr (n);

	for (auto &it : arr)
		cin >> it;

	set<int> types (arr.begin (), arr.end ());

	if (types.size () == 1)
	{
		cout << ((*types.begin ()) == 0 ? "Yes" : "No") << endl;

		return;
	}

	if (n % 3 == 0)
	{
		int x = 0;

		for (auto it : types)
			x ^= it;

		if (x == 0 && types.size () == 3 && count (arr.begin (), arr.end (), *types.begin()) == n / 3 &&
			count (arr.begin (), arr.end (), *types.rbegin()) == n / 3)
		{
			cout << "Yes" << endl;

			return;
		}

		if (types.size () == 2 && (*types.begin ()) == 0 && count (arr.begin (), arr.end (), *types.rbegin()) == 2 * n / 3)
		{
			cout << "Yes" << endl;

			return;
		}
	}

	cout << "No" << endl;
}


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

	cout << fixed;

#ifdef LOCAL
	ifstream fin("../input.txt");

	solve(fin);

	cout << setprecision(4);
	cout << "clock: " << clock() / (double) CLOCKS_PER_SEC << endl;
#else
	solve();
#endif

	return 0;
}


Measured memory_bytes: 4224