akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<stdio.h>
using namespace std;

int main() {
    int A[100],a[100],n,m,i,ii;
    int p[100] = {0};
    cin >> n >> m;
    for(i = 0;i < m;i++){
        cin >> a[i];        //???????????????????°???????a
    }
    for(i = 0;i < m;i++){
        for(ii = 0;ii < n;ii++){
            cin>>A[ii];
        }
        for(ii = 0;ii < n;ii++){
            if(A[ii]==a[i]){
                p[ii] += 1;
            }else{
                p[a[i]-1] +=1;
            }
        }
    }
    
    for(i = 0;i < n;i++){
        cout << p[i] << endl;
    }
}

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

#define INF INT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

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

    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    REP(i,n)cin >> h[i];

    vector<int> dp(n,INF);
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);

    for(int i=2;i < n;i++){
        int min_v = INF;
        for(int j = 1;j <= k && i-j>=0;j++){
            // cout << j << endl;
            min_v = min(min_v,dp[i-j] + abs(h[i-j]-h[i]));
        }
        dp[i] = min_v;
    }

    cout << dp[n-1] << endl;
    return 0;
}    

Measured memory_bytes: 1024
import fractions

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

l = [0] * n
r = [0] * n
l[0] = a[0]
r[n-1] = a[n-1]
for i in range(1, n):
  l[i] = fractions.gcd(l[i-1], a[i])
  r[n-1-i] = fractions.gcd(r[n-i], a[n-1-i])

maxgcd = 0
for i in range(n):
  if i == 0:
    maxgcd = max(maxgcd, r[1])
  elif i == (n-1):
    maxgcd = max(maxgcd, l[n-2])
  else:
    maxgcd = max(maxgcd, fractions.gcd(l[i-1], r[i+1]))

print (maxgcd)

Measured memory_bytes: 89580
#include <iostream>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <cmath>
#include <cstring>
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;

char c[200000];

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

    rep0(i, N)
    {
        cin >> c[i];
    }

    int w=0, r=0;
    int count = 0;

    while (true)
    {
        rep(w,w, N)
        {
            if (c[w] == 'W')
                break;
        }
        rep(r,r, N)
        {
            if (c[N-r-1] == 'R')
                break;
        }
        if(w==N-r)
            break;
        else
        {
            c[w]='R';
            c[N-r-1]='W';
            count++;
        }
    }

    cout << count << endl;
    return 0;
}

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

string s;

int main(){
	cin>>s;
	if(s == "A"){
		cout<<"T"<<endl;
	}else if(s == "T"){
		cout<<"A"<<endl;
	}else if(s == "C"){
		cout<<"G"<<endl;
	}else if(s == "G"){
		cout<<"C"<<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 erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using Tuple = tuple<int, int, int>;


int main() {
    ll n,a,b; cin >> n >> a >> b;
    vector<ll> x(n);
    rep(i, n) cin >> x[i];

    ll ans = 0;
    rep(i, n-1) {
        ans += min((a*(x[i+1]-x[i])), b);
    }

    cout << ans << endl;
}


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

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

    for(int c = 0; c <= x; c++) {
        int t = x - c;
        int asi = 2*c+4*t;
        if(y == asi) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
fun main(args: Array<String>) {
    val K = nextInt()
    val ans = mutableListOf<Long>()
    (0 .. 9).forEach { ans.add(it.toLong()) }
    var p = 1
    while (p < K) {
        val x = ans[p++]
//System.err.println(x)
        val r = x % 10
        if (r != 0L) ans.add(10 * x - 1 + r)
        ans.add(10 * x + r)
        if (r != 9L) ans.add(10 * x + 1 + r)
    }
    println(ans[K])
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)


Measured memory_bytes: 40488
#include <bits/stdc++.h>
#include <cctype>
#define pb push_back 
#define ll long long 
#define forit(it,a) for(_typeof(a.begin()) it =a.begin();it!=a.end();it++)
#define mp make_apir 

using namespace std;

int main(){
	char t;
	cin >> t;
	if(isupper(t)){
		cout << 'A'<<"\n";
	}
	else{
		cout <<'a'<<"\n";
	}
	
	return 0;
}

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

vector<int> v[100005];

lli dp[100005] = {};
struct ufind {
    vector<int> par;
    vector<int> rank;
    vector<int> count;
    ufind(int n)
    {
        par.resize(n);
        rank.resize(n);
        count.resize(n);


        rep(i, n)
        {
            par[i] = i;
            rank[i] = 0;
            count[i] = 1;
        }
    }
    int find(int x)
    {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
};
vector<int> e[100005];
#define MAX 100010
class Scc
{
public:
    vector<int> e[MAX];
    vector<int> re[MAX];
    vector<int> vs;
    bool used[MAX];
    int cmp[MAX];
    int v;
    Scc(){};
    Scc(int v) : v(v) {}
    void add_edge(int from, int to)
    {
        e[from].push_back(to);
        re[to].push_back(from);
    }
    void dfs(int v)
    {
        used[v] = true;
        rep(i, e[v].size()) if (!used[e[v][i]]) dfs(e[v][i]);
        vs.push_back(v);
    }
    void rdfs(int v, int k)
    {
        used[v] = true;
        cmp[v] = k;
        rep(i, re[v].size()) if (!used[re[v][i]]) rdfs(re[v][i], k);
    }
    int scc()
    {
        rep(i, MAX) used[i] = false;
        vs.clear();
        rep(i, v) if (!used[i]) dfs(i);
        int k = 0;
        rep(i, MAX) used[i] = false;
        rrep(i, vs.size()) if (!used[vs[i]]) rdfs(vs[i], k++);
        return k;
    }
};
int main()
{

    int n, m;

    cin >> n >> m;

    Scc s(n);
    map<int, map<int, lli>> di;
    int l, r, d;
    rep(i, m)
    {
        cin >> l >> r >> d;
        l--, r--;
        s.add_edge(l, r);
        di[l][r] = d;
    }
    int k = s.scc();

    rep(i, n)
    {
        v[s.cmp[i]].push_back(i);
        for (auto ss : di[i]) {
            if (s.cmp[i] == s.cmp[ss.first]) {
                if (ss.second != 0) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    rep(i, k)
    {
        for (auto ss : v[i]) {
            for (auto sss : di[ss]) {
                int nxt = s.cmp[sss.first];
                int dist = dp[s.cmp[sss.first]];
                if (dist == 0) {
                    dp[s.cmp[sss.first]] = dp[i] + sss.second;
                } else if (dp[s.cmp[sss.first]] != dp[i] + sss.second) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 42104
#include <iostream>
#include <map>  
#include <algorithm>


int main()
{
	int N, a;
	std::map<int, int> counter;
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		std::cin >> a;
		auto itr = counter.find(a); 
		if (itr != counter.end()) {
			counter[a]++;
		}
		else {
			counter[a] = 1;
		}
	}

	int sum = 0;
	for (auto itr = counter.begin(); itr != counter.end(); ++itr) {
		if (itr->second - itr->first >= 0) {
			sum += itr->second - itr->first;
		}
		else{
			sum += itr->second;
		}
		
	}

	std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 4736
#include <iostream>

using namespace std;

void solve(int n) {}

int main() {
    int t;
    cin >>t ;
    if(t <= 1000)
        cout << (1000 - t);
    else {
        int f = t;
        int c = 1;
        while(t/10 > 0) {
            c = c * 10;
            t=t/10;
        }
//        cout << t << endl;
//        cout << c <<endl;
        int z = (t * c) - f;
        if(z < 0){
            cout << ( (t+1) * c) - f;
        }else{
            cout << z;
        }

    }
    return 0;
}


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

long long gcd(long long a, long long b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

long long lcm(long long a, long long b){
    return (a * b) / gcd(a, b);        
}

int main(){
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long e = min(c, d);
    long long f = max(c, d);
    long long g = lcm(c, d);
    long long tmp = (b - a + 1);
    long long x = b / e - a / e;
    if(a % e == 0){
        x += 1;
    }
    long long y = b / f - a / f;
    if(a % f == 0){
        y += 1;
    }
    long long z = b / g - a / g;
    if(a % g == 0){
        z += 1;
    }
    long long ans = (b - a + 1) - (x + y - z);
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll m;
  cin>>m;
  vll d(m),c(m);
  REP(i,m)cin>>d[i]>>c[i];


  ll sum_c=-1;
  ll sum_d=-1;
  REP(i,m){
    sum_c+=c[i];
    sum_d+=d[i]*c[i];
  }

  ll ans=sum_c+sum_d/9;
  cout<<ans<<endl;
}



Measured memory_bytes: 6308
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

const int mod = 1e9+7;

int n;
int k;
int q;
int cm[N];

int main(){
    scanf("%d%d%d" , &n , &k , &q);
    while(q--){
        int x;
        scanf("%d" , &x);
        cm[0]--;
        cm[x]++;
        cm[x+1]--;
        cm[n+1]++;
    }
    for(int i = 1; i <= n; i++){
        cm[i] += cm[i - 1];
        if(k+cm[i] > 0){
            puts("Yes");
        } else {
            puts("No");
        }
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
string tmp,ch;
char a,k;
int n,i,j,ans,temp,ans2;
int main()
{
	cin>>n;
	cin>>ch;
	tmp=ch;
	ans=0;
	for(i=1;i<n;i++)
	{
		ans2=0;
		string tmpa,tmpb;
		tmpa=ch.substr(0,i);
		tmpb=ch.substr(i,n);
		for(k='a';k<='z';k++)
		{
			int finda,findb;
			finda=tmpa.find(k);
			findb=tmpb.find(k);
			if(finda!=string::npos && findb!=string::npos)
				ans2++;
		}
		ans=max(ans,ans2);
	}
	cout<<ans;
	return 0;
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
int main() {
  int n;cin>>n;
  bool ans=false;
  int mx=0;
  int sum=0;
  REP(i,n){
    int p;cin>>p;
    sum+=p;
    mx=max(mx,p);
  }
  sum-=mx/2;
  cout << sum << endl;
}

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

int a[1000000];

int main(){

  a[0] = 1;
  a[1] = 1;

  for(int i=2;i*i<1000000;i++){
    if(!a[i]){
      for(int j=i+i;j<1000000;j+=i) a[j] = 1;
    }
  }

  int n;

  while(cin >> n, n){

    int ans = 0;

    for(int i=2;i<=n/2;i++){
      if(!a[i] && !a[n-i]) ans++;
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 5064
#include <bits/stdc++.h>
#define int long long
#define double long double
#define N 100010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T> void prArr(T a,string s=" "){int i=0;for(auto t:a)cout<<i++? s:""<<t;cout<<endl;}

int n,y;
int used[2010][2010];

void dfs(int cnt,int mon,int a,int b,int c){


  
  if(cnt == n) {
    if(mon == y){
      cout<<a<<" "<<b<<" "<<c<<endl;
      exit(0);
    }
    return;
  }
  if(mon > y) return; 
  if(used[cnt][mon]++) return;

  dfs(cnt+1,mon+10,a+1,b,c);
  dfs(cnt+1,mon+5,a,b+1,c);
  dfs(cnt+1,mon+1,a,b,c+1);
  
}


signed main(){

  cin>>n>>y;
  y/=1000;

  dfs(0,0,0,0,0);
  cout<<-1<<" "<<-1<<" "<<-1<<endl;

  return 0;
}


Measured memory_bytes: 30976
z=[]
ac=[]
wa=[]
tle=[]
re=[]
a=int(input())
for i in range(a):
    b=input()
    z.append(b)
for i in z:
    if i=='AC':
        ac.append(1)
for i in z:
    if i=='WA':
        wa.append(1)
for i in z:
    if i=='TLE':
        tle.append(1)
for i in z:
    if i=='RE':
        re.append(1)
        
print('AC x ',len(ac))
print('WA x ',len(wa))
print('TLE x ',len(tle))
print('RE x ',len(re))

Measured memory_bytes: 16928
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstring>
using namespace std;
#define Maxn 5005
#define LL long long
const int mod = 1e9+7;
int n,h[Maxn],p[Maxn];
char s[Maxn];
map<int,int>M;
bool check(int s)
{
    M.clear();
    for(int i=s;i<=n;i++) 
    {
        int t=(h[i]-(LL)h[i-s]*p[s]%mod+mod)%mod;
        int pre=M[t];
        if(pre) 
        {
            if(i-pre>=s) return true; 
        }
        else M[t]=i;
    }
    return false;
}
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    p[0]=1; h[0]=0;
    for(int i=1;i<=n;i++) h[i]=((LL)h[i-1]*29+s[i])%mod,p[i]=(LL)p[i-1]*29%mod;
    int l=0,r=n;
    while(l<r)
    {
        int mid=(l+r+1)>>1;
        if(check(mid))l=mid;
        else r=mid-1;
    }
    printf("%d\n",l);
    return 0;
}

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

int main() {
    int n, k, s;
    int A = 1000000000;
    scanf("%d %d %d", &n, &k, &s);
    for (int i = 0; i < n; i++) {
        if (i < k)
            printf("%d ", s);
        else if (s != A)
            printf("%d ", s + 1);
        else printf("%d ", A - 1);
    }
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define ll long long
//不要再爆long long了！！！！！！！！不要再爆long long了！！！！！！！ 

int main()
{
	long double b;
	ll a;
	cin>>a>>b;
	ll c=a*b;
	printf("%lld",c);
	return 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)

int N, M;
double L, P[110], T[110], V[110];
double p[110][55];

void solve() {
	for_(i,0,N) {
		double dp[55][55] = { 0.0 }, pi = P[i] / 100.;
		dp[0][0] = 1.0;
		
		for_(j,0,M) for_(k,0,M) {
			dp[j+1][k] += dp[j][k] * (1.0 - pi);
			dp[j+1][k+1] += dp[j][k] * pi;
		}
		
		for_(k,0,M+1) p[i][k] = dp[M][k];
	}
	
	for_(i,0,N) {
		double ans = 0.0;
		
		if (V[i] > 0) {
			for_(j,0,M+1) {
				double t1 = L / V[i] + (j * T[i]);
				double mul = 1.0;
				
				for_(ii,0,N) {
					if (i != ii && V[ii] > 0) {
						double mii = 0.0;								
						double t2 = L / V[ii] + (M * T[ii]);
						
						for_rev(k,M,0) {
							if (t2 - t1 < 1e-9) break;
							mii += p[ii][k];
							t2 -= T[ii];
						}
					
						mul *= mii;
					}
				}
				
				ans += mul * p[i][j];
			}
		}
		
		printf("%.9lf\n", (N == 1) ? 1.0 : ans);
	}
}

int main() {
	cin >> N >> M >> L;
	for_(i,0,N) cin >> P[i] >> T[i] >> V[i];
	
	solve();
	
	return 0;
}

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

int main()
{
    string s, t;
    cin >> s >> t;
    int ans = 0;
    rep(i, 0, s.size()){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3836
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 200005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

const ll mod=1000000007;
vector <int> mp[maxn];
ll fac[maxn],inv[maxn],siz[maxn],n,ans[maxn];

inline ll pw(ll a,ll b)
{
	ll ans=1,base=a;
	while(b)
	{
		if(b&1) ans=(ans*base)%mod;
		base=(base*base)%mod; b>>=1;
	}
	return ans;
}

inline void dfs1(int u,int fa)
{
	siz[u]=1;
	for(int i=0;i<mp[u].size();i++)
	{
		int v=mp[u][i]; if(v==fa) continue;
		dfs1(v,u); siz[u]+=siz[v];
	}
}

inline void dfs2(int u,int fa)
{
	for(int i=0;i<mp[u].size();i++)
	{
		int v=mp[u][i]; if(v==fa) continue;
		ans[v]=(ans[u]*pw(n-siz[v],mod-2)%mod)*siz[v]%mod; dfs2(v,u);
	}
}

int main()
{
	n=read(); fac[0]=1; inv[0]=1;
	for(int i=1;i<=maxn-5;i++) fac[i]=(fac[i-1]*i)%mod;
	for(int i=1;i<=maxn-5;i++) inv[i]=pw(fac[i],mod-2);
	for(int i=1;i<n;i++)
	{
		int u=read(),v=read();
		mp[u].push_back(v),mp[v].push_back(u);
	}
	dfs1(1,0); ll tmp=fac[n];
	for(int i=1;i<=n;i++) tmp=(tmp*pw(siz[i],mod-2))%mod; ans[1]=tmp;
	dfs2(1,0);
	for(int i=1;i<=n;i++) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 20212
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for _ in range(d)]
C=sum(c)
tot=0
mem=[0]*26
for i in range(d):
	t=int(input())
	mem[t-1]=i+1
	tot+=s[i][t-1]
	for j in range(26):
		tot-=c[j]*((i+1)-mem[j])
	print(tot)

Measured memory_bytes: 9372
N = int(input())
C = [int(input()) for _ in range(N)]
MOD = 10**9 + 7

dp = [0] * (N + 1)
colorToIndex = [-1] * (max(C) + 10)
colorToIndex[C[0]] = 0
dp[0] = 1

for i, color in enumerate(C[1:], start=1):
    prevIndex = colorToIndex[color]
    dp[i] = dp[i - 1]

    if prevIndex != i - 1:
        dp[i] += dp[prevIndex]

    dp[i] %= MOD
    colorToIndex[color] = i

ans = dp[N - 1]
print(ans)


Measured memory_bytes: 25996
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    int n, m;
    cin >> n >> m;
    vector<long long> h(n);
    rep(i, n) cin >> h[i];
    vector<bool> ans(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;

        if (h[a-1] < h[b-1]) ans[a-1] = true;
        else if (h[a-1] > h[b-1]) ans[b-1] = true;
        else {
            ans[a-1] = true;
            ans[b-1] = true;
        }
    }

    int cnt = 0;
    rep(i, n) {
        if (ans[i] == false) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 4052
N=gets.to_i
A=gets.split.map(&:to_i)
data=Hash.new(0)
A.each do |aa|
    data[aa] += 1
end

ans=0
data.each do |k,v|
    if k < v
        ans += v - k
    elsif k > v
        ans += v
    end
end

p ans


Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define long long long // for codeforces

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

  int n;
  long a,d;
  int m;
  cin>>n>>a>>d>>m;

  vector<int> x(m), y(m), z(m);
  rep(i,m) cin>>x[i]>>y[i]>>z[i];
  rep(i,m) y[i]--,z[i]--;
  int k;
  cin>>k;
  k--;

  for(int i=m-1; i>=0; i--){
    if(x[i]==0 && y[i]<=k && k<=z[i]){
      k = y[i] + z[i] - k;
    }
  }

  long ans = a + d*k;
  rep(i,m) if(y[i]<=k && k<=z[i]){
    if(x[i]==0){
      k = y[i] + z[i] - k;
    }
    else if(x[i]==1){
      ans++;
    }
    else if(x[i]==2){
      ans /= 2;
    }
    else assert(false);
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 4856
#M=0 A=1 R=2 C=3 H=4
p = [0,0,0,0,0,0,1,1,1,2]
q = [1,1,1,2,2,3,2,2,3,3]
r = [2,3,4,3,4,4,3,4,4,4]

n = int(input())
name = [0,0,0,0,0]
for i in range(n):
    s = input()
    if s[0] == 'M':
        name[0] += 1
    elif s[0] == 'A':
        name[1] += 1
    elif s[0] == 'R':
        name[2] += 1
    elif s[0] == 'C':
        name[3] += 1
    elif s[0] == 'H':
        name[4] += 1

ans = 0
for i in range(10):
    ans += name[p[i]] * name[q[i]] * name[r[i]]

print(ans)

Measured memory_bytes: 9168
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

const LL MOD = 998244353;

const int N = 300;
LL dp[N+1][N*N+1] = {{0}};
LL dp2[N+1][N*N+1] = {{0}};

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    VL a(n);
    REP(i,n)cin>>a[i];
    LL s = 0;
    REP(i,n) s += a[i];

    dp[0][0] = 1;
    REP(i,n){
        REP(j, N*N+1)if(dp[i][j]>0){
            dp[i+1][j] = (dp[i+1][j] + dp[i][j] * 2) % MOD;
            dp[i+1][j + a[i]] = (dp[i+1][j + a[i]] + dp[i][j]) % MOD;
        }
    }
    dp2[0][0] = 1;
    REP(i,n){
        REP(j, N*N+1)if(dp2[i][j]>0){
            dp2[i+1][j] = (dp2[i+1][j] + dp2[i][j]) % MOD;
            dp2[i+1][j + a[i]] = (dp2[i+1][j + a[i]] + dp2[i][j]) % MOD;
        }
    }


    LL ans = 3;
    REP(i, n - 1) ans = (ans * 3) % MOD;
    LL s2 = (s+1)/2;
    LL count = 0;
    FOR(i,s2, N*N+1)count = (count + dp[n][i]) % MOD;
    ans = (ans - count + MOD) % MOD;
    ans = (ans - count + MOD) % MOD;
    ans = (ans - count + MOD) % MOD;
    if(s % 2 == 0){
        ans = (ans + dp2[n][s2] * 3) % MOD;
    }
    PUTS(ans);

    //REP(i, N*N+1)if(dp[n][i]>0)cout<<i<<","<<dp[n][i]<<endl;
    //REP(i, N*N+1)if(dp2[n][i]>0)cout<<i<<","<<dp2[n][i]<<endl;
}

Measured memory_bytes: 421504
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#define Rint register int
#define mem(a,b) memset(a,(b),sizeof(a))
#define Temp template<typename T>
using namespace std;
typedef long long LL;
Temp inline void read(T &x){
    x=0;T w=1,ch=getchar();
    while(!isdigit(ch)&&ch!='-')ch=getchar();
    if(ch=='-')w=-1,ch=getchar();
    while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^'0'),ch=getchar();
    x=x*w;
}

int a,b;
bool flag=1;

int main(){
	read(a);read(b);
	char ch;
	for(Rint i=1;i<=a;i++){
		cin>>ch;
		if(!isdigit(ch))flag=0;
	}
	cin>>ch;
	if(ch!='-')flag=0;
	for(Rint i=1;i<=b;i++){
		cin>>ch;
		if(!isdigit(ch))flag=0;
	}
	if(flag)printf("Yes\n");
	else printf("No\n");
}


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

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

  int x; cin >> x;
  int y; cin >> y;
  ll ans = 0;
  if (y > x) {
    if (y >= 0 && x >= 0) {
      ans = y - x;
    } else if (y == 0) {
      ans = -x;
    } else if (y >= 0 && x < 0) {
      if (y == -x) ans = 1;
      else if (y > -x) ans = 1 + (y + x);
      else ans = 1 - (y + x);
    } else {
      ans = y - x;
    }
  } else {
    if (y == 0 || x == 0) {
      ans = 1 + (x - y);
    } else if (x >= 0 && y >= 0) {
      ans = 1 + (x - y) + 1;
    } else if (x >= 0 && y < 0) {
      if (x == -y) ans = 1;
      else if (x > -y) ans = 1 + (x + y);
      else ans = 1 - (x + y);
    } else {
      ans = 1 + (-y + x) + 1;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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 (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  ll k,q;
  cin>>k>>q;
  vector<ll> d(k);
  for(ll i = 0LL; i < k; i++) cin>>d[i];
  for(ll i = 0LL; i < q; i++){
    ll n,x,m;
    cin>>n>>x>>m;
    vector<ll> S(k,0LL);
    for(ll j = 0LL; j < k; j++){
      ll t = d[j]%m;
      if(t==0LL) t+=m;
      if(j==0LL)S[j]=t;
      else S[j]=S[j-1]+t;
    }
    ll total = x%m + ((n-1LL)/k)*S[k-1];
    if((n-1LL)%k!=0LL) total += S[((n-1LL)%k)-1LL];
    ll ans = n-(total/m)-1LL;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 384
// Daniel Grzegorzewski
// while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

int k;
int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
  init_ios();
  cin >> k;
  --k;
  cout<<a[k]<<"\n";
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N ,K;
  int a = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (0 < x < K) {
      if (x - 0 < K - x) {a += (x - 0) * 2; continue;}
      else {a += (K - x) * 2; continue;}
    }
    if (0 < K < x) {a += (K - x);}}
  cout << a << endl;
}

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

int main(){
  int64_t A,B,V,W,T;
  cin >> A >> V >> B >> W >> T;
  int64_t C=abs(B-A),D=V-W;
  if(D<=0){
    cout << "NO" << endl;
  }
  else if(C<=T*D){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}   

Measured memory_bytes: 3640
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = 0;
        
        for(int i = a;i <= b;i++){
            if(c % i ==0)x++;
            
        }
        System.out.printf("%d\n",x);
    }
}


Measured memory_bytes: 26504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define Would
#define you
#define please

int main() {
	//おまじない
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	int saidai = 2 * max(X, Y);
	int saishou = 1000000000;

	rep(i, saidai + 1) {
		int X2 = X - i / 2;
		int Y2 = Y - i / 2;
		if (X2 < 0) X2 = 0;
		if (Y2 < 0) Y2 = 0;
		int cost = i * C + X2 * A + Y2 * B;
		saishou = min(saishou, cost);
	}

	co(saishou);
	Would you please return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
const int loose = 0;
const int tight = 1;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


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

	ll h, a;
	cin >> h >> a;

	if (h % a == 0) {
		cout << h / a << endl;
	}
	else {
		cout << h / a + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = []#生徒たちが出席した順番
rev = [0]*N #早く来た順の生徒の番号

for x in input().split():
    A.append(int(x))

for i in range(N):
    rev[A[i]-1] = i+1

print(' '.join(map(str,rev)))

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

int main(){
  int N, A;
  cin >> N;
  
  int count=0;
  int answer=31;
  for (int i=0; i<N; i++){
    cin >> A;
    
    if (A%2 == 0){
      
      
      for (int j=0; A%2 == 0; j++){
        A /=2;
        //cout << i << "A:"<< A;;
        count++; 
        //cout << "count:" << count << endl;
      }
      
      if (count <= answer){
        answer = count;
        count = 0;
        //cout << "ans:" << answer << endl;
      }
      else{
        count = 0;
      }
      
    }
    
    else{
      answer = 0;
      break;
    }
    
    
      
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
const main = (input) => {
  const s = input.trim()

  let count = 0
  let max = 0

  for (let i=0; i<s.length; i++) {
    if (s[i] === 'R') {
      count++
      max = Math.max(max, count)
    } else count = 0

  }

  return console.log(max)
}

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29688
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

//"Never let your head hang down. Never give up and sit down and grieve. Find another way." - Satchel Paige

void solve() {
	int r;
	cin >> r;
	cout << r * r << endl;
}

int main(){
#define MULTITEST 0
#if MULTITEST   
 
    CASET {
        solve();
    }
    
#else

    solve();
    
#endif

    return 0;
}

Measured memory_bytes: 3584
#!/usr/bin/env python
# coding: utf-8

# In[24]:


from collections import Counter


# In[34]:


s = input()


# In[36]:


mylist = [x for x,c in sorted(Counter(s).items(), key=lambda x: x[1], reverse=True)]
ans = len(s)
for w in mylist:
    myword = s
    cnt = 0
    while len(set(myword)) > 1 and cnt <= ans:
        cnt += 1
        tmp = []
        for i in range(len(myword)-1):
            if myword[i] == w or myword[i+1] == w:
                tmp.append(w)
            else:
                tmp.append(myword[i])
        myword = tmp
    ans = min(cnt, ans)
#     print(myword)
print(ans)


# In[ ]:






Measured memory_bytes: 9340
N=int(input())
S=input()

count=0
for p in range(10):
    s=S.find(str(p))
    if s==-1:
        continue
    for q in range(10):
        t=S.find(str(q),s+1)
        if t==-1:
            continue
        for r in range(10):
            u=S.find(str(r),t+1)
            if u!=-1:
                count+=1
print(count)

Measured memory_bytes: 9212
def resolve():
    from collections import deque
    q = int(input())
    ans = deque()
    for _ in range(q):
        q = [int(i) for i in input().split()]
        if q[0] == 2:
            if q[1] == 0:
                ans.popleft()
            else:
                ans.pop()
        else:
            if q[0] == 0:
                if q[1] == 0:
                    ans.appendleft(q[2])
                else:
                    ans.append(q[2])
            else:
                print(ans[q[1]])


resolve()



Measured memory_bytes: 21960
#include <iostream>
#include <bitset>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <set>
#include <map>


using namespace std;

int main(){
	int x, y;
	scanf("%d%d", &x, &y);
	printf("%d", (x + (y / 2)));
	return 0;
}

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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define ll long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define inf 1e18
#define vll vector<ll>
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define flr(i,a,b) for(ll i=a;i>b;i--)
#define print(v) for(auto i=v.begin();i!=v.end();i++){cout<<*i<<" ";}cout<<"\n";
#define MOD 1000000007

ll ncr(ll n, ll r){
	ll ans = 1;
	flr(i,n,n-r){
		ans*=i;
	}
	ll rfac = 1;
	fl(i,1,r+1)
		rfac*=i;
	return ans/rfac;
}
int main()
{
    speed;
    ll n,m; cin>>n>>m;
    cout<< ncr(n,2)+ncr(m,2);
    return 0;
}


Measured memory_bytes: 256
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int n,k;
int p[5005],c[5005],vis[5005];
int32_t main() 
{
    IOS;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>p[i];
    for(int i=1;i<=n;i++)
        cin>>c[i];
    int maxans=-1e18;
    for(int i=1;i<=n;i++)
    {
        vector<int>v;
        int sum=0;
        while(!vis[i])
        {
            vis[i]=1;
            v.push_back(i);
            sum+=c[i];
            i=p[i];
        }
        if(v.size()==0)
            continue;
        if(v.size()==1)
        {
            int val=c[v[0]];
            if(val>0)
                maxans=max(maxans,val*k);
            else
                maxans=max(maxans,val);
            continue;
        }
        int ans=0;
        int sz=v.size();
        int left=k;
        if(sum>0)
        {
            ans=(k/sz)*sum;
            left=k-(k/sz)*sz;
            if(left==0)
            {
                left=sz;
                ans-=sum;
            }
        }
        else
        {
            sum=0;
            left=min(k,sz);
        }
        int arr[2*sz+10]={};
        for(int i=1;i<=sz;i++)
            arr[i]=c[v[i-1]];
        for(int i=sz+1;i<=2*sz;i++)
            arr[i]=arr[i-sz];
        int maxval=-1e18;
        for(int i=1;i<=sz;i++)
        {
            int sum1=ans;
            for(int j=i;j<=min(2*sz,i+left-1);j++)
            {
                sum1+=arr[j];
                maxval=max(maxval,sum1);
            }
        }
        maxans=max(maxval,maxans);
    }
    print(maxans);
}

Measured memory_bytes: 3956
#include<stdio.h>
int main(void)
{
	int N,A;
	scanf("%d",&N);

	if(N<10){
		A=N;
	}else if(N<100){
		A=9;
	}else if(N<1000){
		A=9+N-99;
	}else if(N<10000){
		A=909;
	}else if(N<100000){
		A=909+N-9999;
	}else{
		A=90909;
	}
	printf("%d",A);
	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
s = list(input())
del s[-1] #/r消し
dainalist = [0]*(len(s)+1)
syounalist = [0]*(len(s)+1)

for i in range(len(s)):
  if s[i] == "<":
    dainalist[i+1] = dainalist[i] + 1
for i in range(len(s)-1,-1,-1):
  if s[i] == ">":
    syounalist[i] = syounalist[i+1] + 1
ans = 0
for i in range(len(dainalist)):
  ans += max(dainalist[i],syounalist[i])
 
print(ans)

Measured memory_bytes: 97664
import sys
from functools import lru_cache
sys.setrecursionlimit(10**9)

def mul(x, y, mod):
  x %= mod
  y %= mod
  return x * y % mod

def div(x, y, mod):
  x %= mod
  y %= mod
  return x * mod_pow(y, mod - 2, mod) % mod

@lru_cache(maxsize=None)
def mod_pow(a, p, mod):
  if p == 0:
    return 1
  if p % 2 == 0:
    root = mod_pow(a, p / 2, mod)
    return root * root % mod
  else:
    return a * mod_pow(a, p - 1, mod) % mod

def dnm(n, mod, factorials):
  denominators = [0] * (n + 1)
  denominators[n] = div(1, factorials, mod)
  for i in reversed(range(n)):
    denominators[i] = mul(denominators[i+1], i+1, mod)
  return denominators

def nmr(n, mod):
  factorials = [0] * (n + 1)
  factorials[0] = 1
  for i in range(n):
    factorials[i + 1] = (i + 1) * factorials[i] % mod
  return factorials

def cmb(a, b, mod, factorials, factorial_divs):
    if len(factorials) == 0:
        raise
    af = factorials[a]
    bf = factorial_divs[b]
    abf = factorial_divs[a - b]
    return mul(mul(af, bf, mod), abf, mod)

MOD=10**9+7
H,W,A,B=map(int,input().split())
ans = 0

n = nmr(H+W-2, MOD)
d = dnm(H+W-2, MOD, n[H+W-2])

for i in range(H-A):
  x = cmb(B-1+i, B-1, MOD, n, d)
  y = cmb(H+W-3-(B-1+i), W-B-1, MOD, n, d)
  ans += x * y % MOD
  ans %= MOD

print(ans)

Measured memory_bytes: 25428
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn=new Scanner(System.in);
        int year=scn.nextInt();
        int flag=0;
        switch(year){
            case 3:
            case 5:
            case 7:
            flag++;
        }
        if(flag==1){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 23124
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define srep(i) for (int i = 0; i < s.size(); i++)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
    using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int n, w;
int weight[105] = {}, value[105] = {};

int dp[105][10005] = {};

int main()
{
    int n,a,b,ans=0;
    cin >> n;
    rep(i,0,n){
        cin>>a>>b;
        ans+=b-a+1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.String.format;

/**
 * Created by Seiya on 2016/10/16.
 */
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String a = scanner.next();
        String b = scanner.next();
        String c = scanner.next();


        System.out.println(a.charAt(0) + "" + b.charAt(0) + "" + c.charAt(0)) ;


    }
}




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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

int main() {
    int a,b,n = 0,m,l = 1;
    cin >> a >> b;
    m = b;

    while(m > 0){
        m/=10;
        n++;
    }
    rep(i,0,n) l *= 10;
    a = (a*l)+b;

    rep(i,0,1000){
        if(i*i == a){
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,a,ans=1,cnt=1;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a;
    ans*=3;
    if(a%2==0) {
      cnt*=2;
    }
  }
  cout << ans-cnt << endl;
}

Measured memory_bytes: 256
/**
  @date Time-stamp: <2019-05-14 21:32:14 tagashira>
  @file a.cpp
  @brief https://atcoder.jp/contests/abc124/tasks/abc124_c
**/

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

  string S;
  cin >> S;

  // @ref https://atcoder.jp/contests/abc124/submissions/4942940
  if (S.size() == 1) {
    cout << "0"
         << "\n";
  } else {
    int pattern0 = 0;
    int pattern1 = 0;

    string a = "", b = "";
    for (int i = 0; i < S.length(); i++) {
      if (i % 2 == 0) {
        a += "0";
        b += "1";
      } else {
        a += "1";
        b += "0";
      }
    }

    for (i = 0; i < S.length(); i++) {
      if (S[i] != a[i]) pattern0++;
      if (S[i] != b[i]) pattern1++;
    }

    cout << min(pattern0, pattern1) << "\n";
  }

  return 0;
}


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

void judgement(int a,int b,int c) {
	if (a == b && b == c || a <= 0 || b <= 0 || c <= 0) {
		cout << "NO" << endl;
		return;
	}
	else if ((a*a) == (b*b) + (c*c) || (b*b) == (a*a) + (c*c) || (c*c) == (a*a) + (b*b)) {
		cout << "YES" << endl;
		return;
	}
	else {
		cout << "NO" << endl;
		return;
	}
}

int main() {
	unsigned int n;//dataset

	cin >> n;

	vector<int> vector_a;
	vector<int> vector_b;
	vector<int> vector_c;

	for (int i = 0; i < n; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		vector_a.push_back(a);
		vector_b.push_back(b);
		vector_c.push_back(c);
	}

	for (int i = 0; i < n; i++) {
		judgement(vector_a[i], vector_b[i], vector_c[i]);
	}

	return 0;

}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define vii vector<ll> 
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const int MOD = 1e9 + 7, N = 1e4 + 3;

int main(){
    fast;
    ll n;
    cin >> n;
    ll a[n], ans = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; i += 2)
    {
        if(a[i]%2 != 0) ++ans;
    }
    cout << ans;
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
#include<string.h>
#include<math.h>
char s1[1000000],s2[1000002];
#define ll long long int
ll ar1[100000],ar2[100000];
int main()
{
    ll a,b,c,d,i;
    cin>>a;
    cin>>s1;
    c=0;
    for(i=0;i<a;i++)
    {
        if(s1[i]=='A' && s1[i+1]=='B' && s1[i+2]=='C'){c++;i+=2;}
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define ll long long int
using namespace std;

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

    vector <ll> v(n);
    for(ll i = 0; i < n; i ++)
    {
    	cin >> v[i];
    }

    ll ans = 0;
    if(v[0] > x)
    {
    	ans = ans + v[0] - x;
    	v[0] = x;
    }
    for(ll i = 0; i < n - 1; i ++)
    {
    	ll check = v[i] + v[i + 1];
    	if(check > x)
    	{
    		ans = ans + v[i + 1] + v[i] - x;
    		v[i + 1] = x - v[i];

    	}
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
/* B - Multiple of 9 */

#include <stdio.h>

int main(void){
  char N[200001], *ptr;
  int num = 0;
  scanf("%s", N);
  ptr = N;
  while(*ptr){
    num += *ptr - '0';
    ptr++;
  }
  if(num % 9 == 0){
    puts("Yes");
  }else{
    puts("No");
  }
  return 0;
}


Measured memory_bytes: 1808
#include<cstdio>
int main(void)
{
	double a,b,c,d,e,f;
	double x,y;
	while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF)
	{
		y=(a*f-d*c)/(-(d*b)+a*e);
		x=(c-b*y)/a;
		if(x==0)
		{
			x=0;
		}
		if(y==0)
		{
			y=0;
		}
		printf("%.3lf %.3lf\n",x,y);
	}
	return 0;
}
/*
ax=c-by
->x=(c-by)/a
d((c-by)/a)+ey=f
(dc-dby)/a+ey=f
(dc-dby)+aey=af
-dby+aey=af-dc
y(-db+ae)=af-dc
->y=(af-dc)/(-db+ae)
*/

Measured memory_bytes: 1080