akhauriyash/Code-Regression huggingface dataset:
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/14/20 20:53:44
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int x,y; cin>>x>>y;
  if (4*x >= y and (4*x-y)%2==0 and (4*x-y)/2 <= x) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
int main()
{
    //freopen("a.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    int n=s.length();
    string tmp=s;
    reverse(tmp.begin(),tmp.end());
    bool flag=tmp==s;
   	for(int i=0;i<n/2;i++){
   		if(s[i]!=s[n/2-1-i])flag=false;
   	}
   	for(int i=n/2+1;i<n;i++){
   	    if(s[i]!=s[n+n/2-i])flag=false;
   	}
   	cout<<(flag?"Yes\n":"No\n");

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int price = a + b + c - max(a, max(b, c));
    cout << price << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

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


using namespace std;


int main() {

	int a,b,c,d;
	char in;
	cin >> in;
	a=in-'0';
	cin >> in;
	b=in-'0';
	cin >> in;
	c=in-'0';
	cin >> in;
	d=in-'0';
	for(int i=0;i<2;i++){
		int ans;
		if(i)
			ans=a+b;
		else
			ans=a-b;
		for(int j=0;j<2;j++){
			int ans1;
			if(j)
				ans1=ans+c;
			else
				ans1=ans-c;
			for(int k=0;k<2;k++){
				int ans2;
				if(k)
					ans2=ans1+d;
				else
					ans2=ans1-d;
				if(ans2==7){
					cout << a;
					cout << (i?'+':'-');
					cout << b;
					cout << (j?'+':'-');
					cout << c;
					cout << ((k)?'+':'-');
					cout << d;
					cout << '=' << 7;
					return 0;
				}
			}
		}
	}

}

Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = (1e9)+7;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  ll n;
  cin>>n;
  ll ans = 1;
  for(ll i=1;i<=n;i++){
  	ans*=i;
  	ans%=MOD;
  }
  cout<<ans<<endl;
}




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


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    table = [0] * (N + 1)
    for i, (s1, s2) in enumerate(zip(S, S[1:]), 1):
        table[i+1] = table[i] + (1 if s1 == 'A' and s2 == 'C' else 0)
    for ll, rr in zip(l, r):
        yield table[rr] - table[ll]

# Generated by 1.1.6 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
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]"
    r = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    for r in solve(N, Q, S, l, r):
        print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15828
n = int(input())
li = list(map(int, input().split()))

for i in range(n-1):
    if li[i] > li[i+1]:
        li[i+1] += 1

if any(li[i] > li[i+1] for i in range(n-1)):
    print("No")
else:
    print("Yes")

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

using namespace std;

int main(){
  vector<string>when;
  when={ "SUN","MON","TUE","WED","THU","FRI","SAT"};
  vector<int>vec;
  vec={7,6,5,4,3,2,1};
  string s;
  cin>>s;
  for(int i=0;i<7;i++){
    if(s==when[i]){
      cout<<vec[i]<<endl;
    }
  }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int x;cin>>x;
    int l=360/__gcd(x,360)*x;
    int ans=l/x;
    cout<<ans<<endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define ll long long
#define vi vector <int>
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define PI 3.14159265359
/*
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
 
using namespace __gnu_pbds;
typedef tree<pii,null_type,less <pii>,rb_tree_tag,tree_order_statistics_node_update>ind_set;
*/
///*X.find_by_order("index")
///X.order_of_key("key")
 
 
 
#define deb(x) cerr<<#x<< " : " <<x<<"\n";
#ifndef local
	#define deb(x) ;
#endif
///----------------------------------------------------------------------------------

int n;
int arr[200005];
int S1[200005],S2[200005];
void solve()
{
	cin>>n;
	rep(i,0,n)cin>>arr[i];rep(i,0,n)arr[i+n]=arr[i];

	
	rep(i,0,2*n)
	{
		if (i&1)
		{
			S1[i]=S1[i-1]-arr[i];
			S2[i]=S2[i-1]+arr[i];

		}
		else
		{
			S1[i]=(i==0?0:S1[i-1]);
			S1[i]+=arr[i];
			S2[i]=(i==0?0:S2[i-1]);
			S2[i]-=arr[i];
		}
	}
	rep(i,0,n)
	{
		if (i&1)
		{
			int val=S2[i+n-1]-(S2[i-1]);
			cout<<val<<" ";
		}
		else
		{
			int val=S1[i+n-1]-(i==0?0:S1[i-1]);
			cout<<val<<" ";
		}
	}


}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
 
    #ifdef local
    ///freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    clock_t qwertyuiop = clock();
    #endif
 
 
    int t=1;
    ///cin>>t;
    
    rep(a,0,t)
    {
        ///cout<<"Case #"<<a+1<<": ";
        solve();
    }
    #ifdef local
	{qwertyuiop = clock() - qwertyuiop;double time_taken = ((double)qwertyuiop)/CLOCKS_PER_SEC;cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "<<time_taken<<" seconds\n";}
	#endif
}

Measured memory_bytes: 6016
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;
typedef long long ll;

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main()
{
    string s;
    cin >> s;
    
    reverse(s.begin(), s.end());
    for(int i = 0; i < 4; i++){
        reverse(divide[i].begin(), divide[i].end());
    }
    bool can = true;
    for(int i = 0; i < s.size();){
        bool can2 = false;
        for(int j = 0; j < 4; j++){
            string d = divide[j];
            if(s.substr(i,d.size()) == d){
                can2 = true;
                i += d.size();
            }
        }
        if(!can2){
            can = false;
            break;
        }
    }
    if(can){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
   
using namespace std;
typedef long long int ll;
  
int main()
{
	int n;
  scanf("%d", &n);
  printf("%d\n", n*(n+1)/2);
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int f[10];

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        for(int i=1;i<=3;i++)
        {
                int a,b;
                cin>>a>>b;
                f[a]++;
                f[b]++;
        }
        sort(f+1,f+5);
        if(f[1]==1 && f[2]==1 && f[3]==2 && f[4]==2)
        {
                cout<<"YES\n";
        }
        else
        {
                cout<<"NO\n";
        }
        return 0;
}
/**

**/


Measured memory_bytes: 256
double M,M0,M1,a[20][3];
n,i,j,k,v[20];
D(depth,m,c){
	if(m==0){
		for(M0=i=0;i<depth-1;i++)for(j=i+1;j<depth;j++)M0+=(a[v[i]][0]-a[v[j]][0])*(a[v[i]][0]-a[v[j]][0])+(a[v[i]][1]-a[v[j]][1])*(a[v[i]][1]-a[v[j]][1])+(a[v[i]][2]-a[v[j]][2])*(a[v[i]][2]-a[v[j]][2]);
		if(M<M0)M=M0;
	}else for(;c<=n-m;c++)v[depth]=c,D(depth+1,m-1,c+1);
}
main(m){
	scanf("%d%d",&n,&m);
	if(m<2)puts("0"),exit(0);
	for(i=0;i<n;i++)for(j=0;j<3;j++)scanf("%lf",a[i]+j);
	M=0;D(0,m,0);
	printf("%f\n",M),exit(0);
}

Measured memory_bytes: 664
n, t = map(int, input().split())
case = []
for i in range(n):
  c = list(map(int, input().split()))
  case.append(c)
mini = 1e9
for i in range(n):
  if(t>= case[i][1]):
    if(mini>case[i][0]):
      mini = case[i][0]
if(mini == 1e9):
  print("TLE")
else:
  print(mini)

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

using namespace std;

int main() {
	int R,G,B,N;
	cin>>R>>G>>B>>N;
	int64_t ans=0;
	for (int i=0;i<=N;++i) {
		for (int j=0;j<=N;++j) {
			int t = i*R+j*G;
			int r=N-t;
			if (r>=0 && r%B==0) ++ans;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mp make_pair
#define pi pair<int,int>
#define pl pair<long long int,long long int>
#define pb push_back
#define fi first
#define se second
#define len(a) (int)(a).length()
#define sz(a) (int)(a).size()

using namespace std;

const int M = 1e9 + 7;
int n, a[21][21], dp[21][(1<<21)];

int fn(int x, int y) {
	if (dp[x][y] != -1) return dp[x][y];
	else dp[x][y] = 0;
	for (int i=0; i<n; ++i)
		if ((y & (1<<i)) && a[x][i])
			dp[x][y] = (dp[x][y] + fn(x+1, y-(1<<i))) %M;
	return dp[x][y];
}

int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	for (int i=0; i<n; ++i)
		for (int j=0; j<n; ++j)
			cin >> a[i][j];
	memset(dp, -1, sizeof(dp));
	for (int i=0; i<n; ++i)
		dp[n-1][(1<<i)] = a[n-1][i];
	for (int i=0; i<(1<<n); ++i)
		if (dp[n-1][i] == -1) dp[n-1][i] = 0;
	cout << fn(0, ((1<<n) - 1)) << endl;
	return 0;
}


Measured memory_bytes: 172288
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let r: usize = read();
    println!("{}", 3 * r * r);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define pb push_back
#define un unordered_map
#define us unordered_set
#define ll long long
#define l long 
using namespace std;
const int  mod= 1e9+7;
const int inf=1e9+3;


 int main()
 {
   
   // 3rd
 ll n;
  cin>>n;
  vector<ll>v(n);
  for(ll i=0;  i<n; i++)
   cin>>v[i];
   
    ll maxi=v[0];
    ll sum=0;
    for( ll j=1; j<n; j++)
    {
        if(v[j]<maxi)
        {
            sum+=(maxi-v[j]);
        }
        else if(v[j]>maxi)
        maxi=v[j];
    }
    cout<<sum;
        
        
       return 0;
     
 }
  

Measured memory_bytes: 4748
#include <cstdio>
#include <algorithm>
using namespace std;

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

const int INF = 100000000;
const int MAX_V = 100;
int graph[MAX_V][MAX_V];
int N, k;

bool visited[MAX_V];
int cost[MAX_V];

void init_graph() {
    REP(i, N) {
        REP(j, N) {
            if (i == j) graph[i][j] = 0;
            else        graph[i][j] = INF;
        }
    }
}

void solve() {

    while (true) {
        scanf("%d %d", &N, &k);

        if (N == 0 and k == 0)
            break;

        init_graph();

        REP(_, k) {
            int mode;
            scanf("%d", &mode);
            if (mode == 0) {
                int a, b;
                scanf("%d %d", &a, &b);
                a--; b--;
                if (graph[a][b] < INF) {
                    printf("%d\n", graph[a][b]);
                } else {
                    printf("-1\n");
                }
            } else {
                int c, d, e;
                scanf("%d %d %d", &c, &d, &e);
                c--; d--;
                if (e < graph[c][d]) {
                    graph[c][d] = graph[d][c] = e;
                    REP(i, N) {
                        REP(j, N) {
                            graph[i][j] = min(graph[i][j], graph[i][c] + graph[c][d] + graph[d][j]);
                            graph[i][j] = min(graph[i][j], graph[i][d] + graph[d][c] + graph[c][j]);
                        }
                    }
                }
            }
        }
    }
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 1080
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int N, K;
    while(cin >> N >> K){
        vector<vector<int>> num(2*K, vector<int>(2*K, 0));
        for(int i=0;i<N;i++){
            int x, y; char c;
            cin >> x >> y >> c;
            if(c == 'B') x += K;
            x %= 2 * K;
            y %= 2 * K;
            int sx = 0, sy = 0;
            while(x + sx * K > 0) --sx;
            while(y + sy * K > 0) --sy;
            for(int j=sx;x+j*K<2*K;j++){
                for(int k=sy;y+k*K<2*K;k++){
                    int nx = max(0, x+j*K);
                    int ny = max(0, y+k*K);
                    int dif = (j > sx && k > sy ? 2 : 1);
                    if((j+k+100)%2 == 0) num[ny][nx] += dif;
                    else if(nx > 0 || ny > 0) num[ny][nx] -= dif;
                }
            }
        }
        int res = 0;
        for(int i=0;i<2*K;i++){
            for(int j=1;j<2*K;j++) num[i][j] += num[i][j-1];
        }
        for(int i=0;i<2*K;i++){
            for(int j=1;j<2*K;j++) num[j][i] += num[j-1][i];
        }
        for(int i=0;i<2*K;i++){
            for(int j=0;j<2*K;j++){
                res = max(res, num[i][j]);
            }
        }
        cout << res << endl;
    }
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li v[55];
li c[55];

int main() {
    li n;
    cin >> n;
    rin{
        cin >> v[i];
    }
    rin{
        cin >> c[i];
    }
    li res = 0;
    rin{
        if (v[i] - c[i] > 0) {
            res += v[i] - c[i];
        }
    }
    cout << res << endl;



    return 0;
}

Measured memory_bytes: 256
#include<map>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
int n,ans;
bool check(int x) {
	int res=0;
	for(int i=1;i<=x;i+=2)
		if(x%i==0) res++;
	return (res==8);	
}
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i+=2)
		if(check(i)) ans++;
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;

int main(){
    long long n, m;
    cin >> n >> m;
    vector<long long> a(n), ps(n);
    map<long long, long long> mp;
    long long ans = 0;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        ps[i] = a[i];
        if(i) ps[i] += ps[i - 1];
        ps[i] %= m;
        if(!ps[i]) ans++;
        ans += mp[ps[i]];
        mp[ps[i]]++;
    }
    cout << ans;
}

Measured memory_bytes: 5760
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
from sys import stdin
from collections import Counter
import sys
NUM = [[0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0],
       [0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
paper = Counter()

for line in sys.stdin:
    x, y, size = (int(s) for s in line.split(','))
 
    xidx = [x, x-1, x, x+1, x-2, x-1, x, x+1, x+2, x-1, x, x+1, x]
    yidx = [y-2, y-1, y-1, y-1, y, y, y, y, y, y+1, y+1, y+1, y+2]
    val = NUM[size-1]
 
    for a, b, i in zip(xidx, yidx, xrange(len(xidx))):
        if a < 0 or 9 < a or b < 0 or 9 < b:
            continue
        paper[a + b * 10] += val[i]
 
print(sum(1 for i in xrange(100) if not paper[i]))
print(max(paper[i] for i in xrange(100)))

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

using namespace std;

#define int long long

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k, r, s, p;
    cin >> n >> k;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    for (int i = 0; i < k; ++i)
    {
        t.push_back('p');
    }
    string ans;
    map<char, char> m;
    map<char, int> cnt;
    m['r'] = 'p';
    m['p'] = 's';
    m['s'] = 'r';
    cnt['r'] = r;
    cnt['s'] = s;
    cnt['p'] = p;
    int res = 0;
    for (int i = 0; i < n; ++i)
    {
        if (i < k || ans[i - k] != m[t[i]])
        {
            ans.push_back(m[t[i]]);
            res += cnt[ans[i]];
        }
        else
        {
            char c = 'r';
            while (c == ans[i - k] || c == m[t[i + k]])
            {
                c = m[c];
            }
            ans.push_back(c);
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
	int c1, c2, c3;

	while ( cin >> c1 >> c2 >> c3 )
	{
		set<int> drawed;
		drawed.insert( c1 );
		drawed.insert( c2 );
		drawed.insert( c3 );

		int sum = c1 + c2, total = 0, count = 0;

		for ( int i = 1; i <= 10; i++ )
		{
			if ( drawed.find( i ) == drawed.end() )
			{
				total++;

				if ( sum + i <= 20 )
				{
					count++;
				}
			}
		}

		cout << ( 0.5 <= count / (double)total ? "YES" : "NO" ) << endl;
	}

	return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

ll x[MAXN], y[MAXN];

void solve(){
	int n, m;
	scanf("%d%d", &n, &m);
	ll sumx = 0;
	REP(i, 0, n){
		scanf("%lld", &x[i]);
		sumx = (sumx + x[i] * (2 * i - (n - 1))) % MOD;
	}
	ll sumy = 0;
	REP(i, 0, m){
		scanf("%lld", &y[i]);
		sumy = (sumy + y[i] * (2 * i - (m - 1))) % MOD;
	}
	ll ans = (sumx * sumy) % MOD;
	printf("%lld\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod =1e9+7;
const int N = (int)2e5 + 5;

void mul(ll &x, ll y){
	x *= y;
	x %= mod;
}
 
void add(ll &x, ll y){
	x = x + y + mod;
	x %= mod;
}
ll binpow(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve(){
	string s;
	cin>>s;
	int q;
	cin>>q;
	bool ok=1;
	string beg="";
	string last="";
	while(q--){
		int t;
		cin>>t;
		if(t==1){
			ok=!ok;
		}
		else{
			int x;
			cin>>x;
			char c;
			cin>>c;
			string t="";
			t+=c;
			if(x==1){
				if(ok){
					beg+=t;
				}
				else{
					last+=t;
				}
			}
			else{
				if(ok){
					last+=t;
				}
				else{
					beg+=t;
				}
			}
		}
	}
	string bas="",aiagy="";
	for(int i=sz(beg)-1;i>=0;i--){
		bas+=beg[i];
	}
	string ans="";
	ans+=bas;
	ans+=s;	
	ans+=last;
	if(!ok){
		for(int i=sz(ans)-1;i>=0;i--)cout<<ans[i];
	}
	else {
		cout<<ans;
	}
	

}


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

Measured memory_bytes: 1580
def main():
    S = input()
    K = int(input())
    
    lengths = []
    s = S[0]
    prev = S[0]
    length = 1
    for s in S[1:]:
        if s == prev:
            length += 1
        else:
            lengths.append([prev, length])
            length = 1
        prev = s
    lengths.append([s, length])

    if len(lengths) == 1:
        ans = lengths[0][1] * K // 2
    else:
        if lengths[0][0] == lengths[-1][0]:
            joint_len = lengths[0][1] + lengths[-1][1]
            ans = lengths[0][1] // 2
            ans += sum([i[1]//2 for i in lengths[1:-1]]) * K
            ans += joint_len // 2 * (K-1)
            ans += lengths[-1][1] // 2
        else:
            ans = sum([i[1]//2 for i in lengths]) * K
    print(ans)
main()

Measured memory_bytes: 3064
object Main {
  def main(args: Array[String]): Unit = {
    val scanner = new java.util.Scanner(System.in)
    val t, s, e, w, n, b = scanner.nextInt
    val com = scanner.next

    var dice = Dice(t, n, e, s, w, b)
    for(c <- com) {
      c match {
        case 'N' => dice = dice.rotN()
        case 'S' => dice = dice.rotS()
        case 'E' => dice = dice.rotE()
        case  _  => dice = dice.rotW()
      }
    }
    println(dice.t)
  }
}

case class Dice(t: Int, n: Int, e: Int, s: Int, w: Int, b: Int) {
  def rotN(): Dice = Dice(s, t, e, b, w, n)
  def rotS(): Dice = Dice(n, b, e, t, w, s)
  def rotW(): Dice = Dice(e, n, b, s, t, w)
  def rotE(): Dice = Dice(w, n, t, s, b, e)
}



Measured memory_bytes: 45160
def primeFactor(N):
    i, n, ret, d, sq = 2, N, {}, 2, 99
    while i <= sq:
        k = 0
        while n % i == 0: n, k, ret[i] = n//i, k+1, k+1
        if k > 0 or i == 97: sq = int(n**(1/2)+0.5)
        if i < 4: i = i * 2 - 1
        else: i, d = i+d, d^6
    if n > 1: ret[n] = 1
    return ret

def divisors(N):
    pf = primeFactor(N)
    ret = [1]
    for p in pf:
        ret_prev = ret
        ret = []
        for i in range(pf[p]+1):
            for r in ret_prev:
                ret.append(r * (p ** i))
    return sorted(ret)

def f(b, n):
    re = 0
    while n:
        re += n % b
        n //= b
    return re

N = int(input())
S = int(input())
if N < S:
    print(-1)
elif N == S:
    print(N+1)
else:
    for b in divisors(N-S):
        b += 1
        if f(b, N) == S:
            print(b)
            break
    else:
        print(-1)


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
//i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;


int main(int argc, char **argv) {
    i64 n;
    cin >>n;
    string s;
    cin >>s;
    vector<i64> v(s.size(), 0);

    i64 num_red{0};
    for (i64 i=0; i<s.size(); ++i) {
        if (s[i]=='R') {
            ++num_red;
            v[i]=1;
        }
    }
    i64 left_w{0}, right_r;
    for (i64 i=0; i<num_red; ++i) {
        if (v[i]==0) ++left_w;
    }

    cout << left_w << endl;
    return 0;
}

Measured memory_bytes: 5236
N, M, X = map(int, input().split())
items = []
for _ in range(N):
    tmps = list(map(int, input().split()))
    price = tmps[0]
    l = tmps[1:]
    items.append((price, l))
n = len(items)
patterns = []

for i in range(2 ** n):
    bag = []
    for j in range(n):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            bag.append(items[j])  # フラグが立っていたら bag に果物を詰める
    patterns.append(bag)

ans = 100000000000
for pattern in patterns:
    sum_price = 0
    sum_l = [0 for _ in range(M)]
    for price, l in pattern:
        sum_price += price
        for i in range(M):
            sum_l[i] += l[i]
    check = True
    for i in range(M):
        if sum_l[i] < X:
            check = False
    if check:
        ans = min(ans, sum_price)

if ans ==  100000000000:
    print(-1)
else:
    print(ans)



    



Measured memory_bytes: 9400
// 入力nを変数に保持
var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim();
var n = parseInt(input, 10);

// 出力用文字列を初期化
var sOut = "" + n + ":";

// 因数2から順番に素因数分解
var iPrime = 2;

// nが1になったら終了
while (n !== 1) {
	// iPrimeがnの因数
	if (n % iPrime === 0) {
		sOut += " " + iPrime;
		n = n / iPrime;
	// iPrimeがnの因数でない、次のiPrimeを使う
	} else {
		iPrime++;
	}
}

// 結果を出力
console.log(sOut);


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

int main() {
	int n;
	cin >> n;
	vector<string> s(n);
	int min_size = 51;
	string minstr;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		if (min_size > s[i].size()) {
			min_size = s[i].size();
			minstr = s[i];
		}
	}
	string ans = "";
	for (int i = 0; i < min_size; i++) {// i th judge
		int count = 0;
		for (int j = 0; j < n; j++) {// j th string
			for (int k = 0; k < s[j].size(); k++) {// j th string's k th char
				if (s[j][k] == minstr[i]) {
					count++;
					s[j].erase(k, 1);
					break;
				}
			}
		}
		if (count == n)
			ans = ans + minstr[i];
	}
	sort(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

inline void OPEN(string s){
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

int main()
{
    //OPEN("arc92-d");
    int n;
    scanf("%d", &n);
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    for(int i = 0; i < n; i++) scanf("%d", &b[i]);
    vector<int> c, d;
    int ans = 0;
    int pow_2 = 1;
    for(int i = 0; i <= 28; i++){
        c = a, d = b;
        for(int j = 0; j < n; j++){
            c[j] %= 2 * pow_2;
            d[j] %= 2 * pow_2;
        }
        sort(c.begin(), c.end());
        sort(d.begin(), d.end());
        int l, r, sum = 0;
        for(int j = 0; j < n; j++){
            l = lower_bound(d.begin(), d.end(), pow_2 - c[j]) - d.begin();
            r = lower_bound(d.begin(), d.end(), 2*pow_2 - c[j]) - d.begin() - 1;
            sum += (r-l+1);
            l = lower_bound(d.begin(), d.end(), 3*pow_2 - c[j]) - d.begin();
            r = lower_bound(d.begin(), d.end(), 4*pow_2 - c[j]) - d.begin() - 1;
            sum += (r-l+1);
        }
        if(sum & 1) ans += pow_2;
        pow_2 *= 2;
    }
    printf("%d\n", ans);
    return 0;
}
/*
容易想到每一位分开来算
那么枚举A中的每一个数，能在B中找到的合法数是一段区间 
*/

Measured memory_bytes: 3328
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
     
double getTime() { 
  return clock() / (double) CLOCKS_PER_SEC;
}
     
void read() {};
     
template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}
     
void print() {};
     
template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

int main() {
  int n; read(n);
  ll d, A; read(d, A);
  vector <pair <ll, ll>> v(n + 1);
  v[n] = {1e18, 1e18};
  for(int i = 0; i < n; i++) {
    read(v[i].first, v[i].second);
    v[i].second = (v[i].second + A - 1) / A;
  }
  sort(v.begin(), v.end());
  vector <ll> pf(n + 1, 0);
  int j = 0; ll moves = 0;
  for(int i = 0; i < n; i++) {
    while(v[i].first + d + d >= v[j].first) j++;
    ll need = max(0LL, v[i].second - pf[i]);
    moves += need;
    pf[i] += need;
    pf[j] -= need;
    pf[i + 1] += pf[i];
  }
  print(moves);
}

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

int n, m;

vector <int> g[15], c[15];
void add_edge(int u, int v, int w) {
	g[u].push_back(v);
	c[u].push_back(w);
}

int dp[1 << 15][15];
int prep[1 << 15][15];

void upd(int &x, int y) {
	if (y < x) x = y;
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++ i) {
		int u, v, w;
		scanf("%d %d %d", &u, &v, &w);
		-- u; -- v;
		add_edge(u, v, w);
		add_edge(v, u, w);
	}
	memset(dp, 0x3f, sizeof(dp));
	int full = (1 << n) - 1;
	for (int msk = 1; msk < (1 << n); ++ msk) {
		for (int i = 0; i < n; ++ i) if (!(msk >> i & 1)) {
			for (int e = 0; e < g[i].size(); ++ e) {
				if (msk >> g[i][e] & 1) prep[msk][i] += c[i][e];
			}
		}
	}
	dp[1][0] = 0;
	for (int msk = 1; msk < (1 << n); ++ msk) {
		for (int u = 0; u < n; ++ u) if (msk >> u & 1) {
			for (int e = 0; e < g[u].size(); ++ e) {
				int v = g[u][e];
				if (!(msk >> v & 1))
					upd(dp[msk | 1 << v][v], dp[msk][u] + prep[msk ^ 1 << u][v]);
			}
			for (int s = full ^ msk; s; s = (s - 1) & (full ^ msk)) {
				int cur = 0;
				for (int i = 0; i < n; ++ i) if (s >> i & 1)
					cur += prep[msk ^ 1 << u][i];
				upd(dp[msk | s][u], dp[msk][u] + cur);
			}
		}
	}
	printf("%d\n", dp[full][n - 1]);
	return 0;
}

Measured memory_bytes: 4096
// スタックサイズ: 100MB

#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1e18;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }




int main() {
	fastio;

	string s;
	cin >> s;
	ll count = 0;
	rep(i, (ll)s.size()) {
		if (s[i] == 'o') ++count;
	}
	count += 15 - (ll)s.size();
	cout << (8 <= count ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int n,money=100000;
	cin>>n;
	
	for(int i=1;i<=n;i++){
		money*=1.05;
		if(money%1000>0){
			money+=1000;
			money-=money%1000;
		}
	}
	cout<<money<<endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    int x;
    cin >> x;
    if (x == 1) {
        cout << 0 << '\n';
    }else {
        cout << 1 << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>

int main() {
  // 入力
  std::string str;
  std::cin >> str;

  // 逆順にする
  if (str.length() == 3) {
    std::reverse(str.begin(), str.end());
  }

  // 出力
  std::cout << str << std::endl;
  
  return 0;
}


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

struct node{
	int id;
	node *right,*left,*parent;
};

node*root;

void insert(int k){
	node *y=NULL,*x=root,*z;
	z=(node*)malloc(sizeof(node));
	z->id=k;
	z->left=NULL;	z->right=NULL;
	while(x!=NULL){
		y=x;
		if(z->id > x->id)	x=x->right;
		else 	x=x->left;
	}
	z->parent=y;
	if(y==NULL)	root=z;
	else{
		if(z->id > y->id)	y->right=z;
		else 	y->left=z;
	}
}

void in(node *cur){
	if(cur==NULL)	return;
	in(cur->left);
	printf(" %d",cur->id);
	in(cur->right);
}
void pre(node *cur){
	if(cur==NULL)	return;
	printf(" %d",cur->id);
	pre(cur->left);
	pre(cur->right);
}

int main(){
	int n;	cin>>n;
	string command;
	int v;
	for(int i=0;i<n;i++){
		cin>>command;
		if(command[0]=='i'){
			cin>>v;
			insert(v);
		}
		else if(command[0]=='p'){
			in(root);	cout<<endl;
			pre(root);	cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 24644
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

x,a = na()

if x < a:
    print(0)
else:
    print(10)

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

int N, M;
#define MAX_N 200000
int A[MAX_N];
int F[MAX_N + 1];
int W[MAX_N + 1];
int R;

int main() {
  cin >> N >> M;
  for(int i = 0; i < N; ++i) {
    cin >> A[i];
    int c = A[i] - F[A[i]]++; if(c >= 1) ++W[c];
  }
  for(int i = 1; i <= N; ++i) R += W[i] == 0;
  for(int i = 0; i < M; ++i) {
    int x, y; cin >> x >> y; --x;
    int c = A[x] - --F[A[x]]; if(c >= 1 && --W[c] == 0) ++R;
    A[x] = y; int d = y - F[y]++; if(d >= 1 && W[d]++ == 0) --R;
    cout << R << endl;
  }
  return 0;
}


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

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


def main():
    n = int(input())
    a = list(map(int, input().split()))
    nn = n*n
    r = [-1] * nn
    ms = []
    us = []
    for i in range(n):
        c = i+1
        ri = a[i] - 1
        r[ri] = c
        ms.append([ri, i, c])
        us.append([ri, n-i-1, c])
    ms.sort()
    si = 0
    for ri, k, c in ms:
        for _ in range(k):
            while r[si] > 0 and si < (nn-1):
                si += 1
            if si > ri or r[si] > 0:
                print('No')
                return
            r[si] = c

    si = nn-1
    us.sort()
    us.reverse()
    for ri, k, c in us:
        for _ in range(k):
            while r[si] > 0 and si > 0:
                si -= 1
            if si < ri or r[si] > 0:
                print('No')
                return
            r[si] = c

    print('Yes')
    print(' '.join(map(str, r)))


main()


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

#define ll long long
#define endl "\n"
#define ios ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);

using namespace std;

int main() {
    ios
    int n;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; ++ i) {
        int x, y;
        cin >> a[i] >> b[i];
        if (i > 1) {
            if (a[i - 2] == b[i - 2] && a[i] == b[i] && b[i - 1] == a[i - 1]) {
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>

using namespace std;

int main(){
  int num[100]={};
  int count=0;

  cin>>count;
  for(int i=0;i<count;i++){
    cin>>num[i];
  }

  for(int i=0;i<count;i++){
    int tmp=num[i];
    int j=i-1;
    while(j>=0&&num[j]>tmp){
      num[j+1]=num[j];
      j--;
    }
    num[j+1]=tmp;
    for(int k=0;k<count;k++){
      cout<<num[k];
      if(k!=count-1) cout<<" ";
    }
    cout<<endl;
  }
}



Measured memory_bytes: 3076
#python3

def main():
    n, m, x = map(int, input().split())
    a = [int(i) for i in input().split()]
    g = [0]*(n+1) 
    for i in a:
        g[i] = 1
    ans = min(sum(g[:x]), sum(g[x+1:]))
    print(ans)
main()


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

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


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

signed main(void)
{
	string s, ans;
	cin >> s;
	rep(i, 5)
	{
		ans += "hi";
		if (ans == s)
		{
			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)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < MOD);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} comb(10000007);
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

mint dp[100005];
bool broken[100005];

int main() {
  int N, M;
  cin >> N >> M;
  rep(i, M) {
    int a;
    cin >> a;
    broken[a] = true;
  }
  dp[0] = 1;
  for (int i = 0; i < N; i++) {
    if (!broken[i+1]) {
      dp[i+1] += dp[i];
    }
    if (!broken[i+2]) {
      dp[i+2] += dp[i];
    }
  }
  cout << dp[N] << '\n';
  return 0;
}

Measured memory_bytes: 160072
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<string>
using namespace std;
int main()
{
    long long int a,b,c,d,e=0,i,x=0,y;
    char s[100];
    cin>>s;
    for(i=0;s[i];i++){
    if(s[i]>=65&&s[i]<=91) cout<<"A"<<endl;
    else cout<<"a"<<endl;
    }


}



Measured memory_bytes: 3592
#include<iostream>
#include<cmath>

using namespace std;

#define EPS 1e-5

struct point{
	double x;
	double y;
};
struct line{
	double a;
	double b;
};

int recog_point_position( const point& a , const point&b , const point& c );
bool get_line( const point& a , const point& b , line *a_b );
inline istream& operator >> ( istream& s , point& p );

int main(void)
{
	point a, b, c, p;

	while(1)
	{
		cin >> a >> b >> c >> p;
		if( cin.eof() ) break;

		int result_ab_c = recog_point_position( a , b , c );
		int result_ab_p = recog_point_position( a , b , p );
		int result_bc_a = recog_point_position( b , c , a );
		int result_bc_p = recog_point_position( b , c , p );
		int result_ca_b = recog_point_position( c , a , b );
		int result_ca_p = recog_point_position( c , a , p );

		cout << (( result_ab_c == result_ab_p && result_bc_a == result_bc_p && result_ca_b == result_ca_p ) ? "YES" : "NO") << endl;
	}

	return 0;
}

int recog_point_position( const point& a , const point& b , const point& c )
{
	line a_b;

	bool result = get_line( a , b , &a_b );
	if( result == false )
	{
		if( (a.x + b.x)/2 < c.x ) return 1; // 点が直線より右にある場合に1をリターン
		else return 0;
	}
	else if( result == true )
	{
		if( c.y > a_b.a * c.x + a_b.b ) return 1; // 点が直線より上にある場合に1をリターン
		else return 0;
	}

}

bool get_line( const point& a , const point& b , line *a_b )
{
	if( fabs(a.x - b.x) < EPS )
	{
		return false;
	}
	else
	{
		a_b->a = (a.y - b.y) / (a.x - b.x);
		a_b->b = a.y - a_b->a * a.x;

		return true;
	}
}

inline istream& operator >> ( istream& s , point& p )
{
	return s >> p.x >> p.y;
}

Measured memory_bytes: 1220
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var in string
	var n int64
	if sc.Scan() {
		in = sc.Text()
		n, _ = strconv.ParseInt(in, 10, 64)
	}

	words := map[string]struct{}{}
	latest := ""

	for i := int64(0); i < n; i++ {
		var in string
		if sc.Scan() {
			in = sc.Text()
			if latest != "" {
				if latest[len(latest)-1] != in[0] {
					fmt.Println("No")
					return
				}
			}
			latest = in
			if _, ok := words[in]; ok {
				fmt.Println("No")
				return
			}
			words[in] = struct{}{}
		}
	}
	fmt.Println("Yes")
}

Measured memory_bytes: 640
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=(0..3).map(|_|read::<i32>()).collect::<Vec<i32>>();
    let k=read::<i32>();
    println!("{}",a.iter().fold(0,|s,x|s+x)+a.iter().max().unwrap()*((1<<k)-1))
}


Measured memory_bytes: 4352
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  V<ll> cnt(n+1,0),v(n);
  rep(i,0,n){
    cin>>v[i];
    cnt[v[i]]++;
  }

  ll tot=0;
  rep(i,0,n+1){
    tot+=(cnt[i])*(cnt[i]-1)/2;
  }

  V<ll> ans(n,tot);
  rep(i,0,n){
    ans[i]-=(cnt[v[i]]-1);
    cout<<ans[i]<<ENDL;
  }
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 7296
import bisect
import sys
sys.setrecursionlimit(10**9)

N = int(input())
A = list(map(int, input().split()))

tree = [[] for i in range(N)]
for i in range(N-1):
  u, v = map(int, input().split())
  tree[u-1].append(v-1); tree[v-1].append(u-1)


ans = [0] * N
ans[0] = 1
INF = 10**10
dp = [INF] * N
dp[0] = A[0]
stack = []
def dfs(node, par, n):
  global ans
  global dp
  global stack
  children = tree[node]
  for child in children:
    if child == par:
      continue
    num = A[child]
    idx = bisect.bisect_left(dp, num)
    stack.append([idx, dp[idx]])
    dp[idx] = num
    ans[child] = max(n, idx+1)
    # ans[child] = bisect.bisect_left(dp, INF)
    dfs(child, node, max(n, idx+1))
    # 巻き戻し
    idx, num = stack.pop()
    dp[idx] = num

dfs(0, -1, 1)
print(*ans, sep='\n')

Measured memory_bytes: 248760
import java.util.*;

class Main {
	Scanner sc;
	int N, D, A;
	int[][] M;
	int[] B;
	
	private void calc() {
		sc = new Scanner(System.in);
		N = sc.nextInt();
		D = sc.nextInt();
		A = sc.nextInt();
		M = new int[N+1][2];
		for (int i = 1; i <= N; i++) {
			M[i][0] = sc.nextInt();
			M[i][1] = (sc.nextInt()+A-1)/A;
		}
		M[0][0] = -1;
		M[0][1] = 0;
		Arrays.sort(M, Comparator.comparingInt(m -> m[0]));
		B = new int[N+1];
		int l = 0;
		long as = 0;
		long ans = 0;
		for (int i = 1; i <= N; i++) {
			as += B[i-1];
			while (M[l][0] + 2*D < M[i][0]) as -= B[l++];
			B[i] = (int)Math.max(0L, M[i][1] - as);
			ans += B[i];
		}
		
		System.out.println(ans);
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}


Measured memory_bytes: 119140