akhauriyash/Code-Regression huggingface dataset:
//                 _                      
//                (_)                     
// _ __ ___   __ _ _  ___  _ __ _ __ ___  
//| '_ ` _ \ / _` | |/ _ \| '__| '__/ _ \ 
//| | | | | | (_| | | (_) | |  | | | (_) |
//|_| |_| |_|\__,_| |\___/|_|  |_|  \___/ 
//               _/ |                     
//              |__/                      
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
  
typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef string str;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vbl;
typedef tree<
    pll,
    null_type,
    less<pll>,
    rb_tree_tag,
    tree_order_statistics_node_update>
ordered_set;

#define majorro cout.precision(20); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define forn(i, n) for(ll (i) = 0; (i) < (n); ++(i))
#define fornm(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define rfornm(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define readvec(vector, n) {ll temp_vec_val;forn(inc, n){cin >> temp_vec_val;vector.push_back(temp_vec_val);}}
#define printvec(vector, delimeter) {ll length_of_vector=vector.size();\
                                    forn(elementvec, length_of_vector){cout << vector[elementvec] << delimeter;}}
#define printarr(arr, length, delimeter) {forn(elementarr, length){cout << arr[elementarr] << delimeter;}}
#define all(vector) (vector).begin(), (vector).end()
#define rall(vector) (vector).rbegin(), (vector).rend()
#define endl "\n"
  
struct pair_hash
{
    template <class T1, class T2>
    std::size_t operator() (const std::pair<T1, T2>& pair) const
    {
        return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
    }
};
 
const ldbl EPS = 1e-6;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// const ll MOD = 3037000499;
// const ull MOD = 1000000000000000003;
const ll INF = 1e18;
const ldbl pi = 2 * acos(0.0);
ll n, m, k, p, q, t, sum = 0, cnt= 0;
ll mx = -INF;
ll mn = INF;
bool flag = 0;
vll v;
str s = "", s1, s2;
 
void bad_solve(){}

void solve() //set.merge() -> c++17
//DELET DEBUG OUTPUT!11!1
//"YES"/"NO" OUTPUT!!!!
//__builtin_popcountll() -> __popcnt64() from <intrin.h>
{
    char c;
    cin >> c;
    if(isupper(c)) cout << "A";
    else cout << "a";
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("F:\\repos\\projects\\contests_vsc\\in.txt", "r", stdin);
    freopen("F:\\repos\\projects\\contests_vsc\\out.txt", "w", stdout);
#endif
    majorro
    
    solve();
  
    // freopen("test.txt", "w", stdout);
    // bad_solve();
  
//  memset(v, INT_MAX, 1000*2000*sizeof(int));
  
    return 0;
}

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

int main() {
  int n,k;
  cin>>n>>k;
  int ans=1;
  for(int i=0;i<n;i++){
    if(ans+k<2*ans) ans+=k;
    else ans*=2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
int main()
{
    int n ; cin >> n;
    int cost = 1000;
    while(cost < n){
        cost += 1000;
    }
    cout << cost - n << endl;
    return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	string s;
	cin >> s;
	ll n = s.size();

	vector<ll> cnt(3, 0);
	for (ll i = 0; i < n; i++) cnt[s[i] - 'a']++;

	if (max({cnt[0], cnt[1], cnt[2]}) - min({cnt[0], cnt[1], cnt[2]}) <= 1) YES();
	else NO();
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N,P;
    string S;
    cin >> N >> P >>S;
    ll U[N+1];
    ll i,ans=0;
    if(P==2){
    	for(i=0;i<N;i++){
    		if((S[i]-'0')%2==0)ans+=i+1;
    	}
    	cout << ans;
    	return 0;
    }
    if(P==5){
    	for(i=0;i<N;i++){
    		if((S[i]-'0')%5==0)ans+=i+1;
    	}
    	cout << ans;
    	return 0;
    }
    map <ll,ll> mp;
    U[N]=0;
    mp[0]=1;
    ll tmp=1;
    for(i=0;i<N;i++){
    	U[N-i-1]=((S[N-i-1]-'0')*tmp+U[N-i])%P;
    	tmp=tmp*10%P;
    	if(mp.count(U[N-i-1])){
    		ans+=mp[U[N-i-1]];
    		++mp[U[N-i-1]];
    	}else{
    		mp[U[N-i-1]]=1;
    	}
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 2564
#include <stdio.h>
 
int main(void) {
    int a, b, c;
    int i, ans;
     
    scanf("%d %d %d", &a, &b, &c);
     
    ans = 0;
    for (i = a; i <= b; i++) if (c % i == 0) ans++;
     
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n,k; cin>>n>>k;
    vector <pair<int,int>> data(n);
    rep(i,n){
        int a,b; cin>>a>>b;
        data[i] = {a,b};
    }
    sort(data.begin(),data.end());
    int ans1 = 0, maxbit=0;
    while((k>>maxbit)){
        maxbit++;
    }
    int ans = 0;
    
    rep(i,n) if(k == (k|data[i].F)) ans += data[i].S;
    
    rep(i, maxbit){
        int tmp = k, val = 0;
        if(!(tmp&(1LL<<i))) continue;
        tmp &= ~(1LL<<i); 
        rep(j,i) tmp |= (1LL<<j);
        rep(j,n) if(tmp==(tmp|data[j].F)) val += data[j].S;
        ans = max(ans, val);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
using namespace std;
typedef long long ll;
int main(void){
    ll h,w,n;
    cin >> h >> w >> n;
    map<pair<ll, ll>, int> d;
    ll a,b;
    ll x, y;
    for(int i=0; i<n; i++){
        cin >> a >> b;
        for(int j=-1; j<2; j++){
            for(int k=-1; k<2; k++){
                x = a+j;
                y = b+k;
                if(x>1 and x<h and y>1 and y<w){
                    map<pair<ll, ll>, int>::iterator it;
                    it = d.find(pair<ll, ll>(x,y));
                    if(it != d.end()){
                        d[pair<ll, ll>(x,y)] += 1;
                    }else{
                        d[pair<ll, ll>(x,y)] = 1;
                    }
                }
            }
        }
    }
    vector<ll> count(10,0);
    map<pair<ll, ll>, int>::iterator it;
    for(auto it=d.begin(); it!=d.end(); it++){
        count[it->second] += 1;
    }
    ll sum=0;
    for(int i=0; i<10; i++){
        sum += count[i];
    }
    cout << (h-2)*(w-2) - sum << endl;
    for(int i=1; i<10; i++){
        cout << count[i] << endl;
    }
}

Measured memory_bytes: 56448
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}


class Node{
	public:
		bool used;
		int prenum; //DFSの訪問の順番
		int parent; //DFS Treeにおける親
		int lowest; //min(自分のprenum, 逆辺がある場合の親のprenum, すべての子のlowest)
		Node() : used(0) { }
};

class articulationPoints {
	private:
		int v, cnt;
		vector<Node> node;
		void dfs(int current, int prev){
			node[current].prenum = node[current].lowest = cnt;
			cnt++;

			node[current].used = true;

			int next;
			rep(i,edge[current].size()){
				next = edge[current][i];
				if(not node[next].used){
					node[next].parent = current;
					dfs(next, current);
					node[current].lowest = min(node[current].lowest, node[next].lowest);
					if(node[current].prenum < node[next].lowest){
						bridge.emplace_back(make_pair(min(current, next), max(current, next)));
					}
				}else if(next != prev){
					node[current].lowest = min(node[current].lowest, node[next].prenum);
				}
			}
		}
	public:
		vector<vector<int>> edge;
		vector<pair<int, int>> bridge;
		set<int> ap; // 関節店
		articulationPoints(int n) : v(n), cnt(1), node(n), edge(n) { }
		void addEdge(int a, int b){
			edge[a].emplace_back(b);
			edge[b].emplace_back(a);
		}
		void run(){
			dfs(0, -1); // 0 == root

			int np = 0;
			range(i,1,v){
				int p = node[i].parent;
				if(p == 0) np++;
				else if(node[p].prenum <= node[i].lowest) ap.emplace(p);
			}
			if(np > 1) ap.emplace(0);
			//for(auto it:ap){ cout << it << endl; } //関節点の全列挙
			sort(all(bridge));
			//for(auto it:bridge){ cout << it.first << ' ' << it.second << endl; } //橋の全列挙

		}
};

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

	articulationPoints ap(n);
	rep(i,m){
		int s, t;
		cin >> s >> t;
		ap.addEdge(s,t);
	}
	ap.run();
	for(auto i : ap.ap){
		cout << i << endl;
	}
}



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

int main(){
    ll h;
    cin >> h;
    ll res = 2;
    while(res <= h) res *= 2;
    cout << res -1 << endl;
}

Measured memory_bytes: 256
A_BASE = ord('a')
A = [1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25]

def brute_force(len4s, dwords):
    b = 0
    for a in A:
        while b < 26:
            for word in len4s:
                dec = [(a * r + b) % 26 for r in word]
                if dec in [[19, 7, 8, 18], [19, 7, 0, 19]]:
                    dec_words = [''.join([chr((a*r + b) % 26 + A_BASE) for r in dw]) for dw in dwords]
                    return ' '.join(dec_words)
            b += 1
        b = 0

def solve():
    n = int(input())
    for _ in range(n):
        text = input()
        words = text.split()
        dwords = [[ord(ch) - A_BASE for ch in word] for word in words]
        len4s = [dw for dw in dwords if len(dw) == 4]
        print(brute_force(len4s, dwords))

if __name__ == "__main__":
    solve()



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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> voting_count(N);
    vector<int> cost(N);
    for (auto &i : cost) cin >> i;
    for (int i = 0; i < M; i++) {
        int p;
        cin >> p;
        for (int j = 0; j < N; j++) {
            if (cost[j] <= p) {
                voting_count[j]++;
                break;
            }
        }
    }

    int ans = 0, count = 0;
    for (int i = 0; i < N; i++) {
        if (voting_count[i] > count) {
            ans = i + 1;
            count = voting_count[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3092
import math

A, B, H, M = map(int, input().split())

h = math.pi / 6 * (H + M / 60)

m = math.pi / 30 * M

if abs(h-m) <= math.pi:
    ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(abs(h-m)))
else:
    ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(-abs(h-m)))

print(ans)

Measured memory_bytes: 9520
N = int(input())
s = [int(input()) for i in range(N)]
T = sum(s)
if T%10 != 0:
    print(T)
else:
    s.sort()
    flag = 0
    for i in range(len(s)):
        if s[i] % 10 != 0:
            T -= s[i]
            flag = 1
            print(T)
            break
    if flag == 0:
        print(0)


Measured memory_bytes: 3060
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
long long n,i,arr[1000004],final[1000004],k,j;
int main()
{
    scanf("%lld %lld",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&arr[i]);
    }
    
    final[1]=abs(arr[1]-arr[0]);
    
    for(i=1;i<n;i++)
    {
        final[i]=INT_MAX;;
        for(j=i-1;j>=i-k && j>=0;j--)
        {
            final[i]=min(final[i],(final[j]+abs(arr[i]-arr[j])));
        }
    }
    // for(i=0;i<n;i++)
    // {
    //     printf("%lld ",final[i]);
    // }
    
    printf("\n%lld\n",final[n-1]);
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()
#define TST(H) (#H);

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI l(n);
	rep(i, n) cin >>l[i];
	ll ans =0;
	sort(all(l));
	rep(i, n) rep2(j,i+1, n) rep2(k, j+1, n){
		if(l[i] + l[j] > l[k] && l[i] !=l[j] && l[i]!=l[k] && l[j]!=l[k]) {
			//dbg(l[i],l[j],l[k],i,j,k);
			ans++;
		}
	}
	
	cout <<ans <<"\n";
	return 0;
}



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

int main()
{
	int n;
	while(cin>>n){
		if(n==0) return 0;

		vector<int> V;
		for(int i=0;i<n;i++){
			int t;
			cin>>t;
			V.push_back(t);
		}
		sort(V.begin(),V.end());

		int ans=0;
		for(int i=1;i<V.size()-1;i++)
			ans+=V[i];
		cout<<ans/(n-2)<<endl;

	}
}

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

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;

    vector<vector<int>> rou(N, vector<int>(N));
    map<int, int> route;

    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            if (i + 1 <= X && j + 1 >= Y) {
                route[j - i - (Y - X - 1)]++;
                rou[i][j] = j - i - (Y - X - 1);
            } else {
                rou[i][j] = min(j - i, abs(X - i - 1) + 1 + abs(Y - j - 1));
                route[rou[i][j]]++;
            }
            // cout << i + 1 << " " << j + 1 << " " << rou[i][j] << endl;
        }
    }

    for (int i = 1; i < N; i++) {
        cout << route[i] << endl;
    }

    return 0;
}


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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  string S;
  cin>>N>>S;
  int ans=0;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      for(int k=0;k<10;k++){
        bool I=false,J=false,K=false;
        for(int l=0;l<N;l++){
          int s=(S[l]-'0');
          K|=(s==k&&I&&J);
          J|=(s==j&&I);
          I|=(s==i);
        }
        if(K)ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
/** author: __nishad__ **/
//#pragma GCC optimize(2)
//#pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a,b) for(ll i=(a);i<(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;
    ll a = 2, b = 1, sum=0;
    int n;

    cin>>n;

    if(n == 0)
        cout<<"2";
    else if(n == 1)
        cout<<"1";
    else{
        loop(i, 1, n){
            sum = a + b;
            a = b;
            b = sum;
        }
        cout<<sum;
    }






}





























Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 1e5+10;
int n,m,q,cnt;
pa a[N];

struct _{
	int fa[N],siz[N];
	inline void init(int n){
		For(i,1,n) fa[i]=i,siz[i]=1;
	}
	inline int Find(int x){
		return fa[x]==x?x:fa[x]=Find(fa[x]);
	}
	inline void Merge(int x,int y){
		x=Find(x),y=Find(y);
		if (x!=y) fa[x]=y,siz[y]+=siz[x];
	}
}f;

int main(){
	n=read(),m=read(),q=read();
	f.init(n);
	For(i,1,q){
		int x=read()+1,y=read()+1,z=read();
		if (z==0) f.Merge(x,y);
			else a[++cnt]=mp(x,y);
	}
	For(i,1,cnt) if (f.Find(a[i].fi)==f.Find(a[i].se)) return puts("No"),0;
	int tot=0;
	For(i,1,n) if (f.Find(i)==i) tot++,m-=f.siz[i]-1;
	if (tot==2&&cnt) return puts("No"),0;
	if (cnt==0){
		if (m==tot-1) return puts("Yes"),0;
			else return puts("No"),0;
	}
	if (tot<=m&&m<=1ll*tot*(tot-1)/2) return puts("Yes"),0;
		else return puts("No"),0;
}

Measured memory_bytes: 5152
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007

ll dp[22][(1<<21)];

ll solve(vector<vector<char> >&mat,ll mask,int i,int n)
{
	if(i>=n)
	{
		if(mask==((1<<n)-1))
		{
			return(1);
		}
		else
		{
			return(0);
		}
	}
	if(dp[i][mask]!=-1)
	{
		return(dp[i][mask]);
	}
	ll j;
	ll ans=0;
	for(j=0;j<n;j++)
	{
		//cout<<((1<<j)&mask)<<" "<<mat[i][j]<<" ";
		if(mat[i][j]=='1' && ((1<<j)&mask)==0)
		{
			//cout<<"yo";
			ans=(ans+solve(mat,((1<<j)|mask),i+1,n))%mod;
		}
	}
	return(dp[i][mask]=ans);
}

int main()
{
	int n;
	cin>>n;
	int i,j;
	memset(dp,-1,sizeof(dp));
	vector<vector<char> >mat(n+1,vector<char>(n+1));
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			cin>>mat[i][j];
		}
	}
	cout<<solve(mat,0,0,n);
}

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

int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    map<string,ll> m;

    for(int i=0; i<n; i++){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        m[s]++;
    }
    for(auto&&x : m) ans += x.second*(x.second-1)/2;
    
    cout << ans << endl;
    return 0;
}

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

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

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

//r本再利用されない時、N本から再利用して売れる本数
int rec(int m,int n,int N,int r){
  if(N == 0) return 0;

  int k = N/m * n;//新たに作り出す本数
  r = N%m;//再利用されない本数
  int res = N + k;//売った本数
  
  while(1){
    k = k/m * n;//k本からk/m本再利用
    res += k;
    r += k%m;
    if(k < m){//k本で再利用できなくなったら
      k += r;
      res += rec(m,n,k,r);
    }
  }
}

int main(){
  int N,K;
  cin >> N >> K;
  if(K == 1) cout << 0 << endl;
  else if(N == K) cout << 0 << endl;
  else if(N > K) cout << N - K << endl; 
}


Measured memory_bytes: 256
// Coded by- Rad0n  275484HW

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define lb(a,x) (lower_bound(all(a),x)-a.begin())
#define ub(a,x) (upper_bound(all(a),x)-a.begin())
#define forn(i,n) for(int i=0;i<int(n);i++)
#define forr(i,n) for(int i=int(n-1);i>=0;i--)
#define fora(i,a,b) for(int i=int(a);i<=int(b);i++)
#define forb(i,a,b) for(int i=int(a);i>=int(b);i--)
#define test int t,o;cin>>o;for(t=1;t<=o;t++)
#define kickstart int t,o;cin>>o;for(t=1;t<=o;t++){cout<<"Case #"<<t<<": ";solve();}
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define o_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define o_multiset tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ll=long long int;
#define mod 1000000007
mt19937 rng(time(NULL));

void solve()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	if(d<a)
	{
		cout<<d<<endl;
		return;
	}
	d-=a;
	ll ans=a;
	d-=b;

	if(d>=0)
	{
		ans-=min(d,c);
	}
	cout<<ans<<endl;

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


Measured memory_bytes: 3612
#include <stdio.h>

int main(void) {
    int h, w;

    while (scanf("%d%d", &h, &w), h != 0) {
        int x = h * h + w * w;
        int bigx = 150 * 150;
        int h2, w2, bigh, bigw;
        for (h2 = 1; h2 <= 150 ; h2++) {
            for (w2 = 150; w2 > h2; w2--) {
                int x2 = h2 * h2 + w2 * w2;
                if ((x < x2 && x2 < bigx) ||
                    (x2 == x && x < bigx && h < h2)) {
                    bigx = x2;
                    bigh = h2;
                    bigw = w2;
                }
            }
        }
        printf("%d %d\n", bigh, bigw);
    }
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//--<for debugging>
#define whatis(x) cout << #x << " is " << x<<" ";
#define whatisl(x) cout << #x << " is " << x<<"\n";
#define parr(array,end)for(ll loop=0;loop<end;loop++)cout<<array[loop]<<" ";cout<<"\n";
#define lline cout<<"\n";
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"\n";}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"___";}
    
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a <<" , ";
    err(++it, args...);
}
//--</for debugging> 
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define testcase ll tt; cin >> tt; while(tt--)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define vars ll h,i,j,k,d,l,p,q,r,x,y,a,b,c,v,var,n,m,z,s,ans,ind1,ind2,flag,limit1,limit2,limit3,mod;
#define vll vector<ll>
#define pll pair<ll,ll>
#define sll set<ll>
#define pint pair<int,int>
const ll INF=1e9+7;
const ll MOD=1e9+7;
int main()
{
    boost vars
    string str,strr;
    cin>>str>>strr;
    strr.pop_back();
    if(str==strr)cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3648
#include <iostream>
#include<string>
using namespace std;
int main(){
    int A,B;
    cin>>A>>B;
    if(A>=13){
        cout<<B<<endl;
    }
    else if(A<=12&&A>=6){
        cout<<B/2<<endl;
    }
    else{cout<<"0"<<endl;}
}

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

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	if (n < m) {
		for (int i = 0; i < m; i++) {
			printf("%d", n);
		}
	}
	else {
		for (int i = 0; i < n; i++) {
			printf("%d", m);
		}
	}
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<functional>
#include<utility>
using namespace std;
int main(){
	int a, b, t,sum=0; cin >> a >> b >> t;
	for (int i = 1; a*i <= t ; ++i) {
		sum += b;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
//temprates
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

using ll = long long;
using namespace std;

#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define LFOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define FORR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define LFORR(i,a,b) for(ll i = (int)(a); i >= (ll)(b); i--)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define LREP(i,n) LFOR(i,0,(ll)(n)-1)
#define REPR(i,n) FORR(i,(int)(n)-1,0)
#define LREPR(i,n) LFORR(i,(ll)(n)-1,0)

#define SIZ(v) int(v.size())
const int INF = 1e8;
const ll LINF = 1e15;
const int MOD = 1e9+7;




int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  char s[4];
  bool ans=false;
  cin >> s;
  if(s[0]==s[1])ans=(s[2]==s[3]&&s[0]!=s[2]);
  else if(s[0]==s[2])ans=(s[1]==s[3]&&s[0]!=s[1]);
  else if(s[0]==s[3])ans=(s[1]==s[2]&&s[0]!=s[1]);

  cout << ((ans)?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int x;
    int y;
    cin >> x >> y ;
    if (x>=10){
        cout <<"-1"<<endl;
    }
    else if(y>=10){
        cout <<"-1"<<endl;
    } 
    else cout << x*y <<"\n";  
}

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

int main() {
	int n, a [100];
	cin >> n;
	
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	for(int k = 0; k < n; k++) {
		cout << a[k];
		if (k < n - 1){
			cout << " ";
		} else{
			cout << endl;
		}
	}
		
	for (int i = 1; i < n; i++){
		int v =a[i];
		int j = i -1;
		while (j >= 0 && a[j] > v) {
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;
		
		for(int k = 0; k < n; k++) {
			cout << a[k];
			if (k < n - 1){
				cout << " ";
			} else { 
				cout << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3084
n, k = map(int, input().split())

li_h = list()
for i in range(n):
    li_h.append(int(input()))

s_li_h = sorted(li_h)

wk = k - 1
li_diff = list()
for i in range(wk, n):
    li_diff.append(s_li_h[i] - s_li_h[i - wk])

print(min(li_diff))

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

int dfs(int n, int k, int s, int d){
  if(k==1){
    if(d<=s&&s<=n) return 1;
    else return 0;
  }
  int ans = 0;
  for(int i=d;i<=min(n,s);i++){
    ans += dfs(n, k-1, s-i, i+1);
  }
  return ans;
}

int main(){
  while(1){
    int n,k,s;
    cin >> n >> k >> s;
    if(n==0) return 0;
    cout << dfs(n,k,s,1) << endl;
  }
  return 0;
}



Measured memory_bytes: 3044
//g++ -std=c++14 test.cpp -o test.out

 //全部開催すると仮定した後、1つずつ減らして調べていく

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL T1,T2;
LL A1,A2;
LL B1,B2;

LL ans = 0;

void solve(){
	if(A1<B1){
		swap(A1,B1);
		swap(A2,B2);
	}
	LL diff = (B1*T1+B2*T2) - (A1*T1+A2*T2);
	if(diff<0LL) ans = 0;
	if(diff==0LL) ans = -1;
	if(diff>0LL){
		LL diff_T2 = diff;
		LL diff_T1 = (A1 - B1)*T1;
		if(diff_T1%diff_T2==0LL){
			ans = (diff_T1/diff_T2)*2LL;
		}else{
			ans = diff_T1/diff_T2*2LL + 1LL;
		}
	}
}

int main(){
    cin >> T1 >> T2;
    cin >> A1 >> A2;
    cin >> B1 >> B2;

    solve();

    if(ans==-1){
    	cout << "infinity" << endl;
    	return 0;
    }
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int N;
vector<int>G[234567];
vector<int>oh[234567];
void dfs(int v, int las, int c) {
	oh[c].push_back(v);
	for (int x : G[v]) {
		if (x == las)continue;
		dfs(x, v, 1 - c);
	}
}

int z = 3, o = 1, t = 2;
int zero() {
	z += 3;
	return z - 3;
}
int zeroone() {
	if (o > N) {
		z += 3;
		return z - 3;
	}
	o += 3;
	return o - 3;
}
int zerotwo() {
	if (t > N) {
		z += 3;
		return z - 3;
	}
	t += 3;
	return t - 3;
}
int zerorest() {
	if (z > N) {
		if (o > N) {
			t += 3;
			return t - 3;
		}
		o += 3;
		return o - 3;
	}
	z += 3;
	return z - 3;
}

int ans[234567];

int main() {
	cin >> N;
	for (int i = 1; i < N; ++i) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0, -1, 0);
	int large,small;
	if (oh[0].size() > oh[1].size()) {
		large = 0;
		small = 1;
	}
	else {
		large = 1;
		small = 0;
	}
	if (oh[small].size() <= (N - 1) / 3) {
		for (int v : oh[small]) {
			ans[v] = zero();
		}
		for (int v : oh[large]) {
			ans[v] = zerorest();
		}
	}
	else {
		for (int v : oh[small]) {
			ans[v] = zeroone();
		}
		for (int v : oh[large]) {
			ans[v] = zerotwo();
		}
	}
	for (int i = 0; i < N; ++i) {
		cout << ans[i] << (i == N - 1 ? "\n" : " ");
	}
	return 0;
}

Measured memory_bytes: 27892
//Let's join Kaede Takagaki Fan Club !!
//明日は高垣楓さんの誕生日！おめでとうございます！！！
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

int main(){
	ll a, v, b, w, t; 
	cin >> a >> v >> b >> w >> t;
	ll d = abs(a-b);
	if(w >= v){
		cout<<"NO"<<endl;
	}
	else{
		t *= (v-w);
		cout<<(t>=d?"YES":"NO")<<endl;
	}
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<string.h>
int main(void) {
	int a, b,c,i;
	char A[4];

	scanf("%d %d", &a, &b);

	if  (b == 100){
		c = a * 1000 + b;
	}
	else if (b >= 10) {
		c = a * 100 + b;
	}
	else {
	c = a * 10 + b; 
	}

	for (i = 1; i < c; i++) {
		if (c%i == 0) {
			if (c / i == i) {
				strcpy(A, "Yes"); break;
			}
		}
		strcpy(A, "No"); 
	}

	printf("%s", A);
	return 0;
}

Measured memory_bytes: 128
def gcd(n,m):
    n,m=sorted([n,m])
    while(m%n!=0):
        n,m=m%n,n
    return n
def lcm(n,m):
    return n*m//gcd(n,m)
n,m=map(int,input().split())
print(lcm(n,m))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double


#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define int ll
const ll mod =1e9+7;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll maxn = 400000+10;
const ll md = (ll) 1e9 + 7;
 
inline ll add(ll a, ll b) {
  a += b;
  if (a >= md) a -= md;
  return a;
}
 
inline ll sub(ll a, ll b) {
  a -= b;
  if (a < 0) a += md;
  return a;
}
 
inline ll mul(ll a, ll b) {
  return (ll) ((long long) a * b % md);
}
 
inline ll power(ll a, long long b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
 
inline ll inv(ll a) {
  a %= md;
  if (a < 0) a += md;
  ll b = md, u = 0, v = 1;
  while (a) {
    ll t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}
int32_t main()
{
 
   IOS
   int n,k;
   cin>>n>>k;
   int ans = 0;
   int f[k+1] = {0};
   for(int  i = k;i>=1;i--){
     f[i] = (power(k/i,n));
     
     for(int j = 2*i;j<=k;j+=i)
      f[i] = sub(f[i],f[j]);
     ans = add(ans,mul(i,f[i]));
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 4328
N=int(input())
A=list(map(int,input().split()))

L=list()
for i in range(N):
    l=[A[i],i+1]
    L.append(l)
L.sort(key=lambda x:x[0])

s=str(L[0][1])
for i in range(N-1):
    s+=" "+str(L[i+1][1])
print(s)

Measured memory_bytes: 22500
import java.io.*;
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int nData = sc.nextInt();
		
		for(int i = 0; i < nData; i++) {
			int n = sc.nextInt();
			int up = 0;
			int down = 0;
			int now = sc.nextInt();
			for(int j = 0; j < n-1; j++) {
				int h = sc.nextInt();
				if(h > now) {
					if(up < h-now) {
						up = h-now;
					}
				}
				else if(h < now) {
					if(down < now-h) {
						down = now-h;
					}
				}
				now = h;
			}
			System.out.println(up + " " + down);
		}
	}
}

Measured memory_bytes: 26948
#include <iostream>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a = 0; int b = 0; int c = 0;
        for (int j = 0; j < 3; j++) {
            int x; cin >> x;
            if (x > a) { c = b; b = a; a = x; }
            else if (x > b) { c = b; b = x; }
            else if (x > c) { c = x; }
        }
        if (a * a == b * b + c * c)
            cout << "YES\n";
        else
            cout << "NO\n";
    }
}

Measured memory_bytes: 3120
def dfs(i, Ope, sum):
    if i == N-1:
        start = 0
        for j in range(N-1):
            if Ope[j] == "+":
                #print(S[start:j+1])
                sum += int(S[start:j+1])
                start = j+1
        #print(S[start:N])
        sum += int(S[start:N])
        return sum
    else:
        Ope_plus = Ope + ["+"]
        Ope_null = Ope + [""]
        sum = dfs(i+1, Ope_plus, sum)
        sum = dfs(i+1, Ope_null, sum)
        return sum

S = input()
N = len(S)
Operator = []
print(dfs(0, Operator, 0))


Measured memory_bytes: 3064
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  ll t;
  cin>>t;
  ll n=50;
  vector<ll> re(n,n+t/n-t%n-1);
  rep(i,t%n) re[i]=n*2+t/n-t%n;
  cout<<n<<endl;
  rep(i,n) cout<<re[i]<<" \n"[i+1==n];
  return 0;
}


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

using namespace std;

# define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;

# define S second
# define F first
# define kill(x) return(cout << x << endl, 0)
# define debug(x) cerr<< #x << " : " << x << endl
# define ddebug(x, y) cerr<< #x << " : " << x  << ", " << #y << " : " << y << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)

const int MAXN = 300 * 1000 + 10, MOD = 998244353;
int fact[MAXN];

int pw(int a, int b) {
	long long ans = 1;
	for(int i = 63; i >= 0; i --) {
		ans *= ans;
		ans %= MOD;
		if((b >> i) & 1)
			ans *= a;
		ans %= MOD;
	}
	return ans;
}

int rev(int a)
{
	return pw(a, MOD - 2);
}

int choose(int nn, int kk)
{
	return fact[nn] * rev(fact[kk]) % MOD * rev(fact[nn - kk]) % MOD;
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n, a, b, k;
	cin >> n >> a >> b >> k;

	fact[0] = 1;
	for (int i = 1; i <= n; i ++)
		fact[i] = fact[i - 1] * i % MOD;

	int ans = 0;
	for (int i = 0; i <= n; i ++)
	{
		if((k - i * a) % b || k - i * a < 0 || (k - i * a) / b > n)
			continue;
		ans += choose(n, i) * choose(n, (k - i * a) / b) % MOD;
		ans %= MOD;
	}
	cout << ans << "\n";

	return 0;
}






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

m = Array.new(n, 0)
n.times do |i|
  if i == 0
    m[i] = a[i]
  else
    m[i] = [m[i - 1], a[i]].max
  end
end
#p m

res = 0
n.times do |i|
  res += m[i] - a[i]
end
puts res

Measured memory_bytes: 31784
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    string s;
    cin >> s;
    REP(i,s.size()){
        if( (i + 1) % 2 == 1){
            if(s[i] == 'L'){
                cout << "No" << endl;
                return 0;
            }
        }
        else{
            if(s[i] == 'R'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

}

Measured memory_bytes: 256
#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++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int h,w,K;cin >> h >> w >> K;
    vector<vector<char>> c(h,vector<char>(w));
    rep(i,h)rep(j,w)cin >> c[i][j];
    int k=(1<<h);
    int l=(1<<w);
    int ans=0;
    rep(ii,k){
        bitset<6> a(ii);
        rep(jj,l){
            bitset<6> b(jj);
            int cnt=0;
            rep(i,h)rep(j,w){
                if(c[i][j]=='#'&&!a[i]&&!b[j])cnt++;
            }
            if(cnt==K)ans++;
            skip:;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (int i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (int i = x.size()-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define fst first
#define scd second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int a,b,c;

int main()
{
    cin>>a>>b>>c;
    Yes((a == b && a != c) || (a == c && a != b) || (c == b && a != b));

    return 0;
}


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

int main(){
    int n,a,ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a);
        while(a%2==0){
            a/=2;
            ans++;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#define FOR(i,b,e) for(int i=b;i<e;i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
 
int main() {
  int n,q;
 
  cin >> n;
  int S[n+1];
  for(int k=0;k<n;k++){
    cin >> S[k];
  }
  cin >> q;
  int T[q];
  for(int l=0;l<q;l++){
    cin >> T[l];
  }
 
  int count=0;
  for(int j=0;j<q;j++){
    int i=0;
    S[n] = T[j];
    while(S[i] != T[j]){
      i++;
    }
    if(i != n) count += 1;
  }
 
  cout << count << endl;
     
  return 0;
}

Measured memory_bytes: 3092
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F();
		var A = G();
		var B = G();
		var C = G();
		Array.Sort(A);
		Array.Sort(B);
		Array.Sort(C);
		var s = 0L;
		int i = 0, k = 0;
		for (var j = 0; j < N; j++)
		{
			while (i < N && A[i] < B[j]) i++;
			while (k < N && B[j] >= C[k]) k++;
			s += i * (long)(N - k);
		}
		Console.WriteLine(s);
	}
}


Measured memory_bytes: 41480
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp> 
const double PI=4*atan(1);
using namespace std;
using boost::multiprecision::cpp_int;
#define ll long long
#define ull unsigned long long
#define ci cpp_int
#define MOD 1000000007

long findmin(long a,long b) {
    return a<b?a:b;
}
long findmax(long a,long b) {
    return a>b?a:b;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s>>t;
    long count=0;
    for(long i=0;i<(long)s.length();i++) {
		if(s[i]!=t[i]) {
			count++;
		}
	}
	cout<<count<<"\n";
    cout.flush();
    return 0;
}


Measured memory_bytes: 3836