akhauriyash/Code-Regression huggingface dataset:
//#include "atcoder/all"
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
// using namespace atcoder;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) fixed << setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll X, Y;
  cin >> X >> Y;

  if (Y >= X)
    cout << min(Y - X, abs(X + Y) + 1) << endl;
  else
    cout << min(X - Y + 2, abs(X + Y) + 1) << endl;

  return 0;
}


Measured memory_bytes: 3632
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: usize, s: String};

    let s1 = &s[0..n / 2];
    let s2 = &s[n / 2..];

    if s1 == s2 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            :oyhhhhhhyo:    
#define next         .sdNNNmNNNNNNNmds. 
#define y0          -hNNNNy`yNNNNNN`/Nh-
#define y1          mNNNNNd+dNNNNNN+sNNm
#define yn          mNNNNNNNNy--:smNNNms
#define tm          .+oooooosyysooooo+- 
#define read               :yhy/        
#define rank              :mNmo         
#define index              ... 
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

const int N = 111111;
int fact[N];
string s;
int n;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> s;
    fact[0] = 1;
    rep(i, 1, n) {
        fact[i] = fact[i - 1] * i % MOD;
    }
    int op = 0, ans = 1;
    rep(i, 1, 2 * n) {
        if((s[i - 1] == 'B') ^ (op & 1)) {
            op++;
        } else {
            ans = ans * op % MOD;
            op--;
        }
        if(op < 0) {
            ans = 0;
            break;
        }
    }
    if(op) {
        ans = 0;
    }
    ans = ans * fact[n] % MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1360
#include <iostream>
#include <cmath>
#include <cstdlib>

using namespace std;

int main(int argc, char* argv[])
{
    int n = 0, n2 = 0;
    cin >> n;
    //n = atoi(argv[1]);
    if(n < 1 || n > 100) {
        return 1;
    }
    n2 = pow(n, 3.0);
    cout << n2 << endl;
}


Measured memory_bytes: 3236
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007
#define inf 1000000000000000000ll
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x,ll y, ll md=inf){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}
 
using namespace std;


#define endl '\n'
#define int ll

signed main() {
	fast;

	int h,w;
	cin>>h>>w;

	pii v[200002];
	for(int i=0;i<h;i++) cin>>v[i].f>>v[i].s;

	map<int,int> mp;
	for(int i=1;i<=w;i++) mp[i] = 0;

	map<int,int> mini = {{0,w}};

	for(int i=0;i<h;i++) {
		int l = v[i].f;
		int r = v[i].s;

		auto it = mp.lower_bound(l);
		int mn = inf;

		while(it!=mp.end() && it->f <= r) {
			mn = min(mn, -(it->f)+(it->s));
			auto it1 = it++;
			auto it2 = mini.find(it1->s);
			if(it2->s==1) mini.erase(it2);
			else it2->s --;
			mp.erase(it1);
		}

		if(r+1<=w && mn<inf) {
			mn += r + 1;
			if(it!=mp.end() && it->f == r + 1) {
				if(it->s > mn) {
					if(mini[it->s]==1) mini.erase(it->s);
					else mini[it->s]--;
					mini[mn]++;
					it->s = mn;
				}
			}
			else {
				mp.insert({r+1,mn});
				mini[mn]++;
			}
		}

		if(mini.size()) cout<<mini.begin()->f+i+1<<endl;
		else cout<<-1<<endl;

	}
}

Measured memory_bytes: 19240
#include <stdio.h>
typedef long long ll;
int isMultFirst(char* s, int n)
{
    ll stack[20], res=0;
    char *p;
    int sp=0;
    for(p=s;*p;++p) {
        if (*p=='*') {
            ll t=stack[--sp]*(*++p-'0');
            stack[sp++]=t;
        }
        else if (*p!='+') {
            stack[sp++]=*p-'0';
        }
    }
    while (sp>1) {
        ll a=stack[--sp];
        ll b=stack[--sp];
        stack[sp++]=a+b;
    }
    return stack[0]==n;
}
int isLeftToRight(char* s, int n)
{
    ll res=s[0]-'0';
    char* p;
    for(p=s+1;*p;p+=2) {
        if (*p=='+')
            res=res+(*(p+1))-'0';
        else
            res=res*((*(p+1))-'0');
    }
    return res==n;
}
int main(void)
{
    char s[20];
    int n;
    while (~scanf("%s%d", s, &n)) {
        int multi=isMultFirst(s, n);
        int ltor=isLeftToRight(s, n);
        puts(multi && ltor ? "U" : multi ? "M" : ltor ? "L" : "I");
    }
    return 0;
}

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

int main() {
  ll a, b, c, r, l;
  cin >> a >> b >> c;
  l = (c - (a + b)) * (c - (a + b));
  r = 4 * a * b;

  if (l > r && c - (a + b) > 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

int main(){
  int N;
  int b=1;
  int ans=0;
  cin >> N;
  vector<int> a(N+1);
  for(int i=1;i<=N;i++) cin >> a.at(i);
  for(int i=1;i<=N;i++){
    b=a[b];
    ans++;
    if(b==2) break;
  }
  if(b!=2) cout << -1;
  else cout << ans;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};



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


  
  


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=4e4+5,maxm=5e4+5;
const ll inf=1e18;
inline int fa(int u){ return u/2; }
inline int ls(int u){ return u*2; }
inline int rs(int u){ return u*2+1; }
struct heap{
	int hea[maxn],pos[maxn],siz;
	ll *dis;
	heap(ll a[],int n){
		dis=a; siz=n;
		int i;
		for (i=1;i<=n;i++){
			dis[i]=inf; hea[i]=i; pos[i]=i;
		}
	}
	void hswap(int u,int v){
		swap(hea[u],hea[v]);
		pos[hea[u]]=u; pos[hea[v]]=v;
	}
	void update(int u){
		if (u==1) return;
		if (dis[hea[fa(u)]]<=dis[hea[u]]) return;
		hswap(u,fa(u));
		update(fa(u));
	}
	void pushdown(int u){
		int v=u;
		if (ls(u)<=siz&&dis[hea[ls(u)]]<dis[hea[v]]) v=ls(u);
		if (rs(u)<=siz&&dis[hea[rs(u)]]<dis[hea[v]]) v=rs(u);
		if (u==v) return;
		hswap(u,v);
		pushdown(v);
	}
	void change(int u,ll val){
		dis[u]=val;
		update(pos[u]);
		pushdown(pos[u]);
	}
	int pop(){
		hswap(1,siz);
		siz--;
		pushdown(1);
		return hea[siz+1];
	}
};
struct gragh{
	int head[maxn],next[maxm],to[maxm],tot;
	ll wei[maxm],cost[maxn];
	gragh(){
		memset(head,-1,sizeof(head));
		tot=0;
	}
	void clear(){
		memset(head,-1,sizeof(head));
		tot=0;
	}
	void add(int u,int v,ll w,ll c){
		next[tot]=head[u];
		head[u]=tot;
		to[tot]=v;
		wei[tot]=w;
		cost[tot]=c;
		tot++;
	}
	void dijkstra(ll dis[],ll val[],int st,int n){
		heap hp(dis,n);
		hp.change(st,0);
		int i,u,v,ed;
		for (i=1;i<=n;i++) val[i]=inf;
		val[st]=0;
		while (hp.siz){
			u=hp.pop();
			for (ed=head[u];ed!=-1;ed=next[ed])
				if (dis[v=to[ed]]>dis[u]+wei[ed])
					hp.change(v,dis[u]+wei[ed]);
		}
		for (u=1;u<=n;u++) for (ed=head[u];ed!=-1;ed=next[ed])
			if (dis[v=to[ed]]==dis[u]+wei[ed])
			val[v]=min(val[v],cost[ed]);
	}
};
gragh g;
ll dis[maxn],val[maxn];
int main(){
	int n,m,i,u,v;
	ll w,c,ans;
	while (scanf("%d%d",&n,&m)&&(n||m)){
		g.clear();
		for (i=0;i<m;i++){
			scanf("%d%d%lld%lld",&u,&v,&w,&c);
			g.add(u,v,w,c);
			g.add(v,u,w,c);
		}
		g.dijkstra(dis,val,1,n);
		ans=0;
		for (i=1;i<=n;i++) ans+=val[i];
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 4568
import java.io.*;
public class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String sln;
        String pln;
        String ans="No";
        int plen,j;
        sln=br.readLine();
        pln=br.readLine();
        plen=pln.length();
        char s[]=(sln+sln.substring(0,plen-1)).toCharArray();
        char p[]=pln.toCharArray();
         
        for(int i=0;i<=s.length-plen;i++){
            if((s[i]==p[0])&&(s[i+plen-1]==p[plen-1])){
                     if(plen==1){
	                    	ans="Yes" ;
	                    	break;
	             }
                   for(j=1;j<plen-1;j++){
                        if(s[i+j]==p[j]){
                            continue;
                        }else break;
                 
                }
                    if(j==plen-1) ans="Yes";
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 17032
#include <stdio.h>
#include <math.h>

int main()
{
    int i;

    int n;
    scanf("%d", &n);
    int x[n], y[n];
    for( i = 0; i < n; ++i )
        scanf("%d", &x[i]);
    for( i = 0; i < n; ++i )
        scanf("%d", &y[i]);

    int p;
    double D;
    for( p = 1; p < 4; ++p ){
        D = 0;
        for( i = 0; i < n; ++i )
            D += (double)(pow(fabs(x[i] - y[i]), p));
        D = (double)pow(D, 1.0/p);
        printf("%lf\n", D);
    }

    D = 0;
    for( i = 0; i < n; ++i ){
        double tmp = (double)(fabs(x[i] - y[i]));
        D = D < tmp ? tmp : D;
    }
    printf("%lf\n", D);

    return 0;
}

Measured memory_bytes: 696
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())

    def solve():
        for i in range(100001):
            cur = i * 108 // 100
            if cur == N:
                return i
        return ":("

    print(solve())


if __name__ == '__main__':
    main()


Measured memory_bytes: 62936
xy = [list(map(int, input().split())) for _ in range(3)]
s = abs((xy[1][0]-xy[0][0])*(xy[2][1]-xy[0][1]) - (xy[1][1]-xy[0][1])*(xy[2][0]-xy[0][0])) / 2
a = ((xy[1][0]-xy[0][0])**2 + (xy[1][1]-xy[0][1])**2)**0.5
b = ((xy[2][0]-xy[0][0])**2 + (xy[2][1]-xy[0][1])**2)**0.5
c = ((xy[2][0]-xy[1][0])**2 + (xy[2][1]-xy[1][1])**2)**0.5
print(1/(2/max(a, b, c) + (a+b+c)/s/2))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
#define EPS 1e(-9);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
//--GLOBAL---------------------------------


ll dsum(ll n) {
    ll ret = 0;
    while (n > 0) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}
ll modpow(ll a, ll n, ll mod=INF2){ // a^n % MOD の計算
  ll res = 1;
  while (n > 0){
      if(n & 1) res = res * a % mod;
      a = a * a  % mod;
      n >>= 1;
  }
  return res;
}
//--MAIN-----------------------------------
void Main() {
    ll K; cin>>K;
    vector<ll> ve;
    rep(i,14){
        ll ans=modpow(10,i);
        reps(j,1,601){
            if(ans*j-1<=0) continue;
            ve.emplace_back(ans*j-1);
        }
    }
    SORT(ve);
    ve.erase(unique(ALL(ve)),ve.end());
    double vex[ve.size()];
    rep(i,ve.size()){
        vex[i]=(double)ve[i]/dsum(ve[i]);
    }
    vector<ll> ve2;
    rep(i,ve.size()){
        bool flag=true;
        reps(j,i+1,ve.size()){
            if(vex[i]>vex[j]){
                flag=false; break;
            }
        }
        if(flag){
            ve2.emplace_back(ve[i]);
        }
    }
    rep(i,K){
        cout<< ve2[i]<<"\n";
    }
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

const int maxn = 2e5 + 5;
int n; ll k;
ll a[maxn];
vector <ll> pos, neg, zero;
int psz, nsz, zsz;
ll NEG, ZERO;

ll count(ll x) {
	if (x < 0) {
		ll ans = 0;
		rep(i, psz) {
			ll thr = -((-x + pos[i] - 1) / pos[i]);
			ans += upper_bound(neg.begin(), neg.end(), thr) - neg.begin();
		}
		return ans;
	} else if (x == 0) {
		return NEG + ZERO;
	} else {
		ll ans = NEG + ZERO;
		rep(i, psz) {
			ll thr = x / pos[i];
			ans += min(pos.begin() + i, upper_bound(pos.begin(), pos.end(), thr)) - pos.begin();
		}
		rep(i, nsz) {
			ll thr = -(x / -neg[i]);
			ans += neg.end() - max(neg.begin() + i + 1, lower_bound(neg.begin(), neg.end(), thr));
		}
		return ans;
	}
}

int main() {
	scanf("%d %lld", &n, &k);
	rep(i, n) scanf("%lld", &a[i]);
	rep(i, n) {
		if (a[i] > 0) pos.pb(a[i]);
		else if (a[i] == 0) zero.pb(a[i]);
		else neg.pb(a[i]);
	}
	sort(pos.begin(), pos.end());
	sort(neg.begin(), neg.end());
	sort(zero.begin(), zero.end());
	psz = pos.size(), nsz = neg.size(), zsz = zero.size();
	NEG = 1LL * psz * nsz;
	ZERO = 1LL * zsz * (zsz - 1) / 2 + 1LL * zsz * (psz + nsz);
	ll lb = -1e18, rb = 1e18;
	while (lb < rb) {
		ll md = lb + (rb - lb) / 2;
		if (count(md) < k) lb = md + 1;
		else rb = md;
	}
	printf("%lld\n", lb);
	return 0;
}


Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

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

    string s;
    int a = 0, b = 0;
    cin >> s;
    int n = s.length();
    for(int i=0;i<n;i++){
    	if(s[i] == '1') a++;
    	else b++;
    }
    a = min(a, b);
    cout << a * 2 << endl;
    return 0;
}


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

typedef long long ll;

int main()
{
    int n;
    cin>>n;
    vector<int>a(n);
    vector<int>b(n);
    vector<int>c(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        cin>>b[i];
    for(int i=0;i<n;i++)
        cin>>c[i];
    sort(a.begin(),a.end());

    sort(c.begin(),c.end());
    ll ret=0;
    for(int i=0;i<b.size();i++){
        int piv=b[i];
        ret+=1LL*(lower_bound(a.begin(),a.end(),piv)-a.begin())*(c.begin()+n-upper_bound(c.begin(),c.end(),piv));
    }
    cout<<ret;
}


Measured memory_bytes: 1408
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:isize,
    b:isize,
    }
    println!("{}",(a+b)%24)
}

Measured memory_bytes: 2124
x, n = gets.split.map(&:to_i)
nums = gets.split.map(&:to_i)
if n == 0
  puts x
  exit
else
  0.upto(200) do |i|
    if !nums.include?(x - i)
      puts x - i
      exit
    elsif !nums.include?(x + i)
      puts x + i
      exit
    end
  end
end


Measured memory_bytes: 14412
S=str(input())
out=["Yes","No"]
flg=0

for i in range(len(S)):
    if i%2==0:
        if S[i]!="R" and S[i]!="U" and S[i]!="D":
            flg=1
            break
    if i%2==1:
        if S[i]!="L" and S[i]!="U" and S[i]!="D":
            flg=1
            break

print(out[flg])

Measured memory_bytes: 3060
import sys

input = sys.stdin.readline

n = int(input())

a_list = list(map(int, input().split()))
sort_a_list = sorted(a_list)

l = 0
r = 0
ans = 0
max_ans = 0
sabun = 0
#print(sort_a_list)

while (r < n):
    #print(l,r)
    #print(ans)
    #print(sabun)
    if (sabun <= 2):
        if sort_a_list[r] - sort_a_list[l] > 2:
            l += 1
            sabun = sort_a_list[r] - sort_a_list[l]
            ans -= 1
            continue
        ans += 1
        max_ans = max(max_ans,ans)
        r += 1
        if r >= n:
            break
        sabun = sort_a_list[r] - sort_a_list[l]
        
    else:
        l += 1
        sabun = sort_a_list[r] - sort_a_list[l]
        ans -= 1
print(max_ans)

Measured memory_bytes: 20772
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

struct Info{
	Info(){
		min = max = value = 0;
	}
	int min,max,value;
};

int main(){

	int D,N;
	scanf("%d %d",&D,&N);

	int temperature[D];

	for(int i = 0; i < D; i++){
		scanf("%d",&temperature[i]);
	}

	Info info[N];
	int dp[D+1][N];
	for(int i = 0; i < D+1; i++){
		for(int k = 0; k < N; k++)dp[i][k] = -1;
	}

	for(int i = 0; i < N; i++){
		scanf("%d %d %d",&info[i].min,&info[i].max,&info[i].value);
	}

	int maximum = 0;

	for(int i = 0; i < N; i++){
		if(info[i].min <= temperature[1] && info[i].max >= temperature[1]){
			for(int k = 0; k < N; k++){
				if(info[k].min <= temperature[0] && info[k].max >= temperature[0]){
					dp[2][i] = max(dp[2][i],abs(info[i].value-info[k].value));
					maximum = max(maximum,dp[2][i]);
				}
			}
		}
	}



	for(int day = 3; day <= D; day++){
		for(int i = 0; i < N; i++){
			if(info[i].min <= temperature[day-1] && info[i].max >= temperature[day-1]){
				for(int k = 0; k < N; k++){
					if(dp[day-1][k] != -1){
						dp[day][i] = max(dp[day][i],dp[day-1][k] + abs(info[i].value-info[k].value));
						maximum = max(maximum,dp[day][i]);
					}
				}
			}
		}
	}

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

	return 0;
}

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

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

    if (c >= a && c <= b)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; cin >> n;
    vi q(n+1, -1);
    rep(i, n){
        int a; cin >> a; a--;
        q[a] = i;
    }

    int mx = 0;
    int cnt = 1;
    rep(i, n){
        if(q[i] < q[i+1]) {
            cnt++; 
        }
        else{
            mx = max(mx, cnt);
            cnt = 1;
        }
    }     
    cout << n - mx << endl;
    return;
}

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

Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   1e9 +7  ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
void solve(){
    vector < int > a(5) ;
    int ans = 0 ;
    for( int i = 0 ; i < 5 ; i++){
        cin >> a[i] ;
        if(a[i]==0){
            ans = i+1 ;
        }
    }
    cout << ans ;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1 ;
    //cin >> t ;
    while(t--){
        solve( );
    }
}


Measured memory_bytes: 3652
#include <iostream>

#include <vector>

using namespace std;

int main(){

	int n;
	vector <int> a;

	cin >> n;

	int t;
	for(int i=0; i < n; ++i){
		cin >> t;
		a.push_back(t);
	}


	if( n % 2 == 0){
		for(int i = 0; i < n/2; ++i)
			cout << a[n - 1 - 2*i] << " ";
		for(int i = 0; i < n/2; ++i)
			cout << a[2*i] << " ";
		cout << endl;
	}else{
		for(int i = 0; i < n/2; ++i)
			cout << a[n - 1 - 2*i] << " ";
		cout << a[0]  << " ";
		for(int i = 0; i < n/2; ++i)
			cout << a[2*i + 1] << " ";
		cout << endl;
	}

	return 0;
}

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


int main(){
  int a,b;cin>>a>>b;
  a==b?cout<<2*a:cout<<2*max(a,b)-1;
}




Measured memory_bytes: 256
/*https://atcoder.jp/contests/abc132/tasks/abc132_c*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int count = 0;
	// cout << a[n / 2 ] << " " << a[n / 2 - 1];
	if (n % 2 == 0 && a[n / 2 ] != a[n / 2 - 1])
		count = a[n / 2 ] - a[n / 2 - 1];
	cout << count;
}

Measured memory_bytes: 4012
def main():
    import sys
    input = sys.stdin.readline
    D, N = map(int, input().split())
    if N != 100:
        print(N, end="")
        for i in range(D):
            print("00", end="")
        print("")
    else:
        print(100 ** (D+1) + 100 ** D)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long K = sc.nextLong();
        
        System.out.print((K <= A ? A - K : 0) + " ");
        long kA = K - A < 0 ? 0 : K - A;
        System.out.println(kA <= B ? B - kA : 0);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int MOD=2019;
int modune[2019];
int main()
{
	string input;
	cin>>input;
	int precal=0,p=1;
	modune[0]=1;
	for(int i=input.length()-1;i>=0;i--)
	{
		precal=(precal+(p*(input[i]-'0'))%MOD)%MOD;
		p=(p*10)%MOD;
		modune[precal]++;
	}
	long long output=0;
	for(int i=0;i<2019;i++)
		output+=(modune[i]*(modune[i]-1))/2;
	cout<<output<<endl;
}

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

using ll = long long;

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

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

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	long long N;
	scanf("%lld",&N);
	long long R;
	scanf("%lld",&R);

	if (N >= 10)
	{
		cout << R << endl;
	} else {
		cout << R + 100 * (10 - N) << endl;
	}

	return 0;
}


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

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	multiset<int> s;
	s.insert(a[0]);
	REP(i, n - 1) {
		int v = a[i];
		auto itr = s.lower_bound(v);
		if (itr != s.begin()) s.erase(--itr);
		s.insert(v);
	}
	int ans = int(s.size());
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5376
//

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    int N;cin>>N;
    vector<int> P(N),Q(N),PP,QQ;
    rep(i,0,N)cin>>P[i];
    rep(i,0,N)cin>>Q[i];
    PP = P;QQ = Q;
    sort(range(PP));
    sort(range(QQ));
    int Ans = 1;
    while(true){
        if(PP==P)break;
        next_permutation(range(PP));
        Ans++;
    }
    while(true){
        if(QQ==Q)break;
        next_permutation(range(QQ));
        Ans--;
    }
    cout << abs(Ans-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    char vowel[5] = {'a','e','i','o','u'},c;
    int i;

    scanf("%c",&c);

    for (i = 0; i < 5; i++)
    {
        if (vowel[i] == c)
        {
            break;
        }
    }
    
    printf(i == 5 ? "consonant\n" : "vowel\n");
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

void solve() {
    using E = tuple<int, int, int>;
    int L;
    cin >> L;
    --L;
    int l = L, t = 0;
    for (; (1 << (t + 1)) - 1 <= l; ++t) {
    }
    const int N = t + 1;
    vector<E> ans;
    rep(i, t) {
        ans.emplace_back(i + 1, i + 2, 0);
        ans.emplace_back(i + 1, i + 2, 1 << i);
    }
    l -= 1 << t;
    int base = 1 << t;
    while (l >= 0) {
        for (t = 0; (1 << (t + 1)) - 1 <= l; ++t);
        ans.emplace_back(t + 1, N, base);
        base += 1 << t;
        l -= 1 << t;
    }
    cout << N << ' ' << sz(ans) << endl;
    each(a, ans) {
        int x, y, z;
        tie(x, y, z) = a;
        cout << x << ' ' << y << ' ' << z << endl;
    }
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,i,j;
  string ans="Yes";
  cin>>h>>w;
  vector<string> s(h);
  for(i=0;i<h;i++) cin>>s.at(i);
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(s.at(i).at(j)=='#'){
        if(0<i&&i<h-1&&0<j&&j<w-1&&s.at(i-1).at(j)=='.'&&s.at(i).at(j-1)=='.'&&s.at(i).at(j+1)=='.'&&s.at(i+1).at(j)=='.') ans="No";
        else if(0==i&&0<j&&j<w-1&&s.at(i).at(j-1)=='.'&&s.at(i).at(j+1)=='.'&&s.at(i+1).at(j)=='.') ans="No";
        else if(i==h-1&&0<j&&j<w-1&&s.at(i-1).at(j)=='.'&&s.at(i).at(j-1)=='.'&&s.at(i).at(j+1)=='.') ans="No";
        else if(0<i&&i<h-1&&0==j&&s.at(i-1).at(j)=='.'&&s.at(i).at(j+1)=='.'&&s.at(i+1).at(j)=='.') ans="No";
        else if(0<i&&i<h-1&&j==w-1&&s.at(i-1).at(j)=='.'&&s.at(i).at(j-1)=='.'&&s.at(i+1).at(j)=='.') ans="No";
        else if(0==i&&0==j&&s.at(i).at(j+1)=='.'&&s.at(i+1).at(j)=='.') ans="No";
        else if(0==i&&j==w-1&&s.at(i).at(j-1)=='.'&&s.at(i+1).at(j)=='.') ans="No";
        else if(i==h-1&&0==j&&s.at(i-1).at(j)=='.'&&s.at(i).at(j+1)=='.') ans="No";
        else if(i==h-1&&j==w-1&&s.at(i-1).at(j)=='.'&&s.at(i).at(j-1)=='.') ans="No";
        if(ans=="No") break;
      }
      if(ans=="No") break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3572
import numpy as np
import sys
from itertools import product

n, m, x = map(int, input().split())
c = []
A = []

ans = 10**9

products = list(product([0,1], repeat=n))

for _ in range(n):
    c_a = list(map(int, input().split()))
    c.append(c_a[0])
    A.append(c_a[1:])

min_price = 10**9

for p in products:
    sum_alg = [0]*m
    price = 0
    for i, pp in enumerate(p):
        if pp == 1:
            for j in range(m):
                sum_alg[j] += A[i][j]
            price += c[i]

    if min(sum_alg) >= x: 
        min_price = min(price, min_price)


if min_price == 10**9:
    print(-1)
else:
    print(min_price)

Measured memory_bytes: 27396
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo 1e18
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>

using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=3e3+10,mod=998244353;

int main ()
{
    FASTIO;
    ll h1 , m1 , h2 , m2 , k ;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    ll mn = h1*60 + m1;
    ll mn2 = h2*60+m2;
    cout << mn2 - mn - k << endl;
    return 0;
}
/**


*/


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

int main()
{
	string N;
	string ans="No";
	cin>>N;
	for(int i=0;i<3;i++){
		if(N[i]=='7'){
			ans="Yes";
		}
	}
	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main(void) {
	string s;
	cin >> s;
	int cnt = 0;
	char prev = s[0];
	for (int i = 1; i < s.size(); ++i) {
		if (s[i] != prev) ++cnt;
		prev = s[i];
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;

int main()
{
    int n,x,i,dap = 0;
    
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&x);
        if(i%2==1&&x%2==1) dap++;
    }
    printf("%d",dap);
    return 0;
}


Measured memory_bytes: 3720
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class _Class
{
	void _()
	{
		var N = _Ns()[0];

		var a = new ulong[N];
		var b = new ulong[N];
		for (int i = 0; i < N; i++)
		{
			var AB = _Ns();
			a[i]=(ulong)AB[0];
			b[i]=(ulong)AB[1];
		}

		ulong s = 0;
		for (int i = N - 1; i >= 0; i--)
		{
			ulong v = a[i] + s;

/*			if (v <= b[i])
			{
				s += (b[i] - v);
			}
			else
*/			{
				ulong d = v % b[i];
				if (d == 0)
				{
				}
				else
				{
					ulong dd = b[i] - d;
					s += dd;
				}
			}
		}

		Console.WriteLine(s);
	}

	static void Main(string[] args)
  {
    new _Class()._();
  }

  #region

  string _S()
  {
    return Console.ReadLine();
  }

  string[] _Ss()
  {
    return Console.ReadLine().Split();
  }

  int[] _N(int n)
  {
    var x = new int[n];
    for (var i = 0; i < n; i++)
    {
      x[i] = int.Parse(Console.ReadLine());
    }
    return x;
  }

  int[] _Ns()
  {
    var ss = Console.ReadLine().Split();

    var x = new int[ss.Length];
    for (var i = 0; i < ss.Length; i++)
      x[i] = int.Parse(ss[i]);

    return x;
  }
  #endregion
}


Measured memory_bytes: 8372
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, h = map(int, readline().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, readline().split())
max_a = max(a)
check = len([i for i in b if i > max_a])
b.sort(reverse=True)
for i in range(check):
    h -= b[i]
    if h <= 0:
        print(i + 1)
        exit()
if h % max_a == 0:
    print(h // max_a + check)
else:
    print(h // max_a + check + 1)


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

using namespace std ;
typedef long long ll;
typedef string str;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii ;

#define REP(i, n) for (ll (i) = 0; (i) < (ll)(n); i++) 
#define FOR(i, a, b) for(ll (i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define CHI 1000000000000000003
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}

struct UnionFind {
  vint par ;  //iの親
  vint rank ; //木の深さ
  vll siz ; //iの属する集合の要素数
  
  //n要素の初期化
  void init(int n){
    REP(i,n){
      par.PB(i) ;
      rank.PB(0) ;
      siz.PB(1) ;
    }
  }
  
  //木の根を求める
  //根が一緒なら同じ集合と判断するため
  int find(int x){
    if(par[x]==x){
      return x ;
    }
    else{
      return par[x] = find(par[x]) ;
    }
  }
  
  //木の併合
  //記録してあるrankをもとに併合
  void unite(int x,int y){
    x = find(x) ;
    y = find(y) ;
    if(x==y){
      return ;
    }
    
    if(rank[x] < rank[y]){
      par[x] = y ;
      siz[y] += siz[x] ;
    }
    else{
      par[y] = x ;
      siz[x] += siz[y] ;
      if(rank[x]==rank[y]){
        rank[x]++ ;
      }
    }
  }
  
  //xとyが同じ集合に属するか
  bool same(int x,int y){
    return find(x) == find(y) ;
  }
  
  ll size(int x){
    return siz[find(x)] ;
  }
  
};


//-------------------------------------------------
// メモ
/*






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


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m ;
  cin >> n >> m ;
  vll ans(m,0) ;
  
  UnionFind tree ;
  tree.init(n) ;
  
  vll you(n,1) ;
  //iの属する集合の要素数
  
  UnionFind memo ;
  memo.init(n) ;
  
  vpii pai(m) ;
  
  REP(i,m){
    int a, b ;
    cin >> a >> b ;
    pai[i] = MP(a-1,b-1) ;
    memo.unite(a-1,b-1) ;
  }
  
  reverse(ALL(pai)) ;
  
  
  vll num2(n,0) ;
  
  REP(i,n){
    num2[memo.find(i)]++ ;
  }
  
  
  ans[0] = 0 ;
  
  REP(i,n){
    ans[0] += num2[i]*(num2[i]-1)/2 ;
  }
  
  REP(i,m-1){
    int A, B ;
    A = pai[i].FI ;
    B = pai[i].SE ;
    if(!tree.same(A,B)){
      ans[i+1] = ans[i] - (tree.size(A)*tree.size(B)) ;
    }
    else{
      ans[i+1] = ans[i] ;
    }
    tree.unite(A,B) ;
  }
  
  reverse(ALL(ans)) ;
  
  REP(i,m){
    cout << ans[i] <<endl ;
  }

  return 0 ;
}

Measured memory_bytes: 8808
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect
from random import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N = read()
s = input()
t = input()

print(2 * N - max(k for k in range(N+1) if s[N-k:] == t[:k]))

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

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

	string s,t;

	cin >> s;
	cin >> t;
	t = t + t;

	for(int i=0;i<t.length();i++)
	{
		string sub = t.substr(i,s.length());
		if(sub==s)
		{
			cout << "Yes" << '\n';
			return 0;
		}
	}

	cout << "No" << '\n';

	return 0;	
}

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

bool memo[1000010] = {};

queue<int> que;

int main(){
  long long n, p;
  cin >> n >> p;

  for(int i = 2;i < 1000010;i++){
    if(!memo[i]){
      que.push(i);
      for(int j = i*2;j < 1000010;j+=i){
        memo[j] = true;
      }
    }
  }

  long long work = p;

  long long ans = 1;
  int ww = que.front();
  que.pop();

  int atmp = 0;
  while(work > 1 && !que.empty()){
    if(work % ww == 0){
      atmp++;
      if(atmp == n){
        ans *= ww;
        atmp = 0;
      }
      work /= ww;
    }else{
      atmp = 0;
      ww = que.front();
      que.pop();
    }
  }

  if(work == 1){
    cout << ans << endl;
  }else{
    if(n == 1){
      cout << p << endl;
    }else{
      cout << ans << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf = 1e18;
int n;
ll cst[26], sat[366][26], last[26], tmp[26];
ll tester(vector<int>v){
	ll res = 0ll;
	memset(last, 0ll, sizeof(last));
	for(int nw, i=0; i<n; i++){
		nw = v[i];
		res += sat[i][nw-1];
		last[nw-1] = i+1;
		for(int j=0; j<26; j++)
			res -= cst[j]*(i+1-last[j]);
	}
	return res;
}
int rand(int x){return rand()%x+1;}
vector<int>gen(int hm, int x){
	vector<int>res;
	for(int cr=rand()%x+1, times=0; times<hm; cr=rand(x)%x+1, times++)
		res.push_back(cr);
	return res;
}
int randlf(int l, int r){return rand()%(r-l+1)+l;}
vector<int>lgg={1, 18, 36, 54, 72, 90, 108, 126, 144, 162, 180};
vector<int>best;
int main(){
	scanf("%d", &n);
	memset(last, 0ll, sizeof(last));
	for(int i=0; i<26; i++) scanf("%lld", &cst[i]);
	for(int i=0; i<n; i++) for(int j=0; j<26; j++)
		scanf("%lld", &sat[i][j]);
	ll res = 0ll;
	vector<int>base;
	for(int nw, i=0; i<n; i++){
		memset(tmp, 0ll, sizeof(tmp));
		for(nw=0; nw<26; nw++){
			tmp[nw] += sat[i][nw];
			for(int j=0; j<26; j++) if(j != nw)
				tmp[nw] -= cst[j] * (i+1-last[j]);
		}
		ll get = -inf; int id = -1;
		for(nw=0; nw<26; nw++) 
			if(get < tmp[nw]){
				get = tmp[nw]; id = nw;
			}else if(get == tmp[nw] && cst[nw] > cst[id]){
				get = tmp[nw]; id = nw;
			}
		base.push_back(id+1); 
		last[id] = i+1; res += tmp[nw];
	}
	best=base;
	clock_t t=clock();
	for(;clock()-t<1500;){
		for(int k=10; k>0; k--){
			vector<int>changeid, changeval;
			for(int tt=0; tt<5*(11-k); tt++){
				int cv = randlf(lgg[k-1], lgg[k]);
				changeid = gen(cv, 365);
				changeval = gen(cv, 26);
				vector<int>cur = best;
				for(int i=0; i<cv; i++)
					cur[changeid[i]-1] = changeval[i];
				if(tester(best) < tester(cur))
					best = cur;
			}
		}
	}
	for(int i=0; i<n; i++) printf("%d\n", best[i]);
	return 0;
}

Measured memory_bytes: 3912
var
	K:Longint;
	L,R,M:int64;
function check(T:int64):Longint;
var
	dp:Array[1..12,0..1,0..9]of Longint;
	dpz:Array[1..12,0..1]of Longint;
	S:String;
	ls,i,j,k,l,nj,lim,sum,llim,rlim:Longint;
begin
	Str(T,S);
	ls:=length(S);
	for i:=1 to ls+1 do for j:=0 to 1 do begin
		for k:=0 to 9 do dp[i,j,k]:=0;
		dpz[i,j]:=0;
	end;
	dpz[1,0]:=1;
	for i:=1 to ls do begin
		for j:=0 to 1 do begin
			if j=0 then lim:=ord(S[i])-48 else lim:=9;
			inc(dpz[i+1,1],dpz[i,j]);
			for l:=1 to lim do begin
				nj:=j;
				if l<lim then nj:=1;
				inc(dp[i+1,nj,l],dpz[i,j]);
			end;
			for k:=0 to 9 do begin
				if dp[i,j,k]=0 then continue;
				llim:=k-1;if llim<0 then llim:=0;
				rlim:=k+1;if rlim>lim then rlim:=lim;
				for l:=llim to rlim do begin
					nj:=j;
					if l<lim then nj:=1;
					inc(dp[i+1,nj,l],dp[i,j,k]);
				end;
			end;
		end;
	end;
	sum:=0;
	for k:=0 to 9 do for i:=0 to 1 do begin
		inc(sum,dp[ls+1,i,k]);
	end;
	check:=sum;
end;
begin
	read(K);
	L:=0;
	R:=3234566667;
	while R-L>1 do begin
		M:=(L+R)div 2;
		if check(M)>=K then R:=M else L:=M;
	end;
	writeln(R);
end.


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

using namespace std;

const int N=1e6+10;
vector<int> G[N];
int order[N];
int low[N];
int p[N];
int child=0;
int cnt=0;
vector<pair<int,int> > ans;

void add(int s,int t)
{
    G[s].push_back(t);
    G[t].push_back(s);
}

void dfs(int v)
{
    order[v]=low[v]=++cnt;
    for(int i=0;i<G[v].size();i++)
    {
        int u=G[v][i];
        if(!order[u])
        {
            if(v==0) child++;
            p[u]=v;
            dfs(u);
            low[v]=min(low[v],low[u]);
            if(low[u]>order[v]) ans.push_back(make_pair(min(u,v),max(u,v)));
        }else if(p[v]!=u)
        {
            low[v]=min(low[v],order[u]);
        }
    }
}

int main()
{
    int v,e;
    cin>>v>>e;

    for(int i=0;i<e;i++){
        int s,t;
        cin>>s>>t;
        add(s,t);
    }

    dfs(0);
    sort(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++)
    {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }

    return 0;
}



Measured memory_bytes: 28084
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

int n, m;
string a[101], b[101];
map<string , int > s, t;

int read() {
    int ret, f = 1;
    char ch;
    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);
    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');
    return ret * f;
}

void print(int x) {
    if(x < 0) putchar('-'), x = -x;
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
}

int main() {
    n = read();
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        ++s[a[i]];
    }
    m = read();
    for(int i = 1; i <= m; ++i) {
        cin >> b[i];
        ++t[b[i]];
    }
    int ans = 0;
    for(int i = 1; i <= n; ++i) {
        int t1 = s[a[i]], t2 = t[a[i]];
        if(t1 > t2) ans = max(ans, t1 - t2), s[a[i]] = 0;
    }
    print(ans);
    return 0;
}


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

int main() {
    int H, W, K;
    vector<string> s;
    string  tmp;
    int     black, ans = 0;
    
    cin >> H >> W >> K;
    
    for ( int ii = 0; ii < H; ii++ ) {
        cin >> tmp;
        s.push_back(tmp);
    }
    
    for ( int maskR = 0; maskR <= (1 << H) - 1; maskR++ ) {
        for ( int maskC = 0; maskC <= (1 << W) - 1; maskC++ ) {
            black = 0;
            for ( int ii = 0; ii < H; ii++ ) {
                for ( int jj = 0; jj < W; jj++ ) {
                    if ( ((maskR >> ii) & 1) == 0 && ((maskC >> jj) & 1) == 0 &&  s[ii][jj] == '#' ) {
                        black++;
                    }
                }
            }
            if ( black == K ) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
let () = Scanf.scanf "%d\n" @@ fun n ->
  let ps = Array.init n @@ fun _ -> Scanf.scanf "%f " @@ fun p -> p in
  let dp = Array.make_matrix (n + 1) (2 * n + 3) 0. in
  dp.(0).(n + 1) <- 1.;
  for i = 0 to n - 1 do
    for j = n - i to n + 2 + i do
      dp.(i + 1).(j) <- ps.(i) *. dp.(i).(j - 1) +. (1. -. ps.(i)) *. dp.(i).(j + 1)
    done
  done;
  Printf.printf "%.12f" @@ Array.fold_left ( +. ) 0. @@ Array.init (n + 1) @@ fun i -> dp.(n).(i + n + 1)


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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, a; cin >> n >> a;

	int i = 1;
	int b = 0;
	for (int i = 1; i < n; i++) {
		if (n - 500 * i < 500) {
			b = n - (500 * i);
			break;
		}
		else {
			continue;
		}

	}
	if (b < 0)b = 0;
	if (b <= a) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	int a[10000], min, max, n, i;
	long long sum = 0;

	scanf("%d", &n);			/* ???????????´??°?????°n?????\??? */
		for(i = 0; i < n; i++){
		scanf("%d", &a[i]);		/* ?????????n????????´??°a?????\??? */
			sum += a[i];		/* ????¨????sum */
	}
	max = min = a[0];
	for(i = 1; i < n; i++){			/* n??????????¨?????????????????????§for?????§??°?????? */
		if(a[i] > max)max = a[i];	/* ?????§???max */
		if(a[i] < min)min = a[i];	/* ????°????min */
	}

	printf("%d %d %lld\n", min, max, sum);

	return 0;
}

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

#define int long long

auto main() -> signed {
    string A, B, C;
    cin >> A >> B >> C;
    if(A[A.size()-1]==B[0]&&B[B.size()-1]==C[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}



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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> V(N);
    rep(i, N) cin >> V[i];
    
    int ans = -100100100;
    rep(n, N + 1) rep(m, N + 1) {
        if (n + m > N || n + m > K) continue;
        vector<int> S;
        rep(i, n) S.push_back(V[i]);
        rep(i, m) S.push_back(V[N - i - 1]);
        sort(S.begin(), S.end());
        vector<bool> toru(S.size(), true);
        rep(i, min((int)S.size(), K - n - m)) {
            if (S[i] < 0) toru[i] = false;
        }
        int sum = 0;
        rep(i, S.size()) {
            if (toru[i]) sum += S[i];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[]) {
    
    double r, s, l;
    scanf("%lf", &r);
    
    //計算
    s = M_PI * r * r;
    l = 2 * M_PI * r;
    
    printf("%f %f\n", s, l);
    
    return 0;
}


Measured memory_bytes: 2104