akhauriyash/Code-Regression huggingface dataset:
n, a, b = map(int, input().split())
ans_nums = []

def isInBetween(i, a, b):
  if i >= a and b >= i:
    return True
  return False

for i in range(1,n+1):
  if i < 10:
    if isInBetween(i, a, b):
      ans_nums.append(i)      
  elif i >= 10 and i < 100:
    second_d = int(i/10)
    first_d = i-second_d*10
    if isInBetween(second_d + first_d, a, b):
      ans_nums.append(i)
  elif i >= 100 and i < 1000:
    third_d = int(i/100)
    second_d = int((i-third_d*100)/10)
    first_d = i-second_d*10-third_d*100
    total = third_d + second_d + first_d
    if isInBetween(total, a, b):
      ans_nums.append(i)
  elif i >= 1000 and i < 10000:
    fourth_d = int(i/1000)
    third_d = int((i-fourth_d*1000)/100)
    second_d = int((i-third_d*100-fourth_d*1000)/10)
    first_d = i-second_d*10-third_d*100-fourth_d*1000
    total = fourth_d + third_d + second_d + first_d
    if isInBetween(total, a, b):
      ans_nums.append(i)
  else:
    if isInBetween(1, a, b):
      ans_nums.append(i)

print(sum(ans_nums))
  


Measured memory_bytes: 3416
#include <bits/stdc++.h>
using namespace std;
const int N = 300010, M = 100010;
#define lowbit(x) ((x) & (-(x)))
int v[M],n,m,s,ans,p=1;
struct data {
  int l,r;
  bool operator < (const data& x) const {
    return r - l < x.r - x.l;
  }
} dat[N];
void add(int p,int val) {
  for (; p <= s ; p += lowbit(p))
    v[p] += val;
}
int query(int p) {
  int res = 0;
  for (; p ; p -= lowbit(p))
    res += v[p];
  return res;
}
int main() {
  scanf("%d%d",&n,&m);
  for (int i = 1 ; i <= n ; ++ i)
    scanf("%d%d",&dat[i].l,&dat[i].r);
  sort(dat+1,dat+n+1);
  s = m+1;
  for (int i = 1 ; i <= m ; ++ i) {
    while (dat[p].r - dat[p].l + 1 < i && p <= n) {
      add(dat[p].l+1,1);
      add(dat[p].r+2,-1);
      p ++;
    }
    ans = n - p + 1;
    for (int j = 0 ; j <= m ; j += i)
      ans += query(j+1);
    printf("%d\n",ans);
  }
  return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int a,p;
    cin >> a >> p;

    cout << (a *  3 + p) / 2 << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int count_dic(vector<int> R, int size_n, vector<int> base) {
    int keta = size_n;
    int count = 1;
    rep(i, size_n) {
        // 使用した数の削除
        // R[i]が今ありうる数の中でなんばん目か
        int diff;
        rep(j, keta) {
            if (base[j] == R[i]) {
                base.erase(base.begin()+j);
                diff = j+1;
            }
        }
        int kake = 1;
        repr(j, 1, keta) {
            kake *= j;
        }
        count += diff*(kake);
        keta -= 1;
    }
    return count;
}

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;
    vector<int> P(N), Q(N);
    vector<int> base(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];
    rep(i, N) {
        base[i] = i+1;
    }

    int ans = abs(count_dic(P, N, base) - count_dic(Q, N, base));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
X, N = [int(s) for s in input().split()]
if N == 0:
    print(X)
    exit()
P = [int(s) for s in input().split()]
Y = list(range(-10, 120))
for a in sorted(map(lambda x: (abs(x - X), x), Y), key=lambda x: [x[0], x[1]]):
    if not a[1] in P:
        print(a[1])
        exit()

print(X)

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

using namespace std;

int main()
{
  while(1)
  {
    int n, x;
    cin >> n >> x;
    if(n == 0&&x == 0)
    {
      exit(0);
    }
    int flag = 0;
    for(int i = 1;i <= n - 2;i++)
    {
      for(int j = i + 1;j <= n - 1;j++)
      {
        for(int k = j + 1;k <= n;k++)
        {
          if(i + j + k == x) flag++;
        }
      }
    }
    cout << flag << endl;
  }
}


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

int main() {
    int N;
    cin >> N;
    vector<int> boss_list(N);
    for (int i=1;i<N;i++) {
        cin >> boss_list.at(i);
    }

    map<int,int> list;
    for (int i=1;i<=N;i++) {
        list[i]=0;
    }

    for (int i=1;i<N;i++) {
        list[boss_list.at(i)]++;
    }

    for (int i=1;i<=N;i++) {
        cout << list.at(i) << endl;
    }
}

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

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

  int n, m; cin >> n >> m;
  priority_queue<pair<int, int>> pque;
  rep(i, n) {
    int a; cin >> a;
    pque.push({a, 1});
  }
  rep(i, m) {
    ll b, c; cin >> b >> c;
    pque.push({c, b});
  }

  ll ans = 0;
  rep(i, n) {
    auto p = pque.top();
    pque.pop();
    ans += p.first;

    if(p.second > 1) {
      p.second--;
      pque.push(p);
    }
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 2420
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;

bool isBad(char p, char q) {
    if (p == 'B' and q == 'B') {
        return true;
    }
    if (p == 'C' and q == 'C') {
        return true;
    }
    if (p == 'C' and q == 'B') {
        return true;
    }
    if (p == 'B' and q == 'A') {
        return true;
    }
    if (p == 'A' and q == 'C') {
        return true;
    }
    if (p == 'A' and q == 'C') {
        return true;
    }
    if (p == 'C' and q == 'A') {
        return true;
    }
    return false;
}

int main() {
    string s;

    cin >> s;
    int N = s.size();
    if (N < 3) {
        cout << 0 << endl;
    }
    else {
        vector<vector<int>> vec(N);
        int position = 0;
        for (int i = 0; i < N; i++) {
            if (i < N-1){
                if (s[i] == 'B' and s[i+1] == 'C') {
                    vec[position].push_back(1);
                    i++;
                }
                else if (s[i] == 'A') {
                    vec[position].push_back(0);
                }
                else if (isBad(s[i], s[i + 1])) {
                    position++;
                }
                else {
                    continue;
                }
            }
            else {
                if (s[i] == 'A') {
                    vec[position].push_back(0);
                }
            }
        }

        vec.resize(position + 1);

        ll cnt = 0;
        for (int j = 0; j < vec.size(); j++) {
            ll diff = 0;
            for (ll k = 0; k < vec[j].size(); k++) {
                if (vec[j][k] == 1) {
                    cnt += (k - diff);
                    diff++;
                }
            }
        }

        cout << cnt << endl;
    }
}

Measured memory_bytes: 6660
n, m = map(int, input().split())
cnt = {i: 0 for i in range(1, n+1)}
for _ in range(m):
    a, b = map(int, input().split())
    cnt[a] += 1
    cnt[b] += 1

if all(cnt[i] % 2 == 0 for i in range(1, n+1)):
    print('YES')
else:
    print('NO')

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

int main() {
  int a, b, x;
  cin >> a >> b >> x;
  
  double A = (double)a;
  double B = (double)b;
  double X = (double)x;
  
  double PI = 3.141592653589;
  
  if (A * A * B <= 2 * X) {
    double u = B / A;
    double v = X / (A * A * A);
  
    cout << fixed << setprecision(10);
  
    cout << atan(2 * (u - v)) * 180 / PI << endl;
  }
  
  if (A * A * B > 2 * x) {
    double w = A * B * B / (2 * X);
    
    cout << fixed << setprecision(10);
    
    cout << atan(w) * 180 / PI << endl;
  }
  
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

ll inv_mod(ll a, ll MOD)
{
    ll b = MOD, u = 1, v = 0;
    while(b){
        ll t = a/b;
        a -= t*b;   swap(a,b);
        u -= t*v;   swap(u,v);
    }
    u %= MOD;
    if(u < 0) u+= MOD;
    return u;
}

int main()
{
    ll i;
    ll n;
    cin >> n;
    const ll MOD = 1e9+7;
    vector<ll> x(n);
    rep(i,n) cin >> x[i];
    vector<ll> inv(n-1);
    rep(i,n-1){
        inv[i] = inv_mod(i+1, MOD);
    }
    ll tmp = 1;
    rep(i,n-1){
        tmp *= i+1;
        tmp %= MOD;
    }
    vector<ll> bun(n-1);
    rep(i,n-1) bun[i] = tmp*inv[i]%MOD;
    vector<ll> wa(n-1);
    wa[0] = bun[0];
    rep(i,n-2){
        wa[i + 1] = wa[i] + bun[i + 1];
        wa[i + 1] %= MOD;
    }
    ll ans = 0;
    rep(i,n-1){
        ans += (x[i+1] - x[i])*wa[i];
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6244
#include <bits/stdc++.h>
#define optimize ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long
#define ld long double
#define lint __int128
#define vi vector<int>
#define pb push_back
#define lp(i,a,b) for(int i = a ; i <= b ; i ++)
#define rlp(i,a,b) for(int i = b ; i >= a ; i --)
#define a_sort(v) sort(v.begin(), v.end())
#define d_sort(v) sort(v.rbegin(), v.rend())
#define pii pair<int,int>
#define pi 3.14159265358979323846264338327950
using namespace std ;
// #define debug

const int MOD = 1E9 + 7 ;
const int N = 1E5 ;

int main() {
    #ifdef debug
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif // debug
    optimize

    string s , t ; cin >> s >> t ;
    int mn = min(s.size(), t.size()) ;
    lp(i, 0, mn-1) {
        if(s[i] != t[i]) {
            cout << "No\n" ;
            return 0 ;
        }
    }
    cout << "Yes\n" ;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    for(int i = 0; i < S.size(); i++) {
        if(S.substr(i, 2) == "AC") {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  vector<long long> num(2); long long k; cin >> num[0] >> num[1] >> k;
  long long tmp = num[0]; num[0] -= min(num[0], k); k -= min(tmp, k); num[1] -= min(num[1], k);
  cout << num[0] << " " << num[1] << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin>>n;
	for(int i=1;i<=sqrt(n);i++) {
		if(n%i==0) {
			if(i<=9 && n/i<=9) {
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

ans = []
for h in range(H - 1):
    for w in range(W):
        if A[h][w] % 2 == 1:
            A[h][w] -= 1
            A[h + 1][w] += 1
            ans.append((h + 1, w + 1, h + 2, w + 1))
for w in range(W - 1):
    if A[H - 1][w] % 2 == 1:
        A[H - 1][w] -= 1
        A[H - 1][w + 1] += 1
        ans.append((H, w + 1, H, w + 2))

print(len(ans))
for a in ans:
    print(*a)


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

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <random>
#include <cmath>
#include <chrono>
#include <bitset>

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;
const int K = 500;
const int maxN = 2e4 + 1;


void solve() {
	string s, t;
	cin >> s >> t;
	vector<int> now(26, -1);
	vector<vector<int>> last(s.size(), vector<int>(26));
	for (int i = (int)s.size() - 1; i >= 0; i--) {
		last[i] = now;
		now[s[i] - 'a'] = i;
	}

	int id = -1;
	int ans = 0;
	for (int i = 0; i < t.size(); i++) {
		if (id == -1) {
			if (now[t[i] - 'a'] == -1) {
				cout << "-1\n";
				return;
			}
			id = now[t[i] - 'a'];
			ans += id + 1;
			continue;
		}
		if (last[id][t[i] - 'a'] == -1) {
			ans += s.size() - id - 1;
			ans += now[t[i] - 'a'] + 1;
			id = now[t[i] - 'a'];
			if (id == -1) {
				cout << "-1\n";
				return;
			}
		}
		else {
			if (last[id][t[i] - 'a'] == -1) ans += s.size() - id - 1;
			else ans += last[id][t[i] - 'a'] - id;
			id = last[id][t[i] - 'a'];
		}
	}
	cout << ans;
}


signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

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

using llong = long long;

// warrnig : The range of this class is from 0 to n-1
class UnionFindTree {
  public:
    //'rank[x]' is a rank of the union find tree the root of which is x.
    //'parents[x]' is the parent of x
    vector<int> rank, parents;

    // constructor
    UnionFindTree() {}
    UnionFindTree(int n) { // make n trees.
        rank.resize(n, 0);
        parents.resize(n, 0);
        for (int i = 0; i < n; i++) {
            makeSet(i);
        }
    }

    // make a union find tree
    void makeSet(int x) {
        parents[x] = x; // the parent of x is x
        rank[x] = 0;
    }

    // check whether the root of x is the same as that of y
    bool same(int x, int y) { return findSet(x) == findSet(y); }

    // unite two tree
    void unite(int x, int y) { link(findSet(x), findSet(y)); }
    void link(int x, int y) {
        if (rank[x] > rank[y]) {
            parents[y] = x;
        } else {
            parents[x] = y;
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
    }

    // travel the parents of tree recursivily to find root
    int findSet(int x) {
        if (x != parents[x]) {
            parents[x] = findSet(parents[x]); // change the x's parent to the root of tree.
        }
        return parents[x];
    }
};

int main() {
    int N;            // the number of nodes
    int Q;            // the number of query
    vector<int> P;    // p is a "same" or "unite" command.
    vector<int> A, B; // a and b are nodes.

    cin >> N >> Q;
    UnionFindTree uft = UnionFindTree(N); // make trees

    for (int i = 0; i < N; i++) {
        int p;
        cin >> p;
        p--;
        P.push_back(p);
    }

    for (int i = 0; i < Q; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        A.push_back(a);
        B.push_back(b);
    }

    for (int i = 0; i < Q; i++) {
        uft.unite(A[i], B[i]);
    }
    int sum = 0;
    for (int i = 0; i < N; i++) {
        if (uft.same(i, P[i])) {
            sum++;
        }
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 2680
n,h = gets.chomp.split.map(&:to_i)
a, b = [], []
n.times do |i|
    a[i], b[i] = gets.chomp.split.map(&:to_i)
end
a.sort!

bb = b.select{|i| i > a[-1]}.sort.reverse

ans = 0
bb.each do |v|
    h -= v
    ans += 1
    if h <= 0
        puts ans
        exit
    end
end

ans += (h.to_f / a[-1]).ceil
puts ans

Measured memory_bytes: 5860
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.AbstractMap.SimpleEntry;

class Main {

    static final int modnum = 1000000000 + 7;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        ArrayList<Integer> city = new ArrayList<Integer>();
        ArrayList<Integer> hunter = new ArrayList<Integer>();
        for (int i = 0; i <= N; i++) {
            city.add(sc.nextInt());
        }
        for (int i = 0; i < N; i++) {
            hunter.add(sc.nextInt());
        }

        long cnt = 0;
        for (int i = 0; i < N; i++) {
            int cap = hunter.get(i);
            int tag1 = city.get(i);
            int tag2 = city.get(i + 1);

            if (tag1 < cap) {
                cap -= tag1;
                cnt += tag1;
                tag1 = 0;
            } else {
                tag1 -= cap;
                cnt += cap;
                cap = 0;
            }

            if (tag2 < cap) {
                cap -= tag2;
                cnt += tag2;
                tag2 = 0;
            } else {
                tag2 -= cap;
                cnt += cap;
                cap = 0;
            }

            city.set(i, tag1);
            city.set(i + 1, tag2);
        }

        // System.out.println(city.toString());
        // System.out.println(hunter.toString());
        System.out.println(cnt);
    }
}

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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll n,a,ans,cnt=1;
	cin>>n;
	forn(i,n){
		cin>>a;
		if(a==cnt)cnt++;
	}
	(cnt==1)?ans=-1:ans = n-cnt+1;
	cout<<ans<<"\n";
	return 0;
}


// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long

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

    double n,d,x,y;
    cin >> n >> d;
    int res = 0;
    while(n--) {
        cin >> x >> y;
        double dist = sqrt(x*x+y*y);
        if(dist<=d) res++;
    }
    cout << res;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> vec(n);

    for (int i=0; i<m; i++) {
        int a, b;
        cin >> a >> b;
        vec.at(a-1)++;
        vec.at(b-1)++;
    }

    for (int i=0; i<vec.size(); i++) {
        cout << vec.at(i) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long 
#define float long double 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 

signed main(){
	IOS;
	int n , w , v = 0; 
	cin >> n >> w ; 
	int weight[n] ;
        int value[n] ;
	for(int i=0;i<n;i++){
		cin >> weight[i] >> value[i] ;
		v+= value[i];
	}
	vector<int>dp(v+1,INT_MAX);
	dp[0] = 0;
	for(int i=0;i<n;i++){
		for(int j = v - value[i] ; j >= 0 ; j-- ){
			dp[j+value[i]] = min(dp[j]+weight[i],dp[j+value[i]]);
		}
	}
	debug() << imie(range(weight,weight+n)) imie(range(value,value+n)) ;
	debug() << imie(range(dp.begin(),dp.end()));
	int ans = 0 ;
	for(int i=0;i<=v;i++){
		if(dp[i] <= w) ans = max(ans,i);
	}
	cout << ans << endl ;
	return 0;
}


Measured memory_bytes: 1024
x=list(map(int,input().split()))
flg=0
a=[[] for i in range(x[0])]
for i in range(x[1]):
    y=list(map(int,input().split()))
    a[y[0]].append(y[1])
for i in range(1,x[0]):
    a[i].sort(reverse=True)
for i in range(len(a[1])):
    if len(a[a[1][i]]) > 0 and a[a[1][i]][0]==x[0]:
        flg=1
        break
if flg==1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 33840
#include<iostream> 
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath> 
#include<algorithm> 
using namespace std;
const int maxn=500010,inf=1e9;
int n;
char s[maxn];
inline void read(int &k)
{
	int f=1;k=0;char c=getchar();
	while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar();
	k*=f;
}
int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<n;i++)
	if(s[i]=='A'&&s[i+1]=='C')return puts("Yes"),0;
	puts("No");
}

Measured memory_bytes: 256
def main():
  n,m = map(int, input().split())
  
  point = sorted(list(map(int, input().split())), reverse=True)
  border = sum(point) / (4*m)
  
  result = 'Yes'
  for i in range(m):
    if point[i] < border:
      result = 'No'
      break
 
  return result

print(main())

Measured memory_bytes: 3060
import math


def get_input():
    input_data = input().split()
    return input_data

def get_max_num(before_tax, after_tax, before_sum):
    max_num = 0
    length = (before_sum // 2) + 2
    for num_1 in range(1, length):
        num_2 = before_sum - num_1
        num_1 = math.floor(((num_1+1) / before_tax) * 100)
        num_2 = math.floor(((num_2+1) / before_tax) * 100)
        if math.floor((num_1 * before_tax) / 100) + math.floor((num_2 * before_tax) / 100) == before_sum:
            tmp_num = math.floor(num_1 * after_tax / 100) + math.floor(num_2 * after_tax / 100)
            if tmp_num >= max_num:
                max_num = tmp_num
    return max_num






if __name__ == "__main__":
    while True:
        input_data = get_input()
        if input_data[0] == "0":
            break
        before_tax = (100 + int(input_data[0]))
        after_tax = (100 + int(input_data[1]))
        before_sum = int(input_data[2])
        max_num = get_max_num(before_tax, after_tax, before_sum)
        print(max_num)




Measured memory_bytes: 5676
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int n;

bool f(vector<vector<int>> v, vector<int> r){
    map<int,int> mp[3];
    rep(j,3){
        map<int,int> &mpp = mp[j];
        vector<int> tmp;
        rep(i,n){
            tmp.pb(v[i][j]);
        }
        sort(all(tmp));
        
        rep(i,tmp.size()){
            mpp[tmp[i]] = r[i];
        }
    }
    
    vector<pii> s;
    rep(i,n){
        int tmp = 0;
        rep(j,3){
            tmp+=mp[j][v[i][j]];
        }
        s.pb(pii(-tmp,i));
    }
    
    sort(all(s));
    
    int pos=-1;
    rep(i,s.size()){
        if(s[i].second==0){
            pos = i;
            break;
        }
    }
    assert(pos!=-1);
    if(pos<8)return true;
    else return false;
}

int main(){
    cin>>n;
    vector<int> r(n);
    rep(i,n)cin>>r[i];
    reverse(all(r));
    
    vector< vector<int> > v(n,vector<int>(3));
    rep(i,n)rep(j,3)cin>>v[i][j];
    
    int ans = INF;
    rep(i,101){
        rep(j,3){
            v[0][j]+=i;
            
            if(f(v,r)){
                ans = min(ans,(int)i);
            }
            
            v[0][j]-=i;
        }
    }
    if(ans==INF)cout<<"Saiko"<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 3180
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{

// }}}


signed main()
{
    string s; cin >> s;

    int cntT = 0;

    int removed = 0;

    for (int i = s.length()-1; i >= 0; --i) {
        char c = s[i];
        if (c == 'S') {
            if (cntT > 0) removed += 2, --cntT;
        } else {
            ++cntT;
        }
    }

    cout << s.length() - removed << endl;
    return 0;
}


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

lint n, k;
vector<lint> a;

// m以下の積がk個以上あるかどうか
bool check(lint m) {
    lint ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            if (m >= 0) {
                ans += n - 1;
            }
        } else if (a[i] > 0) {
            lint pair = m / a[i];
            if (m < 0 && m % a[i] != 0) {
                pair--;
            }
            ans += upper_bound(a.begin(), a.end(), pair) - a.begin();
            if (a[i] * a[i] <= m) {
                ans--;
            }
        } else {
            lint pair = m / a[i];
            if (m < 0 && m % a[i] != 0) {
                pair++;
            }
            ans += a.end() - lower_bound(a.begin(), a.end(), pair);
            if (a[i] * a[i] <= m) {
                ans--;
            }
        }
    }
    ans /= 2;
    return ans >= k;
}

int main() {
    cin >> n >> k;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    lint ok = LLONG_MAX / 2, no = LLONG_MIN / 2;
    while (abs(ok - no) > 1) {
        lint mid = (ok + no) / 2;
        if (ok + no < 0 && (ok + no) % 2 != 0) {
            mid--;
        }
        // cout << mid << " " << check(mid) << endl;
        if (check(mid)) {
            ok = mid;
        } else {
            no = mid;
        }
    }
    cout << ok << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
using namespace std;
using ll=long long;

int main(){
    int n,k
    ; cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];

    ll sum=accumulate(a.begin(),a.end(),0LL);


    vector<ll> divs;
    for(ll i=1;i*i<=sum;i++){
        if(sum%i==0){
            divs.push_back(i);
            divs.push_back(sum/i);
        }
    }

    ll res=1;

    for(auto x:divs){
        vector<int> piyo(n);
        for(int i=0;i<n;i++){
            piyo[i]=(a[i]%x);
        }
        sort(piyo.begin(),piyo.end());
        ll cnt=0;
        int lef=0;
        int rig=n-1;
        while(lef<rig){
            int lrem=piyo[lef];
            int rrem=x-piyo[rig];
            if(lrem<rrem){
                cnt+=lrem;
                piyo[lef]-=lrem;
                piyo[rig]+=lrem;
                lef++;
            }
            else{
                cnt+=rrem;
                piyo[lef]-=rrem;
                piyo[rig]+=rrem;
                rig--;
            }
        }
        if(cnt<=k) res=max(res,x);
    }
    cout<<res<<endl;
    return 0;
}


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

int main()
{
    int n;
    int sum = 0;
    int cnt = 0;
    cin >> n;
    for (int i=0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        if (cnt < 3) {
            if (a == b){
                cnt += 1;
            } else {
                cnt = 0;
            }
        }
    }
    if (cnt >= 3) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}


Measured memory_bytes: 3596
using System;
using System.Linq;

public class Hello{
    public static void Main(){
        // Your code here!
        
        var c = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        int a = c[0];
        int b = c[1];
        
        int[] enzan = new int[3]{a+b,a-b,a*b};
        
        Array.Sort(enzan);
        Console.WriteLine(enzan[2]);
        
    }
}


Measured memory_bytes: 13396
loop do
  n = gets.to_i
  break if n == 0

  arr = []
  n.times { arr << gets.to_i }

  count = 0
  0.upto(n-1) do |i|
    0.upto(n-2-i) do |j|
      if arr[j] > arr[j+1]
        arr[j], arr[j+1] = arr[j+1], arr[j]
        count += 1
      end
    end
  end

  puts count
end

Measured memory_bytes: 8632
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

ans = collections.deque(ns())
q = ni()
now = 0
for i in range(q):
    query = ns().split(' ')
    if query[0] == '1':
        now = 1 - now
    else:
        f, c = query[1], query[2]
        if f == '1':
            if now == 1:
                ans.append(c)
            else:
                ans.appendleft(c)
        else:
            if now != 1:
                ans.append(c)
            else:
                ans.appendleft(c)

if now == 1:
    for i in range(len(ans)):
        print(ans[-(i+1)], end="")
else:
    for i in range(len(ans)):
        print(ans[i], end="")
print()

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

using namespace std;

// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);

void solve()
{
    int k;
    cin >> k;
    int x = 7 % k;
    int it = 1;
    vector<char> seen(k, 0);
    while (it < 1e6 && x != 0)
    {
        it++;
        x = ((x%k) * (10%k)) % k;
        x = (x + 7%k)%k;
        if(seen[x]) break;
        seen[x] = 1;

    }
    if (x == 0)
        cout << it << '\n';
    else
        cout << -1 << '\n';
}

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

    int nCases = 1;
    // cin >> nCases;

    while(nCases--)
        solve();

    return 0;
}


Measured memory_bytes: 4244
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int X = l[0], t = l[1];

            Console.WriteLine(Math.Max((X - t), 0));
        }
    }
}


Measured memory_bytes: 13396
#include<stdio.h>

int a[45];
int fib(int n)
{
  if(n == 0 || n == 1)
    {
      a[n] = 1;
    }
  if(a[n] != -1)
    {
      return a[n];
    }
  return a[n] = fib(n - 1) + fib(n - 2);
}

int main()
{
  int n, i;
  for(i = 0; i < 45; i++)
    {
      a[i] = -1;
    }
  scanf("%d", &n);
  printf("%d\n", fib(n));
  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;
ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}
ll LCM(ll x, ll y) { 
  return x / GCD(x, y) * y;
}

int main(){
  int n; cin >> n;
  vector<int> a(n), b(n), c(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n-1) cin >> c[i];
  int ans = 0;
  rep(i, n) {
    ans += b[a[i]-1];
  }
  rep(i, n-1) {
    if(a[i] + 1 == a[i+1]) ans += c[a[i]-1];
  }

  cout << ans << endl;
}


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

#ifdef DEBUG
#define debug(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == 0) {
        v.clear();
        return 0;
    }
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}

bool solve(int N, vi& a) {
    sort(ALL(a));
    int sm =accumulate(a.begin(), a.end()-1, 0);
    return (sm > a.back());
}

int main() {
    vi a;
    int N = loadvec(a);
    cout << (solve(N,a) ? "Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 256
import collections

n = int(input())
s = []
for i in range(n):
    s.append(input())


def same_word_check(s):
    c = collections.Counter(s)
    l = sorted(list(c.values()), reverse=True)
    if l[0] >= 2:
        print('No')
        exit()


def shiritori_rule(s):
    for i in range(len(s)-1):
        if s[i][-1] != s[i+1][0]:
            print('No')
            exit()

same_word_check(s)
shiritori_rule(s)
print('Yes')

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

struct Edge {
  int id, a, b;

  bool operator < (const Edge e) const {
    if (a == e.a) return b < e.b;
    else return a < e.a;
  }
};

int main() {
  int n;
  cin >> n;
  vector<Edge> e(n - 1);
  vector<int> dig(n, 0);
  int a, b;
  rep(i, n - 1) {
    e[i].id = i;
    cin >> a >> b;
    a--;
    b--;
    e[i].a = a, e[i].b = b;
    dig[a]++;
    dig[b]++;
  }

  int k = 0;
  rep(i, n) {
    k = max(k, dig[i]);
  }
  cout << k << endl;

  sort(e.begin(), e.end());
  vector<int> ans(n - 1);
  vector<int> color(n, 1);
  rep(i, n - 1) {
    ans[e[i].id] = color[e[i].a];
    color[e[i].a]++;
    if (color[e[i].a] > k) color[e[i].a] = 1;
    color[e[i].b] = color[e[i].a];
  }
  rep(i, n - 1) cout << ans[i] << endl;



  
  return 0;
}

Measured memory_bytes: 2816
<?php
$string_tmp = array();
// 回答保存用
$ans_set = array();
// 入力受付処理
while ($line = fgets(STDIN)) {
   $tmp[] = trim($line);
}
// INIT処理
$max_lenge = 8;
foreach($tmp as $val){
    // データセットをデクリメント
    $max_lenge--;
    // 1があるかどうかを確認
    if(preg_match('/1/',$val)){
        $string_tmp[] = $val;
    }// 一つデータセットを見終わった時の処理
     // 見つかった行数によって図形を判別
    if($max_lenge < 0){
        $ans_set[] = judge($string_tmp);
        // INIT 処理
        $string_tmp = array();
        $max_lenge = 8;
    }
}
$ans_set[] = judge($string_tmp);
foreach($ans_set as $val){
    echo $val."\n";
}
function judge($string_tmp){
    $ans;
    $tmp_length = count($string_tmp);
        if($tmp_length == 4){
            $ans = "B";
        }elseif($tmp_length == 1){
            $ans = "C";
        }elseif($tmp_length == 2){
            $ans = judge_line2($string_tmp);
        }elseif($tmp_length == 3){
            $ans = judge_line3($string_tmp);
        }
    return $ans;
}
// ラインが二列だった時の図形判別用
function judge_line2($string_tmp){
    $pos = strpos($string_tmp[0], "1");
    $pos2 = strpos($string_tmp[1], "1");
    if($pos == $pos2){
        return "A";
    }elseif ($pos < $pos2) {
        return "E";
    }else{
        return "G";
    }
}// ラインが三列だった時の図形判別用    
function judge_line3($string_tmp){
    $pos = strpos($string_tmp[0], "1");
    $pos2 = strpos($string_tmp[1], "1");
    if($pos > $pos2){
        return "D";
    }else{
        return "F";
    }
}


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

Measured memory_bytes: 1280
#include<iostream>
#include <string.h>
#include <algorithm>
typedef long long ll;
using namespace std;

int main(){
    ll n,max=0,ans=0,h;
    cin >> n;
    for(int i = 0; i<n; i++){
       cin >> h;
       if(h>=max){
          ans++;
          max=h;
      }
}
cout << ans << endl;


    

    return 0;

}


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

int main(){

    int N, K;
    cin >> N >> K;
    vector<int> check(N);
    rep (i, K){
        int d;
        cin >> d;
        rep (j, d){
            int A;
            cin >> A; 
            check[A-1] = 1;
        }
    }

    int ans = 0;
    for (int ele:check){
        if (ele == 0) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        aa: [i64;n]
    }
    let mut neg = 0;
    let aa = aa.iter().map(|a| {
        if *a < 0 {
            neg += 1;
            a * -1
        } else {
            *a
        }
    }).collect::<Vec<_>>();
    let sum = aa.iter().sum::<i64>();
    if neg % 2 == 0 {
        println!("{}", sum);
    } else {
        println!("{}", sum - (aa.iter().min().unwrap() * 2));
    }
}


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


int main()
{
	int a,b,x=0,c,t1,t2;
	cin>>a>>b>>c;
while(a%2==0 && b%2==0 && c%2==0)
{if(a==b && b==c && a==c)
{
	x=-1;
	break;
}
	t1=a;
	t2=b;
	a=c/2+b/2;
	b=t1/2+c/2;
	c=t1/2+t2/2;
	x++;
}

cout<<x<<endl;


return 0;
}

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

int main(){
    int n;
    char buf[30];

    //標準入力から1行bufに格納
    fgets(buf, sizeof(buf), stdin);
    n = atoi(buf);

    n = n + n*n + n*n*n;

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

    return 0;   
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    cout<<3*n*n<<"\n";
}


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

#define int         long long
#define pb          push_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 all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int expo(int base,int exponent,int mod){
    int ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
int n,k,a[100005],ans;
void solve(){
  cin>>n>>k;
  for(int i=k;i>=1;i--){
    a[i]=k/i;
    a[i]=expo(a[i],n,hell);
    for(int j=2*i;j<=k;j+=i){
      a[i]=(a[i]-a[j]+hell)%hell;
    }
    ans=(ans+a[i]*i)%hell;
  }
  cout<<ans<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4388
import sys

n, y = map(int, input().split())
for i in range(n+1):
  for j in range(n-i+1):
    k = n - i - j
    money = 10000 * i + 5000 * j + 1000 * k
    if y == money:
      print("{} {} {}".format(i, j, k))
      sys.exit()
print(-1, -1, -1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define f first
#define s second
typedef pair<int,int> P;
int n,m,r,i,j,a,b,c,x,y;
int sum[100000],flg[100000];
vector<int>  om[100000],hc[100000];
int main(void)
{
	P p;
	priority_queue<P,vector<P>,greater<P> > qu;
	
	cin>>n>>m>>r;
	for(i=0;i<n;i++) sum[i]=M,flg[i]=0;
	for(i=0;i<m;i++){
		cin>>a>>b>>c;
		hc[a].push_back(b);
		om[a].push_back(c);
	}
	qu.push(P(0,r));
	sum[r]=0;
	while(qu.size()!=0){
		p=qu.top();
		qu.pop();
		if(flg[p.s]==0){
			flg[p.s]=1;
			for(i=0;i<om[p.s].size();i++){
				x=hc[p.s][i];
				y=om[p.s][i];
				if(sum[x]>p.f+y){
					sum[x]=p.f+y;
					qu.push(P(sum[x],x));
				}
			}
		}
	}
	for(i=0;i<n;i++) {
		if(sum[i]!=M) cout<<sum[i]<<endl;
		else cout<<"INF"<<endl;
	}
	return 0;
}


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

#define INF 1e9
using namespace std;

int main() {

    int N; cin >> N;

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

    vector<int> s(N);
    s = p;
    sort(s.begin(), s.end());

    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        if (p[i] != s[i]) {
            ++cnt;
        }
    }

    if (cnt == 0 || cnt == 2) {
        puts("YES");
    } else {
        puts("NO");
    }
}

Measured memory_bytes: 256