akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stack>
using namespace std;
typedef long long ll;
ll mod=1e9+7;
ll add(ll x,ll y){return (x+y)%mod;}
ll mul(ll x,ll y){return (x*y)%mod;}
ll pow(ll x,ll y){
  ll v=1;
  for(;y;x=mul(x,x),y>>=1)
    if(y&1)v=mul(v,x);
  return v;
}

int H,W;

ll y[100005];
ll ky[100005];

ll x[100005];
ll kx[100005];

int main(){
  cin>>H>>W;


  ll total=0;
  for(int i=0;i<H;i++){
    cin>>y[i];
    
    if(i){
      ky[i-1]=mul(y[i]-y[i-1], mul(i, H-i) );
      total=add(total,ky[i-1]);
    }
  }

  ll ans=0;
  for(int i=0;i<W;i++){
    cin>>x[i];
    if(i){
      kx[i-1]=mul(x[i]-x[i-1], mul(i, W-i) );
      ans=add(ans, mul(total,kx[i-1]) );
    }
  }
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(int i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(int i=a;i<=n;i++)
#define inf 1000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=100005;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
int n,vis[N],x,y;
vi gr[N];
int dp[N][2];
int dfs(int u,int col,int par){
	if(u==par) return 0;
	int ans=1;
	if(gr[u].size()==1&&u!=1) return dp[u][col]=1;
	if(dp[u][col]!=-1) return dp[u][col];
	for(int i=0;i<gr[u].size();i++){
		int v=gr[u][i];
		if(v==par) continue;
		if(col==1){
			ans=(1LL*ans*dfs(v,0,u))%mod;
		}
		else{
			ans=(1LL*ans*(dfs(v,0,u)%mod*1LL+dfs(v,1,u))%mod)%mod;
		}
	}
	return dp[u][col]=ans;
}
int main(){
	fast
	cin>>n;
	mem(dp,-1);
	if(n==1){
		cout<<2;return 0;
	}
	FOR0(n-1){
		cin>>x>>y;
		gr[x].pb(y);
		gr[y].pb(x);
	}
	cout<<(1LL*dfs(1,1,-1)+ dfs(1,0,-1))%mod;
}



Measured memory_bytes: 14848
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
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;}




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

    bool ans = false;
    for(ll i = 120; i > -120 ; i--){
        for(ll j = -120; j < 120; j++){
            if(X == (pow(i,5) - pow(j,5))){
                cout << i << " " << j << endl;
                ans = true;
                if(ans) break;
            }
        }
        if(ans) break;
    }

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

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

#define Max 			1e6
#define ff              first
#define ss              second
#define ll              long long
#define pb              push_back
#define ppb				pop_back
#define pf				push_front
#define ppf				pop_front
#define mp              make_pair
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define v 				vector
#define mii             map<ll,ll>
#define umap			unordered_map
#define pq              priority_queue<ll>
#define pqm             priority_queue<ll,vi,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            ll x; cin>>x; while(x--)
#define all(x)			x.begin(),x.end()
#define sp 				' '
#define pi 				3.14159265359
#define intmax 			INT32_MAX
#define intmin			INT32_MIN
#define conti           continue
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
ll d8[8][2] = {{ -1, -1}, { -1, 0}, { -1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};
ll d4[4][2] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}};
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
/* ordered set:
tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
member functions :
1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/
void IO()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}
void fastIO()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}




int main()
{
	fastIO();
	IO();
	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll p1 = 0;
	ll p2 = n - 1;
	ll c = 0;
	while (p1 < p2)
	{
		if (s[p1] == 'R' && s[p2] == 'W')
		{
			p1++;
			p2--;
		}
		if (s[p1] == 'W' && s[p2] == 'R')
		{
			c++;
			p1++;
			p2--;
		}
		if (s[p1] == 'W' && s[p2] == 'W')
		{
			p2--;
		}
		if (s[p1] == 'R' && s[p2] == 'R')
		{
			p1++;
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 3780
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
#define ll int
typedef unsigned long long ull;
typedef long double ld;

#define pii         pair<ll ,ll >
#define vi          vector<ll >
#define vii         vector<pii>
#define mi          map<ll ,ll >
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define pb          push_back
#define hell        1000000007 
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define take        rep(i,0,n) cin>>v[i];
#define MAXN        200005


#define allr(c) (c).rbegin(),(c).rend()
int mod = 998244353;
const int inf = 1034567891;
const long long LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(long long x, long long y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(ll x, ll y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(ll x, ll y){ return (x * 1ll * y) % mod;}
inline ll powr(ll a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline long long inv(long long a){ return powr(a, mod - 2);}
ll Powb(ll b,ll n,ll m)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2,m);
    if(n%2==0){return (temp*temp)%m;}
    else{return (b*((temp*temp)%m))%m;}
}


void solve()
{
	ll n,x,t;
	cin>>n>>x>>t;
	ll p=n/x+(n%x>0?1:0);
	cout<<t*p<<endl;
	
}
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);                                                        
      
    ll t;
        
    t=1;
   
    
  // cin>>t;
    while(t--)
    solve();
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
using namespace std;struct edge{int to,next;}e[200005];
int tot=0,last[200005],a[200005];bool ans[200005],vis[200005];
inline void adde(int u,int v) {e[++tot]=(edge){v,last[u]},last[u]=tot;return;}
void dfs(int root) {if (vis[root]) return;vis[root]=1;
	for (register int i=last[root];i;i=e[i].next) dfs(e[i].to),ans[root]|=!ans[e[i].to];return;
}int main() {int n,u,v;//freopen("game.in","r",stdin),freopen("game.out","w",stdout);
	scanf("%d",&n);for (register int i=1;i<=n;++i) scanf("%d",a+i);
	for (register int i=1;i<n;++i) {scanf("%d%d",&u,&v);
		if (a[u]>a[v]) adde(u,v);if (a[u]<a[v]) adde(v,u);
	}for (register int i=1;i<=n;++i) {dfs(i);if (ans[i]) printf("%d ",i);}return 0;
}

Measured memory_bytes: 256
n = int(input())
ans = [0] * n
if n >= 100: N = 100
else: N = n
for x in range(1,N+1):
    for y in range(1, N+1):
        for z in range(1, N+1):
            a =  x**2 + y**2 + z**2 + x*y + y*z + z*x
            if a <= n:
                ans[a-1] += 1
for i in ans: print(i)

Measured memory_bytes: 9240
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int cnt = 0;
    while(a >= b){
        b*=2;
        cnt++;
    }
    while(b >= c){
        c*=2;
        cnt++;
    }
    if(cnt <= x) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)


// Write From This Line
int main()
{
	char s[4];
	scanf("%s",s);
	if(s[0] == '7' || s[1] == '7' || s[2] == '7') puts("Yes");
	else puts("No");
}


Measured memory_bytes: 3764
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

double stack[100];
int top;

void push(double n);
double pop(void);

int main(void)
{
    char str[100];
	char str1[100];
    char *token;
	double temp1;
	double temp2;
    int i;

    // extras
    int flag;

    // scanf("%[^\n]%*c", str) != EOF

    while (fgets(str1, sizeof(str1), stdin)){

        // 初期化
        flag = 0;
        top = 0;
        for (i = 0; i < 100; i++){
            stack[i] = 0;
        }
		
        // strにstr1の'\n'の前までをコピーする
		strncpy(str, str1, strlen(str1) - 1);
		str[strlen(str1) - 1] = '\0';

        token = strtok(str, " ");   // get first string before first " "

        while (token != NULL){
			// printf("[%s] ", token);
			
            if (strncmp(token, "+", 2) == 0){
                push(pop() + pop());
            }
            else if (strncmp(token, "-", 2) == 0){
                temp1 = pop();
                temp2 = pop();

                push(temp2 - temp1);
            }
            else if (strncmp(token, "*", 2) == 0){
                push(pop() * pop());
            }
            else if (strncmp(token, "/", 2) == 0){
				temp1 = pop();
				temp2 = pop();
				
                if (temp1 == 0 && temp2 == 0){
                    flag = 1;
                    break;
                }
                else if (temp1 == 0){
                    flag = 1;
                    break;
                }
                else {
                    push(temp2 / temp1);
                }
            }
            else {
                push(atol(token));
            }
            token = strtok(NULL, " ");      // token = strtok(NULL, " \n"); pun boleh
        }
        if (flag != 0){
            continue;
        }
        printf("%lf\n", pop());      // final answer will still be in stack[0]
    }
    return (0);
}

void push(double n)
{
    stack[top] = n;
    // printf("push = %f\n", stack[top]);
    top++;
}

double pop(void)
{
	// printf("pop = %f\n", stack[top - 1]);
    return (stack[--top]);
}



Measured memory_bytes: 1988
#include <stdio.h>
int main(void){
	int n=0,a[100]={0},i=0,z=0;
	scanf("%d",&n);
	while(1){
		if(i>=n)break;
	scanf("%d",&a[i]);
	i++;
	}
	i=0;
	while(1){
		if(i>(n/2)-1)break;
		z=a[i];
		a[i]=a[n-i-1];
		a[n-i-1]=z;
		z=0;
		i++;
	}
	i=0;
	while(1){
		if(i>=n)break;
		if(i==0){printf("%d",a[i]);
		}else if(i==n){
			printf("%d",a[i]);
			}else{
		{printf(" %d",a[i]);}}
		i++;
			
	}
	printf("\n");
	return 0;
}

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

#define ll long long

ll gcd(ll a, ll b) {
   if (a < b) { // aの方が大きくなるようにする
      swap(a, b);
   }
   ll k = a % b;
   while (k) {
      a = b;
      b = k;
      k = a % b;
   }
   return b;
}

ll lcm(ll a, ll b) {
   ll c = gcd(a, b);
   return a / c * b;
}

int main() {
   int n;
   cin >> n;
   vector<ll> v(n);
   for (ll& x : v) cin >> x;

   if (n == 1) {
      cout << v[0] << endl;
      return 0;
   }

   ll a = lcm(v[0], v[1]);
   for (int i = 2; i < n; i++) {
      a = lcm(a, v[i]);
   }

   cout << a << endl;

   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,M;
  cin>>N>>M;
  priority_queue<int> A;
  for(int i=0;i<N;i++){
    int j;
    cin>>j;
    A.push(j);
  }
  for(int i=0;i<M;i++){
    A.push(A.top()/2);
    A.pop();
  }
  int j=0;
  while(!A.empty()){
    j+=A.top();
    A.pop();
  }
  cout<<j<<endl;
}

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

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

int gcd(int a, int b)
{
    if (b == 0) {
        return a;
    }
    else {
        return (gcd(b, a % b));
   }
}

int lcm(int a, int b)
{
    return ((a * b) / gcd(a, b));
}

int main()
{
    int n;
    int x[10];

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

    int ans = lcm(x[0], x[1]);

    FOR (i, 2, n) {
        ans = lcm(ans, x[i]);
    }
    cout << ans << endl;

    return (0);
}

Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void counting_sort(vector<int> &A, int n){

    int k = *max_element(A.begin(), A.end());
    vector<int> B(n+1);
    vector<int> C(k+1);

    for(int i=0; i<k; i++) C[i] = 0;
    for(int j=0; j<n; j++) C[A[j]]++;
    for(int i=1; i<=k; i++) C[i] = C[i] + C[i-1];

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

    for(int i=1; i<=n; i++){
        if(i != n){
            cout << B[i] << " ";
        }else{
            cout << B[i] << endl;
        }
    }
}

int main(){

    int n; cin >> n;
    vector<int> A(n);
    for(int i=0; i<n; i++) cin >> A[i];

    counting_sort(A,n);
    
    return 0;
}

Measured memory_bytes: 18284
#include <iostream>

using namespace std;

int main(void) {
  int button_a;
  int button_b;

  cin >> button_a >> button_b;

  int sum = 0;

  for (int i = 0; i < 2; i++) {
    if (button_a >= button_b) {
      sum += button_a;
      button_a --;
    } else {
      sum += button_b;
      button_b --;
    }
  }

  cout << sum << '\n';

  return 0;
}

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

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

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N;
  cin >> N;
  int t[N], x[N], y[N];
  for (int i = 0; i < N; i++) cin >> t[i] >> x[i] >> y[i];

  int nx = 0, ny = 0, nt = 0;
  string ans = "Yes";
  for (int i = 0; i < N; i++) {
    int tmp = abs(x[i] - nx) + abs(y[i] - ny);
    if (tmp <= t[i] - nt) {
      if (((t[i] - nt) & 1) != (tmp & 1)) {
        ans = "No";
        break;
      }
    } else {
      ans = "No";
      break;
    }

    nx = x[i]; ny = y[i]; nt = t[i];
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1408
MAX = 10000000

N = int(input())
human_points = list(map(lambda x: int(x), input().split()))

min_sum = MAX

for i in range(1, 100):
  tmp_sum = 0
  for point in human_points:
    tmp_sum += (point - i)**2
  if min_sum > tmp_sum:
    min_sum = tmp_sum
print(min_sum)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    string S;
    cin>>S;
    int n=S.size();
    int l[n+1]={},r[n+1]={};
    int ans=0;
    rep(i,n){
        if(S[i]=='<'){
            if(i==0) l[i]=0;
            l[i+1]=l[i]+1;
        }
    }
    for(int i=n-1;i>=0;i--){
        if(S[i]=='>'){
            if(i==n-1) r[i+1]=0;
            r[i]=r[i+1]+1;
        }
    }
    rep(i,n+1){
        ans+=max(l[i],r[i]);
    }
     cout << ans << endl;



}


Measured memory_bytes: 8732
/*
No not today :3
*/
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define mod 1000000007
#define ll_inf 1000000000000000
#define int_inf 1000000000
#define mp make_pair
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define eps 1e-9
#define PI acos(-1.0)
using namespace std;
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }
ll POWER(ll x,ll y, ll m){
    if(y==0) return 1;
    if(y%2==0) { ll temp= POWER(x,y/2,m);   temp*=temp; temp%=m;	return temp;}
    ll temp= POWER(x,y-1,m);    temp*=x;	temp%=m;	return temp;
}

ll POWER(ll x,ll y){
    if(y==0) return 1;
    if(y%2==0) { ll temp= POWER(x,y/2);   temp*=temp;  return temp;	}
    ll temp= POWER(x,y-1);    temp*=x;	return temp;
}

int main(){
    //cout.precision(12);
    ifstream fin("ali");
    ll n,k;
    cin>>n>>k;
    cout<<3*(n-gcd(n,k))<<endl;
}


Measured memory_bytes: 256
#include<string>
#include<iostream>
using namespace std;
int main(){
  int a[3]={};
  int acheck[3]={};
  int b[3]={};
  int bcheck[3]={};
  int c[3]={};
  int ccheck[3]={};
  int i;
  int j;
  int bingoflag=0;
  cin>>a[0]>>a[1]>>a[2]>>b[0]>>b[1]>>b[2]>>c[0]>>c[1]>>c[2];
  int check[10];
  for(i=0;i<=9;i++){
  cin>>check[i];
  }
  for(i=0;i<=9;i++){
  for(j=0;j<=2;j++){
    if(a[j]==check[i]){
    acheck[j]=1;
    }
    if(b[j]==check[i]){
    bcheck[j]=1;
    }
    if(c[j]==check[i]){
    ccheck[j]=1;
    }
  }
  }
  if(acheck[0]==1&&acheck[1]==1&&acheck[2]==1){
    bingoflag=1;
  }
   if(bcheck[0]==1&&bcheck[1]==1&&bcheck[2]==1){
    bingoflag=1;
  }
   if(ccheck[0]==1&&ccheck[1]==1&&ccheck[2]==1){
    bingoflag=1;
  }
  if(acheck[0]==1&&bcheck[0]==1&&ccheck[0]==1){
  bingoflag=1;
  }
   if(acheck[1]==1&&bcheck[1]==1&&ccheck[1]==1){
  bingoflag=1;
  }
    if(acheck[2]==1&&bcheck[2]==1&&ccheck[2]==1){
  bingoflag=1;
  }
    if(acheck[0]==1&&bcheck[1]==1&&ccheck[2]==1){
  bingoflag=1;
  }
    if(acheck[2]==1&&bcheck[1]==1&&ccheck[0]==1){
  bingoflag=1;
  }
  if(bingoflag==1){
  cout<<"Yes";
  }
  else{
  cout<<"No";
  }
}

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

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

    int count_AC[N];
    int count_WA[N];

    for (int i = 0; i < N; i++){
        count_AC[i] = 0;
        count_WA[i] = 0;
    }

    int P[M];
    string S[M];
    string tmp[N];

    for (int i = 0; i < N; i++){
        tmp[i] = "WA";
    }

    for(int i = 0; i < M; i++){
        cin >> P[i] >> S[i];

        if (tmp[P[i]-1] == "WA" && S[i] == "AC"){
            count_AC[P[i]-1]++;
            tmp[P[i]-1] = "AC";
        }
        else if(tmp[P[i]-1] == "WA" && S[i] == "WA"){
            count_WA[P[i]-1]++;
        }
    }

    int AC = 0;
    int WA = 0;

    for (int i = 0; i < N; i++){
        if (tmp[i] == "AC"){
            AC += count_AC[i];
            WA += count_WA[i];
        }
    }

    cout << AC << " " << WA << endl;
}


Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a = n%10;
	
	if(a == 3){
		cout << "bon";
    	return 0;
  	}
  	
  	else if(a == 0 || a == 1 || a == 6 || a == 8){
		cout << "pon";
    	return 0;
  	}
  	
	else{
		cout << "hon";
    	return 0;
  	}
  	return 0;
}

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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if(A + B > C + D) {
    cout << "Left" <<endl;
  }
  if(A + B == C + D) {
    cout << "Balanced" <<endl;
  }
  if(A + B < C + D) {
    cout << "Right" <<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdlib>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
int n,K;
ll dp[310][310],a[310];
int main()
{
	cin>>n>>K;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    memset(dp,inf,sizeof(dp));
    dp[0][0]=0;
    ll ans=1e15;
    for(int i=1;i<=n;i++)
    for(int j=0;j<i;j++)
    for(int k=i-1;k>=0;k--)
    dp[i][k+1]=min(dp[i][k+1],dp[j][k]+max(0ll,a[i]-a[j]));
    for(int i=0;i<=n;i++)
    for(int j=0;j<=n;j++)
    if(j>=n-K) ans=min(ans,dp[i][j]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  int n,h;
  int max=0,count=0;
  cin >> n;
  
    while(n--){
    cin >> h;
    if(max<=h){
      max = h;
      count++;
    }
  }
  cout << count << endl;
  return 0;
  
}

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

const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    ll N;
    cin >> N;
    vector<ll> DP(N+1,0);//,memo(N, 0);
    vector<ll> A(N);
    vector<ll> C(N+1,0);
    rep(i,N){
        cin >> A[i];
    }
    C[0] = 3;
    ll sum = 1;
    rep(i,N){
      sum *= C[A[i]];
      sum %= mo;
      C[A[i]]--;
      if(C[A[i]] < 0){
        cout << 0 << endl;
        return 0;
      }
      C[A[i]+1]++;
      if(C[A[i]] > 3){
        cout << 0 << endl;
        return 0;
      }
    }
    cout << sum << endl;
    /*DP[0] = 1;
    rep(i,N){
        memo[A[i]]+=1;
        cout << "memo[]"<<memo[A[i]] << endl;
        mint tmp = 1;
        vector<ll> memo2;
        rep(i,memo.size()){
          memo2.push_back(memo[i]);
        }
        rep(j,int(A[i]+1)){
            memo2[j]--;
            tmp *= max(ll(1), memo2[j]);
        }
        DP[i+1] = tmp;*/
        /*
        if(A[i] == i){
            DP[i+1] = DP[i]*3;
        }else if(A[i] == 0 ){

        }*/
    //}
    //cout << DP[N] << endl;
}


Measured memory_bytes: 2560
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;

 main()

{
    fast
    int n,d;
    cin>>n>>d;
    d=d*d;
    int cnt=0;
    f(i,1,n)
    {
        int x,y;
        cin>>x>>y;
        x=x*x;
        y=y*y;
        x+=y;
        if(x<=d)
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;

}





































Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>


#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	string s; cin >> s;
	int n = 0;
	for (int i = 0; i < 3; i++) {
		n |= (s[i] - 'A' + 1);
	}
	cout << ((n == 3) ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(K: int):
    if K % 2 == 0:
        print(int((K/2)**2))
    else:
        print(int(K//2*(K//2+1)))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    K = int(input())
    solve(K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#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 rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
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() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    int n; cin >> n;
    VI a(n); cin >> a;
    int ans = 1;
    FOR(i, 0, n - 1)if (a[i] >= a[i + 1])++ans;
    cout << ans << "\n" << n << "\n";
}



Measured memory_bytes: 3124
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();
	}
}

class Pair {
	int a[];

}

class TaskB {

	public void solve(int testNumber, InputReader in, PrintWriter pw) {
		int X = in.nextInt();
		int i = 0, count = 0;
		while (i != 360) {
			i %= 360;
			i += X;
			count++;
		}
		pw.println(count);

	}

	int __gcd(int a, int b) {
		if (b == 0)
			return a;
		return __gcd(b, a % b);

	}

	public int getInt(int num) {
		int ret = -1;
		switch (num) {
		case 0:
			ret = 6;
			break;
		case 1:
			ret = 2;
			break;
		case 2:
			ret = 5;
			break;
		case 3:
			ret = 5;
			break;
		case 4:
			ret = 4;
			break;
		case 5:
			ret = 5;
			break;
		case 6:
			ret = 6;
			break;
		case 7:
			ret = 3;
			break;
		case 8:
			ret = 7;
			break;
		case 9:
			ret = 6;
			break;
		}
		return ret;
	}

	public int isPow(long num) {
		int count = 0;
		while (num > 0) {
			num /= 2;
			count++;
		}
		return count;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


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

int main(){
    string S; cin >> S;
    string s[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    rep(i, 0, 7) if(S == s[6-i]) cout << i + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
const int N = 1e5 + 5;
ll n, k, ans = INT_MAX, arr[N];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for(int i = 0;i < n;++i)
        cin >> arr[i];
    sort(arr, arr + n);
    for(int i = 0;i + k - 1 < n;++i)
        ans = min(ans, arr[i + k - 1] - arr[i]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <climits>
#include <stack>
#include <string>
#include <random>
#include<set>
#include <iomanip>
#include <climits>

class Probability {
	std::vector<double> key_probabilities, dummy_probabilities;
public:
	Probability(const std::vector<double> &keys, const std::vector<double> &dummies) {
		key_probabilities.push_back(0); dummy_probabilities.push_back(0);
		for (const auto k : keys) {
			key_probabilities.push_back(key_probabilities.back() + k);
		}
		for (const auto d : dummies) {
			dummy_probabilities.push_back(dummy_probabilities.back() + d);
		}
	}
	double sum_key(const int from, const int until) const {
		return key_probabilities[until] - key_probabilities[from];
	}
	double sum_dummy(const int from, const int until) const {
		return dummy_probabilities[until] - dummy_probabilities[from];
	}
	double key(const int position) const {
		return key_probabilities[position + 1] - key_probabilities[position];
	}
	double dummy(const int position) const {
		return dummy_probabilities[position + 1] - dummy_probabilities[position];
	}
};
constexpr double NA = -1;
double sub_sequence(const int from, const int until, std::vector<std::vector<double>> &memo, const Probability &prob) {
	if (from == until) return prob.dummy(from);
	if (memo[from][until - from - 1] != NA) return memo[from][until - from - 1];
	double min = 500 * 500;
	for (auto mid = from; mid < until; ++mid) {
		auto seq = sub_sequence(from, mid, memo, prob) + sub_sequence(mid + 1, until, memo, prob) + prob.sum_key(from, until) + prob.sum_dummy(from, until + 1);
		if (min > seq) min = seq;
	}
	return memo[from][until - from - 1] = min;
}
int main() {
	int n; std::cin >> n;
	std::vector<double> key(n); for (auto &k : key) std::cin >> k;
	std::vector<double> dummy(n + 1); for (auto &d : dummy) std::cin >> d;
	Probability sum(key, dummy);
	std::vector<std::vector<double>> memo;
	for (auto i = 0; i < n; ++i) {
		memo.push_back(std::vector<double>(n - i, NA));
	}
	std::cout << sub_sequence(0, n, memo, sum) << std::endl;

}


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

using namespace std;


int main(void) {
    constexpr long MOD = 1e9 + 7;

    long n, m;
    cin >> n >> m;
    vector<long> a(n), b(m);
    for(auto &e: a) cin >> e;
    for(auto &e: b) cin >> e;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    long x = 0, y = 0;

    auto aidx = [&](long x) {
        auto i = lower_bound(a.begin(), a.end(), x) - a.begin();
        return a[i] == x ? i : -1;
    };
    auto bidx = [&](long x) {
        auto i = lower_bound(b.begin(), b.end(), x) - b.begin();
        return b[i] == x ? i : -1;
    };

    long r = 1;
    for(int i=m*n; i>=1; i--) {
        long ai = aidx(i), bi = bidx(i);

        if(ai>=0 && bi>=0) {
            x++, y++;
            continue;
        }

        if(ai>=0) {
            x++;
            r *= y, r %= MOD;
            continue;
        }

        if(bi>=0) {
            y++;
            r *= x, r %= MOD;
            continue;
        }

        r *= x*y - (m*n - i), r %= MOD;
    }

    cout << r << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a-1;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

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

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,N,H,W,ans;
  cin>>N>>H;
  cout<<N*(N-1)/2+H*(H-1)/2<<endl;
  return 0;
}

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

int main() {
  ll n,a,b; cin>>n>>a>>b;
  ll d=b-a;
  ll ans;
  if(d<0||(n==1&&d!=0)){ans=0;}
  else if(n==1){ans=1;}
  else{ans=d*(n-2)+1;}
  cout<<ans<<endl;
}
      

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int n = sc.nextInt();
        int atk = 0;
        for(int i = 0; i < n; i++){
            atk += sc.nextInt();
        }
        if(atk >= h){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}
 

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

using namespace std;

int main (void) {
    string N;
    int K;
    cin >> N >> K;
    vector<int> D(10, 1);
    for ( int i = 0; i < K; i++ ) {
        int d;
        cin >> d;
        D.at(d) = 0;
    }

    reverse(N.begin(), N.end());

    vector<int> available;
    for ( int i = 0; i < 10; i++ ) {
        if ( D.at(i) == 1 ) available.push_back(i);
    }

    int ans = 0;
    int digit = 1;
    int inc = 0;
    int len = N.size();
    for ( int i = 0; i < len; i++ ) {
        bool is_larger = false;

        int n = N.at(i) - '0' + inc;
        inc = 0;

        auto itr = lower_bound(available.begin(), available.end(), n);
        if ( itr == available.end() ) {
            inc = 1;
            n = available.at(0);
            is_larger = true;
        }
        else {
            if ( n < *itr ) is_larger = true;
            n = *itr;
        }

        if ( is_larger ) {
            /* 下位桁をすべて最小値に変更 */
            ans = 0;
            digit = 1;
            for ( int j = 0; j < i; j++ ) {
                ans += available.at(0) * digit;
                digit *= 10;
            }
        }

        /* 最終的な結果を格納 */
        ans += n * digit;
        digit *= 10;
    }
    if ( inc != 0 ) {
        /* 下位桁をすべて最小値に変更 */
        ans = 0;
        digit = 1;
        for ( int j = 0; j < len; j++ ) {
            ans += available.at(0) * digit;
            digit *= 10;
        }

        auto itr = lower_bound(available.begin(), available.end(), inc);
        assert(itr != available.end());
        ans += *itr * digit;
    }

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


Measured memory_bytes: 3572
# coding: utf-8
import sys
from math import sin, cos, radians

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

# 2点間の距離、x座標とy座標、複素数
A, B, H, M = lr()
d1 = radians(30 * H + 30 * M / 60)
d2 = radians(360 * M / 60)
x1, y1 = A * cos(d1), A * sin(d1)
x2, y2 = B * cos(d2), B * sin(d2)
c1 = complex(x1, y1)
c2 = complex(x2, y2)
answer = abs(c1-c2)
print(answer)


Measured memory_bytes: 9540
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
c = [0]*(n-1)
s = [0]*(n-1)
f = [0]*(n-1)

for i in range(n-1):
    c[i], s[i], f[i] = map(int, input().split())

def dfs(eki,t):
    if eki == n-1:
        return t

    cc = c[eki]
    ss = s[eki]
    ff = f[eki]

    m = max(0,-(-t+ss)//ff)
    if t < ss:
        return dfs(eki+1, ss+cc)
    elif t%ff==0:
        return dfs(eki+1, t+cc)
    else:
        return dfs(eki+1, t+ff-(t%ff)+cc)

for i in range(n):
    print(dfs(i,0))
    

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <complex>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>

#define rep(i, b) for(int i = 0; i < b; i++)
#define repi(i, a, b) for(int i = a; i < b; i++)
#define all(c) c.begin(),c.end()
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define MAX_V 1001
#define MAX_E 401
#define INF INT_MAX
#define MOD 1000000007
#define EPS 1e-7
typedef long long ll;
inline int toInt(std::string s) { int v; std::istringstream sin(s); sin >> v; return v; }
template<class T> inline std::string toString(T x) { std::ostringstream sout; sout << x; return sout.str(); }
using namespace std;

typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
#define X real()
#define Y imag()
typedef pair<int, int> pii;

int main()
{
	int count = 0;
	int A, B;
	cin >> A >> B;
	repi(i, A, B + 1)
	{
		string s = toString(i);
		if (s[0] == s[4] && s[1] == s[3])
			count++;
	}
	cout << count << endl;
	return 0;
}

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

public class Main {


	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int[] count = new int[4];
		for (int i = 0; i < 6; i++) {
			int n = in.nextInt();
			count[n-1]++;
		}
		boolean yes = Arrays.stream(count).filter(n -> n >= 3).count() == 0;
		System.out.println(yes ? "YES" : "NO");
	}
}


Measured memory_bytes: 26952
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using ii = pair<int, int>;
 
void solve();
 
clock_t start_time;
double get_current_time() {
	return (double)(clock() - start_time) / CLOCKS_PER_SEC;
}
 
int main() {
	// freopen("input.txt", "r", stdin);
	// freopen();

	ios_base::sync_with_stdio(false);
	solve();
}
 
/* ========== actual code starts here ========== */
 
#define fi first
#define re return
#define se second
#define in insert
#define pb push_back
#define eb emplace_back
#define y1 y123123123123
#define all(x) x.begin(), x.end()
#define hash hash123s
 
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repx(i, x, n) for (int i = x; i < (n); i++)
#define repd(i, n, d) for (int i = 0; i < (n); i += d)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepd(i, n, d) for (int i = (n) - 1; i >= 0; i -= d)
 
#ifdef artem
	#define debug(x) x
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define debug(x)
#endif

const int limit = 100500;
const int k = 18;
const int inf = 10050000;

int n, l;
int x[ limit ];
int dp[ limit ][ k + 1 ];

void precalc() {
	int j = 0;
	for(int i = 0; i < n; i++) {
		while(j < n && x[ j ] - x[ i ] <= l) {
			++j;
		}
		dp[ i ][ 0 ] = j - 1;
	}
	dp[ n - 1 ][ 0 ] = n - 1;
	for(int i = n - 1; i >= 0; i--) {
		for(int j = 1; j <= k; j++) {
			dp[ i ][ j ] = dp[ dp[ i ][ j - 1 ] ][ j - 1 ];
		}
	}

	// for(int i = 0; i <= k; i++) {
	// 	for(int j = 0; j < n; j++) {
	// 		cout << dp[ j ][ i ] << ' ';
	// 	}
	// 	cout << endl;
	// }
}

int calc(int l, int r) {
	int ans = 0;
	for(int j = k; j >= 0; j--) {
		if(dp[ l ][ j ] < r) {
			l = dp[ l ][ j ];
			ans += (1 << j);
		}
	}
	re ans + 1;
}

void solve() {
	cin >> n;
	rep(i, n) {
		cin >> x[ i ];
	}
	cin >> l;

	precalc();
	int q;
	cin >> q;
	while(q--) {
		int l, r;
		cin >> l >> r, --l, --r;
		if(l > r) swap(l, r);
		cout << calc(l, r) << '\n';
	}
}

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

using namespace std;

int main(){
  int N,M,C;
  cin >> N >> M >> C;
  int B[M];

  for(int i = 0; i < M; i++){
    cin >> B[i];
  }
  int A[N][M];
  for(int i = 0; i < N; i++){
    for(int j = 0; j < M; j++){
      cin >> A[i][j];
    }
  }

  int ans = 0;
  for(int i = 0; i < N; i++){
    int sum = 0;
    for(int j = 0; j < M; j++){
      sum += A[i][j] * B[j];
    }
    sum += C;
    if(sum > 0){ ans += 1; }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256