akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, M;
	cin >> N >> M;
	vector<int> cnt(N);
	for (int i = 0; i < M; i++) {
		int u, v;
		cin >> u >> v; u--, v--;
		cnt[u]++;
		cnt[v]++;
	}
	bool ok = true;
	for (int i = 0; i < N; i++) {
		ok &= cnt[i] % 2 == 0;
	}
	puts(ok ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
    char d[101][101],ch;int w,h,i,j;
    while(cin>>h>>w,h){
        for(i=0;i<h;i++)for(j=0;j<w;j++)cin>>d[i][j];i=j=0;
        while(d[i][j]!='.'&&d[i][j]!='X'){
            ch=d[i][j];d[i][j]='X';
            switch (ch){
                case '>':j++;break;
                case '<':j--;break;
                case 'v':i++;break;
                case '^':i--;
            }
        }(d[i][j]=='.')?(cout<<j<<" "<<i<<endl):(cout<<"LOOP"<<endl);
    }
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    map<string,int> m;
    
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++){
        string N;
        cin >> N;
        m[N]++;
    }
    
    vector<string> v;
    int most = 0;
    for(auto i = m.begin(); i != m.end() ; ++i ) {
        if(most < i->second){
            v.clear();
        }
        if(most <= i->second){
            v.push_back(i->first);
            most = i->second;
        }
    }
    
    for(int i = 0; i < v.size(); i++){
        cout << v[i] << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 26868
#include <iostream>

int main(void)
{
	int H, W, chip;
	while (true)
	{
		std::cin >> H >> W;
		if (H == 0 && W == 0) break;
		for (int i = 0; i < H; i++) {
			chip = i % 2;
			for (int i = chip; i < W + chip; i++) {
				std::cout << (i % 2 ? '.' : '#');
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
	}
	return 0;
}

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

int main(void){
    int N, o = 0, e = 0, ans = 0;
    std::cin >> N;
    for (int i = 0; i < N; ++i){
        int a;
        std::cin >> a;
        if (a % 2 == 0) ++e;
        else ++o;
    }

    ans = std::pow(3, N) - std::pow(1, o) * std::pow(2, e);

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 4072
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int A, B;
    cin >> A >> B;
    if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <bitset>
using namespace std;
typedef long long int lli;
int main(void)
{
    lli X, Y;
    cin >> X >> Y;
    if (X % Y == 0)
    {
        cout << -1 << endl;
        return 0;
    }
    else
    {
        cout << X << endl;
    }
    return 0;
}

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

int main(){
    int N;
    cin>>N;
    for(int i=0;i<30;i++){
        if(N==(1<<i)) {printf("No\n"); return 0;}
    }

    printf("Yes\n");
    printf("%d %d\n", N+1, N+3);
    for(int i=3;i<=N;i+=2){
        printf("%d %d\n", 1, i);
        printf("%d %d\n", 1, i-1);
        printf("%d %d\n", i, i+N-1);
        printf("%d %d\n", i-1, i+N);
    }

    if(N%2==0){
        for(int i=2;i<N;i++){
            if(((N+1)^i)<N){
                printf("%d %d\n", i, N);
                printf("%d %d\n", (N+1)^i, 2*N);
                break;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[110];
    rep(i,0,N) cin >> A[i];
    bool flg = true;
    ll cnt = 0;
    while(flg){
        flg = false;
        rrep(j,N-1,1){
            if(A[j-1] > A[j]){
                swap(A[j-1], A[j]);
                flg = true;
                cnt++;
            }
        }
    }
    printa(A, N);
    print(cnt);
}


Measured memory_bytes: 3212
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 



int main(void){
    int n,m;
    cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2<<endl;
    return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
T,A = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
d = 1000000000000
index = 0
for i in range(N) :
    dT = T - H[i] * 0.006
    dd = abs(A - dT)
    if dd < d :
        d = dd
        index = i
print(index+1)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
    int A,B,M;
    cin >> A >> B >> M;
    int a[A];
    int ma = 100000;
    for(int i = 0; i < A; i++){
        cin >> a[i];
        if(a[i] < ma) ma = a[i];
    }
    int b[B];
    int mb = 100000;
    for(int i = 0; i < B; i++){
        cin >> b[i];
        if(b[i] < mb) mb = b[i];
    }
    int out = ma + mb;
    for(int i = 0; i < M; i++){
        int x,y,c;
        cin >> x >> y >> c;
        if(a[x-1]+b[y-1]-c < out) out = a[x-1]+b[y-1]-c;
    }
    cout << out << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat May  2 21:22:24 JST 2020
 **/

signed main() {
    Int n, m;
    std::cin >> n >> m;
    std::vector<std::pair<Int, Int>> ans;
    Int mid = (m / 2 + 1) * 2, r = 2 * m + 1;
    // even
    REP(i, m / 2) {
        ans.push_back({1 + i, mid - 1 - i});
    }
    // odd
    REP(i, (m + 1) / 2) {
        ans.push_back({mid + i, r - i});
    }
    REP(i, m) {
        std::cout << ans[i].first << " " << ans[i].second << "\n";
    }
}


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

struct data {
    int l, r, id;
    bool operator<(data const& other) const {
        return l < other.l;
    }
};

int main() {
    int N;
    while(cin >> N, N) {
        vector<data> v = {data{-1, -1, -1}};
        for(int i=0; i<N; ++i) {
            char c;
            cin >> c;
            if(c == 'W') {
                int l, S;
                cin >> l >> S;
                vector<data> app;
                for(int j=0; j<v.size()-1; ++j) {
                    int w = v[j+1].l - v[j].r - 1;
                    if(w > 0) {
                        app.push_back(data{v[j].r+1, v[j].r+min(w, S), l});
                        S -= min(w, S);
                        if(S == 0) {
                            break;
                        }
                    }
                }
                if(S > 0) {
                    app.push_back(data{v[v.size()-1].r+1, v[v.size()-1].r+S, l});
                }
                v.insert(v.end(), app.begin(), app.end());
                sort(v.begin(), v.end());
            } else if(c == 'D') {
                int l;
                cin >> l;
                v.erase(remove_if(v.begin(), v.end(), [l](data const& d) {
                    return d.id == l;
                }), v.end());
            } else if(c == 'R') {
                int P;
                cin >> P;
                bool f = true;
                for(int j=0; j<v.size(); ++j) {
                    if(v[j].l <= P && P <= v[j].r) {
                        cout << v[j].id << endl;
                        f = false;
                    }
                }
                if(f) {
                    cout << -1 << endl;
                }
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3152
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;

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

  set<ll> st;
  ll cur = 0;
  ll ans = 0;

  while (st.count(ans) == 0) {
    st.insert(ans);
    ans = (ans * 10 + 7) % K;
    cur += 1;

    if (ans == 0) {
      break;
    }
  }
  if (ans == 0) {
    cout << cur << endl;
  } else {
    cout << -1 << endl;
  }
}

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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N;
  cin >> N;

  vi A(N);
  vi B(N);
  vi C(N-1);

  for (int i=0; i<N; i++) {
    cin >> A[i];
    A[i]--; // 0-indexed
  }
  for (int i=0; i<N; i++) {
    cin >> B[i];
  }
  for (int i=0; i<N-1; i++) {
    cin >> C[i];
  }

  int ret = 0;
  for (int i=0; i<N; i++) {
    ret += B[A[i]];
    if (i > 0 && A[i]-A[i-1] == 1) {
      ret += C[A[i-1]];
    }
  }

  cout << ret << endl;


  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int beki(ll x){
	int ret = 0;
	while(x > 0){
		x /= 2;
		ret++;
	}

	return ret;
}

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

	ll n;
	cin >> n;

	ll a[n];
	rep(i, n) cin >> a[i];

	sort(a, a + n);

	bool used[n];
	rep(i, n) used[i] = false;

	int ans = 0;
	int p = 0;
	ll bef = -1;
	for(int i = n-1; i >= 0; i--){
		if(used[i]) continue;
		used[i] = true;

		ll s = (1LL << beki(a[i]));
		// cout << a[i] << " " << s << endl;

		if(bef != s){
			p = 0;
			bef = s;
		}

		while(true){
			if(p >= i || a[p] + a[i] > s) break;
			if(a[p] + a[i] == s && !used[p]){
				// cout << "ans:" << i << " " << p << endl;
				ans++;
				used[p] = true;
				break;
			}
			p++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
簡単な気がする
ABA
BBB
AAA

BA
BA
BA
BA
=3個
BX
XA
=5個
*/
int main(){
  ll N,A=0,B=0,BA=0,AB=0; cin>>N;
  for(ll i=0; i<N; i++){
    string S; cin>>S;
    ll sz=S.size();
    if(S[0]=='B') B++;
    if(S[sz-1]=='A') A++;
    if(S[0]=='B' && S[sz-1]=='A') BA++;
    for(ll j=0; j<sz-1; j++) if(S[j]=='A' && S[j+1]=='B') AB++;
  }
  if(A==B && B==BA && A>0) AB+=BA-1;
  else AB+=min(A,B);
  cout<<AB<<endl;
}

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

long long swp(long long a, int i, int j) {
    long long t = ((a >> (i << 2)) ^ (a >> (j << 2))) & 15;
    return a ^ (t << (i << 2)) ^ (t << (j << 2));
}

int main() {
    int n;
    cin >> n;
    long long a = 0, m = 0;
    for (int i = 0; i < n; ++i) {
        int b;
        cin >> b;
        a = (a << 4) + b;
        m = (m << 4) + i + 1;
    }
    unordered_map<long long, int> mp;
    mp[m] = 0;
    queue<long long> q;
    q.push(m);

    int lim = 4;

    while (!q.empty()) {
        long long p = q.front();
        q.pop();
        if (mp[p] > lim) break;

        for (int i = 0; i < n; ++i) {
            long long pa = p;
            for (int j = 1; i + j < n && i - j >= 0; ++j) {
                pa = swp(pa, i - j, i + j);
                if (!mp.count(pa)) {
                    mp[pa] = mp[p] + 1;
                    q.push(pa);
                }
            }
            pa = p;
            for (int j = 0; i + j + 1 < n && i - j >= 0; ++j) {
                pa = swp(pa, i - j, i + j + 1);
                if (!mp.count(pa)) {
                    mp[pa] = mp[p] + 1;
                    q.push(pa);
                }
            }
        }
    }
    if (mp.count(a)) {
        cout << mp[a] << "\n";
        return 0;
    }
    unordered_map<long long, int> mp2;
    mp2[a] = 0;
    queue<long long> q2;
    q2.push(a);
    while (!q2.empty()) {
        long long p = q2.front();
        q2.pop();

        for (int i = 0; i < n; ++i) {
            long long pa = p;
            for (int j = 1; i + j < n && i - j >= 0; ++j) {
                pa = swp(pa, i - j, i + j);
                if (!mp2.count(pa)) {
                    mp2[pa] = mp2[p] + 1;
                    if (mp.count(pa)) {
                        cout << (mp[pa] + mp2[pa]) << "\n";
                        return 0;
                    }
                    q2.push(pa);
                }
            }
            pa = p;
            for (int j = 0; i + j + 1 < n && i - j >= 0; ++j) {
                pa = swp(pa, i - j, i + j + 1);
                if (!mp2.count(pa)) {
                    mp2[pa] = mp2[p] + 1;
                    if (mp.count(pa)) {
                        cout << (mp[pa] + mp2[pa]) << "\n";
                        return 0;
                    }
                    q2.push(pa);
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 69032
#include <bits/stdc++.h>
using namespace std;
int main(){
  char a,s;
  cin>>a>>s;
  int j,k;
  if(a=='A')j=0;
  else if(a=='B')j=1;
  else if(a=='C')j=2;
  else if(a=='D')j=3;
  else if(a=='E')j=4;
  else j=5;

  if(s=='A')k=0;
  else if(s=='B')k=1;
  else if(s=='C')k=2;
  else if(s=='D')k=3;
  else if(s=='E')k=4;
  else k=5;
  if(j>k)cout<<">"<<endl;
  else if(j==k)cout<<"="<<endl;
  else cout<<"<"<<endl;


  

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll m,k;cin>>m>>k;
    if(k>=(1ll<<m))return cout<<"-1" , 0;
    if(m==1){
        if(k==0)cout<<"0 1 1 0";
        else cout<<"-1";
        return 0;
    }
    for(ll i=0;i<=(1ll<<m)-1;i++)if(i!=k)cout<<i<<" ";
    cout<<k<<" ";
    for(ll i=(1ll<<m)-1;i>=0;i--)if(i!=k)cout<<i<<" ";
    cout<<k;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N - 1];
    int[] b = new int[N - 1];
    for (int i = 0; i < N - 1; i++) {
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
    }
    sc.close();

    @SuppressWarnings("unchecked")
    List<int[]>[] g = new List[N + 1];
    g[0] = Collections.emptyList();
    for (int i = 0; i < N - 1; i++) {
      if (g[a[i]] == null) g[a[i]] = new ArrayList<>();
      g[a[i]].add(new int[] {b[i], i});
      if (g[b[i]] == null) g[b[i]] = new ArrayList<>();
      g[b[i]].add(new int[] {a[i], i});
    }

    int K = 0;
    for (List<int[]> e : g) K = Integer.max(K, e.size());

    int[] c = new int[N - 1];

    Deque<int[]> q = new ArrayDeque<>();
    q.addLast(new int[] {1, 0, 0});
    while (!q.isEmpty()) {
      int[] n = q.pollFirst();

      int cno = n[0];
      int pno = n[1];
      int pc = n[2];
      int ec = 1;
      List<int[]> es = g[cno];
      for (int[] e : es) {
        int dno = e[0];
        int eid = e[1];
        if (dno == pno) continue;

        if (ec == pc) ec++;
        if (K < ec) ec = 1;
        c[eid] = ec++;
        q.addLast(new int[] {dno, cno, c[eid]});
      }
    }

    System.out.println(K);
    for (int i = 0; i < N - 1; i++)
      System.out.println(c[i]);
  }
}

Measured memory_bytes: 81448
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  map<string,ll> mp;
  rep(i,N){
    string s;cin >> s;
    sort(all(s));
    ++mp[s];
  }
  ll ans = 0;
  for(const pair<string,ll> &m :mp){
    ans += m.second*(m.second-1);
  }
  cout << ans/2 << endl;
  return 0;
}


Measured memory_bytes: 11264
#!/usr/bin/perl
#abc082_a.pl
#Sun Jan 14 20:46:59 2018
#

use warnings;
use strict;

my $temp = <STDIN>;
chomp $temp;

my @temps = split(" ", $temp);

my $n = $temps[0];
my $a = $temps[1];
my $b = $temps[2];

if($n==2){
	print "Borys\n";
}elsif (($b-$a)%2==1){
	print "Borys\n";
}else{
	print "Alice\n";
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        List<Integer> list = new ArrayList<>();

        for(int i = 0; i < n; i++) {
            list.add(scanner.nextInt());
        }

        int count = 0;

        int max = 0;

        for(int i = 0; i < list.size(); i++) {
            int num = list.get(i);
            if(max <= num) {
                max = num;
                count++;
            }
        }

        System.out.println(count);

    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
vector<ll> H;
//A2 B1として1e9/2回全探索、ぎりまにあう？
//最大値がどれかの探索でまいかい10^5だからむり
//降順sort、
//2番目との差
//おいついたら3番目との差
//おいついたら4番目･･･
//A3 B1
//100 80 70 40
//70 70 60 30
//50 60 50 20...

//グラフがあって、1個だけウエからA-B減らせる
//下からB全部へるって感じ
//priority_queueでだしてはいれて。カウントとる
//priorityがどんだけかかるかわかんない。間に合わないきがすんだよな
//ああ、だめそう
//2分探索?
//A3 B1
//100 80 70 40
//2番目に大きい値との差 20
//20/A=6+1=7
//2番目は80-7*B=73>0　NG
//3番目に大きい値との差30+10=40
//30/A+10/A=10+4=14
//3番目70-A*14=56>0
//4番目 60+40+30
//20+14+10=44
//40-44*B=-4<0
//44回おえた時点
//56 36 26 -4
//16 8 6 -4 //AでなくA-Bをひくのか

//100 80 70 40
//4番目 60+40+30
//30 20 15=65
//35 15 5 -25
//-25 -25 -25 -25
//いったん全部B引いて、A-Bを個別に判定、倒せるかどうか。
//攻撃回数で２分探索
bool beat(ll n, ll A, ll B, ll N){
  ll a=n;
  for(int i=0; i<N; i++){
    ll tmp=(H[i]-n*B);
    if(tmp<0) break;
    if(tmp%(A-B)>0) a--;
    tmp/=A-B;
    a-=tmp;
    if(a<0) return false;
  }
  return true;
}

int main(){
  ll N,A,B; cin>>N>>A>>B;
  ll ans=0, tmp;
  H.assign(N,0);
  for(int i=0; i<N; i++){
    ll h; cin>>h; H[i]=h;
  }
  sort(H.begin(), H.end(), greater<ll>());
  ll high=1e9, low=0, mid;
  while(high-low>1){
    mid=(high+low)/2;
    if(beat(mid,A,B,N))
      high=mid;
    else
      low=mid;
  }
  if(beat(low,A,B,N)) ans=low;
  else ans=high;
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <set>
#include <stack>
#include <string>
#include <utility>

using namespace std;

int main() {
  int height, width, num;
  cin >> height >> width >> num;
  deque<deque<char>> board(height, deque<char>(width));

  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cin >> board[i][j];
    }
  }

  // 全探査
  int res = 0;
  for (int flag_col = 0; flag_col < (1 << (height)); flag_col++) {
    for (int flag_row = 0; flag_row < (1 << (width)); flag_row++) {
      // フラグが確定
      int cnt = 0;
      for (int i = 0; i < height; i++) {
        // フラグが1ならスキップ
        if ((flag_col >> i) & 1) {
          continue;
        }

        for (int j = 0; j < width; j++) {
          if ((flag_row >> j) & 1) {
            continue;
          }

          if (board[i][j] == '#') {
            cnt++;
          }
        }
      }

      if (cnt == num) {
        res++;
      }
    }
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3228
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	ArrayList<Integer>[] g;

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextLong();
		}
		long ans = 0;
		for (int i = 0; i < N; ++i) {
			if ((i == 0 && A[0] != 0) || (i > 0 && A[i] - A[i - 1] > 1)) {
				System.out.println(-1);
				return;
			}
		}
		for (int i = 1; i < N; ++i) {
			if (i == N - 1 || A[i + 1] != A[i] + 1) {
				ans += A[i];
			}
		}
		System.out.println(ans);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


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

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   lld     =   long double;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<lld>;
const double PI = acos(-1);

#ifdef tejasp
#include "library/debugger.cpp"
#else
#define trace(...) {}
#define cotra(...) {}
#define end_routine() {}
#define localsys 0
#define endl '\n'
#endif

std::vector<vll> adj(500010);
vi dist(500010);

void dijkstra(int s, vi &d)
{
    d.assign(sz(d),mod);
    d[s] = 0;
    deque<int> q;
    q.pb(s);
    while (!q.empty()) {
        int v = q.front();
        q.ppf;
        for (auto to : adj[v]) {
            if (d[v] + to.ss < d[to.ff]) {
                d[to.ff] = d[v] + to.ss;
                if(to.ss) q.pb(to.ff);
                else q.pf(to.ff);
            }
        }
    }
}


int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    map<pll,int> mp;
    cin>>n>>m;
    fol(i,0,m)
    {
        cin>>u>>v>>temp;
        if(mp.count({u,temp})==0) mp[{u,temp}]=n+(2*i)+1;
        if(mp.count({v,temp})==0) mp[{v,temp}]=n+(2*i)+2;
        adj[u].pb({mp[{u,temp}],1});
        adj[mp[{u,temp}]].pb({u,0});
        adj[v].pb({mp[{v,temp}],1});
        adj[mp[{v,temp}]].pb({v,0});
        adj[mp[{u,temp}]].pb({mp[{v,temp}],0});
        adj[mp[{v,temp}]].pb({mp[{u,temp}],0});
    }
    dijkstra(1,dist);
    if(dist[n]==mod) cout<<-1<<endl;
    else cout<<dist[n]<<endl;
    return 0;
}

signed main()
{
    #ifdef tejasp
            freopen("input.txt", "rt", stdin);
            freopen("output.txt", "wt", stdout);
    #endif
    if(!localsys) { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
    end_routine();
    if(localsys) system("pause");
}

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

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)

int main(){
	ll Q; cin>>Q;
  	vector<ll> l(Q);
  	vector<ll> r(Q);
  	rep(i,Q) cin>>l[i]>>r[i];
    ll s[100001];
    bool is_prime[100001];
    rep(i,100001) is_prime[i]=true;
  	is_prime[0]=is_prime[1]=false;
  	for(int i=2;i<=100000;i++){
    	if(is_prime[i]){
        	for(int j=2*i;j<=100000;j+=i) is_prime[j]=false;
        }
    }
    s[1]=0;
  	for(ll i=3;i<=100000;i+=2){
      	ll tmp=(i+1)/2;
    	if(is_prime[i] && is_prime[tmp]) s[i]=s[i-2]+1;
      	else s[i]=s[i-2];
    }
  	rep(i,Q){
      ll R=r[i],L=l[i];
      if(L==1) printf("%lld\n",s[R]);
      else printf("%lld\n",s[R]-s[L-2]);
    }
}

Measured memory_bytes: 3072
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
      
      Scanner scanner = new Scanner(System.in);
      int n = scanner.nextInt();
      int a1;
      int[][] a2 = new int[n][2];

      for (int i = 0;  i < n  ; i ++ ) {
          a1 = scanner.nextInt();
          a2[i][0] = i + 1;
          a2[i][1] = a1;
      }

      quick_sort(a2, 0, n - 1);

      for (int i = 0;  i < n ; i ++ ) {
         System.out.print(a2[i][0]);
         System.out.print(" ");
      }

      return;
    }

    static void quick_sort(int[][] d, int left, int right) {
        if (left>=right) {
            return;
        }
        int p = d[(left+right)/2][1];
        int l = left, r = right;
        int a3_1;
        int a3_2;
        while(l<=r) {
            while(d[l][1] < p) { l++; }
            while(d[r][1] > p) { r--; }
            if (l<=r) {
                a3_1 = d[l][0];
                a3_2 = d[l][1];
                d[l][0] = d[r][0];
                d[l][1] = d[r][1];
                d[r][0] = a3_1;
                d[r][1] = a3_2;
                l++; r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    }

  }


Measured memory_bytes: 63268
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)
#define x first
#define y second

template <typename T> struct BinaryIndexedTree {
    vector<T> data;

    BinaryIndexedTree(int sz) { data.assign(++sz, 0); }

    T sum(int k) {
        T ret = 0;
        for (++k; k > 0; k -= k & -k)
            ret += data[k];
        return (ret);
    }

    void add(int k, T x) {
        for (++k; k < (int)data.size(); k += k & -k)
            data[k] += x;
    }
};

int solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n + 1);
    FOR(i, 1, n + 1) { cin >> a[i]; }
    BinaryIndexedTree<int> fn(n + 1);
    vector<int> last(n + 1, -1), ans(q);
    vector<pair<int, int>> vec[n + 1];
    REP(i, q) {
        int l, r;
        cin >> l >> r;
        vec[r].emplace_back(l, i);
    }
    FOR(i, 1, n + 1) {
        fn.add(i, 1);
        if (last[a[i]] != -1) {
            fn.add(last[a[i]], -1);
        }
        last[a[i]] = i;
        int val = fn.sum(i);
        for (auto j : vec[i]) {
            ans[j.y] = val - fn.sum(j.x - 1);
        }
    }
    for (auto &x : ans) {
        cout << x << '\n';
    }
    return 0;
}
signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 44196
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

// author:Swastik Banerjee

using namespace std;

typedef long long ll;
#define MOD 1000000007

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


  ll n;
  cin >> n;
  ll arr_a[n], arr_b[n], arr_c[n];
  for (ll i = 0; i < n; i++) {
    cin >> arr_a[i] >> arr_b[i] >> arr_c[i];
  }

  ll dp_a[n], dp_b[n], dp_c[n];

  ll dp[n];

  dp_a[0] = arr_a[0];
  dp_b[0] = arr_b[0];
  dp_c[0] = arr_c[0];

  dp[0] = max(dp_c[0], max(dp_a[0], dp_b[0]));

  for (int i = 1; i < n; i++) {
    dp_a[i] = arr_a[i] + max(dp_b[i - 1], dp_c[i - 1]);

    dp_b[i] = arr_b[i] + max(dp_a[i - 1], dp_c[i - 1]);

    dp_c[i] = arr_c[i] + max(dp_b[i - 1], dp_a[i - 1]);

    dp[i] = max(dp_c[i], max(dp_a[i], dp_b[i]));
  }

  cout << dp[n - 1];
}

Measured memory_bytes: 5760
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int N, A, B, C;
    cin >> N >> A >> B >> C;

    vector<int> l(N);
    for (int i = 0; i < N; i++) {
        cin >> l[i];
    }

    ll cost = 1000000000;
    for (int i = 0; i < (1 << (2*N)); i++) {
        int tmp = i;
        vector<int> a, b, c;
        ll tmpa = 0, tmpb = 0, tmpc = 0;
        for (int j = 0; j < N; j++) {
            if (tmp % 4 == 0) {
                a.push_back(l[j]);
                tmpa += l[j];
            } else if (tmp % 4 == 1) {
                b.push_back(l[j]);
                tmpb += l[j];
            } else if (tmp % 4 == 2) {
                c.push_back(l[j]);
                tmpc += l[j];
            }
            tmp /= 4;
        }

        int lena = a.size();
        int lenb = b.size();
        int lenc = c.size();

        if ( lena == 0 || lenb == 0 || lenc == 0) {
            continue;
        } else {
            lena--; lenb--; lenc--;
            cost = min(cost, abs(A - tmpa) + abs(B - tmpb) + abs(C - tmpc) + 10 * ( lena + lenb + lenc ) );
        }
    }

    cout << cost << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  long long n;
  cin >> n;
  
  long long sum = n + (n * n) + (n * n * n);
  
  cout << sum << "\n";
  
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    string s;
    cin >> s;
    if(s>"2019/04/30") cout << "TBD\n";
    else cout << "Heisei\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int c0=0,c1=0,c2=0,c3=0;
  while(n--)
  {
    string a;
    cin>>a;
    if(a=="AC")
      c0++;
    else if(a=="WA")
      c1++;
   	else if(a=="TLE")
      c2++;
    else if(a=="RE")
      c3++;
  }
  cout<<"AC x "<<c0<<endl;
  cout<<"WA x "<<c1<<endl;
  cout<<"TLE x "<<c2<<endl;
  cout<<"RE x "<<c3<<endl;
  return 0;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
using namespace std;
//
const int inf=1e9+7;//0x3f
//
int main(){
	int N;
	int D[50];
	int cnt[13];
	fill(cnt,cnt+13,0);
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>D[i];
		cnt[D[i]]++;
	}
	if(cnt[0]==1||cnt[12]==2){
		cout<<0<<endl;
		return 0;
	}else{
		for(int i=1;i<12;i++){
			if(cnt[i]>=3){
				cout<<0<<endl;
				return 0;
			}
		}
	}
	int ans=0;
	for(int i=0;i<(1<<11);i++){
		int diff=inf;
		vector<int> V;
		V.push_back(0);
		for(int j=0;j<11;j++){
			if(cnt[j+1]==0){
				continue;
			}else if(cnt[j+1]==1){
				if((i>>j)&1){
					V.push_back(j+1);
				}else{
					V.push_back(24-(j+1));
				}
			}else{
				V.push_back(j+1);
				V.push_back(24-(j+1));
			}
		}
		if(cnt[12]==1){
			V.push_back(12);
		}
		sort(V.begin(),V.end());
		for(int j=0;j<V.size()-1;j++){
			diff=min(diff,abs(V[j]-V[j+1]));
		}
		diff=min(diff,abs(24-V[V.size()-1]));
		ans=max(ans,diff);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int q;
  scanf("%d",&q);
  int A[800010];
  int start=400000;
  int last=400001;
  int command;
  int d,x,p;
  for(int i=0;i<q;i++){
    scanf("%d",&command);
    if(command==0){
      scanf("%d %d",&d,&x);
      if(d==0){
        A[start]=x;
        start--;
      }
      else{
        A[last]=x;
        last++;
      }
    }
    else if(command==1){
      scanf("%d",&p);
      printf("%d\n",A[p+start+1]);
    }
    else if(command==2){
      scanf("%d",&d);
      if(d==0){
        start++;
      }
      else{
        last--;
      }

    }
  }
  return 0;
}



Measured memory_bytes: 3336
import bisect
import sys
input=lambda : sys.stdin.readline().rstrip()
a,b,q=map(int,input().split())
s=sorted([int(input()) for i in range(a)])
t=sorted([int(input()) for i in range(b)])
for i in range(q):
    ans=999999999999
    x=int(input())
    w=bisect.bisect_left(s,x)
    for j in range(2):
        if not 0<=w-j<len(s):
            continue
        z=bisect.bisect_left(t,s[w-j])
        for k in range(2):
            if not 0<=z-k<len(t):
                continue
            ans=min(ans,abs(x-s[w-j])+abs(s[w-j]-t[z-k]))
    w=bisect.bisect_left(t,x)
    for j in range(2):
        if not 0<=w-j<len(t):
            continue
        z=bisect.bisect_left(s,t[w-j])
        for k in range(2):
            if not 0<=z-k<len(s):
                continue
            ans=min(ans,abs(x-t[w-j])+abs(t[w-j]-s[z-k]))
    print(ans)

Measured memory_bytes: 12840
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		ll n,a,b;
		cin>>n>>a>>b;
		ll ca=(n/(a+b))*a,cb=((n/(a+b))*b);
		while(ca+cb<n){
			if(ca+cb+a>n){
				ca+=n-ca-cb;
			}
			else{
				ca+=a;
				cb+=n-ca-cb;
			}
		}
		cout<<ca;
	}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if (abs(b - a) <= d && abs(c - b) <= d) {
        print("Yes");
    } else if (abs(c - a) <= d) {
        print("Yes");
    } else {
        print("No");
    }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int n;
    cin >> n;
    VL a(n);
    REP(i, n) cin >> a[i];
    VL asum(n);
    REP(i, n) {
        asum[i] = a[i] + (i == 0 ? 0 : asum[i - 1]);
    }
    map<LL, int> mp;
    REP(i, n) {
        mp[asum[i]]++;
    }
    LL ans = 0, now = 0;
    REP(i, n) {
        ans += mp[now];
        mp[asum[i]]--;
        now = asum[i];
    }
    cout << ans << endl;
}


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

using namespace std;
#define ll long long
const int N = 1e5 + 5;
vector<int> g[N];
int dist[N][3];

int bfs(int source, int target) {
    for (int i = 0; i < N; i++) for (int j = 0; j < 3; j++) dist[i][j] = 1e8;
    queue<pair<int, int> > q;
    q.push({source, 0});
    dist[source][0] = 0;
    while (q.size()) {
        int node = q.front().first;
        int mod = q.front().second;
        q.pop();
        for (auto child:g[node]) {
            int nmod = (mod + 1) % 3;
            if (dist[child][nmod] > dist[node][mod] + 1) {
                dist[child][nmod] = dist[node][mod] + 1;
                q.push({child, nmod});
            }
        }
    }
    if (dist[target][0] > 1e7) return -1;
    return dist[target][0] / 3;
}

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

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
     }
    int s, t;
    cin >> s >> t;
    cout << bfs(s, t) << endl;
    return 0;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
const int INF=10000000;

int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    ll l=floor(n/(a+b));
    ll ans=a*l;
    ll d=n%(a+b);
    cout << ans+min(d,a) << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main( )
{
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    int ans=0;
    for(int i=0;i<=a;i++)
    for(int j=0;j<=b;j++)
    for(int k=0;k<=c;k++)
    {
        if(i*500+j*100+k*50==x) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
  tmp = [int(j) for j in input().split()]
  s.append(tmp)
  
sat = 0
lst = [0 for i in range(26)]

for i in range(D):
  satlst = [0 for j in range(26)]
  for j in range(26):
    sattmp = sat + s[i][j]
    for k in range(26):
      if j != k:
        sattmp -= c[k] * ((i + 1) - lst[k])
    satlst[j] = sattmp
  sat = max(satlst)
  lst[satlst.index(sat)] = (i + 1)
  print(satlst.index(sat) + 1)


Measured memory_bytes: 9524
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <map>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <memory>

using namespace std;

#if 1
#define PRINT(x) { cout << #x << ": " << (x) << endl; }
#define PRINT_CONTAINER(x)  { cout << #x << ": ";                       \
        for (size_t ix = 0; ix < (x).size(); ++ix) cout << (x)[ix] << ", "; \
        cout << endl; }
#else
#define PRINT(x)
#define PRINT_CONTAINER(x)
#endif

typedef pair<int, int> p;

int a, b, c;

int main(int argc, char *argv[]) {
    scanf("%d %d %d", &a, &b, &c);
    puts(a + b >= c ? "Yes" : "No");
}


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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int N, T;
    cin >> N >> T;
    vector<pair<int, int>> data(N);
    REP(i, N) {
        int c, t;
        cin >> c >> t;
        data[i].first = c;
        data[i].second = t;
    }

    int ans = 1001;
    REP(i, N) {
        int c = data[i].first;
        int t = data[i].second;
        if (t > T) continue;
        ans = min(ans, c);
    }
    if (ans == 1001) {
        cout << "TLE" << endl;
    } else {
        cout << ans << endl;
    }
}

signed main() {
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    int num = 0;
    rep(i,N){
        if(S[i]=='I'){
            num += 1;
            ans = max(ans,num);
        }else if(S[i]=='D'){
            num -=1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
  	ci(n);
  vll A;
  vll B(n);
  FOR(i,0,n){
	ci(B[i]);
  } 
  oFOR(i,0,n){
    A.push_back(B[i]);
  }
  REV(A);
  oFOR(i,1,n){
    A.push_back(B[i]);
  }
  if(n%2==0) REV(A);
  FOR(i,0,n){
    cout<<A[i]<<" ";
  }
  co(" ")
}
  

Measured memory_bytes: 5488
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()
#define chmax(x,y) x=max(x,y)




int main(){
    int n,a; cin>>n>>a;
    cout<<n*n-a<<endl;
}

Measured memory_bytes: 3652