akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;


signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
 
    string s;
    cin>>s;
    int n=s.size();
    int cnt=1;
    int ans[n]={};
    
    for(int i=1;i<n;i++){
        if(s[i]=='R') cnt++;
        if(s[i]=='L'){
            ans[i] += cnt/2;
            ans[i-1]+=(cnt+1)/2;
            cnt=0;
        }
    }
    cnt=1;
    for(int i=n-2;i>=0;i--){
        if(s[i]=='L')cnt++;
        if(s[i]=='R'){
            ans[i]+=cnt/2;
            ans[i+1] += (cnt+1)/2;
            cnt=0;
        }
    }


    for(int i=0;i<n;i++){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 1104
from collections import Counter

def update(dic, b, c):
    n = dic.pop(b)
    dic[c] = n + dic.get(c, 0)
    
def calc_diff(dic, b, c):
    if dic.get(b):
        return c * dic[b] - b * dic[b]
    return 0

def calc_total(dic):
    return sum(k * v for k, v in dic.items())

N = int(input())
lis = list(map(int, input().split()))
dic = dict(Counter(lis))
Q = int(input())
total = calc_total(dic)
for _ in range(Q):
    B, C = map(int, input().split())
    diff = calc_diff(dic, B, C)
    total += diff
    print(total)
    if diff:
        update(dic, B, C)

Measured memory_bytes: 21380
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  int x;
  cin >> x;
  int t = 0;
  for (int i = 1; i < 10000000; ++i) {
    t += i;
    if (t >= x) {
      if (t == 0) {
        cout << i - 1 << endl;
        return 0;
      } else {
        cout << i << endl;
        return 0;
      }
    }
  }
}


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

int main(){
	int n,m; cin>>n>>m;
	vector<int>sum(m);
	for(int i=0;i<n;++i){
		int k; cin>>k;
		for(int j=0;j<k;++j){
			int a; cin>>a;
			++sum.at(a-1);
		}
	}
	cout<<count(sum.begin(),sum.end(),n)<<"\n"s;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007LL
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  150
#define tmod             998244353LL
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll SUMD(ll n);
ll BS(vector<pair< ll ,ll > > &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
//bool P[N+1];
void Sieve(int n=N);
ll Powb(ll b,ll n);

int main()
{
fast;
ll q=1,t;
//cin >> q;
while(q--)
{
    ll i,j,n,m,k,l,r,a,b,c=0,d,e,g,p,q,u,v,w,x,y,flag=1;
    //n=m=k=i=j=l=r=a=b=c=d=u=v=w=p=x=y=0;
    cin >> n >> m;
    if(m>=n) cout << "unsafe";
        else cout << "safe";
}
    return 0;
}

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

ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}

ll SUMD(ll n)
{   ll sum=0;
    while(n>0){sum += n%10;n = n/10;}
    return sum;

}
ll BS(vector<pair<ll,ll> > &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid].F==ser)
    {
        return mid;
    }
    else if(PS[mid].F > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}
/*
void Sieve(int n)
{
    memset(P,true,sizeof(P));
    P[0] = false;
    P[1]= false;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i])
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                P[j]=false;
            }
        }
    }

}

*/


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using db = double;
#define pb push_back

ll n, a, b, c, d;

bool solve() {
	--n;
	for (ll i = 0; i <= n; ++i) {
		ll j = n - i;
		ll L = c * i + -d * j;
		ll R = L + (d - c) * n;
		if (L <= b && b <= R)
			return true;
	}
	return false;
}

int main() {
	cin >> n >> a >> b >> c >> d;
	b -= a;
	a -= a;
	
	puts(solve() ? "YES" : "NO");
	
	return 0;
}


Measured memory_bytes: 256
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    ll a[402],cum[402];
    ll dp[402][402];
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i];
    	cum[i]=a[i];
    }
    for (int i = 1; i < n; ++i)
    {
    	cum[i]+=cum[i-1];
    }
    for (int i = 0; i <=400; ++i)
    {
    	for (int j = 0; j <=400 ; ++j)
    	{
    		if(i==j)
    		{
    			dp[i][j]=0;
    			continue;
    		}
    		dp[i][j]=10000000000000;
    	}
    }
    // for (int i = 0; i < n; ++i)
    // {
    // 	cout<<cum[i]<<" ";
    // }
    // cout<<'\n';
    for (int j = 1; j < n; ++j)
    {
    	for (int i = j-1; i >=0; --i)
    	{
    		// cout<<i<<" "<<j<<" ";
    		if(j==i+1)
    		{
    			dp[i][j]=a[i]+a[j];
    			// cout<<'\n';
    			continue;
    		}
    		ll ans;
    		if(i!=0)
    		{
    			ans=cum[j]-cum[i-1];
    		}
    		else
    		{
    			ans=cum[j];
    		}
    		for (int k = i; k < j; ++k)
    		{
    			// cout<<"k "<<k<<" ";
    			dp[i][j]=min(dp[i][k]+dp[k+1][j]+ans,dp[i][j]);
    		}
    		// cout<<'\n';
    	}
    }
    // for (int i = 0; i < n; ++i)
    // {
    // 	for (int j = 0; j < n; ++j)
    // 	{
    // 		cout<<dp[i][j]<<" ";
    // 	}
    // 	cout<<'\n';
    // }
    cout<<dp[0][n-1]<<'\n';
}


Measured memory_bytes: 1536
program beginning
	implicit none
    integer :: a,b,c,d,i
    integer :: status(4)
    
    read(*,*) a,b,c,d
    
    status=0
    
    i = 1
    if (a == i .or. b == i .or. c==i .or. d==i ) then
    	status(1)=1
    end if
    i = 9
    if (a == i .or. b == i .or. c==i .or. d==i ) then
    	status(2)=1
    end if
    i = 7
    if (a == i .or. b == i .or. c==i .or. d==i ) then
    	status(3)=1
    end if
    i = 4
    if (a == i .or. b == i .or. c==i .or. d==i ) then
    	status(4)=1
    end if
    
    do i = 1, 4
    	if ( status(i)  == 0 ) then
        	write(*,*) 'NO'
            stop
        end if
	end do
    
    write(*,*) 'YES'
    
    stop
end program beginning


Measured memory_bytes: 2860
n,m = map(int, input().split())
AC = [False]*n
WA = [0]*n

for i in range(m):
    p,s = input().split()
    p = int(p)-1

    if AC[p] == False:
        if s == 'WA':
            WA[p] += 1
        else:
            AC[p] = True

wa = 0

for i in range(n):
    if AC[i]:
        wa += WA[i]
        

print(AC.count(True),wa)



Measured memory_bytes: 10388
from collections import Counter

N = int(input())
S = Counter()
for _ in range(N):
    S[input()] += 1

# print(S)
maxCnt = 0
for key in list(S.keys()):
    cnt = S[key]
    if cnt > maxCnt:
        ans = [key]
        maxCnt = cnt
    elif cnt == maxCnt:
        ans.append(key)

ans.sort()
for key in ans:
    print(key)


Measured memory_bytes: 96984
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

	int dif = b - a;
	
	int dp[dif] = {0};
	dp[0] = 1;
	for (int i = 1; i < dif; i++){
		dp[i] = dp[i - 1] + i + 1;
	}

	cout << dp[dif - 1]  - b<< endl;

}


Measured memory_bytes: 256
#include <cstdio>

const int maxn=3005;

double dp[maxn][maxn];
double l[maxn];

int main(){
	int n;
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%lf", &l[i]);
	}
	dp[0][0]=1;
	for(int i=1; i<=n; i++){
		dp[i][0]=dp[i-1][0]*(1.0-l[i-1]);
		for(int j=1; j<=i; j++){
			dp[i][j]=dp[i-1][j-1]*l[i-1]+dp[i-1][j]*(1.0-l[i-1]);
		}
	}
	double sol=0;
	for(int i=n/2+1; i<=n; i++){
		sol+=dp[n][i];
	}
	printf("%.9lf\n", sol);
	return 0;
}

Measured memory_bytes: 68992
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }
        for (int m = 0; m < a.length - 1; m++) {
            System.out.print(a[m] + " ");
        }
        System.out.print(a[a.length - 1] + "\n");
        for (int i = 1; i < a.length; i++) {

            int key = a[i];
            int j = i - 1;
            while (j >= 0 && a[j] > key) {
                a[j + 1] = a[j];
                j--;
            }
            a[j + 1] = key;

            for (int m = 0; m < a.length - 1; m++) {
                System.out.print(a[m] + " ");
            }
            System.out.print(a[a.length - 1] + "\n");

        }
    }
}



Measured memory_bytes: 31508
#include <bits/stdc++.h>
using namespace std;
#define eni(x) template < class c > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
template < class c > struct rge { c b, e; };
template < class c > rge<c> range(c i, c j) { return rge<c>{i, j}; }
template < class c > auto dud(c* x) -> decltype(cerr << *x, 0);
template < class c > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; return * this; }
eni(==) return * this << range(begin(i), end(i)); }
template < class c, class b > debug & operator <<(pair < b, c > d) {
  return * this << "(" << d.first << ", " << d.second << ")";
}
template < class c > debug & operator <<(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  return * this << "]";
}
#else
template < class c > debug & operator <<(const c&) { return * this; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 300005
mt19937 myrand(time(0));

struct SegmentTree{
    int tree[4*mx];

    void init(){
        memset(tree,0,sizeof tree);
    }

    void update(int pos, int l, int r, int idx, int value){
        if(l==r && l==idx){
            tree[pos]=max(value,tree[pos]);
            return;
        }
        int mid=(l+r)>>1;
        if(idx>=l && idx<=mid) update(pos*2,l,mid,idx,value);
        if(idx>=(mid+1) && idx<=r) update(pos*2+1,mid+1,r,idx,value);
        tree[pos]=max(tree[pos*2],tree[pos*2+1]);
    }

    int query(int pos, int l, int r, int L, int R){
        if(l>=L && r<=R) return tree[pos];
        if(r<L || l>R || L>R) return 0;
        int mid=(l+r)>>1;
        int q1=query(pos*2,l,mid,L,R);
        int q2=query(pos*2+1,mid+1,r,L,R);
        return max(q1,q2);
    }
};

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    SegmentTree s;
    s.init();
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        int q=s.query(1,0,300000,max(0,x-k),min(300000,x+k));
        s.update(1,0,300000,x,q+1);
    }
    cout<<s.query(1,0,300000,0,300000)<<endl;
    return 0;
}

Measured memory_bytes: 8356
#include <cstdio>
#include <vector>
#include <algorithm>
#define N 100005

using namespace std;

int n, m;
int deg[N];
bool vis[N];
vector<pair<int,int> > e[N];

bool dfs(int ,int);

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++i){
		int u, v; scanf("%d%d", &u, &v);
		++deg[u]; ++deg[v];
		e[u].push_back(make_pair(v, i));
		e[v].push_back(make_pair(u, i));
	}
	for(int i = 1; i <= n; ++i)
		if(deg[i] & 1) return puts("No"), 0;
	int x = 0, y = 0, tot = 0;
	for(int i = 1; i <= n; ++i){
		if(deg[i] >= 6) return puts("Yes"), 0;
		if(deg[i] == 4){
			if(tot == 2) return puts("Yes"), 0;
			++tot; x ? y = i : x = i;
		}
	}
	if(tot < 2) return puts("No"), 0;
	dfs(x, y); dfs(x, y);
	puts(dfs(x, y) ? "No" : "Yes");
	return 0;
}

bool dfs(int u, int t){
	if(u == t) return true;
	int sz = e[u].size();
	for(int i = 0; i < sz; ++i){
		int v = e[u][i].first, id = e[u][i].second;
		if(vis[id]) continue; vis[id] = true;
		if(dfs(v, t)) return true;
	}
	return false;
}

Measured memory_bytes: 8576
#include<stdio.h>
int main(void)
{
	int s[6], smod[6];
	int i,min, add;
	for(i=0;i<5;i++){
		scanf("%d",&s[i]);
	}
	
	add = 0;
	min = 10;
	for(i=0;i<5;i++){
		smod[i] = s[i]%10;
		if(smod[i] == 0){continue;}
		
		if(smod[i]<min){min = smod[i];}
	}
		
	for(i=0;i<5;i++){
		s[i] = (s[i]/10)*10;
		if(smod[i] != 0){s[i] += 10;}
		add += s[i];
	}
	add = add+min-10;
	
	printf("%d",add);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#define ll long long
using namespace std;
const double PI=3.14159265358979323846;
int main(){
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double minu=60*h+m;
    double hspeed=1/12.0/60.0*2*PI;
    double mspeed=1/60.0*2*PI;
    double hangle=hspeed*minu;
    double mangle=mspeed*minu;

    double ans=pow(a*a+b*b-2*a*b*(cos(mangle-hangle)),0.5);
    cout<<fixed<<setprecision(15)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4264
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pq              priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void c_p_c()
{
	ios_base::sync_with_stdio(0); 
	cin.tie(0);
	cout.tie(0);
/*
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
*/
}

int32_t main()
{
	c_p_c();
	int n;
	cin>>n;
	int arr[n-1];
	for(int i=0;i<n-1;i++)
	{
		cin>>arr[i];
	}
	unordered_map<int,int>mp;
	for(int i=0;i<n-1;i++)
	{
		mp[arr[i]]++;
	}
	for(int i=1;i<=n;i++)
	{
		cout<<mp[i]<<endl;
	}
	
	return 0;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

void insertionSort(int A[], int N){
    for(int i=1; i<N; i++){
        int v = A[i];
        int j = i-1;
        while(j>=0 && A[j]>v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        rep(k,N){
            cout << A[k];
            if(k != N-1) cout << " ";
        }
        cout << endl;
    }
}

int main()
{
    int N; cin >> N;
    int A[N];
    rep(i,N){
        int Ai; cin >> Ai;
        A[i] = Ai;
    }
    rep(k,N){
        cout << A[k];
        if(k != N-1) cout << " ";
    }
    cout << endl;
    insertionSort(A, N);
}


Measured memory_bytes: 3088
s = gets.chomp
a,b = s[0..1], s[2..3]
a_ = 1 <= a.to_i && a.to_i <= 12
b_ = 1 <= b.to_i && b.to_i <= 12
if a_ and b_
  puts :AMBIGUOUS
elsif a_
  puts :MMYY
elsif b_
  puts :YYMM
else
  puts :NA
end


Measured memory_bytes: 1788
//
// Created by Kiran Chavhan on 25/07/2020.
//

#include<bits/stdc++.h>

#define int long long
#define MOD 1000000007
#define sort(a) sort(a.begin(),a.end())
#define endl '\n'

using namespace std;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x;
    cin>>x;
    if(x>=400 and x<=599){
        cout<<8;
    }
    else if(x>=600 and x<=799){
        cout<<7;
    }
    else if(x>=800 and x<=999){
        cout<<6;
    }
    else if(x>=1000 and x<=1199){
        cout<<5;
    }
    else if(x>=1200 and x<=1399){
        cout<<4;
    }else if(x>=1400 and x<=1599){
        cout<<3;
    }else if(x>=1600 and x<=1799){
        cout<<2;
    }
    else if(x>=1800 and x<=1999){
        cout<<1;
    }
}

Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    string s;
    cin>>s;
    string com="AIDUNYAN";
    sort(com.begin(),com.end());
    rep(i,s.length()){
        if(i+8>=s.length()+1)continue;
        string temp=s.substr(i,8);
        //cout<<temp<<endl;
        sort(temp.begin(),temp.end());
        if(temp==com){
            s.erase(s.begin()+i,s.begin()+i+8);
            s.insert(i,"AIZUNYAN");
            i+=7;
        }
    }
    cout<<s<<endl;
}

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

int main(){
  string s,a,b;
  bool flag=false;
  cin >> s;
  r(i,8){
    a=s.substr(0,i);
    b=s.substr(s.length()-7+i,7-i);
    if(a+b=="keyence"){
      cout << "YES"<<endl;
      flag=true;
      break;
    }
  }
  if(!flag)cout << "NO"<<endl;
}

Measured memory_bytes: 256
using System;
class Program{
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		long ans=0;
		for(int i=s[1]+1;i<=s[0];i++){
			ans+=(s[0]-i+1)/i*(i-s[1])+((s[0]-i+1)%i>s[1]?((s[0]-i+1)%i-s[1]):0)+i-s[1];
		}
		ans-=s[1]==0?s[0]:0;
		Console.WriteLine("{0}",ans);
	}
}

Measured memory_bytes: 13268
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define LL long long
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int calculate_digits_total(int x) {
	int digits_total = 0;
	while (x) {
		digits_total += x % 10;
		x /= 10;
	}

	return digits_total;
}

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

	int f_x = calculate_digits_total(N);
	string result = (N % f_x == 0) ? "Yes" : "No";
	cout << result << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <cctype>
#include <cmath>
#include <iomanip>
#define ARB ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);
using namespace std;
typedef long long ll;

int main()
{
    ARB
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    ll cnt=0;
    string sub7, sub6, sub5;
    while(cnt<s.length())
    {
        if(cnt+7<=s.length())
        {
            sub7=s.substr(cnt,7);
        }
        if(cnt+6<=s.length())
        {
            sub6=s.substr(cnt,6);
        }
        if(cnt+5<=s.length())
        {
            sub5=s.substr(cnt,5);
        }

        if(sub7=="remaerd")
        {
            cnt+=7;
        }
        else if(sub6=="resare")
        {
            cnt+=6;
        }
        else if(sub5=="maerd" || sub5=="esare")
        {
            cnt+=5;
        }
        else
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 512
n = int(input())
s_list = sorted([int(input()) for _ in range(n)])
m = 0
ans = 0
for s in s_list:
    ans += s
    if m == 0 and s % 10 != 0:
        m = s
if m == 0:
    ans = 0
elif ans % 10 == 0:
    ans -= m
print(ans)

Measured memory_bytes: 9120
from collections import deque
K = int(input())
G = [[] for i in range(K)]
for i in range(K):
    G[i].append(((i+1) % K, 1))
    G[i].append((10*i % K, 0))

visited = [0] * K
queue = deque([(1, 1)])

# 01BFS
while queue:
    now, cost = queue.popleft()
    if now == 0:
        print(cost)
        break

    visited[now] = 1
    for n, c in G[now]:
        if visited[n]:
            continue

        if c == 0:
            queue.appendleft((n, cost))
        else:
            queue.append((n, cost+1))


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

int f(int x)
{
    if (x % 2) {
        return (3 * x + 1);
    }
    return (x / 2);
}

int main( )
{
    int s;
    cin >> s;
    map<int, int> mp;
    mp[s] = 1;
    int i = 2, j;
    while ( 1 ) {
        j = f(s);
        if (mp.find(j) != mp.end()) {
            cout << i << '\n';
            return 0;
        }
        mp[j] = 1;
        s = j;
        i++;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;

class Main{

	int ans=0;
	int max;
	int ansNum=0;

	Main(){
		Scanner scan = new Scanner(System.in);	
		while(true){
			int up =scan.nextInt();
			int down = scan.nextInt();
			if(up==0&&down==0){
				break;
			}
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i=0;i<up+down;i++){
				list.add(scan.nextInt());	
			}
				
			Collections.sort(list);

			int p=0,max=0;
			for(int i :list){
				if(i-p>max){
					max=i-p;
					int a=i-p;
				//	System.out.println("p-i:"+p+"-"+i+"="+a);
				}
				p=i;
			}
			System.out.println(max);
			list.clear();
		}
	}

	public static void main(String[] args){
		Main a = new Main();
	}


}

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

int main()
{
    string s;
    cin >> s;
    int a = 0;
    if(s == "SAT") a = 1;
    else if(s=="SUN") a = 7;
    else if(s=="MON") a = 6;
    else if(s=="TUE") a = 5;
    else if(s=="WED") a = 4;
    else if(s=="THU") a = 3;
    else if(s=="FRI") a = 2;
    cout << a << endl;

    return 0;
}

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

//vector…可変長、データの大きさに合わせてサイズを変える
//list…双方向リスト、要素を挿入、削除の多いとき
//forward_list
//array…固定長配列
//set…集合
//multiset
//bitset…2進数、固定長ビット列
//map…連想配列、キーと値を関連付ける
//multimap
//deque
//stack…FILO
//queue…FIFO
//priority_queue…格納された最大値から順に取り出す
//pair…二つの値を一組
//tuple…複数の値を一組

template<typename T>
void remove(std::vector<T>& vector, char index) {
    vector.erase(vector.begin() + index);
}

template<class T>
T ma(std::vector<T> &v) {
    T maxi = 0;
    for(auto &i:v) maxi = max(maxi, i);
    return maxi;
}

template<class T>
T mi(std::vector<T> &v) {
    T mini = 0;
    for(auto &i:v) mini = min(mini, i);
    return mini;
}

template <class T>
T pow(T x, T y, T n = numeric_limits<T>::max()) {
    if(y == 0) return 1;
    if(y % 2 == 0) return pow((x * x) % n, y / 2);
    return (x * pow(x, y - 1)) % n;
}

#define rep(i, n, m) for (int i = n; i <= m; i++)
#define Rep(i, n, m) for (int i = m; i >= 1; i--)

typedef long long ll;
typedef unsigned long long ull;

ull ans = 0;
/*
int gcd(int x, int y) {
    if (x < y) swap(x, y);
    return !y ? x : gcd(x % y, y);
}
*/
int main() {
    int a, p;
    cin >> a >> p;
    ans = (a * 3 + p) / 2;
    cout << ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
int main(){
	int x,a;
	cin>>x>>a;
	if (x<a) cout<<"0";
	else cout<<"10";
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
C = [0,0,0]
Ans = 1
MOD = 1000000007
for a in A:
    ask = C.count(a)
    if ask==0:
        Ans=0
        break
    ind = C.index(a)
    C[ind] += 1
    Ans = (Ans*ask)%MOD
print(Ans)


Measured memory_bytes: 20644
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int N;

int main()
{
  cin >> N;

  double res = 0.0;
  REP(i,0,N) {
    double x;
    string u;
    cin >> x >> u;
    if (u == "JPY") res += x;
    else if (u == "BTC") res += x * 380000;
    // else
  }

  cout << setprecision(20) << res << endl;

  return 0;
}


Measured memory_bytes: 256
import math
a,b,x=map(int,input().split())
if a*a*b<=2*x:
    c=(b-x/(a**2))*2/a
    ans=math.degrees(math.atan(c))
else:
    c=a*b*b/(2*x)
    ans=math.degrees(math.atan(c))
print(ans)


Measured memory_bytes: 3064
//  Twitter@KonoLv1 2020年春からエンジニア見習いデビュー！
 
//  標準入出力を扱うヘッダーファイルの読み込み
#include <stdio.h>
//  "atoi" "atof"などのキャスト、"rand" 疑似乱数を発生させるヘッダーファイルの読み込み
#include <stdlib.h>
//  "strcpy" "strcat"などの文字列操作や"strlen"文字列長さ取得などを行うヘッダーファイルの読み込み
#include <string.h>
//  "sqrtl" "fmax"などの数値操作を行うヘッダーファイルの読み込み
#include <math.h>
 
int main(void){
 
    int x,y,z;
    int i,j,k;
    int count = 0;
    int flg = 0;
    char s[200000] = {};
    int box[200000] = {};
    int sum = 0;
 
    //scanf("%s %d",&s,&box[0]);
    scanf("%d %d",&x,&y);
    // HP x
    // DM y
    for (i = 0; i < y; i++){
        scanf("%d",&sum);
        count = count + sum;
    }
    if (count >= x){
        printf("Yes");
    }else{
        printf("No");
    }
    

 
}

Measured memory_bytes: 128
#include <iostream>


using namespace std; 
int main()

{
    int person[4][3][10]; //棟　階　部屋
    int n = 0;
    int b,f,r,v;
    for(int i = 0; i < 4; i++){  
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 10; k++){
                person[i][j][k] = 0;
            }
        }
    }
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> b >> f >> r >> v;
        person[b - 1][f - 1][r - 1] += v;
    }
    for(int i = 0; i < 4; i++){
        
        for(int j = 0; j < 3; j++){
            
            for(int k = 0; k < 10; k++){
                cout << " " << person[i][j][k];
            }
            cout << endl;
        }
        if(i < 3){
            cout << "####################" << endl;
        }
    }
	return 0;

}



Measured memory_bytes: 3080
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        boolean isOdd = true;
        boolean wrong = false;
        for (char c : s.toCharArray()) {
            if (isOdd) {
                if (c == 'R' || c == 'U' || c == 'D'){

                } else {
                    wrong = true;
                    break;
                }
            } else {
                if (c == 'L' || c == 'U' || c == 'D'){
                } else {
                    wrong = true;
                    break;
                }
            }
            isOdd = !isOdd;
        }
        if (wrong) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <cstdlib>

using namespace std;

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

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

    int ans = 1000;
    int diff = 1000;
    bool flg = true;
    for (int i = -1; i <= 101; i++)
    {
        int tmp = abs(x - i);

        if (tmp < diff)
        {
            for (int j = 0; j < n; j++)
            {
                if (p[j] == i)
                {
                    flg = false;
                }
            }
            if (flg)
            {
                ans = i;
                diff = tmp;
            }
            flg = true;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
# -*- coding: utf-8 -*-

def maxHeapify(A, i):
    l = 2*i
    r = 2*i+1
    if l <= n and A[l] > A[i]:
        largest = l
    else:
        largest = i
    if r <= n and A[r] > A[largest]:
        largest = r
    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        maxHeapify(A, largest)

def buildMaxHeap(A):
    for i in range(n/2, 0, -1):
        maxHeapify(A, i)

n = int(raw_input())
l = map(int, raw_input().split())
A = [0]
for i in range(n):
    A.append(l[i])
buildMaxHeap(A)
print " "+" ".join(map(str, A[1:]))

Measured memory_bytes: 69424
a,b,i,c,k[3100];
main()
{
  for(scanf("%d%d",&a,&b);;puts(""))
    {
      c=0;
      for(i=a;i<=b;i++)
	if(i%400==0||(i%100!=0&&i%4==0))
	  k[c++]=i;
      if(!c)
	puts("NA");
      else
	  for(i=0;i<c;)
	    printf("%d\n",k[i++]);	
      scanf("%d%d",&a,&b);
      if(!a)exit(0);
    }
}

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

int main(void){
    int n,ans,i;
    string s;
    ans = 0;

    cin >> n >> s;

    for(i=0; i<=n-3; i++){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n,k,i;
	for(;cin>>n>>k,n;){
		vector<int>vec(n);
		for(i=0;i<n;i++)vec[i]=i+1;
		i=(k-1)%vec.size();
		vec.erase(vec.begin()+i);
		for(;vec.size()>1;vec.erase(vec.begin()+i))if(i+=(k-1)%vec.size(),i>=vec.size())i-=vec.size();
		cout<<vec[0]<<endl;
	}
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1000000007;

long long mod(long long a) {
	a %= MOD;
	return a >= 0 ? a : a+MOD;
}

long long pow_mod(long long a, long long n) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = (res * a) % MOD;
		n >>= 1;
		a = (a * a) % MOD;
	}
	return res;
}

long long inverse_mod(long long a) {
	long long b = MOD, x = 1, u = 0;
	while (b != 0) {
		long long r = a % b, q = a / b;
		a = b; b = r;
		int nu = x - q*u;
		x = u; u = nu;
	}
	x %= MOD;
	if (x < 0) x += MOD;
	return x;
}

vector<pair<long long, int>> prime_factorization(long long n) {
	vector<pair<long long, int>> v;
	for (long long i = 2; i * i <= n; ++i) {
		int e = 0;
		while (n % i == 0) {
			++e;
			n /= i;
		}
		if (e != 0) v.emplace_back(i, e);
	}
	if (n != 1) v.emplace_back(n, 1);
	return v;
}

vector<pair<long long, int>> lcm(vector<pair<long long, int>> a, vector<pair<long long, int>> b) {
	vector<pair<long long, int>> v;
	int i = 0, j = 0;
	while (i < a.size() && j < b.size()) {
		if (a[i].first == b[j].first) {
			v.emplace_back(a[i].first, max(a[i].second, b[j].second));
			i++; j++;
		}
		else if (a[i].first < b[j].first) {
			v.push_back(a[i]);
			i++;
		}
		else {
			v.push_back(b[j]);
			j++;
		}
	}
	for (; i < a.size(); ++i) v.push_back(a[i]);
	for (; j < b.size(); ++j) v.push_back(b[j]);
	return v;
}

int main() {
	long long n;
	cin >> n;
	vector<int> A(n);
	for (int i = 0; i < n; i++) cin >> A[i];
	vector<pair<long long, int>> lp;
	for (int i = 0; i < n; i++) {
		auto v = prime_factorization(A[i]);
		lp = lcm(lp, v);
	}
	long long l = 1;
	for (auto x : lp) l = mod(l * pow_mod(x.first, x.second));
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans = mod(ans + l * inverse_mod(A[i]) % MOD);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4152
#include <iostream>

using namespace std;

int main()
{
	string s;

	cin >> s;

	int c = 0;
	int max = 0;
	bool f = false;

	for (auto i : s) {
		if (i == 'R') f = true;
		else {
			f = false; 
			c = 0;
		}
		if (f) {
			if (i == 'R') c++;
			if (max < c) max = c;
		}
	}


	cout << max << endl;
}

Measured memory_bytes: 3600
// D - Decayed Bridges
// Graph Theory, Union-Find
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef pair<int, int> pr;
typedef priority_queue<int> p_int_max;
typedef priority_queue<int, vector<int>, greater<int>> p_int_min;

int p[100005], r[100005], c[100005]; // parent, rank, count

void initset(int n)
{
	rep(i, n)
	{
		p[i] = i;
		r[i] = 0;
		c[i] = 1;
	}
}

// Return rep index
int findset(int n)
{
	if (p[n] == n)
		return n;
	p[n] = findset(p[n]);
	return p[n];
}

bool sameset(int n, int m)
{
	return findset(n) == findset(m);
}

int countset(int n)
{
	return c[findset(n)];
}

void mergeset(int n, int m)
{
	n = findset(n);
	m = findset(m);
	if (r[n] > r[m])
	{
		p[m] = n;
		c[n] += c[m];
	}

	else if (r[m] > r[n])
	{
		p[n] = m;
		c[m] += c[n];
	}
	else
	{
		p[m] = n;
		c[n] += c[m];
		r[n]++;
	}
}

int n, m, ai, bi;
ll ans[100005]; // inconvenience
pr b[100005];		// bridge pairs
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m;
	initset(n);
	rep(i, m)
	{
		cin >> ai >> bi;
		b[i] = pr(ai, bi);
	}
	// Reverse decay - merge op instead of expensive nonexistent "break" op
	reverse(b, b + m);
	rep(i, m)
	{
		ai = b[i].first, bi = b[i].second;
		// ans[0] has to be 0 - all bridges decayed
		ans[i + 1] += ans[i]; // Add previous routes
		if (!sameset(ai, bi))
		{
			//cout << "ai " << findset(ai) << " bi " << findset(bi) << "\n";
			//cout << "count " << countset(ai) << " " << countset(bi) << "\n";
			ans[i + 1] += countset(ai) * countset(bi);
			mergeset(ai, bi);
		}
		// cout << "ans[] ";
		// rep(i, m + 1) cout << ans[i] << " ";
		// cout << "\n";
		// cout << "c[] ";
		// rep(i, n) cout << c[i] << " ";
		// cout << "\n\n";
	}
	reverse(ans, ans + m + 1);
	rep(i, m)
	{
		cout << ans[0] - ans[i + 1] << "\n";
	}
}


Measured memory_bytes: 4096
module Main where
import qualified Control.Monad as C
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A

int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = map int . tail . words
printer = unlines . (:[]) . show

solver as = foldl1 gcd as



Measured memory_bytes: 2428
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    int N = S.size();
    int val = 0;
    rep(i,N) {
        val += S[i] - '0';
        val %= 9;
    }

    cout << (val ? "No" : "Yes") << ln;
}

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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N+1), B(N);
    for (int i = 0; i < N + 1; ++i) cin >> A[i];
    for (int i = 0; i < N; ++i) cin >> B[i];

    long long cnt = 0;
    for (int i = 0; i < N; ++i) {
        if (A[i] < B[i]) {
            cnt += A[i];
            long long tmp = B[i]-A[i];
            if (tmp > A[i + 1]) {
                cnt += A[i+1];
                A[i+1] = 0;
            } else {
                A[i + 1] -= tmp;
                cnt += tmp;
            }
        } else {
            cnt += B[i];
        }
    }
    cout << cnt << endl;
}

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

int main()
{
	string X, Y, Z;
	cin >> X >> Y >> Z;
	int A, B;
	A = X.size();
	B = Y.size();
	char r = X[A-1];
	char s = Y[0];
	char t = Y[B-1];
	char u = Z[0];


	if (r == s && t == u)
	{
		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<int(n);++i)
#define all(a) a.begin(),a.end()
typedef long long ll;

using P = pair<ll,ll>;
#define v first
#define w second

// v/w 高い順
bool comp1(P a, P b){
    return a.v*b.w > b.v*a.w;
}

// v高い順（vが同じならw軽い方優先）
bool comp(P a, P b){
    return a.v == b.v ? a.w < b.w : a.v > b.v;
}

int main(void){
    ll N,W;
    cin>>N>>W;
    vector<P> a(N);
    rep(i,N){
        ll v,w;
        cin>>v>>w;
        a[i] = {v,w};
    }
    // sort(all(a),comp1);
    vector<P> dp = {{0,0}};

    rep(i,N){
        vector<P> tmp;
        for(auto& s : dp){
            tmp.push_back(s);
            tmp.push_back({s.v + a[i].v, s.w + a[i].w});
        }

        sort(all(tmp),comp);
        dp.clear();
        ll w_border = W+1;
        for(auto& s : tmp){
            if( w_border > s.w){
                w_border = s.w;
                dp.push_back(s);
            }
        }
        assert(dp.size() <= N*N*2);
    }
    cout<<dp[0].v<<endl;
    return 0;
}



Measured memory_bytes: 3176
import sys
input = sys.stdin.readline
N, M, Q = map(int, input().split())

sum_table = [[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
    l, r = map(int, input().split())
    sum_table[l][r] += 1

for i in range(1, N+1):
    for j in range(1, N+1):
        sum_table[i][j] += sum_table[i-1][j] + sum_table[i][j-1] - sum_table[i-1][j-1]

for _ in range(Q):
    p, q = map(int, input().split())
    print(sum_table[q][q] - sum_table[q][p-1] - sum_table[p-1][q] + sum_table[p-1][p-1])




Measured memory_bytes: 54696
n = int(input())
a = [int(i) for i in input().split()]
ans = int(1)
flag = True

for i in a:
    if i == 0:
        print(0)
        flag = False

if flag:
    for i in range(n):
        ans = ans * a[i]
        if ans > int(1000000000000000000):
            flag  = False
            break

    if flag:
        print(ans)
    else:
        print(-1)




Measured memory_bytes: 21652
#include<iostream>
#include<string>
#include<vector>
using namespace std;
string rollstr(string _T) {
	char tmp_c = _T[_T.length() - 1];
	for (int i = _T.length()-1; i > 0; i--) {
		_T[i] = _T[i-1];
	}
	_T[0] = tmp_c;
	return _T;
}
int main()
{
	string S, T;
	cin >> S >> T;
	bool flag = false;
	for (int i = 0; i <= S.length(); i++) {
		if (S == T) {
			flag = true;
			break;
		}
		T=rollstr(T);
	}
	if (flag)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
typedef  int long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    if(a+b>=c){
        cout<<b+c<<endl;return 0;
    }else {
        
        cout<<b+b+a+1<<endl;
        
    }
    
    
    
    
return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int N,M,A[1001],B[1001],x,sum=0,i,j;
	scanf("%d%d",&N,&M);
	for(i=0;i<M;i++){
		scanf("%d%d",&A[i],&B[i]);
	}
	for(i=0;i<M;i++){
		for(j=i+1;j<M;j++){
			if(A[i]<A[j]){
				x=A[i];
				A[i]=A[j];
				A[j]=x;
			}
		}
	}
	for(i=0;i<M-1;i++){
		if(A[i]<N){
			sum+=N-A[i];
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 2768
#include <stdio.h>

int main() {
	char a;
	scanf("%c\n", &a);
	if (a == 'A')printf("T\n");
	else if (a == 'T')printf("A\n");
	else if (a == 'C')printf("G\n");
	else if (a == 'G')printf("C\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
#define debug(x) cerr << #x << ":" << x << endl;

int main()
{
  int n;cin>>n;
  vector<int> a(n+1);
  for(int i=0;i<n;++i) cin>>a[i+1];

  // 1-indexedにする
  vector<int> memo(n+1,0);
  for(int i=n;i>=1;--i){

    int sm = 0;
    for(int j=i;j<=n;j+=i){
      sm ^= memo[j];
    }
    if (a[i] != sm) memo[i] ^= 1;
  }

  /* 出力*/
  vector<int> ans;
  for(int i=1;i<=n;++i){
    if (memo[i]) ans.push_back(i);
  }

  cout<<ans.size()<<endl;
  for(auto ai: ans){
    cout<<ai<<endl;
  }
  
  return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll MOD = ll(1e9+7);


int main(){
    ll n, ans = 1, d = 0;
    cin >> n;
    vector<ll> x(n);
    for(int i=0;i<n;i++) cin >> x[i];
    for(ll i=0;i<n;i++){
        ans *= i-d+1;
        ans %= MOD;
        d = max(d, (i*2+1-x[i]+1)/2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int h,m,s,S;

	scanf("%d", &S);

	h = S/3600;
	m = (S%3600)/60;
	s = S%3600%60;

	printf("%d:%d:%d\n", h,m,s);

	return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<algorithm>
#include<vector>
#include <string>
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i] >> y[i];
typedef long long int ll;
using namespace std;
int eval(string s,int&pos){
	if(s[pos]=='0'){
		++pos; return 0;
	}
	if(s[pos]=='1'){
		++pos; return 1;
	}
	if(s[pos]=='2'){
		++pos; return 2;
	}
	if(s[pos]=='-'){
		++pos; return 2- eval(s,pos);
	}
	if(s[pos]=='('){
		++pos;
		int a=eval(s,pos);
		char c =s[pos++];
		int b= eval(s,pos);
		pos++;
		if(c =='*'){
			return min(a,b);
		}
		if(c =='+'){
			return max(a,b);
		}
	}
}

int solve(const string&str){
	int cnt=0;
	for(int p=0;p<=2;p++){
		for(int q=0;q<=2;q++){
			for(int r=0;r<=2;r++){
				string s=str;
				for(int i=0;i<s.size();i++){
					if(s[i]=='P'){
						s[i]=p+'0';
					}
					if(s[i]=='Q'){
						s[i]=q+'0';
					}
					if(s[i]=='R'){
						s[i]=r+'0';
					}
				}
				int t=0;
				if(eval(s,t)==2){
					cnt++;
				}
			}
		}
	}
	return cnt;
}
int main(){
 	string str;
 	while(1){
 		cin >>str;
 		if(str==".")break;
 		cout << solve(str) << endl;
 	}
}


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



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

    int x;
    cin >> x;
    for (int i = -1000; i <= 1000; i++){
      for (int j = -1000; j <= 1000; j++){
        if (pow(i, 5) - pow(j, 5) == x){
          cout << i << " " << j << endl;
          return 0;
        }
      }
    }
}

Measured memory_bytes: 4044
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
double dp[3030][3030];
double p[3030];

int main(){
    INIT;
    cin >> n;
    dp[0][0] = 1.0;
    for(int i = 1;i <= n;i++){
        cin >> p[i];
        for(int j = 0;j <= i;j++){
            dp[i][j] += dp[i - 1][j]*(1.0 - p[i]);
            if(j)dp[i][j] += dp[i - 1][j - 1]*p[i];
        }
    }
    double ans = 0;
    for(int i = n/2 + 1;i <= n;i++){
        ans += dp[n][i];
    }
    cout << fixed << setprecision(13) << ans << endl;
}

Measured memory_bytes: 70272