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

int main(){
    int n;
    vector<long long> a;
    vector<long long> b;
    cin >> n;
    for (auto i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }

     for (auto i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        b.push_back(tmp);
    }

    long long pool = 0;
    long long cap = 0;

    for (auto i = 0; i < n; i++)
    {
        if(a[i] > b[i]){
            pool += a[i] - b[i];
        }else if(a[i] < b[i]){
            cap += (b[i] - a[i]) % 2 == 0 ? b[i] - a[i] : b[i] - a[i] - 1;
        }
    }

    pool *= 2;

    if(pool > cap){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    
}

Measured memory_bytes: 512
n,k = map(int,input().split())
t = [[0,0] for i in range(n)]
for i in range(n):
    a,b = map(int,input().split())
    t[i] = (a,b)
kk = 0
t = sorted(t, key=lambda t: t[0])

for i in range(n):
    kk += t[i][1]
    if kk >= k:
        print(t[i][0])
        break

Measured memory_bytes: 19572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, m, n) for(ll i = (ll)m; i < (ll)n; i++)
#define PER(i, m, n) for(ll i = (ll)m; i > (ll)n; i--)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    bool ok = true;

    if(a > b) ok = false;
    if(n == 1 && a != b) ok = false;

    if(ok) cout << (n - 2) * (b - a) + 1 << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define maxn (int)(1e5)
#define i64 long long
#define pii pair<i64,i64>
#define all(x) x.begin(),x.end()
#define LB(x,v) lower_bound(all(x), v) - x.begin()
#define fread() freopen("in.txt", "r", stdin);
using namespace std;
vector<i64>d;

void generate_divisors(i64 n){
    d.clear();
    for(i64 i=1;i*i<=n;i++){
        if(n%i==0){
            d.push_back(i);
            if(n/i != i) d.push_back(n/i);
        }
    }
}

i64 solve(i64 n){
    //generate_divisors(n);
    i64 sq = sqrt(n);
    i64 minVal = n-1;
    for(i64 i = sq; i > 0; i--){
        if(n%i==0){
            return ( (i-1) + (n/i -1)); 
            //distance from (1,1) to (i, n/i)
        }
    }
    return minVal;
}
int main() {
    /*BEFORE SUBMIT, CHECK
    sample i/o format
    statements for debugging are removed/comment out
    global values / stl containers are initialized/cleared for each test (if needed)
    all array size are sufficient
    loop variable or output value doesn't cross min/max limit of input
    // */
    
    i64 n;
    while(scanf("%lld",&n)==1){
        printf("%lld\n", solve(n));
    }    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int N;
    cin >> N;
    vl A(N);
    in(N,A);
    ll ans = 1;
    rep(i,N) if(A[i] == 0) {
        cout << 0 << endl;
        return 0;
    }
    
    ll aa = 1e18;
    rep(i,N) aa /= A[i];
    if(aa == 0) cout << -1 << endl;
    else{
        rep(i,N) ans *= A[i];
        cout << ans << endl;
    }
    

    return 0;
}


Measured memory_bytes: 3992
#!/usr/bin/env python3

n = int(input())
x = input()
b = [0] * (n+1)
for i in range(1, n+1):
    bit_count = 0
    for j in range(20):
        if i >> j & 1:
            bit_count += 1
    b[i] = bit_count

popcount = [0] * (n+1)
cnt = x.count('1')
for i in range(1, n+1):
    popcount[i] = popcount[i % b[i]] + 1

ans = []
if cnt == 1:
    tmp = 0
    for i in range(n):
        if x[i] == '1':
            tmp += pow(2, n-i-1, 2)
            tmp %= 2
    for i in range(n):
        if x[i] == '1':
            ans.append(0)
        else:
            ans.append(popcount[(tmp - pow(2, n-i-1, 2)) % 2] + 1)
else:
    tmp1 = 0
    tmp2 = 0
    for i in range(n):
        if x[i] == '1':
            tmp1 += pow(2, n-i-1, cnt + 1)
            tmp2 += pow(2, n-i-1, cnt - 1)
    for i in range(n):
        if x[i] == '1':
            ans.append(popcount[(tmp2 - pow(2, n-i-1, cnt - 1)) % (cnt - 1)] + 1)
        else:
            ans.append(popcount[(tmp1 + pow(2, n-i-1, cnt + 1)) % (cnt + 1)] + 1)

for i in ans:
    print(i)

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

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

    int N;
    cin >> N;
    vector<long long> A(N);

    for (auto &a : A)
        cin >> a;

    A.insert(A.begin(), 0);
    A.push_back(0);

    vector<long long> prefix(N + 5, 0);
    prefix[0] = 0;

    for (int i = 1; i <= N + 1; i++)
        prefix[i] = prefix[i - 1] + abs(A[i - 1] - A[i]);

    vector<long long> suffix(N + 5, 0);
    suffix[N + 1] = 0;

    for (int i = N; i >= 0; i--)
        suffix[i] = suffix[i + 1] + abs(A[i] - A[i + 1]);

    for (int i = 1; i <= N; i++) {
        long long sum = prefix[i - 1] + suffix[i + 1];
        sum += abs(A[i - 1] - A[i + 1]);
        cout << sum << '\n';
    }
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  using BS = bitset<64>;
  BS b(0);

  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int t,x=-1;
    cin>>t;
    if(t<4) cin>>x;
    if(t==0) cout<<b[x]<<endl;
    if(t==1) b.set(x);
    if(t==2) b.reset(x);
    if(t==3) b.flip(x);
    if(t==4) cout<<b.all()<<endl;
    if(t==5) cout<<b.any()<<endl;
    if(t==6) cout<<b.none()<<endl;
    if(t==7) cout<<b.count()<<endl;
    if(t==8) cout<<b.to_ullong()<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
 
using namespace std;
 
int main (){
  
  long long int a;
 
  
  
  cin >>a ;
  int i=0;
 for(;i*(i+1)<2*a;i++);
  int b = i*(i+1)/2-a;
  for(int j=1;j<=i;j++){
    if(j-b !=0)cout << j << endl;
    //三角数の総和から足りないあまりの数字を引く方が最小を作れる。//
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1,n,a,b,m=1e9+7;
    //cin>>t;
    cin>>n;
    vector<ll> ar(n+1),col(4,0);
    for(ll i=0;i<n;i++){
        cin>>ar[i];
    }
    ll ans=1;
    for(ll i=0;i<n;i++){
        ll cnt=0;
        for(ll j=0;j<3;j++){
            if(col[j]==ar[i])
                cnt++;
        }
        for(ll j=0;j<3;j++){
            if(col[j]==ar[i]){
                col[j]++;
                break;
            }
        }
        ans=(ans%m*cnt%m)%m;
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 1024
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
def two(x):
	s="0"*(n-len(bin(x))+2)
	return s+bin(x)[2:]
ans=set()
for i in range(2**n):
	p=0
	for j in range(n):
		if two(i)[j]=="1":
			p+=a[j]
	ans.add(p)
for i in range(m):
	if b[i] in ans:
		print("yes")
	else:
		print("no")




Measured memory_bytes: 5664
#include <bits/stdc++.h>
using namespace std;
int N, M;
int H[100000];
int HH[100000];
int A[100000];
int B[100000];
int cnt;

int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    A[i] -= 1;
    B[i] -= 1;
    if (H[A[i]] > H[B[i]]) HH[B[i]] = -1;
    else if (H[A[i]] < H[B[i]]) HH[A[i]] = -1;
    else if (H[A[i]] == H[B[i]]) {
      HH[A[i]] = -1;
      HH[B[i]] = -1;
    }
  }
  for (int i = 0; i < N; i++) {
    if (HH[i] != -1) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 5192
from math import gcd, sqrt
 
n = int(input())
A = [int(x) for x in input().split()]
 
g = A[0]
for a in A[1:]:
    g = gcd(g, a)
 
ans = set()
 
for i in range(1, int(sqrt(g)) + 1):
    if g % i == 0:
        ans.add(i)
        ans.add(g // i)
 
for a in sorted(ans):
    print(a)


Measured memory_bytes: 5672
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> s(h+2);
    string t;
    rep(i,w+2)t.push_back('#');
    s[0] = t;
    s[h+1] = t;
    rep(i,h){
        cin >> s[i+1];
        s[i+1] = "#"+s[i+1]+"#";
    }
    cerr << "test" << endl;
    int ma = 0;
    vector<vector<int> > dp(h+2,vector<int>(w+2));
    vector<vector<int> > dp2(h+2,vector<int>(w+2));
    vector<vector<int> > dp3(h+2,vector<int>(w+2));
    vector<vector<int> > dp4(h+2,vector<int>(w+2));
    rep(i,h+2){
        rep(j,w+2){
            if(s[i][j]=='.'){
                dp[i][j] = dp[i-1][j] + 1;
                dp2[i][j] = dp2[i][j-1] + 1;
            }
        }
    }
    for(int i=h+1;i>=0;i--){
        for(int j=w+1;j>=0;j--){
            if(s[i][j]=='.'){
                dp3[i][j] = dp3[i+1][j] + 1;
                dp4[i][j] = dp4[i][j+1] + 1;
            }
        }    
    }
    rep(i,h+2){
        rep(j,w+2){
            if(s[i][j]=='.'){
                
                ma=max(ma,dp[i][j]+dp2[i][j]+dp3[i][j]+dp4[i][j]-3);
                //cout << i << " " << j << " " << tmp << endl;
            }
        }
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 67200
#include <stdio.h>
#include <algorithm>

int main(void) {
  int i, n, x, ans = 0;
  scanf("%d%d", &n, &x);
  int a[n];
  for(i = 0; i < n; ++i) scanf("%d", &a[i]);
  std::sort(a, a + n);
  for(i = 0; i < n - 1; ++i) {
    if(a[i] <= x) ++ans, x -= a[i];
    else break;
  }
  if(a[n - 1] == x) ++ans;
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

bool is_acgt(char c){
	return (c == 'A' || c == 'C' || c == 'G' || c == 'T');
}

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

	int len = S.length();
	int ans = 0;
	for (int i = 0; i < len; i++){
		int counter = 0;
		for (int j = 0; j < len - i; j++){
			if(!is_acgt(S[i + j])){
				break;
			}
			counter++;
		}

		if(ans < counter){
			ans = counter;
		}
	}

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

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

using namespace std;

int n;
map<int, set<pair<int, int>>> edge;
vector<long long> cost;

void dfs(int k) {
  cost[k] = 0;
  queue<int> q;
  q.push(k);
  while (!q.empty()) {
    auto u = q.front();
    q.pop();
    for (auto vs: edge[u]) {
      int v = vs.first, l = vs.second;
      if (cost[v] != 1e18) {
        continue;
      }
      cost[v] = cost[u] + l;
      q.push(v);
    }
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int u, v, l;
    scanf("%d %d %d", &u, &v, &l);
    edge[u].insert(make_pair(v, l));
    edge[v].insert(make_pair(u, l));
  }
  int q, k;
  scanf("%d %d", &q, &k);
  cost = vector<long long>(n + 1, 1e18);
  dfs(k);
  for (int i = 0; i < q; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    long long ans = cost[x] + cost[y];
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 21376
a, b = map(int, input().split())
c = b - a
t = [1]
for i in range(1100):
    t.append(t[i]+i+2)
idx = 0
for i in range(1000):
    if t[i+1] - t[i] == c:
        idx = i + 1
        break

print(idx * (idx+1)//2-a)

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

li = [0 for i in range(N)]
ans = 1

for i in range(N):
    a = A[i]
    if a>0:
        ans *= min(3-li[a],li[a-1]-li[a])
        ans %= 10**9+7
        li[a] += 1
    elif a==0:
        ans *= 3-li[0]
        li[a] += 1
    # print(i,ans)

print(ans)

Measured memory_bytes: 13964
// E - Multiplication 4
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	int N, K; cin>>N>>K;
	vector<ll> P, M, A(N);
	rep(i, N){
		cin>>A[i];
		if(A[i] < 0) M.push_back(A[i]);
		else P.push_back(A[i]);
	}

	bool can_minus = true;
	if(P.size() > 0) can_minus = K<N? false: M.size()%2;
	else can_minus = K%2;

	ll ans = 1, mod = 1'000'000'007;

	if(can_minus){
		sort(A.begin(), A.end(), [](ll x, ll y){ return abs(x) < abs(y); });
	}

	else{
		A.clear();
		sort(P.begin(), P.end());
		sort(M.rbegin(), M.rend());
		if(K % 2){ ans = P.back(); P.pop_back(); }
		while(P.size() > 1){
			ll x = P.back(); P.pop_back();
			x *= P.back(); P.pop_back();
			A.push_back(x);
		}
		while(M.size() > 1){
			ll x = M.back(); M.pop_back();
			x *= M.back(); M.pop_back();
			A.push_back(x);
		}
		sort(A.rbegin(), A.rend());
	}

	if(!can_minus) K /= 2;
	rep(i, K) ans = (ans * (A[i] % mod)) % mod;
	cout<< (ans+mod)%mod <<endl;
}


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

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

void solve(){
    ll a,b,c;
    cin >> a >> b >> c;

    if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
        cout << 0 << endl;
        return;
    }


    ll m=LLONG_MAX;
    m = min(m, abs( (a/2)*b*c - (a-a/2)*b*c ));
    m = min(m, abs( a*(b/2)*c - a*(b-b/2)*c ));
    m = min(m, abs( a*b*(c/2) - a*b*(c-c/2) ));
    cout << m << endl;

    return;
}

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


Measured memory_bytes: 256
#include <stdio.h>
#define s 36

typedef struct{
	int value;
	char key;
} jinde;

jinde temp;

BubbleSort(jinde *B, int N)
{
	int flag=1, j;
	while(flag){
		flag=0;
		for(j=N-1; j>0; j--){
			if(B[j].value<B[j-1].value){
				temp=B[j];
				B[j]=B[j-1];
				B[j-1]=temp;
				flag=1;
			}
		}
	}
}

SelectionSort(jinde *S, int N)
{
	int i, j, min;
	for(i=0; i<N-1; i++){
		min=i;
		for(j=i+1; j<N; j++){
			if(S[min].value>S[j].value) min=j;
		}
		temp=S[i];
		S[i]=S[min];
		S[min]=temp;
	}
}

int main()
{
	int n, i, no=0;
	jinde B[s], S[s];
	
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf(" %c%d", &B[i].key, &B[i].value);
		S[i]=B[i];
	}
	
	BubbleSort(B, n);
	for(i=0; i<n; i++){
		if(i==n-1) printf("%c%d\nStable\n", B[i].key, B[i].value);
		else printf("%c%d ", B[i].key, B[i].value);
	}
	SelectionSort(S, n);
	for(i=0; i<n; i++){
		if(i==n-1) printf("%c%d\n", S[i].key, S[i].value);
		else printf("%c%d ", S[i].key, S[i].value);
		if(B[i].key!=S[i].key) no=1; //Bのローマ字と一致するか,しなければno=1
	}
	
	if(no) printf("Not stable\n"); //一致しなかったら(no=1なら)Not stable
	else printf("Stable\n");
	
	return 0;
}


Measured memory_bytes: 2088
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("fma,avx,avx2")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

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

    string s;
    cin >> s;
    string ans;
    for (auto &el : s) {
        if (el == 'P') ans += 'P';
        else ans += 'D';
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 3880
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;
 
//const int MOD=998244353;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n,t;
    cin>>n>>t;
    
    vector<pair<int,int>> vp(n);
    for(auto&p:vp){
        int a,b;
        cin>>a>>b;
        p={a,b};
    }
    
    auto f =[](auto p1, auto p2){return p1.first<p2.first || (p1.first==p2.first && p1.second>p2.second);};
    sort(vp.begin(),vp.end(), f);
    vector<vector<int>> dp(3000,vector<int>(6001));
    
    int ans=0;
    
    for(int i=0; i<n; i++){
        for(int j=vp[i].first; j<=vp[i].first+t-1; j++){
            if(!i) dp[i][j]=vp[i].second;
            else{
                dp[i][j]=dp[i-1][j-vp[i].first]+vp[i].second;
                //dp[i][j]=max(dp[i][j],dp[i-1][j]);
            }
            ans=max(ans,dp[i][j]);
        }
        if(i){
            for(int j=0; j<=vp[i].first+t-1; j++){
                dp[i][j]=max(dp[i][j],dp[i-1][j]);
            }
        }
    }
    //cout<<dp[1][110]<<'\n';
    
    cout<<ans;
    
    
    return 0;
}

Measured memory_bytes: 70784
#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 LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
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(){
    cin.tie(0);ios::sync_with_stdio(false);
    int l,r,d;
    cin>>l>>r>>d;
    int ans=0;
    for(int i=l;i<=r;i++){
        if(i%d==0)ans++;
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 3608
N=int(input())
A=[int(input()) for i in range(N)]
ans=0

for i in range(N):
    #print(str(i-1)+"  ",end="")
    #print(ans)
    if i==0:
        if A[i]!=0:
            ans=-1
            break
    else:
        if A[i-1]+1 > A[i]:
            ans+=A[i-1]
        elif A[i-1]+1==A[i]:
            continue
        else:#A[i-1]<A[i]:
            ans=-1
            break
else:
    ans+=A[i]
print(ans)


Measured memory_bytes: 11048
#104a
R = int(input())

#AtCode で次に開催されるコンテストは ABC と呼ばれ、レーティングが 1200未満の参加者のレーティングが変動します。
#その次に開催されるコンテストは ARC と呼ばれ、レーティングが 2800未満の参加者のレーティングが変動します。
#そのさらに次に開催されるコンテストは AGC と呼ばれ、すべての参加者のレーティングが変動します。

if R<1200:
    print("ABC")
elif R<2800:
    print("ARC")
else:
    print("AGC")

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

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

vector<int> G[60];
bool is_bridge[60];
bool visited[60];
P p[60];
int N, M;
void dfs(int n, int m){
  visited[n]=true;
  rep(i,G[n].size()){
    int next=G[n][i];
    if(visited[next]) continue;
    if(p[m]==P(n,next)||p[m]==P(next,n)) continue;
    dfs(next, m);
  }
}

int main(){
  cin >> N >> M;
  rep(i,M){
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    p[i]=P(a,b);
  }
  rep(i,M) is_bridge[i]=false;
  rep(i,M){
    rep(j,N) visited[j]=false;
    dfs(0,i);
    rep(j,N) if(!visited[j]) is_bridge[i]=true;
  }
  int ans=0;
  rep(i,M) ans+=is_bridge[i];
  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n" 
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll n,m,k,x1,x2,y1,y2,x,y,nx,ny;
  cin>>n>>m>>k;
  cin>>x1>>y1>>x2>>y2;
  string s[n+5];
  vector<vector<ll>> v(n+5,vector<ll> (m+5,-1));
  vector<vector<bool>> vis(n+5,vector<bool> (m+5,0));
  ll i=1;
  while(i<=n)
  {
    cin>>s[i];
    s[i]='!'+s[i];
    i++;
  }
  
  /*//memset(v,-1,sizeof(v));
  ll j;
  i=1;
  while(i<=n)
  {
    j=1;
    while(j<=m)
    {
      v[i][j]=-1;
      j++;
    }
    i++;
  }*/
  queue<pair<ll,ll>> q;
  q.push({x1,y1});
  v[x1][y1]=0;
  vis[x1][y1]=1;
  while(!q.empty())
  {
    x=q.front().ff;
    y=q.front().ss;
    q.pop();
    nx=x;
    i=k;
    while(i--)
    {
      nx--;
      if(nx<1||s[nx][y]=='@')
        break;
      if(v[nx][y]!=-1&&v[nx][y]<=v[x][y])
        break;
      v[nx][y]=v[x][y]+1;
      if(vis[nx][y]==0)
      {
        vis[nx][y]=1;
        q.push({nx,y}) ;
      }
    }
    nx=x;
    i=k;
    while(i--)
    {
      nx++;
      if(nx>n||s[nx][y]=='@')
        break;
      if(v[nx][y]!=-1&&v[nx][y]<=v[x][y])
        break;
      v[nx][y]=v[x][y]+1;
      if(vis[nx][y]==0)
      {
        vis[nx][y]=1;
        q.push({nx,y}) ;
      }
    }
    ny=y;
    i=k;
    while(i--)
    {
      ny--;
      if(ny<1||s[x][ny]=='@')
        break;
      if(v[x][ny]!=-1&&v[x][ny]<=v[x][y])
        break;
      v[x][ny]=v[x][y]+1;
      if(vis[x][ny]==0)
      {
        vis[x][ny]=1;
        q.push({x,ny}) ;
      }
    }
    ny=y;
    i=k;
    while(i--)
    {
      ny++;
      if(ny>m||s[x][ny]=='@')
        break;
      if(v[x][ny]!=-1&&v[x][ny]<=v[x][y])
        break;
      v[x][ny]=v[x][y]+1;
      if(vis[x][ny]==0)
      {
        vis[x][ny]=1;
        q.push({x,ny}) ;
      }
    }
  }
  deb(v[x2][y2])
}

Measured memory_bytes: 57800
#include<iostream>
#include<vector>

using namespace std;

int main(void){

    int n, t, a;
    int min = 1000000007, index = 0;

    cin >> n >> t >> a;

    t *= 1000;
    a *= 1000;

    vector<int> h(n), sub(n);

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

    for(int i = 0;i < n;i++){
        sub[i] = t - h[i] * 6;
        if(min > abs(sub[i] - a)){
            min = abs(sub[i] - a);
            index = i+1;
        }
    }

    cout << index << endl;

    return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    s = list(input())

    ans = 0
    now = 0
    for i, i_d in enumerate(s):
        if i_d == 'I':
            now += 1
            ans = max(ans, now)
        else:
            now -= 1

    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

void solve(ll N, vector<ll> H) {
  int ma{};
  int ans{};
  for(auto i=0; i!=N; ++i) {
    if (ma <= H[i]) {
      ma = H[i];
      ++ans;
    }
  }
  cout << ans << endl;
}

int main() {
  ll N;
  cin >> N;
  vector<ll> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  solve(N, move(H));
  return 0;
}


Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    read!(usize);
    let (S, T) = read!(String, String);

    let u = S
        .chars()
        .zip(T.chars())
        .flat_map(|(s, t)| vec![s, t])
        .collect::<String>();

    println!("{}", u)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 2e18;
const ll fact_table = 1200008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define endl "\n"
#ifdef ENJAPMA
    #undef endl
#endif
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
const ll mod = 998244353ll;
// const ll mod = 1000000007ll;
  
ll mypow(ll number1,ll number2, ll mod){
    if(number2 == 0){
        return 1ll;
    }else{
        ll number3 = mypow(number1,number2 / 2, mod);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5]; 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/

bool multicase = false;

ll n,m,num,a,b,c,d,e,h,q;
ll w, k;

void solve(){
    cin >> a >> b >> c >> d;
    while(true){
        c -= b;
        if(c <= 0){
            p("Yes");
            return;
        }
        a -= d;
        if(a <= 0){
            p("No");
            return;
        }
    }
    return;
}


int main(){
    // init();
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if(multicase){
        cin >> q;
    }else{
        q = 1; 
    }
    while(q--){
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    
    // solve();
    return 0;
}
















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

int main() {
    int a,b;
    cin>>a>>b;
    if (a==b) cout<<"Draw"<<endl;
    else if(a==1) cout<<"Alice"<<endl;
    else if(b==1) cout<<"Bob"<<endl;
    else if(a<b) cout<<"Bob"<<endl;
    else cout<<"Alice"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
using namespace std;
int main() {
	char s[100001];
	cin >> s;
	int x = strlen(s);
	while (x > 0) {
		if (strncmp("dream", s + x - 5, 5) == 0) {
			x -= 5;
			continue;
		}
		if (strncmp("dreamer", s + x - 7, 7) == 0) {
			x -= 7;
			continue;
		}
		if (strncmp("erase", s + x - 5, 5) == 0) {
			x -= 5;
			continue;
		}
		if (strncmp("eraser", s + x - 6, 6) == 0) {
			x -= 6;
			continue;
		}
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 384
import sys
readline = sys.stdin.readline

def main():
    N = int(readline())
    A = [int(readline()) - 1 for _ in range(N)]
    ans = 0
    pre = 0
    visited = set([0])
    while ans <= N:
        pre = A[pre]
        if pre in visited:
            print(-1)
            return
        visited.add(pre)
        ans += 1
        if pre == 1:
            print(ans)
            return
    
    print(-1)
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 13220
def ans(station,start):
    global c
    global s
    global f
    global n

    if(station==n-1):
        return start
    if(start<=s[station]):
        return ans(station+1,s[station]+c[station])
    else:
        if(start%f[station]==0):
            return ans(station+1,start+c[station])
        else:
            return ans(station+1,start + (f[station] - start%f[station]) + c[station])





n=int(input())

c=[0]*n
s=[0]*n
f=[0]*n
for i in range(n-1):
    c[i],s[i],f[i]=map(int,input().split())

for i in range(n):
    print(ans(i,0))

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 200100;
ll n, arr[maxn];

ll pref[maxn][2];
ll suff[maxn][2];

ll prefsum[maxn];

ll bruteforce() {
    ll diff = LLONG_MAX;
    for(int i=1;i<=n-3;i++) {
        for(int j=i+1;j<=n-2;j++) {
            for(int k=j+1;k<=n-1;k++) {
                ll a = prefsum[i];
                ll b = prefsum[j] - prefsum[i];
                ll c = prefsum[k] - prefsum[j];
                ll d = prefsum[n] - prefsum[k];

                ll maxv = max(max(a, b), max(c, d));
                ll minv = min(min(a, b), min(c, d));
                ll curr = maxv - minv;
                if(curr < diff) {
                    diff = curr;
                }
            }
        }
    }
    return diff;
}

ll checkprefdiff(int x, int y) {
    ll li = prefsum[x];
    ll ri = prefsum[y] - prefsum[x];
    ll diff = max(li, ri) - min(li, ri);
    return diff;
}

ll checksuffdiff(int x, int y) {
    ll ri = prefsum[n] - prefsum[y-1];
    ll li = prefsum[y-1] - prefsum[x-1];
    ll diff = max(li, ri) - min(li, ri);
    return diff;
}

int main() {
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>arr[i];
        prefsum[i] = prefsum[i-1] + arr[i];
    }

    ll splitpoint = 1;
    for(int i=2;i<=n;i++) {
        while(splitpoint + 1 < i && checkprefdiff(splitpoint, i) > checkprefdiff(splitpoint + 1, i)) splitpoint++;
        ll li = prefsum[splitpoint];
        ll ri = prefsum[i] - prefsum[splitpoint];
        if(ri < li) swap(li, ri);
        pref[i][0] = ri;
        pref[i][1] = li;
    }

    splitpoint = n;
    for(int i=n-1;i>=1;i--) {
        while(splitpoint - 1 > i &&  checksuffdiff(i, splitpoint) > checksuffdiff(i, splitpoint - 1)) splitpoint--;
        ll li = prefsum[splitpoint-1] - prefsum[i-1];
        ll ri = prefsum[n] - prefsum[splitpoint-1];
        if(ri < li) swap(li, ri);
        suff[i][0] = ri;
        suff[i][1] = li;
    }

    ll diff = LLONG_MAX;
    for(int i=3;i<=n-1;i++) {
        ll a = pref[i-1][0];
        ll b = pref[i-1][1];
        ll c = suff[i][0];
        ll d = suff[i][1];
        ll maxv = max(max(a,b), max(c,d));
        ll minv = min(min(a,b), min(c,d));
        diff = min(maxv - minv, diff);
    }

    cout<<diff<<"\n";

    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <vector>
#include <cstdlib>
#include <cstdio>

using namespace std;

struct edge{
};



int main(){

	int width;
	int height;
	int numOfQuery;

	cin >> height;
	cin >> width;
	cin >> numOfQuery;

	char planet[width][height];
	
	struct position{
		int x;
		int y;
	};

	struct land{
		int I;
		int O;
		int J;
		land& operator+(const land& rhs){
			this->I += rhs.I;
			this->O += rhs.O;
			this->J += rhs.J;
			return *this;
		}
		land& operator-(const land& rhs){
			land& r = *this;
			const land& l = rhs;
			r.I -= l.I;
			r.O -= l.O;
			r.J -= l.J;
			return *this;
		}

	};

	land* buf[width + 1];
	for( int i = 0; i < width + 1; i ++){
		buf[i] = new land[height + 1];
		for( int j = 0; j < height + 1; j ++){
			buf[i][j].I = 0;
			buf[i][j].J = 0;
			buf[i][j].O = 0;
		}
	}

	for ( int y = 0; y < height; y++){
		for( int x = 0; x < width; x++){
			cin >> planet[x][y];
		}
	}

	for ( int y = 1; y < height + 1; y++){
		for( int x = 1; x < width + 1; x++){
			land prevA = buf[x - 1][y - 1];
			land prevB = buf[x][y - 1];
			land prevC = buf[x - 1][y];
			land current = prevB + prevC - prevA;
			switch(planet[x - 1][y - 1]){
				case 'J' : current.J ++; break;
				case 'O' : current.O ++; break;
				case 'I' : current.I ++; break;
			}
			buf[x][y] = current;
		}
	}

	for(int i = 0; i < numOfQuery; i ++){

		position top_left;
		position bottom_right;

		cin >> top_left.y;
		cin >> top_left.x;
		cin >> bottom_right.y;
		cin >> bottom_right.x;

		land ans;

		ans.I = 0;
		ans.O = 0;
		ans.J = 0;

		top_left.x -= 1;
		top_left.y -= 1;
		
		land RectA = buf      [top_left.x]     [top_left.y];
		land RectB = buf      [top_left.x] [bottom_right.y];
		land RectC = buf  [bottom_right.x]     [top_left.y];
		land RectD = buf  [bottom_right.x] [bottom_right.y];

		ans = RectD + RectA - RectB - RectC;
 		cout << ans.J << ' ' << ans.O << ' ' << ans.I << endl;
	}
};

Measured memory_bytes: 13796
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second
#define double long double

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

const double pi = atan(1) * 4;

int A, B, H, M;

void read_input()
{
    cin >> A >> B >> H >> M;
}

void solve()
{
    double alpha = (double)M * 6.0;
    double beta = ((double)H / 12.0 + (double)M / 720.0) * 360.0;
    double mega;
    if((double)M / 60.0 >= (double)H / 12.0 + (double)M / 720.0)
        mega = alpha - beta;
    else
        mega = beta - alpha;
    cout << fixed << setprecision(12);
    cout << sqrt((double)A * A + (double)B * B - 2.0 * A * B * cos(mega * pi / 180.0)) << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



Measured memory_bytes: 4200
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <ll , ll>;
void in(ll &x);
const ll N = 16;
ll n;
ll value[1 << N];
vector < vector <ll> > grid, dp;

void precompute() {
  for (ll mask = 0 ; mask < (1 << n) ; mask++) {
    for (ll i = 0 ; i < n ; i++) {
      for (ll j = i + 1 ; j < n ; j++) {
        if ((mask & (1 << i)) && (mask & (1 << j))) {
          value[mask] += grid[i][j];
        }
      }
    }
  }
}

ll notMask(ll mask) {
  ll sol = 0;
  for (ll i = 0 ; i < n ; i++) {
    if (mask & (1 << i)) {

    } else {
      sol += (1 << i);
    }
  }
  return sol;
}

ll f(ll cur , ll mask) {
  if (__builtin_popcount(mask) == n) return 0;
  if (cur >= n) return 0;

  ll &sol = dp[cur][mask];
  if (sol != -1) return sol;

  sol = 0;
  ll others = notMask(mask);
  for (ll i = others ; i > 0 ; i = (i - 1) & others) {
    sol = max(sol , f(cur + 1 , mask | i) + value[i]);
  }

  return sol;
}

int main() {
  in(n);
  grid.resize(n + 1 , vector <ll> (n + 1 , 0));
  for (ll i = 0 ; i < n ; i++) {
    for (ll j = 0 ; j < n ; j++) {
      in(grid[i][j]);
    }
  }

  precompute();

  dp.resize(n + 1 , vector <ll> (1 << n , -1));
  printf("%lld\n" , f(0 , 0));
  return 0;
}

void in(ll &x){
	bool neg = false;
	register ll c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


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

using namespace std;
int n,m;
vector<vector<int>> g;
vector<int> dp;

int func(int idx) {
	if(idx>=n && idx<0)
		return INT_MIN;
	
	if(g[idx].size() == 0)
		return 0;

	if(dp[idx]!=-1)
		return dp[idx];
	

	int maxm = -1;
	for(int i=0; i<g[idx].size(); i++) {
		maxm = max(maxm, func(g[idx][i]) +1);
	}

	return dp[idx] = maxm;
}

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

	g.clear();
	g.resize(n+1);
	dp.resize(n+1,-1);

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

	int maxm = -1;
	for(int i=0; i<=n;i++) {
		if(dp[i]==-1) {
			func(i);
		}
		// cout<<dp[i]<<" ";
		maxm = max(dp[i], maxm);
	}
	// cout<<endl;
	cout<<maxm<<endl;
}

Measured memory_bytes: 10624
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
	int n, m;
	cin >> n >> m;
	int dp[100]= {};
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		dp[a]++;
		dp[b]++;
	}
	for (int i = 1; i <= n; i++) {
		cout << dp[i] << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)
const ll INF = 10010001010;
const int inf = 1000034000;
typedef vector<ll> vecl;
typedef vector<int> veci;
typedef tuple<string, int, int> TUP;

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

int main()
{
    int N;
    cin >> N;
    ll ans = 0;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N);
    for (int i = 0; i < N;i++)
    {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> B[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> C[i];
    }
    sort(all(A));
    sort(all(B));
    sort(all(C));
    for (int i = 0; i < N;i++)
    {
        auto itA = lower_bound(A.begin(),A.end(),B[i]);
        auto itC = upper_bound(C.begin(), C.end(),B[i]);
        ll a = itA - A.begin();
        ll b = C.end() - itC;
        //cout << a <<" " << b << endl;
        ans += a * b;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4560
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    int n, m, x;
    cin >> n >> m >> x;
    int ans = 1e9;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> c(n);

    rep(i, n){
        cin >> c[i];
        rep(j, m){
            cin >> a[i][j];
        }
    }

    for(int bit = 0; bit < (1 << n); bit++){
        vector<int> aa;
        int total = 0;
        for(int i = 0; i < n; i++){
            if(bit & (1 << i)){
                aa.push_back(i);
                total += c[i];
            }
        }

        vector<int> u(m, 0);

        for(int i = 0; i < aa.size(); i++){
            for(int j = 0; j < a[i].size(); j++){
                u[j] += a[aa[i]][j];
            }
        }
        bool ok = true;
        for(int i = 0; i < m; i++){
            if(u[i] < x){
                ok = false;
            }
        }
        if(ok){
            ans = min(ans, total);
        }
    }
    cout << (ans==1e9?-1:ans) << endl;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main(void){
    int n,min,max,answer;
    scanf("%d",&n);
    int w[n],ans[n-1];
    for(int i=0;n>i;++i)
    scanf("%d",&w[i]);

    for(int t=1;n>t;++t){
        min=0;max=0;
        for(int i=0;n>i;++i){
            if(i<=t)
            min+=w[i];
            else
            max+=w[i];
        }
        ans[t-1]=abs(max-min);
    }
    min=ans[0];
    for(int i=1;n-1>i;++i)
    min=min<=ans[i]?min:ans[i];
    printf("%d",min);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("outp.txt","w",stdout);
    #endif
    ll n;cin>>n;
    vector<ll> v(n+1);
    for(ll i=1;i<=n;i++)
        cin>>v[i];
    ll xo=v[1];
    for(ll i=2;i<=n;i++)
        xo=xo^v[i];
    for(ll i=1;i<=n;i++)
        cout<<(xo^v[i])<<" ";
}

    


Measured memory_bytes: 4748
//ThakurAnurag
//TemplateCode

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

#define ll long long int
#define ull unsigned long long int
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define fo2(i,a,n) for(ll i=n;i>=a;i--)
#define endl "\n"
#define sp " "
#define f first
#define s second
#define pb push_back
#define buffer ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod 1000000007
#define lower(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define upper(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
#define init(arr,val) memset(arr,val,sizeof(arr))
#define vecl(v) vector<ll> v
#define vecs(v) vector<string> v
#define vecp(v) vector < pair <ll,ll> > v

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

	ll arr[n];
	bool seive[1000001];
	init(seive,false);
	ll maxi = -1;
	map<ll, ll> myMap;
	fo(i,0,n){
		cin>>arr[i];
		maxi = max(maxi,arr[i]);
		myMap[arr[i]]++;
	}

	fo(i,0,n){
		ll j=2;
		while(arr[i]*j <= maxi){
			seive[arr[i]*j] = true;
			j++;
		}
	}

	ll ans=0;
	fo(i,0,n){
		if(myMap[arr[i]]==1 && !seive[arr[i]])
			ans++;
	}

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

Measured memory_bytes: 18612