akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <cassert>
#include <time.h>
#include <numeric>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef vector<int> vi;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define ll long long int
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i, a, b) for(int i = a; i < b; i++)
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define trarr(a,n) rep(i,0,n) cerr<<a[i]<<" \n"[i==n-1];
#define trmat(g,n,m) rep(i,0,n)rep(j,0,m) cerr<<g[i][j]<<" \n"[i==m-1];
#define tr(...) cerr<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

const ld PI = acos(-1);
const ld EPS = 1e-9;
const int inf = 1e9+10;
const ll INF = 1e18+10;
const int P = 1e9+7;
const int N = 2e5+10;

void solve(int _t){
	int n;
	cin >> n;
	int a[n];
	rep(i, 0,  n) cin >> a[i];
	sort(a, a+n);
	ll ans = 0;
	ans = a[n-1];
	int i = n-2;
	int j = n-2;
	while(i > 0){
		ans+=min(2, i)*a[j];
		i-=2;
		j-=1;
		// tr(ans, j, i);
	}
	cout<<ans<<endl;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	// cin >> t;
	rep(test, 1, t+1){
		solve(test);
	}
	return 0;
}  

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

int main(){
    int X, N;
    cin >> X >> N;
    set<int> st;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        st.insert(a);
    }

    int ans = 1e9;
    for(int i=X-100; i<=X+100; i++) if(!st.count(i) && abs(i-X) < abs(ans-X)) ans = i;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
a[2][4];
main(i){
	float e[2];
	for(;~scanf("%f%f",e,e+1);){
		for(i=0;i<2;i++){
			if     (e[i]<0.2)	a[i][3]++;
			else if(e[i]<0.6)	a[i][2]++;
			else if(e[i]<1.1)	a[i][1]++;
			else				a[i][0]++;
		}
	}
	for(i=0;i<4;i++)	printf("%d %d\n",a[0][i],a[1][i]);
	exit(0);
}

Measured memory_bytes: 0
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n; cin>>n;
    map<int, int>mp;
    vi hoge(n); rep(i,n)cin>>hoge[i];
    rep(i,hoge.size()){
        mp[hoge[i]]=1;
        if(i+1<hoge.size()){
            mp[hoge[i]*10+hoge[i+1]]++;
        }
        if(i+2<hoge.size()){
            mp[hoge[i]*100+hoge[i+1]*10+hoge[i+2]]++;
        }
    }
    for(int i=0; i<1001;i++)if(!mp[i]){cout<<i<<endl;return 0;}
}

Measured memory_bytes: 3116
n = int(input())
a = [int(input()) for _ in range(n)]

no1 = max(a)
place_ma = a.index(no1)

a.pop(place_ma)

no2 = max(a)

for i in range(n):
    if i == place_ma:
        print(no2)
    else:
        print(no1)

Measured memory_bytes: 12532
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<vector<int> >in(n+1,vector<int>(n+1));
  rep(i,n)rep(j,n){
    int d;cin>>d;
    rep(k,i+1)rep(l,j+1)in[k][l]+=d;
  }
  //rep(i,n){
  //  rep(j,n)printf("%2d",in[i][j]);//cout<<" "<<in[i][j];
  // cout<<endl;}
  int maxi=-1*1e9;
  rep(i,n)rep(j,n)loop(k,i,n)loop(l,j,n)
    maxi=max(maxi,in[i][j]+in[k+1][l+1]-in[k+1][j]-in[i][l+1]);
  cout<<maxi<<endl;
}

Measured memory_bytes: 1256
n = int(input())
s = input()
i = 0
count = 0

while i < len(s):
    if not (s[i] == 'A'):
        i+=1
        continue

    i+=1
    if not i < len(s):
        break
    if not (s[i] == 'B'):
        continue

    i+=1
    if not i < len(s):
        break
    if not (s[i] == 'C'):
        continue

    i+=1
    count+=1

print(count)

Measured memory_bytes: 3064
def factorials(n,m):
    # 0~n!のリスト
    f = [1,1]
    for i in range(2,n+1):
        f.append(f[-1]*i%m)

    # 0~n!の逆元のリスト
    g = [1]
    for i in range(n):
        g.append(pow(f[i+1],m-2,m))

    return f,g

x,y = map(int, input().split())

m = 10**9+7

if (2*y-x)%3!=0:
    print(0)
    exit()

b = (2*y-x)//3
a = y-2*b

if a<0 or b<0:
    print(0)
    exit()

f,g = factorials(a+b,m)

nCr = f[a+b]*g[b]*g[a]

print(nCr%m)

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

#define ll long long
#define fr(i, n) for(int i=0;i<n;i++)
#define forall(i, j, n) for(int i=j; i<n; i++)
#define all(c) c.begin(), c.end()
#define tr(container, it) for (__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define rt(container, it) for (__typeof(container.rbegin()) it = container.rbegin(); it != container.rend(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresetn(container, element) (find(all(container)), element) != container.end())
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define si(n) scanf("%d", &n)
#define sll(n) scanf("%lld", &n)
#define pi(n) 0*printf("%d\n", n)
#define pll(n) 0*printf("%lld\n", n)
#define SET(container, value) memset(container, value, sizeof container)
#define MP make_pair
#define F first
#define S second

#define scan_all(...) __s(__VA_ARGS__)
template <typename Arg1>
void __s(Arg1&& arg1) {
  cin >> arg1;
}
template <typename Arg1, typename... Args>
void __s(Arg1&& arg1, Args&&... args) {
  cin >> arg1 ; __s(args...);
}

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << 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...);
}

std::vector<std::string> tokenize(
				  const std::string& s,
				  const std::string& delims){
  std::vector<std::string> tokens;
  size_t offset = 0;

  while (true) {
    size_t nonDelim = s.find_first_not_of(delims, offset);

    if (nonDelim == std::string::npos) {
      break; // Nothing left.
    }

    size_t delim = s.find_first_of(delims, nonDelim);

    // Finish tokenizing if this is the last token,
    // or we've found enough tokens.
    if (delim == std::string::npos) {
      tokens.push_back(s.substr(nonDelim));
      break;
    }

    tokens.push_back(s.substr(nonDelim, delim - nonDelim));
    offset = delim;
  }

  return tokens;
}

int main(){
  int n;
  si(n);
  vector<int> dp(n+1), h(n+1);
  for(int i=1; i<=n; i++) cin >> h[i];
  dp[1] = 0; dp[2] = abs(h[2]-h[1]);
  for (int i=3; i<=n; i++) {
    dp[i] = min(dp[i-1] + abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2] - h[i]));
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 1024
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut ans = 0;
    for i in 0 .. n {
        if i % 2 == 0 && a[i] % 2 == 1 { ans += 1 };
    }

    println!("{}", ans);

}


Measured memory_bytes: 2092
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const ll mod=1000000007;
ll ans;
ll a[2005][2005];
int main(){
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++){
		string s=to_string(i);
		a[s[0]-'0'][s.back()-'0']++;
	}
	for(ll i=0;i<10;i++){
		for(ll j=0;j<10;j++){
			ans+=a[i][j]*a[j][i];
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
	int N, A, B;
	cin >> N >> A >> B;
	if (A == B) {
		int res = 0;
		for (int i = 0, S; i < N; i++) {
			cin >> S;
			res ^= S % (A + 1);
		}
		cout << (res ? "Hanako" : "Jiro") << endl;
	}
	else if (A > B) {
		bool flag = false;
		int res = 0;
		for (int i = 0, S; i < N; i++) {
			cin >> S;
			if (S > B) flag = true;
			res ^= S % (B + 1);
		}
		cout << (flag || res ? "Hanako" : "Jiro") << endl;
	}
	else {
		int cnt = 0;
		int res = 0;
		vector<int> S(N);
		for (int i = 0; i < N; i++) {
			cin >> S[i];
			if (S[i] > A) cnt++;
			res ^= S[i] % (A + 1);
		}
		if (cnt == 0) {
			cout << (res ? "Hanako" : "Jiro") << endl;
		}
		else if (cnt >= 2 || res == 0) {
			cout << "Jiro" << endl;
		}
		else {
			for (int i = 0; i < N; i++) {
				if (S[i] > A) {
					int tmp = S[i] % (A + 1); tmp ^= res;
					cout << (tmp <= A && S[i] - tmp <= A && S[i] > tmp ? "Hanako" : "Jiro") << endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3176
// tested by Hightail: https://github.com/dj3500/hightail
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <stack>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cassert>
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (__typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

const int N = 4444;
vi adj[N];

int countmore (int v, int p, int d, int lim) {
   int res = 0;
   if (d > lim) ++res;
   for (int x : adj[v]) if (x != p) {
      res += countmore(x, v, d+1, lim);
   }
   return res;
}

int main () {
   wez2(n,k);
   vector<pii> edges;
   FOR(u,n-1) {
      wez2(a,b);
      edges.pb(mp(a,b));
      adj[a].pb(b);
      adj[b].pb(a);
   }
   int res = INF;
   if (k % 2 == 0) {
      FORI(c,n) {
         REMIN(res, countmore(c, -1, 0, k/2));
      }
   } else {
      for (auto e : edges) {
         REMIN(res, countmore(e.fi, e.se, 0, k/2) + countmore(e.se, e.fi, 0, k/2));
      }
   }
   pisz(res);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n;

struct LazySegmentTree{
	vector<ll> data, lazy;
	int sz;
	
	LazySegmentTree(int n){
		sz = 1;
		while(sz < n) sz *= 2;
		data.assign(2*sz, 0);
		lazy.assign(2*sz, 0);
	}
	
	void update(int k, int x){
		k  += sz-1;
		data[k] = x;
		
		while(k){
			k = (k-1)/2;
			data[k] = data[2*k+1] + data[2*k+2];
		}
	}
	
	void push(int k, int len){
		if(k < sz){
			lazy[2*k+1] += lazy[k];
			lazy[2*k+2] += lazy[k];
		}
		
		data[k] += lazy[k] * len;
		lazy[k] = 0;
	}
	
	void add(int a, int b, int x){
		_add(a, b, 0, 0, sz, x);
	}
	
	void _add(int a, int b, int k, int l, int r, int x){
		push(k, r-l);
		if(b<=l||r<=a) return ;
		if(a<=l&&r<=b){
			lazy[k] += x;
			push(k, r-l);
			return ;
		}
		
		_add(a, b, 2*k+1, l, (l+r)/2, x);
		_add(a, b, 2*k+2, (l+r)/2, r, x);
		data[k] = data[2*k+1] + data[2*k+2];
	}
	
	ll get(int a, int b){
		return _get(a, b, 0, 0, sz);
	}
	
	ll _get(int a, int b, int k, int l, int r){
		push(k, r-l);
		if(b<=l||r<=a) return 0;
		if(a<=l&&r<=b) return data[k];
		
		return _get(a, b, 2*k+1, l, (l+r)/2) + _get(a, b, 2*k+2, (l+r)/2, r);
	}
};

int main(){
	int n,q;
	cin >> n >> q;
	LazySegmentTree seg(n);
	REP(i,0,q){
		int a; cin >> a;
		
		if(a == 0){
			int b, c, d; cin >> b >> c >> d;
			seg.add(b-1, c, d);
		}else if(a == 1){
			int b, c; cin >> b >> c;
			cout << seg.get(b-1, c) << endl;
		}
	}
	
	return 0;
}



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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
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
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= 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
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  ll a, b, c;
  cin >> a >> b >> c;
  if(0 >= c-a+b) {
    cout << "No" << endl;
    return 0;
  }

  if(4*a*b < (c-a-b)*(c-a-b)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int main()
{
  int H,W ;
  cin>>H>>W ;
  vector<string>vec(H) ;
  
  for(int i=0;i<W+2;i++) cout<<"#" ;
  cout<<endl ;
  
  for(int i=0;i<H;i++){
    cin>>vec.at(i) ;
    cout<<"#"<<vec.at(i)<<"#"<<endl ;
  }
  for(int i=0;i<W+2;i++) cout<<"#" ;
  cout<<endl ;
  
  return 0 ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,s,sum,g,i,A,B,C;
main(){
	cin>>n>>s;if(n==s){cout<<n+1<<endl;return 0;}
	for(i=2;i<=min(n+1,3000000LL);i++){
		sum=0;g=1;
		while(g<=1LL<<37){sum+=(n/g)%i;g*=i;}
		if(sum==s){cout<<i<<endl;goto E;}
	}
	for(i=min(s,n/1000000);i>=1;i--){
		A=i,B=s-i;
		if((n-B)%A!=0)continue;
		C=(n-B)/A;if(C<=B||C<=1)continue;
		cout<<C<<endl;goto E;
	}
	cout<<"-1"<<endl;E:;
}

Measured memory_bytes: 256
import java.math.BigDecimal

fun main(args: Array<String>){
    val N = readLine()!!.toInt()

    val A = readLine()!!.split(" ").map{it.toBigDecimal()}



    if(BigDecimal(0)in A){
        println(0)
        return
    }

    var total = A[0]
    val max = BigDecimal(10).pow(18)

    for(i in 1 until N){
        total *= A[i]
        if(total > max){
            total = BigDecimal(-1)
            break
        }
    }

    println(total)


}

Measured memory_bytes: 66052
n,k=[int(x) for x in input().split()]

p=[int(_) for _ in input().split()]

t=[0 for i in range(n)]
t[0]=p[0]+1
for i in range(1,n):
  t[i]=t[i-1]+p[i]+1
  
ans=t[k-1]
for i in range(n-k):
  ans = max(ans,t[i+k]-t[i]) 
 # print(ans,t[i+k],t[i])
#print(t)
print(ans/2)

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

int check(char c)
{
	if (c == ',' || c == '.' || c == ' ' || c == '\n' || c == 0){
		return 0;
	}
	else {
		return 1;
	}
}

int main(void)
{
	char str[1026];
	int i;
	int len;
	char word[128];
	char flag = 0;
	
	fgets(str, 1025, stdin);
	for (i = 0; check(str[i]) == 1; i++){
		word[i] = str[i];
	}
	word[i] = 0;
	len = strlen(word);
	if (3 <= len && len <= 6){
		printf("%s", word);
		flag = 1;
	}
	for (; str[i] != 0;){
		int j;
		
		for (j = 0; check(str[i]) == 1; i++, j++){
			word[j] = str[i];
		}
		word[j] = 0;
		len = strlen(word);
		if (3 <= len && len <= 6){
			if (flag == 0){
				printf("%s", word);
				flag = 1;
			}
			else {
				printf(" %s", word);
			}
		}
		while (str[i] != 0 && check(str[i]) == 0){
			i++;
		}
	}
	puts("");
	
	return 0;
}

Measured memory_bytes: 524
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

// dp[i] .. position from 0 by i.
vector<vector<ll>> dp;

// nex[i][j] .. position from i by 2^j
vector<vector<ll>> nex;

vector<vector<ll>> g;
vector<ll> visited;

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n, k;
  cin >> n >> k;
  dp.resize(n+1);

  vector<ll> a(n);
  rep(i,n) {
    cin >> a[i];
    --a[i];
  }
  // printvec(a);

  ll l;
  {
    l = 0;
    while ((1ll<<l) < k) {
      //cout << l << endl;
      ++l;
    }
    nex.assign(n, vector<ll>(l));
  }
  // cout << "l: " << l << endl;
  {
    rep(i,n) {
      nex[i][0] = a[i];
    }
    rep(i, l-1) {
      rep(v, n) {
        nex[v][i+1] = nex[nex[v][i]][i];
      }
    }
  }
  // Here, nex is calculated

  ll now = 0;
  for (ll i = l; i >= 0; --i) {
    if (k&(1ll<<i)) { // k has i
      now = nex[now][i];
    }
  }
  cout << now+1 << endl;
}


Measured memory_bytes: 111172
#include <iostream>
#include <cstdio>
using namespace std;
int n, m;
int main() {
	cin >> n >> m;
	for (int i = 1, j = m + 1; i < j; i++, j--) {
		cout << i << " " << j << endl;
	}
	for (int i = m + 2, j = 2 * m + 1; i < j; i++, j--) {
		cout << i << " " << j << endl;
	}
	return 0;
} 

Measured memory_bytes: 3640
#include <bits//stdc++.h>
using namespace std;
int main(void){
    int a,b,c,i,j,ans;
    ans=0;
    cin>>a>>b>>c;
    int member[a];
    for(i=0;i<a;i++)
    member[i]=0;
    for(i=0;i<c;i++){
        cin>>j;
        member[j-1]++;
    }
    for(i=0;i<a;i++){
        if(c-member[i]<b)
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;
    }
    
}


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

for i in range(min(M, N // 4)):
    print("{} {}".format(i + 1, N - i))

center = (N + 1) // 2

for i in range(max(0, M - N // 4)):
    print("{} {}".format(center - i - 1, center + i + 1))

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

int		main(void)
{
	int		a;
	int		b;
	int		add;
	int		sub;
	int		mul;
	cin >> a;
	cin >> b;
	add = a + b;
	sub = a - b;
	mul = a * b;
	cout << max(add, max(sub, mul)) << endl;
}

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

int main() {
  int N, M, incomemax=0, income;
  cin >> N;
  vector<string> ao(N);
    for(int i=0; i<N; i++){
    cin >> ao.at(i);
    }
  cin >> M;
  vector<string> aka(M);
    for(int i=0; i<M; i++){
    cin >> aka.at(i);
    }
  
  for(int i=0; i<N; i++){
  income =0;
    for(int j=0; j<N; j++){
    if(ao.at(j) == ao.at(i)) {income++;}
    }
     for(int k=0; k<M; k++){
    if(aka.at(k) == ao.at(i)) {income--;}
    }
  if(income > incomemax){ incomemax = income;} 
  }
  cout << incomemax << endl;
}


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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

lint gcd(lint x, lint y){
    lint r = x % y;
    while(r != 0LL){
        x = y;
        y = r;
        r = x % y;
    }
    return y;
}

int main(){
    lint n, x;
    cin >> n >> x;
    lint ans = 3 * (n - gcd(n, x));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// A - Colorful Subsequence
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var S = Str;
		var cnt = new int[26];
		foreach (var c in S) cnt[c - 'a']++;
		var icnt = new long[26];
		for (var i = 0; i < 26; i++) icnt[i] = cnt[i] == 0 ? 0 : Inverse(cnt[i], MOD);
		var sum = 0L;
		var lim = 1u << 26;
		var G = 0u;
		var prod = 1L;
		var zero = 0;
		for (var i = 1u; i < lim; i++)
		{
			var Gnext = i ^ (i >> 1);
			var f = Gnext > G;
			var k = MSB(G ^ Gnext);
			G = Gnext;
			if (f)
			{
				if (cnt[k] == 0) zero++;
				else prod = prod * cnt[k] % MOD;
			}
			else
			{
				if (cnt[k] == 0) zero--;
				else prod = prod * icnt[k] % MOD;
			}
			if (zero == 0) sum += prod;
		}
		WriteLine(sum % MOD);
	}
	public static long Inverse(long a, long mod)
	{
		if (a < 0) { a %= mod; if (a < 0) a += mod; }
		var t = SolveLinear(a, mod);
		return t.Item1 > 0 ? t.Item1 : t.Item1 + mod;
	}
	public static Tuple<long, long> SolveLinear(long n, long m)
	{
		if (n < 0) { var p = SolveLinear(-n, m); return p == null ? p : new Tuple<long, long>(-p.Item1, p.Item2); }
		if (m < 0) { var p = SolveLinear(n, -m); return p == null ? p : new Tuple<long, long>(p.Item1, -p.Item2); }
		if (n < m) { var p = SolveLinear(m, n); return p == null ? p : new Tuple<long, long>(p.Item2, p.Item1); }
		long a = 1, b = 0, c = 0, d = 1;
		while (m > 0)
		{
			var r = n % m;
			var q = n / m;
			n = m;
			m = r;
			var tmp = a;
			a = -a * q + b;
			b = tmp;
			tmp = c;
			c = -c * q + d;
			d = tmp;
		}
		return n != 1 ? null : new Tuple<long, long>(d, b);
	}
	public static int MSB(uint n)
	{
		n |= (n >> 1);
		n |= (n >> 2);
		n |= (n >> 4);
		n |= (n >> 8);
		n |= (n >> 16);
		return BitCount(n) - 1;
	}
	public static int BitCount(uint n)
	{
		n = (n & 0x55555555) + ((n >> 1) & 0x55555555);
		n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
		n = (n & 0x0f0f0f0f) + ((n >> 4) & 0x0f0f0f0f);
		n = (n & 0x00ff00ff) + ((n >> 8) & 0x00ff00ff);
		return (int)((n & 0x0000ffff) + ((n >> 16) & 0x0000ffff));
	}
}


Measured memory_bytes: 13244
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

const LL mod = 1e9+7;

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<int> a(n);
		REP(i,n) cin >> a[i];
		map<int,int> m;
		REP(i,n) m[a[i]]++;
		LL ans = 0;
		if(n%2 == 0){
			REP(i,n/2){
				if(m[i*2+1] != 2){
					ans = -1;
				}
			}
			if(ans != -1){
				ans = 1;
				REP(i,n/2){
					ans *= 2;
					ans %= mod;
				}
			}
		}else{
			if(m[0] != 1) ans = -1;
			FOR(i,1,n/2+1){
				if(m[i*2] != 2){
					ans = -1;
				}
			}
			if(ans != -1){
				ans = 1;
				REP(i,n/2){
					ans *= 2;
					ans %= mod;
				}
			}
		}
		if(ans == -1) ans = 0;
		cout << ans << endl;
	}
	return 0;
}


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

int main(void){
 
   char a,b;
   cin >> a >> b;
   
   if(a == 'H'){
       if(b == 'H'){
           cout << 'H' <<endl;
       }
       else{
           cout << 'D' <<endl;
       }
   }
   else{
       if(b == 'H'){
           cout << 'D' <<endl;
       }
       else{
           cout << 'H' <<endl;
       }
   }
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, x;
    cin >> a >> b >> x;
    if (x == a * a * b) {
        cout << fixed << setprecision(15) << 0 << "\n";
    } else if (2 * x <= a * a * b) {
        double t = (a * b * b) * 1.0 / (2 * x);
        cout << fixed << setprecision(15) << atan(t) / acos(-1) * 180 << "\n";
    } else {
        double z = 2 * x * 1.0 / (a * a) - b;
        cout << fixed << setprecision(15) << 90 - atan(a / (b - z)) / acos(-1) * 180 << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
ll calc(ll a,ll b)
{
	return b==0?0:(a/b)*b*2+calc(b,a%b);
}
int main()
{
	ll n,x;
	cin>>n>>x;
	cout<<3*(n-__gcd(n,x));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 int a,b,c;
 cin >> a >> b>> c;
 if(abs(a-b)<abs(a-c)){
     cout << "A" << endl;
 }else{
     cout << "B" << endl;
 }
return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(;;){
		vi a(6); rep(i,6) cin>>a[i];
		if(count(allof(a),0)==6) break;
		
		rep(i,3)
			a[i]+=a[i+3];
		
		vi b(3);
		rep(i,3){
			b[i]=a[i]/3;
			a[i]%=3;
		}
		int mn=*min_element(a.begin(),a.begin()+3);
		rep(i,3)
			a[i]-=mn;
		
		int res=b[0]+b[1]+b[2]+mn;
		rep(i,3) repi(j,i+1,3)
			if(a[i]==2 && a[j]==2 && b[3-i-j]>0)
				res++;
		
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
MOD = 10**9 + 7
pos = []
neg = []
n, k = gets.split.map(&:to_i)
gets.split.map(&:to_i).each{|a|
	if a >= 0
		pos.push(a)
	else
		neg.push(-a)
	end
}
pos.sort!
neg.sort!

ans = 1
if ([neg.size, k].min & ~1) + pos.size >= k
	if k % 2 == 1
		ans = ans * pos.pop % MOD
		k -= 1
	end
	while k > 0
		if neg.size < 2 || (pos.size >= 2 && pos[-1] * pos[-2] > neg[-1] * neg[-2])
			ans = ans * pos.pop % MOD * pos.pop % MOD
		else
			ans = ans * neg.pop % MOD * neg.pop % MOD
		end
		k -= 2
	end
else
	ans = MOD - 1
	[*pos, *neg].min(k).each{|x| ans = ans * x % MOD }
end

puts ans


Measured memory_bytes: 36180
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    while (1)
    {
        cin >> n;
        if (n == 0)
            break;
        typedef pair<string, string> SS;
        vector<SS> S(n);
        rep(i, n) cin >> S[i].first >> S[i].second;
        sort(all(S));
        vector<int> sh(n), sm(n), ss(n), gh(n), gm(n), gs(n);
        rep(i, n)
        {
            string s = S[i].first, t = S[i].second;
            sh[i] = (s[0] - '0') * 10 + s[1] - '0';
            sm[i] = (s[3] - '0') * 10 + s[4] - '0';
            ss[i] = (s[6] - '0') * 10 + s[7] - '0';
            gh[i] = (t[0] - '0') * 10 + t[1] - '0';
            gm[i] = (t[3] - '0') * 10 + t[4] - '0';
            gs[i] = (t[6] - '0') * 10 + t[7] - '0';
        }
        vector<int> h, m, s;
        rep(i, n)
        {
            bool f = false;
            int pos;
            rep(j, h.size())
            {
                if (h[j] > sh[i])
                    continue;
                if (h[j] == sh[i] && m[j] > sm[i])
                    continue;
                if (h[j] == sh[i] && m[j] == sm[i] && s[j] > ss[i])
                    continue;
                f = true;
                pos = j;
            }
            if (!f)
            {
                h.push_back(gh[i]);
                m.push_back(gm[i]);
                s.push_back(gs[i]);
            }
            else
            {
                h[pos] = gh[i];
                m[pos] = gm[i];
                s[pos] = gs[i];
            }
        }
        cout << h.size() << endl;
    }
}


Measured memory_bytes: 4716
#include<bits/stdc++.h>
using namespace std;
int a[7];
int main(){
    a[0]=1;
    for(int i=1;i<7;++i) a[i]=a[i-1]<<1;
    int n;
    while(cin>>n){
        int t=lower_bound(a,a+7,n)-a;
        if(a[t]==n) cout<<n<<endl;
        else cout<<a[t-1]<<endl;
    }
    return 0;
}


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

int main(){
    int n,k;
    cin>>n>>k;
  while(k--){
    int x,y;
    cin>>x>>y;
    int w=min(x,n-x+1);
    int h=min(y,n-y+1);

    if(h>w){
      cout<<(w-1)%3+1<<endl;
    }
    else{
      cout<<(h-1)%3+1<<endl;
    }
  }
    return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

#define B       (cout << "Sehen Sie mich!" << endl)
#define VB(val) (cout << val << endl)

inline int ctoi(const char c){
        if('0' <= c && c <= '9') return (c -'0');
        return -1;
}

int main()
{
        int x, y, z;
        int ret = 0;
        cin >> x >> y >> z;

        x = x - z;
        while (x >= y + z) {
                x = x - y - z;
                ret++;
        }
        VB(ret);
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;
const int MAX_N=2e5+5;
inline int qi(){
    int f=0,fu=1; char c=getchar();
    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
    return f*fu;
}
inline ll ql(){
	ll f=0;int fu=1; char c=getchar();
    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
    return f*fu;
}
int a[MAX_N];
int main()
{
	ll ans=0;
	int n=qi();
	repi(i,1,n) a[i]=qi();
	repi(i,2,n)if(a[i]<a[i-1]) ans+=(a[i-1]-a[i]),a[i]=a[i-1];
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;


void AGC039A()
{
	string S;
	cin >> S;
	ll K;
	cin >> K;
	ll ct = 0;
	int N = S.size();

	bool isSingle = true;
	for (int i = 1; i < N; ++i)
	{
		if (S[i] != S[0])
		{
			isSingle = false;
			break;
		}
	}
	if (isSingle)
	{
		cout << N * K / 2 << endl;
		return;
	}


	bool update = false;
	for (int i = 1; i < N; ++i)
	{
		if (!update && S[i] == S[i - 1])
		{
			++ct;
			update = true;
		}
		else
			update = false;
	}
	ct *= K;
	if (K > 1 && S.back() == S[0] && !update)
	{
		int ct2 = 0;
		for (int i = 1; i < N; ++i)
		{
			if (S[i] != S[0])
				break;
			++ct2;
		}
		if (ct2 % 2 == 0)
			ct += K - 1;
	}
	cout << ct << endl;
}

int main()
{
	AGC039A();
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  int maxP;
  int sum = 0;
  for(int i = 0; i < n; i ++){
    int p;
    scanf("%d", &p);
    if(i == 0 || maxP < p) maxP = p;
    sum += p;
  }
  sum -= maxP/2;
  printf("%d", sum);
  return 0;
}

Measured memory_bytes: 128
from fractions import gcd
a,b,c,d = map(int,input().split())
if a % c == 0:
    c_times = b//c - a//c + 1
else:
    c_times = b//c - a//c
#print(c_times)
if a % d == 0:
    d_times = b//d - a//d +1
else:
    d_times = b//d - a//d
#print(d_times)
lcm = c*d // gcd(c,d)
if a % lcm == 0:
    lcm_times = b//lcm - a//lcm +1
else:
    lcm_times = b//lcm - a//lcm
#print(lcm_times)
total = (b-a+1) - (c_times + d_times - lcm_times)
print(total)

Measured memory_bytes: 5052
#include<climits>
#include<iostream>

using namespace std;

int main(){
    int n;
    cin>>n;
    
    long long int sum=1LL;
    int c=0;
    long long int o=1000000000000000000LL;
    
    for(int i=1;i<=n;i++){
        long long int t;
        cin>>t;
        if(t==0){
            c=0;
            sum=0;
            break;
        }
        if(sum>o/t)
            c++;
        sum *=t;
    }
    
    cout<<(c ? -1 : sum)<<endl;
}

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

int main() {
  int a, b, c;
  string d;
  cin >> d;
  
  int count = 0;
  for (int i = 0; i < 3; i++) {
    if (d.at(i) == '1') count++;
  }
  cout << count;
}


Measured memory_bytes: 256
from math import factorial as fact
from operator import mul
from functools import reduce
import sys
input = sys.stdin.readline


def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


N, M = map(int, input().split())
num = []
p_flag = [True]*(int(M**0.5)+2)

for i in range(2, int(M**0.5)+2):
    if p_flag:
        for j in range(2*i, int(M**0.5)+2, i):
            p_flag[j] = False

        cnt = 0
        while M % i == 0:
            cnt += 1
            M //= i
        if cnt > 0:
            num.append(cnt)
        if M == 1:
            break
else:
    num.append(1)

ans = 1
for i in num:
    ans = (ans * cmb(N-1+i, i)) % (10**9+7)
print(ans)

Measured memory_bytes: 3936
# 最小公倍数を返す
def euclid(x, y):
    x_1 = x
    y_1 = y
    a = x_1%y_1
    while a != 0:
        x_1 = y_1
        y_1 = a
        a = x_1%y_1
    return (x * y) // y_1

# x以下のCとDで割り切れる数を返す
def dif(x, C, D):
    return x - (x//C) - (x//D) + (x//(euclid(C, D)))

def main():
    A, B, C, D = map(int, input().split())
    return dif(B, C, D) - dif((A-1), C, D)

if __name__ == '__main__':
    print(int(main()))

Measured memory_bytes: 3064
/*
 * Welcome to my code!
 * -------------------------------------------- *
 * author : lynmisakura(twitter : @andoreiji11)
 */

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define repn for(int i = 0;i < n;i++)
#define ain(a) for(auto& i : a)cin >> i;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define cont continue

//Simple Array Input
#define SAI int n;cin >> n;vi a(n);ain(a)
//Simple Graph Input
#define SGI(m) for(int i=0;i<m;i++){int a,b;cin >> a >> b;g[--a].pb(--b);g[b].pb(a);}
//Simple Tree Input
#define STI SGI(n-1)

typedef long long ll;
typedef long long integer;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
template<class T> void print(std::vector<T> a){
    for(int i=0;i<a.size();i++)cout << a[i] << (i < a.size()-1 ? ' ' : '\n');
}
long long gcd(long long a, long long b) {
  return b != 0 ? gcd(b, a % b) : a;
}
long long lcm(long long a, long long b) {
  return a * b / gcd(a, b);
}
// a x + b y = gcd(a, b)
long long extgcd(long long a, long long b, long long &x, long long &y) {
  long long g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}

bool func(ll& n,ll& a,ll& b){
  
  ll g1 = gcd(a , b);
  
  ll p = a * b / g1;
  ll q = (a + b) / g1;

  ll g2 = gcd(n , p);
  
  if(4LL * p - n * q == g2){
    cout << a << ' ' << b << ' ' << n * p / g2 << '\n';
    return true;
  }else return false;

}


int main(int argc, char const *argv[])
{
  long long n;cin >> n;
  for(ll a = 1;a <= 3500;a++){
    for(ll b = 1;b <= 3500;b++){
      if(func(n,a,b))return 0; 
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
       String s=sc.nextLine();
       if(s.equals("acb")||s.equals("abc")||s.equals("bac")||s.equals("bca")||s.equals("cab")||s.equals("cba"))
    	   System.out.println("Yes");
       else
    	   System.out.println("No");
    }
    }

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(long int I=X;I<Y;I++)
#define REP(I,X) for(long int I=X;I>=0;I--)
#define INF 1e9+7
using namespace std;

struct vec{
  double x;
  double y;
  double z;
  vec operator+(const vec & vec2)const{
    return {x+vec2.x,y+vec2.y,z+vec2.z};
  }
  vec operator-(const vec & vec2)const{
    return {x-vec2.x,y-vec2.y,z-vec2.z};
  }
  double operator*(const vec & vec2)const{
    return x*vec2.x+y*vec2.y+z*vec2.z;
  }
};

double ABS(vec v){
  return sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
}

vec multiple(vec v,double k){
  return {k*v.x,k*v.y,k*v.z};
}

vec standardize(vec v){
  return multiple(v,1/ABS(v));
}

int main(){
  double x1,y1,x2,y2,x,y;
  int q;
  cin >> x1 >> y1 >> x2 >> y2 >> q;
  vec p1 = {x1,y1,0},p2 = {x2,y2,0},p1p2 = p2 - p1;
  vector<vec> ans;
  FOR(i,0,q){
    cin >> x >> y;
    vec v = {x,y,0};
    v = multiple(standardize(p2-p1),(v-p1)*standardize(p1p2));
    ans.push_back(v+p1);
  }
  for(auto p:ans)cout << fixed << setprecision(15) << p.x << " " << p.y << endl;
}



Measured memory_bytes: 3332
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007

int main(){
    int n,m;
    int sum=0;
    cin >> n;
    vector<int>t(n);
    rep(i,n) {
        int a;
        cin >> a;
        t[i]=a;
        sum+=a;
    }
    cin >> m;
    rep(i,m){
        int p,x;
        cin >> p >> x;
        cout << sum-t[p-1]+x << endl;
    }
    return 0;
}

Measured memory_bytes: 256