akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
long long int dp[100001][100]={};
bool tf[100001][100]={};
long int dpcalc(long int v,int i,long int a[][2],long int n)
{
    if(v<=0)
    return 0;
    if(i==-1)
     return 100000000001;
    if(tf[v][i])
    return dp[v][i];
    tf[v][i]=1;
    dp[v][i]=std::min(dpcalc(v,i-1,a,n),dpcalc(v-a[i][1],i-1,a,n)+a[i][0]);
    return dp[v][i];
   }
 

long int knapsack(long int a[][2],long int n,long int w)
{for(long int v=100001;v>=0;v--)
 {long long int ans=dpcalc(v,n-1,a,n);
  if(ans<=w)
    return v;
   }
 return 0;
  
}


  
int main()
{long int n,w;
 std::cin>>n>>w;
 long int a[n][2];
 for(int i=0;i<n;i++)
 std::cin>>a[i][0]>>a[i][1];
 std::cout<<knapsack(a,n,w);
 return 0;

}

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

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

    set<int> s;
    rep(i, n) {
        int a;
        cin >> a;
        if (s.find(a) != s.end())
            s.erase(a);
        else
            s.insert(a);
    }

    cout << s.size() << endl;
    return 0;
}


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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

ll N, K;
vector<ll> A;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

  cin >> N >> K;
  mint ans;
  for (ll i = K; i <= N+1; ++i) {
    //ll l = (i-1)*i/2;
    //ll r = (N+N-i+1)*i/2;
    ans += (N-i+1)*i + 1;
  }
  cout << ans<< endl;
  return 0;
}

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

#define PI 3.14159265359

int main() {
  string S, T;
  cin >> S >> T;
  bool flag = false;
  for (int i = 0; i < S.size(); i++){
    if (S[i] != T[i]){
      flag = true;
    }
  }
  if (flag){
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3628
z,*s=gets.split(/[
T]/,-1).map &:size;Y=1<<l=s.reduce(0,:+);X=Y<<z;s.each_slice(2){|t,u|Y=Y>>t|Y<<t;u&&X=X>>u|X<<u};eval"puts X>>l+%d&Y>>l+%d&1>0?:Yes: :No"%gets.split

Measured memory_bytes: 7420
#include<cstdio>

void InitializeIntegerMatrix(int nmbr_of_rows, int nmbr_of_columns, int m[][100]){
	for (int row = 0; row < nmbr_of_rows; ++row) {
		for (int column = 0; column < nmbr_of_columns; ++column)
			m[row][column] = 0;
	}
}

void ListToMatrix(int number_of_vertices, int adjmtr[][100]){
	int vertex_from, vertex_to, degree_out;	
	for (int vertex_i = 0; vertex_i < number_of_vertices; ++vertex_i) {
		scanf("%d %d", &vertex_from, &degree_out);
		vertex_from--; //0?????????????????????
		for (int vertex_out_i = 0; vertex_out_i < degree_out; ++vertex_out_i) {
			scanf("%d", &vertex_to);
			vertex_to--; //0?????????????????????
			adjmtr[vertex_from][vertex_to] = 1;
		}
	}
}

void PrintIntegerMatrix(int nmbr_of_rows, int nmbr_of_columns, int mtr[][100]){
	for (int row = 0; row < nmbr_of_rows; ++row) {
		for (int column = 0; column < nmbr_of_rows; ++column) {
			if(column > 0)
				printf(" ");
			printf("%d", mtr[row][column]);
		}
		printf("\n");
	}
}

int main(void){
	int number_of_vertices;
	scanf("%d", &number_of_vertices);
	int n = number_of_vertices;
	int adjmtr[100][100];
	InitializeIntegerMatrix(n, n, adjmtr);
	ListToMatrix(n, adjmtr);
	PrintIntegerMatrix(n, n, adjmtr);
	return 0;
}

Measured memory_bytes: 2720
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
using namespace std;

int main() {
    int n,cnt=0;
    cin >> n;
    int a[100] = {};
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = n - 1;j > i; j--) {
            if (a[j] < a[j - 1]) {
                swap(a[j], a[j - 1]);
                cnt++;
            }
        }
        if (i) cout << " ";
        cout << a[i];
    }
    cout << endl;
    cout << cnt << endl;
}



Measured memory_bytes: 3100
s = input()

ans = True
for i in range(len(s)):
    if (i+1) % 2 == 0:
        if not(s[i] in ["L", "U", "D"]):
            ans = False

    else:
        if not(s[i] in ["R", "U", "D"]):
            ans = False

if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
#include <cassert>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
const int p2=1<<19;
int N,Q;
string s;
int segm[p2*2],sega[p2*2],inf=1e8;
set<int> st;
void add(int a,int b,int l,int r,int k,int x){
	if(b<=l||r<=a) return;
	if(a<=l&&r<=b){
		sega[k]+=x;
		return;
	}
	add(a,b,l,(l+r)/2,k*2+1,x);
	add(a,b,(l+r)/2,r,k*2+2,x);
	segm[k]=min(segm[k*2+1]+sega[k*2+1],segm[k*2+2]+sega[k*2+2]);
}
void change(int x){
	if(s[x]=='('){
		s[x]=')';
		st.insert(x);
		add(x,p2,0,p2,0,-2);
	}else{
		s[x]='(';
		st.erase(x);
		add(x,p2,0,p2,0,2);
	}
}
int getmin(int a,int b,int l,int r,int k){
	if(b<=l||r<=a) return inf;
	if(a<=l&&r<=b) return segm[k]+sega[k];
	return min(getmin(a,b,l,(l+r)/2,k*2+1),getmin(a,b,(l+r)/2,r,2*k+2))+sega[k];
}
int main(){
	cin>>N>>Q;
	cin>>s;
	rep(i,N) if(s[i]==')') st.insert(i);
	rep(i,p2) segm[p2-1+i]=inf;
	rep(i,N) segm[p2-1+i]=segm[p2-2+i]+(s[i]=='('?1:-1);
	for(int i=p2-2;i>=0;i--){
		segm[i]=min(segm[i*2+1],segm[i*2+2]);
	}
	rep(i,Q){
		int q;
		cin>>q;
		q--;
		if(s[q]=='('){
			change(q);
			int a=*st.begin();
			cout<<a+1<<endl;
			change(a);
		}else{
			change(q);
			int ub=q,lb=-1;
			while(ub-lb>1){
				int m=(ub+lb)/2;
				if(getmin(m,q+1,0,p2,0)>=2) ub=m;
				else lb=m;
			}
			cout<<ub+1<<endl;
			change(ub);
		}
	}
}

Measured memory_bytes: 15872
from bisect import (
    bisect_left,
    bisect_right,
)

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

pl = [i + v for i, v in enumerate(a)]

spl = sorted(pl)

c = 0

for j, v in enumerate(a):
    w = j - v
    left = bisect_left(spl, w)
    right = bisect_right(spl, w)
    tmp = right - left
    c += tmp

print(c)


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

int main() {
  string s;
  cin >> s;
  if(s=="Sunny") cout << "Cloudy" << endl;
  else if(s=="Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
  return 0;
}


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

# スペース区切りの整数の入力
a, b, c, k = map(int, input().split())

if (k < a):
    ans = k
elif (k < a + b):
    ans = a
else:
    ans = a + 0 - (k - a - b)

# 出力
print(str(ans))

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
        string s;
        cin >> s;
        
        if (s.find('7') != string::npos) {
                cout << "Yes" << endl;
        } else {
                cout << "No" << endl;
        }

        return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  int cnt=0;
  for(int i=1; i<n; i++){
    for(int j=1; j<n; j++){
      if(n-i*j < 0)
        break;
      
      if(n-i*j > 0)
        cnt++;
    }
  }
  
  cout << cnt << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 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; }

int main()
{
    string s;
    cin >> s;
    bool a = 0;
    string t[12] = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"};
    for (int i = 0; i < 12; i++)
    {
        if (s.substr(0, 2) == t[i])
            a = 1;
    }
    bool b = 0;
    for (int i = 0; i < 12; i++)
    {
        if (s.substr(2, 2) == t[i])
            b = 1;
    }
    if (a == 1 && b == 1)
        cout << "AMBIGUOUS" << endl;
    else if (a == 1 && b == 0)
        cout << "MMYY" << endl;
    else if (a == 0 && b == 1)
        cout << "YYMM" << endl;
    else
        cout << "NA" << endl;
}

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

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


Measured memory_bytes: 256
#include<iostream>
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX =  100000;
int i, j, v, num, color[MAX];
vector<int> list[MAX];
 
void dfs(int r, int c){
 stack<int> S;
 S.push(r);
 color[r] = c;
 while( !S.empty() ){
   int u = S.top(); S.pop();
   for(i=0; i<list[u].size(); i++){
     v = list[u][i];
     if(color[v] == -1){
       color[v] = c;
       S.push(v);
     }
   }
 }
}
  
void assigncolor(){
 int id = 1;
 for(i=0; i<num; i++){
   color[i] = -1;
 }
 for(j=0; j<num; j++){
   if(color[j] == -1)
     dfs(j, id++);
 }
}
  
int main(){
 int a, b, trial, start, goal, kaisuu;
 cin >> num >>kaisuu;
  
 for(i=0; i<kaisuu; i++){
   cin >> a >> b;
   list[a].push_back(b);
   list[b].push_back(a);
 }
 
 assigncolor();
 
 cin >> trial;
 
 for(i=1; i<=trial; i++){
   cin >> start >> goal;
   if(color[start] == color[goal]){  
     cout << "yes" << endl;
   } else{
     cout << "no" << endl;
   }
 }
  
 return 0;
}

Measured memory_bytes: 8992
#include<bits/stdc++.h>
#define ll long long int
#define l(i,a,b) for(ll i=a;i<b;i++)
using namespace std;
int main(){
	ll k;
	cin>>k;
	ll n = 3*k;
	ll a[n];
	l(i,0,n) cin>>a[i];
	sort(a,a+n);
	ll i=n-2;
	ll num = 0,sum = 0;
	while(num<k){
		sum+=a[i];
		i-=2;
		num++;
	}	
	cout<<sum<<"\n";
}

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

using namespace std;

#define MAX 10000
typedef pair<int,int> pii;
int a,b,c;

bool input(){
  cin >> a >> b >> c;
  return a;
}

int main(){
  while(input()){
    bool found = false;
    vector<pii> pr,qs;
    for(int p = 1 ; p <= a ; p++){
      int r = a/p;
      if(a % p != 0 || p < r) continue;
      pr.push_back(pii(p,r));
    }
    int cc = c < 0 ? -c : c;
    for(int q = -cc ; q <= cc ; q++){
      if(q == 0) continue;
      int s = 0;
      if(c < 0){
        if(q < 0 && abs(c) % abs(q) == 0){
          if(abs(c) % abs(q) == 0){
            s = abs(c)/abs(q);
          }
        }else{
          if(abs(c) % q == 0){
            s = abs(c)/q;
            s = -s;
          }
        }
      }else{
        if(q < 0){
          if(c % abs(q) == 0){
            s = c/abs(q);
            s = -s;
          }
        }else{
          if(c % q == 0){
            s = c/q;
          }
        }
      }
      if(s == 0) continue;
      qs.push_back(pii(q,s));
    }
    if(c == 0){
      for(int i = -MAX ; i <= MAX ; i++){
        qs.push_back(pii(0,i));
        qs.push_back(pii(i,0));
      }
    }
    for(int i = 0 ; i < (int)pr.size() ; i++){
      for(int j = 0 ; j < (int)qs.size() ; j++){
        int p = pr[i].first,r = pr[i].second;
        int q = qs[j].first,s = qs[j].second;
        if(p == r && q < s) continue;
        if(p*s+q*r == b){
          cout << p << " " << q << " " << r << " " << s << endl;
          found = true;
          goto END;
        }
      }
    }
    if(!found){
      cout << "Impossible" << endl;
    }
  END:;
  }
  return 0;
}

Measured memory_bytes: 1844
import java.util.Scanner;
 
public class Main {
    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int[] numbers = new int[n];
        for (int i = 0; i < n; i++) {
            numbers[i] = scanner.nextInt();
        }
 
        int q = scanner.nextInt();
        int[] patterns = new int[q];
        for (int i = 0; i < q; i++) {
            patterns[i] = scanner.nextInt();
        }
 
        int count = 0;
        for (int i = 0; i < q; i++) {
            for (int j = 0; j < n; j++) {
                if (patterns[i] == numbers[j]) {
                    ++count;
                    break;
                }
            }
        }
 
        System.out.println(count);
    }
}

Measured memory_bytes: 31088
import sys

input = sys.stdin.readline

s = list(input().rstrip())

lis = ['A', 'C', 'G', 'T']

for i in range(len(s)):
    for j in range(4):
        if (s[i] == lis[j]):
            s[i] = 'AYATASO'
            break

ct = 0
ct_lis = []

for i, x in enumerate(s):
    if (x == 'AYATASO'):
        ct += 1
    else:
        ct_lis.append(ct)
        ct = 0

ct_lis.append(ct)

print(max(ct_lis))


Measured memory_bytes: 3064
D = int(input())
# with open("sample1.in") as f:

last = [0 for i in range(26)]
s = [[0 for j in range(26)] for i in range(D)]
c = list(map(int, input().split(" ")))
result = []
total = 0
# opened = []  #開催したやつを保存
for i in range(D):
    a = list(map(int, input().split(" ")))
    for j, k in enumerate(a):
        #print(i, j, k)
        s[i][j] = int(k)
        # スコア計算
    score_max = 0
    score_index = 0
    for j in range(26):

        if j == 0:
            score_max = s[i][j]  # - (i - last[j]) * c[j]
            for k in range(26):
                if j != k:
                    score_max -= (i + 1 - last[k]) * c[k]
            score_index = 0
        else:
            score = s[i][j]
            for k in range(26):
                if j != k:
                    score -= (i + 1 - last[k]) * c[k]

            if score_max < score:
                score_max = score
                score_index = j
            #print(i, j, score)
    result.append(score_index)
    #print(score_index, score)
    last[score_index] = i + 1
    total += score
    # print(a.index(max(a)))
# print(total)
for i in range(D):
    # print(s.index(max(s[i])))
    print(result[i]+1)


Measured memory_bytes: 9520
// Charan Sriramula

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

const ll lg=22;
const ll N=1e6+5;
const ll INF=1e18+5;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;

#define is(n) scanf("%d",&n)
#define io(n) printf("%d\n",n)
#define ls(n) scanf("%lld",&n)
#define lo(n) printf("%lld\n",n)

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
template<typename T> T power(T x,T y){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%mod;y>>=1LL;x=(x*x)%mod;}return ans%mod;}

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll inv(ll a){ return power(a, mod - 2); }

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

int main()
{
  ll n;
  string s;
  cin>>s;
  n=s.length();
  ll cnt=0;
  for(ll i=0;i<n/2;i++)
  {
    ll j=n-i-1;
    if(s[i]==s[j]){continue;}
    cnt++;
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
import math

def solve():
    a,b,x = map(int, input().split())
    if a*b/2*a<=x:
        return math.degrees(math.asin((b-x/a**2)*2 / (a**2 + ((b-x/a**2)*2)**2)**0.5))
    else:
        return math.degrees(math.asin(b / ((x/b/a*2)**2 + b**2)**0.5))

if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 3060
#include <stdio.h>
#define I 100000
int partition(int,int);
int n,A[I];
int main(){
  int k,q,i;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  q=partition(0,n-1);
  
  for(k=0;k<q;k++){
    printf("%d ",A[k]);
  }
  printf("[%d] ",A[q]);
  for(k=q+1;k<n-1;k++){
    printf("%d ",A[k]);
  }
  printf("%d\n",A[n-1]);
  return 0;
}

int partition(int p,int r) {
  int x,i,j,B,C,k;
  x=A[r];
  i =p-1;

  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      B=A[i];
      A[i]=A[j];
      A[j]=B;
    }
  }
 
  C=A[i+1];
  A[i+1]=A[r];
  A[r]=C;

  return i+1;
}
 

Measured memory_bytes: 988
package main

import (
	"fmt"
)

func main() {
	var arg int
	_, _ = fmt.Scan(&arg)

	ans := 0

	if arg%2 == 0 {
		ans = (arg / 2) * (arg / 2)
	} else {
		ans = (arg / 2) * ((arg / 2) + 1)
	}
	fmt.Printf("%d\n", ans)

}


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

using namespace std;

int main() {
  int N, M;
  
  cin >> N >> M;
  
  priority_queue<long long> Q;
  
  for (int i = 0; i < N; i++) {
    long long in;
    
    cin >> in;
    
    Q.push(in);
  }
  
  for (int i = 0; i < M; i++) {
    long long tmp = Q.top();
    Q.pop();
    tmp >>= 1;
    Q.push(tmp);
  }
  
  long long sum = 0;
  
  for (int i = 0; i < N; i++) {
    sum += Q.top();
    Q.pop();
  }
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 4296
import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  [a, b] <- readInts
  putStrLn $ solve a b

solve :: Int -> Int -> String
solve a b = if a <= 8 && b <= 8 then "Yay!" else ":("

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

toTup2 :: [[a]] -> [(a, a)]
toTup2 = map (\ys -> case ys of y : z : zs -> (y, z))

encIdx2 :: Int -> (Int, Int) -> Int
encIdx2 mx (y, x) = y * mx + x

decIdx2 :: Int -> Int -> (Int, Int)
decIdx2 mx idx = (idx `div` mx, idx `mod` mx)

encIdx3 :: (Int, Int) -> (Int, Int, Int) -> Int
encIdx3 (my, mx) (z, y, x) = z * my * mx + y * mx + x

decIdx3 :: (Int, Int) -> Int -> (Int, Int, Int)
decIdx3 (my, mx) idx = (z, y, x)
  where
    basez = my * mx
    z = idx `div` basez
    y = (idx `mod` basez) `div` mx
    x = idx `mod` mx

while :: Monad m => m Bool -> m () -> m ()
while cond body = do
  b <- cond
  when b $ do
    body
    while cond body


Measured memory_bytes: 380
//Shivam gupta (Codeforces handle : shivam_1999)

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

#define mod 1000000007
#define ll long long
#define ld long double
typedef vector<long long> vi;
typedef vector<vi> vvi;
typedef pair<long long, long long> pii;
typedef vector<pair<long long, long long>> vpii;
typedef map<long long, long long> mii;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(x) x.begin(), x.end()
#define sorta(x) sort(x.begin(),x.end())
#define sortd(v) sort(all(v), greater<ll>())
#define el cout << endl;
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define cpresent(container, element) (find(all(container), element) != container.end())
#define deb(x) cout << #x << x << endl;
#define fl(i,n) for(ll i=0;i<n;i++)
#define fls(i,x,n) for(ll i=x;i<n;i++)
#define flr(i,n)  for(ll i=n-1;i>=0;i--)
#define fla(i,v)  for(auto i:v)    
#define in(v) for(auto &i:v){cin>>i;}
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define tt    \
    int T;    \
    cin >> T; \
    while (T--)

int main()
{   fast
    ll n,w;
    cin >> n >> w;
    ll wg[n], v[n];
    ll dp[n + 1][w + 1];
    fl(i,n){
        cin >> wg[i] >> v[i];
    }
    fls(i,0,n+1){
        fls(j,0,w+1){
            if(i==0||j==0)
                dp[i][j] = 0;
            else if(wg[i-1]<=j)
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wg[i - 1]] + v[i - 1]);
            else
                dp[i][j] = dp[i - 1][j];
        }
    }
    cout << dp[n][w] << endl;
}


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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define all(x) begin(x),end(x)

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

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    for (;;) {
        ll N, S, W, Q;
        cin >> N >> S >> W >> Q;
        if (N == 0) break;

        vll a(N);
        int g = S;
        REP(i, N) {
            a[i] = (g/7) % 10;
            if( g%2 == 0 ) { g = (g/2); }
            else           { g = (g/2) ^ W; }
        }

        if (Q == 2) {
            ll ans = 0, tmp = 0;
            REP(i, N) {
                if (a[i] != 0) ++tmp;
                if (a[i] % 2 == 0) ans += tmp;
            }
            cout << ans << endl;
            continue;
        }
        if (Q == 5) {
            ll ans = 0, tmp = 0;
            REP(i, N) {
                if (a[i] != 0) ++tmp;
                if (a[i] % 5 == 0) ans += tmp;
            }
            cout << ans << endl;
            continue;
        }

        vll sum(N+1);
        ll tmp = 1;
        RREP(i, N) {
            sum[i] = (sum[i+1] + a[i] * tmp) % Q;
            (tmp *= 10) %= Q;
        }

        map<ll,vi> cnt;
        REP(i, N+1) {
            cnt[sum[i]].push_back(i);
        }

        ll ans = 0;
        for (auto& tp : cnt) {
            auto& v = tp.second;
            int m = v.size();
            REP(i, m) {
                if (a[v[i]] != 0) ans += m-i-1;
            }
        }
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 14176
#include<bits/stdc++.h>
#define N 15
using namespace std;
int n,ans[N][N],cnt,num;

int main(){
  while(1){
    cnt=1,num=2;
    memset(ans,0,sizeof(ans));
    cin>>n;
    if(!n)break;
    int y=n/2+1,x=n/2;
    ans[y][x]=1;
    while(cnt++!=n*n){
      y++,x++;
      if(n<=y)y=0;
      if(n<=x)x=0;
      while(ans[y][x]){
	y++,x--;
	if(n<=y)y=0;
	if(n<=x)x=0;
	if(y<0)y=n-1;
	if(x<0)x=n-1;
      }
      ans[y][x]=num++;
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++)
	printf("%4d",ans[i][j]);
      cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1192
x1,y1,x2,y2 = map(int,input().split())
nvec = (y1-y2,x2-x1)
x3,y3 = x2+nvec[0],y2+nvec[1]
x4,y4 = x1+nvec[0],y1+nvec[1]
print(x3,y3,x4,y4)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main(){
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	int num[3] = { 0, 0, 0 };
	if (A + B > C * 2){
		if (X > Y){
			num[2] += Y * 2;
			if (A > C * 2){
				num[2] += (X - Y) * 2;
			}
			else{
				num[0] += X - Y;
			}
		}
		else{
			num[2] += X * 2;
			if (B > C * 2){
				num[2] += (Y - X) * 2;
			}
			else{
				num[1] += Y - X;
			}
		}
	}
	else{
		num[0] = X;
		num[1] = Y;
	}

	int price;
	price = num[0] * A + num[1] * B + num[2] * C;
	cout << price;

	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	VI A(N);
	REP(i, N) cin >> A[i];
	VI B(N), C(N);
	B[0] = A[0];
	C[N - 1] = A[N - 1];
	REP(i, N - 1){
		B[i + 1] = max(A[i + 1], B[i]);
		C[N - i - 2] = max(A[N - i - 2], C[N - i - 1]);
	}

	REP(i, N){
		int b = 0 < i ? B[i - 1] : 0;
		int c = i < N - 1 ? C[i + 1] : 0;
		cout << max(b, c) << endl;
	}


	return 0;
}


Measured memory_bytes: 3968
#include<iostream>
#include<string>
using namespace std;
string map[20]={""};
void check(int x,int y);
int main(void){
    while(1){
        int ans=0;
        for(int i=0;i<12;i++){
            cin>>map[i];
            if(cin.eof())goto end;
        }
        for(int i=0;i<12;i++){
            for(int j=0;j<12;j++){
                if(map[i][j]=='1'){
                    check(i,j);
                    ans++;
                }
            }
        }
        cout<<ans<<endl;
    }
    end:;
    return 0;
}
void check(int x,int y){
    map[x][y]='0';
    if(x!=11&&map[x+1][y]=='1')check(x+1,y);
    if(y!=11&&map[x][y+1]=='1')check(x,y+1);
    if(x!=0&&map[x-1][y]=='1')check(x-1,y);
    if(y!=0&&map[x][y-1]=='1')check(x,y-1);
    return;
}

Measured memory_bytes: 1204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

struct State {
	vector<uint16_t> A;
	int idx = 0;
	bool did = false;
	uint16_t getOpponent() {
		return A[idx];
	}
	void matched() {
		idx++;
		did = true;
	}
};

int main() {
	int N; cin >> N;
	vector<State> A(N);
	rep(i, N) {
		A[i].A.resize(N - 1);
		rep(j, N - 1) {
			cin >> A[i].A[j];
			A[i].A[j]--;
		}
	}
	int ans = 0;
	while (true) {
		bool fin = true;
		rep(i, N) {
			if (A[i].idx != N - 1 && !A[i].did) {
				fin = false;
				uint16_t a = A[i].getOpponent();
				if (A[a].getOpponent() == i && !A[a].did) {
					A[i].matched();
					A[a].matched();
				}
			}
		}

		if (fin) break;

		bool cannot = true;
		rep(i, N) {
			if (A[i].did) cannot = false;
			A[i].did = false;
		}
		if (cannot) {
			cout << -1 << endl;
			return 0;
		}
		ans++;
	}
	cout << ans << endl;

}

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

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 

#define int long long
#define mod 1000000007
#define pb push_back
#define S second
#define F first
#define INF 1e18
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n" \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x) \
  int x;     \
  cin >> x;  \
  while (x--)

int32_t main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<pair<int,int>> v(n);
  for(auto &i: v)
    cin >> i.F >> i.S;
  
  int a = -INF,b = -INF; 
  sort(v.begin(),v.end());
  
  int ans = 0;
  
  for(auto i: v) {
   if(a != -INF) {
      ans = max(ans,i.F + i.S + a);
   }
    if(b != -INF) {
      ans = max(ans,i.F - i.S + b);
    }
    a = max(a,-i.F-i.S);
    b = max(b,-i.F+i.S);
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 6348
import java.util.*;
 
public class Main{
  	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      
      int a = sc.nextInt();
      int b = sc.nextInt();
      
      if(((a * b) % 2) == 0) {
        System.out.print("Even");
      }
      else{
        System.out.print("Odd");
      }
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

void solve() {
    ll x; cin >> x;
    if(x % 11 >= 7) {
        cout << (x / 11) * 2 + 2 << endl;
    } else if(x % 11 <= 6 && x % 11 >= 1) {
        cout << (x / 11) * 2 + 1 << endl;
    } else {
        cout << (x / 11) * 2 << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define MN 3000
#define mod 1000000007
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,m,s[MN+5],f[MN+5],g[MN+5],l[MN+5],r[MN+5],p[MN+5],inv[MN+5];
char st[MN+5];
void Move(int s)
{
	for(int i=n;i>=s;--i) f[i]=f[i-s];
	for(int i=0;i<s;++i) f[i]=0;
}
inline int C(int n,int m){return 1LL*p[n]*inv[m]%mod*inv[n-m]%mod;} 
int main()
{
	n=read();m=read();scanf("%s",st+1);p[0]=p[1]=inv[0]=inv[1]=f[0]=1;
	for(int i=1;i<=n;++i) s[i]=s[i-1]+(st[i]=='1');
	for(int i=2;i<=n;++i) p[i]=1LL*p[i-1]*i%mod,inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
	for(int i=2;i<=n;++i) inv[i]=1LL*inv[i-1]*inv[i]%mod;n=0;
	for(int i=1;i<=m;++i) l[i]=read(),n=max(n,r[i]=read());l[m+1]=n+1;
	for(int i=1,mr=l[1]-1;i<=m;++i)
	{
		if(r[i]>mr) Move(s[r[i]]-s[mr]),mr=r[i];
		if(l[i+1]>l[i])
		{
			int len=min(l[i+1]-1,mr)-l[i]+1;
			for(int j=0;j<=n;++j) if(f[j])
			{
				for(int k=0;k<=j&&k<=len;++k) if(mr-l[i]+1-j>=len-k)
					g[j-k]=(g[j-k]+1LL*f[j]*C(len,k))%mod;	
			}
			for(int j=0;j<=n;++j) f[j]=g[j],g[j]=0;
			mr=max(mr,l[i+1]-1);
		}
	}
	printf("%d\n",f[0]);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <stdio.h>
using namespace std;
int main(){
    int a,t[1000000],u[1000000];
    for(int i=0;i<1000000;i++){
        t[i]=1;
    }
    t[0]=t[1]=u[0]=u[1]=0;
    for(int i=2;i<=1000000;i++){
        if(t[i]==1){
            for(int j=i+i;j<1000000;j+=i)t[j]=0;
            u[i]=u[i-1]+1;
        }else{
            u[i]=u[i-1];
        }
    }
    while(cin>>a){
        cout<<u[a]<<endl;
    }
    return 0;
}



Measured memory_bytes: 10860
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
const int MOD = 1e9+7;
const int INF = 1e9;
const int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
#else
#define debug(...) 42
#endif


int main() {
  int A, B;
  cin >> A >> B;

  int max_N = (A+1) / 0.08;
  int min_N = A / 0.08;
  // Nは[min_N, max_N)
  int min_N2 = B / 0.1;
  int max_N2 = (B+1) / 0.1;
  rep(i, max(min_N, min_N2), min(max_N, max_N2)) {
    if (floor(i * 0.08) == A && floor(i * 0.10) == B) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1\n";

  return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    N, W = map(int, sys.stdin.readline().split())
    L = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
    #print(L)
    dp = [[0 for i in range(W+1)] for j in range(N)]
    #初期設定
    dp[0][L[0][1]] = L[0][0]
    for i in range(1, N):
        dp[i] = dp[i-1].copy() #1.前回データの更新
        v, w = L[i][0], L[i][1]
        dp[i][w] = max(dp[i][w], v) #2.今回データの挿入
        for j in range(W+1): #3.足し算データ更新
            if dp[i-1][j] !=0 and j+w<=W:
                dp[i][j+w] = max(dp[i-1][j]+v, dp[i-1][j+w]) 
    print(max(dp[-1]))


if __name__=='__main__':
    main()


Measured memory_bytes: 22360
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int N, X;
  cin >> N >> X;
  vector<int> L(N, 0);
  rep(i, 0, N) {
    cin >> L[i];
  }
  int ans = 1;
  int dist = 0;
  for (auto n : L) {
    dist += n;
    if (dist <= X)
      ++ans;
    else
      break;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    ll a , v , b , w , t;
    cin >> a >> v >> b >> w >> t;
    ll s = abs(a - b);
    ll g = (v - w) * t;
    if(s <= g){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 3592
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

ll t[200010] = {};

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

  ll N, T;
  cin >> N >> T;

  REP(i, N) {
    cin >> t[i];
  }

  ll total = 0;
  REP(i, N - 1) {
    total += min(t[i + 1] - t[i], T);
  }
  total += T;

  cout << total << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	int n = s.length(), i, j, k;
	vector<bool> dp(n + 1, false);
	dp[0] = true;
	vector<string> ss = { "dream", "dreamer", "erase", "eraser" };
	for (i = 0; i < n; i++) {
		if (!dp[i]) continue;
		for (j = 0; j < 4; j++) {
			if ((i + ss[j].length() <= n) && (s.substr(i, ss[j].length()) == ss[j])) dp[i + ss[j].length()] = true;
		}
	}

	if (dp[n]) cout << "YES";
	else cout << "NO";

	return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
struct edge {
  int to, cost;
};
struct UnionFind {
  vector< int > data;
  UnionFind(int sz){ data.assign(sz, -1); }
  int Find(int x){ return(data[x] < 0 ? x : data[x] = Find(data[x])); }
  bool Same(int a, int b){ return(Find(a) == Find(b)); }
  void Unite(int a, int b){ a = Find(a), b = Find(b); data[a] += data[b]; data[b] = a; }
};
const int INF = 1 << 30;
typedef pair< int, int > Pi;

int N, M, C;
vector< edge > graph[100000];
Pi min_cost[100000];

void Dijkstra()
{
  for(int i = 0; i < N; i++) {
    min_cost[i] = make_pair(INF, i);
  }
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  que.push(make_pair(0, 0));
  min_cost[0].first = 0;
  while(!que.empty()) {
    Pi p = que.top(); que.pop();
    if(min_cost[p.second].first < p.first) continue;
    for(int i = 0; i < graph[p.second].size(); i++) {
      const edge& e = graph[p.second][i];
      if(min_cost[e.to].first <= p.first + e.cost) continue;
      min_cost[e.to].first = p.first + e.cost;
      que.push(make_pair(min_cost[e.to].first, e.to));
    }
  }
}


int main()
{
  long long ALL = 0;
  scanf("%d %d %d", &N, &M, &C);
  for(int i = 0; i < M; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    --a, --b;
    graph[a].push_back((edge){b, c});
    graph[b].push_back((edge){a, c});
    ALL += c;
  }
  Dijkstra();
  sort(min_cost, min_cost + N);
  vector< int > nums(N);
  for(int i = 0; i < N; i++) {
    nums[i] = min_cost[i].first;
  }
  nums.erase(unique(nums.begin(), nums.end()), nums.end());
  UnionFind uftree(N);
  long long ret = 1LL << 60;
  for(int i = 0, ptr = 0; i < nums.size(); i++) {
    for( ; ptr < N && nums[i] == min_cost[ptr].first; ++ptr) {
      int curr = min_cost[ptr].second;
      if(!uftree.Same(curr, 0)) uftree.Unite(curr, 0);
      for(int j = 0; j < graph[curr].size(); j++) {
        if(uftree.Same(curr, graph[curr][j].to)) ALL -= graph[curr][j].cost;
      }
    }
    ret = min(ret, ALL + (long long)C * nums[i]);
  }
  cout << ret << endl;
}

Measured memory_bytes: 11224
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
inline ll modadd(ll n,ll m,ll mod){
    ll sum = ((n+m)%mod+mod)%mod;
    return sum;
} 
const ll N=1e9+7;
int main()
{
   int n,m;
   cin>>n>>m;
   char arr[n][m];
   forl(i,0,n)forl(j,0,m) cin>>arr[i][j];
   ll dp[n][m];
   forl(i,0,n) forl(j,0,m) dp[i][j]=0;
   dp[0][0]=1;
   forl(i,0,n)
   {
       forl(j,0,m)
       {
           if(arr[i][j]=='#')
           {
               dp[i][j]=0;
               continue;
           }
           if(i-1>=0)dp[i][j]=modadd(dp[i][j],dp[i-1][j],N);
           if(j-1>=0)dp[i][j]=modadd(dp[i][j],dp[i][j-1],N);

       }
   }
   cout<<dp[n-1][m-1]<<endl;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll a, b, k; cin >> a >> b >> k;

    if (a >= k) {
        cout << a - k << ' ' << b <<  endl;
    } else if (a < k && b >= k - a) {
        cout << 0 << ' ' << b - (k - a) << endl;
    } else {
        cout << 0 << ' ' << 0 << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
        int n = sc.nextInt();
        int m = sc.nextInt();
        int miss = 0, count = 0;
        int tmp;String tmp2;
        int ans[] = new int[n];
        boolean ans2[] = new boolean[n];
        for(int i = 0;i < n;i++){
             ans[i] = 0;
             ans2[i] = false;
        }      
      
      
        for(int i = 0;i < m;i++){
             tmp = sc.nextInt();
             tmp2 = sc.next();
             if(ans2[tmp - 1] == false){
               if(tmp2.equals("AC")){
                 count +=1;
                 ans2[tmp - 1] = true;
                 miss += ans[tmp - 1];
               }else{
                 ans[tmp - 1] += 1;
               }
             }
        }
        System.out.println(count + " " +  miss);
    }
}

Measured memory_bytes: 60296
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}

	return i
}
func main() {
	sc.Split(bufio.ScanWords)
	k := nextInt()
	s := nextStr()

	if len(s) <= k {
		fmt.Println(s)
	} else {
		fmt.Println(s[:k] + "...")
	}

}
func nextStr() string {
	sc.Scan()
	i := sc.Text()
	return i
}


Measured memory_bytes: 1756
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define ml cout<<endl
 
#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define ff first
#define ss second
#define mod 1000000007

#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
//ll ans;

// ll dfs(vi v ,ll m ){
//   if(visited[]) 
// }
int main(){
	ios_base::sync_with_stdio(false);
     	cin.tie(NULL);
    	cout.tie(NULL);    
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    
    // while(a!=0 && c!=0){
    //     c-=b;
    //     a-=d;
    // }
    ll ans = 0;//a/d + (a%d==0)? 0: 1 ;
    ll  p = 0;//c/b + (c%b==0)? 0: 1 ;
    while(a>0){
        a-=d;
        ans++;
    }
    while(c>0){
        c-=b;
        p++;
    }
    
   // test4(a,ans,c,p);
    if(ans<p){
        no;
    }else{
        yes;
    }

    // string str;
    // cin>>str;
    // ll n= str.size();
    // ll ans=0;
    // rep(i,0,n){
    //   // test1(i);
    //     string s="";
    //     ll p=0;
    //     rep(j,i,n){
    //         s+= str[j];
    //         p = p*10 + str[j]-'0';
    //         // string w = s;
    //         // ll  p = stoi(w);
    //         // test1(p);
    //         if(p%2019==0){
    //             ++ans;
    //         }
    //     }
    // }
    // cout<<ans<<endl;
	return 0;
}






Measured memory_bytes: 3576
#include <iostream>

using namespace std;

int main(){
    int N;

    cin >> N;

    if(N % 10 == 7) {cout << "Yes" << endl;}
    else if(700 <= N && N <= 799){cout << "Yes" << endl;}
    else if((N % 100) / 10 == 7){cout << "Yes" << endl;}
    else{cout << "No" << endl;}

    return 0;
}



Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

int n, s1, s2, a, num, mn;
int main()
{
	int i, t1, t2;
//	freopen ("input.txt","r", stdin);
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf ("%d", &a);
		if (a % 4 == 0) s1++;
		else if (a % 2 == 0) s2++;
	}
	if (s1 > 0 && s2 <= 1) {
		num = s1 * 2 +1;
	} else if (s1 == 0 && s2 >= 2) {
		num = s2;
	} else {
		num = s1 * 2 + s2;
	}
	if (num >= n) cout << "Yes";
	else cout << "No";
    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_right

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

BN = []
for b in B:
    i = bisect_right(C, b)
    BN.append(N - i)
for i in range(N - 2, -1, -1):
    BN[i] += BN[i + 1]
BN.append(0)
s = 0
for a in A:
    i = bisect_right(B, a)
    s += BN[i]
print(s)


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

int main() {
	string S, T;
	cin >> S >> T;
	int lenS = S.length();
	int lenT = T.length();
	if (lenS < lenT) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	vector<string> Answers;

	for (int i = lenS - lenT; i >= 0; i--) {
		int key_start = i;
		for (int j = 0; j < lenT; j++) {
			if (S[i + j] != '?' && S[i + j] != T[j]) {
				key_start = -1;
				break;
			}
		}
		if (key_start >= 0) {
			string ans;
			for (int j = 0; j < lenS; j++) {
				if (j == key_start) {
					ans += T;
					j += lenT - 1;
				}
				else ans+= S[j] == '?' ? 'a' : S[j];
			}
			Answers.push_back(ans);
		}
	}
	if (Answers.empty()) cout << "UNRESTORABLE" << endl;
	else {
		sort(Answers.begin(), Answers.end());
		cout << *Answers.begin() << endl;
	}
}

Measured memory_bytes: 256