akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
int v[1000000];
ll vsum(vector<ll>a){
  ll r = 0;
  rep(i,a.size()){
    if(a[i] < 0)r += (a[i] * -1);
    else r += a[i];
  }
  return r;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  int n;
  cin >> n;
  vector<ll>v(n);
  rep(i,n)cin >> v[i];
  int count = 0;
  rep(i,n){
    if(v[i] < 0)count++;
  }
  rep(i,n){
    if(v[i] < 0)v[i] *= -1;
  }
  
  if(count % 2 == 0){
    cout << vsum(v) << endl;
  }
  else{
    sort(v.begin(),v.end());
    ll ans = v[0];
    ll tmp = 0;
    REP(i,1,n){
      tmp += v[i];
    }
    cout << tmp - ans << endl;
  }
  return 0;
} 

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

#ifdef ONLINE_JUDGE
#define endl "\n"
#endif
using namespace std;
typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
const ll MOD = 1e9 + 7;
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define yesno(f) \
    if (f)       \
        yes else no;
#define noo \
    { no return; }
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define sz(x) (ll) x.size()
#define sq(x) ((x) * (x))

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<typename T = ll>
vector<T> ga(ll n, bool oneIndexed = false) {
    vector<T> a = vector<T>(n + oneIndexed);

    for (ll i = 0; i < n; i++) {
        T p;
        cin >> p;
        a[i + oneIndexed] = p;
    }

    return move(a);
}

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

    v p = ga(a);
    v q = ga(b);
    v r = ga(c);
    sort(rall(p));
    sort(rall(q));
    sort(rall(r));

    ll sum = 0;
    ll i = 0, j = 0, k = 0;
    ll total = 0;

    while (total < x + y) {
        ll usa = i < x ? p[i] : -1;
        ll usb = j < y ? q[j] : -1;
        ll usc = k < c ? r[k] : -1;

        if (usa >= max(usc, usb)) {
            sum += usa;
            i++;
        } else if (usb >= max(usc, usa)) {
            sum += usb;
            j++;
        } else {
            sum += usc;
            k++;
        }
        total++;
    }
    cout << sum << endl;
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // ll t;cin >> t;while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 2560
<?php
# 数値の入力
fscanf(STDIN, "%d", $data1);
$anser = 0;
if($data1<10){
    $anser = $data1;
}elseif($data1<100){
    $anser = 9;
}elseif($data1<1000){
    $anser = 9+$data1-99;
}elseif($data1<10000){
    $anser = 9+900;
}elseif($data1<100000){
    $anser = 9+900+$data1-9999;
}else{
    $anser = 9+900+90000;
}
echo $anser."\n";
?>

Measured memory_bytes: 3576
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<list>
//#include<unordered_map>
using namespace std;
#define ll long long 
#define dd cout<<endl
#define lll __int128
const int mod=1e9+7;
const int inf=1e9+7;

//const int maxn=

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	string a,b;
	
	while(cin>>a>>b)
	{
		int cnt=0;
		for(int i=0;i<a.size();i++)
			if(a[i]==b[i])
				cnt++;
		cout<<cnt<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import numpy as np
n,m = map(int, input().split())
arr = np.zeros(m)
for i in range(n):
    ka = np.array([int(i) for i in input().split()])
    for j in range(ka[0]):
        arr[ka[j+1]-1] += 1
ans = (arr == n).sum()
print(ans)

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

int main()
{
	int r, c;
	cin.tie(0);
	cin >> r >> c;

	int s[100][100] = { 0 };
	for (int i = 0; i < r; i++)
		for (int j = 0; j < c; j++)
			cin >> s[i][j];

	int sum[100] = { 0 };
	int rs, cs;
	for (int i = 0; i < r; i++) {
		rs = 0;
		int j;
		for (j = 0; j < c; j++) {
			rs += s[i][j];
			sum[j] += s[i][j];
			cout << s[i][j] << " ";
		}
		sum[j] += rs;
		cout << rs << "\n";
	}

	for (int j = 0; j < c + 1; j++) {
		if (j > 0) cout << " ";
		cout << sum[j];
	}
	cout << "\n";
}



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


int main() {
	int N, M;
	cin >> N >> M;

	vector<int> X(M);
	for(auto& e : X) {
		cin >> e;
	}

	if(M <= N) {
		cout << 0 << endl;
		return 0;
	}

	sort(X.begin(), X.end());
	vector<int> diff(M - 1);
	for(int i=0;i+1<M;i++) {
		diff[i] = X[i + 1] - X[i];
	}
	sort(diff.begin(), diff.end());

	ll ans = 0;
	for(int i=0;i + N < M;i++) {
		ans += diff[i];
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
import Data.List.Split
import Data.Maybe
import qualified Data.ByteString.Char8 as B
main=mapM_(putStrLn.solve).chunksOf 2.map(map(fst.fromJust.B.readInt).B.words).B.lines=<<B.getContents
solve[[n,k],as]=if k<=maximum as && 0==k`mod`foldr1 gcd as then "POSSIBLE" else "IMPOSSIBLE"

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

int main(){
int N,A;
cin>>N>>A;
for(int i=500;i<=N;i+=0){
N-=500;
}
if(A<N){
  cout<<"No"<<endl;
}
  else{
    cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n, x;
    scanf("%ld%ld", &n, &x);
    
    vector<ll> a(n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%lld", &a[i]);
    }

    ll sum=0;
    for(i=0; i<n; i++) {
        ll tmp = MAX(a[i]-x, 0);
        a[i]-=tmp;
        sum += tmp;
    }
    for(i=1; i<n; i++) {
        ll tmp = MAX(a[i-1]+a[i]-x, 0);
        a[i] -= tmp;
        sum += tmp;
    }
    printf("%lld\n", sum);

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
    int a,b,c,d,e,k;
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&k);
    if( e - a > k){
            printf(":(\n");
        }else{
            printf("Yay!");
        }

    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int N,M,C,ans=0,temp,A;

int main(){
    cin>>N>>M>>C;
    int B[M];
    rep(i,M){
        cin>>B[i];
    }
    rep(i,N){
        temp=0;
        rep(j,M){
            cin>>A;
            temp+=A*B[j];
        }
        temp+=C;
        if(temp>0)ans++;
    }
    out(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map> 
#define io ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
#define int long long
#define sp " "
#define fi freopen("bruh.txt","r",stdin);
#define fo freopen("input.txt", "w", stdout);
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),c.end();
#define allr(x) x.rbegin(), x.rend()
#define pii pair< int , int >
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rev(i,n,a)for(int i=n;i>=a;i--)
#define mem(ara,a) memset(ara,a,sizeof (ara))
long long inf=2e18;
long long minf=-inf;
using namespace std;

signed main(){
int n , m=0;
cin>>n;
for(int i=1;i<=n;i++){
    if(i%3==0 or i%5==0)continue;
    m+=i;
}
cout<<m<<endl;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1000000007;

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

    ll ans = 100000000000;
    ll x2y;

    // A
    x2y = y - x;
    if(x2y >= 0) ans = min(ans, x2y);
    // B -> A
    x2y = y - (-x);
    if(x2y >= 0) ans = min(ans, 1 + x2y);
    // A -> B
    x2y = (-y) - x;
    if(x2y >= 0) ans = min(ans, 1 + x2y);
    // B -> A -> B
    x2y = (-y) - (-x);
    if(x2y >= 0) ans = min(ans, 2 + x2y);

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int n, k;

int main() {
	cin >> n >> k;
	int ans = 0;
	inc(i, n) {
		int h; cin >> h;
		if(h >= k) { ans++; }
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int main(){
  int n, sum = 0;
  cin >> n;
  int a[n+2];

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

  for(int i = 1; i < n+2; i++){
    sum += abs(a[i-1] - a[i]);
  }

  for(int i = 1; i < n+1; i++){
    int fee;
    fee = sum - (abs(a[i-1] - a[i]) + abs(a[i] - a[i+1]));
    fee += abs(a[i-1] - a[i+1]);
    cout << fee << endl;
  }

}




Measured memory_bytes: 1664
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
		long n = long.Parse(input[0]);
		long m = long.Parse(input[1]);
    long[,] vertexes = new long[n,3];//ここに受け取る
    long[] sumPPP = new long[n];
    long[] sumPPm = new long[n];
    long[] sumPmP = new long[n];
    long[] sumPmm = new long[n];
    long[] summPP = new long[n];
    long[] summPm = new long[n];
    long[] summmP = new long[n];
    long[] summmm = new long[n];
    long answer = 0;
    long memo = 0;
    for(long i = 0; i < n; i++)
    {
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
      sumPPP[i] = nums[0] + nums[1] + nums[2];
      sumPPm[i] = nums[0] + nums[1] - nums[2];
      sumPmP[i] = nums[0] - nums[1] + nums[2];
      sumPmm[i] = nums[0] - nums[1] - nums[2];
      summPP[i] = -nums[0] + nums[1] + nums[2];
      summPm[i] = -nums[0] + nums[1] - nums[2];
      summmP[i] = -nums[0] - nums[1] + nums[2];
      summmm[i] = -nums[0] - nums[1] - nums[2];
    }
    Array.Sort(sumPPP);
    Array.Sort(sumPPm);
    Array.Sort(sumPmP);
    Array.Sort(sumPmm);
    Array.Sort(summPP);
    Array.Sort(summPm);
    Array.Sort(summmP);
    Array.Sort(summmm);
    Array.Reverse(sumPPP);
    Array.Reverse(sumPPm);
    Array.Reverse(sumPmP);
    Array.Reverse(sumPmm);
    Array.Reverse(summPP);
    Array.Reverse(summPm);
    Array.Reverse(summmP);
    Array.Reverse(summmm);

    memo = 0;
    for(int i = 0; i < m; i++) memo += sumPPP[i];
    answer = Math.Max(answer, Math.Abs(memo));
    memo = 0;
    for(int i = 0; i < m; i++) memo += sumPPm[i];
    answer = Math.Max(answer, Math.Abs(memo));
    memo = 0;
    for(int i = 0; i < m; i++) memo += sumPmP[i];
    answer = Math.Max(answer, Math.Abs(memo));
    memo = 0;
    for(int i = 0; i < m; i++) memo += sumPmm[i];
    answer = Math.Max(answer, Math.Abs(memo));
    memo = 0;
    for(int i = 0; i < m; i++) memo += summPP[i];
    answer = Math.Max(answer, Math.Abs(memo));
    memo = 0;
    for(int i = 0; i < m; i++) memo += summPm[i];
    answer = Math.Max(answer, Math.Abs(memo));
    memo = 0;
    for(int i = 0; i < m; i++) memo += summmP[i];
    answer = Math.Max(answer, Math.Abs(memo));
    memo = 0;
    for(int i = 0; i < m; i++) memo += summmm[i];
    answer = Math.Max(answer, Math.Abs(memo));
    
		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 13300
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<queue>
using namespace std;
int n, k;
int cost[110][110];//cost(direct)
int MAX=9999999;


int main() {
	for (int dd = 0; dd < 5; dd++) {
		cin >> n >> k;
		if (n + k == 0)break;

		else {

			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					cost[i][j] = MAX;
					if (i == j)cost[i][j] = 0;
				}
			}

			for (int i = 0; i < k; i++) {
				int seat;
				cin >> seat;

				if (seat == 0) {//cost?
					int a, b;
					cin >> a >> b;
					if (cost[a][b] == MAX)cout << -1 << endl;
					else cout << cost[a][b] << endl;
				}

				else {//ship
					int c, d, e;
					cin >> c >> d >> e;
					if (cost[c][d] > e) cost[c][d] = cost[d][c] = e;
					//revise
					for (int j = 1;j <= n; j++) {
						for (int t = 1; t <= n; t++) cost[j][t] = min(cost[j][t], min(cost[j][c] + e + cost[d][t], cost[j][d] + e + cost[c][t]));
					}
				}

			}
		}
	}
	return 0;
}



Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string>
#include<string.h>
typedef long long int llint;
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	int ans = 0;
	int tmp = 0;
	for (int j = 0;;j++) {
		for (int i = 0;i < n;i++) {
			if (a[i] != 0) {
				tmp = 1;
				while (i < n) {
					if (a[i] == 0) {
						break;
					}
					a[i]--;
					i++;
				}
				ans++;
			}
		}
		if (tmp == 0) {
			break;
		}
		else {
			tmp = 0;
		}
	}
	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 < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
  string s;
  cin >> s;
  int ans = 0, cnt=0;
  rep(i,3){
    if(s[i]=='R') cnt++;
    else {
      ans = max(ans,cnt);
      cnt = 0;
    }
  }
  ans = max(ans,cnt);
  cout << ans << endl;
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;
int factor(int x){
    if(x%4==0) return 4;
    else if(x%2==0) return 2;    
    else return 0;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<int>a(n);
map<int,int>facts;
rep(i,n){
    cin>>a[i];
    facts[factor(a[i])]++;
}
if(facts[2]==n){
    cout<<"Yes"<<endl;
}
else{
    if(facts[2]>0)facts[0]++;

    if(facts[4]>0){
        if(facts[0]<=facts[4]+1){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    else{
        cout<<"No"<<endl;
    }
}
return 0;
}

Measured memory_bytes: 640
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
// const ll mod = 1000000007;
const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"

bool solve(){
    ld r;cin>>r;
    cout<<r*2*pi<<endl;
    return false;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(30);
    solve();
}


Measured memory_bytes: 3772
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;
  int cnt[100010];
int main() {
  int N,Q; cin >> N >> Q;
  string S; cin >> S;
  int l[100010],r[100010];
  for ( int i = 0; i < Q; i++ ) {
    cin >> l[i] >> r[i];
    l[i]--,r[i]--;
  }

  for ( int i = 0; i < S.length()-1; i++ ) {
    if ( S[i] == 'A' &&  S[i+1] == 'C' ) {
      cnt[i+1] = cnt[i]+1;
    } else {
      cnt[i+1] = cnt[i];
    }
  }
  //  for ( int i = 0; i < N; i++ ) {
  //    cout << cnt[i] << " ";
    
  //  }
  for ( int i= 0; i  < Q; i++ ) {
    cout << cnt[r[i]]-cnt[l[i]] << endl;
  }
  return 0;
}


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

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

  if(N>500){B=N/500; C=N-500*B;}
  else if(N==500){ C=0;}
  else{C=N;}           
  if(A>=C){cout << "Yes" << endl;}
  else{ cout << "No" << endl;} 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
long long gcd(long x,long y){
    if(y==0)return x;

    return gcd(y,x%y);
}
long long lcm(long x,long y){
    return x*y/gcd(x,y);
}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main()
{
    int X,Y;
    cin>>X>>Y;

    if(X%Y==0){
        cout<<-1<<endl;
    }else{
        cout<<X<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
import sys


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())

    i = 1
    r = 6
    k = 9
    G = [1]
    while r <= N+1:
        G.append(k)
        G.append(r)
        k *= 9
        r *= 6

    number =[10**9] *(N+1)
    number[0]=0

    for i in range(N):
        c = number[i]
        for g in G:
            if i+g <=N:
                number[i+g] =min(c+1,number[i+g])
    print(number[N])



if __name__ == "__main__":
    main()


Measured memory_bytes: 88712
#include <bits/stdc++.h>
#define sz(v) (int)v.size()
#define v(x) vector<x>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int n, r;
    cin >> n >> r;
    int ir = n >= 10 ? r : r + 100 * (10 - n);
    cout<<ir;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

int main(){
    char s[100];
    char t[100];
    int sl,tl,i,j;
    
    scanf("%s",s);
    scanf("%s",t);
    
    sl = strlen(s);
    tl = strlen(t);
    
    char v;
    for(i=0;i<sl-1;i++){
        for(j=0;j<sl-1;j++){
            if(s[j]>s[j+1]){
                v = s[j];
                s[j] = s[j+1];
                s[j+1] = v;
            }
        }
    }
    
    for(i=0;i<tl-1;i++){
        for(j=0;j<tl-1;j++){
            if(t[j]<t[j+1]){
                v = t[j];
                t[j] = t[j+1];
                t[j+1] = v;
            }
        }
    }
    
    int x = 0;
    if(sl<=tl){
        x = tl;
    }else{
        x = sl;
    }
    int cnt = 0;
    for(i=0;i<100;i++){
        if(s[i]<t[i]){
            printf("Yes");
            break;
        }else if(s[i]>t[i]){
            printf("No");
            break;
        }
        for(j=0;j<x;j++){
            if(s[j]==t[j]){
                cnt++;
            }
        }
        if(cnt==x){
            printf("No");
            break;
        }
    }
}

Measured memory_bytes: 128
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var MTPR=arr.shift();
   if(MTPR=="0 0 0 0")break;
   MTPR=MTPR.split(" ").map(Number);
   var team=[];
   for(var i=0;i<MTPR[1];i++)team.push([0,0,[0,0,0,0,0,0,0,0,0,0],i]);
   for(var i=0;i<MTPR[3];i++){
      var mtpj=arr.shift().split(" ").map(Number);
      var m=mtpj[0];
      var t=mtpj[1]-1;
      var p=mtpj[2]-1;
      var j=mtpj[3];
      if(j==0){
         team[t][0]++;
         team[t][1]+=m+team[t][2][p]*20;
      }
      if(j!=0)team[t][2][p]++;
   }
   team.sort(function(a,b){
      if(a[0]==b[0] && a[1]==b[1])return b[3]-a[3];
      else if(a[0]==b[0])return a[1]-b[1];
      else return b[0]-a[0];
   });
   var ans=[];
   var same=[-1,-1];
   team.forEach(function(v,i){
      if(same[0]==v[0] && same[1]==v[1])ans[ans.length-1]+="="+(v[3]+1);
      else {ans.push(v[3]+1);same=[v[0],v[1]];}
   });
   console.log(ans.join(","));
}

Measured memory_bytes: 20920
# ヒント　dp[i]=(石の個数がi個の時直後の手番の人が勝てるか？)
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*(k+1)
for i in range(1,k+1):
    for j in range(n):
        if i-a[j]>=0 and dp[i-a[j]]==0:
            dp[i]=1
# 1つでもi-a[j]==0なら勝てる.
print("First" if dp[k] else "Second")

Measured memory_bytes: 41836
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            int[] A = new int[N];
            for (int i = 0; i < N; ++i) { A[i] = cin.ReadInt; }
            int res = 0;

            var exist_odd = false;

            while (true)
            {
                for (int i = 0; i < N; ++i)
                {
                    if (A[i] % 2 != 0)
                    {
                        exist_odd = true;
                    }
                }
                if (exist_odd) { break; }

                for (int i = 0; i < N; ++i)
                {
                    A[i] = A[i] / 2;
                }
                ++res;
            }
            //Console.WriteLine(N);
            Console.WriteLine(res);       
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}




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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) break;

        int cnt = 0;
        while (n != 1) {
            if (n%2 == 0) n /= 2;
            else n = 3*n+1;
            cnt++;
        }

        cout << cnt << endl;
    }

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;
vector<ll> p(100000), y(100000), yd[100001];

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

  rep(i, m) cin >> p[i] >> y[i], yd[p[i]].push_back(y[i]);
  rep(i, n) sort(yd[i + 1].begin(), yd[i + 1].end());
  rep(i, m) printf("%06lld", p[i]),
      printf("%06lld\n", lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) -
                             yd[p[i]].begin() + 1);
}


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

using namespace std;

bool pairCompare(const pair<uint64_t, uint64_t>& firstElof, const pair<uint64_t, uint64_t>& secondElof)
{
  return firstElof.first > secondElof.first;
}

int main()
{
  int n, m;
  cin >> n >> m;
  vector<pair<uint64_t, uint64_t> > a; // number and maisu
  a.resize(n + m);
  for(int i = 0;
      i < n;
      ++i)
    {
      cin >> a[i].first;
      a[i].second = 1;
    }

  int b,c;
  for(int i = n;
      i < n + m;
      ++i)
    {
      cin >> a[i].second >> a[i].first;
    }

  sort(a.begin(), a.end(), pairCompare);
  uint64_t sum = 0;
  uint64_t num = 0;

  for(int i = 0;
      num < n;
      ++i)
    {
      if(i >= n + m)
        {
          break;
        }
      if(a[i].second + num > n)
        {
          sum += a[i].first * (n - num);
          num = n;
        }
      else
        {
          sum += a[i].first * a[i].second;
          num += a[i].second;
        }
    }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3328
let () = Scanf.scanf "%d\n" @@ fun n ->
  let cas = Array.init (2 * n) @@ fun _ -> Scanf.scanf "%c %d\n" @@ fun c a -> c, a in
  let inv_ws = Array.make n 0 in
  let inv_bs = Array.make n 0 in
  let acc_ws = Array.make_matrix (2 * n + 1) (n + 1) 0 in
  let acc_bs = Array.make_matrix (2 * n + 1) (n + 1) 0 in
  for i = 2 * n - 1 downto 0 do
    begin match cas.(i) with
    | ('W', a) ->
        inv_ws.(a - 1) <- i;
        acc_ws.(i).(a) <- 1 + acc_ws.(i).(a)
    | ('B', a) ->
        inv_bs.(a - 1) <- i;
        acc_bs.(i).(a) <- 1 + acc_bs.(i).(a)
    end;
    for j = 1 to n do
      acc_ws.(i).(j) <- acc_ws.(i).(j) + acc_ws.(i).(j - 1);
      acc_bs.(i).(j) <- acc_bs.(i).(j) + acc_bs.(i).(j - 1)
    done;
    for j = 0 to n do
      acc_ws.(i).(j) <- acc_ws.(i).(j) + acc_ws.(i + 1).(j);
      acc_bs.(i).(j) <- acc_bs.(i).(j) + acc_bs.(i + 1).(j)
    done
  done;
  let dp = Array.make_matrix (n + 1) (n + 1) max_int in
  dp.(0).(0) <- 0;
  for w = 1 to n do
    dp.(w).(0) <- dp.(w - 1).(0) - w + 1
      + inv_ws.(w - 1)
      + acc_ws.(inv_ws.(w - 1) + 1).(w)
  done;
  for b = 1 to n do
    dp.(0).(b) <- dp.(0).(b - 1) - b + 1
      + inv_bs.(b - 1)
      + acc_bs.(inv_bs.(b - 1) + 1).(b)
  done;
  for w = 1 to n do
    for b = 1 to n do
      dp.(w).(b) <- min
        ( dp.(w - 1).(b) + inv_ws.(w - 1)
          + acc_ws.(inv_ws.(w - 1) + 1).(w)
          + acc_bs.(inv_ws.(w - 1) + 1).(b) )
        ( dp.(w).(b - 1) + inv_bs.(b - 1)
          + acc_ws.(inv_bs.(b - 1) + 1).(w)
          + acc_bs.(inv_bs.(b - 1) + 1).(b) ) - w - b + 1
    done
  done;
  Printf.printf "%d\n" @@ dp.(n).(n)


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

int main(){
	long long int a,b,x;
	cin>>a>>b>>x;
	
	long long int ans;
	int ax=(a-1)/x+1;
	if(a==0)ax=0;
	
	ans = b/x+1-ax;
	
	cout<<ans<<endl;
	return 0;
}

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

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

  ll x = n % k;
  ll y = -(x - k);
  ll ans = (x < y) ? x : y;
  cout << ans << endl;
  return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  if (C >= A && C <= B ) {
    cout << "Yes" << endl;
  }

  if (!( C >= A && C <= B )) {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 3620
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
int a[3],ans; 
int main(){
	scanf("%d%d%d",&a[0],&a[1],&a[2]);
	sort(a,a+3);
	while(a[1]<a[2]){
		a[0]++;
		a[1]++;
		ans++;
	}
	while(a[0]<a[1]){
		a[0]+=2;
		ans++;
	}
	if(a[1]!=a[0])
		ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second

using namespace std;

const  long long mod = 1007050321;
const  long long base = 521;
const  long long N = 2e5 + 5;
const  long long MOD = 1e9 + 7;
const  long long inf = 2e9;

long long n,a[N];
pair < long long, long long> it[4*N];

void up ( long long id, long long l, long long r, long long pos, long long val) {
    if (pos < l || pos > r)
        return;
    if (l == r) {
        it[id].fi += val;
        it[id].se = it[id].fi*(it[id].fi-1)/2;
        return;
    }
    long long mid = l + r >> 1;
    up (id*2,l,mid,pos,val);
    up (id*2+1,mid+1,r,pos,val);

    it[id].se = it[id*2].se + it[id*2+1].se;
}

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

    cin >> n;
    for ( long long i = 1; i <= n; ++i)
        cin >> a[i];

    for ( long long i = n; i >= 1; --i)
        up(1,1,200000,a[i],1);

    for ( long long i = 1; i <= n; ++i) {
        up(1,1,200000,a[i],-1);
        cout << it[1].se << "\n";
        up(1,1,200000,a[i],1);
    }

    return 0;
}


Measured memory_bytes: 13440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
const ll INF=1e9+7;
const ll N = 100002;
ll a,b,c,m,k;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>a>>b>>c>>k;
	m=max({a,b,c});
	a+=b;
	a+=c;
	a-=m;
	FOR(i,0,k){
		m*=2;
	}
	pri(m+a);
	return 0;
}

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

int n, m;
vector<vector<int>> g;
vector<bool> vis; // 探索のときの目印が必要

void dfs(int i) {
	if(vis[i]) return;
	vis[i] = true;
	// for(int j=0;j<g[i].size();j++){
	// 	dfs(g[i][j]);
	// }
	for(auto j : g[i]){
		dfs(j);
	}
}


int main() {
	cin >> n >> m;
	vector<int> a(m), b(m);
	for(int i=0;i<m;i++){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}
	int cnt = 0;
	for(int i=0;i<m;i++){
		g.clear();  // 空にする
		g.resize(n); // サイズをnにする
		for(int j=0;j<m;j++){
			if(j==i) continue;
			g[a[j]].push_back(b[j]);
			g[b[j]].push_back(a[j]);
		}
		vis.clear();
		vis.resize(n, false);
		dfs(0);
		for(int i=0;i<n;i++){
			if(vis[i]==false){
				cnt++;
				break;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#define _USE_MATH_DEFINES
#include<cmath>
using namespace std;
int main(){
  int m,min,max;
  while(cin >> m >> min >> max,m){
    int p[m];
    for(int i=0;i<m;i++) cin >> p[i];
    int gap=0,n=0;
    for(int i=min-1;i<max;i++){
      if(gap<=p[i]-p[i+1]){
        n=i+1;
        gap=p[i]-p[i+1];
      }
    }
  cout << n << endl;
  }
}

Measured memory_bytes: 3012
""" 解答AC """

N,x = map(int,input().split())
a = [int(i) for i in input().split()]

# b[i]: 色iを飼うために「捕まえる」の最小値
b = a.copy()

ans = float("inf")
# 魔法を「ちょうど」k回唱える場合
for k in range(N):
    for i in range(N):
        b[i] = min(b[i], a[(i - k) % N])

    ans = min(ans, k * x + sum(b))

print(ans)

Measured memory_bytes: 3188
#include<cstdio>
#include<cmath>
using namespace std;

const int N = 1<<18;
const int LGN = 19;

long long max_ll(long long a,long long b) {return a<b ? b : a;}

long long a[N+5];
long long d[N+5];
long long s1[N+5];
long long c1[N+5];
long long s2[N+5];
long long c2[N+5];
long long mx1[N+2];
long long mx2[N+2];
int n;
long long m;

int main()
{
	scanf("%d%lld",&n,&m); n+=2; a[1] = 0ll; d[1] = 0ll; a[n] = 0ll; d[n] = m;
	for(int i=2; i<n; i++) scanf("%lld%lld",&d[i],&a[i]);
	s1[0] = 0;
	for(int i=1; i<=n; i++) s1[i] = s1[i-1]+a[i];
	for(int i=1; i<=n; i++) s1[i] -= d[i];
	for(int i=1; i<=n; i++) mx1[i] = max_ll(mx1[i-1],s1[i]);
	for(int i=1; i<=n; i++) c1[i] = s1[i]-d[i];
	s1[n+1] = 0;
	for(int i=n; i>=1; i--) s2[i] = s2[i+1]+a[i];
	for(int i=n; i>=1; i--) s2[i] -= (m-d[i]);
	for(int i=n; i>=1; i--) mx2[i] = max_ll(mx2[i+1],s2[i]);
	for(int i=n; i>=1; i--) c2[i] = s2[i]-(m-d[i]);
	long long ans1 = 0ll,ans2 = 0ll;
	for(int i=n; i>1; i--)
	{
		long long tmp = mx1[i-1];
		ans1 = max_ll(ans1,c2[i]+tmp);
	}
	for(int i=1; i<n; i++)
	{
		long long tmp = mx2[i+1];
		ans2 = max_ll(ans2,c1[i]+tmp);
	}
	long long ans = max_ll(ans1,ans2);
	if(ans>0ll) printf("%lld\n",ans);
	else printf("0\n");
	return 0;
}

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

#define pb push_back
#define fi first
#define se second
typedef long long ll;

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

	int a, b;
	cin >> a >> b;
	cout << max(a + b, max(a - b, a * b)) << '\n';
}


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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

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

int main(void)
{
	int n, k; cin >> n >> k;
	int ans = (n<k?0:10);

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

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

typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back

const int maxn = 200005;
ll a[maxn],b[maxn];
int main() {
    int n,m;
    ll k;
    cin>>n>>m>>k;
    ii cin>>a[i];
    ij cin>>b[i],b[i]+=b[i-1];
    ll s=0;
    int ans=upper_bound(b+1,b+1+m,k)-b-1;
    for(int i=1;i<=n;++i) {
        s+=a[i];
        if(s>k) break;
        int pos=upper_bound(b+1,b+1+m,k-s)-b-1;
        ans=max(ans,i+pos);
    }
    cout<<ans<<endl;
}

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

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var abs = new KeyValuePair<int, int>[n];
        for (int i = 0; i < abs.Length; ++i)
        {
            var list = Console.ReadLine().Split(' ');
            abs[i] = new KeyValuePair<int, int>(
                int.Parse(list[0]),
                int.Parse(list[1])
            );
        }

        Array.Sort(abs, (l, r) => l.Value.CompareTo(r.Value));

        long total = 0;
        for (int i = 0; i < abs.Length; ++i)
        {
            total += abs[i].Key;
            if (total > abs[i].Value)
            {
                Console.WriteLine("No");
                return;
            }
        }

        Console.WriteLine("Yes");
    }

    private static int GCD(int a, int b) => a > b ? GCD_impl(a, b) : GCD_impl(b, a);
    private static int GCD_impl(int a, int b) => b == 0 ? a : GCD_impl(b, a % b);
    private static long LCM(int a, int b) => (long)a * b / GCD(a, b);

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


Measured memory_bytes: 17412
N,Q = gets.split.map(&:to_i)
count = Array.new(N+1,0)
tree = Array.new(N+1,0)

(N-1).times.map{
    a,b = gets.split.map(&:to_i)
    tree[b] = a
}
Q.times.map{
    p,x = gets.split.map(&:to_i)
    count[p] += x
}
2.upto(N) do |node_n|
  count[node_n] += count[tree[node_n]]
end

puts count[1..N].join(" ")

Measured memory_bytes: 12412
n = int(input())
aarr = list(map(int, input().split()))
barr = list(map(int, input().split()))
carr = list(map(int, input().split()))
sarr = []

for i in range(n):
    sarr.append(barr[aarr[i] - 1])

    if (i != n - 1) and (aarr[i] + 1 == aarr[i + 1]):
        sarr[len(sarr) - 1] += carr[aarr[i] - 1]

print(sum(sarr))


Measured memory_bytes: 3064
#include <stdio.h>

int search(int A[], int n, int key) {
  int i = 0;  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}

int main(void) {
  int i, n, A[10000+1], q, key, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d", &A[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++) {
    scanf("%d", &key);
    if(search(A, n, key))sum++;
  }
  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 2108
N,K = list(map(int, input().split()))
d = []
A = []
for i in range(K):
  d.append(int(input()))
  A.append(list(map(int, input().split())))

ls = [0 for i in range(N+1)]
for i,a in enumerate(A):
  for j in range(d[i]):
    ls[a[j]]=1

cnt=0
for i in range(1,N+1):
  if ls[i] == 0:
    cnt+=1
print(cnt)


Measured memory_bytes: 9196
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  string s;
  cin >> s;

  for(int i=0;i<3;i++){
    if(s[i]=='7'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long

signed main(){
  int n;
  cin>>n;
  vector<int> v;
  int ans=n-1;
  if(n<3){
    cout<<0<<endl;
    return 0;
  }
  if(n==3){
    cout<<2<<endl;
    return 0;
  }
  for(int i=2;i*i<n;i++){
    if(n%i==0){
      if(n/i-1==i) continue;
      ans+=n/i-1;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class T> ostream& operator<<(ostream &os, set<T> S){os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {os << "{ "; for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") "; return os<<"}";}
#ifdef np
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>void __f(const char *name, Arg1 &&arg1) { cout<<name<<" : "<<arg1<<endl;}
template<typename Arg1, typename ... Args>void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,','); cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif


int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

	int n ; cin>>n;
	for(int i =1 ; i<=9 ; ++i){
		for(int j = 1 ; j<=9 ; j++){
			if(i*j==n) {cout<<"Yes"; return 0; }
		}
	}
	cout<<"No";

#ifdef np
    cerr <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif  
 return 0; 
 }


Measured memory_bytes: 256
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}

// O(sqrt(n))
map<ll, ll> PrimeFact(ll n) {
  map<ll, ll> ret;
  if (n != 1) {
    for (ll i = 2; i * i <= n; i++) {
      ll c = 0;
      while (n % i == 0) {
        c++;
        n /= i;
      }
      if (c)
        ret.emplace(i, c);
    }
    if (n != 1)
      ret.emplace(n, 1);
  }
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  auto mp = PrimeFact(n);
  ll ans = 0;
  for(auto&& e: mp){
    ll i = 1;
    ll x = e.second;
    while(x >= i){
      x -= i;
      i++;
      ans++;
    }
  }
  print(ans);
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N;
	cin>>N;
	vector<int> a(N);
	vector<int> a_pre(N);
	rep(i,N){
		cin>>a[i];
		a_pre[i] = a[i];
	}
	sort(all(a));
	/*print(a);
	print(a_pre);*/
	rep(i,N){
		if(a_pre[i] == a[N-1]){
			cout<<a[N-2]<<endl;
		}
		else{
			cout<<a[N-1]<<endl;
		}
	}
}

Measured memory_bytes: 3200