akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

struct C{
	double r,x,y;
	C(double r,double x,double y) : r(r) , x(x) , y(y) {}
};

bool cmp_x(const C &a,const C &b){ return a.x == b.x ? a.y < b.y : a.x < b.x ; }
bool cmp_y(const C &a,const C &b){ return a.y == b.y ? a.x < b.x : a.y < b.y ; }

double dist(const C &a,const C &b){
	double x = a.x - b.x;
	double y = a.y - b.y;
	return sqrt( x * x + y * y );
}
int main(){
	int n;
	while(cin >> n && n){
		vector<C> a,b;
		for(int i = 0 ; i < n ; i++){
			double r,x,y;
			cin >> r >> x >> y;
			a.push_back(C(r,x,y));
			b.push_back(C(r,x,y));
		}
		double ans = 1e15;
		sort(a.begin(),a.end(),cmp_x);
		sort(b.begin(),b.end(),cmp_y);
		for(int i = 0 ; i < n ; i++){
			for(int j = max(0,i-100) ; j < min(i+100,n) ; j++){
				if(i!=j) ans = min(ans,dist(a[i],a[j])-a[i].r-a[j].r);
			}
			for(int j = max(0,i-100) ; j < min(i+100,n) ; j++){
				if(i!=j) ans = min(ans,dist(b[i],b[j])-b[i].r-b[j].r);
			}
		}
		printf("%.7f%c",ans,10);
	}
}

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

#define int long long 

const int N = 1e5+10;
const int mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i) cin >> a[i];
	int cnt = 0;
	for(int i = 0; i < n - 1; ++i)
	{
		if(a[i] != i+1)cnt++;
	}
	if(cnt <= 2)
	cout << "YES";
	else cout << "NO";
}



Measured memory_bytes: 256
/*
 * 2300.cc: Calender Colors
 */

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

/* constant */

const int MAX_N = 20;
const int MAX_NBITS = 1 << MAX_N;

/* typedef */

/* global variables */

double ls[MAX_N], as[MAX_N], bs[MAX_N];
double ds[MAX_N][MAX_N], dsums[MAX_NBITS];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) cin >> ls[i] >> as[i] >> bs[i];

  for (int i = 0; i < n; i++) {
    ds[i][i] = 0.0;
    for (int j = i + 1; j < n; j++) {
      double dl = ls[j] - ls[i], da = as[j] - as[i], db = bs[j] - bs[i];
      ds[i][j] = ds[j][i] = dl * dl + da * da + db * db;
    }
    dsums[1 << i] = 0.0;
  }

  int nbits = 1 << n;
  double maxd = 0.0;
  
  for (int bits = 1; bits < nbits; bits++) {
    int k = 0;
    for (int i = 0, bi = 1; i < n; i++, bi <<= 1)
      if (bits & bi) k++;
    if (k > m) continue;

    if (k == m) {
      if (maxd < dsums[bits]) maxd = dsums[bits];
      continue;
    }

    for (int i = 0, bi = 1; i < n; i++, bi <<= 1)
      if (! (bits & bi)) {
	int bits0 = bits | bi;
	dsums[bits0] = dsums[bits];
	for (int j = 0, bj = 1; j < n; j++, bj <<= 1)
	  if (bits & bj) dsums[bits0] += ds[i][j];
      }
  }

  printf("%.9lf\n", maxd);
  return 0;
}

Measured memory_bytes: 9440
#include<bits/stdc++.h>
using namespace std;
void pre(){}
long long int mod = 1e9+7;
void solve(){
    long long int n,k;cin>>n>>k;n++;
    long long int arr[n+1];
    long long int start=0,end=0;
    for(int i=0;i<n;i++){
        start+=i+1;
        end+=n-i;
        start%=mod;
        end%=mod;
        arr[i]=(end-start+1+mod)%mod;
        //cout<<arr[i]<<"\n";
    }
    long long int ans = 0;
    for(int i=k-1;i<n;i++){
        ans+=arr[i];
        ans%=mod;
    }
    cout<<ans<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}


Measured memory_bytes: 5156
s = gets.chomp
s.reverse!

i = 0
while i < s.length do
	if s[i,5] == 'maerd' then
		i += 5
	elsif s[i, 7] == 'remaerd' then
		i+= 7
	elsif s[i, 5] == 'esare' then
		i += 5
	elsif s[i,6] == 'resare' then
		i += 6
	else
		break;
	end
end

if i == s.length
	print "YES", "\n"
else 
	print "NO", "\n"
end


Measured memory_bytes: 3836
from collections import Counter

n = int(input())
words = []
flag = True

for i in range(n):
    w = input()
    if i >= 1:
        if words[-1][-1] != w[0]:
            flag = False
        
    words.append(w)

    
c = Counter(words)

for j in  c.values():
    if j != 1:
        flag = False
        
if flag :
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38468
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 100005
int a[N],b[N],n,ans;
priority_queue<int>q;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)scanf("%d",&b[i]);
	for(int i=1;i<=n;i++)if(a[i]>b[i])q.push(a[i]-b[i]);
	for(int i=1,now=0;i<=n;i++)
	{
		if(a[i]<b[i])
		{
			ans++;
			while(now<b[i]-a[i])
			{
				if(q.empty())return puts("-1"),0;
				a[i]+=now,now=q.top();q.pop();ans++;
			}
			now-=b[i]-a[i];
		}
	}
	printf("%d\n",ans);
}

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

using namespace std;

typedef int64_t ll;

typedef vector<ll> vll;

struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n, m;
        in >> n;
        vll d(n);
        for (int i = 0; i < n; i++) {
            in >> d[i];
        }
        sort(d.begin(), d.end());
        in >> m;
        vll t(m);
        for (int i = 0; i < m; i++) {
            in >> t[i];
        }
        sort(t.begin(), t.end());
        bool ans = true;
        if (n >= m) {
            int j = 0;
            for (int i = 0, j = 0; i < m; i++) {
                for (; j < n; j++) {
                    if (t[i] == d[j]) {
                        t[i] = d[j] = 0;
                        break;
                    }
                }
            }
            for (int i = 0; i < m; i++) {
                ans &= t[i] == 0;
            }
        }
        out << (n >= m && ans ? "YES" : "NO") << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}

#include <fstream>
#include <iostream>

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;

    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 3328
x = int(input())
if 400 <= x <= 599:
  print(8)
elif 600 <= x <= 799:
  print(7)
elif 800 <= x <= 999:
  print(6)
elif 1000 <= x <= 1199:
  print(5)
elif 1200 <= x <= 1399:
  print(4)
elif 1400 <= x <= 1599:
  print(3)
elif 1600 <= x <= 1799:
  print(2)
elif 1800 <= x <= 1999:
  print(1)

Measured memory_bytes: 9184
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3) / 2, -1):
            if n3 + min(n2 - 1, x - n3 - n2):
                ans += 1
    return ans

while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    print(get_num(n, x))

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


bool solve(string const& s) {
    if(s.size() <= 3) {
        return s == "ABC";
    }
    if(s.find("ABC") == string::npos) {
        return false;
    }

    string prev;
    for(int i=0; i<s.size(); ++i) {
        if(i < s.size() - 2 && s.substr(i, 3) == "ABC") {
            i += 2;
            prev += 'x';
        } else {
            prev += s[i];
        }
    }
    bool used[3] = {false};
    for(int i=0; i<prev.size(); ++i) {
        if(prev[i] == 'x') continue;
        used[prev[i]-'A'] = true;
    }
    for(int i=0; i<3; ++i) {
        if(used[i]) {
            continue;
        }
        string prev2;
        for(int j=0; j<prev.size(); ++j) {
            if(prev[j] == 'x') {
                prev2 += 'A' + i;
            } else {
                prev2 += prev[j];
            }
        }
        if(solve(prev2)) {
            return true;
        }
    }
    return false;
}

int main() {
    string s;
    cin >> s;
    if(solve(s)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 27920
#include<cstdio>
#define neko 4010
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~i))
const int mod=924844033;
int dp[neko][neko][2],f[neko],ed[neko],fac[neko],cnct[neko][2],n,k,ans,cnt;
int ADD(int x,int y){return (x+=y)>=mod?x-mod:x;}
typedef long long ll;
void solvcoef()
{
	int now;
	f(i,1,n)
	 f(j,0,1)
	 if(!cnct[i][j])
	 {
		 now=0;
		 for(register int x=i,y=j;x<=n;x+=k,y^=1)cnct[x][y]=1,++now;
		 ed[cnt+=now]=1;
	 }
	dp[0][0][0]=1;
	f(i,1,cnt)
	 f(j,0,i)
	 {
		 dp[i][j][0]=ADD(dp[i-1][j][0],dp[i-1][j][1]);
		 if(!ed[i]&&j)dp[i][j][1]=dp[i-1][j-1][0];
	 }
	f(i,0,n)f[i]=ADD(dp[cnt][i][0],dp[cnt][i][1]);
}
int main()
{
	scanf("%d%d",&n,&k);
	fac[0]=1;
	f(i,1,2005)fac[i]=(ll)fac[i-1]*i%mod;
	solvcoef();
	f(i,1,n)ans=ADD(mod,ADD(ans,(ll)(i&1?-1:1)*fac[n-i]%mod*f[i]%mod));
	return printf("%d\n",ADD(ADD(ans,fac[n]),mod)),0;
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
  ll q, h, s, d, n, v;
  cin >> q >> h >> s >> d >> n;
  if (n % 2 == 0){
	v = n / 2 * d;
	v = min(v, n * s);
	v = min(v, n * 2 * h);
	v = min(v, n * 4 * q);
  }else{
	v = n * 4 * q;
	v = min(v, n * 2 * h);
	v = min(v, n * s);
	v = min(v, (n-1)/2 * d + s);
	v = min(v, (n-1)/2 * d + 2 * h);
	v = min(v, (n-1)/2 * d + 4 * q);
  }
  cout << v << endl;
}

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

int main() {
  string S;
  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>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	Info(int arg_attack,bool arg_is_throw){
		attack = arg_attack;
		is_throw = arg_is_throw;
	}
	bool operator<(const struct Info &arg) const{

		return attack < arg.attack; //攻撃力の降順(PQ)
	}
	int attack;
	bool is_throw;
};

int N,H;

//投げて死ななかったら、その前に殴っていたことにすれば良い

int main(){

	scanf("%d %d",&N,&H);

	priority_queue<Info> Q;

	int a,b;

	for(int loop = 0; loop < N; loop++){

		scanf("%d %d",&a,&b);

		Q.push(Info(a,false));
		Q.push(Info(b,true));
	}

	int ans = 0;

	while(H > 0){

		if(Q.top().is_throw){

			H -= Q.top().attack;
			Q.pop();
			ans++; //投げるのは1回だけ

		}else{ //通常攻撃なら、残りずっとその武器を使う

			if(H%Q.top().attack == 0){

				ans += H/Q.top().attack;

			}else{

				ans += H/Q.top().attack+1;
			}

			break;
		}
	}

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

	return 0;
}


Measured memory_bytes: 2420
def ng(a):
    b = []
    for x in a:
        two = 0
        while x%2 == 0:
            x //= 2
            two += 1
        b.append(two)
    return sum(b) != b[0]*len(b)

def gcd(a, b):
    return a if b == 0 else gcd(b, a%b)

def lcm(a, b):
    return a//gcd(a,b)*b

def fail():
    print(0)
    exit(0)

n, m = map(int, input().split())
a = [int(x)//2 for x in input().split()]

if ng(a):
    fail()

lc = 1
for x in a:
    lc = lcm(lc, x)
    if lc > m:
        fail()

ret = 1
m -= lc
ret += m//(2*lc)
print(ret)


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int n,m;
int cnt[111111];

int main(){
	cin.sync_with_stdio(false);
  cin>>n>>m;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    cnt[--a]++; cnt[--b]++;
  }
  rep(i,n){
    if(cnt[i]%2!=0){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
	return 0;
}


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

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

    if (R < 1200){
        cout << "ABC" << endl;
    }
    else if (R < 2800){
        cout << "ARC" << endl;
    }
    else {
        cout << "AGC" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a,c,i;
  char b[11],e;
  scanf("%d\n%s\n%d",&a,b,&c);
  e=b[c-1];
  for (i=1;i<=a;i++){
    if(b[i-1]!=e){
      b[i-1]='*';
    }
  }
  printf("%s",b);
  return 0;
} 


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>

using namespace std;

typedef long long ll;

int main()
{
  cout << setprecision(15);

  int N;
  cin >> N;

  double ans;
  if(N%2==0)
      ans = 1.0/2.0;
  else
    {
      N = static_cast<double>(N);
      ans = (N/2.0+0.5)/N;
    }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
int main(){

long long n,w,h;
    if(scanf("%llu", &h)!=1){ };
    if(scanf("%llu", &w)!=1){ };

    if(h!=1&&w!=1){
        printf("%llu",(w*h+1)/2);
    }else{
        printf("1");
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <map>
#include <queue>
using namespace std;
int n, a[15], flag;
int main() {
	cin >> n;
	for(int i= 1; i <= 9; i++)
		for(int j= 1; j <= 9; j++) flag|= (i * j == n);
	cout << (flag ? "Yes" : "No") << endl;
	return 0;
}

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

void push(int);
void calc(char);

int top = 1;
int s[100];

int main()
{

    char num[4];
    int i, tmp, flag = 0;

    while (1)
    {
        if (scanf("%s", num) == EOF)
            break;

        flag = 0;
        for (i = 0; i < strlen(num); i++)
        { //数字判定
            if (num[i] < '0' || '9' < num[i])
                flag = 1;
        }

        if (flag == 0)
            push(atoi(num)); //数字

        if (num[0] == '+' || num[0] == '-' || num[0] == '*')
            calc(num[0]); //演算子
    }
    printf("%d\n", s[1]);

    return 0;
}

void push(int x)
{
    s[top] = x;
    // printf("入った数字%d\n",s[top]);
    top++;
}

void calc(char ope)
{
    top--;
    if (ope == '+')
        s[top - 1] = s[top - 1] + s[top];
    if (ope == '-')
        s[top - 1] = s[top - 1] - s[top];
    if (ope == '*')
        s[top - 1] = s[top - 1] * s[top];

    // printf("")
}



Measured memory_bytes: 2056
package main

import (
    "fmt"
)

func main() {
    var s, t []byte
    fmt.Scan(&s)
    fmt.Scan(&t)
    var ok bool
    n := len(s)
    for i := 0; i < n; i++ {
        var ng bool
        for j := 0; j < n; j++ {
            if s[(i+j)%n] != t[j] {
                ng = true
            }   
        }   
        if !ng {
            ok = true
        }   
    }   
    if ok {
        fmt.Println("Yes")
    } else {
        fmt.Println("No")
    }   
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int x;cin>>x;
    int ans=0;
    int tmp=x;
    ans=tmp/500*1000;
    tmp=tmp%500;
    ans+=tmp/5*5;
    cout<<ans<<endl;
}

Measured memory_bytes: 3608
//By Don4ick
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qwer1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

const int N = (int)2e5 + 228;

using namespace std;

int n, a[N];
map < ll, int > cnt;

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//~read
	scanf("%d", &n);
	forn(i, n)
	{
		scanf("%d", &a[i]);
	}
	//~solve
	ll cur = 0;
	cnt[cur]++;
	ll ans = 0;
	forn(i, n)
	{
		cur += a[i];
		ans += cnt[cur];
		cnt[cur]++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 13568
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
//#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 998244353
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
#define base 1000000000000000000ll
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=mul(ans,a,c);a=mul(a,a,c),b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ld pi = acos(-1);
const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100+10,maxn=2000000+10,inf=0x3f3f3f3f;

string s;
char mi='z';
string gao(string s,int k)
{
    if(!k)return s;
    int n=s.size();
    while(k--)
    {
        int num=0;
        for(int i=n-1;i>=0;i--)
        {
            if(s[i]==mi)num++;
            else break;
        }
        if(num==n)return s;
        string t=s;
        reverse(t.begin(),t.end());
        if(k==0)return (s+t).substr(n-num,n);
        s=(s+t).substr(num,n);
    }
    return s;
}
int main()
{
//    fin;
    int n,k;
    cin>>n>>k>>s;
    for(int i=0;i<s.size();i++)mi=min(mi,s[i]);
    string ans=s;
    if(k==1)
    {
        string t=s;
        reverse(t.begin(),t.end());
        for(int i=0;i<s.size();i++)ans=min(ans,(s+t).substr(i,s.size()));
        cout<<ans;
        return 0;
    }
//    cout<<s<<" "<<mi<<endl;
    for(int i=0;i<s.size()-1;i++)if(s[i]==mi)
    {
        string t=s;
        reverse(t.begin(),t.end());
        t=(s+t).substr(s.size()-i,s.size());
//        cout<<t<<endl;
        ans=min(ans,gao(t,k-1));
    }
    if(s[s.size()-1]==mi)ans=min(ans,gao(s,k));
    cout<<ans;
    return 0;
}
/********************

********************/


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

int slove(int sum, int w){
  if(sum <= 60 && w <= 2) return 600;
  if(sum <= 80 && w <= 5) return 800;
  if(sum <= 100 && w <= 10) return 1000;
  if(sum <= 120 && w <= 15) return 1200;
  if(sum <= 140 && w <= 20) return 1400;
  if(sum <= 160 && w <= 25) return 1600;
  return 0;
}
int main(){
  int n;
  while(cin >> n){
    if(n==0) break;
    int price=0;
    for(int i=0; i<n; i++){
      int x,y,h,w;
      cin >> x >> y >> h >> w;
      int sum=x+y+h;
      
      price += slove(sum,w);
    }
    cout << price << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int mycard1,mycard2,yourcard,card[11],coun=0;
    while(cin>>mycard1>>mycard2>>yourcard){
        for(int i=1;i<11;i++)card[i]=0;
        card[mycard1]=1;card[mycard2]=1;card[yourcard]=1;
        mycard1+=mycard2;
        for(int i=1;i+mycard1<=20&&i<11;i++)if(card[i]==0)coun++;
        if(coun<4)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
        coun=0;
    }
}

Measured memory_bytes: 1152
#include <cstdio>
#include <iostream>
#define ll long long
using namespace std;
int main(){
	ll N;
	scanf("%lld", &N);
	for (ll w = 1; w <= 3500; w++)
		for (ll h = 1; h <= w; h++){
			ll k = 4 * h * w - N * h - N * w;
			if (k <= 0) continue;
			if (N * w * h % k == 0){
				cout << w << " " << h << " " << N * w * h / k << endl;
				return 0;
			}
		}
	return 0;
}


Measured memory_bytes: 764
import java.util.*;
import java.io.*;
import java.lang.*;

public 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 k = sc.nextInt();
        long ans = 0;
        if (k<=a){
            ans = k;
        }
        else if(k<=(a+b)){
            ans = a;
        }
        else if (k>(a+b)){
            ans = a + ((k-(a+b))*-1);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35404
n = int(input())
A = [int(x) for x in input().split()]
res = 0
counter = {}
for i in reversed(range(n)):
    x = A[i]
    res += counter.get(x + i, 0)
    counter[i - x] = counter.get(i - x, 0) + 1
print(res)

Measured memory_bytes: 40508
#include<iostream>
#include<fstream>

using namespace std;

int cat_count();

int main(){
  int data_set;
  cin >> data_set;
  int i;
  for(i=0;i<data_set;i++){
    cat_count();
  }
}

int cat_count(){
    int campus_x[2];  //?????£????????????x??§?¨?????????????
    int campus_y[2];
    int wide_x,wide_y; //?????£??????????????????
    
    cin >>campus_x[0]>>campus_y[0]>>wide_x>>wide_y;

    campus_x[1] = campus_x[0] + wide_x;
    campus_y[1] = campus_y[0] + wide_y;

    int cat_number;
    cin >> cat_number;

    int cat_x[cat_number];
    int cat_y[cat_number];

    int i;
    for(i=0;i<cat_number;i++){
      cin >> cat_x[i] >> cat_y[i];
    }


    int count = 0;
    for(i=0;i<cat_number;i++){
      if(cat_x[i] >= campus_x[0] && cat_x[i] <= campus_x[1]){
	if(cat_y[i] >= campus_y[0] && cat_y[i] <= campus_y[1]){
	  count += 1;
	}
      }
    }

    cout << count << endl;
}

Measured memory_bytes: 1160
n,m=map(int,input().split())
u=[0]*n
a=list(map(int,input().split()))
b=a[0]-1
for x in a[1:]:
    x-=1
    u[max(b,x)]-=1
    u[min(b,x)]+=1
    b=x
ans=0
for i in range(n-1):
    u[i+1]+=u[i]
    d,b,c=map(int,input().split())
    ans+=min(d*u[i],b*u[i]+c)
print(ans)

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

typedef long long ll;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REPD(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define REP(i, n) REP2(i, 0, n)


int main() {
  string s;
  cin >> s;
  ll cur = 0;
  vector<ll> values(s.size() + 1);
  REP(i, s.size()) {
    if (s[i] == '<') {
      values[i + 1] = max(values[i] + 1, values[i + 1]);
    }
  }

  REP(i, s.size()) {
    int j = s.size() - i - 1;
    if (s[j] == '>') {
      values[j] = max(values[j + 1] + 1, values[j]);
    }
  }
  ll res = 0;
  REP(i, values.size()) {
    res += values[i];
  }
  cout << res << endl;
}



Measured memory_bytes: 4740
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			long N = sc.nextLong();

			if (N % 2 == 1) {
				System.out.println(0);
				return;
			}

			long total = 0;

			long div = 1;
			while (N / div >= 5) {
				div *= 5;
				total += (N / (div * 2));
			}

			System.out.println(total);

		}
	}

}


Measured memory_bytes: 23764
import java.util.*;
 
public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] P = new int[N];
        for (int i = 0; i < N; i++) {
            P[i] = sc.nextInt();
        }

        int ans = 0;
        int min = N;
        for (int i = 0; i < N; i++) {
            min = Math.min(min, P[i]);
            if (P[i] <= min) {
                ans++;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 64332
# modulo
MOD = 10 ** 9 + 7

# number of vertices
n = int(input())
# adjacency list
edge = [[] for _ in range(n)]
# 0-index
for _ in range(n-1):
  a, b = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

# factorial and inverse and inverse of factorial
fact = [1] * n
inverse = [1] * n
inv_fact = [1] * n
for i in range(2, n):
  fact[i] = fact[i-1] * i % MOD
  inverse[i] = -inverse[MOD % i] * (MOD // i) % MOD
  inv_fact[i] = inv_fact[i-1] * inverse[i] % MOD

# regarding index 0 as root of tree
# calculating parents of vertices and route from root with DFS
stack = [0]
parent = [0] * n
route = []
while stack:
  vertex = stack.pop()
  route.append(vertex)
  for child in edge[vertex]:
    if parent[vertex] != child:
      parent[child] = vertex
      stack.append(child)

# tree DP regarding index 0 as root of tree
# process from leaves to root
dp = [1] * n
size = [1] * n
for vertex in route[:0:-1]:
  pa = parent[vertex]
  sz = size[vertex]
  dp[vertex] = dp[vertex] * fact[sz-1] % MOD
  dp[pa] = dp[pa] * dp[vertex] * inv_fact[sz] % MOD
  size[pa] += sz
dp[0] = dp[0] * fact[n-1] % MOD

# rerooting
# process from root to leaves
for vertex in route[1:]:
  pa = parent[vertex]
  sz = size[vertex]
  inv_dp = pow(dp[vertex], MOD - 2, MOD)
  dp[vertex] = dp[vertex] * dp[pa] * inv_dp * sz * inverse[n-sz] % MOD

# printing result
for value in dp:
  print(value)

Measured memory_bytes: 80804
package main

import (
	"fmt"
)

func main() {
	result := []string{}

	for {
		var s string
		fmt.Scan(&s)

		if s == "-" {
			break
		}

		var m int
		fmt.Scan(&m)

		for i := 0; i < m; i++ {
			var h int
			fmt.Scan(&h)

			head := s[:h]
			tail := s[h:]

			s = tail + head
		}

		result = append(result, s)
	}

	for _, v := range result {
		fmt.Println(v)
	}
}



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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    string x, y, z;

    long long r = 0;
    long long g = 0;
    long long b = 0;
    for(int i = 0; i < n; i++) {
        if(s[i] == 'R') r++;
        if(s[i] == 'G') g++;
        if(s[i] == 'B') b++;
    }

    long long ans = r * g * b;
    for(int i = 0; i < n - 1; i++) {
        for(int j = 1; i + 2*j < n; j++) {
            if(s[i] != s[i + j] && s[i + j] != s[i + 2*j] && s[i + 2*j] != s[i]) {
                ans--;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>

int main(void){

	long n, m=0, G=0, Min, Max, a[10000];

	scanf("%ld", &n);
	while (m < n) {
		scanf("%ld", &a[m]);
			if (m != 0)
			{
				if (Max <= a[m])
				{
					Max = a[m];
				}
				if (Min >= a[m])
				{
					Min = a[m];
				}
			}
			else
			{
				Max = a[m], Min = a[m];
			}
			G += a[m];
			m++;
	}
	printf("%ld %ld %ld\n", Min, Max, G);

	return 0;
}

Measured memory_bytes: 1856
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  I n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  string an;
  REP(i,n){
    an += s.at(i);
    an += t.at(i);
  }
  cout << an << endl;
  return 0;
}



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

int main() {
  int N;
  string S;
  cin >>N;
  cin>>S;
  int m=0;
  for(int i=1;i<=N-1;i++){
    string s1 = S.substr(0,i);
    string s2 = S.substr(i,N-i);
    int count=0;
    // char型のfor文 c = 'a','b','c'...'x','y','z'
    for(char c='a';c<='z';c++){
      int l=0,r=0;
      for(int j=0;j<i;j++){
        if(s1[j]==c) l=1;
      }
      for(int j=0;j<N-i;j++){
        if(s2[j]==c) r=1;
      }
      count += l*r;
    }
    m = max(m,count);
  }
cout<<m<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,k;
  cin >> a >> b>> c >> k;
  int xa=min(a,k);
  k-=xa;
  int xb=min(b,k);
  k-=xb;
  int xc=k;
  cout << xa-xc << endl;
  return 0;
}

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

llint n;
llint a[55], b[55];
bool dp[55][55];
llint memo[55][55][55];

bool calc(llint a, llint b, llint p)
{
	if(memo[a][b][p] != -1) return memo[a][b][p];
	if(p == 0) return a == b;
	if(a < b) return memo[a][b][p] = false;
	return memo[a][b][p] = calc(a, b, p-1) || calc(a%p, b, p-1);
}

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) cin >> b[i];
	
	for(int i = 0; i < 55; i++){
		for(int j = 0; j < 55; j++){
			for(int k = 0; k < 55; k++){
				memo[i][j][k] = -1;
			}
		}
	}
	
	for(int i = 1; i <= n; i++) dp[i][a[i]] = true;
	
	llint ans = 0;
	for(int i = 51; i >= 1; i--){
		bool flag = false;
		for(int j = 1; j <= n; j++){
			bool flag2 = false;
			for(int k = 0; k < 55; k++){
				if(!dp[j][k]) continue;
				if(calc(k, b[j], i-1)) flag2 = true;
			}
			if(!flag2) flag = true;
		}
		if(flag){
			ans += 1LL<<i;
			for(int j = 1; j <= n; j++){
				for(int k = 0; k < 55; k++){
					dp[j][k%i] |= dp[j][k];
				}
			}
		}
	}
	
	if(ans >= 1LL<<51) ans = -1;
	cout << ans << endl;
	
	return 0;
}


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


int main() {
    int N, X, Y;
    cin >> N >> X >> Y;

    int A[N+1], B[N];
    for (int i = 0; i < N; i++) {
        A[i+1] = i+1;
        B[i] = 0;
    }
    
    for (int i = 1; i < N; i++) {
        for (int j = i + 1; j < N+1; j++) {
            int s = min(j - i, abs(X - i) + 1 + abs(j - Y));
            s = min(s, abs(Y - i) + 1 + abs(j - X));
            if (0 < s < N) {
                B[s]++;
            }
        }
    }


    for (int k = 1; k < N; k++) {
        cout << B[k] << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

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

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}

int main() {
	cin >> n;
	for (ll i = 1; i <= 9; i++) {
		if (n % i == 0 && n / i <= 9) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

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

int main() {
  LL s; cin >> s;
  LL x = 0, y = 0;
  LL x1 = 1e9, y1 = 1;
  LL x2, y2;

  x2 = (x1 - (s % x1)) % x1;
  y2 = (s + x2) / 1e9;

  cout << x << " " << y << " " << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int x = sc.nextInt();

		System.out.println(a <= x && a + b >= x ? "YES" : "NO");
	}
}

Measured memory_bytes: 35312
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>

using namespace std;

const int mod = 998244353;

vector<long long> range_mod_inverse(int n, const int mod) {
  vector<long long> ret(n + 1);
  ret[1] = 1;
  for (int i = 2; i <= n; i++)
    ret[i] = (long long)(mod - mod / i) * ret[mod%i] % mod;
  return ret;
}

vector<long long> getFactorials(int n, const int mod) {
  vector<long long> ret(1, 1);
  for (int i = 1; i <= n; i++) ret.push_back((long long)ret.back()*i%mod);
  return ret;
}

vector<long long> getInverseFactorials(int n, const int mod) {
  vector<long long> invmod(range_mod_inverse(n, mod));
  vector<long long> ret(1, 1);
  for (int i = 1; i <= n; i++) ret.push_back((long long)ret.back()*invmod[i] % mod);
  return ret;
}


vector<long long> factorials;
vector<long long> invfact;

long long binomial(int n, int m) {
  if (n < 0 || m < 0 || m > n) return 0;
  long long ans = factorials[n];
  ans *= invfact[m]; ans %= mod;
  ans *= invfact[n - m]; ans %= mod;
  return ans;
}

long long arrange(int rooms, int items) {
  return binomial(rooms + items - 1, items);
}

int main() {
  factorials = getFactorials(1'000'000, mod);
  invfact = getInverseFactorials(1'000'000, mod);

  int K, N;
  scanf("%d%d", &K, &N);
  vector<int> answers;
  for (int i = 2; i <= K + 1; i++) {
    long long result = 0;
    if (i % 2 == 1) {
      int ih = i / 2;
      for (int a = 0; a <= ih; a++) {
        result += binomial(ih, a) * arrange(ih + K - i + 1, N - a) % mod;
      }
    }
    else {
      int ih = i / 2 - 1;
      for (int a = 0; a <= ih; a++) {
        result += binomial(ih, a) * (arrange(ih + K - i + 1, N - a) + arrange(ih + K - i + 1, N - a - 1)) % mod;
      }
    }
    result %= mod;
    result += mod;
    result %= mod;
    printf("%lld\n", result);
    answers.push_back(result);
  }
  int v = answers.size();
  for (int i = v - 2; i >= 0; i--) {
    printf("%lld\n", answers[i]);
  }
  return 0;
}


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

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

	string S[N];
	for (int i = 0; i < N; ++i) {
		cin >> S[i];
	}

	char head[] = { 'M', 'A', 'R', 'C', 'H' };
	long long headCount[] = { 0, 0, 0, 0, 0 };

	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 5; ++j) {
			if (S[i][0] == head[j]) {
				headCount[j]++;
			}
		}
	}

	long long result = 0;

	for (int i = 0; i < 3; ++i) {
		for (int j = i + 1; j < 4; ++j) {
			for (int k = j + 1; k < 5; ++k) {
				result += headCount[i] * headCount[j] * headCount[k];
			}
		}
	}

	cout << result << endl;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
int main(){
    long n,m;
    cin >> n >> m;
    vector<set<int> >move(n);
    int u,v;
    for(int i=0;i<m;i++){
        cin >> u >> v;
        u--;
        v--;
        move[u].insert(v);
    }
    int s,t;
    cin >> s >> t;
    s--;
    t--;
    int ans = -3;
    vector<vector<bool> >went(n,vector<bool>(3,false));
    queue<pair<int,int> >que;
    que.push(make_pair(s,0));
    while(!que.empty()){
        int tmp = que.front().first;
        int moved = que.front().second;
        que.pop();
        if(tmp == t && moved%3 == 0){
            ans = moved;
            break;
        }

       
        if(!went[tmp][moved%3]){
            for(auto j:move[tmp]){
                que.push(make_pair(j,moved+1));
            }
        }

       went[tmp][moved%3] = true;
    
        
        
       
    }
    cout << ans/3 << endl;

}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    ll ans = 0;
    rep(i, K) {
        queue<char> ban;
        int n = i;
        while (n < N) {
            if (ban.empty()) {
                ban.push(T[n]);
                if (T[n] == 'r') {
                    ans += P;
                }
                else if (T[n] == 's') {
                    ans += R;
                }
                else {
                    ans += S;
                }
                n += K;
                continue;
            }
            if (T[n] == ban.front()) {
                n += K;
                ban.pop();
                continue;
            }
            if (T[n] == 'r') {
                ans += P;
            }
            else if (T[n] == 's') {
                ans += R;
            }
            else {
                ans += S;
            }
            ban.push(T[n]);
            ban.pop();
            n += K;
        }
        ban.pop(); 
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
i = input()[::-1]
T = []
for t in ['dreamer', 'dream', 'eraser', 'erase']:
    T.append(t[::-1])

match = True
while match:
    match = False
    for t in T:
        if i.startswith(t):
            match = True
            i = i.replace(t, '', 1)
            if len(i) < 1:
                print('YES')
                exit()

print('NO')

Measured memory_bytes: 3188
// Problem : D - Friends
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define mt                make_tuple
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
#define sz(x)             (int)x.size()
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

const int tam = 2e5 + 10;

int P[tam], sz[tam];

int findP(int v) {
	if (P[v] == -1) return v;
	return P[v] = findP(P[v]);
}

void _join(int a, int b) {
	a = findP(a);
	b = findP(b);
	if (a == b) return;
	sz[b] += sz[a];
	P[a] = b;
}

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    clr(P, -1);
    int n, m;
    cin >> n >> m;
    fore(i, 0, n ) sz[i] = 1;
    fore(i, 0, m) {
    	int a, b;
    	cin >> a >> b;
    	a--; b--;
    	_join(a, b);
    }
    int res = 1;
    fore(i, 0, n) {
    	res = max(res, sz[i]);
    }
    cout << res << '\n';
    return 0;
}
// Dinosaurs are cool!

Measured memory_bytes: 5200
#include<stdio.h>
int main()
{
  int N,K,Q;
  int i,a[1000000],j,b;
  scanf("%d %d %d",&N,&K,&Q);
  for(i=1;i<=N;i++)
    {
      a[i]=0;
    }
  for(j=1;j<=Q;j++)
    {
      scanf("%d",&b);
      a[b]=a[b]+1;
    }
  for(i=1;i<=N;i++)
    {
      if(K-Q+a[i]>0){
        printf("Yes\n");
      }
      else {
        printf("No\n");
      }
    }
      return 0;
}




Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
int n;
int ans[503][503];
void dfs(int l,int r,int cnt){
	if (l==r) return;
	int mid=(l+r)/2;
	for (int i=l;i<=mid;i++)
		for (int j=mid+1;j<=r;j++) ans[i][j]=cnt;
	dfs(l,mid,cnt+1);
	dfs(mid+1,r,cnt+1);
}
int main(){
	cin>>n;
	dfs(1,n,1);
	for (int i=1;i<=n-1;i++){
		for (int j=i+1;j<=n;j++) cout<<ans[i][j]<<" ";
		puts("");
	}
}

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

#define fi first
#define se second

const int N = 200200;
const int mod = 1e9 + 7;

using namespace std;

int n;
int p[N];
int s[N];
int a[N];
int b[N];
int c[N];

int get(int x) { return p[x] == x ? x : p[x] = get(p[x]); }

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> n;
        for(int i = 1; i <= n; i++){
                int y;
                cin >> a[i] >> y;
                b[a[i]] = y;

                s[i] = 1;
                p[i] = i;
        }
        set < pair < int, int > > S;
        for(int i = 1; i <= n; i++){
                c[i] = b[i];
                while(!S.empty() && b[i] > S.begin()->fi){
                        int j = S.begin()->se;
                        c[i] = min(c[i], c[j]);
                        j = get(j);
                        if(j != i){
                                p[j] = i;
                                s[i] += s[j];
                        }
                        S.erase(S.begin());
                }
                S.insert({c[i], i});
        }
        for(int i = 1; i <= n; i++){
                cout << s[get(a[i])] << "\n";
        }
}


Measured memory_bytes: 12056
n = int(input())
list_A  = list(map(int, input().split()))
list_B  = list(map(int, input().split()))
list_C  = list(map(int, input().split()))

list_A_01 = []
for i in range(len(list_A) - 1):
    if list_A[i] == list_A[i + 1] - 1:
        list_A_01.append(list_A[i])

    if list_A[i] != list_A[i + 1] - 1:
        list_A_01.append(0)

result = 0

for i, score in enumerate(list_A_01):
    if score != 0:
        result = result + list_C[score-1]

print(sum(list_B) + result) 

Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <bits/stdc++.h>
#include <cstdlib>
#include <math.h>
using namespace std;
#define ll long long int 
int main()
{
	ll n,m;
	cin>>n>>m;
	ll ans=1;
	for(int i=0;i<m;i++)
	ans=ans*2;
	ans*=100*(18*m+n);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
const int INF = 1e9+5;

int main(){
	int N;
	cin >> N;
	vector<int> dp(3,0);
	for(int i=0; i<N; ++i){
		vector<int> costs(3);
		vector<int> dp_daily(3,0);
		for(int j=0; j<3; ++j){
			cin >> costs[j];
		}
		for(int j=0; j<3; ++j){ // What was before in the previous 3 days
			for(int k=0; k<3; ++k){ // What is going to be obtained in the new day
				if(k!=j){
					dp_daily[k] = max(dp_daily[k], dp[j]+costs[k]);
				}
			}
		}
		dp = dp_daily;
	}
	cout << max({dp[0],dp[1],dp[2]}) << endl;
	return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
const int mod = 1e9+7;

struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod only
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint dp[2005][2005];
mint sum[2005][2005];
int main(){
    int n,m; cin >> n >> m;
    vector<int> s(n),t(m);
    rep(i,n) cin >> s[i];
    rep(i,m) cin >> t[i];
    dp[0][0] = 1; sum[1][1] = 1;
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            if(i == 0 && j == 0) continue;
            if(i >= 1 && j >= 1 && s[i-1] == t[j-1]) dp[i][j] = sum[i][j];
            sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + dp[i][j];
        }
    }
    cout << sum[n+1][m+1].x << endl;
}

Measured memory_bytes: 63104
#!/usr/bin/env python3

# import sys
# sys.setrecursionlimit(200000)  # ttk

MOD = 1000000007
fact = []
q = []

def main():
    n = int(input())
    an = list(map(int, input().split()))
    init_fact(100000)
    init_q(100000, n)
    res = 0
    for j, a in enumerate(an):
        res += a * (q[n - j] + q[j + 1] - q[1])
        res %= MOD
    print(res)

def init_q(maxn, n):
    assert len(q) == 0
    assert len(fact) == maxn + 1
    q.append(0)
    for l in range(1, maxn + 1):
        dq = fact[n] * inv(l)
        q.append((q[-1] + dq) % MOD)

def init_fact(maxn):
    assert len(fact) == 0
    fact.append(1)
    for i in range(1, maxn + 1):
        fact.append((fact[i - 1] * i) % MOD)

def inv(n):
    return pow(n, MOD - 2)

def pow(n, p):
    if p == 0:
        return 1
    elif p % 2 == 0:
        x = pow(n, p // 2)
        return (x * x) % MOD
    else:
        x = pow(n, p - 1)
        return (x * n) % MOD

main()


Measured memory_bytes: 15716
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s=="SUN")
		cout<<7;
	if(s=="MON")
		cout<<6;
	if(s=="TUE")
		cout<<5;
	if(s=="WED")
		cout<<4;
	if(s=="THU")
		cout<<3;
	if(s=="FRI")
		cout<<2;
	if(s=="SAT")
		cout<<1;

}

Measured memory_bytes: 256