akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>  //{{{
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>

#define ALL(c) (c).begin(), (c).end()
#define DUMP(x) std::cerr << #x << ':' << x << '\n';

typedef long long ll;
// clang-format off
template<typename T,typename U>inline bool chmax(T&x,U a){if(x>=a)return 0;x=a;return 1;}
template<typename T,typename U>inline bool chmin(T&x,U a){if(x<=a)return 0;x=a;return 1;}
inline int in(){int x;scanf("%d", &x);return x;}
// clang-format on
// }}}
//{{{ graph.hpp
#ifndef INCLUDE_GRAPH_HPP
#define INCLUDE_GRAPH_HPP
#include <vector>
#include <climits>
namespace orliv {
namespace graph {
struct Edge {
  typedef int weight_type;
  static constexpr weight_type INF =
      std::numeric_limits<weight_type>::max() - 100;

  int from, to;
  weight_type w;
  Edge(int from, int to, weight_type w = 1) : from(from), to(to), w(w) {}
  bool operator<(const Edge& rhs) const {
    if (w != rhs.w) return w > rhs.w;
    if (from != rhs.from) return from < rhs.from;
    return to < rhs.to;
  }
};

typedef Edge::weight_type Weight;
typedef std::vector<Edge> Edges;
typedef std::vector<Weight> Weights;
typedef std::vector<int> Path;
}
typedef std::vector<graph::Edges> Graph;
}
#endif
//}}}
//{{{ kruskal.cc
#ifndef INCLUDE_GRAPH_HPP
#include "graph.hpp"
#endif
#include <algorithm>

namespace orliv {
namespace graph {
namespace kruskal_internal {
struct UnionFind {
  std::vector<int> par;
  UnionFind(int n) : par(n, -1) {}
  int root(int x) { return par[x] >= 0 ? par[x] = root(par[x]) : x; }
  bool same(int x, int y) { return root(x) == root(y); }
  bool merge(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) std::swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
};
}

Edges kruskal(const Graph& g) {
  const int V = g.size();
  Edges es;
  for (const auto& v : g)
    for (const auto& e : v) es.emplace_back(e);
  std::sort(es.begin(), es.end());
  std::reverse(es.begin(), es.end());
  kruskal_internal::UnionFind uf(V);
  Edges spanning_tree;
  spanning_tree.reserve(V - 1);
  for (const auto& e : es) {
    if (!uf.merge(e.from, e.to)) continue;
    spanning_tree.emplace_back(e);
  }
  return std::move(spanning_tree);
}
}
}
//}}}

using namespace std;

int main() {
  int V = in(), E = in();
  orliv::Graph g(V);
  for (int i = 0; i < E; i++) {
    int s = in(), t = in(), w = in();
    g[s].emplace_back(s, t, w);
    g[t].emplace_back(t, s, w);
  }
  auto es = orliv::graph::kruskal(g);
  ll tot = 0;
  for (const auto& e : es) {
    tot += e.w;
  }
  cout << tot << endl;
  return 0;
}

Measured memory_bytes: 9024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000005,p=998244353,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,m,fl,ans,a[N],b[N];
char ch[N];
int calc(int x){
	int t=0;
	while ((x&1)==0) x>>=1,t++;
	return t;
}
int C(int n,int m){return (b[n]-b[m]-b[n-m]) ? 0 : 1;}
int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	n=read();
	scanf(" %s",ch+1);
	for (int i=1;i<=n;i++) a[i]=ch[i]-'1';
	fl=2;
	for (int i=1;i<=n;i++) if (a[i]==1) fl=1;
	if (fl==1) for (int i=1;i<=n;i++) a[i]&=1;
	else for (int i=1;i<=n;i++) a[i]/=2;
	
	for (int i=1;i<=n;i++) b[i]=b[i-1]+calc(i);
	for (int i=1;i<=n;i++) ans=(ans+C(n-1,i-1)*a[i])&1;
	printf("%d\n",ans*fl);
	return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vint A(N);
  rep(i, N) cin >> A[i];
  map<int, int> mp;
  rep(i, N) mp[A[i]]++;
  int ans = 0;
  for(auto&& p : mp) ans += p.second%2;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,i,k,flag=0;
    cin>>k>>a>>b;
    for(i=a; i<=b; i++)
    {
        if(i%k==0)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    {
        cout<<"OK";
    }
    else
        cout<<"NG";
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

//#include "All.h"

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

string S;
ll Smod[200010] = {};
//ll Bmod[200010] = {};
ll T[200010] = {};
const ll mod = 2019;
ll ans = 0;

int main() {
    cin >> S;
    const ll N = S.length();
    Smod[N] = 0;
    T[Smod[N]]++;
    //cout << T[Smod[N]] << endl;
    //Bmod[N] = 1;
    ll Bmod = 1;
    for (int i = N - 1; i >= 0; i--) {
        
        Smod[i] = (Smod[i + 1] + Bmod * (S[i] - '0')) % mod;
        Bmod = (Bmod * 10) % mod;

        T[Smod[i]]++;
        //cout << Smod[i] << endl;
    }
    rep(i, 2019) {
        ans += T[i] * (T[i] - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5284
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int n,m,l; cin >> n >> m >> l;
	vector<vector<int>> dist(n,vector<int>(n,INF));
	rep(i,n) dist[i][i]=0;
	rep(i,m){
		int a,b,c;
		cin >> a >> b >> c;
		a--; b--;
		dist[a][b] = dist[b][a] = c;
	}
	rep(k,n)rep(j,n)rep(i,n) dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
	vector<vector<int>> dist2(n,vector<int>(n,INF));
	rep(i,n) dist2[i][i]=0;
	rep(i,n)rep(j,n){
		if(dist[i][j]<=l) dist2[i][j]=1;
	}
	rep(k,n)rep(j,n)rep(i,n) dist2[i][j] = min(dist2[i][j],dist2[i][k]+dist2[k][j]);
	int q; cin >> q;
	rep(i,q){
		int s,t; cin >> s >> t;
		s--; t--;
		int ans = dist2[s][t]-1;
		if(dist2[s][t] == INF) out(-1);
		else out(ans);
	}
}




Measured memory_bytes: 1280
#include <algorithm>
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
using ll = long long;
using p = pair<int, int>;

int main(void){
  
  int N;
  cin >> N;
  ll sum = 0;
  
  for (int i = 1; i <= N; i++) {
    if (i%3 != 0 && i%5 != 0) sum += i;
  }
  printf("%lld\n", sum);
  
  return 0;
}


Measured memory_bytes: 3760
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        System.out.println(String.format("%.6f %.6f", r*r*Math.PI, 2*r*Math.PI));
    }
}


Measured memory_bytes: 28268
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<functional>
#include<string>
using namespace std;

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }


  template< typename C >
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

vector<int> ANS;
int main(){
    int n, q;
    string S;
    cin >> n >> S >> q;
    SegmentTree<int> seg(n+3, [](int a, int b){return a|b;}, 0);
    for(int i = 0; i < n; i++){
        int k = 1 << (S[i]-'a');
        seg.set(i+1, k);
    }
    seg.build();
    for(int i = 0; i < q; i++){
        int query;
        cin >> query;
        if (query == 1){
            int s;
            char c;
            cin >> s >> c;
            int k = 1 << (c - 'a');
            seg.update(s, k);
        }
        else if (query == 2){
            int l, r;
            cin >> l >> r;
            int t = seg.query(l, r+1);
            int num = 0;
            while(t > 0){
                if (t & 1)num++;
                t >>= 1;
            }
            ANS.push_back(num);
        }
    }
    for(int i = 0; i < ANS.size(); i++){
        cout << ANS[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5124
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define MOD 1e9 + 7
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265359

void Main()
{
    string s1;
    cin >> s1;

    // rep(i, (s1.size() - 1))

    if (s1[(s1.size() - 1)] == '?')
        s1[(s1.size() - 1)] = 'D';

    for (int i = (s1.size() - 2); i != -1; --i)
    {
        if (s1[i] == '?')
        {
            s1[i] = 'D';
        }
    }

    cout << s1 << endl;
    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3804
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 c = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        if(a+b<2*c){
            System.out.println(a*x+b*y);
            return;
        }

        int needA = 0;
        int needB = 0;
        int needC = 0;
        if(x>y){
            needA = x-y;
            needC = 2*y;
            if(a*needA > 2*needA*c){
                needC += 2*needA;
                needA = 0;
            }else{
            }
        }else{
            needB = y-x;
            needC = 2*x;
            if(b*needB > 2*needB*c){
                needC += 2*needB;
                needB = 0;
            }else{
            }
        }
//        System.out.println(needA+" "+needB+" "+needC);
        System.out.println(needA*a+needB*b+needC*c);
    }
}

Measured memory_bytes: 35856
#include <iostream>
using namespace std;
int main()
{
    int x,a,b,n,m,q,t;
    cin>>x>>a>>b;
    n=x-a;
    m=n/b;
    q=m*b;
    t=q-n;
    if(t<0){t=t*-1;}
    cout<<t;
    return 0;
}


Measured memory_bytes: 3088
N,M=map(int,input().split())
DP=[[-1]*6000 for i in range(6000)]
def P(n,k):
  if n<0 or k<1:
    return 0
  if DP[n][k]!=-1:
    return DP[n][k]
  if k==1:
    DP[n][k]=1
    return 1
  DP[n][k]=(P(n,k-1)+P(n-k,k))%M
  return DP[n][k]

for i in range(5500):
  for j in range(i+1):
    P(i+1,j+1)
X=[0]
DP[0][0]=1
for i in range(5500):
  X.append(0)
  for j in range(i+1):
    X[-1]=(X[-1]+DP[j][j]*DP[i-j][i-j])%M
Y=[0]
for i in range(10800):
  Y.append(Y[i]+X[i>>1])
P=0
for i in range(1,N+1):
  P=(P+X[i])%M
  if 2*i>N:
    P=(P-Y[2*i-N])%M
print(P)

Measured memory_bytes: 356996
#include<bits/stdc++.h>
using namespace std;
int main (){
    int l,r,a,b,c,d;cin>>a>>b>>c>>d;
    l=a+b;
    r=c+d;
    if(l>r)cout<<"Left";
    if(l==r)cout<<"Balanced";
    if(l<r)cout<<"Right";
    return 0;
}


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

//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).end()) i=(c).end(); i!=(c).begin(); --i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())

#define PB(a) push_back(a)

#define FS first
#define SE second

#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal var
//------------------------------------------


int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------

  int A,B,T;
  cin >> A >> B >> T ;
  int ans = 0;
  ans = T/A*B;
  cout << ans << endl;
  return 0;
}


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

int main() {
    
    int N,K,c=0;
    cin >> N >> K;
    map<int,int> sunuke{};
    
    for(int i=0;i<N;i++){
        sunuke[i+1] = 0;
    }
    
    for(int i=0;i<K;i++){
        int d_i;    
        cin >> d_i;
        for(int j=0;j<d_i;j++){
            int a_i;
            cin >> a_i;
            sunuke[a_i] += 1;
        }
    }
    
    for(int i=0;i<N;i++){
        if(sunuke[i+1] == 0) c++;
    }
    
    cout << c <<endl;
}

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

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

  ll n, m;
  cin >> n >> m;
  ll ans = 1;

  ll i = 1;
  while (i * i <= m) {
    if (m%i == 0) {
      if (m/i >= n) ans = max(ans, i);
      if (i >= n) ans = max(ans, m/i);
    }
    i++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(ll, N, M);
  vector<pll> p(M);
  rep(i, 0, M) {
    in(p[i].second, p[i].first);
  }
  auto p2 = p;
  sort(all(p));
  map<ll, ll> mp;
  map<string, ll> memo;
  each(x, p) {
    memo[to_string(x.second) + ":" + to_string(x.first)] = ++mp[x.second];
  }

  each(x, p2) {
    printf("%06lld%06lld\n", x.second, memo[to_string(x.second) + ":" + to_string(x.first)]);
  }
}


Measured memory_bytes: 23296
#include <stdio.h>
#include <string.h>
int main(void){
	int N,i;
	int count;
	char S[51];
	scanf("%d",&N);
	scanf("%s",S);
	count=0;
	for(i=0;i<N-2;i++){
		if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C'){
			count++;
		}
	}
	printf("%d\n",count);
	return 0;
	}


Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    int n;
    cin>>n;
    V<ll> a(n),s(n+1,0),t(n+1,0);
    cinf(n,a);
    rep(i,n) s[i+1]=s[i]+a[i];
    ll ans=INF;
    for(int i=1;i<n;i++){
        chmin(ans,abs(s[n]-s[i]-s[i]));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4992
using System;

using System.Linq;

class Mainp{
    public static void Main(){
        var str = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        if(Math.Abs(str[0]-str[1])>=(Math.Abs(str[0]-str[2])+Math.Abs(str[1]-str[2]))) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

Measured memory_bytes: 11220
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int H, W;
  int h, w;
  cin >> H >> W;
  cin >> h >> w;

  cout << (H - h) * (W - w) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define FOR(i,m,n) for(i=m;i<n;i++)


int main(void)
{
	int a,b[100],c[100],i,d=0;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d",&b[i]);
	}
	for(i=0;i<a;i++){
		scanf("%d",&c[i]);
		if(b[i]-c[i]>0) d=d+b[i]-c[i];
	}
	printf("%d\n",d);
	return 0;
}

Measured memory_bytes: 128
import numpy as np
N,M = list(map(int,input().split()))
x = []
y = []
z = []
for i in range(N):
    a,b,c = list(map(int,input().split()))
    x.append(a)
    y.append(b)
    z.append(c)
x = np.array(x)
y = np.array(y)
z = np.array(z)
ppp = x+y+z
ppn = x+y-z
pnp = x-y+z
pnn = x-y-z
npp = -x+y+z
npn = -x+y-z
nnp = -x-y+z
nnn = -x-y-z
score=[]
score.append(sum(sorted(list(ppp))[::-1][:M]))
score.append(sum(sorted(list(ppn))[::-1][:M]))
score.append(sum(sorted(list(pnp))[::-1][:M]))
score.append(sum(sorted(list(pnn))[::-1][:M]))
score.append(sum(sorted(list(npp))[::-1][:M]))
score.append(sum(sorted(list(npn))[::-1][:M]))
score.append(sum(sorted(list(nnp))[::-1][:M]))
score.append(sum(sorted(list(nnn))[::-1][:M]))
print(max(score))


Measured memory_bytes: 12516
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    ans = 0
    motikosi = 0
    for i in range(N+1):
        if i <= N-1:
            if B[i]+motikosi > A[i]:
                # この街のモンスは全部倒す
                ans += A[i]
                restA = max(A[i]-motikosi, 0)
                motikosi = B[i] - restA
            else:
                # この街のモンスは全部倒しきれない
                ans += B[i]+motikosi
                motikosi = 0
        else:
            # 最後の街は総力戦
            if A[i] > motikosi:
                ans += motikosi
            else:
                ans += A[i]

    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 18624
/*
	RAone00
	Rohit sharma
	*/

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

	typedef long long ll;
	typedef long double ld;
	typedef pair < ll, ll > pll;
	typedef vector < vector < ll > > matrix;
	typedef vector < ll > vll;

	#define pb push_back
	#define debug(x) cout << (#x) << " is " << (x) << endl
	#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

	const ll mod = 1e9 + 7;
	const ll inf = LLONG_MAX;
	const ll N = 1e5 + 10;

	
	int main() {
	    fast_io();
	    int n;
	    cin >> n;
	    int a[n];
	    for (int i = 0; i < n; ++i) {
	    	cin >> a[i];
	    }
	    int s = 0, d = 0;
	    for (int i = 0; i < n; ++i) {
	    	if (a[i] % 2 == 0) {
	    		d++;
	    		if ((a[i] % 3 == 0) || (a[i] % 5 == 0)) s++;
                else {
                	cout << "DENIED\n";
                	break;
                }
	    	}
	    }
	    if (s == d) cout << "APPROVED\n";
	    return 0;
	}

 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <iomanip>
#include <set>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
set <int> vec;


int main()
{
	ios::sync_with_stdio(false);

#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif


	int num, sum;

	int ans1 = 0, ans2 = 0, ans3 = 0;

	cin >> num >> sum;
	sum = sum / 1000;

	ans3 = sum % 5;

	while (ans3 <= sum) {

		int ost = num - ans3;

		for (int i = 0; i <= ost; ++i) {
			if (5 * i + 10 * (ost - i) == sum - ans3) {
				ans1 = ost - i;
				ans2 = i;
				cout << ans1 << ' ' << ans2 << ' ' << ans3;
				return 0;
			}
		}

		ans3 += 5;
	}

	cout << "-1 -1 -1";
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
    }
    if a < 10 && b < 10 {
        println!("{}", a * b);
    } else {
        println!("-1");
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (1e10)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x) { cout << setprecision(12) << x << endl; }
template<class T, class... A> void print(const T& first, const A& ... rest) { cout << first << " "; print(rest...); }
struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); } } premain;



int main() {
	int a;
	cin >> a;
	string s;
	cin >> s;

	if (3200 <= a) {
		print(s);
	}
	else {
		print("red");
	}

}


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

int main() {
  int a,b,c;
  cin >> a >>b >>c ;
  
  if( a == 1){
 cout << "Hello World" << endl;
  }
  else if (a == 2){
    cout << b+c << endl;
  }
}
  




Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N;
    string S;
    
    cin >> N;
    cin >> S;

    int cnt = 0;
    for( int ii = 0; ii < N-2; ++ii ){
        auto substr = S.substr(ii, 3);
        if( substr == "ABC" ){
            ++cnt;
        }
    }
    
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

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

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

int main(){
  ll A, B; cin >> A >> B;
  cout << LCM(A, B);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FASTINPUT ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) 
#define ll long long 
#define mp make_pair
#define pb push_back
#define Ma 1000000007

int main(){
  FASTINPUT;
  //#ifndef ONLINE_JUDGE
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  //#endif
   ll t;
   t=1;
   while(t>0)
   {
    char ch;
    cin>>ch;
    if(ch=='T')
    {
      cout<<"A";
    }
    if(ch=='A')
    {
      cout<<"T";
    }
    if(ch=='C')
    {
      cout<<"G";
    }
    if(ch=='G')
    {
      cout<<"C";
    }
    
    t--;
   }
  
 return 0; 
    
}

           

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int n;
    cin >> n;

    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> cusum(n);
    cusum[0] = a[0];
    for(int i = 1; i < n; i++){
        cusum[i] = cusum[i-1] + a[i];
    }

    int tc = 2;
    ll ans = 1e18;
    while(tc--) {
        ll sum = 0;
        ll tmp = 0;
        for (int i = 0; i < n; i++) {
            ll x = cusum[i] + sum;
            if (x > 0) {
                if ((tc && i % 2 == 0) || (tc == 0 && i % 2 == 1)) {
                    continue;
                } else {
                    tmp += x + 1;
                    sum -= (x + 1);
                }
            } else if(x < 0){
                if ((tc && i % 2 == 0) || (tc == 0 && i % 2 == 1)) {
                    tmp += ((-1) * x + 1);
                    sum += ((-1) * x + 1);
                } else {
                    continue;
                }
            } else {
                if((tc && i % 2 == 0) || (tc == 0 && i % 2 == 1)){
                    sum++;
                    tmp++;
                } else {
                    sum--;
                    tmp++;
                }
            }
        }
        ans = min(ans,tmp);
    }
    cout << ans << endl;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int gcd(int  a, int  b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}
signed main(){
  int n,q,sum=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      q=gcd(i,j);
      for(int  k=1;k<=n;k++){
        sum+=gcd(q,k);
      }
    }
  }
  cout<<sum<<"\n";
}

Measured memory_bytes: 3628
n=int(input())
def numalpa(num):
  if num<=26:
    return chr(64+num)
  elif num%26==0:
    return numalpa(num//26-1)+chr(90)
  else:
    return numalpa(num//26)+chr(64+num%26)
print(str.lower(numalpa(n)))

Measured memory_bytes: 9176
#include "bits/stdc++.h"

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
//const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};

const long long INF = 1LL << 60;

int n;
ll h[100010];

ll dp[100010];

int main(void){
	cin>>n;
	for(int i=0;i<n;i++) cin>>h[i];

	for(int i=0;i<n;i++) dp[i] = INF;

	dp[0] = 0;

	for(int i=1;i<n;i++) {
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if(1 < i) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}

	cout<< dp[n - 1] <<endl;

	return 0;
}

Measured memory_bytes: 1792
x,k,d = map(int,input().split())

def ceil(a, b):
	return -(-a//b)

mint = abs(x)//d
targ1 = min(abs(x-d*mint), abs(x+d*mint))
targ2 = min(abs(targ1-d), abs(targ1+d))

if mint >= k:
	print(min(abs(x-k*d), abs(x+k*d)))
	exit()
else:
	targ3 = k-mint
	if targ3 % 2 == 0:
		print(targ1)
	else:
		print(targ2)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
#define i64 long long int
const i64 INF = (i64)(1e18);
int n,sz[5555];
i64 a[5555];
bool dp1[5555][5555];
i64 dp2[5555][5555];
//current vertex as root, M cuts in subtree:
//dp1: if all positive reachable?
//dp2: minimized value of root block?
vector<int> e[5555];
void dfs(int x,int fat){
	sz[x] = 1;
	if(a[x] > 0)dp1[x][0] = true;
	dp2[x][0] = a[x];
	bool tmp1[5555];i64 tmp2[5555];
	for(auto y : e[x]){
		if(y == fat)continue;
		dfs(y, x);
		for(int i=0; i<sz[x]+sz[y]; i++){
			tmp1[i] = false;
			tmp2[i] = INF;
		}
		for(int i=0; i<sz[x]; i++)for(int j=0; j<sz[y]; j++){
			//Cut at the root of Y.
			if(dp1[x][i]){
				if(dp1[y][j] || dp2[y][j] < 0)
					tmp1[i+j+1] = true;
			}
			if(dp2[x][i] != INF){
				if(dp1[y][j] || dp2[y][j] < 0)
					tmp2[i+j+1] = min(tmp2[i+j+1], dp2[x][i]);
			}
			//Not cut at the root of Y.
			if(dp1[x][i]){
				if(dp1[y][j])
					tmp1[i+j] = true;
			}
			if(dp2[x][i] != INF){
				tmp2[i+j] = min(tmp2[i+j], dp2[x][i] + dp2[y][j]);
			}
		}
		memcpy(dp1[x], tmp1, sizeof(tmp1));
		memcpy(dp2[x], tmp2, sizeof(tmp2));
		sz[x] += sz[y];
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n;for(int i=1; i<=n; i++)cin >> a[i];
	for(int i=1; i<n; i++){
		int x,y;
		cin >> x >> y;
		e[x].push_back(y);
		e[y].push_back(x);
	}
	dfs(1, 1);
	for(int i=0; i<n; i++)if(dp1[1][i] || dp2[1][i] < 0){
		printf("%d\n",i);
		break;
	}
	return 0;
}


Measured memory_bytes: 373120
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <ctime>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <climits>
#include <set>
#include <vector>
#define int long long
using namespace std;
inline int read(){
	int k=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}
	return k*f;
}
int n,m;
signed main()
{
	n=read();m=read();
	int ans=min(n,m/2);
	n-=ans;m-=ans*2;
	ans+=m/4;printf("%lld",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<int,int> m;
vector<int> v;
int main()
{
    int n,ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        if(m[x]==0) v.push_back(x);
        ++m[x];
    }
    for(int i=0;i<v.size();i++) 
        if(m[v[i]]>=v[i]) ans+=m[v[i]]-v[i]; 
        else ans+=m[v[i]];
    printf("%d",ans);
    return 0;
}

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


int main(){
    long long n,a,b,c,d;
    cin>>n>>a>>b;
    c=n/(a+b);
    if(n-(a+b)*c>=a){
        d=a*(c+1);
    }
    else{
        d=a*c+n-c*(a+b);
    }
    cout<<d<<endl;
    return 0;
}

Measured memory_bytes: 256
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    ll N;
    cin >> N;
    if (N % 2){
        cout << N * 2 << endl;
    } else {
        cout << N << endl;
    }

    return 0;
}


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

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		System.out.println((a+b)*h/2);
		
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

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

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
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; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
template< int mod > struct ModInt {
    int x; ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
    ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
    ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}
    ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); }return ModInt(u);}
    ModInt pow(int64_t n) const {ModInt ret(1), mul(x); while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x;}
    friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); }
    static int get_mod() { return mod; }
}; using modint = ModInt< mod >;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    iosetup;
    int A, B; cin >> A >> B;
    int C, D; cin >> C >> D;
    cout << max(0, min(B, D) - max(A, C)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
  
const int MAX = 1e6 + 5; 
  
// structure to store queries 
struct Query 
{ 
    int l, r, idx; 
}; 
  
// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
    return x.r < y.r; 
} 
  
// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 
  
// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
    int sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 
  
void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
    // initialising bit array 
    int bit[n+1]; 
    memset(bit, 0, sizeof(bit)); 
  
    // holds the rightmost index of any number 
    // as numbers of a[i] are less than or equal to 10^6 
    int last_visit[MAX]; 
    memset(last_visit, -1, sizeof(last_visit)); 
  
    // answer for each query 
    int ans[q]; 
    int query_counter = 0; 
    for (int i=0; i<n; i++) 
    { 
        // If last visit is not -1 update -1 at the 
        // idx equal to last_visit[arr[i]] 
        if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit, n); 
  
        // Setting last_visit[arr[i]] as i and updating 
        // the bit array accordingly 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit, n); 
  
        // If i is equal to r of any query  store answer 
        // for that query in ans[] 
        while (query_counter < q && queries[query_counter].r == i) 
        { 
            ans[queries[query_counter].idx] = 
                     query(queries[query_counter].r + 1, bit, n)- 
                     query(queries[query_counter].l, bit, n); 
            query_counter++; 
        } 
    } 
  
    // print answer for each query 
    for (int i=0; i<q; i++) 
        cout << ans[i] << endl; 
} 
  
// driver code 
int main() { 
    // int a[] = {1, 1, 2, 1, 3}; 
    // int n = sizeof(a)/sizeof(a[0]); 
    // Query queries[3]; 
    // queries[0].l = 0; 
    // queries[0].r = 4; 
    // queries[0].idx = 0; 
    // queries[1].l = 1; 
    // queries[1].r = 3; 
    // queries[1].idx = 1; 
    // queries[2].l = 2; 
    // queries[2].r = 4; 
    // queries[2].idx = 2; 
    // int q = sizeof(queries)/sizeof(queries[0]); 
    int n, q;
    cin >> n >> q;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    Query queries[q];
    for (int i = 0; i < q; i++) {
      cin >> queries[i].l >> queries[i].r;
      queries[i].l -= 1;
      queries[i].r -= 1;
      queries[i].idx = i;
    }
    sort(queries, queries+q, cmp); 
    answeringQueries(a, n, queries, q); 
    return 0; 
} 


Measured memory_bytes: 19300
n = int(input())
p = list(map(int, input().split()))

cnt = 0
if p[0] == 1:
    p[0], p[1] = p[1], p[0]
    cnt += 1

if p[n-1] == n:
    p[n-1], p[n-2] = p[n-2], p[n-1]
    cnt += 1

for i in range(n):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        cnt += 1

print(cnt)

Measured memory_bytes: 14004
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int_fast64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7;
constexpr int mod2 = 998244353;

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
template <class T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class K, class V> using Umap = gp_hash_table<K, V>;
using Trie = trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update>;

inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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


signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    int n;
    cin >> n;

    vector<int> a(n);
    vector<int> cum_sum(n+1), cum_xor(n+1);

    rep(i,n){
        cin >> a[i];
        cum_sum[i+1] = cum_sum[i] + a[i];
        cum_xor[i+1] = cum_xor[i] ^ a[i];
    }

    auto getsum = [&](int l, int r){
        return (cum_sum[r] - cum_sum[l-1]);
    };

    auto getxor = [&](int l, int r){
        return (cum_xor[r] ^ cum_xor[l-1]);
    };

    int res = 0;
    for(int i = 1; i <= n; ++i){
        int low = i, high = n + 1;
        while(high - low > 1){
            int mid = (high + low) / 2;
            if(getsum(i, mid) == getxor(i, mid)) low = mid;
            else high = mid;
        }
        res += low - i + 1;
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 7952
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);

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

int main() {
  ll N, M;
  std::cin >> N >> M;
  std::vector<ll> L(M);
  std::vector<ll> R(M);
  REP(i, M) { std::cin >> L[i] >> R[i]; }
  sort(ALL(L));
  reverse(ALL(L));
  sort(ALL(R));

  if (L[0] <= R[0]) {
    std::cout << R[0] - L[0] + 1 << '\n';
  } else {
    std::cout << 0 << '\n';
  }
}

ll div_ceil(ll a, ll b) {
  ll quotient = a / b;
  ll remainder = a % b;
  if (remainder == 0) {
    return quotient;
  } else {
    return quotient + 1;
  }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int n, m;
vector<P> branch[128];

int prim();

int main()
{
    while (scanf("%d %d", &n, &m), n != 0){
        for (int i = 0; i < n; i++) branch[i].clear();

        for (int i = 0; i < m; i++){
            int a, b, c;

            scanf("%d %d %d", &a, &b, &c);
            branch[a].push_back(P(c, b));
            branch[b].push_back(P(c, a));
        }
        printf("%d\n", prim());
    }

    return 0;
}

int prim()
{
    bool v[1024] = {false};
    priority_queue<P, vector<P>, greater<P> > q;
    int sum = 0;

    q.push(P(0, 0));
    v[0] = 0;
    while (!q.empty()){
        P p = q.top(); q.pop();

        if (v[p.second]) continue;
        v[p.second] = true;
        sum += p.first;
        for (int i = 0; i < branch[p.second].size(); i++){
            q.push(branch[p.second][i]);
        }
    }

    return sum;
}

Measured memory_bytes: 1196
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque

n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1; v -= 1
    edge[u].append(v)
    edge[v].append(u)

ans = [-2] * n
def bfs(p, v):
    dq = deque()
    dq.append((p, v))
    while dq:
        p, v = dq.popleft()
        if ans[v] == -1:
            ans[v] = p
        for nv in edge[v]:
            if nv == p:
                continue
            if ans[nv] == -2:
                dq.append((v, nv))
                ans[nv] = -1 

bfs(-1, 0)
if -1 in ans[1:]:
    print("No")
else:
    print("Yes")
    for item in ans[1:]:
        print(item + 1)

Measured memory_bytes: 92044
#include<iostream>
#include<string>
using namespace std;
int n,cnt;
string s;
int main(){

  cin>>n;
  cin>>s;
  for(int i=0;i<1000;i++){
    int c[3]={i/100,(i/10)%10,i%10};
    int f=0;
    for(int j=0;j<n;j++){
      if(s[j]==('0'+c[f])) f++;
      if(f==3) break;
    }
    if(f==3) cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 256
N = int(input())
import sys
input = sys.stdin.readline
a = []
for i in range(1,N+1):
    a.append(int(input()))
ans = 1
check = a[0]
pre_index = 1
while True:
    if 10**5 < ans:
        print(-1)
        exit()
    if check == 2:
        print(ans)
        exit()
    if pre_index == a[check-1]:
        print(-1)
        exit()
    pre_index = check
    check = a[check-1]
    ans += 1

Measured memory_bytes: 7084