akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//  C - Count Order
//
//  Created by Hashizo on 2020/01/10.
//  Copyright © 2020 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())


vector<ll> p(8);
vector<ll> q(8);
ll n;
ll cnt = 0;
ll pCnt = 0;
ll qCnt = 0;


void foreach_permutation(ll n, std::function<void(int *)> f) {
  int indexes[n];
  for (int i = 0; i < n; i++) indexes[i] = i;
  do {
    f(indexes);
  } while (std::next_permutation(indexes, indexes + n));
}

int main(int argc, const char * argv[]) {

	cin >> n;

	REP(i, n) {
		cin >> p[i];
	}

	REP(i, n) {
		cin >> q[i];
	}


	foreach_permutation(n, [](int *indexes) {
		cnt++;
		//std::cout << indexes[0]+1 << ',' << indexes[1]+1 << ',' << indexes[2]+1 << std::endl;

		if(pCnt == 0) {
			REP(i, n) {
				if ((indexes[i]+1) == p[i]) {
					pCnt = cnt;
				}
				else {
					pCnt = 0;
					break;
				}
			}
		}
			
		if(qCnt == 0) {
			REP(i, n) {
				if ((indexes[i]+1) == q[i]) {
					qCnt = cnt;
				}
				else {
					qCnt = 0;
					break;
				}
			}
		}
	});
	
	cout << abs(pCnt-qCnt) << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

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

    int res = 0;
    for (int i = 0; i <= 26; i++) {
        for (int j = 0; j <= 16; j++) {
            if(i*4 + j*7 == n) {
                cout << "Yes" << endl;
                return 0;
            } 
        }
    }

    cout << "No" << endl;
    return 0;
}




Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.conv;
import std.numeric;
import std.math;
import std.string;

void main()
{
	auto tokens = split(chomp(readln()));
	int n = to!int(tokens[0]);
	int m = to!int(tokens[1]);
	int[][] nodes;
	int[][] edges;
	nodes.length = n;
	foreach (i; 0..m)
	{
		auto tokens2 = split(chomp(readln()));
		int a = to!int(tokens2[0]) - 1;
		int b = to!int(tokens2[1]) - 1;
		nodes[a] ~= b;
		nodes[b] ~= a;
		edges    ~= [a, b];
	}

	bool search(int src, int dst, in int[] open, int startPos)
	{
		if (src == dst) return true;
		if (src == startPos) return false;

		foreach (next; nodes[src])
		{
			auto oi = countUntil(open, next);
			if (oi == -1) continue;
			auto r = search(next, dst, remove(open.dup, oi), startPos);
			if (r) return true;
		}
		return false;
	}

	int result = m;
	int[] open;
	foreach (i; 0..n) open ~= i;
	foreach (edge; edges)
	{
		foreach (next; nodes[edge[0]])
		{
			if (next == edge[1]) continue;
			auto r = search(next, edge[1], open, edge[0]);
			if (r)
			{
				--result;
				break;
			}
		}
	}
	
	writeln(result);
	stdout.flush();
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll merge(ll x,ll y){
    if(x>=y) return x+1;
    else return y;
}
ll add_root(ll x){
    return x+1;
}
vec G[200001],dp(200001);
void dfs(int v,int p=-1){
    if(p!=-1&&G[v].size()==1){
        dp[v]=0;
        return;
    }
    ll ans=-1;
    vec A;
    for(auto i:G[v]){
        if(i==p) continue;
        dfs(i,v);
        A.push_back(dp[i]);
    }
    sort(all(A));
    for(auto i:A) ans=merge(ans,i);
    dp[v]=add_root(ans);
}
int main(){
    int n,a;
    cin>>n;
    rep(i,n-1) cin>>a,G[a].push_back(i+2),G[i+2].push_back(a);
    dfs(1);
    cout<<dp[1]<<"\n";
}

Measured memory_bytes: 18944
import java.util.Scanner;
 
public class Main {
	
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if(a <= 8 && b <= 8){
			System.out.println("Yay!");
		}else{			
			System.out.println(":(");
		}
	}
 
}

Measured memory_bytes: 23636
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int n;
	cin>>n;
	int a[105];
	for(int i=0;i<n;i++)
	 cin>>a[i];
	sort(a,a+n,cmp);
	int asum=0,bsum=0;
	for(int i=0;i<n;i++)
	{
		if(i%2==0)asum=asum+a[i];
		else bsum=bsum+a[i];
	}
	cout<<asum-bsum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,k;
  cin >> n >> k;
  ll ans=0;
  REP(b,1,n+1) {
    ll x=max(0LL,b-k);
    ans+=(ll)(n/b)*x;
    ll y=n%b;
    ans+=max(0LL,y-max(0LL,k-1));
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, M; cin >> N >> M;
	vector<int> a(N, 0), b(N, 0);
	rep (i, N){
		cin >> a[i] >> b[i];
	} // end rep
	vector<int> c(M, 0), d(M, 0);
	rep (i, M){
		cin >> c[i] >> d[i];
	} // end rep

	map<int,int> cp; cp.clear();

	rep (i, N){
		int cand = -1;
		int maxL = (int)1e9;
		rep (j, M){
			int curr = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (curr < maxL){
				maxL = curr;
				cand = j;
			} // end if
		} // end rep
		cp[i+1] = cand + 1;
	} // end rep

	rep (i, N){
		cout << cp[i+1] << endl;
	} // end rep
		
	return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  
  if(a+b == c){
    cout <<"Yes"<<endl;
  }
  else if(b+c == a){
    cout <<"Yes"<<endl;
  }
  else if(a+c == b){
    cout <<"Yes"<<endl;
  }
  else{
    cout <<"No"<<endl;
  }
}

Measured memory_bytes: 256
d,n=map(int,input().split())
if d==0:
    if n==100:
        print(101*1)
    else:
        print(int(n*1))
elif d==1:
    if n==100:
        print(101*100)
    else:
        print(int(n*100))
elif d==2:
    if n==100:
        print(101*10000)
    else:
        print(int(n*10000))


Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)

















int main(){
    string s;
    cin >> s;
    ll cnt = 0;
    REP(i, s.size()){
        if(s[i] == 'o') cnt++;
    }
    cout << ((cnt + 15 - s.size() >= 8)? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
import Data.Functor( (<$>))

main = do
    s <- getLine
    p@(h:_) <- getLine
    let
	verify 0 _ = False
	verify n str@(c:cs)
	    | and $ zipWith (==) p str	= True
	    | otherwise			= verify (n-1) (cs++[c])

    putStrLn $ if verify (length s) s
		    then "Yes"
		    else "No"



Measured memory_bytes: 3848
import scala.collection.mutable
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val Array(n, m, s, t) = readLine.trim.split(' ').map(_.toInt)
  val edges = Array.tabulate(n){_ ⇒ Nil: List[(Int, Int)]}
  for (_ ← 0 until m){
    val Array(a, b, c, d) = readLine.trim.split(' ').map(_.toInt)
    edges(a - 1) ::= (b - 1, d)
    edges(a - 1) ::= (c - 1, d)
    edges(b - 1) ::= (a - 1, d)
    edges(b - 1) ::= (c - 1, d)
    edges(c - 1) ::= (a - 1, d)
    edges(c - 1) ::= (b - 1, d)
  }
  val queue = mutable.PriorityQueue()(Ordering.by[(Int, Long), Long](_._2).reverse).also{_.enqueue((s - 1, 0L))}
  val minMemo = Array.tabulate(n){_ ⇒ Long.MaxValue}.also{_(s - 1) = 0L }
  while (queue.head._1 != t - 1){
    val (top, distance) = queue.dequeue()
    if (minMemo(top) == distance) {
      for ((to, diff) ← edges(top)) {
        if (minMemo(to) > distance + diff) {
          minMemo(to) = distance + diff
          queue.enqueue((to, minMemo(to)))
        }
      }
    }
  }
  println(
    queue.head._2
  )
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 481116
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  int n,m;
  cin >> n >> m;
  int* count = new int[30];
  for(int i=0;i<m;i++) count[i] = 0;

  for(int i=0;i<n;i++){
    int k;
    cin >> k;
    for(int j=0;j<k;j++){
      int l;
      cin >> l;
      count[l-1]++;
    }
  }
  int ans = 0;
  for(int i=0;i<m;i++) if(count[i] == n) ans ++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n-1):
	if a[i]+1 == a[i+1]:
		ans += c[a[i]-1]

ans += sum(b)

print(ans)


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN



int main(void){
	ll N,ST[200001],a,min=LLONG_MAX;
	ST[0]=0;
	cin>>N;
	rep(i,N){
		cin>>a;
		ST[i+1]=ST[i]+a;
	}
	reg(i,1,N-1){
		if(abs(ST[N]-ST[i]*2)<min)min=abs(ST[N]-ST[i]*2);
	}
	cout<<min<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int main(void)
{
    double r;
    cin >> r;
    
    r *= (MATHPI *2);
    
    
    cout << r;
    
    
   
    
}

Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll x, y;std::cin >> x >> y;
  std::cout << (abs(x-y)<=1?"Brown":"Alice") << '\n';
  return 0;
}


Measured memory_bytes: 256
S = input()
S = S[::-1]

divide = ["dream", "dreamer", "erase", "eraser"]

for i, r in enumerate(divide):
    divide[i] = r[::-1]


i = 0
while i < len(S):
    can2 = False
    for j in range(4):
        d = divide[j]
        d_size = len(d)
        if S[i:d_size + i] == d:
            can2 = True
            i += d_size
    if can2 == False:
        break

if can2:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3188
N, K = list(map(int, input().split()))
h = [int(input()) for i in range(N)]

h.sort()
ans = 100000000000000000000

for i in range(N - K + 1):
    diff = h[i + K - 1] - h[i]
    if diff < ans:
        ans = diff

print(ans)


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

int main(){
   int N;
   cin >> N;
   if(N%10 == 3) cout << "bon" << endl;
   else if(N%10 == 0 ||N%10 == 1||N%10 == 6||N%10 == 8) cout << "pon" << endl;
   else cout << "hon" << endl; 
}

Measured memory_bytes: 3632
s = int(input())

if s == 1 or s == 2:
    print(4)
else:
    for i in range(1000000):
        if s == 4:
            print(i + 4)
            break

            
        if s % 2 == 0:
            s = s / 2
        else:
            s = 3 * s + 1
        
    







        



Measured memory_bytes: 2940
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
  int n;
  vector<int> data;
  cin >> n;
  data.resize(n*2);
  for (int i = 0; i < n*2; ++i) {
    cin >> data[i];
  }
  sort(data.begin(), data.end());
  int ans = 0;
  for (int i = 0; i < n*2; i+=2) {
    ans += data[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import math
import numpy as np
def input():
    return sys.stdin.readline().rstrip()
def dist(y, z, d):
    ret = 0.0
    for i in range(d):
        ret += pow(y[i] - z[i], 2)
    return pow(ret, 0.5)
def main():
    n, d = [int(e) for e in input().split()]
    x = [[int(e) for e in input().split()] for _ in range(n)]
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            dist_yz = dist(x[i], x[j], d)
            if math.ceil(dist_yz) == math.floor(dist_yz):
                ans += 1
    print(ans)
main()

Measured memory_bytes: 12344
n, k = map(int, input().split())
lp = list(map(int, input().split()))

le = [(p + 1) / 2 for p in lp]

e = sum(le[:k])
m = e
for i in range(n - k):
    e -= le[i]
    e += le[k + i]
    m = max(m, e)

print(m)


Measured memory_bytes: 32204
public class Hello{
    public static void Main(){
        for(int x=1; 2*x<19; x=x+1) 
        {
            for(int y=1; 2*y<19; y=y+1)
            {
                System.Console.WriteLine(x+"x"+y+""+"="+x*y);
            }
        }
    }
}


Measured memory_bytes: 15804
#include <cstdio>
#include <cmath>

int main(void) {
    double x = 0, y = 0, c = 0;
    int a, b;
    while (true) {
        scanf("%d,%d", &a, &b);
        if (a == 0 && b == 0) break;
        x += a * sin(c);
        y += a * cos(c);
        c += (b / 180.0) * M_PI;
    }
    printf("%d\n%d\n", (int)x, (int)y);
    return 0;
}

Measured memory_bytes: 1032
// Shift-JIS（シフトジス）

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

int main()
{
    int N;
    cin >> N;
    long long A, B;
    vector<pair<long long, long long>> pairs(N);

    for (int i = 0; i < N; i++)
    {
        cin >> A >> B;
        pairs[i] = make_pair(B, A);
    }

    sort(pairs.begin(), pairs.end());

    long long T = 0;
    bool flag = true;

    for (int i = 0; i < N; i++)
    {
        B = pairs[i].first;
        A = pairs[i].second;
        T += A;
        if (T > B)
        {
            flag = false;
            break;
        }
    }

    if (flag)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3328
/// Kazuki Hoshino


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define endl '\n'

int n, m, x[55], y[55], ans;
vi adj[555];
bool forbid[55][55], vis[555];


void dfs(int s){

    if(vis[s])return;
    vis[s]=true;
    for(auto t: adj[s]){
        if(forbid[s][t])dfs(t);
    }

}

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

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


cin >> n >> m;

rep(i, 1, m){
cin >> x[i] >> y[i];
adj[x[i]].pb(y[i]);
adj[y[i]].pb(x[i]);
forbid[x[i]][y[i]]=true;
forbid[y[i]][x[i]]=true;
}


rep(i, 1, m){

    forbid[x[i]][y[i]]=false;
    forbid[y[i]][x[i]]=false;

    rep(j, 1, n){
    vis[j]=false;
    }

    dfs(1);

    rep(j,1,n){
    if(!vis[j]){
        ans++;
        break;
    }
    }

    forbid[x[i]][y[i]]=true;
    forbid[y[i]][x[i]]=true;

}


cout << ans << endl;




return 0;}
///....


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

typedef long double ld;									// XD
#define int long long
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int>
#define vii vector< ii >
#define F first
#define S second
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
#define mem(a,x) memset(a,x,sizeof(a))   
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
typedef tree<int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;  

inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int mod = 998244353ll;
const int inf = 1e18;
const int maxn = 2e5+5;
int dp[maxn], pf[maxn];
void solve(){
	int n, k; cin>>n>>k;
	int a[k], b[k];
	rep(i, 0, k) cin>>a[i]>>b[i];
	dp[1] = 1, pf[1] = 1;
	rep1(j, 2, n){

		rep(i, 0, k){
			int l = max(j-b[i]-1, 0ll);
			int r = max(j-a[i], 0ll);
		//	cout<<l<<" "<<r<<"\n";
			dp[j] += (pf[r] - pf[l] + mod)%mod;
		}
		dp[j] = dp[j]%mod;
		pf[j] = (dp[j] + pf[j-1])%mod;
	}
	cout<<dp[n];
}

signed main() 
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //io();
    //cout<<setprecision(16);
    int tc=1; //cin>>tc; 
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}



Measured memory_bytes: 6764
S=input()
T=input()
dp=[[0 for j in range(len(T)+1)] for i in range(len(S)+1)]
for i in range(len(S)):
    for j in range(len(T)):
        if S[i]==T[j]:
            dp[i+1][j+1]=dp[i][j]+1
        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j])
        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1])
i=len(S)
j=len(T)
ans=""
while i>0 and j>0:
    if dp[i][j]==dp[i-1][j]:
        i-=1
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    else:
        ans=S[i-1]+ans
        i-=1
        j-=1
print(ans)

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

int main() {

	int s[4] = {};
	rep(i, 3){
		int a, b;
		cin >> a >> b;
		s[a-1]++;
		s[b-1]++;
	}
	sort(s, s+4);
	if(s[0] == 1 && s[1] == 1 && s[2] == 2 && s[3] == 2){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = mutableListOf<Long>()
    val b = mutableListOf<Long>()
    (1..n).forEach { _ ->
        val (x, y) = readLine()!!.split(" ").map { it.toLong() }
        a.add(x); b.add(y)
    }
    a.sort(); b.sort()
    if(n%2 == 0){
        val l = n/2-1; val r = n/2
        println(b[r]+b[l]-a[r]-a[l]+1)
    }else{
        val m = (n-1)/2
        println(b[m]-a[m]+1)
    }
}

Measured memory_bytes: 74716
#include<bits/stdc++.h>
// */
using namespace std;
#define int long
signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(auto& i:a)cin>>i;
  sort(a.begin(),a.end(),greater<>());
  map<int,int> m;
  int s=0;
  for(int i=0;i<n;++i){
    ++m[a[i]];
    if(m[a[i]]>1){
      if(s)return cout<<s*a[i],0;
      m[s=a[i]]=0;
    }
  }
  cout<<0;
}

Measured memory_bytes: 6272
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)

cnt = 0
flg = 1
while flg == 1
	flg = 0
	(1..n-1).reverse_each do |j|
		if a[j] < a[j-1]
			a[j],a[j-1] = a[j-1],a[j]
			flg = 1
			cnt+=1
		end
	end
end

puts a.join(" ")
puts cnt

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

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

    vector<int> A(3);
    REP(i, 3) cin >> A[i];

    sort(A.begin(), A.end());

    int a, b;
    a = A[2] - A[1];
    b = A[2] - A[0];

    int ans = 0;
    if(a % 2 == b % 2){
        ans = (a + b) / 2;
    }else{
        ans = 1 + (a + b + 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  long long int m =1000;
  long long int s =0;
  for(int i=0;i<n-1;i++){
    if(a.at(i+1)>a.at(i)){
      s=m/a.at(i);
      m%=a.at(i);
      m+=s*a.at(i+1);
    }
  }
  cout << m << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn = 1e5+10;
int main()
{
    long long int n;
    while(~scanf("%lld",&n))
    {
        long long int num=0;
        if(n==3)
        {
            printf("3\n");
            continue;
        }
        for(long long int i=1;i<=(long long int)sqrt(n);i++)
        {
            if(i*i==n)break;
            num+=1LL;
            long long int x=n/i;
            if(n%i==0)
            {
                x--;
            }
            //cout<<x<<endl;
            x-=i;
            num+=x*2;
        }
        printf("%lld\n",num);
    }
    return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
 
#define mem(dp,a)       memset(dp,a,sizeof dp)
#define ninja           ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb(x)           push_back(x)
#define mp(x,y)         make_pair(x,y)
#define all(c)          c.begin(), c.end()
#define ff              first
#define ss              second
#define nl              '\n'
#define inf             1e9+7
 
int main()
{
	ninja
	int t; //cin>>t;
	t=1;
	while(t--)
	{
		vector<int> a(3);
		cin>>a[0]>>a[1]>>a[2];
		sort(all(a));
		cout<<a[0]+a[1];
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
// #define mod 998244353
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	vector<ll> count(2019);
	count[0] = 1;
	int cur = 0;
	ll ans = 0;
	ll temp = 1;
	for(int i = s.length() - 1; i >= 0; i--){
		char c = s[i];
		cur += temp * (c - '0');
		cur %= 2019;
		ans += count[cur];
		count[cur]++;
		// cout<<cur<<" "<<count[cur]<<endl;
		temp *= 10;
		temp %= 2019;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3748
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL)x=x->right;
  return x;
}

Node treeSearch(Node u,int x){
  while(u!= NIL && x != u->key){
    if(x < u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  if(x->right != NIL)return treeMinimum(x->right);
  Node y = x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y;
  Node x;
  if(z->left == NIL || z->right == NIL)y=z;
  else y= treeSuccessor(z);
  if(y->left != NIL)x=y->left;
  else x=y->right;
  if(x!=NIL)x->parent=y->parent;
  if(y->parent==NIL)root=x;
  else{
    if(y==y->parent->left)y->parent->left=x;
    else y->parent->right=x;
  }
  if(y!=z)z->key=y->key;
  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else {
    if(z->key < y->key)y->left=z;
    else y->right=z;
  }
}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char c[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", c);
    if(c[0]=='f'){
      scanf("%d",&x);
      Node t = treeSearch(root,x);
      if(t!=NIL)printf("yes\n");
      else printf("no\n");
    }
    else if ( c[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( c[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if(c[0]== 'd'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
    else;
  }

  return 0;
}



Measured memory_bytes: 20472
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
 
	ll x, y, z;

    cin >> x >> y;
    if (x % y == 0) {
        cout << -1 << endl;
        return 0;
    }

    z = x;
    while (z % y == 0)
        z += x;
    cout << x << endl;
 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

const int MAX = 5050;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

int N, K;
bool dp[MAX][MAX];
vector <int> v;

bool check(int x) {
    int n = (int)v.size();
    memset(dp, false, sizeof(dp));
    dp[0][0] = true;
    rep(n, i) rep(K, j) {
        dp[i+1][j] = dp[i][j] || dp[i+1][j];
        if (j+v[i] < K && dp[i][j] && x != i) dp[i+1][j+v[i]] = true;
    }
    /*
    cout << "x = " << x << endl;
    rep(n+1, i) {
        rep(K+1, j) cout << dp[i][j] << ' ';
        cout << endl;
    }*/
    rep(K, j) if (dp[n][j] && j + v[x] >= K) return true;
    return false;
}

void solve(void){
    cin >> N >> K;
    rep(N, i) {
        int d; cin >> d;
        if (d < K) {
            v.pb(d);
        }
    }
    sort(all(v));
    int ok = (int)v.size(), ng = -1;
    while(abs(ok-ng)>1) {
        int mid = (ok + ng) / 2;
        if (check(mid)) ok = mid;
        else ng = mid;
    }
    cout << ng+1 << endl;
}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}


Measured memory_bytes: 25216
#include "iostream"
using namespace std;

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	while (true) {
		if (a + 1 == b)
			a--;
		else 
			a++;
		if (a == 0) {
			cout << "Borys" << endl;
			return 0;
		}
		if (b - 1 == a)
			b++;
		else
			b--;
		if (b == n + 1) {
			cout << "Alice" << endl;
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int pp[100][100];
void init(){
	for(int i=0;i<100;i++){
		for(int j=0;j<100;j++){
			pp[i][j]=0;
		}
	}
}
int main(){
	int a;
	int b;
	scanf("%d%d",&a,&b);
	int h=100,w=100;
	int num0=1,num1=0;
	printf("%d %d\n",h,w);
	int bx=0,by=0;
	while(num0<a){
		//pp[bx][by]=0;
		if(bx==0 && by==0)num1=1;
		pp[bx+1][by+1]=1;
		pp[bx+1][by]=1;
		pp[bx][by+1]=1;
		bx+=2;
		if(bx>99){
			bx=0;
			by+=2;
		}
		num0++;
	}
	int wx=99,wy=99;
	while(num1<b){
		pp[wx][wy]=1;
		wx-=2;
		if(wx<0){
			wx=99;
			wy-=2;
		}
		num1++;
	}
	for(int i=0;i<100;i++){
		for(int j=0;j<100;j++){
			printf(pp[i][j]?"#":".");
		}puts("");
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define has(c,i) 		((c).find(i) != end(c))
#define UNIQUE(v)       sort(all(v));v.erase(unique(all(v)),v.end());
#define has_str(s, c)	((s).find(c) != string::npos)
typedef long long ll;
int main() {
#ifdef online_judge
    freopen("input.txt", "wt", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n, x, t;
    cin >> n >> x >> t;
    if(n % x == 0)
        cout << n / x * t;
    else
        cout << (n / x + 1) * t;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n,maxi=0, x, cnt = 0;
	cin >> n;
	rep(i, n){
		cin >> x;
      	if(maxi <= x) {
        	maxi = x;
          	cnt++;
        }
	}
	cout << cnt << endl;
	
}

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

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; }

using ll = long long;

const int INF = 1<<30;
int dp[10050];
bool memo[10050];
int s;
int f(const vector<vector<int>> &v, int x){
  if(memo[x])return dp[x];
  else {
    memo[x] = true;
    for(int i = 0;i < s;i++) {
      if(x>=v.at(i).at(0)) chmin(dp[x], v.at(i).at(1)+f(v,x-v.at(i).at(0)));
      else if(x<v.at(i).at(0)) chmin(dp[x], v.at(i).at(1));
    }
    return dp[x];
  }
}

int main() {
  int N, H;
  cin >> H >> N;
  s=N;
  vector<vector<int>> v(N,vector<int>(2));
  for(int i = 0;i < N; i++) {
    cin>>v.at(i).at(0) >> v.at(i).at(1);
  }
  for(int i = 0; i< 10050; i++) {
    if(i==0)dp[i]=0;
    else dp[i]=INF;
  }
  cout << f(v,H) << endl;
}

Measured memory_bytes: 1024
n = int(input())

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

count = 0
trial = factorization(n)
for i in range(len(trial)):
    p = 1
    while trial[i][1] > 0:
        trial[i][1] -= p
        p += 1
        if trial[i][1] >= 0:
            count += 1

if n == 1:
    print(0)
else:
    print(count)


Measured memory_bytes: 9520
# -*- coding: utf-8 -*-
# 標準入力を取得
N = int(input())

def g(N: int) -> int:
    return int(N * (N + 1) / 2)

# 求解処理
ans = 0
for n in range(1, N + 1):
    ans += n * g(N // n)
            
# 結果出力
print(ans)

Measured memory_bytes: 9172
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
using namespace std;

int main(){
    int x,a,b;
    cin>>x>>a>>b;
    cout<<(x-a)%b<<endl;
}   





Measured memory_bytes: 256
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

n = inp[0]
a = inp
b = inp
c = inp
ans = 0
mae = -9
a.each do |i|
  ans += b[i-1]
  if(i-1 == mae+1)
    ans += c[mae]
  end
  mae = i-1
end
p ans

Measured memory_bytes: 1788
#include <stdio.h>
int main () {
  int h, w, i, j, k, l, temp;
  char s[51][51];
  char t[51][51];
  scanf ("%d%d", &h, &w);
  for (i = 0; i < h; ++i) {
    scanf ("%s", s[i]);
  }
  for (i = 0; i < h; ++i) {
    for (j = 0; j < w; ++j) {
      if (s[i][j] == '#') {
        t[i][j] = s[i][j];
      } else {
        temp = 0;
        for (k = i-1; k < i+2; ++k) {
          if (k == -1 || k == h) {
            continue;
          } else {
            for (l = j-1; l < j+2; ++l) {
              if (l == -1 || l == w) {
                continue;
              } else {
                if (s[k][l] == '#') {
                  temp += 1;
                }
              }
            }
          }
        }
        t[i][j] = '0' + temp;
      }
    }
  }
  for (i = 0; i < h; ++i) {
    t[i][w] = '\0';
    printf ("%s\n", t[i]);
  }
  return 0;
}

Measured memory_bytes: 1652
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
using namespace std;
char s[80][80];
pair<string,int> t[80][80];
int operator<(pair<string,int>& s,pair<string,int>& t){
  if(0){
  }else if(s.second<t.second){
    return 1;
  }else if(s.second>t.second){
    return 0;
  }else{
    return s.first<t.first;
  }
}
pair<string,int> fi(int x,int y){
  if(t[y][x].second==0){
    if('0'<=s[y][x+1]&&s[y][x+1]<='9'){
      pair<string,int> u=fi(x+1,y);
      if(t[y][x]<u)
	t[y][x]=u;
    }
    if('0'<=s[y+1][x]&&s[y+1][x]<='9'){
      pair<string,int> u=fi(x,y+1);
      if(t[y][x]<u)
	t[y][x]=u;
    }
    t[y][x]=make_pair(s[y][x]+t[y][x].first,t[y][x].second+1);
  }
  return t[y][x];
}
int main(){
  int i,j;
  int w,h;
  while(cin>>w>>h,w||h){
    fill(s[0],s[0]+80*80,0);
    for(i=0;i<h;++i)
      cin>>s[i];
    fill(t[0],t[0]+80*80,make_pair("",0));
    pair<string,int> mx=make_pair("",0);
    for(i=0;i<h;++i){
      for(j=0;j<w;++j){
	if('1'<=s[i][j]&&s[i][j]<='9'){
	  pair<string,int> u=fi(j,i);
	  if(mx<u)
	    mx=u;
	}
      }
    }
    cout<<mx.first<<endl;
  }
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> v(N);
    map<int, int> ma0, ma1;
    rep(i, N) {
        cin >> v[i];
        if (i % 2 == 0)
            ma0[v[i]]++;
        else
            ma1[v[i]]++;
    }

    vector<pair<int, int>> cnt0, cnt1;

    for (auto m : ma0) {
        cnt0.push_back({m.second, m.first});
    }

    for (auto m : ma1) {
        cnt1.push_back({m.second, m.first});
    }

    sort(all(cnt0), greater<pair<int, int>>());
    sort(all(cnt1), greater<pair<int, int>>());

    int ans;
    if (cnt0[0].second != cnt1[0].second)
        ans = N - (cnt0[0].first + cnt1[0].first);
    else if (cnt0.size() >= 2 && cnt1.size() >= 2) {
        if (cnt0[1].first >= cnt1[1].first)
            ans = N - (cnt0[1].first + cnt1[0].first);
        else
            ans = N - (cnt0[0].first + cnt1[1].first);
    } else if (cnt0.size() >= 2 && cnt1.size() == 1) {
        ans = N - (cnt0[1].first + cnt1[0].first);
    } else if (cnt0.size() == 1 && cnt1.size() >= 2) {
        ans = N - (cnt0[0].first + cnt1[1].first);
    } else {
        ans = N - (max(cnt0[0].first, cnt1[0].first));
    }

    cout << ans << endl;
}

Measured memory_bytes: 6520
#include <stdio.h>

#define PI 3.141592653589793

int main()
{
    double r;
    double S;            /* 面積 */
    double l;            /* 演習 */

    scanf("%lf", &r);

    S = PI * r * r;
    l = 2.0 * PI * r; 

    printf("%lf %lf\n", S, l);

}


Measured memory_bytes: 2140
#pragma region Template
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <stack>
#include <set>
#include <algorithm>
#include <bitset>
#include <functional>
#include <ctime>
#include <cassert>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <complex>
#pragma comment(linker, "/STACK:167772160")

using namespace std;
#define mp make_pair
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define print_var(x) cerr << #x << " : " << (x) << endl
#define print_array(arr, len) {cerr << #arr << " : "; for(int i = 0; i < len; ++i) cerr << arr[i] << ' '; cerr << endl;}
#define print_2d_array(arr, len1, len2) {cerr << #arr << endl; for(int i = 0; i < len1; ++i, cerr << endl) for(int j = 0; j < len2; ++j) cerr << arr[i][j] << ' ';}
#define print_iterable(i) {cerr << #i << " : "; for(auto e : i) cerr << e << ' '; cerr << endl;}
#define print_new_line() cerr << endl
#else
#define eprintf(...) (void)0
#define print_var(x) (void)0
#define print_array(arr, len) {}
#define print_2d_array(arr, len1, len2) {}
#define print_iterable(i) {}
#define print_new_line() (void)0
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int INF = 1e9 + 10;
const ll LINF = ll(2e18) + 10;
const double PI = acosl(-1);
const double eps = 1e-8;
const ld EPS = 1e-11;
#pragma endregion

const int N = 1e5 + 10;
char s[N], t[N];
int n;
char an[256];

bool check()
{
	for (int i = 1; i < n; ++i)
		if (t[i] == 'S' && s[i] == 'o' || t[i] == 'W' && s[i] == 'x')
			t[i + 1] = t[i - 1];
		else
			t[i + 1] = an[t[i - 1]];
	if (t[n] != t[0])
		return false;
	if (t[0] == 'S' && s[0] == 'o' || t[0] == 'W' && s[0] == 'x')
	{
		if (t[1] != t[n - 1])
			return false;
	}
	else if (t[1] == t[n - 1])
		return false;
	t[n] = 0;
	return true;
}

void solve()
{
	scanf("%d%s", &n, s);
	an['S'] = 'W';
	an['W'] = 'S';
	for(auto c1 : {'W', 'S'})
		for(auto c2 : {'W', 'S'})
		{
			t[0] = c1;
			t[1] = c2;
			if (check())
			{
				puts(t);
				return;
			}
		}
	puts("-1");
}

int main()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#ifdef NOERR
	freopen("err.txt", "w", stderr);
#endif
#else
	//freopen("alter.in", "r", stdin);
	//freopen("alter.out", "w", stdout);
#endif

#ifdef ST
	while(true)
		solve();
#endif
#ifdef CASES
#define MULTITEST
#endif
#ifdef MULTITEST
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; ++i)
	{
#ifdef CASES
		printf("Case #%d: ", i + 1);
#endif
		solve();
#ifdef CASES
		//eprintf("Passed case #%d:\n", i + 1);
#endif
	}
#else
		solve();
#endif

	eprintf("\n\nTime: %.3lf", double(clock()) / CLOCKS_PER_SEC);
}

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

int main() {
    string s;
    cin >> s;
    string words[4] = {"dream","dreamer","erase","eraser"};
    reverse(s.begin(),s.end());
    for(int i=0;i<4;i++)reverse(words[i].begin(),words[i].end());

    bool devided = false;
    for(int i=0;i<s.size();){
        for(int j=0;j<4;j++){
            string d=words[j];
            if(s.substr(i,d.size())==d){
                i+=d.size();
                devided = true;
                break;
            }
        }
        if(!devided){
            cout << "NO" << endl;
            return 0;
        }
        devided = false;
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 512
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s[] = sc.next().split("");
    String t[] = sc.next().split("");
    int ans = 0;
    for (int i = 0; i < s.length; i++){
      if (!(s[i].equals(t[i]))) ans++;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 67628
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
int cnt[2][105];
int h, w;
bool flag[110][110];

int main() {
	int w, h, n;
	cin >> w >> h >> n;
	vector<int>x(n), y(n), a(n);
	rep(i, n) {
		cin >> x[i] >> y[i] >> a[i];
		if (a[i] == 1) {
			for (int j = 0;j <= x[i];++j) {
				for (int k = 1;k <= h;++k) {
					flag[j][k] = true;
				}
			}
		}
		else if (a[i] == 2) {
			for (int j = x[i]+1;j <= w;++j) {
				for (int k = 1;k <= h;++k) {
					flag[j][k] = true;
				}
			}
		}
		else if (a[i] == 3) {
			for (int j = 1;j <= w;++j) {
				for (int k = 0;k <= y[i];++k) {
					flag[j][k] = true;
				}
			}
		}
		else {
			for (int j = 1;j <= w;++j) {
				for (int k = y[i]+1;k <= h;++k) {
					flag[j][k] = true;
				}
			}
		}
	}
	int ans = 0;
	for (int i = 1;i <= w;++i) {
		for (int j = 1;j <= h;++j) {
			if (flag[i][j] == false)ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


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


int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  int ans=10000000;
  int x=0;
  rep(i,n)cin>>vec.at(i);
  
  for(int i=1;i<=100;i++){
    rep(j,n){
      x+=(i-vec.at(j))*(i-vec.at(j));
      }  
    ans=min(ans,x);
    x=0;
  }  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int D;
  cin >> D;
  if(D==25)
    cout << "Christmas" << endl;
  else if(D==24)
    cout << "Christmas Eve" << endl;
  else if(D==23)
    cout << "Christmas Eve Eve" << endl;
  else
    cout << "Christmas Eve Eve Eve" << endl;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    double ave;
    double sum = 0;
    int p;
    ll ans = 0;
    rep(i, n)
    {
        cin >> a[i];
        sum += a[i];
    }
    ave = sum / n;
    p = round(ave);
    rep(i, n)
    {
        ans += pow(p - a[i], 2);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	 static class Unionfind{
		int[] number;
		
		Unionfind(int n){
			number = new int[n];
			for(int i=0;i<n;i++){
				number[i] = i;
			}
		}
		
		int find(int x){
			if(number[x]==x){
				return x;
			}
			return number[x] = find(number[x]);
		}
		
		void unite(int x,int y){
			if(number[x]==number[y]){
				
			}
			else{
				number[find(x)] = number[find(y)];
			}
		}
		
		void same(int x,int y){
			if(number[find(x)]==number[find(y)]){
				System.out.println("1");
			}
			else{
				System.out.println("0");
			}
		}
	}
	
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int q =stdIn.nextInt();
		Unionfind union = new Unionfind(n);
		
		for(int i=0;i<q;i++){
			int com = stdIn.nextInt();
			int x = stdIn.nextInt();
			int y = stdIn.nextInt();
			if(com==0){
				union.unite(x, y);
			}
			else{
				union.same(x, y);
			}
		}
		
	}
}

Measured memory_bytes: 94816
n = int(input())
f = 0
L = []
for i in range(n):
	a,b = map(int, input().split())
	L.append([a,b])
for i in range(2,n):
	if(L[i-2][0] == L[i-2][1] and L[i-1][0] == L[i-1][1] and L[i][0] == L[i][1]):
		f = 1
		break
if(f):
	print('Yes')
else:
	print('No')

Measured memory_bytes: 62436
#include <stdio.h>

int	main(void)
{
	int	N, X, T;

	scanf("%d %d %d", &N, &X, &T);
	if (N % X)
		printf("%d\n", (N / X + 1) * T);
	else
		printf("%d\n", (N / X) * T);
	return (0);
}


Measured memory_bytes: 1712