akhauriyash/Code-Regression huggingface dataset:
/*
    It’s Always Darkest Before the Dawn
                This Time is that Darkness in you Life
                                                            */
 
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define pb push_back  
#define F first
#define S second
#define pii pair<int,int>
#define all(a) a.begin(),a.end()
 
const ll mod=1e9+7,di=998244353,N=3e5+1;
 
bool IsQuery=false; 
ll q=1,a[N];
 
map<int,vector<int>> edge;
map<int,bool> occ;
 
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
 
void solve(){
 	
  	ll n,a[3];
  	
  	cin>>n;
  	
  	ll dp[n+1][3];
  	
  	memset(dp,0,sizeof(dp));
  
  	for(int i=1;i<=n;i++){
		
      	cin>>a[0]>>a[1]>>a[2];
      
      	dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[0];
      	dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[1];
      	dp[i][2]=max(dp[i-1][0],dp[i-1][1])+a[2];
    }
  
  	cout<<max(max(dp[n][0],dp[n][1]),dp[n][2]);
  
    return;   
} 
int main(){
    
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    if(IsQuery)
    cin>>q;
 
    for(int i=0;i<q;i++){
        solve();
        cout<<"\n";
    }
    return 0;
}


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

int main(){
  int n;
  cin>>n;
  vector<bool> num(1000000001,false);
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    if(!num[a]) num[a]=true;
    else num[a]=false;
  }int count=0;
  for(int i=1;i<1000000001;i++){
    if(num[i]) count++;
  }
  cout<<count<<endl;
}


Measured memory_bytes: 122368
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>

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

using namespace std;

int main(){
    int n,k; cin >> n >> k;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    cout << ceil((n-k)/(double)(k-1)) + 1 << endl;
}



Measured memory_bytes: 640
character a*10, b*10, c*10
integer lena, lenb
read*, a, b, c
lena=len_trim(a)
lenb=len_trim(b)
if(a(lena:lena) == b(1:1) .and. b(lenb:lenb) == c(1:1)) then
	print*, 'YES'
else 
	print*,'NO'
end if
end

Measured memory_bytes: 256
#include <iostream>
#define re register int
using namespace std;
int n,k,ans;
int main()
{
    cin>>n>>k;
    ans=1;
    for(re i=1;i<=n;i++)
    {
        if(ans>k)
        	ans+=k;
        else 
        	ans*=2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
// Problem : F - Many Many Paths
// Contest : AtCoder - AtCoder Beginner Contest 154
// URL : https://atcoder.jp/contests/abc154/tasks/abc154_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 2000005

//Solution

int binpow(int x,int y){
    x %= mod;
    int res = 1;
    while(y){
        if(y&1) res = (res*x)%mod;
        x = (x*x)%mod;
        y = y/2;
    }
    return res;
}
 
int inv(int a){
    return binpow(a,mod-2);
}
 
int fact[N], invfact[N];
 
void precompute(){
    fact[0] = 1;
    for(int i=1;i<N;i++) fact[i] = (fact[i-1]*i)%mod;
    invfact[N-1] = inv(fact[N-1])%mod;
    for(int i=N-2;i>=0;i--) invfact[i] = (invfact[i+1]*(i+1))%mod;
}
 
int ncr(int n, int r){
    if(n<r) return 0;
    return (((fact[n]*invfact[r])%mod)*invfact[n-r])%mod;
}

int g(int x,int y){
    int ret = ncr(x+y+2,x+1);
    ret--;
    ret += mod;
    ret %= mod;
    return ret;
}

void solve(){
    precompute();
    int r1,c1,r2,c2;
    cin>>r1>>c1>>r2>>c2;
    int ans = g(r2,c2);
    ans = (ans-g(r2,c1-1)+mod)%mod;
    ans = (ans-g(r1-1,c2)+mod)%mod;
    ans = (ans+g(r1-1,c1-1))%mod;
    cout<<ans<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 34856
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef pair<int, int> P;

char field[21][21];
int w, h;
P pos;
int dir;


int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};

void sim(char c){
	if(c != 'S'){
		rep(i, 4){
			if(c == "UDLR"[i]){
				dir = i;
				int nx = pos.X + dx[dir], ny = pos.Y + dy[dir];
				if(nx < 0 || nx >= w || ny < 0 || ny >= h) return;
				if(field[ny][nx] != '.') return;
				pos = MP(nx, ny);
				return;
			}
		}
	}else{
		int nx = pos.X, ny = pos.Y;
		while(1){
			nx += dx[dir], ny += dy[dir];
			if(nx < 0 || nx >= w || ny < 0 || ny >= h) return;
			if(field[ny][nx] == '#') return;
			if(field[ny][nx] == '*'){
				field[ny][nx] = '.';
				return;
			}
		}
	}
}

int main(){
	int T;
	cin >> T;
	rep(sets, T){
		if(sets) cout << endl;
		cin >> h >> w;
		rep(i, h) rep(j, w) cin >> field[i][j];

		rep(i, h) rep(j, w){
			rep(d, 4){
				if(field[i][j] == "^v<>"[d]){
					pos = MP(j, i);
					dir = d;
					field[i][j] = '.';
				}
			}
		}

		int n;
		cin >> n;
		rep(i, n){
			char c;
			cin >> c;
			sim(c);
		}
		field[pos.Y][pos.X] = "^v<>"[dir];

		rep(i, h){
			rep(j, w) cout << field[i][j];
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1152
#include <functional>
 #include <algorithm>
 #include <iostream>
 #include <numeric>
 #include <iomanip>
 #include <utility>
 #include <cstdlib>
 #include <sstream>
 #include <bitset>
 #include <vector>
 #include <cstdio>
 #include <ctime>
 #include <queue>
 #include <deque>
 #include <cmath>
 #include <stack>
 #include <list>
 #include <map>
 #include <set>
 
 using namespace std;
 
 typedef vector<int> VI;
 typedef pair<int,int> PII;
 typedef long long ll;
 
 #define dump(x)  cerr << #x << " = " << (x) << endl
 #define rep(i,n) for(int i=0;i<(n);i++)
 #define ALL(a)  (a).begin(),(a).end()
 #define PB push_back
 #define sz size()
 
 const double EPS = 1e-10;
 const int INF = 100000000;
 
 
 
 int main(){
 int data[]={0,6000,4000,3000,2000};
 rep(i,4){
 int a,b;
 cin>>a>>b;
 cout<<data[a]*b<<endl;
 }
 
 return 0;
 }

Measured memory_bytes: 1160
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>

using namespace std;

#define size_t int


int main(int argc, char const *argv[]) {
  int N, H, W;
  scanf("%d %d %d", &N, &H, &W);
  printf("%d\n", (N - H + 1) * (N - W + 1));
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;



int main(void){
    int A,B,C,D;
    bool turnFlg=true;
    double tmp1,tmp2;

    cin>>A>>B>>C>>D;

    while(1){
        if(turnFlg){
            C=C-B;
        }else{
            A=A-D;
        }

        if(C<= 0){
            cout<<"Yes"<<endl;
            break;
        }
        if(A <= 0){
            cout<<"No"<<endl;
            break;
        }

        turnFlg= !turnFlg;
    }







    return 0;
}



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

using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;

	int res = -1;
	if (A >= 1 && A <= 9 && B >= 1 && B <= 9)
	{
		res = A * B;
	}
	cout << res << endl;
}



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

using namespace std;
typedef long long ll;

int main(){
    ll N; cin >> N;
    ll min = 1e13;
    for (ll i = 1;i * i <= N;i++){
        if ((N % i) == 0){
            ll a,b;
            a = i;
            b = N /i;
            ll tmp = abs(a-1) + abs(b-1);
            if (tmp < min){
                min = tmp;
            }
        }
    }
    cout << min << endl;
    return 0;
}

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

struct UnionFind {
    vector<long long> par;
    UnionFind(long long size) : par(size + 1, -1) {}
    bool unite(long long x, long long y){
        x = root(x);
        y = root(y);
        if(x != y) {
            if(par[y] < par[x]) swap(x, y);
            par[x] += par[y];
            par[y] = x;
        }
        return x != y;
    }
    bool same(long long x, long long y){ return root(x) == root(y); }
    int root(long long x){ return par[x] < 0 ? x : par[x] = root(par[x]); }
    int size(long long x){ return -par[root(x)]; }
};

int main()
{
    int n, m;
    cin >> n >> m;
    UnionFind tree(n);
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        tree.unite(a, b);
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(tree.root(i) == i) ans++;
    }
    cout << ans - 1 << endl;
    return 0;
}


Measured memory_bytes: 4004
a, b, q = map(int, input().split())
S = [int(input()) for _ in range(a)]
T = [int(input()) for _ in range(b)]

S.sort()
T.sort()

S = [-10**18]+S+[10**18]
T = [-10**18]+T+[10**18]

import bisect

for i in range(q):
    x = int(input())
    j = bisect.bisect_left(S, x)
    k = bisect.bisect_left(T, x)
    ans = 10**18
    for dj, dk in (-1, -1), (-1, 0), (0, -1), (0, 0):
        nj = j+dj
        nk = k+dk
        temp = min(abs(S[nj]-x)+abs(T[nk]-S[nj]), abs(T[nk]-x)+abs(T[nk]-S[nj]))
        ans = min(ans, temp)
    print(ans)


Measured memory_bytes: 78808
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

int f(int n){
    int ret = 0;
    while(n > 0){
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

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

    int n;
    cin >> n;

    int num = f(n);
    cout << (n % num == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(){
  string s;
  string x="0",y="1";
  cin >> s;
  string zero="0";
  string one="1";
  for (int i=1; i < s.size(); i++){
    if (i%2) {
      x+=one;
      y+=zero;
    }
    else{
       x+=zero;
      y+=one;
    }
  }
  int mx=0,my=0;
  for (int j=0; j < s.size();j++){
    if (s.at(j)!=x.at(j)) mx++;
    if (s.at(j)!=y.at(j)) my++;
  }
  cout << min(mx,my) << endl;
  return 0;
}
    
  

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

#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ll long long

int main() {
    ll n;
    cin >> n;
    ll x, y;
    ll ans = pow(10, 12);
    int flag = 0;
    std::vector<ll> v;
    for (int i = 1; i <= sqrt(n); ++i) {
        if ( n%i == 0 ) {
            x = n/i;
            y = i;
            v.push_back(x+y-2);
        }
    }
    cout << *min_element(v.begin(), v.end()) << endl;

    return 0;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  ll h,w;
  cin>>h>>w;

  if(h>w)swap(h,w);
  if(h==1){
    cout<<1<<endl;
    return 0;
  }

  ll ans = 0;
  for(ll i=1;i<=h;++i){
    if(i&1){
      if(w&1)ans+=w/2+1;
      else ans+=w/2;
    }else{
      ans+= w/2;
    }
  }
  cout<<(ans)<<endl;

}


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

int main(){
   char abc[]={'A','B','C'};
   char arc[]={'A','R','C'};
   char str[3];
   int i;
   scanf("%s",str);
   if(str[1]=='B'){
      printf("ARC");
   }else if(str[1]=='R'){
      printf("ABC");
   }
   
   return 0;
}
     

Measured memory_bytes: 1712
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)a
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/

int main()
{
    //freopen("input.txt", "r", stdin);
    SPEED
    int n;
    cin >> n;
    const int MOD = 1e9 + 7;
    ll ans = 0;
    vector<ll> a(n);
    for (auto &e : a) cin >> e;
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        ans += sum * a[i];
        ans %= MOD;
        sum += a[i];
        sum %= MOD;
    }
    cout << ans;
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


Measured memory_bytes: 4752
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;


void solve(long long A, long long B){
  if(A>=13) cout << B << endl;
  else if(A>=6) cout << B/2 << endl;
  else cout << "0" << endl;
}

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll dp[110][5][2];

int main(void){
	int n,k,i,j,d;
	string s;
	cin >> s;
	n = s.l_ength();
	cin >> k;
	dp[0][0][0] = 1ll;
	for(i=0; i<n; ++i){
		s[i] -= '0';
		for(j=0; j<4; ++j){
			if(s[i]){
				dp[i+1][j][1] += dp[i][j][0];
				for(d=1; d<s[i]; ++d){
					dp[i+1][j+1][1] += dp[i][j][0];
				}
				dp[i+1][j+1][0] += dp[i][j][0];
			}else{
				dp[i+1][j][0] += dp[i][j][0];
			}
			dp[i+1][j][1] += dp[i][j][1];
			for(d=1; d<10; ++d){
				dp[i+1][j+1][1] += dp[i][j][1];
			}
		}
	}
	cout << (dp[n][k][0]+dp[n][k][1]) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
int main(void) {
	int n, A[100001],i,j,sum,tmp;
	A[0] = 0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&A[i]);
	}
	
		sum = 0;
		for(i=1;i<=n;i++) sum += abs(A[i]-A[i-1]);
		sum += abs(A[n]);
	
	for(j=1;j<=n;j++){
		tmp = sum;
		tmp -= abs(A[j]-A[j-1]) + abs(A[j+1]-A[j]);
		tmp += abs(A[j+1]-A[j-1]);
		printf("%d\n",tmp);
	}
	return 0;
}

Measured memory_bytes: 1536
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    let mut task = vec![];
    for _ in 0 .. n {
        let a = get!();
        let b = get!();
        task.push((b, a));
    }
    task.sort();
    let mut t = std::i64::MAX;
    while let Some((b, a)) = task.pop() {
        if b <= t {
            t = b;
        }
        t -= a;
    }
    if t < 0 {
        println!("No");
    } else {
        println!("Yes");
    }
}

Measured memory_bytes: 13684
#include <bits/stdc++.h>
using namespace std;
#define vl vector <long long>
#define lli long long

vl st;

void update(int v,int i,int l,int r,lli val){
    if(l>r)return;
    if(l==r){
        st[v]=val;
    }
    else{
    int mid=(l+r)/2;
    if(i<=mid)update(2*v,i,l,mid,val);
    else update(2*v+1,i,mid+1,r,val);
    st[v]=max(st[2*v],st[2*v+1]);
    }
}

lli  query(int v,int ll,int rr,int l,int r){
    if(ll>rr)return 0;
    if(l==ll&&r==rr){
        return st[v];
    }
    else{
    int mid=(l+r)/2;
    lli left=query(2*v,ll,min(mid,rr),l,mid);
    lli right=query(2*v+1,max(mid+1,ll),rr,mid+1,r);
    return max(left,right);
    }
}

int main() {
    int n;
    cin>>n;
    st.assign(4*n+1,0);
    vl vec(n,0);
    vector <pair<lli,int>> svec(n);
    vl val(n,0);
    for(int i=0;i<n;i++){
        cin>>vec[i];
        svec[i].first=vec[i];
        svec[i].second=i;
    }
    for(int i=0;i<n;i++){
        cin>>val[i];
    }
    sort(svec.begin(),svec.end());
    map<lli,int>ind;
    for(int i=0;i<n;i++)ind[svec[i].first]=i;
    lli ans=0;
    for(int i=n-1;i>=0;i--){
        int index=ind[vec[i]];
        lli mx=query(1,index+1,n-1,0,n-1);
        lli value=mx+val[i];
        //cout<<value<<" "<<i<<" "<<mx<<" "<<index<<endl;
        if(ans<value)ans=value;
        update(1,index,0,n-1,value);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 25344
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

	int n,a[51],b[51],m,u[21],v[21];
	vector<int> t[51];

	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		cin>>a[i]>>b[i];
		t[a[i]].push_back(b[i]);
		t[b[i]].push_back(a[i]);
	}

	cin>>m;
	for(int i=0;i<m;i++)
	{
		cin>>u[i]>>v[i];
	}

	int rnk[51];
	memset(rnk,-1,sizeof(rnk));
	rnk[1]=0;
	queue<int> q;
	q.push(1);

	vector<int> g[51];
	int par[51];
	par[1]=0;

	while(q.size())
	{
		int p=q.front();
		q.pop();

		for(int i:t[p])
		{
			if(rnk[i]!=-1) continue;
			rnk[i]=rnk[p]+1;
			g[p].push_back(i);
			par[i]=p;
			q.push(i);
		}
	}

	int lca[51][51];
	memset(lca,-1,sizeof(lca));

	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
		{
			int l=i;
			int r=j;
			if(rnk[l]>rnk[r]) swap(l,r);
			while(rnk[l]!=rnk[r])
				r=par[r];

			while(l!=r)
				r=par[r],l=par[l];

			lca[i][j]=l;
		}

	P r[51];
	for(int i=1;i<=n;i++) r[i]={rnk[i],i};
	sort(r+1,r+n+1);


	ll res=1LL<<(n-1);

	priority_queue<P> qq;
	for(int i=0;i<=n;i++) if(g[i].size()==0) qq.push({rnk[i],i});

	for(int i=1;i<(1<<m);i++)
	{
		int pl[51];
		memset(pl,0,sizeof(pl));

		int cnt=0;
		for(int j=0;j<m;j++)
		{
			if((i&(1<<j))==0) continue;
			int l=lca[u[j]][v[j]];
			pl[l]-=2;
			pl[u[j]]++;
			pl[v[j]]++;
			cnt++;
		}
		cnt%=2;

		int fcnt=0;

		for(int j=n;j>1;j--)
		{
			int p=r[j].second;
			pl[par[p]]+=pl[p];
			fcnt+=pl[p]==0;
		}
			
		res+=(1-2*cnt)*(1LL<<fcnt);
	}

	cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N,K;
int A[100009];

void pr(string ans){
    cout1(ans)
    exit(0);
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>K;
    rep(i,N) cin>>A[i];
    
    bool f=false;
    int g=A[0];
    rep(i,N){
        if(K<=A[i])f=true;
        if(K==A[i])pr("POSSIBLE");
        g=gcd(g,A[i]);
    }
    
    if(f){
        f=false;
        rep(i,N){
            int d=abs(K-A[i]);
            if(d%g==0){
                f=true;
                break;
            }
        }
    }
    
    if(f) pr("POSSIBLE");
    else pr("IMPOSSIBLE");
    
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int  n, t, a[200005];
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> t;
    ll ans = t;
    rep(i, 0, n) cin >> a[i];
    rep(i, 1, n) {
        ans += min(t, a[i] - a[i-1]);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll dp[122121];
ll a[122211];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,k; cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	dp[0]=0;
	for(int i=1;i<n;i++)
	{
		dp[i]=ll(1e18);
		for(int j=1;j<=k;j++)
		{
			if(i-j>=0) dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
		}
	}
	cout<<dp[n-1]<<'\n';
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int n=sc.nextInt();
			int op=0;
			for(int i=0; i<n; i++) {
				int a=sc.nextInt();
				int count=0;
				while(a>0) {
					if(a%2==1) {
						break;
					}
					a=a/2;
					count++;
				}
				op+=count;
			}

			System.out.println(op);
		}
	}
}

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

def calc(s):
    res = []
    for v in s:
        v = v + '-'
        tmp = []
        nc = v[0]
        nn = 0
        for c in v:
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                    tmp.extend([0 for _ in range(nn)])
                else:
                    tmp.extend( [nn for _ in range(nn)])
                nc = c
                nn = 1
        res.append(tmp)
    return res

def calc2(s):
    res = []
    for j in range(w):
        tmp = []
        nc = s[0][j]
        nn = 0
        for i in range(h):
            c = s[i][j]
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                    tmp.extend([0 for _ in range(nn)])
                else:
                    tmp.extend( [nn for _ in range(nn)])
                nc = c
                nn = 1
        if nc == '#':
            tmp.extend([0 for _ in range(nn)])
        else:
            tmp.extend( [nn for _ in range(nn)])
        res.append(tmp)
    return res

tate = calc2(S)
yoko = calc(S)

print(max([tate[j][i] + yoko[i][j] for i in range(h) for j in range(w) if tate[j][i] * yoko[i][j] != 0]) - 1)


Measured memory_bytes: 236504
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

int main()
{
  ll H, W; cin >> H >> W;
  vector<vector<char>> grid(H + 2, vector<char>(W + 2));
  rep(j, 0, W + 2) {
  	grid[0][j] = '.';
  }
  rep(i, 1, H + 1) {
  	grid[i][0] = '.';
    rep(j, 1, W + 1) {
    	cin >> grid[i][j];
    }
    grid[i][W + 1] = '.';
  }
  rep(j, 0, W + 2) {
  	grid[H + 1][j] = '.';
  }
  rep(i, 1, H + 1) {
  	rep(j, 1, W + 1) {
    	if (grid[i][j] == '#' && grid[i - 1][j] == '.' && grid[i + 1][j] == '.' && grid[i][j - 1] == '.' && grid[i][j + 1] == '.') {
        	cout << "No"; return 0;
        }
    }
  }
  cout << "Yes";
}

Measured memory_bytes: 256
N,Q=map(int,input().split())

Group = [i for i in range(N+1)] # グループ分け
Nodes = [1]*(N+1) # 各グループのノードの数

def find(x):
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):
    if find(x) != find(y):
        if Nodes[find(x)] < Nodes[find(y)]:
            
            Nodes[find(y)] += Nodes[find(x)]
            Nodes[find(x)] = 0
            Group[find(x)] = find(y)
            
        else:
            Nodes[find(x)] += Nodes[find(y)]
            Nodes[find(y)] = 0
            Group[find(y)] = find(x)

for i in range(Q):
    t,u,v=map(int,input().split())
    if t==0:
        Union(u,v)
    else:
        if find(u)==find(v):
            print(1)
        else:
            print(0)

Measured memory_bytes: 17776
//by kcz 1552920354@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;

template <typename T> void chmin(T &x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define mp make_pair
#define gc (c=getchar())
char readc()
{
	char c;
	while(gc<'-');
	return c;
}
int read()
{
    char c;
    while(gc<'-');
    if(c=='-')
    {
        int x=gc-'0';
        while(gc>='0')x=x*10+c-'0';
        return -x;
    }
    int x=c-'0';
    while(gc>='0')x=x*10+c-'0';
    return x;
}
#undef gc

const int N=100+5;
int a[N],cnt[N];
int n,L,L2;

ll ans;
void dfs(int x,ll s)
{
	if(x>L)
	{
		rep(i,L+1,L2)
		if(!cnt[i])
		{
			if(!cnt[i*2])
			{
				if(a[i]+a[i*2]<0)s-=a[i]+a[i*2];
			}
			else
			{
				if(a[i]<0)s-=a[i];
			}
		}
		chmax(ans,s);
		return ;
	}
	dfs(x+1,s);
	if(cnt[x]||a[x]>=0)return ;
	for(int y=x;y<=n;y+=x)
	if(++cnt[y]==1)s-=a[y];
	dfs(x+1,s);
	for(int y=x;y<=n;y+=x)--cnt[y];
}

int main()
{
	//freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
	cin>>n;
	rep(i,1,n)cin>>a[i];
	L=n/3;L2=n/2;
	rep(i,1,n)	
	{
		for(int j=i;j<=n;j+=i)
		if(a[j]>0)goto End;
		for(int j=i;j<=n;j+=i)a[j]=0;
		End : ;	
	}

	ll s=0;
	rep(i,1,n)s+=a[i];
	ans=s;
	dfs(1,s);
	cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline

n=int(input())
a=[int(input()) for _ in range(n)]
ans=0
s=0
for i in range(n):
    s+=a[i]
    if a[i]==0:
        ans+=(s//2)
        s=0
ans+=(s//2)
print(ans)


Measured memory_bytes: 44124
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int a, b;
  cin >> a >> b;

  int x = min(a, b);
  int y = max(a, b);
  int z;
  if (x == 1 && y == 2) z = 3;
  if (x == 1 && y == 3) z = 2;
  if (x == 2 && y == 3) z = 1;

  cout << z << endl;

  return 0;
}


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

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> P[51];
	int a, b;
	for (int i = 0; i < m; ++i)
	{
		cin >> a >> b;
		P[a].push_back(b);
		P[b].push_back(a);
	}
	for (int i = 1; i <= n; ++i)
	{
		cout << P[i].size() << endl;
	}
	return 0;
}

Measured memory_bytes: 256
while True:
    h,w = list(map(int,input().split()))
    if h==0: break
    rect = "#" * w + "\n"
    if h<3 or w<3:
        rect += rect * (h-1)
    else:
        rect += ("#" + "." * (w-2) + "#\n") * (h-2) + "#" * w + "\n"
    print(rect)


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

int main()
{
  int W,H,x,y,r;
  cin >>W >>H >>x >>y >>r;

if(-100<=x && x<=100
  && -100<=y && y<=100
  && 0<W && W <=100
  && 0<H && H <=100
  && 0<r && r <=100){
  if ((x+r)>W || (x-r)<0 ||(y+r)>H || (y-r)<0) {
    cout <<"No" <<endl;
  }
  else {
    cout << "Yes" <<endl;
  }
}
  return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int i,sougaku,kakaku,hon;
	while(1)
	{
		kakaku=0;
		cin>>sougaku;
		if(sougaku==0)
			break;
		kakaku=sougaku;
		for(i=0;i<9;i++)
		{
			cin>>hon;
			kakaku=kakaku-hon;
		}
		cout<<kakaku<<endl;
	}
	return 0;

}
		
			

Measured memory_bytes: 3048
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<int> A;
int Mx=0,Mn=1e6;
void input(){
    fast_io();
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int a; cin >> a;
        Mn = min(Mn,a);
        Mx = max(Mx,a);
        A.push_back(a);
    }
}

int solve(){
    Mx -= Mn;
    for(auto &a:A) a-=Mn;
    DBG(A)
    vector<int> cnt(Mx+1,0);
    int MaxCnt = 0;
    for(auto a:A) MaxCnt=max(MaxCnt,++cnt[a]);
    DBG(cnt)
    for(auto &c:cnt) {
        if(c>=3){
            if(c%2) c=1;
            else c=2;
        }
    }
    DBG(cnt)
    vector<int> cntShrink;
    for(auto c:cnt) if(c) cntShrink.push_back(c);
    DBG(cntShrink)

    vector<int> Mc(3,0);
    for(auto c:cntShrink) if(c) Mc[c]++;
    DBG(Mc)
    if(Mc[2]%2) {
        Mc[1]+=Mc[2]-1;
        DBG(Mc)
        }
    else{
        bool ok = false;
        for(auto &c:cntShrink) c--;
        vector<int> CS(cntShrink.size()+1,0);
        for (int i = 0; i < cntShrink.size(); i++)
        {
            CS[i+1] = CS[i]+cntShrink[i];
        }
        for (int i = 1; i < cntShrink.size(); i++)
        {
            if((CS[i-1]==(CS[cntShrink.size()]-CS[i])) && CS[i-1]>0) ok=true;
        }
        if(ok || Mc[2]>=4) Mc[1] += Mc[2];
        else Mc[1] += max(Mc[2]-2,0);
    }
    DBG(Mc)
    cout << Mc[1]<< endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

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


int main() {
	int N, A, B;
	int a[110];
	cin >> N;
	for (int i = 0; i < N; ++i)cin >> a[i];

	sort(a, a + N, greater<int>());
	int Alice = 0;
	int Bob = 0;
	for (int i = 0; i < N; ++i) {
		if (i % 2 == 0) {
			Alice += a[i];
		}
		else {
			Bob += a[i];
		}
	}
	cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
x1, x2, x3, x4, x5 = map(int, input().split())
if x1 != 1:
    print(1)
elif x2 != 2:
    print(2)
elif x3 != 3:
    print(3)
elif x4 != 4:
    print(4)
elif x5 != 5:
    print(5)


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

int main(int argc, const char * argv[]) {
    int N = 0;
    int K = 0;
    int value = 0;
    int count = 1;
    
    cin >> N;
    cin >> K;
    
    

    value = K;
    while(N >= value){
        value = value * K;
        count++;
    }
    cout << count;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=1e5+100;
vector <int> g[N],q[N];
ll vis[N];
ll cnt[4];
ll p1=0;
vector <int> ras;
ll z=0;
ll dfs(ll v,ll k){
    ras.pb(v);
    k%=3;
    if (k==0) k=3;
    vis[v]=k;
    cnt[k]++;
    z+=g[v].size();
    for (int i=0;i<g[v].size();i++){
        ll u=g[v][i];
        ll t=k+1;
        t%=3;
        if (t==0) t=3;
        if (vis[u]==0) dfs(u,t);
        else{
            if (vis[u]!=t) p1=1;
        }
    }
    for (int i=0;i<q[v].size();i++){
        ll u=q[v][i];
        ll t=k+2;
        t%=3;
        if (t==0) t=3;
        if (vis[u]==0) dfs(u,t);
        else{
            if (vis[u]!=t) p1=1;
        }
    }
}
int32_t main(){
    ll n,m;
    cin >> n >> m;
    for (int i=0;i<m;i++){
        ll x,y;
        cin >> x >> y;
        g[x].pb(y);
        q[y].pb(x);
    }
    ll ans=0;
    for (int i=1;i<=n;i++){
        if (vis[i]) continue;
        cnt[0]=0;
        cnt[1]=0;
        cnt[2]=0;
        cnt[3]=0;
        ras.clear();
        z=0;
        p1=0;
        dfs(i,1);
        ll p=ras.size();
        if (p1==1){
            ans+=p*p;
            continue;
        }
        if (cnt[1]==0 || cnt[2]==0 || cnt[3]==0){
            ans+=z;
            continue;
        }
        else{
            ans+=cnt[1]*cnt[2]+cnt[2]*cnt[3]+cnt[3]*cnt[1];
        }
    }
    cout << ans;
}


Measured memory_bytes: 19064
import java.io.*;

class Main
{
    public static void main(String[] args)
	throws IOException
    {
	int dx[] = {0,1,0,-1};
	int dy[] = {1,0,-1,0};
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	for(int i=0;i<1000;i++)
	    {
		String line = in.readLine();
		boolean ok = true;
		int p = (int)(line.charAt(0)-'A');
		for(int j=1;j<line.length();j++)
		    {
			boolean ok2 = false;
			for(int k=0;k<4;k++)
			    {
				int nx = p%3 + dx[k];
				int ny = p/3 + dy[k];
				if(!(0 <= nx && nx < 3 && 0 <= ny && ny < 3))continue;
				if((char)((nx+ny*3)+'A') == line.charAt(j))ok2 = true;
			    }
			if(!ok2)
			    {
				ok = false;
				break;
			    }
			p = (int)(line.charAt(j)-'A');
		    }	
		if(ok)System.out.println(line);
	    }
    }
    
}

Measured memory_bytes: 21392
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
lli a[2*maxn];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0;
    cin>>n;
    map<lli, int> fb;
    map<lli, int> fc;
    for(int i=1;i<=n;++i)
    {
        cin>>a[i];
        if(a[i]-i<=0)
            fb[abs(a[i]-i)]++;
        fc[(a[i]+i)]++;
    }
    lli res=0ll;
    for(auto i: fb)
    {
        if(fc.find(i.fi)!=fc.end())
        {
            res+=(1ll*(i.se)*fc[i.fi]);
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 21388
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,ans;
    long long int a[11];
    scanf("%lld",&n);
    for(int i=0;i<5;i++)
        scanf("%lld",&a[i]);
    sort(a,a+5);
    if(n%a[0]==0)
        ans=4+n/a[0];
    else
        ans=5+n/a[0];
    printf("%lld\n",ans);
}


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

public class Main {

	static int n;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		for(int i = 0 ; i < n ; i++) {
			a[i] = sc.nextInt();
		}
		for(int i = 0 ; i < n ; i++) {
			b[i] = sc.nextInt();
		}
		for(int i = 0 ; i < n ; i++) {
			c[i] = sc.nextInt();
		}
		Arrays.sort(a);
		Arrays.sort(c);
		long ans = 0;
		for(int i = 0 ; i < n ; i++) {
			ans += binary_search(a, b[i]) * (n - binary_search(c, b[i] + 1));
		}
		System.out.println(ans);
	}

	public static long binary_search(int[] a, int x) {
		int l = 0;
		int r = n;
		while(r > l) {
			int center = (l + r) / 2;
			if(a[center] >= x) r = center;
			else l = center + 1;
		}
		return l;
	}

}


Measured memory_bytes: 94572
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)n;i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
#define REP(i,b,e) for(int i=b;i<(int)e;i++)
typedef long long ll;
typedef map<ll,ll> mll;
typedef vector<ll> vll;
ll INF=1e18;
int inf=1e9+1000;

string alpha="abcdefghijklmnopqrstuwvxyz";

int A,B;



int main(){
    cin>>A>>B;
    if(A<=8 &&B<=8){
        cout<<"Yay!"<<endl;
    }
    else cout<<":("<<endl;
 

    return 0;
}

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

// See debug.cc for usage etc
#define DEBUG 0

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

ll N, X;
vector<ll> L(100);

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif


  cin >> N >> X;
  ll D = 0;
  ll cnt = 1;
  for (size_t i = 0; i < (size_t)N; i++) {
    ll L;
    cin >> L;
    D += L;
    if (D <= X) cnt++;
  }
  cout << cnt << endl;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int min = Math.min(a, b);
        int max = Math.max(a, b);
        
        String ans = "";
        for(int i=0; i<max; i++) {
            ans += String.valueOf(min);
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <stdio.h>

int bubble_sort(int A[], int N) {
    int key, swap = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = N-1; j >= i+1; --j) {
            if (A[j] < A[j-1]) {
                swap++;
                key = A[j];
                A[j] = A[j-1];
                A[j-1] = key;
            }
        }
    }
    return swap;
}

int main() {
    int N, swap;
    scanf("%d", &N);
    int A[N];
    for (int i = 0; i < N; ++i) {
        scanf("%d", &A[i]);
    }

    swap = bubble_sort(A, N);
    for (int j = 0; j < N; ++j) {
        if (j > 0) printf(" ");
        printf("%d", A[j]);
    }
    printf("\n");
    printf("%d\n", swap);

    return 0;

}


Measured memory_bytes: 2100
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int main(){
	string s,hoge="";
	cin>>s;
	rep(i,s.size()){
		if(i%2==0)hoge+=s[i];
	}
	cout<<hoge<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,a[200010],dp[200010][3];
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i <= n;i++){
		for(int j = 0;j < 3;j++) dp[i][j] = -INF;
	}
	dp[0][0] = 0;
	for(int i = 0;i < n / 2;i++){
		chmax(dp[i + 1][0],dp[i][0] + a[i * 2]);
		chmax(dp[i + 1][1],max(dp[i][0],dp[i][1]) + a[i * 2 + 1]);
		if(n % 2) chmax(dp[i + 1][2],max({dp[i][0],dp[i][1],dp[i][2]}) + a[i * 2 + 2]);
	}
	cout << max({dp[n / 2][0],dp[n / 2][1],dp[n / 2][2]}) << endl;
}

Measured memory_bytes: 9884
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){

	int a[5],n;
	for(int i=0;i<3;i++){
		cin>>a[i];
	}
	cin>>n;
	sort(a,a+3);
	int ans=a[2];
	for(int i=1;i<=n;i++){
		ans=ans*2;
	}
	ans=ans+a[0]+a[1];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256