akhauriyash/Code-Regression huggingface dataset:
use proconio::*;
use proconio::marker::*;

// k * (k + 1) / 2 == 0 (mod n)
// n % 2 != 0 なら
// k * (k + 1) == 0 (mod n)
// n % 2 == 0 なら
// k * (k + 1) == 0 (mod 2 * n)
// k を約数dで決めうち
// a * d + 1 == 0 (mod n / d)
//
// を満たすaを求める

fn factorize(n: u128) -> Vec<(u128, u128)> {
    let mut f = vec![];
    let mut n = n;
    for i in 2.. {
        if i * i > n {
            break;
        }
        let mut c = 0;
        while n % i == 0 {
            n /= i;
            c += 1;
        }
        if c > 0 {
            f.push((i, c));
        }
    }
    if n > 1 {
        f.push((n, 1));
    }
    f
}

fn gcd(a: u128, b: u128) -> u128 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn mod_pow(r: u128, n: u128, m: u128) -> u128 {
    let mut t = 1;
    let mut s = r;
    let mut n = n;
    while n > 0 {
        if n & 1 == 1 {
            t = t * s % m;
        }
        s = s * s % m;
        n >>= 1;
    }
    t
}

#[fastout]
fn run() {
    input! {
        n: u128,
    }
    let m = if n % 2 == 0 {
        2 * n
    } else {
        n
    };
    let p = factorize(m);
    let mut ans = m;
    for bit in 0..(1 << p.len()) {
        let mut x = 1;
        let mut y = 1;
        let mut z = 1;
        for (i, &(p, a)) in p.iter().enumerate() {
            if bit >> i & 1 == 1 {
                x *= p.pow(a as u32);
            } else {
                y *= p.pow(a as u32);
                z *= (p - 1) * p.pow((a - 1) as u32);
            }
        }
        if y == 1 {
            ans = std::cmp::min(ans, x);
        } else {
            let ix = mod_pow(x, z - 1, y);
            assert!(ix * x % y == 1, "{} {} {}", x, y, x * ix % y);
            let a = ix * (y - 1) % y;
            ans = std::cmp::min(ans, a * x);
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 2208
#include <stdio.h>

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

    scanf("%d", &S);

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

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

    return 0;
}

Measured memory_bytes: 592
s=input()[::-1]
l=len(s)
dp=[[0]*2 for _ in range(l+1)]
for i in range(l):
  dp[i+1][0]=min(dp[i][0]+int(s[i]),dp[i][1]+int(s[i])+1)
  if i!=0:
    dp[i+1][1]=min(dp[i][0]+10-int(s[i]),dp[i][1]+10-(int(s[i])+1))
  else:
    dp[i+1][1]=dp[i][0]+10-int(s[i])
print(min(dp[l][0],dp[l][1]+1))

Measured memory_bytes: 141628
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

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

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

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

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = 1e15;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,c; cin >> n >> c;
    set<int> s;
    vector<pair<int,int>> a(2*n);
    rep(i,0,n){
        int s,t,c; cin >> s >> t >> c;
        a[2*i] = make_pair(s,-c);
        a[2*i+1] = make_pair(t,c);
    }
    sort(all(a));
    int ans = 0;
    map<int,int> m;
    rep(i,0,2*n){
        if(a[i].second<0){
            if(s.end()!=s.find(-a[i].second)){
                m[-a[i].second]++;
                continue;
            }          
            s.insert(-a[i].second);
        }
        else{
            if(m[a[i].second]>0){
                m[a[i].second] = 0;
                continue;
            }
            s.erase(a[i].second);
        }
        int x = s.size();
        debug(x);
        chmax(ans,x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    vector<int> c(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    int sum=0;
    for(int i=0;i<n;i++){
        int r=v[i]-c[i];
        if(r>0){
            sum+=v[i]-c[i];
        }
    }
    
    cout<<sum<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

#define m0(x) memset(x, 0, sizeof(x))
#define fill(x, y) memset(x, y, sizeof(x))

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}

int main(){
    string s, t; cin >> s >> t;
    int ans = 0;
    rep(i, t.size()){
        if (s[i] != t[i]) ans ++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3864
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <functional>
#include <cassert>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

void solve() {
    int n;
    std::string s;
    std::cin >> n >> s;

    std::vector<int> ps(1 << n);
    for (auto& p : ps) std::cin >> p;

    auto tab = vec(n + 1, vec(1 << n, 0));
    for (int i = 0; i < (1 << n); ++i) tab[0][i] = ps[i];

    for (int k = 0; k < n; ++k) {
        for (int i = 0; i + (1 << k) < (1 << n); ++i) {
            int x = tab[k][i],
                y = tab[k][i + (1 << k)];
            if (x > y) std::swap(x, y);

            int win = (s[y - x - 1] == '0' ? x : y);
            tab[k + 1][i] = win;
        }
    }

    std::function<int(int, int, int)>
        dfs = [&](int l, int r, int k) {
            if (k == 0) {
                return (l == 1 ? tab[k][(1 << n) - 1] : tab[k][0]);
            }

            int x, y;
            if (l < r) {
                int rem = (1 << (k - 1)) - l;
                x = dfs(l, rem, k - 1);
                y = tab[k - 1][rem];
            } else {
                x = tab[k - 1][(1 << n) - l];
                y = dfs(l - (1 << (k - 1)), r, k - 1);
            }

            if (x > y) std::swap(x, y);
            return (s[y - x - 1] == '0' ? x : y);
        };

    for (int i = 0; i < (1 << n); ++i) {
        int l = (1 << n) - i,
            r = i;

        std::cout << dfs(l, r, n) << std::endl;
    }
}

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

    solve();

    return 0;
}



Measured memory_bytes: 25012
#include <bits/stdc++.h>
using namespace std;
int N;
int main() {
    cin >> N;
    int cnt = 0;
    int nana = N / 7 + 1;
    int yon = N / 4 + 1;
    int sum = 0;

    for(int i = 0; i <= yon; ++i) {
        sum += i * 4;
        for(int j = nana; j >= 0; --j) {
            sum += j * 7;
            if(sum == N) cnt++;
            sum -= j * 7;
        }
        sum = 0;
    }

    if(cnt > 0) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

ll D, G;
ll p[111], c[111], sum[111];

int main() {
   cin >> D >> G;
   G /= 100;
   rep (i, D) {
      cin >> p[i] >> c[i];
      c[i] /= 100;
      sum[i] = (i+1)*p[i] + c[i];
      // printf("sum[%d]: %lld\n", i, sum[i]);
   }

   ll ans = 1e8;
   for (int mask = 0; mask < (1<<D); mask++) {
      ll score = 0, cnt = 0;

      for (int i = 0; i < D; i++) {
         if (mask & (1<<i)) {
            score += sum[i];
            cnt += p[i];
         }
      }

      if (score >= G) {
         chmin(ans, cnt);
         continue;
      }

      for (int i = D-1; i >= 0; i--) {
         if (mask & (1<<i)) continue;
         for (int j = 0; j < p[i]; j++) {
            score += i + 1;
            cnt++;
            if (score >= G) {
               chmin(ans, cnt);
               break;
            }
         }
      }
   }

   cout << ans << endl;

   return 0;
}

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

int main()
{
  long long INF=1e13;
  
  int n,w;
  cin>>n>>w;
  
  vector<int> weight(n);
  vector<int> value(n);
  int vsum=0;
  for(int i=0;i<n;i++)
  {
    cin>>weight[i]>>value[i];
    vsum+=value[i];
  }
  
  vector<long long> x(vsum+1);
  for(int i=0;i<=vsum;i++)
    x[i]=INF;
  x[0]=0;
  
  for(int i=0;i<n;i++)
  {
    for(int j=vsum;j>=value[i];j--)
      x[j]=min(x[j],x[j-value[i]]+(long long)weight[i]);
  }
  
  for(int j=vsum;j>=0;j--)
  {
    if(x[j]<=w)
    {
      cout<<j<<endl;
      break;
    }
  }
}

Measured memory_bytes: 1024
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n = int(rl())
	A = deque(rli())
	tot = sum(A)
	dp = [[A[i] if i == j else 0 for j in range(n)] for i in range(n)]
	for c in range(1, n):
		for r in range(c-1, -1, -1):
			dp[r][c] = max(A[r] - dp[r+1][c], A[c] - dp[r][c-1])
	print(dp[0][-1])
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 119900
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
const int N= 1e5+5;
int t, n;

int32_t main()
{
	IOS;
 	int sum=0;
 	cin>>n;
	for(int i=1;i<=n;i++){
		if(i%3==0 || i%5==0)
			continue;
		sum+= i;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>                                  
using namespace std;                                 
                                                     
int main(void) {                                     
  int a, b;                                          
  cin >> a >> b;                                     
  int S = a*b;                                       
  int R = 2*(a+b);                                   
  cout << S << " " << R << endl;                     
  return 0;                                          
}                                                    
                                                     
                                                     
                           

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

int main() {
  string n;
  int f = 0;

  cin >> n;

  for(int i = 0; i <= (int)n.size(); ++i){
    if(i < 3){
      if(n[i] == n[i + 1] && n[i] == n[i + 2]){
        ++f;
      }
    }
  }

  if(f > 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main() {
  
  string b;
  cin >> b;
  
  if ( b == "A" )
    cout << "T" << endl;
  
  else if ( b == "T" )
    cout << "A" << endl;
  
  else if ( b == "G" )
    cout << "C" << endl;
  
  else if ( b == "C" )
    cout << "G" << endl;
}

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

int main(int argc, char const *argv[])
{
	int n;
	string s;
	cin>>n>>s;
	int ans=1;
	for (int i = 1; i < n; ++i)
	{
		if (s[i-1]!=s[i])
		{
			++ans;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

#define          IOS                    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define          ll                     long long int
#define          EPS                    10E-10
#define          ull                    unsigned long long int
#define          db                     double
#define          pii                    pair < int, int>
#define          pll                    pair < ll, ll>
#define          MOD                    1000000007
#define          vi                     vector<int>
#define          vl                     vector<ll>
#define          pb                     push_back
#define          sc                     scanf
#define          pf                     printf
#define          scin(x)                scanf("%d",&(x))
#define          scin2(x,y)             scanf("%d %d",&(x),&(y))
#define          scln(x)                scanf("%lld",&(x))
#define          scln2(x,y)             scanf("%lld %lld",&(x),&(y))
#define          min3(a,b,c)            min(a,min(b,c))
#define          min4(a,b,c,d)          min(d,min(a,min(b,c)))
#define          max3(a,b,c)            max(a,max(b,c))
#define          max4(a,b,c,d)          max(d,max(a,max(b,c)))
#define          ms(a,b)                memset(a,b,sizeof(a))
#define          gcd(a, b)              __gcd(a,b)
#define          lcm(a, b)              ((a)*(b)/gcd(a,b))
#define          input                  freopen("input.txt","rt", stdin)
#define          output                 freopen("output.txt","wt", stdout)
#define          PI                     3.141592653589793238462643
#define          rep( i , a , b )       for( i=a ; i<b ; i++)
#define          rev( i , a , b )       for( i=a ; i>=b ; i--)
#define          repx( i ,a,b, x)       for( i=a ; i<b ; i+=x)
#define          RUN_CASE(t,T)          for(__typeof(t) t=1;t<=T;t++)
#define          zero(a)                memset(a,0,sizeof a)
#define          all(v)                 v.begin(),v.end()
#define          get_pos(c,x)           (lower_bound(c.begin(),c.end(),x)-c.begin())
#define          CASEL(t)               printf("Case %d:\n",t)
#define          Unique(X)             (X).erase(unique(all(X)),(X).end())
map<string, ll>month ;
void Month()
{
    month["January"] = 1, month["February"] = 2, month["March"] = 3, month["April"] = 4, month["May"] = 5, month["June"] = 6 ;
    month["July"] = 7, month["August"] = 8, month["September"] = 9, month["October"] = 10, month["November"] = 11, month["December"] = 12 ;
}
ll arr[1000009];
ll arr2[1000000];

int main()
{
    // input;
    // output;
    // cout<<"Case "<<i<<": ";
    IOS;
    ll val1=0,val2=0;
   string s;
   cin>>s;
   for(ll i=0;i<s.size();i++)
   {
       if(s[i]=='+')
       {
          val1++;
       }
       else
       {
           val2++;
       }
   }
    cout<<val1-val2<<endl;



    return 0;
}
/*




*/


Measured memory_bytes: 256
import copy

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)

n,m = ips()
a = []
s = 0
for i in range(m):
    x,y = ips()
    a.append([x,y])
connection = [[] for i in range(n+1)]
for i in range(m):
    [x,y] = a[i]
    connection[x].append(y)
    connection[y].append(x)
for loop in range(50):
    for i in range(1,n+1):
        if len(connection[i]) == 1:
            temp = connection[i][0]
            d = connection[temp].index(i)
            connection[temp].pop(d)
            s+=1
            connection[i].pop(0)
print(s)

Measured memory_bytes: 3444
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string.h>

using namespace std;

int main()
{
	char str[21];
	int tmp;
	cin >> str;
	tmp=strlen(str);
	for (int i = tmp-1; i >=0; i--) {
		cout << str[i];
	}
	cout << "\n";
	return 0;
}

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

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

  int L[N];

  rep(i, N) { cin >> L[i]; }
  sort(L, L + N);

  int count = 0;

  for (int i = 0; i < N - 2; i++) {
    for (int j = i + 1; j < N - 1; j++) {
      int a = L[i];
      int b = L[j];
      for (int k = j + 1; k < N; k++) {
        if (a + b > L[k]) {
          count++;
        } else {
          break;
        }
      }
    }
  }

  cout << count << endl;

  return 0;
}

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

int main(){
    int n;cin>>n;
    int ans=0;
    string s;cin>>s;
    for(int i=0;i<n-2;i++){
        if(s.substr(i,3)=="ABC") ans++;
    }
    cout<<ans<<endl;
}

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

using namespace std;
string S;
int N;
vector<int> rp;
vector<int> gp;
vector<int> bp;
int tr, tg, tb;
int r, g, b;

int main()
{
	cin>>N;
	cin>>S;
	tr = tg = tb = 0;
	for(int i = 0; i < N; ++i)
	{
		if(S[i] == 'R')
			++tr;
		else if(S[i] == 'G')
			++tg;
		else
			++tb;
	}
	ll ans = 0;
	for(int i = 0; i < N; ++i)
	{
			if(S[i] == 'R')
			{
				ans += (ll)(g) * (ll)(tb - b);
				ans += (ll)(b) * (ll)(tg - g);
				for(int j : gp)
				{
						if(2 * i - j < N && S[2*i-j] == 'B')
						{
								--ans;
						}
				}
				for(int j : bp)
				{
						if(2 * i - j < N && S[2*i-j] == 'G')
						{
								--ans;
						}
				}
				rp.push_back(i);
				++r;
			}
			else if(S[i] == 'G')
			{
				ans += (ll)(r) * (ll)(tb - b);
				ans += (ll)(b) * (ll)(tr - r);
				for(int j : rp)
				{
						if(2 * i - j < N && S[2*i-j] == 'B')
						{
								--ans;
						}
				}
				for(int j : bp)
				{
						if(2 * i - j < N && S[2*i-j] == 'R')
						{
								--ans;
						}
				}
				gp.push_back(i);
				++g;
			}
			else
			{
				ans += (ll)(r) * (ll)(tg - g);
				ans += (ll)(g) * (ll)(tr - r);
				for(int j : rp)
				{
						if(2 * i - j < N && S[2*i-j] == 'G')
						{
								--ans;
						}
				}
				for(int j : gp)
				{
						if(2 * i - j < N && S[2*i-j] == 'R')
						{
								--ans;
						}
				}
				bp.push_back(i);
				++b;
			}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3676
N, M = map(int, input().split())

ans = ["x"]*N

if N == 1 and M == 0:
    print(0)
    exit()
    
for i in range(M):
    s,c = map(int, input().split())
    s -= 1
    if N != 1 and s == 0 and c == 0:
        print(-1)
        exit()
    if ans[s] == "x":
        ans[s] = str(c)
    else:
        if ans[s] != str(c):
            print(-1)
            exit()

if ans[0] == "x":
    ans[0] = "1"
for i in range(1,N):
    if ans[i] == "x":
        ans[i] = "0"

ans = "".join(ans)
print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){
    int n;
    string name;
    cin >> n;
    cin >> name;
    int nsize = name.size();
    int cnt = 0;
    while(n--){
        string old;
        cin >> old;
        int osize = old.size();
        bool o_flg = false;
        for(int st = 0; st <= osize; ++st){
            for(int m = 1; m <= 100; ++m){
                bool flg = true;
                for(int i=0; i < nsize; ++i){
                    if( st + i*m >= osize || name[i] != old[st+i*m]) {
                        flg = false;
                        break;
                    }
                }
                if( flg ) { cnt++; o_flg = true; break; }
            }
            if(o_flg) break;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>

using namespace std;
int main(void){
    int n,x,tmp,sum=0,num=0;
    vector<int> array;

    cin >> n >> x;

    for(int i=0;i<n;i++){
        cin >> tmp;
        array.push_back(tmp);
        sum+=tmp;
    }

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

    if(x>=sum){
        num+=n;
        x-=sum;
        if(x>0)num+=x/array.at(0);
    }

    cout << num << endl;
}

Measured memory_bytes: 256
ns=list(map(str,input().split()))
mp={}
for n in ns:
	if n in mp:
		mp[n]=mp[n]+1
	else:
		mp[n]=1
long_word=''
freq_word=''
max_len=0
max_fre=0

for k,v in mp.items():
	if max_len<len(k):
		long_word=k
		max_len=len(k)
	if max_fre<v:
		freq_word=k
		max_fre=v
print(freq_word,long_word)


Measured memory_bytes: 5556
#include <iostream>
#include <string>
#include <set>
#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;

int main(){
	int n,m;
	set<string> sset;
	string red[100],blue[100];
	cin >> n;
	rep(i,n){
		cin >> red[i];
		sset.insert(red[i]);
	}
	cin >> m;
	rep(j,m){
		cin >> blue[j];
		sset.insert(blue[j]);
	}
	int i_max=0;
	for (set<string>::iterator ite=sset.begin();ite!=sset.end();ite++){
		int temp=0;
		rep(i,n)
			if (red[i]==*ite)
				temp++;
		rep(j,m)
			if (blue[j]==*ite)
				temp--;
		i_max = max(temp,i_max);
	}
	cout << i_max << endl;
}

Measured memory_bytes: 256
def solve():
    from sys import stdin
    INF = float('inf')
    input = stdin

    while True:
        N, M = map(int, input.readline().split())
        if N == 0:
            break

        C = tuple(int(input.readline()) for i in range(M))

        # decode table
        tbl_1 = tuple(tuple(255 if i + c > 255 else 0 if i + c < 0
                            else i + c for c in C) for i in range(256))
        # print(tbl_1)
        # tabale of squared difference
        tbl_2 = tuple(tuple((i - j) ** 2 for j in range(256))
                      for i in range(256))
        # print(tbl_2)
        dp1 = [INF] * 256
        dp2 = [INF] * 256
        dp1[128] = 0

        for i in range(N):
            x = int(input.readline())
            tbl_2_x = tbl_2[x]
            for signal, pre_cost in enumerate(dp1):
                for decoded in tbl_1[signal]:
                    new_cost = pre_cost + tbl_2_x[decoded]
                    if new_cost < dp2[decoded]:
                        dp2[decoded] = new_cost
            dp1 = dp2[:]
            dp2 = [INF] * 256
        # print(dp1)
        print(min(dp1))


solve()



Measured memory_bytes: 10904
#include<iostream>
#include <algorithm>
using namespace std;

int n,r,p,c;

int main(){
  while(cin >> n >> r && n!=0 || r!=0){
    int A[n];
    for(int i=0;i<n;i++){
      A[i]=n-i;
    }
    //for (auto e:A) cout << e;
    //cout << "\n";
    for(int i=0;i<r;i++){
      cin >> p >> c;
      rotate(A,A+p-1,A+p-1+c);
    }
    cout << A[0] << endl;
  }
}



Measured memory_bytes: 3120
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

bool ok1, ok2;
int t1, t2;
string s, tmp1, tmp2;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> s;
	tmp1 = s.substr(0, 2); tmp2 = s.substr(2, 2);
	t1 = stoi(tmp1); t2 = stoi(tmp2);
	if (1 <= t2 && t2 <= 12) {
		ok1 = true;
	}
	if (1 <= t1 && t1 <= 12) {
		ok2 = true;
	}
	if (ok1 && ok2) {
		cout << "AMBIGUOUS\n";
	}
	else if (ok1) {
		cout << "YYMM\n";
	}
	else if (ok2) {
		cout << "MMYY\n";
	}
	else {
		cout << "NA\n";
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    string n;
    cin >> n;
    sort(n.begin(),n.end());
    if(n[0]==n[1] && n[2]==n[3] && n[0]!=n[2]){
        cout << "Yes" << endl;
        return 0;
    }
    
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define itn int
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=2e9;
const ll lnf=9e18;

struct unionfind{
  vector<int> par;
  unionfind(int n):par(n,-1){}
  void init(int n){par.assign(n,-1);}
  int root(int x){
    if(par[x]<0) return x;
    else return par[x]=root(par[x]);
  }
  bool issame(int x,int y){
    return root(x)==root(y);
  }
  bool merge(int x,int y){
    x=root(x); y=root(y);
    if(x==y) return false;
    if(par[x]>par[y]) swap(x,y);
    par[x]+=par[y];
    par[y]=x;
    return true;
  }
  int size(int x){
    return -par[root(x)];
  }
};

int main(){
  itn n,m; cin >> n >> m;
  unionfind uf(n);
  rep(i,m){
    itn a,b;
    cin >> a >> b;
    a--; b--;
    uf.merge(a,b);
  }
  ll ans=0;
  rep(i,n){
    chmax(ans,(ll)uf.size(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 4036
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    int n, k;
    cin >> n >> k;

    int i = 1;
    int x = 1;
    while (x * k <= n) {
        i++;
        x *= k;
    }

    cout << i << endl;

    return 0;
}

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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    pair <int,int> a[n];
    pair <int,pair <int,int> > d[2*n];
    int z[2*n];
    map <int,int> h;
    for(int i=0;i<n;++i)
    {
        int x,y;
        cin>>x>>y;
        a[i].first=(x-y);a[i].second=(x+y-1);
        d[i]={x-y,{0,i}};
        d[n+i]={x+y-1,{1,i}};
        z[i]=x-y;z[i+n]=x+y-1;
    }
    sort(d,d+2*n);
    sort(z,z+2*n);
    for(int i=0;i<2*n;++i)
    {
        if(!h.count(z[i]))
        h[z[i]]=i;
    }
    int dp[2*n+1];
    dp[0]=0;
    for(int i=1;i<=2*n;++i)
    {
        /*if(d[i-1].second.first)
        {
            cout<<" close "<<d[i-1].second.second<<endl;
        }
        else
        {
            cout<<" open "<<d[i-1].second.second<<endl;
        }*/
        dp[i]=dp[i-1];
        pair <int,int> z=d[i-1].second;
        if(z.first==1)
        {
            dp[i]=max(dp[i],dp[h[a[z.second].first]]+1);
        }
    }
    cout<<dp[2*n];
    return 0;
}


Measured memory_bytes: 22144
import sys
stdin=sys.stdin

ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()
yp='Yes'
np='No'

s=sp()
t=sp()

l=len(s)

if s[0:l]==t[0:l]:
  print(yp)
else:
  print(np)

Measured memory_bytes: 9052
import random
from copy import deepcopy

d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(d)]

ans = [1]*d

def score(l):
    lastd = [0]*26
    point = 0
    for j,k in enumerate(l):
        kk = k-1
        point += s[j][kk]
        lastd[kk] = j+1
        for l in range(26):
            point -= c[l]*(j+1-lastd[l])
    return point

ma = score(ans)

def random_search():
    global ans
    li = deepcopy(ans)
    D = random.randrange(0,d,1)
    Q = random.randrange(0,26,1)
    li[D] = Q+1
    if score(li) > ma:
        ans = deepcopy(li)

for i in range(1000):
    random_search()

for i in ans:
    print(i)

Measured memory_bytes: 84408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll ac = a*c, ad = a*d;
    ll bc = b*c, bd = b*d;
    ll x[4] = {ac, ad, bc, bd};
    ll res = -LLONG_MIN; 
    for(ll i=0; i<4; ++i){
        res = max(res, x[i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size()
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define forn(i, n) for (int i = 1; i <= n; i++)
#define ford(i, n) for (int i = n; i >= 0; i--)
#define REP(i, a, n) for (int i = a; i < n; i++)
#define foreach(itr, c) for (__typeof((c).begin(), (c).end()) itr = c.begin(); itr != c.end(); itr++)
#define fill(a, b) memset(a, b, sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<char> vs;
typedef vector<pi> vpi;

using namespace std;

int main()
{
    int N;
    int res = -1;
    int t = 0;
    int countRed = 0;
    int moves = 0;

    cin >> N;
    vs c(N);
    bool allRed = true;

    rep(i, N)
    {
        cin >> c[i];

        if (c[i] == 'W')
        {
            allRed = false;
        }
        else
        {
            countRed++;
        }
    }
    if (allRed)
    {
        cout << 0;
        return 0;
    }
    rep(i, countRed)
    {
        if (c[i] == 'W')
        {
            moves++;
        }
    }
    cout << moves;
    return 0;
}

Measured memory_bytes: 3620
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=2050;
int main() {
	int H,W;
	cin>>H>>W;
	string S[SIZE];
	for(int i=0;i<H;i++){
		cin>>S[i];
	}
	int lit[SIZE][SIZE]={};
	int til[SIZE][SIZE]={};
	for(int i=0;i<H;i++){
		int temp=0;
		for(int j=0;j<W;j++){
			if(S[i][j]=='.'){
				temp++;
				lit[i][j]=temp;
			}
			else{
				temp=0;
			}
		}

		temp=0;
		for(int j=W-1;j>=0;j--){
			if(S[i][j]=='.'){
				temp=max(temp,lit[i][j]);
				lit[i][j]=temp;
			}
			else{
				temp=0;
			}
		}
	}

	for(int j=0;j<W;j++){
		int temp=0;
		for(int i=0;i<H;i++){
			if(S[i][j]=='.'){
				temp++;
				til[i][j]=temp;
			}
			else{
				temp=0;
			}
		}
		temp=0;
		for(int i=H-1;i>=0;i--){
			if(S[i][j]=='.'){
				temp=max(temp,til[i][j]);
				til[i][j]=temp;
			}
			else{
				temp=0;
			}
		}
	}

	int ans=0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			ans=max(ans,lit[i][j]+til[i][j]-1);
		}
	}
	cout<<ans<<endl;
	/*
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++)
			cout<<lit[i][j];
		cout<<endl;
	}
	cout<<endl;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++)
			cout<<til[i][j];
		cout<<endl;
	}*/
    return 0;
}

Measured memory_bytes: 37248
#include <iostream>
#include <stack>
#include <unordered_map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <functional>
#include <iterator>
#include <tuple>

using namespace std;

int main() {
  long long int n;
  cin >> n;
  
  long long int result = (n-1) * n /2;
 
  cout << result <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by Reopard on 2014/05/13.
 */
public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String args[]) {
        int N, tmp, count;
        while (true) {
            N = sc.nextInt();
            count = 0;
            if (N == 0) break;
            for(int i = 1; i <= N/2; i++) {
                tmp = 0;
                for(int j = i; tmp < N; j++){
                    tmp += j;
                    if(tmp == N) count++;
                }
            }
        System.out.println(count);
        }
    }

}

Measured memory_bytes: 19868
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define N_MAX 1000
#define ll long long int
using namespace std;

int main() {
	int H, A; cin >> H >> A;
	if (H % A == 0) cout << H / A << endl;
	else cout << H / A + 1 << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	long long int n,a,b;
	long long int s=0;
	cin>>n>>a>>b;
	if(n==1){
		if(a==b)s=1;
	}else if(n==2 && a<=b)s=1;
	else if(a<=b){
		s=(n-2)*(b-a)+1;
	}
	cout<<s<<endl;
	return 0;
}




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

int main(){
	int A,B,C;

	scanf("%d",&A);
	scanf("%d",&B);
	scanf("%d",&C);


	if( A==B && A != C){
		printf("Yes\n");
	}
	else if(A==C && A != B){
		printf("Yes\n");
	}
	else if(B==C && B != A){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

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

using namespace std;

typedef long long int lli;

int main () {
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a <= c && c <= b ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
// 選択ソート
#include<iostream>
#include<algorithm>
using namespace std;

static const int MAX_N = 100;

void selectionSort(int A[], int n);

int main(void)
{
    int N;
    int ary_sequence[MAX_N];

    cin >> N;

    for(int i = 0; i < N; i++)
    {
        cin >> ary_sequence[i];
    }

    selectionSort(&ary_sequence[0], N);

    return 0;
}

// 選択ソートを実施する関数
void selectionSort(int A[], int n)
{

    int count = 0;
    // 最小値の存在する配列の要素No.
    int min_pos;

    for(int i = 0; i < n; i++)
    {
        min_pos = i;

        for(int j = i; j < n; j++)
        {
            if( A[j] < A[min_pos] )
            {
                // 最小値の存在する位置を保存する
                min_pos = j;
            }
        }

        if( i != min_pos )
        {
            // 最小値を移動させる
            swap(A[i], A[min_pos]);

            count++;
        }
    }

    // 結果表示用
   for(int i = 0; i < n; i++)
   {
       if( i )
       {
           cout << ' ';
       }

       cout << A[i];
   }

   cout << endl;
   cout << count << endl;

    return;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    scanf("%d", &N);

    vector<int> vec(N, 0);
    for(int i=1; i<N; i++){
        int tmp;
        scanf("%d", &tmp);
        vec.at(tmp)++;
    }

    for(int i=1; i<N; i++){
        printf("%d\n", vec.at(i));
    }
    printf("0\n");
}

Measured memory_bytes: 4128
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>

using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=1e9+1000;
const int mod=1e9+7;
ll infi=1e18+100;

//x=10111;
//x<<2 = 1011100 (右シフト),x>>2 = 101 (左シフト)
//(x>>2)&1 = 101 & 001 = 1
//iビット目は、(x>>i) & 1 でわかる(x>>i)%2 でもよい

int N;
int a;


int main(){
	cin>>N;
	int ans=1;
	int ma=0;
	rep(i,N){
      a=0;
		int j=i;
		while(j%2==0){
			j/=2;
			a++;
		}
		if(a>ma){ans=i; ma=a;}
	}

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

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

const int MAX_N = 2010;
vector<int> graph[MAX_N];
int d[MAX_N];
int ans[MAX_N];
int N, X, Y;
typedef pair<int,int> P;

void solve(int j) {
    for(int i = 0; i < N; ++i) d[i] = 10000;
    d[j] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0,j));
    while(!que.empty()){
        auto p = que.top();
        que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        ++ans[d[v]];
        for(int i = 0; i < graph[v].size(); ++i) {
            int to = graph[v][i];
            if(d[to] > d[v] + 1) {
                d[to] = d[v] + 1;
                que.push(P(d[to], to));
            }
        }
    }
    /*
    cout << "j: " << j << endl;
    for(int i = 0; i < N; ++i) cout << d[i] << " ";
    cout << endl;
    return ;
    */
}

int main()
{
    cin >> N >> X >> Y;
    --X, --Y;
    for(int i = 1; i < N; ++i) {
        graph[i-1].push_back(i);
        graph[i].push_back(i-1);
    }
    graph[X].push_back(Y);
    graph[Y].push_back(X);

    int res = 0;
    for(int j = 0; j < N; ++j) {
        solve(j);
    }

    for(int k = 1; k < N; ++k) {
        cout << ans[k]/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n , L , m ;
int a[ N ] , to[ N ] ;
int num , block , belong[ N ] ; 
int nxt[ N ] , val[ N ] ;

int find( int x ) {
    int l = x + 1 , r = n , ans = 0 ;
    while( l <= r ) {
        int mid = ( l + r ) >> 1 ;
        if( a[ mid ] - a[ x ] <= L ) l = mid + 1 , ans = mid ;
        else r = mid - 1 ;
    }
    return ans ;
}

int main() {
    scanf( "%d" , &n ) ;
    for( int i = 1 ; i <= n ; i ++ ) {
        scanf( "%d" , &a[ i ] ) ;
    }
    sort( a + 1 , a + n + 1 ) ;
    scanf( "%d%d" , &L , &m ) ;
    for( int i = 1 ; i < n ; i ++ ) {
        to[ i ] = find( i ) ;
    }
    to[ n ] = n + 1 ;
    block = sqrt( n ) ;
    num = n / block ;
    if( n % block ) num ++ ;
    for( int i = 1 ; i <= n ; i ++ ) {
        belong[ i ] = ( i - 1 ) / block + 1 ;
    }
    for( int i = 1 ; i < n ; i ++ ) {
        int t = i , sp = 0 ;
        while( belong[ t ] == belong[ i ] ) {
            t=to[ t ] ;
            sp ++ ;
        }
        val[ i ] = sp ;
        nxt[ i ] = t ;
        if( i >= block * ( num - 1 ) + 1 ) val[ i ] -- , nxt[ i ] -- ;
    }
    for( int i = 1 ; i <= m ; i ++ ) {
        int x , y  , ans = 0 ;
        scanf( "%d%d" , &x ,&y ) ;
        if( x > y )swap( x , y ) ;
        while( belong[ x ] < belong[ y ] ) {
            ans += val[ x ] ;
            x = nxt[ x ] ;
        }
        while( x < y ) {
            x = to[ x ] ;
            ans ++ ;    
        } 
        printf( "%d\n" , ans  ) ;
    }
    return 0 ;
} 

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main()
{
	char a,b;
	cin>>a>>b;
	if((a=='H'&&b=='H')||(a=='D'&&b=='D'))cout<<"H"<<endl;
	else cout<<"D"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
//#define int long long
#define all(vec) vec.begin(), vec.end()
#define dbg(x) cerr << #x << " = " << (x) << endl

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

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

	int N, M;
	cin>>N>>M;
	int a[55] = {0};
	for (int i = 0; i < N; i++) {
		int K;
		cin>>K;
		for (int j = 0; j < K; j++) {
			int tmp;
			cin>>tmp;
			a[tmp]++;
		}
	}
	int ans=0;
	for (int i = 0; i <= M; i++) {
		if(a[i]==N){
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

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

string S;

int main(){
    cin >> S;
    vector<string> v = {
        "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"
    };
    vector<string>::iterator sitr = find(v.begin(),v.end(), S);
    cout << 7 - (sitr - v.begin()) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

#define MOD (long long)1e9+7

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

void factorial(ll n);
void rfactorial(ll n);
ll binary_square(ll x, ll n);

vector<ll> fact(1e6, -1), rfact;

int main() {
  ll n, k, m = MOD;
  cin >> n >> k;
  factorial(2 * n);
  rfactorial(n + 1);
  ll ans = (fact[2 * n - 1] * rfact[n - 1] % m) * rfact[n] % m;
  if (k < n - 1) {
    ll x = fact[n];
    ans = 0;
    rep(i, k+1){
        ll zero = (((x * rfact[i]) % m) * rfact[n-i]) % m;
        ll rem = (((fact[n-1] * rfact[i]) % m) * rfact[n - 1 - i]) % m;
        ans = (ans + (zero * rem % m)) % m;
        // cout << ans << endl;
    }
  }
  cout << ans << endl;
  return 0;
}

void factorial(ll n) {
  ll m = MOD;
  fact[0] = 1;
  rep2(i, 1, n+1){
      fact[i] = fact[i-1] * i % m;
  }
}

void rfactorial(ll n) {
  rep(i, n) { rfact.push_back(binary_square(fact[i], MOD - 2)); }
}

ll binary_square(ll x, ll n) {
  ll m = MOD;
  ll ans = 1;
  while (n) {
    if (n % 2 == 1) {
      ans = ans * x % m;
    }
    x = x * x % m;
    n >>= 1;
  }
  return ans % m;
}

Measured memory_bytes: 13068
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

char ch[2] = {'h', 'i'};
string s;

int main() {
    cin >> s;
    int k = s.length();
    if(k%2) {cout << "No" << endl;return 0;}
    for(int i = 0; i < k; i++) {
        if(s[i] != ch[i%2]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

int data[1000000];
int main(void){
	long n,hei,cnt=0;
	long i,j;
	
	while(scanf("%ld",&n)==1){
		for(i=2;i<=n;i++)
			data[i]=1;
		hei=(long)sqrt(n);
		for(i=2;i<=hei;i++){
			if(data[i]!=0){
				for(j=i*2;j<=n;j+=i) //j=i*2EEE±ÌiÆjÌÔÉÍfª¶ÝµÈ¢½ß
					data[j]=0; //0=Áµ½
			}
		}
		for(i=2;i<=n;i++){
			if(data[i]==1)
				cnt++;
		}
		
		printf("%ld\n",cnt);
		cnt=0;
	}
	
	return 0;
}

Measured memory_bytes: 4312
#include <bits/stdc++.h>
using namespace std;
int main() {
    int64_t N;
    cin >> N;
    if(N % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }
    int64_t count = 0;
    while(N > 0) {
        count += N / 10;
        N /= 5;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

void mod( ll &n, ll m=MOD ){ n%=m,n+=m,n%=m; }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    int n;
    cin>>n;
    vector<pii>v(n);
    loop(i,0,n)
    {
        cin>>v[i].S>>v[i].F;
    }
    sort(all(v));

    ll time = 0;
    for(int i=0;i<n;i++)
    {
        if( time+v[i].S > v[i].F )
        {
            cout<<"No";
            return 0;
        }
        time += v[i].S;
    }
    cout<<"Yes";

    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

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

const ll mod = 1000000007;

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

  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;

  for (int i = 0; i < min(k, 50); i++) {
    vector<ll> next(n);
    vector<ll> imos(n+1);
    for (int j = 0; j < n; j++) {
      imos[max(0, (int)(j-a[j]))]++;
      imos[min(n, (int)(j+a[j]+1))]--;
    }
    int now = 0;
    for (int j = 0; j < n; j++) {
      now += imos[j];
      next[j] = now;
    }
    a = next;
  }

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

  return 0;
}


Measured memory_bytes: 7924