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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

// template<class T> void chmin(T& a, T b) {
//     if (a > b) {
//         a = b;
//     }
// }

// template<class T> void chmax(T& a, T b) {
//     if (a < b) {
//         a = b;
//     }
// }

int main(void) {
    int x, y;
    cin >> x >> y;

    cout << x+y/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main(){
    ll n, m;
    cin >> n >> m;

    vector<ll> l(n), r(n), d(n);

    UnionFind<ll> uf(n);

    rep(i, m){
        ll l, r, d;
        cin >> l >> r >> d;
        
        l--, r--;
        if(uf.issame(l, r) && d != uf.diff(l, r)){
            cout << "No\n";
            return 0;
        }
        else {
            uf.merge(l, r, d);
        }
    }

    cout << "Yes\n";
}

Measured memory_bytes: 4224
function Sub(grid, w, h, x, y, a) {
  for (var i = 0; i < h; i++) {
    for (var j = 0; j < w; j++) {
      if (a === 1 && j < x) {
        grid[i][j] = false;
      } else if (a === 2 && j >= x) {
        grid[i][j] = false;
      } else if (a === 3 && i < y) {
        grid[i][j] = false;
      } else if (a === 4 && i >= y) {
        grid[i][j] = false;
      }
    }
  }
  return grid;
}

function Main(input) {
  var inputs = input.split("\n");
  var w_h_n = inputs[0].split(" ").map(e => parseInt(e, 10));
  var grid = new Array(w_h_n[1]);
  for (var i = 0; i < w_h_n[1]; i++) {
    grid[i] = new Array(w_h_n[0]).fill(true);
  }
  var x_y_a;
  for (var i = 1; i <= w_h_n[2]; i++) {
    x_y_a = inputs[i].split(" ").map(e => parseInt(e, 10));
    Sub(grid, w_h_n[0], w_h_n[1], x_y_a[0], x_y_a[1], x_y_a[2]);
  }
  var sum = 0;
  for (var i = 0; i < w_h_n[1]; i++) {
    for (var j = 0; j < w_h_n[0]; j++) {
      sum += grid[i][j] === true ? 1:0;
    }
  }
  console.log(sum);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
  int h, w, n, answer;
  cin >> h >> w >> n;
  if(h < w){
    answer = n/w + 1;
    if(n%w == 0)
      answer--;
  }
  else{
    answer = n/h + 1;
    if(n%h == 0)
      answer--;    
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
import itertools

h, w, k = map(int, input().split())
lst = []
for _ in range(h):
  lst.append(input())
#
data = [0, 1]
all_lists = list(itertools.product(data, repeat=h+w))
#print(all_lists)
count = 0
for each in all_lists:
  #print(each)
  x_list = []
  y_list = []
  number = 0
  for i in range(h + w):
    if each[i] == 1:
      if i < h:
        x_list.append(i)
      elif i < h + w:
        y_list.append(i - h)
  #print(x_list)
  #print(y_list)
  for i in range(h):
    if i not in x_list:
      lst_h = lst[i]
      for j in range(w):
        if j not in y_list:
          lst_hw = lst_h[j]
          if lst_hw == '#':
            number += 1
  #print(number)
  if number == k:
    count += 1
print(count)

Measured memory_bytes: 9536
# input
N = int(input())
A = list(map(int, input().split()))

# solution
counter = 0
while sum([e < 2 for e in A]) == 0:
    if sum([e % 2 for e in A]) == 0:
        counter += 1
        A = [e // 2 for e in A]
    else:
        break
    
# output
print(counter)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<=(b);++i)
#define ROF(i,a,b) for (int i=(a);i>=(b);--i)
typedef long long ll;
inline int read() {
	int x=0,s=1; char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') s=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return s*x;
}

const int MAXN=200005,Mo=1000000007;
int n,m,q,a[MAXN],b[MAXN];
int main(){
	n=read(); m=read();
	if (abs(n-m)>1) puts("0");
	else {
		int ans=1;
		FOR(i,1,n) ans=1ll*ans*i%Mo;
		FOR(i,1,m) ans=1ll*ans*i%Mo;
		if (n==m) ans=1ll*ans*2%Mo;
		printf("%d\n",ans);
	}
	return 0;
}

/*
*/


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];
    SORT(a),SORT(b);
    if(n%2)cout<<b[n/2]-a[n/2]+1<<endl;
    else cout<<b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1]+1<<endl;
}

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

int main() { 
  int A, B;
  cin >> A >> B;
  
  if (A >= 13)
    cout << B << endl;
  else if (6 <= A && A <= 12) 
    cout << B/2 << endl;
  else
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define THE using
#define DARK namespace
#define ONE std
#define dbg(x) cout << #x << " = " << x << endl

THE DARK ONE;
map<int, int> factor(int n){
    map<int, int> f;
    int p = 2;
    while(p * p <= n){
        while(n % p == 0){
            n /= p;
            f[p]++;
        }
        p += 1 + p % 2;
    }
    if(n > 1) f[n]++;
    return f;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    freopen("out.txt", "w", stdout);
//    freopen("input.txt", "r", stdin);
    int n, ans = 0;
    cin >> n;
    map<int, int> p, cnt;
    for(int i = 2; i <= n; i++){
        map<int, int> tmp = factor(i);
        for(auto pi: tmp){
            p[pi.first] += pi.second;
        }
    }
    for(auto pi: p){
        if(pi.second >= 74) cnt[74]++;
        if(pi.second >= 24) cnt[24]++;
        if(pi.second >= 14) cnt[14]++;
        if(pi.second >= 4) cnt[4]++;
        if(pi.second >= 2) cnt[2]++;
    }
    ans += cnt[74];
    ans += cnt[24] * (cnt[2] - 1);
    ans += cnt[14] * (cnt[4] - 1);
    ans += (cnt[4] * (cnt[4] - 1)) / 2 * (cnt[2] - cnt[4]);
    ans += (cnt[4] * (cnt[4] - 1)) / 2 * (cnt[4] - 2);

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



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

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i = 0; i < N; i++){
    cin >> H.at(i);
  }
  int answer = 0;
  for(int i = 0; i < N-1; i++){
    int j, count;
    for(j = i, count = 0; j < N - 1 && H.at(j+1) <= H.at(j); j++, count++){
      i ++;
    }
    if(answer < count) answer = count;
  }
  cout << answer << endl;
}

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

int lock[9][9]={
  {0,1,0,1,0,0,0,0,0},
  {1,0,1,0,1,0,0,0,0},
  {0,1,0,0,0,1,0,0,0},
  {1,0,0,0,1,0,1,0,0},
  {0,1,0,1,0,1,0,1,0},
  {0,0,1,0,1,0,0,0,1},
  {0,0,0,1,0,0,0,1,0},
  {0,0,0,0,1,0,1,0,1},
  {0,0,0,0,0,1,0,1,0},
};

int main(){
  int n=1000;
  while(n--){
    string str;
    cin>>str;
    int size=(int)str.size();
    for(int i=0;i<size-1;i++){
      if(lock[str[i]-'A'][str[i+1]-'A']==0)
	goto end;
    }
    cout<<str<<endl;
  end:
    ;
  }
  return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <algorithm>
#include <string>

int main()
{
  int k, a, b;
  
  std::cin >> k;
  std::cin >> a >> b;
  
  bool result = false;
  
  const int bound = std::min(a + k, b);
  
  for (int i=a; i<=bound; ++i)
  {
    if (i % k == 0) {
      result = true;
    }
  }
  const std::string judge = result ? "OK" : "NG";
  std::cout << judge;
}

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

import sys
from itertools import permutations

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def check(li):
    while len(li) > 1:
        nxt = []
        for i in range(len(li)-2):
            li2 = [li[i], li[i+1], li[i+2]]
            li2.sort()
            nxt.append(li2[1])
        li = nxt.copy()
    return li[0]

N, X = MAP()
M = N*2 - 1

# C = [0] * (N*2-1)
# for perm in permutations(range(N*2-1)):
#     res = check(list(perm))
#     C[res] += 1
# print(C)

# A = LIST()
# print(check(A))

if X == 1 or X == M:
    No()
    exit()

A = [0] * M
A[M//2] = X
if X <= M//2:
    X2 = X - 1
else:
    X2 = X + 1
A[M//2+1] = X2

a = 1
for i in range(M):
    while a == X or a == X2:
        a += 1
    if i == M//2 or i == M//2+1:
        continue
    A[i] = a
    a += 1
Yes()
[print(a) for a in A]


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

int main() {
	int n;
	cin>>n;
	double prob = 1;
	if(n == 1) cout<<prob;
	else{
		if(n%2){
			prob = n;
			cout<<setprecision(6)<<(n/2 + 1)/prob;
		}
		else cout<<setprecision(6)<<prob/2;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define li(x) x.size()-1
#define oo 1000000000
#define inf 1000000000000000000
#define M 1000000007
#define M2 1000000009
#define pii pair<ll,ll>
using namespace std;
typedef long long ll;
const int N = 2e5+100;
const int SQRTN = 320;
const int LOGN = 20;
const double PI = acos(-1);

int dp[N][2];
int n ;
vector<vector<int> > g;

int calc(int node, int prt, bool prtBlack){
	int&ret = dp[node][prtBlack];
	if(ret!=-1)
		return ret;
	if(g[node].size()==1&&prt)
		return ret=1;
	ret=1;
	for(int i = 0 ; i < g[node].size() ; i++){
		if(g[node][i]==prt)
			continue;
		ret= ret*1ll*((!prtBlack)*(calc(g[node][i],node,1))+calc(g[node][i],node,0))%M;
	}
	return ret;
}

int main() {
	cin >> n;
	g.resize(n+1);
	for(int i = 1,a,b ; i < n ; i++){
		scanf("%d%d",&a,&b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	setDP(dp);
	cout << (calc(1,0,0)+calc(1,0,1))%M << endl;;


    return 0;
}

Measured memory_bytes: 14208
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long LL;
const LL N=1000005;
const LL MOD=998244353;
LL JC[N],inv[N];
LL Pow (LL x,LL y)
{
	if (y==1) return x;
	LL lalal=Pow(x,y>>1);
	lalal=lalal*lalal%MOD;
	if (y&1) lalal=lalal*x%MOD;
	return lalal;
}
LL n,m;
LL C (LL x,LL y)	{return JC[x]*inv[y]%MOD*inv[x-y]%MOD;}
LL calc (LL x,LL y)	{return C(x+y,x);}
void solve ()
{
	LL ans=0;
	for (LL u=1;u<=min(n,m);u++)
		ans=(ans+calc(u,u)*calc(n-u,m-u)%MOD)%MOD;
	ans=ans*Pow(calc(n,m),MOD-2)%MOD;
	ans=ans*Pow(2,MOD-2)%MOD;
	ans=(ans+max(n,m))%MOD;
	printf("%lld\n",ans);
}
int main()
{
	JC[0]=1;for (LL u=1;u<=1000000;u++) JC[u]=JC[u-1]*u%MOD;
	inv[1000000]=Pow(JC[1000000],MOD-2);
	for (LL u=999999;u>=0;u--) inv[u]=inv[u+1]*(u+1)%MOD;
	scanf("%lld%lld",&n,&m);
	solve();
	return 0;
}

Measured memory_bytes: 15872
#include<stdio.h>

int main (void){

 while(1){

 char x;

 int sum=0;

 scanf("%c", &x);

 while(x!='\n'){

  sum+=x-'0';

  scanf("%c",&x);

 }

 if(sum ==0){

  break;

 }

 printf("%d\n",sum);

 }

 return 0;

}

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

#include <iostream>
#include <fstream>

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}



void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using namespace std;

int dist(const vector<int> &a, const vector<int> &b){
    double ans = 0;
    for (int i = 0; i < a.size(); i++){
        ans += sqr(a[i]-b[i]);
    }
    return sqrt(ans) == trunc(sqrt(ans));
}

class BGoodDistance {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int n, d;
	    in >> n >> d;
	    vector<vector<int>> x;
	    vector<int> a;
	    int m;
	    for (int i = 0; i < n; i++){
	        a.clear();
	        for (int j = 0; j < d; j++){
	            in >> m;
	            a.pb(m);
	        }
	        x.pb(a);
	    }
	    int ans = 0;
	    for (int i = 0; i < n; i++){
	        for (int j = i+1; j < n; j++){
	            ans += dist(x[i], x[j]);
	        }
	    }
        out << ans;
	}
};

int main() {
	BGoodDistance solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res;
}
const int N = 1e5+5;
int n,m,x,y,id,cnt[N];
char opt[3],vis[N];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),read(m);
	for(ri i=1;i<=m;++i){
		read(id),scanf("%s",opt);
		if(vis[id]) continue;
		if(opt[0]=='A') vis[id]=1,++x,y+=cnt[id];
		else ++cnt[id];
	}
	cout<<x<<" "<<y;
	return 0;
}

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

#define int long long
#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) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

string S;
int a[220000];
int p[2019];
signed main() {
    cin >> S;
    int N = S.length();
    int cur = 1;
    for (int i = N - 1; i >= 0; i--) {
        a[i] = (a[i + 1] + (S[i] - '0') * cur) % 2019;
        (cur *= 10) %= 2019;
    }
    int ans = 0;
    for (int i = 0; i <= N; i++) {
        ans += p[a[i]];
        p[a[i]]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5260
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,Alice=0,Bob=0;
  	cin >> N;
	vector<int> A(N);
	for(int i =0; i<A.size();i++)
		cin >> A.at(i) ;
	sort(A.begin(),A.end());
  	reverse(A.begin(),A.end());
	for(int i =0; i<A.size();i++){
      if(i%2==0)
		Alice+=A.at(i);
  	  else
        Bob+=A.at(i);
    }
	cout << Alice-Bob<<endl;	
}

Measured memory_bytes: 256
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader bf = 
            new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(bf.readLine()),
            max = 0,
            sum = 0;
        int[] p = new int[N];
        for(int i = 0; i < N; i++){
            p[i] = Integer.parseInt(bf.readLine());            
            sum += p[i]; 
            if(max < p[i]){
                max = p[i];
            }
        }
        sum -= max/2;        
        System.out.println(sum);
    }
}

Measured memory_bytes: 20948
#include<cstdio>
inline int in();
inline void wr(int);
int main(int argc,char**argv){
	register int x=in();
	wr(x/500*1000+(x%500)/5*5),putchar('\n');
}
inline int in(){
	register char c=getchar();
	register int x=0,f=1;
	for(;c<'0'||c>'9';c=getchar())
		if(c=='-')f=-1;
	for(;c>='0'&&c<='9';c=getchar())
		x=(x<<1)+(x<<3)+(c&15);
	return x*f;
}
inline void wr(int x){
	if(x<0)putchar('-'),x=-x;
	if(x/10)wr(x/10);
	putchar(x%10+'0');
}


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

int main() {
  int N;
  cin >> N;
  int l,r;
  int answer;
  
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    answer += r - l + 1;
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
/// @pSaurabh

#include <bits/stdc++.h>

using namespace std;

#define read(a, n) for(int i = 0; i < n; i++) cin >> a[i];
#define print(a, n) for(int i = 0; i < n; i++) if(i < n - 1){ cout << a[i] << " "; } else cout << a[i] << "\n";

typedef long long ll;
typedef long double ld;

const ll mod = 1e9 + 7;

void fast(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout .tie(0);
}

int ans = 0;
map <int, vector <int>> adj;
vector <int> dp(100001, -1);

void dfs(int cur){
	if(dp[cur] != -1){
		return;
	} 
	if(!adj.count(cur)){
		dp[cur] = 0;
		return;
	}

	int mx = 0;

	for(auto it: adj[cur]){
		dfs(it);
		mx = max(mx, dp[it]);
	}

	dp[cur] = 1 + mx;
	ans = max(ans, dp[cur]);
}

int main(){
	// fast();

	int n, m;
	cin >> n >> m;

	int x, y;
	for(int i = 0; i < m; ++i){
		cin >> x >> y;
		--x; --y;
		adj[x].push_back(y);
	}

	for(int i = 0; i < n; ++i){
		dfs(i);
	}

	cout << ans << "\n";

	return 0;
}


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

const int maxn = 1e5 + 10;
map<int, int> cnt;

int main() {
    int n; cin >> n;
    while (n--) {
        int a; cin >> a;
        ++cnt[a];
    }
    long long ans = 0;
    vector<int> t;
    for (auto i : cnt) {
        if (i.second >= 4) ans = max(ans, i.first * 1ll * i.first);
        if (i.second >= 2) t.push_back(i.first);
    }
    sort(t.begin(), t.end());
    if (t.size() >= 2) ans = max(ans, t[t.size() - 1] * 1ll * t[t.size() - 2]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;

static class MainClass
{
    public static void Main(string[] args)
    {
        var xy = Console.ReadLine().SplittedStringToInt32List();
        var A = xy[0];
        var B = xy[1];
        var paliolist = new List<int>();
        for (int i = A; i <= B; i++)
        {
            var str = i.ToString();
            if (str[0] == str[4] && str[1] == str[3])
            {
                paliolist.Add(i);
            }
        }
        Console.WriteLine(paliolist.Count);
        Console.ReadLine();
    }


    //// s番目の頂点から各々の頂点への最短距離を求めるBellman-Ford

    //public static void Initialize(int N)
    //{

    //}

    //public static int N;

    //public class Edge
    //{
    //    public int From;
    //    public int To;
    //    public int Cost;
    //}

    //public static List[N Edges;

    //public static List<int> ShortestDistances;

    
    
    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    #endregion
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste

// #include "UnionFind.hpp"
// #include "power.hpp"

signed main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) break;
        vector<double> A(n);
        for (int i = 0; i < n; i++) cin >> A[i];
        double average = accumulate(A.begin(), A.end(), 0.0) / n;
        double deviation = 0;
        for (int i = 0; i < n; i++) deviation += pow(A[i] - average, 2);
        deviation /= n;
        deviation = sqrt(deviation);
        cout << fixed << setprecision(15) << deviation << endl;
    }
}



Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
void solve(){
    ll d,t,s;
    cin>>d>>t>>s;
    if(t*s>=d)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}
int main()
{
   int t=1;
  // int t;
    //cin>>t;
    while(t--)
        solve();  
   return 0;   
}




Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define debug(a) cout << "["; rep(i,a.size()) cout << a.at(i) << ", "; cout<<"]"<< endl;

const ll mod = 1000000007;

int main() {
    ll n; cin >> n;
    vector<ll> cnt(n,1);
    for(ll i = 2; i <= n; i++){
        ll d = 1;
        while(i * d <= n){
            cnt.at(i * d - 1)++;
            d++;
        }
    }
    ll ans = 0;
    rep(i,n){
        ans += (i+1) * cnt.at(i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 81332
#include<cstdio>
#include<cstring>
int main(){
	char str_i[20],str_o[20];
	scanf("%s",str_i);
	int l = strlen(str_i);
	//printf("%d\n",l);
	for(int i=0;i<l;i++){
		str_o[i] = str_i[l-1-i];
		printf("%c",str_o[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 2616
import java.util.*;

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

        String s = sc.next();
        String t = sc.next();

        int ans = 0;
        for(int i = 0; i < s.length(); i++){
            if(!(s.charAt(i) == t.charAt(i))){
                ans++;
            }
        }

        System.out.println(ans);

    }
}


Measured memory_bytes: 41236
N = int(input())
A = list(map(int, input().split()))


def solve(N,A):
    s,e = 0, N-1
    dp = [[0]*N for i in range(N)]
    for k in range(N):
        for i in range(N):
            j = i+k
            if j>=N:
                continue
            sign = (-1)**(N-1-k)
            if k==0:
                dp[i][j] = sign*A[i]
                continue
            dp[i][j] = sign*max(sign*dp[i+1][j]+A[i],sign*dp[i][j-1]+A[j])
    ans = dp[0][N-1]
    return ans
print(solve(N,A))

Measured memory_bytes: 111964
// Problem : C - Low Elements
// Contest : AtCoder - AtCoder Beginner Contest 152
// URL : https://atcoder.jp/contests/abc152/tasks/abc152_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

//Macros

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

//Solution

void solve(){
    int n;
    cin>>n;
    int a;
    int mn = inf;
    int ans = 0;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a < mn) mn = a, ans++;
    }
    cout<<ans;
}

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

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

int main() {
  int n,m,X,Y,z,x[101],y[101],i,x_max=-200,y_min=200,yj=810;
  cin>>n>>m>>X>>Y;
  for(i=0;i<n;i++){cin>>x[i];if(x[i]>x_max)x_max=x[i];}
  for(i=0;i<m;i++){cin>>y[i];if(y[i]<=y_min)y_min=y[i];}
  for(z=X+1;z<=Y;z++){
    if(z>x_max&&y_min>=z)yj=0;
  }
  yj==810?cout<<"War":cout<<"No War";
  return 0;
}

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

using namespace std;
typedef long long ll;

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

    ll b;
    cin >> b;

    if (a > 9 || b > 9)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << a * b << endl;
    }

    // for (int i = 0; i < n; i++)
    // {
    //     cin >> a[i];
    // }

    // vector<ll> a;
    // for (int i = 0; i < n; i++)
    // {
    //     int j;
    //     cin >> j;
    //     a.push_back(j);
    // }

    //sort(a,a+n); ソート
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	unsigned char num[1000];
	unsigned short ans = 0;
	int i;
	
	while(1){
		
		for(i = 0;i < 1000;i++){
			num[i] = 0;
		}
		scanf("%s", &num);
		
		for(i = 0;num[i] != 0;i++){
			ans += num[i] - 48;
		}
		
		if(ans == 0){
			break;
		}
		
		printf("%d\n", ans);
		
		ans = 0;
	}
	return 0;
}


Measured memory_bytes: 2040
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

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

    vi v={0,1,2,3,4,5,6,7};
    int N; cin >> N;
    vc<pi> vv;
    rep(i,N){
        int a,b; cin >> a >> b;
        vv.eb(a,b);
    }
    char C[8][8];
    rep(i,8) rep(j,8) C[i][j]='.';
    do{
        set<pi> s;
        rep(i,8){
            s.insert(pi(i,v[i]));
        }
        bool can=true;
        for(auto a:vv){
            if(!s.count(a)) can=false;
        }
        for(auto p:s){
            rep(i,20){
                if(i==10) continue;
                if(s.count(pi(p.fi+i-10,p.se+i-10)) || s.count(pi(p.fi+i-10,p.se-i+10)))
                    can=false;
            }
        }
        if(can) {
            for(auto p:s){
                C[p.fi][p.se]='Q';
            }
            break;
        }
    }while(next_permutation(all(v)));
    rep(i,8){
        rep(j,8){
            cout << C[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3180
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=100005;

int dp[3003][3003];
void solve()
{
    string s,t;
    cin>>s>>t;
    int n=s.length(),m=t.length();
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    int i=n,j=m;vector<char>ans;
    while(i>0&&j>0)
    {
        if(s[i-1]==t[j-1])
        {
            ans.pb(s[i-1]);
            i--;j--;
        }
        else
        {
            if(dp[i][j]==dp[i-1][j])
                i--;
            else
                j--;
        }
    }
    
    reverse(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++)
        cout<<ans[i];
    cout<<endl;
    
    
    
    
    
}


int32_t main()
{
    IOS;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}






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

int main() {
  int N; cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; ++i) {
    cin >> H[i];
  }
  
  int count = 1;
  int max_high = H[0];
  
  for (int i = 1; i < N; ++i) {
    if (H[i] >= max_high) {
      count++;
    }
    max_high = max(H[i], max_high);
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
// finish date: 2018/07/19
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    ll temp = A[0];
    int cnt = 1;
    FOR(i, 1, N) {
        if (temp * 2 >= A[i]) {
            cnt++;
        } else {
            cnt = 1;
        }
        temp += A[i];
    }
    cout << cnt << endl;

    return 0;
}



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

typedef long long ll;

struct median {
private:
    priority_queue<int> L;
    priority_queue<int, vector<int>, greater<int> > R;
    ll sumL = 0LL, sumR = 0LL;

public:
    void add(int x) {
        if(L.size() == 0 || x <= L.top()) {
            L.push(x);
            sumL += x;
        }
        else {
            R.push(x);
            sumR += x;
        }

        while(L.size() < R.size()) {
            sumL += R.top();
            sumR -= R.top();
            L.push(R.top());
            R.pop();

        }

        while(R.size() + 1 < L.size()) {
            sumR += L.top();
            sumL -= L.top();
            R.push(L.top());
            L.pop();
        }
    }
    ll getMedian() {
        return L.top() * 1LL;
    }
    ll getLowerSum() {
        return sumL * 1LL;
    }
    ll getUpperSum() {
        return sumR * 1LL;
    }
    ll getSizeL() {
        return L.size() * 1LL;
    }
    ll getSizeR() {
        return R.size() * 1LL;
    }
};

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

    priority_queue<int> L;
    priority_queue<int, std::vector<int>, std::greater<int> > R;

    int n;
    cin >> n;

    ll c = 0;

    median g;

    for(int i = 0; i < n; i++) {
        int t;
        cin >> t;

        if(t == 1) {
            int a, b;
            cin >> a >> b;

            c += b * 1LL;
            g.add(a);
        }
        else {
            ll med = g.getMedian();
            cout << med << " ";
            cout << c + med * g.getSizeL() - g.getLowerSum() + g.getUpperSum() - med * g.getSizeR() << endl;
        }
    }
}


Measured memory_bytes: 3452
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>

using namespace std;

int main()
{
    char str[110];
    cin >> str;
    int len = strlen(str);
    cout<<str[0]<<len-2<<str[len-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
problem_num = int(input())
solve_time = []
sum_time = 0
for t in input().split():
    solve_time.append(int(t))
    sum_time += int(t)

drink_num = int(input())
pair = []
for i in range(drink_num):
    program_num, time = map(int, input().split())
    pair.append((program_num, time))

for i in range(drink_num):
    label = pair[i][0]
    time = pair[i][1]
    print(sum_time + time - solve_time[label - 1])


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

#define x first
#define y second
#define x1 X1 
#define x2 X2
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
inline int read ()
{
	int sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

const int MaxN = 50 + 5;

int N, A[MaxN], B[MaxN], Dis[MaxN][MaxN];

inline int Check (LL ans)
{
	memset(Dis, 0, sizeof Dis);
	for (int i = 0; i <= 50; ++i) Dis[i][i] = 1;
	for (int i = 1; i <= 50; ++i) if ((1ll << i) & ans) for (int j = 0; j <= 50; ++j) Dis[j][j % i] = 1;
	for (int k = 0; k <= 50; ++k)
		for (int i = 0; i <= 50; ++i)
			for (int j = 0; j <= 50; ++j)
				if (Dis[i][k] && Dis[k][j]) Dis[i][j] = 1;
	for (int i = 1; i <= N; ++i)
		if (!Dis[A[i]][B[i]]) return 0;
	return 1;
}

int main()
{
#ifdef hk_cnyali
	freopen("C.in", "r", stdin);
	freopen("C.out", "w", stdout);
#endif
	N = read();
	for (int i = 1; i <= N; ++i) A[i] = read();
	for (int i = 1; i <= N; ++i) B[i] = read();
	LL ans = (1ll << 51) - 1; 
	for (int i = 50; i >= 0; --i)
	{
		ans ^= (1ll << i);
		if (!Check(ans)) ans ^= (1ll << i);
	}
	cout<<(ans == ((1ll << 51) - 1) ? -1 : ans)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#define w first
#define k second
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int N=200010;
pii a[N],b[N];
int p[N];
int find(int x)
{
    if(p[x]!=x) p[x]=find(p[x]);
    return p[x];
}
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int n,cnta=0,cntb=0;
        cin>>n;
        ll res=0;
        for(int i=1;i<=n;i++) p[i]=i;
        for(int i=0;i<n;i++)
        {
            int k,l,r;
            cin>>k>>l>>r;
            if((k==0&&l>=r)||(k==n&&r>l)) 
            {
                res+=min(l,r);
                continue;
            }
            if(l>=r) res+=r,a[cnta++]={l-r,k};
            else res+=l,b[cntb++]={r-l,n-k};
        }
        sort(a,a+cnta),sort(b,b+cntb);
        reverse(a,a+cnta),reverse(b,b+cntb);
        for(int i=0;i<cnta;i++)
        {
            int pos=find(a[i].k);
            if(pos) p[pos]=pos-1,res+=a[i].w;
        }
        for(int i=1;i<=n;i++) p[i]=i;
        for(int i=0;i<cntb;i++)
        {
            int pos=find(b[i].k);
            if(pos) p[pos]=pos-1,res+=b[i].w;
        }
        cout<<res<<endl;
    }
    return 0;
}

Measured memory_bytes: 5928
#include <bits/stdc++.h>
using namespace std;
bool comp(int i,int j)
{
    return (i>j);
}

int main()
{

   int a[10];


   int x,i;

   for(i=0; i<5; i++)
   scanf("%d",&a[i]);






    sort(a,a+5,comp);
    int size=5;
    for(i=0; i<size; i++)
    {

        printf("%d",a[i]);
        if(i<size-1)
        printf(" ");
    }
    printf("\n");
    return 0;



}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
//#include <stdio.h>

 
int main(void)
{
    long long n, i;
    cin >> n;
    vector<long long> a(n - 1), b(n + 1, 0);
    for(i = 0; i < n - 1; i++) {
        cin >> a.at(i);
        b.at(a.at(i))++;
    }

    for(i = 1; i <= n; i++)
        cout << b.at(i) << endl;
}

Measured memory_bytes: 6352
import sys
sys.setrecursionlimit(1000000)

def dfs(n,p,d):
    visited[n] = True
    dist[n] = d
    for (i,c) in A[n]:
        if i != p and not visited[i]:
            dfs(i,n,d+c)

N = int(input())
A = [[] for _ in range(N)]
for _ in range(N-1):
    a,b,c = map(int,input().split())
    A[a-1].append((b-1,c))
    A[b-1].append((a-1,c))
Q,K = map(int,input().split())
B = []
for _ in range(Q):
    x,y = map(int,input().split())
    B.append((x,y))

dist = [-1]*N
visited = [False]*N
dfs(K-1,N,0)

for (x,y) in B:
    print(dist[x-1]+dist[y-1])



Measured memory_bytes: 146028
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD=1000000007;

void cout_vec(vector<long long> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

void cout_mat(vector<vector<long long>> &mat){
    for(int i=0; i<mat.size(); i++){
        vector<long long> vec = mat[i];
        cout_vec(mat[i]);
    }
}

int main(){
    int N, X;
    cin >> N >> X;
    vector<int> S(N,0);
    for(int i=0; i<N; i++){
        cin >> S[i];
    }
    int max_=X+1;
    for(int i=0; i<N; i++){
        cin >> S[i];
        if(S[i]>max_){
            max_=S[i];
        }
    }

    sort(S.rbegin(),S.rend());
    vector<vector<long long> > dp(N+1,vector<long long>(max_,0));
    dp[0][X]=1;
    for(int i=0; i<N; i++){
        for(int j=0; j<max_; j++){
            int r=j%S[i];
            dp[i+1][r]+=dp[i][j];
            dp[i+1][r]%=MOD;
            dp[i+1][j]+=dp[i][j]*(N-i-1);
            dp[i+1][j]%=MOD;
        }
    }
    //cout_mat(dp);
    long long ans = 0;
    for(int i=0; i<max_; i++){
        ans+=(long long)i*dp[N][i];
        ans%=MOD;
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
  int h,n;
  cin>>h>>n;
  int sum=0;
  while(n--)
  {
    int a;
    cin>>a;
    sum+=a;
  }
  if(h>sum)
  {
    cout<<"No\n";
  }
  else
  {
    cout<<"Yes\n";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n;
string s;
string table[] = { "*****     ", "     *****", "==========",
" **** ****", "* **** ***", "** **** **", "*** **** *", "**** **** " };
bool f = 0;

int main(){
	while (cin >> s){
		if (f)cout << endl;
		reverse(ALL(s));
		REP(i, 4){
			if (s.size() >= 5)break;
			s += "0";
		}
		reverse(ALL(s));
		REP(i, 8){
			REP(j, s.size()){
				cout << table[i][s[j] - '0'];
			}
			cout << endl;
		}
		f = 1;
	}
}

Measured memory_bytes: 1184
using System;

class Program
{
    public static void Main(){
        int n=int.Parse(Console.ReadLine());
        string[] s=Console.ReadLine().Split(' ');
        int[] a=new int[n];
        for(int i=0; i<n; i++){
            a[i]=int.Parse(s[i]);
        }

        for(int i=1; i<n; i++){
            for(int k=0; k<n; k++){
                if(k>=n-1){
                    Console.WriteLine(a[k]);
                } else{
                    Console.Write(a[k]+" ");
                }
            }
            
            int key=a[i];
            int j=i-1;
            while(j>=0 && a[j]>key){
                a[j+1]=a[j];
                j--;
            }
            a[j+1]=key;

        }
        
        for(int k=0; k<n; k++){
            if(k>=n-1){
                Console.WriteLine(a[k]);
            } else{
                Console.Write(a[k]+" ");
            }
        }
    }
}

Measured memory_bytes: 9148
import sys
input = sys.stdin.readline
n = int(input())
c = []
for i in range(n):
  a = [int(i) for i in input().split()]
  c.append(a)

from operator import itemgetter
c = sorted(c,key=itemgetter(2),reverse=True)
p,q,r = c[0]
end = c[-1]
c = c[1:]
for i in range(101):
  for j in range(101):
    if r > 0:
      chk = abs(p-i)+abs(q-j)+r
    else:
      chk = 1
    for num,k in enumerate(c):
      x,y,h = k
      if h == 0:
        if abs(x-i)+abs(y-j) < chk:
          break
      else:
        if abs(x-i)+abs(y-j)+h != chk:
          break
      if k == end:
        ans = (i,j,chk)

print(*ans)

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

#define ll long long
 int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     
     int t,minimo=1000000;
     cin>>t;
     int v[t];
     for(int i=0;i<t;i++){
     	int num;
     	cin>>num;
     	v[i]=num;
     }
     
     for(int i=1;i<101;i++){
     	int ans=0;
     	for(int j=0;j<t;j++){
     		ans=ans+pow(v[j]-i,2);
     	}
     	minimo=min(ans,minimo);
     }
     cout<<minimo;
     
     return 0;
}

Measured memory_bytes: 256