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

int main() {
    int n, m, d, t;
    map<int, int> mpd, mpt;
    cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%d", &d);
        mpd[d]++;
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
        scanf("%d", &t);
        mpt[t]++;
    }
    
    bool ret = true;
    for (auto& mt : mpt) {
        if (mt.second > mpd[mt.first]) {
            ret = false;
            break;
        }
    }
    
    puts(ret ? "YES" : "NO");
}


Measured memory_bytes: 18944
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
  read(x), read(y...);
}
const int N=3e2+10,P=1e9+7;
int n;
int A[N<<1],vis[N<<1],G[N<<1],F[N<<1][N][N];
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  read(n);
  for(int i=1;i<=n<<1;++i) read(A[i]);
  int GG=0;
  for(int i=1;i<=n;++i) {
    if((~A[i*2])&&(~A[i*2-1])) vis[A[i*2]]=vis[A[i*2-1]]=2;
    else if(~A[i*2]) vis[A[i*2]]=1;
    else if(~A[i*2-1]) vis[A[i*2-1]]=1;
    else ++GG;
  }
  int cnt=0;
  for(int i=1;i<=n<<1;++i) {
    if(vis[i]<2) {
      G[++cnt]=i;
    }
  }
  F[cnt][0][0]=1;
  for(int i=cnt;i;--i) {
    for(int j=0;j<=n;++j) {
      for(int k=0;k<=n;++k) if(F[i][j][k]) {
        if(vis[G[i]]) {
          (F[i-1][j+1][k]+=F[i][j][k])%=P;
          if(k) (F[i-1][j][k-1]+=F[i][j][k])%=P;
        }
        else {
          (F[i-1][j][k+1]+=F[i][j][k])%=P;
          if(j) (F[i-1][j-1][k]+=1ll*F[i][j][k]*j%P)%=P;
          if(k) (F[i-1][j][k-1]+=F[i][j][k])%=P;
        }
      }
    }
  }
  int t=1;
  for(int i=1;i<=GG;++i) t=1ll*t*i%P;
  printf("%lld\n",1ll*F[0][0][0]*t%P);
  return 0;
}


Measured memory_bytes: 225536
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#ifdef LOCAL
#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
#define bits(x) bitset<22>(x)
#define tham getchar()
#endif

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

mt19937_64 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
//const ll mod = ;
//const ld error = ;
const ld PI = acosl(-1);

//inline ll MOD(ll x, ll m = mod){
//    ll y = x % m;
//    return (y >= 0) ? y: y+m;
//}

//const int/ll inf = ;
//const int nmax = ;
///===========================================  template  =======================================================

typedef pair<int, int> pii;
typedef pair<pii, pii> ppp;

int cnt(ll x, int p){
    int ret = 0;
    while(x % p == 0) x /= p, ret++;
    return ret;
}

int main(){
    FASTIO;

    int n;
    cin>>n;
    vector<ll> N(n), D(n);
    map<ppp, ll> mp;
    int extra = 0;
    for(int i = 0; i<n; i++){
        string s;
        cin>>s;
        D[i] = 1;
        auto wtf = s.find('.');
        if(wtf != string::npos){
            int len = int(s.size()-wtf)-1;
            for(int j = 0; j<len; j++) D[i] *= 10;
            s.erase(s.begin()+wtf);
        }

        N[i] = stoll(s);

        ll g = __gcd(N[i], D[i]);
        N[i] /= g;
        D[i] /= g;

        ppp p = { {cnt(N[i], 2), cnt(N[i], 5)}, {cnt(D[i], 2), cnt(D[i], 5)} };
        mp[p]++;
        if(D[i] == 1)
            extra++;
    }

    assert(mp.size() < 6000);

    ll ans = 0;
    for(auto p1 : mp){
        auto p = p1.first;
        for(auto p2 : mp){
            auto q = p2.first;
            if(p.first.first + q.first.first >= p.second.first + q.second.first &&
               p.first.second + q.first.second >= p.second.second + q.second.second)
                ans += p1.second*p2.second;
        }
    }

    ans -= extra;
    ans /= 2;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 6256
#include<bits/stdc++.h>
using namespace std;
int main()
{
     long long t,i,j,n,l,m,k,p;

    cin>>n;
    l=n%10;
    if(l==2 || l==4||l==5||l==7||l==9)
    cout<<"hon";
    else if(l==0 ||l==1 ||l==6||l==8)
    cout<<"pon";
    else
    cout<<"bon";
    
    
    
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10 , OO = 0x3f3f3f3f ;
const int mod = 1e9 + 7;
 
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define xloop(i,a,b) for(int i = int(a);i <= int(b);i++)
#define range(vec) for(auto &x : vec) cin >> x;
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction


int main()
{
   // startTime = (double)clock();
    #ifndef ONLINE_JUDGE
        //freopen("in.in", "r", stdin);
        //freopen("out.in", "w", stdout);
    #endif
	//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    int x , y , cnt = 0;
    scanf("%d %d" ,&x , &y);
    
    for(int i = 0 ; i <= x ; ++i){
        int cnt = (i * 4) + (x - i) * 2;
        if(cnt == y)
            return puts("Yes") , 0; 
    }
    puts("No");


    return 0;
}

Measured memory_bytes: 3768
n,m = map(int,input().split())
li = list(map(int,input().split()))
road = []
while True:
    try:
        road.append(list(map(int,input().split())))
 
    except:
        break;
        #または、quit(),os.exit()をして止める。
 
#print(road)

x = [0]*n
for i in range(m):
    if li[road[i][1]-1]>=x[road[i][0]-1]:
        x[road[i][0]-1]=li[road[i][1]-1]
    if li[road[i][0]-1]>=x[road[i][1]-1]:
        x[road[i][1]-1]=li[road[i][0]-1]
    
cnt = 0    
for i in range(n):
    if li[i]>x[i]:
        cnt += 1
#print(x)
#print(li)
print(cnt)

Measured memory_bytes: 32048
#include<bits/stdc++.h>
using namespace std;
int main(){
    int H,W;
    cin >> H >> W;
    char field[H+2][W+2];
    for(int i = 0; i < H+2; i++){
        for(int j = 0; j < W+2; j++){
            if(i == 0 || i == H+1) field[i][j] = '*';
            else if(j == 0 || j == W+1) field[i][j] = '*';
            else cin >> field[i][j];
        }
    }
    for(int i = 1; i < H+1; i++){
        for(int j = 1; j < W+1; j++){
            if(field[i][j] == '#'){
                cout << "#";
                continue;
            }
            int c = 0;
            char f1 = field[i-1][j-1];
            char f2 = field[i-1][j];
            char f3 = field[i-1][j+1];
            char f4 = field[i][j-1];
            char f5 = field[i][j+1];
            char f6 = field[i+1][j-1];
            char f7 = field[i+1][j];
            char f8 = field[i+1][j+1];
            if(f1 == '#') c++; if(f2 == '#') c++;
            if(f3 == '#') c++; if(f4 == '#') c++;
            if(f5 == '#') c++; if(f6 == '#') c++;
            if(f7 == '#') c++; if(f8 == '#') c++;
            field[i][j] = (char)c;
            cout << c;
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			Job[] jobs = new Job[n];
			IntStream.range(0, n).forEach(i -> jobs[i] = new Job(scanner.nextInt(), scanner.nextInt()));
			Arrays.sort(jobs);
			int sum = 0;
			for (Job job : jobs) {
				sum += job.time;
				if (sum > job.dueTo) {
					System.out.println("No");
					return;
				}
			}
			System.out.println("Yes");
		}
	}

	private static class Job implements Comparable<Job> {
		/** 仕事をこなすための時間 */
		int time;
		/** 仕事の締め切り時間 */
		int dueTo;

		Job(int time, int dueTo) {
			super();
			this.time = time;
			this.dueTo = dueTo;
		}

		@Override
		public int compareTo(Job job) {
			if (0 == (this.dueTo - job.dueTo)) {
				return this.time - job.time;
			} else {
				return this.dueTo - job.dueTo;
			}
		}
	}
}


Measured memory_bytes: 120100
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
deque<pair<ll,long double> > dq;
long double total,eps = 1e-10;

int main() {
	ll n,L,t,v;
	cin >> n >> L;
	for (int i = 0; i < n; i++) {
		cin >> t >> v;
		ll x  = v;
		while (x && !dq.empty()) {
			 int a = dq.front().first;
			 if (a <= x) {
			 	x -= a;
			 	total -= dq.front().second*a;
			 	dq.pop_front();
			 }
			 else {
			 	dq[0].first -= x;
			 	total -= dq.front().second*x;
			 	break;
			 }
		}
		long double cur = t;
		total +=cur*v; 
		while (!dq.empty() && dq.back().second +eps> cur)  {
			cur = (long double)((double)dq.back().second*(double)dq.back().first + (double)cur*v)/(long double)(v + dq.back().first);
			v += dq.back().first;
			 dq.pop_back();
		}
		dq.push_back({v,cur});
	cout << fixed<<setprecision(10) <<total/(double)L <<'\n';     //  cout << dq.size() <<'\n';
	}
	
}

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

int main(){
  int N,K;
  cin >> N >> K;
  long long x[N],y[N],xx[N],yy[N];
  long long mnX,mnY,mxX,mxY;
  long long size;
  For(i,N){
    cin >> x[i] >> y[i];
    xx[i] = x[i],yy[i] = y[i];
  }
  sort(x,x+N);
  sort(y,y+N);
  size = (x[N-1]-x[0])*(y[N-1]-y[0]);
  For(i,N-1) for(int j=i+1; j<N; j++){
    For(k,N-1) for(int l=k+1; l<N; l++){
      int num=0;
      mnX = x[i], mxX = x[j];
      mnY = y[k], mxY = y[l];
      for(int p=0; p<N; p++){
        if(mnX<=xx[p] && xx[p]<=mxX && mnY<=yy[p] && yy[p]<=mxY){
          num++;
        }
        if(num>=K) size = min(size, (mxX-mnX)*(mxY-mnY));
      }
    }
  }
  cout << size << endl;
  return 0;
}


Measured memory_bytes: 256
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let s: u64 = sc.read();
    let t: u64 = sc.read();
    let _: u64 = sc.read();
    let _: u64 = sc.read();
    let _: u64 = sc.read();
    let y: u64 = sc.read();
    let x = t ^ s;
    let fy = y ^ x;
    println!("{}", fy);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}



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

const int MAXN = 100 + 10;
int N, x;
int a[MAXN];

void read(){
	cin >> N >> x;
	for(int i = 0;i < N; ++i){
		cin >> a[i];
	}
	sort(a, a + N);
	return;
}

void find(){
	for(int i = 0;i < N; ++i){
		x -= a[i];
		if(x <= 0){
			cout << i + (x == 0) << endl;
			return; 
		}
	}
	cout << N - 1 << endl;
	return;
}

int main(){
	read(); find();
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int naive(string s){
    int n = s.length();
    queue<string> que;
    que.push(s);
    set<string> st;
    st.insert(s);
    while (!que.empty()){
        string t = que.front();
        que.pop();
        REP(i,n-1){
            if (t[i] != t[i+1]){
                string u = t;
                string sub = t.substr(i, 2);
                if (sub == "ab" || sub == "ba"){
                    u[i] = u[i+1] = 'c';
                }else if (sub == "bc" || sub == "cb"){
                    u[i] = u[i+1] = 'a';
                }else{
                    u[i] = u[i+1] = 'b';
                }

                if (st.count(u) == 0){
                    st.insert(u);
                    que.push(u);
                }
            }
        }
    }

    return st.size();
}

ll dp[200010][3][3][2];
const ll mod = 998244353;

int main() {
    string s;
    cin >> s;
    int n = s.length();

    bool same = true;
    REP(i,n) if (s[0] != s[i]) same = false;

    if (same){
        cout << 1 << endl;
        return 0;
    }

    if (n <= 10){
        cout << naive(s) << endl;
        return 0;
    }

    int m = 0;
    REP(i,n) m = (m + s[i] - 'a') % 3;

    REP(i,3) dp[0][i][i][0] = 1;

    REP(i,n-1) REP(j,3) REP(p,3) REP(k,2){
        REP(l,3){
            (dp[i+1][(j+l)%3][l][k|(p==l)] += dp[i][j][p][k]) %= mod;
        }
    }

    ll ans = 0;
    REP(j,3) ans = (ans + dp[n-1][m][j][1]) % mod;

    bool dif = true;
    REP(i,n-1) if (s[i] == s[i+1]) dif = false;

    if (dif) ans = (ans + 1) % mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 28676
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
#define vcin(a)                          \
    for (int i = 0; i < (a).size(); i++) \
        cin >> (a)[i];

int main()
{
    int N;
    cin >> N;
    vint A(N), B(N), C(N);
    rep(i, N)
    {
        cin >> A[i];
    }
    rep(i, N)
    {
        cin >> B[i];
    }
    rep(i, N)
    {
        cin >> C[i];
    }
    sort(all(A));
    sort(all(B));
    sort(all(C));
    ll ans = 0;
    rep(i, N)
    {
        auto itr1 = lower_bound(all(A), B[i]);
        ll idx1 = distance(A.begin(), itr1);
        if (itr1 == A.end())
            idx1 = N;
        auto itr2 = upper_bound(all(C), B[i]);
        ll idx2 = distance(itr2, C.end());
        if (itr2 == C.end())
            idx2 = 0;
        ans += (idx1 * idx2);
    }
    cout << ans;
    return 0;
}

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

void add(vector<int> &a, int i, int x) {
    a[i-1] += x;
}

int getSum(vector<int> &a, int s, int t) {
    int sum = 0;
    for(int i=s-1; i<=t-1; ++i) {
        sum += a[i];
    }
    return sum;
}

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n, 0);

    vector<int> com, x, y;
    for(int i=0; i<q; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        com.push_back(a);
        x.push_back(b);
        y.push_back(c);
    }

    for(int i=0; i<q; ++i) {
        if(com[i] == 0) {
            add(a, x[i], y[i]);
        } else if(com[i] == 1) {
            cout << getSum(a, x[i], y[i]) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4600
S=int(input())
y=S//100
m=S%100



if y>=13 and m>=13:
    print("NA")
elif y>=13 and m!=0 :
    print("YYMM")
elif m>=13 and y!=0 :
    print("MMYY")
elif 1<=m and 12>=m and y==0 :
    print("YYMM")
elif 1<=y and 12>=y and m==0 :
    print("MMYY")
elif m==0 or y==0:
    print("NA")
else:
    print("AMBIGUOUS")

Measured memory_bytes: 3064
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    def select(n,k):
        return math.factorial(n)//(math.factorial(k)*math.factorial(n-k))
    n,m = LI()
    ans = 0
    if n>=2:
        ans += n*(n-1)//2
    if m>=2:
        ans += m*(m-1)//2

    print(ans)
main()            


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

int main() {
	long long n, m;
	scanf("%lld %lld", &n, &m);
	//long long ans = min(n, m / 2);
	long long k = (m - 2 * n) / 4;
	if (k < 0) k = 0;
	m -= 2 * k;
	n += k;
	long long ans = min(m / 2, n);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
base = input().split()
a = int(base[0])
b = int(base[1])
c = int(base[2])
d = int(base[3])

for i in range(max(a,c)):
    c -= b
    if c<1:
        print("Yes")
        break
    a -= d
    if a<1:
        print("No")
        break


Measured memory_bytes: 9184
#include <cstdio>
#include <vector>

using namespace std;

long long a[200];
char s[201];

long long check(vector<long long>& v, long long x) {
    int i;
    
    for (i = 0; i < v.size(); i++) {
        if ((x ^ v[i]) < x) x ^= v[i];
    }
    
    return x;
}

bool solve() {
    int n, i;
    vector<long long> v;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%lld", &a[i]);
    
    scanf("%s", s);
    
    for (i = n - 1; i >= 0; i--) {
        long long x = check(v, a[i]);
        
        if (s[i] == '0') {
            if (x != 0) v.push_back(x);
        } else {
            if (x != 0) return false;
        }
    }
    
    return true;
}

int main() {
    int t, i;
    
    scanf("%d", &t);
    
    for (i = 0; i < t; i++) {
        if (solve()) {
            puts("0");
        } else {
            puts("1");
        }
    }
    
    return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
        int n, m;
        cin>>n>>m;
        int ans[51]={};
        for(int i=0; i<m; i++){
            int a, b;
            cin>>a>>b;
            ans[a]++;
            ans[b]++;
        }
        for(int i =1; i<=n; i++){
            cout<<ans[i]<<endl;
        }
}


Measured memory_bytes: 3124
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
superior = lr()
sub = [0] * (N+1)
for i in range(2, N+1):
    x = superior[i-2]
    sub[x] += 1

for i in range(N):
    print(sub[i+1])


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

typedef long long ll;
typedef pair<int,int> P;

#define fr first
#define sc second

struct Tree{
	int V;
	vector<int> G[100010];
	int dist[3][100010];
	void dfs(int v,int p,int t){
		dist[t][v] = dist[t][p]+1;
		for(int u: G[v]){
			if(u == p)continue;
			dfs(u,v,t);
		}
	}
	int cnt[100010];
	void solve(){
		int x = 1;
		dist[0][0] = -1;
		dfs(x,0,0);
		int y = 1;
		for(int i = 1 ; i <= V ; i ++){
			if(dist[0][i] > dist[0][y])y = i;
		}
		dist[1][0] = -1;
		dfs(y,0,1);
		int z = 1;
		for(int i = 1 ; i <= V ; i ++){
			if(dist[1][i] > dist[1][z])z = i;
		}
		dist[2][0] = -1;
		dfs(z,0,2);
		for(int i = 0 ; i <= dist[1][z] ; i ++){
			cnt[i] = 0;
		}
		
		/*cout << y << " " << z << endl;
		for(int i = 1 ; i <= V ; i ++){
			cout << dist[1][i] << " " << dist[2][i] << endl;
		}*/
		
		for(int i = 1 ; i <= V ; i ++){
			if(dist[1][i]+dist[2][i] == dist[1][z])continue;
			else if(dist[1][i]+dist[2][i] >= dist[1][z]+4){
				puts("-1");
				return;
			}
			else {
				cnt[dist[1][i]-1] ++;
			}
		}
		
		/*for(int i = 0 ; i <= dist[1][z] ; i ++){
			cout << cnt[i] << " ";
		}cout << endl;*/
		
		vector<int> v;
		for(int i = 0 ; i <= dist[1][z] ; i ++){
			v.push_back(cnt[i]);
		}
		vector<int> u = v; reverse(u.begin(),u.end());
		for(int i = 0 ; i < v.size() ; i ++){
			if(v[i] < u[i])break;
			if(v[i] > u[i]){
				v = u;
				break;
			}
		}
		int cnt = 0;
		int hoge = 1;
		int ret[100010];
		for(int i = 0 ; i+1 < v.size() ; i ++){
			ret[cnt+v[i]+1] = hoge++;
			//printf("%d ",cnt+v[i]+1);
			for(int j = 0 ; j < v[i] ; j ++){
				ret[cnt+j+1] = hoge++;
				//printf("%d ",cnt+j+1);
			}
			cnt += v[i]+1;
		}
		ret[V] = V;
		//printf("%d\n",V);
		
		for(int i = 1 ; i <= V ; i ++){
			printf("%d%c",ret[i],(i==V)?'\n':' ');
		}
	}
}tree;

int main(){
	scanf("%d",&tree.V);
	for(int i = 0 ; i < tree.V-1 ; i ++){
		int a,b;
		scanf("%d%d",&a,&b);
		tree.G[a].push_back(b);
		tree.G[b].push_back(a);
	}
	tree.solve();
}



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

#define MOD 1000000007
typedef unsigned long long ull;

int main() {
  // 0, 1, 2
  // 3, 4, 5
  // 6, 7 ,8
  vector<int> a(9);
  for (int i = 0; i < 9; i++) {
    cin >> a[i];
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    for (int j = 0; j < 9; j++) {
      if (a[j] == b) {
        a[j] = 0;
      }
    }
  }

  if ((a[0] == 0 && a[1] == 0 && a[2] == 0) ||
      (a[3] == 0 && a[4] == 0 && a[5] == 0) ||
      (a[6] == 0 && a[7] == 0 && a[8] == 0) ||
      (a[0] == 0 && a[3] == 0 && a[6] == 0) ||
      (a[1] == 0 && a[4] == 0 && a[7] == 0) ||
      (a[2] == 0 && a[5] == 0 && a[8] == 0) ||
      (a[0] == 0 && a[4] == 0 && a[8] == 0) ||
      (a[2] == 0 && a[4] == 0 && a[6] == 0)) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


Measured memory_bytes: 256
# encoding: utf-8
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

ans = -1
dmin = 1000
for i, Hi in enumerate(H):
    tmp = T - Hi * 0.006
    dtmp = tmp - A if tmp > A else A - tmp
    if dtmp < dmin:
        ans = i
        dmin = dtmp

print(ans + 1)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
 
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(vector<vector<T>> x){cerr<<"\n{"; int f=x.size();for(int i=0;i<f;i++){cerr<<"("; int g=x[i].size(); for(auto j:x[i]){cerr<<j; (--g!=0)?cerr<<",":cerr<<"";}cerr<<")\n";}cerr<<"}";}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void __print(vector<bool> x){cerr<<"{";int f=x.size();for(auto i:x){cerr<<i;(--f !=0)?cerr<<",":cerr<<"";}cerr<<"}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
 
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define trace(x...)
#endif
 
template<typename... T>
void read(T&... args) {
    ((cin >> args), ...);
}
 
template<typename... T>
void writ(T&&... args) {
    ((cout << args << " "), ...);
}
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define INF (ll)1e18
#define IINF (int)1e9
#define EPS 1e-9

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t; cin>>s>>t;
    int x=t.length();
    for(int i=0;i<=s.length()-t.length();i++){
        //trace(i);
        int g=0;
        for(int j=0;j<t.length();j++){
            if(s[i+j]!=t[j]) g++;
        }
        x=min(g,x);
    }
    cout<<x<<endl;
    return 0;
}



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

int m,n,ans,a[N][N],b[N][N],c[N],q[N],lf[N],rg[N];
char s[N];
int main(){
	scanf("%d%d",&m,&n);
	int i,j,k;
	for (i=1; i<=m; i++){
		scanf("%s",s+1);
		for (j=1; j<=n; j++) a[i][j]=(s[j]=='#');
	}
	for (i=1; i<=m; i++)
		for (j=2; j<=n; j++)
			b[i][j]=(a[i][j]^a[i+1][j])==(a[i][j-1]^a[i+1][j-1])?b[i-1][j]+1:0;
	for (i=1; i<=m; i++){
		for (j=2; j<=n; j++) c[j]=1+b[i-1][j];
		//if (i==2) for (j=2; j<=n; j++) cout<<c[j]<<' ';puts("");
		q[k=1]=1; c[1]=-2; c[n+1]=-1;
		for (j=2; j<=n+1; j++){
			for (; c[j]<=c[q[k]]; k--) rg[q[k]]=j;
			lf[j]=q[k]; q[++k]=j;
		}
		for (j=2; j<=n; j++){
			//cout<<j<<' '<<lf[j]<<' '<<rg[j]<<endl;
			ans=max(ans,c[j]*(rg[j]-lf[j]));
		}
	}
	printf("%d\n",max(ans,max(m,n)));
	return 0;
}


Measured memory_bytes: 31744
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
static const ll maxLL = (ll)1 << 62;

int main() {
	ll N; cin >> N;
	map<ll, ll>mp;
	rep(i, 0, N) {
		ll a; cin >> a;
		mp[a]++;
	}

	ll sq = 0, rec1 = 0, rec2 = 0;
	for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
		if (it->second >= 4) {
			sq = it->first;
		}

		if (it->second >= 2) {
			if (rec1 < it->first) {
				if (rec2 < rec1) {
					rec2 = rec1;
				}
				rec1 = it->first;
			}
			else if (rec2 < it->first) {
				rec2 = it->first;
			}
		}
	}
	cout << ((sq*sq > rec1*rec2) ? sq * sq : rec1 * rec2) << endl;;

	return 0;
}

Measured memory_bytes: 6528
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n = int(input())
    a = list(map(int, input().split()))
    tmp = 0
    for i in range(1,n):
        if a[i-1] > a[i]:
            tmp = a[i-1]-a[i]
            ans += tmp
            a[i] += tmp
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 31420
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;


int main() {
    int n;
    cin >> n;
    ll ans=0;
    repr(i,1,n+1) {
        if (!(i%3==0 || i%5==0)) ans+=i;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main() {
	double n; cin >> n;
	double d; cin >> d;
	int c = 0;
	for (int i = 1; c == 0; i++) {
		if (n / (2 * d + 1) <= i) {
			c = i;
	}
	}
	cout << c;
	return 0;
}

Measured memory_bytes: 256
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	int n;
	cin >> n;
	string s = "0";
	while(n--) {
		s[0]++;
		for(int i = 0; i < s.size(); i++) {
			if((i+1<s.size() && s[i]>min('9', char(s[i+1]+1))) || (i+1==s.size() && s[i]>'9')) {
				if(i+1==s.size())
					s.pb('0');
				s[i+1]++;
				s[i]='0';
			}
		}
		//cout << s << '\n';
		for(int i = s.size()-1; i; i--) {
			if(s[i-1] < max('0', (char)(s[i]-1)))
				s[i-1]=max('0', (char)(s[i]-1));

		}
	}
	reverse(all(s));
	cout << s;

	return 0;
}


Measured memory_bytes: 256
#input
N = int(input())
XD = []
for _ in range(N):
    x, d = map(int, input().split())
    XD.append((x, x+d))

MOD = 998244353

# process
XD.sort(reverse=True)

sei = [(10**9, 0)]
pattern = [0]*(N+1)
pattern[0] = 1
for i, (s, e) in enumerate(XD):
    ei = i
    while e > sei[-1][0]:
        _, ei = sei.pop()
    sei.append((s, ei))
    pattern[i+1] = (pattern[i] + pattern[ei]) % MOD

# output
print(pattern[-1])


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

using namespace std;

int main()
{
	set<int> s;
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int t;
		scanf("%d",&t);
		s.insert(t);
	}
	scanf("%d",&n);
	int ans=0;
	for(int i=0;i<n;i++)
	{
		int t;
		scanf("%d",&t);
		ans+=s.count(t);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5196
#include <climits>
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> m(n);
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        m[i] = make_pair(a, b);
    }

    vector<vector<int>> v(n, vector<int>(n, INT_MAX));
    for (int i = 0; i < n; ++i)
        v[i][i] = 0;

    for (int width = 2; width <= n; ++width) {
        for (int i = 0; i < n - width + 1; ++i) {
            int j = i + width - 1;
            for (int k = i; k < j; ++k) {
                v[i][j] =
                    min(v[i][j], v[i][k] + v[k + 1][j] +
                                     m[i].first * m[k].second * m[j].second);
            }
        }
    }
    cout << v[0][n - 1] << '\n';
}



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

int main(){
	int n;
	cin >> n;
	int a[n];
	double sum = 0;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		sum += 1.0 / (a[i]*1.0);
	}
	cout << (double) 1.0 / sum << endl;
	return 0;
}

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

const int INF = 1e9;

ll n;
vector<ll> h(2000000);

ll k;
int main() {
	cin >> n >> k;
	FOR(i, 1, n) cin >> h[i];
	vector<ll> dp(n,INF);
	dp[0] = 0;
	
	REP(i, n-1) {
		FOR(j, i + 1, min(n-1,i+k)) {
			dp[j] = min(dp[i] +abs(h[i+1]-h[j+1]) , dp[j]);
		}
		
	}
	cout << dp[n-1]<<endl;
}

Measured memory_bytes: 16640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef std::vector<int64_t> vI;

template<typename T>
ostream& operator<<(ostream& os, vector<T> const& v) {
  os << "[";
  for (size_t i = 0; i < v.size(); i++) {
    os << (i == 0 ? "" : ",") << v[i];
  }
  return os << "]";
}

int64_t count_lower(int64_t v, vI aa) {
//  std::cerr << "aa=" << aa << std::endl;
//  std::cerr << "count_lower v=" << v << std::endl;
  int64_t r = 0;
  for (size_t i = 0; i < aa.size() - 1; i++) {
    if (aa[i] < 0ll) {
      size_t lb = i, ub = aa.size() - 1;
//      std::cerr << "aa[i]=" << aa[i] << ",aa[ub]=" << aa[ub] << ",v=" << v << std::endl;
      if (aa[i] * aa[ub] >= v) continue;
      while (ub - lb > 1) {
        size_t mid = (lb + ub) / 2;
//        if (mid < 0) {mid = (lb + ub - 1) / 2; }
        if (aa[i] * aa[mid] >= v) {
          lb = mid;
        } else {
          ub = mid;
        }
      }
      r += aa.size() - ub;
    } else if (aa[i] == 0) {
      if (v > 0) r += aa.size() - i - 1;
    } else {
      size_t lb = i + 1;
      size_t ub = aa.size();
//      std::cerr << "aa[i]=" << aa[i] << ",aa[lb]=" << aa[lb] << ",v=" << v << std::endl;
      if (aa[i] * aa[lb] >= v) continue;
      while (ub - lb > 1) {
        size_t mid = (lb + ub) / 2;
//        if (mid < 0) {mid = (lb + ub - 1) / 2; }
        if (aa[i] * aa[mid] >= v) {
          ub = mid;
        } else {
          lb = mid;
        }
      }
      r += lb - i;
    }
//    std::cerr << "i=" << i << ",r=" << r << std::endl;
  }
//  std::cerr << "r=" << r << std::endl;
  return r;
}

int main() {
  int64_t n, k;
  std::cin >> n >> k;
//  std::cerr << "n=" << n << ",k=" << k << std::endl;
  vI aa(n);
  for (int64_t i = 0; i < n; i++) std::cin >> aa[i];
  std::sort(aa.begin(), aa.end());
  int64_t lb = std::min(aa[0] * aa[1], std::min(aa[0] * aa[aa.size() -1], int64_t(0)));
  int64_t ub = std::max(aa[0] * aa[1], aa[aa.size() - 2] * aa[aa.size() - 1]) + 1;  
//  std::cerr << "lb=" << lb << ",ub=" << ub << std::endl;
  while (ub - lb > 1) {
    int64_t mid = (lb + ub) / 2;
//    if (mid < 0) {mid = (lb + ub - 1) / 2; }
//    std::cerr << "lb=" << lb << ",ub=" << ub << ",mid=" << mid << std::endl;
//    std::cerr << "countlower(mid=" << mid << ")=" << count_lower(mid, aa) << std::endl;
    if (count_lower(mid, aa) <= k - 1) {
      lb = mid;
    } else {
      ub = mid;
    }
  }
  std::cout << lb << std::endl;
}


Measured memory_bytes: 3428
/**
 *  author: mahfuzz
 *  created: 27.03.2020
**/
 
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << ':' << x << "\n";
//~ const double pi = 2*acos(0.0);
//~ const long long mod = 1e9+7;
//~ const int max_n = 1e6+5;
typedef long long ll;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    int a, b , k;
    cin >> a >> b >> k;
    
    int i, j;
    
    for(i = a; i < k + a && i <= b; i++){
        cout << i << "\n";
    }
    
    
    for(j = max(i, b - k + 1); j <= b ; j++){
        cout << j << "\n";
    }
    
        
    return 0;
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            double N = double.Parse(Console.ReadLine());
            if (N %2 ==0)
            {
                Console.WriteLine(0.5);
            }
            else
            {
                double A = Math.Floor(N/2);
                Console.WriteLine(1-A/N);
            }
        }
    }
}

Measured memory_bytes: 13140
import java.io.*;
import java.lang.System;
import java.util.*;

public class Main {
    public static void main(String[] args)throws IOException{
        Scanner s = new Scanner(System.in);

        int numSet[] = new int[101];
        for (int i = 1; i < numSet.length; i++) {
            numSet[i] = 0;
        }

        while(s.hasNext()){
            int in = s.nextInt();
            numSet[in]++;
        }

        // 出現度が最大のものを求める
        int max = getMaxFreq(numSet);

        for (int i = 1; i < numSet.length; i++) {
            if (numSet[i] == max) {
                System.out.println(i);
            }
        }
    }

    public static int getMaxFreq(int[] arr) {
        int max = 0;
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        return max;
    }
}

Measured memory_bytes: 18152
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

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

    vector<vector<P>> vec(N);
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        for(int j = 0; j < a; j++){
            int x;
            int y;
            cin >> x >> y;
            x--;
            vec[i].push_back(P(x, y));
        }
    }

    int ans = -1;
    for(int i = 0; i < (1 << N); i++){
        bool check = true;
        for(int j = 0; j < N; j++){
            if(i & (1 << j)){
                //jが正直者
                for(int k = 0; k < vec[j].size(); k++){
                    int x = vec[j][k].first;
                    int y = vec[j][k].second;
                    if((i & (1 << x)) > 0 && y == 0) check = false;
                    if((i & (1 << x)) == 0 && y == 1) check = false;
                }
            }
            else {
                //jがうそつき

            }
        }

        if(check){
            //cout << i << endl;
            int cnt = 0;
            for(int j = 0; j < N; j++){
                if(i & (1 << j)) cnt++;
            }
            ans = max(ans, cnt);
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from math import gcd
from collections import defaultdict
N=int(input())
mod = 10**9+7
d_1 = defaultdict(int)
d_2 = defaultdict(int)
zeros = 0

def to_irreducible(a,b):
    GCD = gcd(a,b)
    return list(map(lambda x:x//GCD,[a,b]))
for i in range(N):
    a,b=map(int,input().split(' '))
    if a==b==0:
        zeros += 1
    elif a*b >= 0 and b!=0:
        a,b = to_irreducible(abs(a),abs(b))
        d_1[(a,b)] +=1
    else:
        a,b = to_irreducible(abs(b),abs(a))
        d_1[(a,b)] +=0
        d_2[(a,b)] +=1

ans =  1

for k,v_1 in d_1.items():
    v_2 = d_2[k]
    ans *= (pow(2,v_1,mod) + pow(2,v_2,mod) -1)
    ans %= mod

print((ans+zeros-1)%mod)

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

using namespace std;

typedef long long int ll;

const int N = 1e3 + 5;

vector < vector < int > > adj (N);

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

  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back (v);
  }

  int len = INT_MAX;
  vector < int > ans;
  for (int s = 1; s <= n; s++) {
    queue < int > q;
    q.push (s);
    vector < bool > used (n + 1, false);
    vector < int > p (n + 1);
    used[s] = true;
    while (!q.empty()) {
      int u = q.front(); q.pop();
      for (auto to : adj[u]) {
        if (!used[to]) {
          p[to] = u;
          used[to] = true;
          q.push (to);
        } else if (to == s) {
          vector < int > path;
          for (int i = u; i != s; i = p[i]) path.push_back (i);
          path.push_back (s);
          if ((int)path.size() < len) {
            len = (int)path.size();
            ans = path;
          }
        }
      }
    }
  }

  if (len == INT_MAX) {
    cout << -1 << '\n';
  } else {
    cout << len << '\n';
    for (auto i : ans) cout << i << '\n';
  }
}


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

using namespace std;

#define vit vector<int>::iterator
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fr first
#define sc second
#define skip continue
#define PI 3.14159265

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;

const int INF = 1e9 + 5;
const long long MAXN=2e5 + 5;;

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool cmp(const string& a, const string& b) {
	return (a + b) < (b + a);
}

vector<int> Reversed(const vector<int>& s){
   vector<int> d = s;
   reverse(all(d));
   return d;
}

void solve(){
    string s;
    cin >> s;
    string str[4] = {"maerd" , "remaerd" , "esare" , "resare"};
    reverse(all(s));
    bool ok, ok2 = true;
    for(int i = 0; i < s.size();){
        ok = false;
        for(int j = 0; j < 4; j++){
            if(str[j] == s.substr(i, str[j].size())){
                ok = true;
                i += str[j].size();
            }
        }
        if(!ok){
            //ok2 = false;
            break;
        }
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}


int main(){
    //freopen("slalom.in","r",stdin);
    //freopen("slalom.out","w",stdout);
    //faster();
    int n = 1;
    //cin >> n;
    while(n--){
        solve();
        cout << endl;
    }
    //fclose(stdout);
}


Measured memory_bytes: 3756
s = list(input())
t = list(input())
for i in range(len(s)-len(t)+1):
  dame = 0
  for j in range(len(t)):
    if s[len(s)-len(t)-i+j] != t[j] and s[len(s)-len(t)-i+j] != "?":
      dame = 1
      break
  if dame == 1:
    continue
  for j in range(len(t)):
      s[len(s)-len(t)-i+j] = t[j]
  for j in range(len(s)):
      if s[j] == "?":
        s[j] = "a"
  print("".join(s))
  exit()
print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
using namespace std;
int main(){

while(true){
		char g1[101],a;
		cin>>g1;
	if(strcmp(g1,"0")==0){
		break;
	}
	int As=0,Bs=0;
		for(int i=1;g1[i]!='\0';i++){
			a=g1[i];
			if(a=='A'){
				As++;
			}
			else{
				Bs++;
			}
		}
		if(As>Bs){
			As++;
		}
		else{
			Bs++;
		}
		cout<<As<<" "<<Bs<<endl;
		As=0;
		Bs=0;
}

return 0;
}

Measured memory_bytes: 1140
import math
import sys
input = sys.stdin.readline

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def main():
  n = original_n = int(input().strip())
  factored = factorization(n)
  result = 0

  if n == 1:
    print("0")
    sys.exit()

  for i, count in factored:
    diff = 1
    while count > 0:
      count -= diff
      if count >= 0:
        result += 1
        diff += 1

  print(result)

main()


Measured memory_bytes: 63544
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (A, B): (i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    let ans = if (A + B) % 2 == 0 { ((A + B) / 2).to_string() } else { "IMPOSSIBLE".to_string() };

    println!("{}", ans);
}


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

int a[200010];
int sum[400010];

int main () {
	int n, k; scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int _ = 0; _ < k; _++) {
		memset(sum, 0, sizeof(sum));
		for (int i = 0; i < n; i++) {
			sum[max(0, i - a[i])]++;
			sum[i + a[i] + 1]--;
		}
		int minj = 0x3f3f3f3f;
		for (int i = 0; i < n; i++) {
			if (i) sum[i] += sum[i - 1];
			a[i] = sum[i];
			minj = min(minj, a[i]);
		}
		if (minj == n) break;
	}
	for (int i = 0; i < n; i++) {
		printf("%d ", a[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 6148
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int main()
{
    int N;
    int A[100];

    cin >> N;
    rep(i, N) cin >> A[i];

    int ans = 0;
    rep(i, N) {
        reep(j, i+1, N) ans = max(ans, abs(A[i] - A[j]));
    }
    cout << ans << endl;
}


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

signed main() {
  int n,m;
  cin >> n >> m;
  if(n == m) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3604
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		double a = x.nextDouble();
		double b = 2 * a * Math.PI;
		double c = a * a * Math.PI;
		System.out.printf("%.6f %.6f",c ,b);
		
		
	}

}

Measured memory_bytes: 18872
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    bool cnt = false;
    int ret = 0;
    for(int i = 0;i < N - 1;i++) {
        if(cnt == true) {
            cnt = false;
            continue;
        }
        if((S.at(i) == 'O' && S.at(i + 1) == 'X') || (S.at(i) == 'X' && S.at(i + 1) == 'O')) {
            ret++;
            cnt = true;
        }
    }
    cout << ret << endl;
}


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

int main() {
  int r,d,x,ans;
  cin >> r >> d >> x;
  rep(i,10){
    x = r*x-d;
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 256