akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

using namespace std;

int main() {
  int i, j, k;
  long long dp[52][52][2701] = {};
  int N, A, x[50];
  scanf("%d %d", &N, &A);
  for (i = 0; i < N; i++) {
    scanf("%d", &x[i]);
  }
  dp[0][0][0] = 1;
  for (i = 1; i <= N; i++) {
    for (j = 0; j <= N; j++) {
      for (k = 0; k <= N*A; k++) {
	if (k < x[i-1]) {
	  dp[i][j][k] = dp[i-1][j][k];
	} else {
	  dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i-1]];
	}
      }
    }
  }
  long long ans = 0;
  for (j = 1; j <= N; j++) {
    ans += dp[N][j][j*A];
  }
  printf("%lld", ans);
  return 0;
}

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

int main() {
  
  int R, G, B, N; cin >> R >> G >> B >> N;
  
  int64_t ans = 0;
  
  for (int i = 0; i * R <= N; i++) {
    
    for (int j = 0; j * G + i * R <= N; j++) {
      
      if ((N - (i * R) - (j * G)) % B == 0) ans++;
      
    }
    
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3640
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>>g;
vector<int>used;

void dfs(int cur,int d,vector<int>&h)
{
    h[cur]=d;
    used[cur]=1;
    for(auto x:g[cur])
    {
        if(!used[x])
        {
            dfs(x,d+1,h);
        }
    }
}



int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	int n,u,v;
	cin>>n>>u>>v;
	u--;
	v--;
	vector<int>hu(n),hv(n);
	g.resize(n);
	used.resize(n);
	for(int i=0;i<n-1;i++)
	{
	    int a,b;
	    cin>>a>>b;
	    a--;
	    b--;
	    g[a].push_back(b);
	    g[b].push_back(a);
	    
	}
	
	//fill(used.begin(),used.end(),0);
	dfs(u,0,hu);
	fill(used.begin(),used.end(),0);
	dfs(v,0,hv);
	int ans=0;
	for(int i=0;i<n;i++)
	{
	    if(hv[i]>hu[i])
	    {
	        ans=max(ans,hv[i]-1);
	    }
	}
	
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 10752
#!/usr/bin python3
# -*- coding: utf-8 -*-
def factorization(n):
    primen, degree, primend = [], [], []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            primen.append(i)
            degree.append(cnt)
            primend.append([i,cnt])
    if temp!=1:
        primen.append(temp)
        degree.append(1)
        primend.append([temp,1])
    if primen==[]:
        primen.append(n)
        degree.append(1)
        primend.append([n,1])
    return degree


def main():
    N = int(input())
    if N==1:
        ret = 0
    else:
        de= factorization(N)
        ret = 0
        for d in de:
            for k in range(d+1):
                if (k+1)*(k+2)//2<=d:
                    continue
                else:
                    break
#            print(d,k)
            ret += k
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9408
k = int(input())
a = [0] * k

x = 0
i = 1
while True:
    x = x * 10 + 7
    x %= k
    m = x % k
    if m == 0:
        print(i)
        exit()
    if a[m] == 1:
        print(-1)
        exit()
    a[m] = 1
    i += 1

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    for (ll i = 1; i <= 3500; i++) {
        for (ll j = 1; j <= 3500; j++) {
            if (4*i*j-N*i-N*j == 0) {
                continue;
            }
            double k = double(N*i*j)/double(4*i*j-N*i-N*j);
            if (k > 0 && ceil(k) == floor(k)) {
                cout << i << " " << j << " " << ll(k) << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N,Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vec<int> s(N,0);
    for(int i=1;i<N;++i){
        if(S[i-1]=='A'&&S[i]=='C'){
            s[i] = s[i-1]+1;
        } else {
            s[i] = s[i-1];
        }
    }
    
    rep(i,Q){
        int l,r;
        cin >> l >> r;
        --l,--r;
        cout << (s[r]-s[l]) << endl;
    }
    
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

ll power(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

int main(){
    ll h;
    cin >> h;

    ll cnt = 0;
    while(h > 1){;
        h >>= 1;
        cnt++;
    }

    cout << power(2, cnt+1) - 1 << endl;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
s_list = []
for i in range(H):
    s_list.append(list(input()))

for i in range(H):
    for j in range(W):
        if s_list[i][j] == '.':
            continue
        else:
            if i != 0:
                if s_list[i - 1][j] == '#':
                    continue
            if i != H - 1:
                if s_list[i + 1][j] == '#':
                    continue
            if j != 0:
                if s_list[i][j - 1] == '#':
                    continue
            if j != W - 1:
                if s_list[i][j + 1] == '#':
                    continue
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	N %= K
	if N < K-N {
		fmt.Println(N)
	} else {
		fmt.Println(K - N)
	}
	// for {
	// 	if N < K {
	// 		fmt.Println(N)
	// 		return
	// 	} else {
	// 		N = abs(N, K)
	// 		fmt.Println(N)
	// 	}
	// }
	// fmt.Println(N)
}


Measured memory_bytes: 512
N = int(input())
H = list(map(int, input().split(' ')))

dp = [100000000] * N
dp[0] = 0
dp[1] = abs(H[0] - H[1])

for i in range(2, N):
    dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2]))

print(dp[N - 1])


Measured memory_bytes: 13924
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

int f(string &s) {
    int n = (int)s.size();
    for (int f = 1; f <= n; f++) {
        if (n % f != 0) continue;
        int b = 1;
        for (int i = 0; i < f; i++) {
            char c = s[i];
            for (int j = i + f; j < n; j += f) {
                if (s[j] != c) {
                    b = 0;
                    break;
                }
            }
            if (!b) break;
        }
        if (b) return f;
    }
    throw;
}

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

    string s, t;
    cin >> s >> t;

    int n = f(s);
    int m = f(t);

    s += s;
    s += s;
    n = (int)s.size();

    constexpr int K = 1 << 13;
    ll ht = 0;
    ll iv = 1;
    for (int i = 0; i < m; i++) {
        ht *= K;
        ht += t[i];
        ht %= P;
        iv = iv * K % P;
    }
    
    ll hs = 0;
    vector<int> hss(n + 1);
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        hs *= K;
        hs += s[i];
        hs %= P;
        hss[i + 1] = (int)hs;
        if (i + 1 >= m) {
            ll h = hss[i + 1] - hss[i + 1 - m] * iv % P;
            if (h < 0) h += P;
            if (h == ht) {
                a[i + 1 - m] = 1;
            }
        }
    }

    int f = m;
    int r = 0;
    for (int i = 0; i < f; i++) {
        int b = 0;
        for (int j = i; j < n; j += f) {
            if (a[j]) {
                b++;
                r = max(r, b);
            } else {
                b = 0;
            }
        }
    }

    if (r * m > n / 2) {
        cout << -1 << endl;
        exit(0);
    }
    cout << r / ((int)t.size() / m) << endl;

    return 0;
}

Measured memory_bytes: 19804
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { 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; }
//const long long INF = 2LL << 60;

using ll = long long;
using P = pair<ll, ll>;

int main(int argc, char const *argv[]){
    ll n;
    ll cnt=0;
    cin >> n;
    for(ll i=2;i<=sqrt(n);i+=2){
        ll acnt=0;
        while(0==(n%i)){
            n/=i;
            acnt++;
        }
        for(ll j=1;acnt>=j;j++){
            acnt-=j;
            cnt++;
        }
        if(i==2){
            i=1;
        }
    }
    if(n>1)cnt++;
    cout << cnt << endl;
}




Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


// bool check_prime(int n)  return whether a number is prime or not O(sqrt(N));
// int BE(int x,int n,int m)  return x^n%m; O(logN);
// void sieve()  from number 1-1000001 saare prime store kar lega  in bool is_prime[1000001] array
// vector<int> z_array(string s)  return vector which is Z-array of string s;
// vector<int> lps(string s)      return vector which is lps array of string s;

vi adj[10];
bool vis[10];
int ans = 0;
int n, m;
void dfs(int i, int k)
{
	if (k == n)
	{
		ans++;
		return;
	}
	vis[i] = true;
	for (int child : adj[i])
	{
		if (!vis[child])
		{
			dfs(child, k + 1);
		}
	}
	vis[i] = false;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________


	cin >> n >> m;
	zip(i, 0, m)
	{
		int a, b;
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	// starting from node 1 we have to visit all node
	// total number of paths

	dfs(1, 1);
	cout << ans << en;





	return 0;

}



Measured memory_bytes: 3568
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - ><
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 500000;

/* typedef */

typedef long long ll;

/* global variables */

char s[MAX_N + 4];

/* subroutines */

/* main */

int main() {
  scanf("%s", s);
  int n = strlen(s);

  ll sum = 0;
  for (int i = 0; i < n;) {
    int j = i;
    while (j < n && s[j] == '<') j++;
    int a = j - i;
    i = j;

    while (j < n && s[j] == '>') j++;
    int b = j - i;
    i = j;

    if (a >= b) b--;
    else a--;
    sum += (ll)a * (a + 1) / 2 + (ll)b * (b + 1) / 2;
  }

  printf("%lld\n", sum);
  return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    for (int i = 0; i < n; ++i) cin >> x[i];
    int ans = 1001001001;
    for (int l = 0; l < n - k + 1; ++l) {
        int lx = x[l];
        int rx = x[l + k - 1];
        if (rx <= 0) ans = min(ans, abs(lx));
        else if (lx < 0 && 0 < rx) ans = min(ans, min(abs(lx), abs(rx)) * 2 + max(abs(lx), abs(rx)));
        else ans = min(ans, rx);
    }
    cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    set<int> s;
    rep(i,n) s.insert(a[i]);
    if(s.size()==n) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

vector<ll> Zalgo(const string& S) {
  ll N = SZ(S);
  vector<ll> res(N);
  res[0] = N;
  ll i = 1, j = 0;
  while (i < N) {
    while (i + j < N && S[j] == S[i + j]) ++j;
    res[i] = j;
    if (j == 0) {
      ++i;
      continue;
    }
    ll k = 1;
    while (i + k < N && k + res[k] < j) res[i + k] = res[k], ++k;
    i += k, j -= k;
  }
  return res;
}

int main() {
  ll N;
  cin >> N;
  string S;
  cin >> S;
  ll ans = 0;
  // l1 = i の場合
  REP(i, N) {
    string T = S.substr(i);
    ll M = SZ(T);
    auto lcp = Zalgo(T);
    // l2 = i+jの場合
    REP(j, M) {
      ll len = min(lcp[j], j);
      ans = max(ans, len);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main(){
    int h,a;
    cin >> h >> a;
    dunk((h+a-1)/a);
}
    





Measured memory_bytes: 256
'use strict'

function main(s) {
  
  s = s.split('\n')[0].split(' ').map(n => Number(n));
  const A = s[0];
  const B = s[1];
  const C = s[2];

  const abc_sum = A + B + C;
  let same_sum = Math.max(...[A, B, C]) * 3;

  if (abc_sum % 2 !== same_sum % 2) same_sum += 3;

  const answer = (same_sum - abc_sum) / 2;
  console.log(answer);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
X, K, D = map(int, input().split())
ans = 0

if abs(X) < (K * D):
    q = abs(X) // D
    r = abs(X) % D
    if (K - q) % 2 == 0:
        ans = r
    else:
        ans = min(abs(r + D), abs(r - D))
elif X > 0:
    ans = X - (K * D)
elif X < 0:
    ans = abs(-(abs(X) - (K * D)))

print(ans)

Measured memory_bytes: 9112
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
using ll = long long;
using namespace std;
int L[51];
int LL[52];
int N;
int get_segment(int a, int b) //L[a] + L[a+1] + ... + L[b]
{
    int sm = LL[b];
    if (a)
        sm -= LL[a - 1];
    return sm;
}
int memo[55];

int check(int idx, int mi, int ma)
{
    if (0 <= memo[idx])
        return memo[idx];
    if (idx == N)
        return 1;

    int lim = (idx == 0) ? N - 1 : N;
    for (int i = idx; i < lim; ++i)
    {
        int sm = get_segment(idx, i);
        if (sm >= mi && sm <= ma)
        {
            if (check(i + 1, mi, ma))
                return memo[idx] = 1;
        }
    }

    return memo[idx] = 0;
}
int main(void)
{
    cin >> N;
    for (int i = 0; i < N; ++i)
        cin >> L[i];

    LL[0] = L[0];
    for (int i = 1; i < N; ++i)
        LL[i] = LL[i - 1] + L[i];

    vector<int> v;
    for (int i = 0; i < N; ++i)
    {
        for (int j = i; j < N; ++j)
        {
            int sm = get_segment(i, j);
            v.push_back(sm);
        }
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    int n = v.size();
    int ans = 1000000;
    for (int i = 0; i < n; ++i)
    {
        for (int j = i; j < n; ++j)
        {
            int mi = v[i];
            int ma = v[j];

            for (int k = 0; k < N + 1; ++k)
                memo[k] = -1;
            if (check(0, mi, ma))
                ans = min(ans, ma - mi);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3176
#include <iostream>
#include <string>

using namespace std;

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

	int taro = 0, hanako = 0;
	while (n--)
	{
		string t, h;
		cin >> t >> h;

		if (t == h)
		{
			taro++, hanako++;
			continue;
		}

		int i = 0;
		while (t[i] || h[i])
		{
			if (t[i] > h[i] || !h[i])
			{
				taro += 3;
				break;
			}
			else if (t[i] < h[i] || !t[i])
			{
				hanako += 3;
				break;
			}

			i++;
		}
	}

	cout << taro << " " << hanako << endl;

	return 0;
}

Measured memory_bytes: 1212
//submitting previously written code, to keep track of my progress. 
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <algorithm>
#include <limits.h>
#include <bits/stdc++.h>
#define fw(x) freopen("x.txt","w",stdout)
#define For(i,a,b,c) for(int i = a;i < b;i+=c)
#define REP(i,n) for(int i = 0;i < n;++i)
#define REP1(i,n) for(int i = 1; i<=n;i++)
#define mem(a,s) memset(a,s,sizeof a)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#define pf printf
#define sc scanf
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define vii vector<int>
#define vll vector<ll>
#define vss vector<string>
#define debug(x)  cout<<#x"="<<(x)<<endl
#define pb push_back


using namespace std;


// moves

//int dx[]= {0,0,1,-1};/*4 side move*/
//int dy[]= {-1,1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/


//big_mod

//ll bigmod(ll a,ll b,ll m)
//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}
//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}
//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}
//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}

const int mod = 1000000007;

    int cost[101];
    int wt[101];
    ll dp[101][100001];
int main()
{
    fast;
    int n, w;
    cin>>n>>w;
    REP1(i, n) cin>>wt[i]>>cost[i];
    REP(i, n+1){
      REP(j, 100001){
        if(j==0) dp[i][j] = 0;
        else if(i==0) dp[i][j] = INT_MAX;
        else{
          if(j>=cost[i]) dp[i][j] = min(dp[i-1][j], dp[i-1][j-cost[i]] + wt[i]);
          else dp[i][j] = dp[i-1][j];
        }
      }
    }
    ll ans = 0;
    REP(i, 100001) if(dp[n][i]<=w) ans = i;
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 82516
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstdlib>
using namespace std;
const int M=10000;
long long int a,b,x;
int main()
{
  cin>>x;
  cin>>a;
  cin>>b;
  cout<<(x-a)%b;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
const int _=1e2;
const int maxn=2e5+_;

int Log[maxn],mn[30][maxn],mx[30][maxn];
int MN(int x,int y)
{
	int k=Log[y-x+1];
	return min(mn[k][x],mn[k][y-(1<<k)+1]);
}
int MX(int x,int y)
{
	int k=Log[y-x+1];
	return max(mx[k][x],mx[k][y-(1<<k)+1]);
}

bool cc[maxn];
int main()
{
	int n,k,ans,s=0;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&mn[0][i]),mx[0][i]=mn[0][i];
		if(mn[0][i]>mn[0][i-1])s++;
		else s=1;
		if(s>=k)cc[i-k+1]=true;
	}
		
	Log[1]=0;for(int i=2;i<=n;i++)Log[i]=Log[i/2]+1;
	for(int j=1;(1<<j)<=n;j++)
		for(int i=1;i+(1<<j)-1<=n;i++)
		{
			mn[j][i]=min(mn[j-1][i],mn[j-1][i+(1<<j-1)]);
			mx[j][i]=max(mx[j-1][i],mx[j-1][i+(1<<j-1)]);
		}
			
	ans=n-k+1; bool bk=cc[1];
	for(int i=1;i+k<=n;i++)
	{
		bool re=false;
		if(MN(i,i+k)==mn[0][i]&&MX(i,i+k)==mx[0][i+k])ans--,re=true;
		if(cc[i+1])
		{
			if(bk&&!re)ans--;
			bk=true;
		}
	}
	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 33792
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
        
    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
        
    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)
        
        if x==y:
            return 
        
        if self.parents[x]>self.parents[y]:
            x,y=y,x
            
        self.parents[x]+=self.parents[y]
        self.parents[y]=x
        
    def size(self,x):
        return -self.parents[self.find(x)]
    
    def same(self,x,y):
        return self.find(x)==self.find(y)
    
    def members(self,x):
        root=self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]
    
    def roots(self):
        return [i for i,x in enumerate(self.parents) if x<0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r:self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r,self.members(r))for r in self.roots())

n,m=map(int,input().split())
INF=float('inf')
uf=UnionFind(n)
for _ in range(m):
  a,b=map(int,input().split())
  uf.union(a-1,b-1)
  
ans=-INF
for i in range(n):
  ans=max(ans,uf.size(i))
  
print(ans)

Measured memory_bytes: 79624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;

int main() {

	string s, t;
	cin >> s;
	cin >> t;

	bool b = true;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			b = false;
			break;
		}
	}
	if (b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
#define rep(i,m,n) for(int i=m;i<n;i++)

int main() {
  int n,a;
  int *p;

  cin >> n;
  p = new int[n];
  rep(i,0,n) cin >> p[i];

  a = 0;
  rep(i,1,n-1){
    if( (p[i-1]<p[i] && p[i]<p[i+1]) || (p[i+1]<p[i] && p[i]<p[i-1]) ) a++;
    
  }
  cout << a << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

double snuke(int n){
    int m = n;
    int s = 0;
    while(m != 0){
        s += m % 10;
        m /= 10;
    }
    return (double)n / s;
}

signed main(){
    int k;
    cin >> k;

    vector<int> a;

    rep(i, 15){
        for(int j = 1; j < 150; j++){
            int x = j;
            rep(k, i){
                x *= 10;
                x += 9;
            }
            a.push_back(x);
        }
    }
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());

    vector<bool> sn((int)a.size(), true);
    rep(i, (int)a.size()){
        for(int j = i+1; j < (int)a.size(); j++){
            if(snuke(a[i]) > snuke(a[j])){
                sn[i] = false;
            }
        }
    }

    vector<int> ans;
    rep(i, (int)a.size()){
        if(sn[i]){
            ans.push_back(a[i]);
        }
    }

    rep(i, k){
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int mincost(int arr[],int n)
{
    int dp[n];
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
    {
       dp[i]=min(dp[i-2]+abs(arr[i-2]-arr[i]),dp[i-1]+abs(arr[i-1]-arr[i]));
    }
    return dp[n-1];
}
int main() {
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    cout<<mincost(arr,n)<<endl;
    //cout<<"Hello World!";
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
const int sq=10000;
const int mod=1e9+7;
int n,a,b;
inline int kuai(int p,int q,int mod) {int tot=1;for(;q;p=(ll)p*p%mod,q>>=1) if(q&1) tot=(ll)tot*p%mod;return tot;}
inline int C(int x,int y) {
	int tot=1;
	for(res i=1;i<=y;++i) tot=(ll)tot*kuai(i,mod-2,mod)%mod;
	for(res i=x-y+1;i<=x;++i) tot=(ll)tot*i%mod;
	return tot;
}
int main()
{
	read(n),read(a),read(b);
	int tot=kuai(2,n,mod)-1;
	tot=(tot-C(n,a)+mod)%mod,tot=(tot-C(n,b)+mod)%mod;
	print(tot,'\n');
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec[i];
  }
  vector<int> bigger(N-1,0);
  for(int i=0; i<N-1; i++){
    if(vec[i] < vec[i+1]){
      bigger[i] = 1;
    }
  }
  
  set<int> S;
  int ans = 1;
  int cnt = 0;
  for(int i=0; i<K; i++){
    S.insert(vec[i]);
    if(i != 0){
      cnt += bigger[i-1];
    }
  }
  
  bool arrange = false;
  
  if(cnt == K-1){
    arrange = true;
  }
  
  

  
  for(int i=K; i<N; i++){
    auto itr_min = S.begin();
    S.insert(vec[i]);
    auto itr_max = S.rbegin();
    cnt -= bigger[i-K];
    cnt += bigger[i-1];
    if(*itr_min != vec[i-K] || *itr_max != vec[i]){
      if(cnt != K-1){
        ans++;
      }
      else if(!arrange){
        ans++;
        arrange = true;
      }
    }
    S.erase(vec[i-K]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 14256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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; }
const int64_t INF = 1LL << 60;

int main() {
 int N;
 cin>>N;
 vector<int>a(N);
 for(int i=0;i<N;i++){
   cin>>a[i];
 }
 int count=0;
 for(int i=0;i<N;i++){
   while(i<N-1&&a[i]==a[i+1]){i++;}
   if(i<N-1&&a[i+1]>a[i]){while(a[i+1]>=a[i]){i++;}}
   else if(i<N-1&&a[i+1]<a[i]){while(a[i+1]<=a[i]){i++;}}
   count++;
 }
 cout<<count<<endl;
  return 0;}

Measured memory_bytes: 640
N,M = map(int, input().split())
L = [0] * M
R = [0] * M
maxL = 1
minR = N

for i in range(M):
    L[i], R[i] = map(int, input().split())
    maxL = max([maxL, L[i]])
    minR = min([minR, R[i]])

ans = minR - maxL + 1
print(max([ans,0]))

Measured memory_bytes: 10868
fun main(args: Array<String>) = println(run {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val a = (1..n).map { readLine()!! }
    val b = (1..m).map { readLine()!! }

    (0..n-m).any { x ->
        (0..n-m).any { y ->
            b == a.slice(y..y+m-1).map { it.slice(x..x+m-1) }
        }
    }.let { if(it) "Yes" else "No" }
})


Measured memory_bytes: 37876
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    string s,t;
    cin >> s >> t;
    map<char,int> smp,tmp;
    map<char,char> change;
    REP(i,s.length())smp[s[i]]++;
    REP(i,t.length())tmp[t[i]]++;
    if(smp.size() < tmp.size()){
        cout << "No" << endl;
        return 0;
    }
    REP(i,s.length()){
        if(change.find(t[i]) != change.end() && change[t[i]] != s[i]){
            cout << "No" << endl;
            return 0;
        }
        //cout << change[t[i]] << " " << s[i] <<endl;
        change[t[i]] = s[i];
    }
    
    cout << "Yes" << endl;
    
    return 0;
}

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

struct State{
    int x,y,t;
    int sc;
};

int dx0[]={0,1,1,0,-1,-1,0};
int dy0[]={1,0,-1,-1,-1,0,0};
int dx1[]={0,1,1,0,-1,-1,0};
int dy1[]={1,1,0,-1,0,1,0};
int main(){
    int sx,sy,gx,gy;
    cin>>sx>>sy>>gx>>gy;
    int n;
    cin>>n;
    vector<int> x(n),y(n);
    for(int i=0;i<n;i++) cin>>x[i]>>y[i];
    int lx,ly;
    cin>>lx>>ly;
    
    int X=2*lx+3;
    int Y=2*ly+3;
    int offX=lx+1;
    int offY=ly+1;
    gx+=offX,gy+=offY;
    sx+=offX,sy+=offY;
    for(int i=0;i<n;i++){
        x[i]+=offX;
        y[i]+=offY;
    }
    
    vector<vector<int>> obj(X,vector<int>(Y,0));
    for(int i=0;i<X;i++){
        obj[i][0]=true;
        obj[i][Y-1]=true;
    }
    for(int i=0;i<Y;i++){
        obj[0][i]=true;
        obj[X-1][i]=true;
    }
    for(int i=0;i<n;i++){
        obj[x[i]][y[i]]=true;
    }

    const int INF=1e8;
    vector<vector<vector<int>>> ans(X,vector<vector<int>>(Y,vector<int>(6,INF)));


    deque<State> que;
    que.push_front(State{sx,sy,0,0});
    ans[sx][sy][0]=0;

    while(!que.empty()){
        auto st=que.front();
        que.pop_front();
        if(ans[st.x][st.y][st.t]<st.sc) continue; 
        int nt=(st.t+1)%6;
        int dir=(abs((st.x-offX)*(st.y-offY)*st.t)%6+6)%6;
        
        for(int i=0;i<7;i++){
            int tox=st.x+((st.x-offX)%2 ? dx1[i] : dx0[i]);
            int toy=st.y+((st.x-offX)%2 ? dy1[i] : dy0[i]);
            if(obj[tox][toy]) continue;
            if(dir==i){
                if(ans[tox][toy][nt]<=st.sc) continue;
                ans[tox][toy][nt]=st.sc;
                que.push_front(State{tox,toy,nt,st.sc});
            }
            else{
                if(ans[tox][toy][nt]<=st.sc+1) continue;
                ans[tox][toy][nt]=st.sc+1;
                que.push_back(State{tox,toy,nt,st.sc+1});
            }
            
        }
    }
    int res=*min_element(ans[gx][gy].begin(),ans[gx][gy].end());
    cout<<(res<INF ? res : -1)<<endl;
    return 0;
}


Measured memory_bytes: 5544
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  std::string S; std::cin >> S;


  for(int i=0; i<sz(S); i++) {
    if ( i < sz(S)-1 ) {
      auto s = S.substr(i,2);
      if ( s[0] == s[1] ) {
        std::cout << i+1 << " " << i+2 << std::endl;
        return 0;
      }
    }
    if ( i < sz(S) -2 ) {
      auto s = S.substr(i,3);
      if ( s[0] == s[2] ) {
        std::cout << i+1 << " " << i+3 << std::endl;
        return 0;
      }
    }
  }
  std::cout << -1 << " " << -1 << std::endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<string>
#include<set>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include <cctype>
#include <cstdio>
#define endl '\n'
#define Bedoazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

const long long N = 1e5 + 5;


int main() {

    Bedoazim

    long long n, arr[N], k;

    cin >> n >> k;

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

        cin >> arr[i];

    }
    

       cout << (n+k-3)/(k-1) << endl;

}

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

int main() {
  int N;
  cin >> N;
  double sum=0;
  for(int i=0;i<N;i++){
    double a;
    cin >> a;
    string b;
    cin >> b;
    if(b=="BTC"){
      a*=380000;
    }
    sum+=a;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

int N;
long long taka, aosh;

int main(){
  ios_base::sync_with_stdio(false); 
  cin >> N;
  taka = 1LL, aosh = 1LL;
  for(int i=0; i<N; ++i){
    int t, a; cin >> t >> a;
    long long p = max((taka+t-1)/t, (aosh+a-1)/a);
    taka = t*p;
    aosh = a*p; 
  }
  cout << taka + aosh << "\n";
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include <math.h>
#include <string>
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i]>>y[i];
typedef long long int ll;
const ll INF =1LL << 62;
using namespace std;
int MAX_E=1000010;
ll dp[1000010];
void split(string s, vector<string> &v){
    v.clear();
    s +='"';
    string str="";
    for(int i=0;i<s.size();i++){
        if(s[i]=='"'){
            v.push_back(str);
            str="";
        }
        else{
            str+=s[i];
        }
    }
}
int main(){
    while(1){
        string s1,s2; cin >>s1;
        if(s1==".")break;
        cin >> s2;
        if(s1==s2){
            cout << "IDENTICAL"<< endl;
        }
        else{
            vector<string> v1,v2;
            split(s1,v1);
            split(s2,v2);
            if(v1.size()!=v2.size()){
                cout << "DIFFERENT" << endl;
            }
            else{
                bool a=false;
                int cnt=0;
                for(int i=0;i<v1.size();i++){
                    if(i%2==0){
                        if(v1[i]!=v2[i])a=true;
                    }
                    else{
                        if(v1[i]!=v2[i])cnt++;
                    }
                }
                if(a){
                    cout << "DIFFERENT" << endl;
                }
                else if(cnt>1){
                    cout << "DIFFERENT" << endl;
                }
                else{
                    cout << "CLOSE" << endl;
                }
            }
        }
    }
}


Measured memory_bytes: 3156
#include <stdio.h>

int main(){
	char ch;
	while((ch = getchar()) != EOF){
			if(ch >= 97 && ch <= 122)
				printf("%c",ch-32);
			else if(ch >= 65 && ch <= 90)
				printf("%c",ch+32);
			else
				printf("%c",ch);
	}
}


Measured memory_bytes: 2520
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll gcd(ll x,ll y){
	ll r;
	r=x%y;
	if(r==0) return y;
	else return gcd(y,r);
}
int main(){
	ll x,y;
	cin>>x>>y;
	cout<<x*y/gcd(x,y);
	return 0;
}

Measured memory_bytes: 256
s = input()
s_split = [s[i] for i in range(len(s))]
result = 0

for i in range(2**(len(s)-1)):
    b = bin(i)[2:]
    b = b.zfill(len(s)-1)
    tmp = s_split.copy()

    for j in range(len(b)-1, -1, -1):
        if b[j] == "1":
            tmp.insert(-j-1, "+")

    before = ""
    num = 0
    for x in range(len(tmp)):
        if tmp[x] == "+":
            num += int(before)
            before = ""
        else:
            before += tmp[x]
    if len(before) != 0:
        num += int(before)
    result += num
print(result)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける



int main() {
	int n;
	string s;

	cin >> n >> s;
	
	char c;

	rep(i, s.size()) {
		c = s.at(i);
		c += n;
		if (c - 'Z' > 0) c -= ('Z' - 'A' + 1);
		cout << c;
	}
	cout << endl;
}

Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

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



int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	int w[n];
	int sum = 0;
	forn(i, n)cin >> w[i], sum += w[i];
	int csum = 0, ans = 4545454;
	forn(i, n){
		csum += w[i];
		sum -= w[i];
		ans = min(ans, abs(sum - csum));
	}
	cout << ans << '\n';
	return 0;
}


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

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

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int n, t, sum, mx;
int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> t;
        sum += t;
        mx = max(mx, t);
    }
    if (sum - mx > mx)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

const int NUM = 4;
string divide[NUM] = { "dream", "dreamer", "erase", "eraser" };

int main()
{
	string str;
	cin >> str;

	reverse( str.begin(), str.end() );
	for ( int i = 0; i < NUM; ++i ) {
		reverse( divide[i].begin(), divide[i].end() );
	}

	bool can1 = true;
	for ( size_t i = 0; i < str.size(); ) {
		bool can2 = false;
		for ( int j = 0; j < NUM; ++j ) {
			string d = divide[j];
			if ( str.substr( i, d.size() ) == d ) {
				can2 = true;
				i += d.size();
				break;
			}
		}
		if ( !can2 ) {
			can1 = false;
			break;
		}
	}

	cout << ( can1 ? "YES" : "NO" ) << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int N,ans;

void dfs(int cur,int mask){
    if(cur>N) return;
    if(mask==7) ans++;
    dfs(cur*10+7,mask|4);
    dfs(cur*10+5,mask|2);
    dfs(cur*10+3,mask|1);
}

signed main()
{
    cin>>N;
    dfs(0,0);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;
import std.math;

void main()
{
    foreach(s;stdin.byLine())
    {
        alias real T;
        auto m = s.split().map!(to!T)();
        immutable a=m[0], b=m[1], c=m[2], d=m[3], e=m[4], f=m[5];
        T solve(T a, T b, T c, T d, T e, T f)
        {
            return round((c*e-f*b)*1000/(a*e-d*b))/1000+0;
        }
        writefln("%.3f %.3f",solve(a,b,c,d,e,f),solve(b,a,c,e,d,f));
    }
}

Measured memory_bytes: 1132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
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; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    if(s[0]==s[1] && s[1]==s[2]&&s[2]==s[0]) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    MOD = 998244353
    N = I()
    D = LI()

    if D[0] != 0:
        print(0)
        return

    if any([d == 0 for d in D[1:]]):
        print(0)
        return

    MAX_D = max(D)
    node = [0] * (MAX_D + 1)

    for i in range(N):
        node[D[i]] += 1

    # print(node)
    ans = 1
    for i in range(1, len(node)):
        ans *= node[i-1] ** node[i]
        ans %= MOD
    print(ans % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 57392
//coded by: pranonrahman-------------------------------------
//-----------------------------------------------------------
//-----------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;


#define O_O ios_base::sync_with_stdio(0); cin.tie(NULL)
#define endl '\n'
#define PI acos(-1.0)
#define CASE(n) cout << "Case " << n << ": "
#define CASE_(n) cout << "Case " << n << endl
#define FIXED(n) cout << fixed << setprecision(n)
#define MOD 1000000007

inline void normal(long long &a) { a %= MOD; (a < 0) && (a += MOD); }
inline long long modMul(long long a, long long b) { normal(a), normal(b); return (a*b)%MOD; }
inline long long modAdd(long long a, long long b) { normal(a), normal(b); return (a+b)%MOD; }
inline long long modSub(long long a, long long b) { normal(a), normal(b); a -= b; normal(a); return a; }
inline long long modPow(long long b, long long p) { long long r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline long long modInverse(long long a) { return modPow(a, MOD-2); }
inline long long modDiv(long long a, long long b) { return modMul(a, modInverse(b)); }


int main()
{
    O_O;
#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
#endif
    long long t=1;
    //cin >> t;
    long long T = t;
    while(t--)
    {
        //write your code here
        string s;
        cin >> s;
       	string s1 = "",s2="";
       	for(int i=0;i<500000;i++)
       	{
       		if(i%2==0)
       		{
       			s1.push_back('1');
       			s2.push_back('0');
       		}
       		else 
       		{
       			s1.push_back('0');
       			s2.push_back('1');
       		}
       	}
       	int c1=0,c2=0;
       	for(int i=0;i<s.size();i++)
       	{
       		if(s[i]!=s1[i])	c1++;
       		if(s[i]!=s2[i])	c2++;
       	}
       	cout << min(c1,c2) << endl;
    }
    return 0;
}




Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(long long N, long long A, long long B){
    cout << min(B, A*N) << endl;
}

int main(){

    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}



Measured memory_bytes: 256