akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
using LL = long long;
using VLL = std::vector<LL>;
using VVLL = std::vector<VLL>;
using VVVLL = std::vector<VVLL>;
using LD = long double;
using VLD = std::vector<LD>;
using VVLD = std::vector<VLD>;
using VVVLD = std::vector<VVLD>;
using BL = bool;
using VBL = std::vector<BL>;
using VVBL = std::vector<VBL>;
using VVVBL = std::vector<VVBL>;


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; }

//template<class T=LL> inline vector<T> cinv(LL N){ vector<T> v(N); REP(i, N)cin>>v[i]; return move(v);}
//template<class T=LL> inline vector<T> cinv(LL N){ vector<T> v(N); REP(i, N)cin>>v[i]; return move(v);}
#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl
#define cmax(a,b) {if(a<b){a=b;}}
#define cmin(a,b) {if(a>b){a=b;}}
#define EACH(a,A) for(auto a: A)
//#define cmax(a,b) a = (a>b ? a:b)
//#define cmin(a,b) a = (a<b ? a:b) 
//cin,cout高速化のおまじない＋桁数指定
inline VLL cinvll(LL N){
  VLL A(N);
  REP(i,N){
    cin >> A[i];
  }
  return move(A);
}
inline VVLL zerosll(LL H, LL W){
  VVLL A(H,VLL(W,0));
  return move(A);
}
struct Fast{
	Fast(){
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(std::numeric_limits<double>::max_digits10);
	}
} fast;

LL H;
LL W;  
VVLL M;
VVLL A;

VLL cnt(2);
void dfs(LL i, LL j,LL v ){
  if(A[i][j]!=0){
    return;
  }
  A[i][j]=v;
  cnt[M[i][j]]++;

  if(i+1<H and M[i+1][j]!= M[i][j]){
    dfs(i+1,j,v);
  }
  if(i-1>=0 and M[i-1][j]!= M[i][j]){
    dfs(i-1,j,v);
  }
  if(j+1<W and M[i][j+1]!= M[i][j]){
    dfs(i,j+1,v);
  }
  if(j-1>=0 and M[i][j-1]!= M[i][j]){
    dfs(i,j-1,v);
  }

}


void func(){
  cin >> H;
  cin >> W;
  M = zerosll(H,W);
  A = zerosll(H,W);
  REP(i,H){
    string s;
    cin >> s;
    REP(j,(LL)s.length()){
      if(s[j]=='#'){
        M[i][j]=1;
      }
    }
  }

  // REP(i,H){
  //   PRINTSP(M[i]);
  // }
  // REP(i,H){
  //   PRINTSP(A[i]);
  // }

  LL color=0;
  VLL C;

  REP(i,H){
    REP(j,W){
      if(A[i][j]==0){
        cnt[0]=0;
        cnt[1]=0;
        dfs(i,j,++color);
        C.push_back(cnt[0]*cnt[1]);
      }
    }
  }
  // REP(i,H){
  //   PRINTSP(A[i]);
  // }
  // PRINTSP(C);
  LL ans = 0;
  for(auto c : C){
    ans +=c;
  }
  cout << ans;

} 

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

Measured memory_bytes: 17792
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    string o, e; cin >> o >> e;

    vector<char> ans;
    rep(i, o.size()) {
        ans.push_back(o[i]);
        if (i == (int)e.size()) continue;
        ans.push_back(e[i]);
    }
    for (auto &ch: ans) {
        cout << ch;
    }
    cout << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int solve(int x){
    return x * x * x;
}

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

    int ans = solve(n);

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



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "NO" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  998244353
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
ll locker[32];
ll N;
vector<ll> solve(ll n, ll a, ll b){
    if(n==1) return {a,b};
    // a,bで異なるkbit目を探す。
    ll k=0;
    rep(i,N) if((a>>i&1)^(b>>i&1)) k=i;
    locker[k]=1;
    // 今まで選んだkbit以外のxbitを変えたものまでの移動
    ll x;
    rep(i,N){
        if(locker[i]==1) continue;
        x=i; break;
    }
    ll c=a^(1<<x);
    auto res1=solve(n-1,a,c);
    // kbitを変えてもとに戻す
    c^=1<<k;
    auto res2=solve(n-1,c,b);
    // 連結してreturn
    res1.insert(res1.end(),ALL(res2));
    locker[k]=0;
    return res1;
}
//--MAIN-----------------------------------
void Main() {
    ll A,B;
    cin>>N>>A>>B;
    ll C=A^B;
    ll ct=0;
    rep(i,N) ct+=(C>>i)&1;
    if(ct%2==0) dame;
    auto ans=solve(N,A,B);
    cout<< "YES"<<"\n";
    for(auto x: ans) cout<< x <<" ";
    cout<<"\n";
}

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


Measured memory_bytes: 2416
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

ll dp[2010];

int main(){
	int S; cin >> S;
	dp[0] = 1;
	rep(i,2010){
		repr(j,3,2010){
			if(i+j > 2010) continue;
			dp[i+j] += dp[i];
			dp[i+j] %= MOD;
		}
	}
	cout << dp[S] << endl;
}



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

int main(){
 int a, b;
  cin>>a>>b;
  int k;
	k=(a+b)/2;
	if(!(abs(a-k) == abs(b-k)))
	   k= -1;
  if(k==-1)
    cout<<"IMPOSSIBLE"<<endl;
  else
    cout<<k<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();
            for(int i=0;i < a.Length - 1; i++)
            {
                if (a[i] == a[i + 1])
                {
                    Console.Write("Bad");
                    return;
                }
            }
            Console.Write("Good");
            
        }
    }
}

Measured memory_bytes: 13140
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

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

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

double w , h , x , y;

int main() {
    fast_io;

    cin >> w >> h >> x >> y;

    printf("%.10f %d" , w * h / 2 , (x == w - x && y == h - y ? 1 : 0));

    return 0;
}
/*

*/


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 int main(){
   int A, B, C, X;
   cin >> A >> B >> C >> X;
   int res = 0;
   for (int a = 0; a <= A; ++a){
     for (int b = 0; b <= B; ++b){
       for (int c = 0; c <= C; ++c){
         int total =500*a + 100*b + 50*c;
         if (total == X) ++res;
       }
     }
   }
   cout << res << endl;
 }


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

int main(){
    ll n;
    cin>>n;
    tuple<long long, long long, long long>G = make_tuple(-1, -1, -1);
    vector<ll> x(n);
    vector<ll> y(n);
    vector<ll> h(n);
    rep(i,n){
        cin>>x[i]>>y[i]>>h[i];
        if (h[i] >= 1) G = make_tuple(x[i], y[i], h[i]);
    }
    ll ax,ay,hhh;
    rep(i,101){
        rep(j,101){
            ll hh=0;
            bool fk=false;
            hh=get<2>(G)+abs(i-get<0>(G))+abs(j-get<1>(G));
            bool f=true;
            rep(k,n){
                ll h2=hh-abs(i-x[k])-abs(j-y[k]);
                h2=max(h2,0LL);
                if(h2!=h[k]) f=false;
            }
            if(f==true){
                ax=i,ay=j,hhh=hh;
            }
        }
    }
    cout<<ax<<" "<<ay<<" "<<hhh<<endl;
}


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

struct Point
{
  double x, y;
};

void koch(int n, Point a, Point b)
{
  if (n == 0)
    return;

  Point s, t, u;
  double th = M_PI * 60.0 / 180.0;

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n - 1, a, s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(n - 1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(n - 1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(n - 1, t, b);
}

int main()
{
  Point p1, p2;
  int n;

  scanf("%d", &n);

  p1.x = 0;
  p1.y = 0;
  p2.x = 100;
  p2.y = 0;

  printf("%.8f %.8f\n", p1.x, p1.y);
  koch(n, p1, p2);
  printf("%.8f %.8f\n", p2.x, p2.y);

  return 0;
}


Measured memory_bytes: 2740
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
string to_string(string s) {
  return '"' + s + '"';
}
string to_string(const char* s) {
  return to_string((string) s);
}
string to_string(bool b) {
  return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define show(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)
#else
#define show(...) 42
#endif
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define  oo 1e15
#define limit 1000000007
#define two pair<int,int>
#define ll long long int
#define int long long int
#define mod(x,m) ((x%m+m)%m)
#define all(v) v.begin(),v.end()
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define fori(x,n) for(int i = x; i < n; i++)
#define forj(y,m) for(int j = y; j < m; j++)
#define fork(z,p) for(int k = z; k < p; k++)
#define speedforces std::ios::sync_with_stdio(false)
#define input_from_file  freopen("input.txt", "r", stdin);
#define output_to_file  freopen("output.txt", "w", stdout);

signed main(){
  //input_from_file;
  speedforces;
  int n; cin>>n;
  int v[n+1][4];
  int dp[n+1][4];
  memset(dp,0,sizeof dp);
  fori(1,n+1) forj(1,4) cin>>v[i][j];
  fori(1,n+1) forj(1,4) {
    if(j == 1) dp[i][j] = max(dp[i-1][j+1],dp[i-1][j+2])+v[i][j];
    if(j == 2) dp[i][j] = max(dp[i-1][j-1],dp[i-1][j+1])+v[i][j];
    if(j == 3) dp[i][j] = max(dp[i-1][j-1],dp[i-1][j-2])+v[i][j];
  }
  cout<<max3(dp[n][1],dp[n][2],dp[n][3])<<endl;
 }


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const ll mod=998244353;

int main()
{
    string s;
    cin>>s;
    ll ans=0;
    for(int i=0; i<s.length(); i++)
    {
        ans+=(s[i]-'0');
    }
    if(ans%9==0)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 3752
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let N: usize = read_line().parse().unwrap();
    let mut A = vec![0; N];
    let mut max = 0;
    let mut second_max = 0;
    for i in 0..N {
        A[i] = read_line().parse().unwrap();
        if max < A[i] {
            max = A[i];
        } else if second_max < A[i] {
            second_max = A[i];
        }
    }
    for a in A {
        if a == max {
            println!("{}", second_max);
        } else {
            println!("{}", max);
        }
    }
}


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

int main(void){
    bool isPrime[100004];
    for(int i=0;i<100004;i++) isPrime[i]=true;
    isPrime[0]=isPrime[1]=false;
    for(int i=0;i<100004;i++){
        if(isPrime[i]==true){
            for(int j=i*2;j<100004;j+=i) isPrime[j]=false;
        }
    }
    int X;
    cin >> X;
    for(int i=X;i<100004;i++){
        if(isPrime[i]){
            cout << i;
            break;
        }
    }
}

Measured memory_bytes: 3732
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef long long ll;
#define sz(a) int((a).size()) 
#define pb push_back 
#define all(c) (c).begin(),(c).end() 
#define rep(i, n) for(int i = 0; i < n; ++i) 
#define foreach(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) 

#define TRACE(x...) x
#define watch(x) TRACE(cout << #x" = " << x << endl)
#define watcharr(i, x) TRACE(cout << #x" = "); rep(i, sz(x)) cout << x[i] << " "; cout << endl

int main() {
	
	ifstream infile("input.in");
	if(infile.good()) cin.rdbuf(infile.rdbuf());
	
    int X; cin >> X;

    int ra = 0, rb = 0;
    //120^5 - (-120)^5 = 2 * 120^5 > 10^9, que eh o constraint do problema
    for(int a = -120; a <= 120; a++)
        for(int b = -120; b <= 120; b++) 
            if(pow(a, 5.0) - pow(b, 5.0) == X)
                ra = a, rb = b;
    
    cout << ra << " "  << rb << endl;

	if(infile.good()) infile.close();
	return 0;
	
}


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

int main(void){
  int n, p[31] = {1, 1, 2};
  for(int i = 3; i <= 30; i++){
    p[i] = p[i-1] + p[i-2] + p[i-3];
  }
  while(true){
    cin >> n;
    if(n == 0) break;
    cout << (p[n] / 10 / 365) + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <unordered_map>
#include <vector>

int main()
{
    std::string s, t;
    std::cin >> s >> t;

    std::unordered_map<char, std::vector<int>> char_pos;

    for (int i = 0; i < s.length(); i++) {
        char_pos[s[i]].push_back(i);
    }

    for (int i = 0; i < s.length(); i++) {
        char_pos[s[i]].push_back(i + s.length());
    }

    int ptr = 0;
    long long ans = 0;
    for (auto c : t) {
        if (char_pos[c].empty()) {
            std::cout << -1 << std::endl;
            return 0;
        }

        ptr = *lower_bound(char_pos[c].begin(), char_pos[c].end(), ptr) + 1;

        if (ptr >= s.length()) {
            ptr -= s.length();
            ans += s.length();
        }
    }

    ans += ptr;
    std::cout << ans << std::endl;
}


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

using namespace std;
using ll = long long;

void solve1(int n, vector<int>& ar) {
	vector<vector<ll>> dp(n + 2, vector<ll>(3, -1e18));
	dp[0][0] = 0;
	for (int i = 0; i <= n; ++i) {
		for (int skip = 0; skip < 3; ++skip) {
			if (i < n) {
				dp[i + 2][skip] = max(dp[i + 2][skip], dp[i][skip] + ar[i]);
			}
			if (skip < 2) {
				dp[i + 1][skip + 1] = max(dp[i + 1][skip + 1], dp[i][skip]);
			}
		}
	}
	cout << dp[n + 1][2] << endl;
}

void solve2(int n, vector<int>& ar) {
	vector<vector<ll>> dp(n + 2, vector<ll>(2, -1e18));
	dp[0][0] = 0;
	for (int i = 0; i <= n; ++i) {
		for (int skip = 0; skip < 2; ++skip) {
			if (i < n) {
				dp[i + 2][skip] = max(dp[i + 2][skip], dp[i][skip] + ar[i]);
			}
			if (skip < 1) {
				dp[i + 1][skip + 1] = max(dp[i + 1][skip + 1], dp[i][skip]);
			}
		}
	}
	cout << dp[n + 1][1] << endl;
}

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> ar(n);
	for (int& v: ar) {
		cin >> v;
	}
	if (n & 1) {
		solve1(n, ar);
	} else {
		solve2(n, ar);
	}
}

Measured memory_bytes: 15140
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstdio>

#include<vector>
using namespace std;
int a[233333];  //A数组
int b[233333];  //B数组
long long ans;  //注意开ll！
vector<int> v;
int sum;
int main(){
    int n;
    cin>>n;
    sum=n;
    for(int i=0;i<n;i++){//读入
        cin>>a[i];
    }
    for(int i=0;i<n;i++){//读入
        cin>>b[i];
    }
    bool flag=true;
    for(int i=0;i<n;i++){
        ans+=a[i]-b[i];//算贡献值
        if(a[i]>=b[i]){//如果贡献值非负
            v.push_back(a[i]-b[i]);//压入贡献值
        }
        else{
            flag=false;
        }
    }
    if(flag){//如果所有人都是非负贡献值
        puts("0");//不需要改变
        return 0;
    }
    sort(v.begin(),v.end());
    if(ans>=0){
        for(int i=0;i<v.size();i++){
            if(ans>=v[i]){//返还贡献值
                ans-=v[i];
                sum--;//计算答案
            }
            else{
                break;
            }
        }
        cout<<sum<<endl;//输出
    }
    else{
        puts("-1");
    }
    return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << x << endl
using namespace std;
int pt[123456], v, e, ans;
pair<int, int>g[123456]; vector<pair<int, int>>vt;
void setup() {
	cin >> v >> e;
	for0(i, v) pt[i] = i;
	return;
}
int root(int i) {
	if (pt[i] == i)return i;
	else return pt[i] = root(pt[i]);
}
void unite(int a, int b) {
	pt[root(b)] = root(a);
	root(b);
	return;
}
signed main() {
	setup();
	for0(i, e) {
		int vi;
		cin >> g[i].first >> g[i].second >> vi;
		vt.push_back(mp(vi, i));
	}
	sort(all(vt));
	for0(i, e) {
		if (root(g[vt[i].second].first) != root(g[vt[i].second].second)) {
			unite(g[vt[i].second].first, g[vt[i].second].second);
			ans += vt[i].first;
		}
	}
	puts(ans);
}


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

string S;
 
signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> S;
    int r = 0, b = 0;
    rep(i, S.size()) {
        if (S[i]=='0') {
            if (b>0) b--;
            else r++;
        }
        else {
            if (r>0) r--;
            else b++;
        }
    }
    cout << S.size()-r-b << endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HIGHINF = (ll)1e18;
const ll LOWINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int N; 
vector<double> x,y;


//Euclidean distance
template<class T> T EucDist(T x1, T y1, T x2, T y2) {
    return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}

int main() {
    cin >> N;
    x.resize(N);
    y.resize(N);
    for(int i = 0; i < N; ++i) cin >> x[i] >> y[i];
    vector<int> idx(N);
    iota(ALL(idx),0);

    double C = 1;
    for(int i = 1; i <= N; ++i) C *= i;
    double ans = 0;
    do {
        double sum = 0;
        for(int i = 0; i+1 < N; ++i){
            sum += EucDist(x[idx[i]],y[idx[i]],x[idx[i+1]],y[idx[i+1]]);
        }
        ans += sum/C;
    } while (std::next_permutation(idx.begin(), idx.end()));
    printf("%.10f",ans);

}


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

int main(){
    string S;
    cin >> S;
    vector<int> a(26);
    for (int i=1; i<=S.size(); i++) {
        a.at((int)S.at(i-1)-97)++;
    }
    for (int i='a'-97; i<='z'-97; i++) {
        if (a.at(i)==0) {
            int ans=i+97;
            cout << (char)ans << endl;
            return 0;
        }       
    }
    cout << "None" << endl;
 }

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<map>
#include<set>
#include<algorithm>
using namespace std;

static const int MAX_WORD_LEN = 30;
static const int MAX_PAGE_NUM = 1000;
static const int MAX_BOOK_NUM = 100;

static const int VOID_PAGE    = -1;

class BookIndex {
public:
  BookIndex() {}
  ~BookIndex() {}
  // ????????????????????°????????????
  void SetWord(string word_, int page_) {
    word_page.insert(M::value_type(word_, page_));
  }
  // ??¨??????????????????????????°?????????
  void PrintWords() {
    for (MIT it = word_page.begin(); it != word_page.end();) {
      cout << it->first << endl;
      int count = word_page.count(it->first);
      set<int> st;
      for (int i = 0; i < count; i++) {
        st.insert(it++->second);
      }
      set<int>::iterator st_it = st.begin();
      cout << *st_it++;
      for (; st_it != st.end();st_it++) {
        cout << " " << *st_it;
      }
      cout << endl;
    }
  }
private:
  typedef multimap<string, int> M;
  typedef M::iterator           MIT;
  M word_page;
};

int main() {
  BookIndex book;

  // ??\????????°
  string word;
  int    page;
  while (cin >> word) {
    cin >> page;
    book.SetWord(word, page);
  }
  book.PrintWords();
}

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

int main(){
    int a, b;
    while (cin >> a >> b){
	a += b;
	b = 1;
	while(1){
	    if (a < 10) break;
	    a /= 10;
	    b++;
	}
	cout << b << endl;
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<stdio.h>
using namespace std;
   int main(){
	int N;
		scanf("%d",&N);
	
		
	int r,sum=0,x;
	x=N;
	if((N>=100)&&(N<=999)){
   while(N)
	{
	  
	  
		r=N%10;
		N=N/10;
		sum=sum*10+r;
		
}

    
	  
	if(x==sum)
	printf("Yes");
	else
	printf("No");
}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int L, R;
  cin >> L >> R;

  if (R - L >= 2019)
  {
    cout << 0 << endl;
    return 0;
  }

  L %= 2019;
  R %= 2019;
  if (L >= R)
  {
    cout << 0 << endl;
    return 0;
  }

  int mn = 2020;
  for (int i = L; i < R; i++)
  {
    for (int j = i + 1; j <= R; j++)
    {
      int m = i * j % 2019;
      if (mn > m)
        mn = m;
    }
  }

  cout << mn << endl;

  return 0;
}


Measured memory_bytes: 3636
a,b,c,d,e,f = map(int, input().split())
water_list = []
for i in range(f+1):
    for j in range(f+1):
        water = a * 100 * i + b * 100 * j
        if water <= f:
            water_list.append(water)
        else:
            break
            
sugar_list = []
for i in range(f+1):
    for j in range(f+1):
        sugar = c * i + d * j
        if sugar <= f:
            sugar_list.append(sugar)
        else:
            break
            
ans = []
for i in list(set(water_list)):
    for j in list(set(sugar_list)):
        if i != 0:
            if float(j) / i  <= e / 100 and (i + j) <= f:
                ans.append((i+j, j))
                
ans_sorted = sorted(ans, key=lambda x: (x[1] / (x[0])))[-1]
print(ans_sorted[0],ans_sorted[1])

Measured memory_bytes: 12820
from sys import stdin, stdout


def readLine_int_list(): return list(map(int, stdin.readline().split()))


def main():
    n = input()
    a = readLine_int_list()

    c = []
    _c = []

    for i in a:
        rank = i // 400
        if rank > 7:
            _c.append(rank)
        else:
            c.append(rank)

    p = len(set(c))
    print(max(1, p), p + len(_c))


if __name__ == "__main__":
    main()



Measured memory_bytes: 3060
import java.util.Scanner;

import javax.sql.rowset.serial.SerialArray;

public class Main {

		public static void main(String[] args){
			
			Scanner sc = new Scanner(System.in);

			String str = sc.next();

			StringBuilder result = new StringBuilder();

			//インデックスは0からスタートするので，奇数番目の文字は偶数のインデックスになる
		    for(int i = 0; i < str.length(); i += 2){
		        result.append(str.charAt(i));
		    }
		    System.out.println(result);

		}
}


Measured memory_bytes: 25956
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  int temp;
  temp = a;
  a = b;
  b = temp;
  temp = a;
  a = c;
  c = temp;
  cout << a <<" " << b << " "<<c;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int ans=0;
    int cnt=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A' ||s[i]=='T' ||s[i]=='G' ||s[i]=='C'){
            ans++;
            
        }else{
            ans = 0;
        }
        cnt = max(cnt,ans);
    }
    
    cout<< cnt <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long maximum;
long long mod = 1000000007;
const int INF = 1001001001;
vector<vector<int>> dp;

int main(){
  ll n;
  cin >> n;
  vector<ll> kir(n);
  ll input;
  ll val = 0;
  for(ll i=0;i<n;i++){
    cin >> input;
    val += input;
    kir.at(i) = val;
  }
  ll dist = 2020202020 * 100000;
  for(ll i=0;i<n;i++){
    dist = min(dist, abs(kir.at(i)*2-kir.at(n-1)));            
  }
  cout << dist << endl;
}


Measured memory_bytes: 1792
/* ITP1_11_A */
#include <stdio.h>

#define HEXA 6
#define ORDER_MAX_LENGTH 101
#define N_CODE 78
#define S_CODE 83
#define W_CODE 87
#define E_CODE 69

/* ?????¢????????¨????§??????? */
typedef struct {
	short surface[HEXA];
} hexahedron;

/* ?????????????????????????????¢??° */
void init_array_short(short array_sh[], short size);
/* ???????????????????????????????????¢??° */
void init_array_char(char array_ch[], short size);
/* ?????¢????????¶???????¨???? */
void rotate(hexahedron *dice, char rotate);
/* N?????????????????¢????????? */
void rotate_N(hexahedron *dice);
/* S?????????????????¢????????? */
void rotate_S(hexahedron *dice);
/* W?????????????????¢????????? */
void rotate_W(hexahedron *dice);
/* E?????????????????¢????????? */
void rotate_E(hexahedron *dice);

int main(void)
{
	hexahedron dice;
	init_array_short(dice.surface, HEXA);
	
	short ii;
	for( ii = 0; ii < HEXA; ii++ )
	{
		scanf("%hd", &dice.surface[ii]);
	}
	
	char order_array[ORDER_MAX_LENGTH];
	init_array_char(order_array, ORDER_MAX_LENGTH);
	
	scanf("%s", order_array);
	
	for( ii = 0; '\0' != order_array[ii] && '\n' != order_array[ii]; ii++ )
	{
		rotate(&dice, order_array[ii]);
	}
	
	printf("%hd\n", dice.surface[0]);
	
	return 0;
}

/* ?????????????????????????????¢??° */
void init_array_short(short array_sh[], short size)
{
	short ii;
	for( ii = 0; ii < size; ii++ )
	{
		array_sh[ii] = 0;
	}
}

/* ???????????????????????????????????¢??° */
void init_array_char(char array_ch[], short size)
{
	short ii;
	for( ii = 0; ii < size; ii++ )
	{
		array_ch[ii] = '\0';
	}
}

/* ?????¢????????¶???????¨???? */
void rotate(hexahedron *dice, char rotate)
{
	switch( rotate )
	{
	case N_CODE:
		rotate_N(dice);
		break;
	case S_CODE:
		rotate_S(dice);
		break;
	case W_CODE:
		rotate_W(dice);
		break;
	case E_CODE:
		rotate_E(dice);
		break;
	default:
		break;
	}
}

/* N?????????????????¢????????? */
void rotate_N(hexahedron *dice)
{
	short temp = dice->surface[0];
	dice->surface[0] = dice->surface[1];
	dice->surface[1] = dice->surface[5];
	dice->surface[5] = dice->surface[4];
	dice->surface[4] = temp;
}

/* S?????????????????¢????????? */
void rotate_S(hexahedron *dice)
{
	short temp = dice->surface[1];
	dice->surface[1] = dice->surface[0];
	dice->surface[0] = dice->surface[4];
	dice->surface[4] = dice->surface[5];
	dice->surface[5] = temp;
}

/* W?????????????????¢????????? */
void rotate_W(hexahedron *dice)
{
	short temp = dice->surface[3];
	dice->surface[3] = dice->surface[0];
	dice->surface[0] = dice->surface[2];
	dice->surface[2] = dice->surface[5];
	dice->surface[5] = temp;
}

/* E?????????????????¢????????? */
void rotate_E(hexahedron *dice)
{
	short temp = dice->surface[2];
	dice->surface[2] = dice->surface[0];
	dice->surface[0] = dice->surface[3];
	dice->surface[3] = dice->surface[5];
	dice->surface[5] = temp;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it = (c).begin(); it != (c).end(); it++)
#define X first
#define Y second

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int N = (int)1e6 + 1;
int main(void){
    bool isP[N];
    memset(isP, true, N);
    isP[0] = isP[1] = false;
    for(int i = 2; i * i < N; i++) if(isP[i]) for(int j = i * i; j < N; j += i) isP[j] = false;

    for(int a, d, n; cin >> a >> d >> n, a; cout << a - d << endl){
        while(n > 0){
            if(isP[a]) n--;
            a += d;
        }
    }
    return 0;
}

Measured memory_bytes: 2144
#include<cstdio>
#include<functional>
#include<algorithm>
#define MM 2000000000
#define F first
#define S1 second.first
#define S2 second.second
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P2;
P2 pp[200000];
int main(void)
{
	int v,e,i,j,s,t,w,par[100000],leng[100000],sum,x,y,cnt;
	scanf("%d %d",&v,&e);
	for(i=0;i<v;i++)	{
		par[i]=i;	leng[i]=1;
	}
	for(i=0;i<e;i++)	{
		scanf("%d %d %d",&s,&t,&w);
		pp[i].F=w;	pp[i].S1=s;	pp[i].S2=t;
	}
	sort(pp,pp+e);
	sum=0;	cnt=0;
	for(i=0;i<e;i++)	{
		x=pp[i].S1;	y=pp[i].S2;
		while(x!=par[x])	x=par[x];
		while(y!=par[y])	y=par[y];
		if(x!=y)	{
			sum+=pp[i].F;
			cnt++;
			if(leng[x]>leng[y])	par[y]=x;
			else if(leng[x]<leng[y])	par[x]=y;
			else {
				par[y]=x;
				leng[x]++;
			}
		}
		if(cnt==v-1)	break;
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 5148
#include<stdio.h>
#include<math.h>
int main()
{

       int a,b,j, k,i,d;

       scanf("%d%d",&a,&b);
       if(a>=500)
       {
           d=a%500;
           if(d<=b)
           {
               printf("Yes");

           }
           else
           {
               printf("No");
           }
       }

       else if(a<500)
       {
           if(b>=a){
             printf("Yes");
           }
           else
           {
               printf("No");
           }

       }
      return 0;

      }



Measured memory_bytes: 1672
N = int(input())
S = input()

RN = S.count('R')
GN = S.count('G')
BN = S.count('B')

ans = RN * GN * BN

for i in range(N):
    for d in range(N):
        j = i + d
        k = i + 2 * d
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -= 1

print(ans)

Measured memory_bytes: 9176
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int S = in.nextInt();
        int h = S/(60*60);
        S -= h*60*60;
        int m = S/60;
        int s = S%60;
        System.out.println(h + ":" + m + ":" + s);
    }
}

Measured memory_bytes: 26024
#pragma GCC Optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lp(i,begin,end) for (int i=begin;i<end;i++)
const int N=30,M=N*N,OO=0x3f3f3f3f;
int freq[30];
int main(){
    string s;
    cin>>s;
    lp(i,0,s.length())
        freq[s[i]-'a']++;
    bool f=1;
    lp(i,0,26)
        if(freq[i]&1){f=0;  break;}
    f?cout<<"Yes":cout<<"No";
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		String st=sc.next();
		int max=0;
		for(int i=0;i<3;i++)
		{
			int j=i,count=0;
			while(j<3&&st.charAt(j)=='R') 
				{
					count++;
					j++;
				}
			max=Math.max(max, count);
		}
		System.out.println(max);
	}
	
}


Measured memory_bytes: 35464
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
 
ll MOD = 1000000007;
ll INF =1<<29;
ll dp[100100];
 
int main() {
     ll a,b,k;
     cin >> a>>b>>k;
     if(a<=k) cout << 0 <<' ';
     else cout << a-k <<' ';
     if(b<max((ll)0,k-a)){
         cout <<0 <<endl;
     }
     else cout << b-max((ll)0,k-a)<<endl;
}

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

int main()
{
  int a, b;
  cin >> a >> b;

  if ((a + b) % 3 == 0 || a % 3 == 0 || b % 3 == 0)
    cout << "Possible";
  else
  {
    cout << "Impossible";
  }
}


Measured memory_bytes: 3604
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
const int MaxN=100010,MaxM=100010;
int N,M,A[MaxM],B[MaxM],C[MaxM],ind[MaxN],outd[MaxN],fa[MaxN],max_outd[MaxN];
int L1[MaxM],L2[MaxM];
int find(int i){return fa[i]==i?i:fa[i]=find(fa[i]);}
int calc(){
	for(int i=1;i<=N;i++)fa[i]=i,ind[i]=outd[i]=max_outd[i]=0;
	for(int i=0;i<M;i++){
		outd[A[i]]++;ind[B[i]]++;
		fa[find(A[i])]=find(B[i]);
	}
	for(int i=1;i<=N;i++){
		if(outd[i]&&!ind[i])return-1;
		if(outd[i]>max_outd[find(i)])max_outd[find(i)]=outd[i];
	}
	int ans=0,cc=0,cnt1=0,cnt2=0;
	long long sc1=0,sc2=0;
	for(int i=1;i<=N;i++)if(fa[i]==i&&max_outd[i]==1)cc++;
	for(int i=0;i<M;i++){
		if(A[i]!=B[i]){
			ans++;
			if(max_outd[find(A[i])]==1)sc2+=C[i]-1;
			else sc1+=C[i]-1;
		}
		else{
			if(max_outd[find(A[i])]==1){
				cc--;
				if(C[i]>2)L2[cnt2++]=2-C[i];
			}
			else if(C[i]>1)L1[cnt1++]=1-C[i];
		}
	}
	ans+=cc;
	cc=cc?sc2<cc?cc-sc2:1:0;
	cc=sc1<cc?cc-sc1:0;
	if(!cc)return ans;
	std::sort(L1,L1+cnt1);
	std::sort(L2,L2+cnt2);
	long long rest=cc;
	int res=-1;
	for(int i=sc1?-1:0,j=0;i<cnt1;i++){
		if(i>=0)rest+=L1[i];
		while(j<cnt2&&rest>0)rest+=L2[j++];
		while(j&&rest-L2[j-1]<=0)rest-=L2[--j];
		if(rest<=0&&(res==-1||ans+i+1+j*2<res))res=ans+i+1+j*2;
	}
	return res;
}
int main(){
	scanf("%d%d",&N,&M);
	for(int i=0;i<M;i++)scanf("%d%d%d",A+i,B+i,C+i);
	printf("%d\n",calc());
}

Measured memory_bytes: 6280
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

bool isPrime(int a) {
  for (int i = 2; i*i <= a; ++i)
  {
    if (a%i==0) return false;
  }
  return true;
}

int main()
{
  int n;
  cin>>n;
  int cnt=0;
  for (int i = 5; i <= 55555; ++i)
  {
    if (!isPrime(i)) continue;
    if (i%5==1) {
      cout<<i<<" ";
      cnt++;
    }
    if (cnt==n) return 0;
  }
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int n;

int main() {

	FAST;

	cin >> n;
	vector <int> v(n);
	int k = 0;
	for (int i = 0; i < n; i ++) {
		cin >> v[i];
		k ^= v[i];
	}
	// cout << k << '\n';
	for (int i = 0; i < n; i ++) {
		cout << (v[i] ^ k) << ' ';
	}
	return 0;
}

Measured memory_bytes: 3976
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits.h>
#include <queue>
#define rep(i,n) (int i=0;i<(int)(n);i++)
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<long long> a(n),b(n);
	for rep(i, n)
		cin >> b[i];
	for rep(i, n)
		cin >> a[i];
	vector<bool> ju(n, true);
	priority_queue<pair<long long, int>> da;
	long long ans = 0;
	for rep(i, n) {
		da.push(make_pair(a[i], i));
		ju[i] = bool(a[i] == b[i]);
	}
	while (!da.empty()) {
		int x = da.top().second;
		da.pop();
		if (!ju[x]) {
			long long y = a[(x + 1) % n] + a[(x - 1 + n) % n];
			if (a[x] <= y) {
				ans = -1;
				break;
			}
			if ((a[x]-b[x]) % y==0) {
				ans += (a[x] - b[x]) / y;
				a[x] = b[x];
				ju[x] = true;
			}
			else {
				ans += a[x] / y;
				a[x] %= y;
				if (a[x] < b[x]) {
					ans = -1;
					break;
				}
				da.push(make_pair(a[x], x));
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 9588
def f(b, n):
    return n if n < b else n % b + f(b, n // b)

def solve():
    N, S = map(int, open(0))

    if N == S:
        return N + 1

    sqr = int(N ** 0.5)

    for b in range(2, sqr + 1):
        if f(b, N) == S:
            return b

    M = N - S
    for p in reversed(range(1, sqr + 1)):
        b = M // p + 1
        if b >= 2 and f(b, N) == S:
            return b

    return -1


print(solve())

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int main(){
  int count=0;
  char s[200001],t[200001];
  scanf("%s",s);
  scanf("%s",t);
  for(int i=0;i<strlen(s)+1;i++){
    if(s[i]!=t[i]){
      count=count+1;
      }
    }
  printf("%d",count);
  }


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

int main(){
	int n;
	cin>>n;
	int s[n];
	int ans=0;
	int mi=101;
	for(int i=0;i<n;i++){
	    cin>>s[i];
	    ans+=s[i];
	    if(s[i]%10!=0){
	        mi=min(mi,s[i]);
	    }
	}
	if(ans%10!=0) cout<<ans<<endl;
	else{
	    if(mi==101) cout<<0<<endl;
	    else cout<<ans-mi<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int d, t, s;
	cin >> d >> t >> s;
	cout << (t * s >= d ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
typedef struct{
    int num[5];
}Dice;
int main(void){
    int i,n,t;
    char command[101];
    Dice dice;
    scanf("%d",&dice.num[0]);
    scanf("%d",&dice.num[1]);
    scanf("%d",&dice.num[2]);
    scanf("%d",&dice.num[3]);
    scanf("%d",&dice.num[4]);
    scanf("%d",&dice.num[5]);
    scanf("%s",command);
    n=strlen(command);
    for(i=0;i<n;i++){
        if(command[i]=='E'){
            t=dice.num[0];
            dice.num[0]=dice.num[3];
            dice.num[3]=dice.num[5];
            dice.num[5]=dice.num[2];
            dice.num[2]=t;
        }else if(command[i]=='N'){
            t=dice.num[0];
            dice.num[0]=dice.num[1];
            dice.num[1]=dice.num[5];
            dice.num[5]=dice.num[4];
            dice.num[4]=t;
        }else if(command[i]=='S'){
            t=dice.num[0];
            dice.num[0]=dice.num[4];
            dice.num[4]=dice.num[5];
            dice.num[5]=dice.num[1];
            dice.num[1]=t;
        }else{
            t=dice.num[0];
            dice.num[0]=dice.num[2];
            dice.num[2]=dice.num[5];
            dice.num[5]=dice.num[3];
            dice.num[3]=t;
        }
    }
    printf("%d\n",dice.num[0]);
    return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> x(n);
  int tmp=0;
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  int ans=x[k-1]-x[0]+min(abs(x[0]),abs(x[k-1]));
  for(int i=1;i+k<=n;i++){
    int tmp=x[i+k-1]-x[i]+min(abs(x[i]),abs(x[i+k-1]));
    if(ans>tmp)ans=tmp;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
import math
n,m = map(int,input().split())
a = int(input())
lis = list(map(int,input().split()))
ans = []
num = math.ceil(n/2)
li = []
for i in range(a):
  for k in range(lis[i]):
    li.append(str(i+1))
for i in range(n):
  l = []
  for k in range(m):
    if i % 2 == 0:
      l.append(str(li[m * i + k]))
    else:
      l.insert(0,str(li[m * i + k]))
  ans.append(l)
  
for i in range(n):print(" ".join(ans[i]))

Measured memory_bytes: 3828
h,w=map(int,input().split())
s=[list(input()) for _ in range(h)]

q=[(0,0)]
s[0][0]=0
dxy=[(1,0),(-1,0),(0,1),(0,-1)]
while q:
    x,y=q.pop(0)
    for dx,dy in dxy:
        nx,ny=x+dx,y+dy
        if not 0<=nx<w:
            continue
        if not 0<=ny<h:
            continue
        if s[ny][nx]=="#":
            continue
        if s[ny][nx]==".":
            s[ny][nx]=s[y][x]+1
            q.append((nx,ny))
        else:
            continue
if s[h-1][w-1]=="." or s[h-1][w-1]=="#":
    print(-1)
else:
    kuro=0
    for i in range(h):
        kuro+=s[i].count("#")

    print(h*w-s[h-1][w-1]-1-kuro)


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

int main(){
    int x,y,z,k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x),b(y),c(z);
    rep(i,x) cin >> a.at(i);
    rep(i,y) cin >> b.at(i);
    rep(i,z) cin >> c.at(i);
    vector<ll> ab,abc;
    rep(i,x){
        rep(j,y){
            ab.push_back(a.at(i)+b.at(j));
        }
    }
    sort(ab.rbegin(),ab.rend());

    rep(i,min(k,x*y)){
        rep(j,z){
            abc.push_back(ab.at(i)+c.at(j));
        }
    
    }
    sort(abc.rbegin(),abc.rend());
    rep(i,k){
        cout << abc.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 44108
n=int(input())
U=(1/2)*n*(n+1)
U3=(3/2)*(n//3)*(n//3+1)
U5=(5/2)*(n//5)*(n//5+1)
U15=(15/2)*(n//15)*(n//15+1)
ans=U-U3-U5+U15
print(int(ans))


Measured memory_bytes: 9092
MOD = 10**9 + 7
N, K = map(int, input().split())
A = sorted([int(i) for i in input().split()])

B = []
plus, zero, minus = 0, 0, 0
for i in range(N):
    if A[i] >= 0:
        B.append((A[i], 1))
        plus += 1
    elif A[i] == 0:
        B.append((0, 0))
        zero += 1
    else:
        B.append((-A[i], -1))
        minus += 1


if plus >= K-(min(K, minus)//2*2):
    B = sorted(B, key=lambda x: x[0], reverse=True)

    c = 1
    for i in range(K):
        c *= B[i][1]

    if c == 1:
        ans = 1
        for i in range(K):
            ans *= B[i][0]
            ans %= MOD

    else:
        ap, an = 1, 1
        skip = []
        for i in range(K-1, -1, -1):
            if B[i][1] == 1:
                ap *= B[i][0]
                skip.append(i)
                break
        else:
            skip.append(K-1)
            an = 0
        for i in range(K-1, -1, -1):
            if B[i][1] == -1:
                an *= B[i][0]
                skip.append(i)
                break
        else:
            skip.append(K-1)
            ap = 0
        for i in range(K, N):
            if B[i][1] == 1:
                ap *= B[i][0]
                break
        for i in range(K, N):
            if B[i][1] == -1:
                an *= B[i][0]
                break
        a = max(ap, an)

        ans = 1
        for i in range(K):
            if i not in skip:
                ans *= B[i][0]
                ans %= MOD
        ans *= a
        ans %= MOD

elif zero >= K-(min(K, minus)//2*2):
    print(0)
    exit()

else:
    B = sorted(B, key=lambda x: x[0], reverse=False)
    ans = 1
    for i in range(K):
        ans *= B[i][0]*B[i][1]
        ans %= MOD

print(ans)


Measured memory_bytes: 112916
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int N;
    int total = 0;
    int average = 0;
    float sum = 0;
    cin >> N;
    int nums[N];
    for (int i=0; i<N; i++) {
        int temp;
        cin >> temp;
        nums[i] = temp;
        sum += temp;
    }
    sum = sum/N;
    average = round(sum);
    for (int i=0; i<N; i++) {
        int temp = average - nums[i];
        total += temp*temp;
    }
    cout << total << endl;
    return 0;
}

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

int main() {
  int s,a,b,c,d;
  cin >> s;
  a = s/1000;
  b = (s%1000)/100;
  c = (s%100)/10;
  d = s%10;
  if(a == b || b == c || c == d)
    cout << "Bad" << endl;
  else
    cout << "Good" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int s[1000],top=0;
void push(int x)
{
    s[++top]=x;
}
int pop()
{
    --top;
    return s[top+1];
}

int main()
{
    int c,b;

    char a[100];
    while(scanf("%s",a)!=EOF)
    {
        if(a[0]=='+')
        {
            b=pop();
            c=pop();
            push(b+c);
        }
         else if(a[0]=='-')
        {
            b=pop();
            c=pop();
            push(c-b);
        }
        else if(a[0]=='*')
        {
            b=pop();
            c=pop();
            push(b*c);
        }
        else{
            push(atoi(a));
        }
    }
    printf("%d\n",pop());
    return 0;
}

Measured memory_bytes: 3220