akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

const int N = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

//uに隣接するvを番号順に取得
int next(int u) {
    for(int v = nt[u]; v < n; v++) {
        nt[u] = v+1;
        if(M[u][v]) {
            return v;
        }
    }

    return -1;
}

//スタックを用いたDFS
void dfs_visit(int r) {
    rep(i, n) {
        nt[i] = 0;
    }

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while( !S.empty() ) {
        int u = S.top();
        int v = next(u);
        if(v != -1) {
            if(color[v] == WHITE) {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }
        else {
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs() {
    rep(i, n) {
        color[i] = WHITE;
        nt[i] = 0;
    }

    tt = 0;

    //未訪問のuを始点としてDFS
    rep(u, n) {
        if(color[u] == WHITE) {
            dfs_visit(u);
        }
    }
    rep(i, n) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main() {
    int u, k, v;

    cin >> n;
    rep(i, n) {
        rep(j, n) {
            M[i][j] = 0;
        }
    }

    rep(i, n) {
        cin >> u >> k;
        u--;
        rep(j, k) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();
    
    return 0;
}


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

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

void Main()
{
  int h,w,k; cin >> h >> w >> k;
  vector<vector<char>> c(h, vector<char>(w));
  int amount = 0;
  rep(i,h) {
    rep(j,w){
      cin >> c[i][j];
      if (c[i][j] == '#') amount++;
    }
  }
  vector<vector<char>> d(h, vector<char>(w));
  int tori = 0;
  for (int bit = 0; bit < (1 << h); ++bit) {
        // どれを選ぶか
        vector<int> S = IntegerToVector(bit, h);
    	for (int bi2 = 0; bi2 < (1<<w); ++bi2) {
            d = c;
          	vector<int> T = IntegerToVector(bi2, w);
          	int nokori = amount;
          	for (int i : S) {
              rep(j, w) {
                if (d[i][j] == '#') {d[i][j] = 'a'; nokori--;}
              }
            }
	        for (int j : T) {
              rep(i,h) {
                if (d[i][j] == '#') {d[i][j] = 'a'; nokori--;}
              }
            }
            if (nokori == k) tori++;
        }
  }
  cout << tori << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 3660
n = int(input())
s = list(input())
ans = s.count("R")*s.count("G")*s.count("B")
for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:
            break
     
        if s[i] != s[j] and  s[i] != s[k] and s[k] != s[j]:
            ans -= 1
print(ans)

Measured memory_bytes: 70040
#include <algorithm>
#include <iostream>
int a[1000000];
int b[1000000];
using namespace std;
int main()
{
int n;

cin>>n;
for (int i=1;i<=n;i++)
cin>>a[i];
for (int i=1;i<=n;i++)
b[a[i]]=i;

for (int i=1;i<=n;i++)
cout <<b[i]<<" ";
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000007
int i[1111][111],u[1111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a=0,b=0,c=0,d=0,e=0;
  cin >>a>>c;
  d=c;
  for(int n=1;n<a;n++){
    cin >>b;
    if(c>b) c=b;
    if(d<b) d=b;
  }
  cout <<d-c<<'\n';
  return (0);
}


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

const int MAXN = 1001000;

  int n;
int K;
int a[MAXN];
bool go(int p) {
  vector<int> v;
  long long cost = 0;
  for(int i = 0; i < n; ++i) {
    int k = a[i] % p;
    if (k < 0) k += p;
    if (k == 0) continue;
    v.push_back(k);
    cost += p - k;
  }
  long long cost2 = 0;
  if (cost2 <= K && cost <= K) {
    return true;
  }
  sort(v.begin(), v.end());
  for(int i = 0; i < v.size(); ++i) {
    int k = v[i];
    cost -= p - k;
    cost2 += k;
    if (cost2 <= K && cost <= K) {
      return true;
    }
  }
  return false;
}

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

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

  int ans = 1;
  for(int p = 1; p <= 5E8; ++p) {
    if (sum % p == 0)  {
      if (go(p)) {
        ans = p;
      }
    }
  }
  cout << ans << "\n";
}


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

int main() {
  string TapDanceMove;
  char buff;
  cin >> TapDanceMove;
  for (int i = 1; i <= TapDanceMove.size(); i++) {
    buff = TapDanceMove[i-1];
    //cout << i << "文字目: " << buff << endl;
    if (i % 2 == 0) {
      if (buff == 'R') {
        cout << "No";
        return 0;
      }
    } else {
      if (buff == 'L') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 55
using namespace std;
string s;
int n,cnt[N][300];

int main(){

  cin>>n;

  for(int i=0;i<n;i++){
    cin>>s;
    
    for(int j=0;j<(int)s.size();j++)
      cnt[i][(int)s[j]]++;
  
  }
  
  int idx='a';
  string ans;
  while(1){
    int mincnt=(1e9);
    
    for(int i=0;i<n;i++)mincnt=min(mincnt,cnt[i][idx]);
    
    for(int i=0;i<mincnt;i++)ans+=(char)(idx);
    
    idx++;
    if(idx=='z'+1)break;
  }
  
  cout<<ans<<endl;
  
  return 0;
}


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




int main(){
    int N;cin >> N;
    string s;cin >> s;
    int K;cin >> K;
    for(int a = 0;a < N;a++){
        if(s.at(K-1) == s.at(a)){
            cout<<s.at(a);
        }else{
            cout<<"*";
        }
    }
    cout<<endl;
}


Measured memory_bytes: 256
s = raw_input()
fx, fy = map(int, raw_input().split())

def possible(x, nums):
    x = abs(x)
    dp1 = [False] * (x + 1)
    dp2 = [False] * (x + 1)
    dp1[0] = True
    for y in nums:
        for i in range(len(dp2)):
            dp2[i] = False
            if i >= y:
                dp2[i] |= dp1[i - y]
            if i + y < len(dp2):
                dp2[i] |= dp1[i + y]
        dp1, dp2 = dp2, dp1
    return dp1[x]

def solve(s, fx, fy):
    try:
        first = s.index('T')
    except:
        return fy == 0 and fx == len(s)
    fx -= first
    s = s[first:]
    ts = []
    for i in range(len(s)):
        if s[i] == 'T':
            ts.append(i)
    ts.append(len(s))
    nums = map(lambda i: ts[i + 1] - ts[i] - 1, range(len(ts) - 1))
    x_nums = []
    y_nums = []
    for i in range(len(nums)):
        if i % 2 == 0:
            y_nums.append(nums[i])
        else:
            x_nums.append(nums[i])
    return possible(fx, x_nums) and possible(fy, y_nums)

print 'Yes' if solve(s, fx, fy) else 'No'


Measured memory_bytes: 33384
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int d, g;
	cin >> d >> g;
	vi p(d), c(d);
	rep(i, d) cin >> p[i] >> c[i];
	//we can do a bitmask on d
	//do we fill up this guy to get the bonus or not
	//then, we keep adding the most expensive problems
	int ans = 1e9;
	rep(i, (1 << d)){
		ll tot = 0;
		int cnt = 0;
		rep(j, d) if(i & (1 << j)){
			tot += (c[j] + (p[j] * ((j + 1) * 100)));
			cnt += p[j];
		}
		if(tot >= g) ans = min(ans, cnt);
		for(int j = d - 1; j >= 0; j--) if(!(i & (1 << j))){
			if(tot > g) break;
			int pos = p[j];
			while(tot < g && pos){
				tot += (j + 1) * 100;
				cnt++;
				pos--;
			}
		}
		if(tot >= g) ans = min(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
N, M = map(int, input().split())
A = []
B = []
parent = [-1 for i in range(N)]
size = [1 for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    A.append(a-1)
    B.append(b-1)


def root(i):
    if parent[i] < 0:
        return i
    parent[i] = root(parent[i])
    return parent[i]


uncomfort = N * (N - 1) // 2
ans = [uncomfort]
for i in reversed(range(1, M)):
    # print(size)
    #print(parent, A[i], B[i])
    if root(A[i]) != root(B[i]):
        comfort = size[root(A[i])] * size[root(B[i])]
        uncomfort -= comfort
        #print(size[root(A[i])], size[root(B[i])])
        if size[root(A[i])] > size[root(B[i])]:
            size[root(A[i])] += size[root(B[i])]
            parent[root(B[i])] = root(A[i])
        else:
            size[root(B[i])] += size[root(A[i])]
            parent[root(A[i])] = root(B[i])
    # print(uncomfort)
    ans.append(uncomfort)
# print(ans[::-1])
for answer in reversed(ans):
    print(answer)

Measured memory_bytes: 17732
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!{
      a: usize,
      b: usize,
      n: usize,
    }
    let x = if b > n {
        n
    } else {
        b-1
    };
    let ans = ((a * x) as f64 / (b as f64)).floor() - (a as f64) * ((x as f64)/(b as f64)).floor();
    puts!("{}\n", ans);
}


Measured memory_bytes: 2716
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <cctype>
#include <algorithm>
using namespace std;
int main(void){
    string a ;
    cin >> a;

    a[5] = ' ' ;
    a[13] = ' ' ;
    
    cout << a << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
	int L, R, d;
	cin >> L >> R >> d;
	int ans=0;
	for(int i=L; i<=R; ++i){
		if(i%d==0) ++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <math.h>
#include <string>

using namespace std;
int main()
{
    string a,b;
    int c=0;
    cin>>a>>b;
    if(a[0] == b[0]){
        c++;
    }
    if(a[1] == b[1]){
        c++;
    }
    if(a[2] == b[2]){
        c++;
    }
    cout<<c;

}

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

using namespace std;

constexpr int mod = 1e9 + 7;

int main(void) {
    string s;
    cin >> s;
    if (s[0] == 'S')
        cout << "Cloudy";
    else if (s[0] == 'C')
        cout << "Rainy";
    else
        cout << "Sunny";
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  int N;
  std::string S; std::cin >> N >> S;
  
  int ans = -1e9;
  // 0 ~ i]  [i+1,
  for(int i=0; i<N-1; i++) {
    std::string x = S.substr(0,i+1);
    std::string y = S.substr(i+1, N);

    std::unordered_map<char, bool> L;
    int cnt = 0;
    for(auto&& s : x) L[s] = true;
    for(auto&& s : y) {
      if ( L.count(s) == 1 && L[s] == true ) {
        cnt++;
        L[s] = false;
      }
    }
    ans = std::max(ans, cnt);
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 +7;
constexpr int MAXNe6 = 1e6 + 7;
#pragma region 
inline long long read()
{
	char c = getchar();long long flag = 1, ans = 0;
	while(c < '0' || c > '9'){if(c == '-')flag = -1; c = getchar();}
	while(c >= '0' && c <= '9'){ans = ans * 10 + c - '0'; c = getchar();}
	return (ans * flag);
}
#pragma endregion
// C'est la vie
pair<int, long long> ve[200007];
int main() {
    // int n = read(), d = read(), a = read();
    int n, d, a;
    cin >> n >> d >> a;
    for(int i = 0; i < n; ++ i) {
        cin >> ve[i].first >> ve[i].second;
        ve[i].second = (ve[i].second + a - 1) / a;
    }
    sort(ve, ve + n);
    for(int i = n - 1; i >= 1; -- i) ve[i].second = ve[i].second - ve[i - 1] .second;
    long long ans = 0;
    for(int i = 0; i < n; ++ i) {
        if(i != 0) ve[i].second += ve[i - 1].second;
        ans += max(ve[i].second, 0ll);
        int pos = upper_bound(ve, ve + n, make_pair(ve[i].first + 2 * d, mod * 1ll)) - ve;
        long long tmp = ve[i].second;
        ve[i].second -= max(tmp, 0ll);
        ve[pos].second += max(tmp, 0ll);
    }
    cout << ans << endl;

    #ifndef ONLINE_JUDGE
    system("pause");
    #endif
}

Measured memory_bytes: 3576
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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


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

const int N = 200005;

int n, d[N];
vector<int> adj[N];

void calc (int C, int P) {
	for(auto &T : adj[C]) {
		if(T == P) continue;
        d[T] = d[C] + 1;
        calc(T, C);
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++) {
		int A, B;
		scanf("%d%d",&A,&B);
		adj[A].push_back(B);
		adj[B].push_back(A);
	}
	calc(1, 0);
	int I = 1;
	for(int i=1;i<=n;i++) {
		if(d[I] < d[i]) I = i;
	}
	d[I] = 0;
	calc(I, 0);
	int X = 0;
	for(int i=1;i<=n;i++) {
		X = max(X, d[i]);
	}
	puts((X - 1) % 3 ? "First" : "Second");
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    vector<double> A(N);
    double sum=0;
    for (int i=0;i<N;++i){
        cin >> A[i]; sum+=A[i];
    }
    sort(A.begin(),A.end()); reverse(A.begin(),A.end());
    for (int i=0;i<M;++i) if (A[i]<sum/(4.0*M)){
        cout << "No" << '\n'; return 0;
    }
    cout << "Yes" << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long N, K;
  cin >> N >> K;
  
  vector<long> monster(N);
  
  for(long i=0; i<N; i++){
    cin >> monster.at(i);
  }
  sort(monster.begin(), monster.end(), greater<long>());
  long cnt=0;
  for(int i=K; i<N; i++){
    cnt += monster.at(i);
  }
  cout << cnt << endl;
}

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

using ll = long long;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define rep(i,n) for_(i,0,(n))
#define rrep(i,n) rfor_(i,0,(n))

void swap(int &a, int &b) {
    int temp = a;
    a = b;
    b = temp;
}

int N;

int A[102];

int c;

int main(){
	cin.tie(0);
	
	cin>>N;
	rep(i, N)cin>>A[i];
	
	rep(i, N) {
		int minj = i;
		for_(j, i, N) {
			if(A[j] < A[minj])minj = j;
		}
		if(i != minj) {
			swap(A[i], A[minj]);
			c++;
		}
	}

	
	rep(i, N)cout<<(i>0?" ":"")<<A[i];
	cout<<endl<<c<<endl;
	
	return 0;
}



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

signed main(){
  const int INF=1e9+7;
  int n,m;
  cin>>n>>m;
  std::vector<int> x(n),y(m);
  for(int i=0;i<n;i++)cin>>x[i];
  for(int i=0;i<m;i++)cin>>y[i];
  int xk,yk;
  xk=yk=0;
  for(int i=0;i<n-1;i++){
    int l=x[i+1]-x[i];
    l%=INF;
    l*=i+1;
    l%=INF;
    l*=n-i-1;
    i%=INF;
    xk+=l;
    xk%=INF;
  }
  for(int i=0;i<m-1;i++){
    int l=y[i+1]-y[i];
    l%=INF;
    l*=i+1;
    l%=INF;
    l*=m-i-1;
    i%=INF;
    yk+=l;
    yk%=INF;
  }
  cout<<(xk*yk)%INF<<endl;
}


Measured memory_bytes: 1792
(let* ((n (read)) (max-q (nth-value 0 (floor n 7))) (flag 0))
  (dotimes (i (1+ max-q))
    (if (= (mod (- n (* i 7)) 4) 0)
      (progn (setq flag 1) (return))))
  (princ (if (= flag 1) "Yes" "No")))


Measured memory_bytes: 13544
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (a, b, c, d) = {
        let abcd = get_line()
            .split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect::<Vec<i32>>();
        (abcd[0], abcd[1], abcd[2], abcd[3])
    };

    let mut a = a;
    let mut c = c;

    loop {
        c -= b;
        if c <= 0 {
            println!("Yes");
            break;
        }
        a -= d;
        if a <= 0 {
            println!("No");
            break;
        }
    }
}


Measured memory_bytes: 2096
#include <stdio.h>
int main(void){
    // Here your code !
    int m,f,r;
    int sum1;
    while(1){
        scanf("%d%d%d",&m,&f,&r);
        if(m == -1 && f == -1 && r == -1){
            return 0;
        }
        if(m == -1 || f == -1){
            printf("F\n");
        }
        else{
        sum1 = m + f;
        if(sum1 >= 80){
            printf("A\n");
        }
        else{
            if(sum1 >= 65){
                printf("B\n");
            }
            else{
                if(sum1 >= 50){
                    printf("C\n");
                }
                else{
                    if(sum1 >= 30){
                        if(r >= 50){
                            printf("C\n");
                        }
                        else{
                            printf("D\n");
                        }
                    }
                    else{
                        printf("F\n");
                    }
                }
            }
        }
    }
}}

Measured memory_bytes: 584
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <bitset>
#include <ctime>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <sstream>
#pragma comment(linker, "/STACK:256000000")
using namespace std;

#define in(s) freopen(s, "r", stdin)
#define out(s) freopen(s, "w", stdout)
#define forn(i, n) for (int i = 0; i < n; i++)
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef long double ld;

inline int last_dig(int x) {
	return x % 10;
}

inline int first_dig(int x) {
	int res = -1;
	while (x) {
		res = x % 10;
		x /= 10;
	}
	return res;
}

int cnt[10][10];

int main()
{
	//in("input.txt");
	//out("output.txt");
	srand(1373737);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n;
	cin >> n;

	for (int i = 1; i <= n; i++) {
		cnt[first_dig(i)][last_dig(i)]++;
	}

	ll ans = 0ll;
	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++)
			ans += (ll)cnt[i][j] * (ll)cnt[j][i];
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}



signed main(){
	ll n;
	cin >> n;
	
	string s,t;
	cin >> s >> t;
	
	rep(i,0,n){
		cout << s[i] << t[i];
	}
	
	cout << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace ITP1
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);
            if (a < b & b < c)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
          
        }
    }
}

Measured memory_bytes: 8880
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

int main(){
   int a, b;
   cin >> a >> b;
   int v1 = max(a,b) - 1;
   int v2 = max(v1, min(a,b)) - 1;
   cout << v1 + v2 + 2 << endl;

   return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
    int n,k;
    cin>>n>>k;
    vi v(n);
    rep(i,n){
        cin >> v[i];
    }
    sort(v.rbegin(), v.rend());
    int ans = 0;
    rep(i, k)
    {
        ans += v[i];
    }
    cout<<ans<<endl;
    return 0;
}

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

using i64 = int64_t;

vector<i64> divisor(i64 n) {
    vector<i64> res;
    for (i64 i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i)
                res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    i64 n;
    cin >> n;
    auto v = divisor(n);
    i64 ans = 0;
    for(auto e: v){
        i64 d = n / e;
        if(d > e + 1)ans += d - 1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
import sys
readline = sys.stdin.readline

def main():
  N = int(readline())
  Sp = []
  Sm = []
  total = 0
  bm = 0
  for i in range(N):
    l = readline().strip()
    b = 0
    h = 0
    for j in range(len(l)):
      if l[j] == '(':
        h += 1
      else:
        h -= 1
      b = min(b, h)
    if h == 0 and b != 0:
      bm = min(bm, b)
    elif h > 0:
      Sp.append([b, h])
    elif h < 0:
      Sm.append([b-h, -h])
    total += h
  Sp.append([bm, 0])
  if total != 0:
    print('No')
    exit()
  Sp.sort(key=lambda x:x[0], reverse=True)
  p = check(Sp)
  if p < 0:
    print('No')
    exit()
  Sm.sort(key=lambda x:x[0], reverse=True)
  m = check(Sm)
  if m < 0:
    print('No')
    exit()
  print('Yes')

def check(S):
  h = 0
  for i in range(len(S)):
    if h + S[i][0] < 0:
      return -1
    else:
      h += S[i][1]
  return h

if __name__ == '__main__':
  main()

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

template <typename T>
struct PrimeFact {
    vector<T> spf;
    PrimeFact(T N) { init(N); }
    void init(T N) { // 前処理。spf を求める
        spf.assign(N + 1, 0);
        for (T i = 0; i <= N; i++) spf[i] = i;
        for (T i = 2; i * i <= N; i++) {
            if (spf[i] == i) {
                for (T j = i * i; j <= N; j += i) {
                    if (spf[j] == j) {
                        spf[j] = i;
                    }
                }
            }
        }
    }
    T get(T n) { // nの素因数分解を求める
        T p = 0, cnt = 0, res = 1;
        while (n != 1) {
          if (p == spf[n])
            cnt++;
          else {
            res *= cnt+1;
            p = spf[n];
            cnt = 1;
          }
          n /= spf[n];
        }
        res *= cnt+1;
        return res;
    }
};

int main() {
  int N;
  cin >> N;
  PrimeFact<ll> P(N+1);
  ll ans = 0;
  for (int i=1; i<=N; i++) {
    ans += i*P.get(i);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 81404
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 300005;
struct Node{
  int x,y;
  bool operator < (const Node &b)const
  {
    return x<b.x;
  }
}a[MAXN<<1],stk[2][MAXN<<1];
int mx[MAXN<<2],add[MAXN<<2],n,w,h,tot_1,tot_2,ql,qr,qval,ans;
inline void pushdown(int i)
{
  int lc=i<<1,rc=lc|1,tag=add[i];add[i]=0;
  mx[lc]+=tag,mx[rc]+=tag;
  add[lc]+=tag,add[rc]+=tag;
}
inline void update(int i,int l,int r)
{
  if(l>=ql && r<=qr){
    mx[i]+=qval;
    add[i]+=qval;
    return;
  }
  if(add[i])pushdown(i);
  int lc=i<<1,rc=lc|1,mid=(l+r)>>1;
  if(qr<=mid)update(lc,l,mid);
  else if(ql>mid)update(rc,mid+1,r);
  else update(lc,l,mid),update(rc,mid+1,r);
  mx[i]=max(mx[lc],mx[rc]);
}
inline void solve()
{
  sort(a+1,a+n+1);
  tot_1=tot_2=0;
  memset(mx,0,sizeof(mx));
  memset(add,0,sizeof(add));
  for(int i=1;i<=n;++i){
    if(a[i].y<=h/2){
      int last=i-1;
      while(tot_1 && a[i].y>stk[0][tot_1].y){
	ql=stk[0][tot_1].x,qr=last,qval=stk[0][tot_1].y-a[i].y;
	update(1,1,n);
	last=stk[0][tot_1].x-1;
	--tot_1;
      }
      if(last!=i-1)stk[0][++tot_1]=(Node){last+1,a[i].y};
    }else{
      int last=i-1;
      while(tot_2 && a[i].y<stk[1][tot_2].y){
	ql=stk[1][tot_2].x,qr=last,qval=a[i].y-stk[1][tot_2].y;
	update(1,1,n);
	last=stk[1][tot_2].x-1;
	--tot_2;
      }
      if(last!=i-1)stk[1][++tot_2]=(Node){last+1,a[i].y};
    }
    stk[0][++tot_1]=(Node){i,0};
    stk[1][++tot_2]=(Node){i,h};
    ql=qr=i,qval=h-a[i].x;
    update(1,1,n);
    ans=max(ans,mx[1]+a[i+1].x);
  }
}
int main()
{
  scanf("%d%d%d",&w,&h,&n);
  for(int i=1;i<=n;++i)scanf("%d%d",&a[i].x,&a[i].y);
  a[++n].x=0,a[n].y=0;
  a[++n].x=w,a[n].y=h;
  solve();
  swap(w,h);
  for(int i=1;i<=n;++i)swap(a[i].x,a[i].y);
  solve();
  cout<<ans*2<<endl;
  return 0; 
}


Measured memory_bytes: 20736
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <iostream>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>

using namespace std;
const int mod=1000000007;

vector<int> st;
vector<long long int> v;

bool check(string s){
    string c;
    c=s;
    reverse(s.begin(), s.end());
    if (c==s) {
        return true;
    }
    return false;
}




int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long int n,m,k,q,d,x,l,a,b,c;
    long double ans;
    cin>>ans;
    ans/=3;
    cout<<setprecision(10);
    cout<<pow(ans, 3)<<"\n";
    
    return 0;
}


Measured memory_bytes: 640
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] s = sc.nextLine().split(" ");
		String len_max = s[0],ans = s[0];
		int count_max = 0;
		Map<String,Integer> map = new HashMap<String,Integer>();
		
		for(int i=0;i<s.length;i++){
			if(len_max.length() < s[i].length()){
				len_max = s[i];
			}
			if(map.get(s[i]) != null){
				map.put(s[i],map.get(s[i])+1);
			}else{
				map.put(s[i], 0);
			}
			if(map.get(s[i]) > count_max){
				count_max = map.get(s[i]);
				ans = s[i];
			}
		}
		
		System.out.println(ans + " " + len_max);
	}
}

Measured memory_bytes: 17112
S = gets.chomp.chars
answer = Array.new(S.length, 0)
count = 0

S.each.with_index do |c, i|
  if c == "R"
    count += 1
  else
    answer[i] += count / 2
    answer[i - 1] += (count + 1) / 2
    count = 0
  end
end

answer.reverse!
count = 0

S.reverse.each.with_index do |c, i|
  if c == "L"
    count += 1
  else
    answer[i] += count / 2
    answer[i - 1] += (count + 1) / 2
    count = 0
  end
end

puts answer.reverse.join(" ")


Measured memory_bytes: 12284
#include <stdio.h>
#define N 10000

int A[2000001],B[2000001],C[N];

int main(){
  int i,j,n;

  scanf("%d",&n);
  for(i=1;i<n+1;i++){
    scanf("%d",&A[i]);
  }
 
  for(i=0;i<N;i++)C[i]=0;

  for(j=1;j<n+1;j++)C[A[j]]+=1;

  for(i=0;i<N;i++)C[i]+=C[i-1];

  for(j=n+1;j > 0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]-=1;
  }

  
  for(i=1;i<n;i++){
  
    printf("%d ",B[i]);
     
  }
  printf("%d",B[i]);
  printf("\n");

  return 0;
}



Measured memory_bytes: 17408
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n = I()
    A = LI()

    def partition(A, p, r):
        x = A[r]
        i = p-1
        for j in range(p, r):
            if A[j]<=x:
                i += 1
                A[i], A[j] = A[j], A[i]
        A[i+1], A[r] = A[r], A[i+1]
        return i+1

    q = partition(A, 0, n-1)
    A_str = [str(i) for i in A]
    A_str[q] = '[' + A_str[q] + ']'
    print(*A_str)

if __name__ == '__main__':
    resolve()



Measured memory_bytes: 16972
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

struct edge {
    int from, to; ll cost;
    edge(int s, int t, ll w = 0) : from(s), to(t), cost(w) {}
};

int main() {
    init();

    int n;
    cin >> n;
    vector<vector<edge>> g(n);
    int a, b;
    FOR(i, 0, n - 1) {
        cin >> a >> b;
        a--, b--;
        g[a].emplace_back(a, b, 1);
        g[b].emplace_back(b, a, 1);
    }

    VI f(n), s(n);
    vector<bool> fe(n, false), se(n, false);
    queue<pair<int,int>> bfs;
    int now, dis;

    bfs.push({ 0,0 });
    while (!bfs.empty()) {
        tie(now, dis) = bfs.front();
        bfs.pop();

        fe[now] = true;
        f[now] = dis;
        for (edge next : g[now]) {
            if (fe[next.to])continue;
            bfs.push({ next.to,dis + 1 });
        }
    }

    bfs.push({ n - 1,0 });
    while (!bfs.empty()) {
        tie(now, dis) = bfs.front();
        bfs.pop();

        se[now] = true;
        s[now] = dis;
        for (edge next : g[now]) {
            if (se[next.to])continue;
            bfs.push({ next.to,dis + 1 });
        }
    }

    int cnt = 0;
    FOR(i, 0, n) {
        if (f[i] <= s[i])cnt++;
        else cnt--;
    }
    cout << (cnt > 0 ? "Fennec\n" : "Snuke\n");
}

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

using namespace std;

const int N = 1e6 + 6;

vector< int > g[N];

int c[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--; v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  queue< int > que;
  c[0] = 1;
  c[n-1] = 2;
  que.push(0);
  que.push(n-1);
  int black = 0, white = 0;
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    if (c[v] == 1) black++;
    else white++;
    for (int u : g[v]) if (!c[u]) {
      c[u] = c[v];
      que.push(u);
    }
  }
  puts(black > white ? "Fennec" : "Snuke");

  return 0;
}

Measured memory_bytes: 29184
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

int i, j, n, m;
string s, t;

void solve()
{
    cin >> s >> t;
    n = sz(s), m = sz(t);
    int ans = INF;
    for (i = 0; i + m - 1 < n; i++)
    {
        string str = s.substr(i, m);
        int changes = 0;
        for (j = 0; j < m; j++)
        {
            if (str[j] != t[j])
                changes++;
        }
        ans = min(ans, changes);
    }
    cout << ans;
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fastio;
    int t;
    //cin >> t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<ll> a(n);
    REP(i,n) cin>>a[i];
    bool plus;//単調増加;
    bool flg=true;

    ll ans=1;
    for(int i=0;i<n-1;i++){
        if(flg){
            if(a[i]==a[i+1]) continue;
            if(a[i]<a[i+1]) plus=true;
            else plus = false;
            flg=false;
            continue;
        }
        if(plus){
            if(a[i]<=a[i+1]) continue;
            else{
                ans++;
                plus=false;
                flg=true;
                //cout<<a[i]<<" "<<a[i+1]<<endl;
            }
        }
        else{
            if(a[i]>=a[i+1]) continue;
            else{
                ans++;
                plus=true;
                flg=true;
            }
        }

    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    int all=0;
    int flag=0; 
    cin >> n >> m;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
        all += a.at(i);
        }
        for(int j=0;j<n;j++){
        if(a.at(j)*4*m>=all){
            flag+=1;
        }
        }
        if(flag>=m){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll n , x;
    cin >> n >> x;
    ll res = 0 ;
    vl v ;
    forn(i , 1 , n){
       ll xx;
       cin >> xx;
       v.pb(xx) ;
       if(v[i-1] > x){
        res = res + v[i-1] - x;
        v[i-1] = x;
       }
    }
    forn(i , 1 , n-1){
       ll nsl = v[i] + v[i-1] ;
       if(nsl > x){
        ll diff = nsl - x;
        v[i] = max(0LL , v[i] - diff) ;
        res = res + diff;
       }
    }

    cout << res<< el ;
    ro ;


}
































Measured memory_bytes: 1400
import java.util.*;

public class Main{
    public static void main(String args[]){
        int[] N = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        Scanner sn = new Scanner(System.in);
        int K = sn.nextInt();
        System.out.println(N[K-1]);

    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i = 0; i < (n);i++)
#define COUT(x) cout << (x) << endl;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    REP(i,n){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b.begin(),b.end());
    ll d = 0;
    REP(i,n){
        if (a[i]!=b[i])
        {
            d++;
        }
    }
    if (d==0)
        {
            COUT(0);
            return 0;
        }
    ll q;
    cin >> q;
    REP(i,q){        
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        if (a[x]==b[x] && a[x]!=b[y])
        {
            d++;
        }
        if (a[x]!=b[x] && a[x]==b[y])
        {
            d--;
        }
        if (a[y]==b[y] && a[y]!=b[x])
        {
            d++;
        }
        if (a[y]!=b[y] && a[y]==b[x])
        {
            d--;
        }
        swap(a[x],a[y]);
        if (d==0)
        {
            COUT(i+1);
            return 0;
        }
    }
    COUT(-1);
}


Measured memory_bytes: 7560
#!/usr/bin/env python3

#import
#import math
#import numpy as np
N = int(input())
S = list(input())

re = S.count("E")
rw = N - re
le = 0
lw = 0

ans = 10**9

for i in range(N):
    if S[i] == "E":
        re -= 1
        ans = min(ans, re + lw)
        le += 1
    else:
        rw -= 1        
        ans = min(ans, re + lw)
        lw += 1

print(ans)




Measured memory_bytes: 11620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
int MOD = 1000000007;
signed main() {
	int N;
	cin >> N;
	vector<int> a(N + 3);
	vector<int> dst(N + 3);
	dst[1] = 1;
	for (ll i = 2; i <= N; i++) {
		dst[i] = dst[MOD % i] * (MOD - MOD / i) % MOD;
	}
	for (int i = 0; i <= N; i++) {
		cin >> a[i];
	}
	vector<int> used(N, -1);
	int d = 0;
	for (int i = 0; i <= N; i++) {
		if (used[a[i] - 1] != -1) {
			d = i - used[a[i] - 1] - 1;
			
		}
		else {
			used[a[i] - 1] = i;
		}
	}
	vector<int> nck(N + 5,0);
	vector<int> nack(N + 5,0);
	nck[0] = 1;
	nack[0] = 1;
	for (int i = 1; i <= N + 1; i++) {
		if (i <= N - 1) { 
			nck[i] = (((nck[i - 1] * (N - i)) % MOD)*dst[i]) % MOD; 
		}
		if (i <= N - d - 1) nack[i] = (((nack[i-1] * (N - d - i)) % MOD)*dst[i]) % MOD;
	}

	int res;
	for (int i = 1; i <= N + 1; i++) {
		if (i == 1) {
			cout << N << endl;
			continue;
		}
		res = 0;
		res = (res + nck[i - 2]) % MOD;
		res = (res + nck[i]) % MOD;
		res = (res + nck[i - 1]) % MOD;
		res = (res + nck[i - 1]) % MOD;
		res = (res - nack[i - 1] + MOD) % MOD;
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 5120
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def mygcd(x, y):
    if x == 0 or y == 0:
        return max(x, y)
    else:
        (x1, y1) = (max(x, y), min(x, y))
        return mygcd(y, x % y)


def main():
    print(mygcd(*map(int, input().split())))

if __name__ == "__main__":
    main()

Measured memory_bytes: 7740
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

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

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

  if(a > 8 || b > 8) cout << ":(" << endl;
  else cout << "Yay!" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int N, D, X;
    int a;

    scanf("%d%d%d", &N, &D, &X);
    int eat = X;

    for (int i = 0; N > i; i++) {
        scanf("%d", &a);
        eat += (D - 1) / a + 1;
    }
    printf("%d\n", eat);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
        
ll n,a,b,c,d;
map<ll,ll> memo;
ll use_coin[3];
ll mod[3] = {2,3,5};
const ll INF = INT64_MAX>>2;

ll dfs(ll k) {
    if(k == 0) return 0;
    if(k == 1) return d;
    if(memo.count(k) > 0) return memo[k];
    ll res = INF;
    if(k < INF/d) res = k*d;
    rep(i,3) {
        ll nk=  k/mod[i];
        ll nc = use_coin[i] + d*(k-nk*mod[i]);
        chmin(res, dfs(nk)+nc);
        nk =  (k+mod[i]-1)/mod[i];
        nc = use_coin[i] + d*(nk*mod[i]-k);
        chmin(res, dfs(nk)+nc);
    }
    return memo[k] = res;
}

int main(){
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    rep(i,t) {
        memo.clear();
        cin >> n >> use_coin[0] >> use_coin[1] >> use_coin[2] >> d;
        cout << dfs(n) << endl;
    }
}


Measured memory_bytes: 4488
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define pb push_back
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (i64)(x).size()
#define bit(n) (1LL<<(n))
typedef vector<i64> vi;
typedef vector<vi> vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

i64 pow_mod(i64 n, i64 k, i64 m){
  i64 r = 1;
  for(;k;k>>=1){
    if(k&1) r=(r*n)%m;
    n=(n*n)%m;
  }
  return r;
}

void Main()
{
  i64 ans = 0;
  i64 n;
  cin >> n;

  i64 a;
  cin >> a;
  if(a>0){
    cout << -1 << endl;
    return;
  }

  i64 pre = a;
  rep(i,n-1){
    cin >> a;
    if(pre+1 < a){
      cout << -1 << endl;
      return;
    }else if(a==pre+1)
      ans++;
    else{
      ans += a;
    }
    pre = a;
  }
  cout << ans << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}


Measured memory_bytes: 256