akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

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

	int x = 0;
	while (7 * x <= n) {
		if ((n - 7 * x) % 4 == 0) {
			cout << "Yes" << endl;

			return 0;
		}
		x++;
	}
	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
a =[]
b = []
for i in range(n):
    a.append(list(map(int,input().split())))

for i in range(m):
    b.append(int(input()))

for i in range(n):
    Sum = 0
    for j in range(m):
        Sum += a[i][j]*b[j]
    print(Sum)


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

using namespace std;

int main(){
    int x,y;

    cin>>x>>y;

    int kazu=x;

    x=x*4;

    for(int i=0;i<=kazu;i++){
        
        if(i*2+(kazu-i)*4==y){
            cout<<"Yes"<<endl;
            return 0;
        }
    }

    cout<<"No"<<endl;
}

Measured memory_bytes: 3668
n, k = map(int, input().split())

mod = 10 ** 9 + 7

fact = [1]
fact_inv = [0] * (n+1)
for i in range(n):
    fact.append(fact[-1] * (i+1) % mod)
fact_inv[-1] = pow(fact[-1], mod-2, mod)
for i in range(n-1, -1, -1):
    fact_inv[i] = fact_inv[i+1] * (i+1) % mod

ans = 0
for i in range(min(n-1, k) + 1):
    com1 = fact[n] * fact_inv[i] * fact_inv[n-i] % mod
    com2 = fact[n-1] * fact_inv[i] * fact_inv[n-i-1] % mod
    mul = com1 * com2 % mod
    ans = (ans + mul) % mod

print(ans)

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

counter=0
for i in range(N):
	Ar = A[i:] #i?????????????´???\????????????????????????
	num = Ar.index(min(Ar)) #i?????????????´???\???????????????????????§???????°???????index?????????
	if num != 0:
		A[i], A[(i+num)] = A[(i+num)], A[i]
		counter += 1
print(" ".join(map(str,A)))
print(counter)

Measured memory_bytes: 7672
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int main()
{
    int n, t, a;
    cin >> n >> t >> a;

    int ans = 0;
    double min = 1e9;
    for (int i = 0; i < n; i++)
    {
        int h;
        cin >> h;
        double d = t - h * 0.006 - a;
        if (d < 0)
        {
            d *= -1;
        }
        if (min > d)
        {
            min = d;
            ans = i + 1;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict 
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    
    ans = 0
    ruiseki = [0]
    d = defaultdict(int)
    d[0]=1
    for i in range(n):
        if i - k + 1>= 0:
            d[ruiseki[i - k+1]]-=1
        ruiseki.append((ruiseki[i] + a[i] - 1)%k)
        ans += d[ruiseki[i+1]]
        d[ruiseki[i + 1]] += 1
    print(ans)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 39204
Module Module1

    Sub Main()
        'let'
        Dim A As Long = Console.ReadLine()
        Dim B As Long = Console.ReadLine()
        Dim C As Long = Console.ReadLine()
        Dim X As Long = Console.ReadLine()

        'var'
        Dim cnt As Long = 0

        For i As Long = 0 To A
            For j As Long = 0 To B
                For k As Long = 0 To C
                    If X = 500 * i + 100 * j + 50 * k Then
                        cnt += 1
                    End If
                Next
            Next
        Next

        Console.WriteLine(cnt)

    End Sub

End Module

Measured memory_bytes: 11220
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if (n <= k) {
        cout << n * x << endl;
        return 0;
    } else {
        cout << y * (n - k) + x * k << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using llong = long long;

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

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

  int K, S;
  cin >> K >> S;

  int X, Y, Z;

  int count = 0;
  REP(i, K + 1) {
    REP(j, K + 1) {
      int k = S - i - j;
      if (k <= K && 0 <= k) {
        count++;
      }
    }
  }
  cout << count << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int a,b,c,d;
  cin >> a >> b >> c >> d;

  while(1){
    c-=b;
    if(c<=0){
      cout << "Yes" << endl;
      return 0;
    }
    a-=d;
    if(a<=0){
      cout << "No" << endl;
      return 0;
    }
  }

  return 0;
}

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

int main() {
	int r, g, b;
	cin >> r >> g >> b;
	if((r * 100 + g * 10 + b) % 4 == 0)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int a,b;
  int t;
  cin >> a >> b >> t;

  cout << (t/a)*b << endl;



  return 0;
}

Measured memory_bytes: 256
#全体の最大値が入っているときは、それが部分列の最大値になるので、わざわざ計算しなくて良い
#こういうことに先気づかないと、TLEになる
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))

a_max = max(a)
max_idx = a.index(a_max)
c = a.count(a_max)

for i in range(n):
  if i!=max_idx:
    print(a_max)
  elif i==max_idx and c>=2:
    print(a_max)
  else:
    a.remove(a[i])
    print(max(a))

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

using namespace std;

int a, b;

int main () {
    cin >> a >> b;
    if (a <= 0 && 0 <= b) {
        cout << "Zero";
    } else if (0 < a) {
        cout << "Positive";
    } else {
        if ((b - a) & 1) cout << "Positive"; else cout << "Negative";
    }
    return 0;
}


Measured memory_bytes: 256
//N+10個のボールのうち15個を黒く塗る。前半5個のボールまでは、
//手前の黒いボール(or先頭)までにあるボールが偶数個になってほしい。何通りの入れ方があるか？
#include <iostream>
#include <vector>
#define int long long
using namespace std;
typedef vector<int> Array;
typedef vector<Array> Mat;

Mat identify(int n) {
	Mat mat(n, Array(n, 0));
	for (int i = 0; i < n; i++) mat[i][i] = 1;
	return mat;
}

Mat multiply(Mat a, Mat b, int mod) {
	Mat mat(a.size(), Array(b[0].size(), 0));
	for (int i = 0; i < a.size(); i++) {
		for (int k = 0; k < b.size(); k++) {
			const int a_const = a[i][k];
			int *ptrB = &b[k][0];
			for (int j = 0; j < b[0].size(); j++) {
				mat[i][j] += a_const * *ptrB;
				mat[i][j] %= mod;
				ptrB++;
			}
		}
	}
	return mat;
}

Mat powmat(Mat a, int n, int mod) {
	if (n == 0) return identify(a.size());
	if (n % 2 == 0) return powmat(multiply(a, a, mod), n / 2, mod);
	return multiply(a, powmat(a, n - 1, mod), mod);
}

//a * b(縦ベクトル). a[0].size() == b.size()
Array multiply(Mat a, Array b, int mod) {
	Array ret(a.size(), 0);
	for (int i = 0; i < a.size(); i++) {
		for (int j = 0; j < b.size(); j++) {
			ret[i] += a[i][j] * b[j];
		}
	}
	return ret;
}

int solve(int n) {
	int mod = 1000000007;
	int i, j;
	
	//dp[i][仕切り数j][個数偶奇k]. vector(i)[2 * j + k] = dp[i][j][k]と表現すると、
	//初期値：vector(0)[0] = 1, vector(0)[0以外] = 0.
	//求めたい：vector(n + 10)[30] + vector(n + 10)[31].
	//
	//dp[i][j][k] -> dp[i+1][j'][k']と遷移するとき、2j' + k'行2j + k列目に遷移数(1)を書いた行列mat
	//を作ると、vector(n) = mat^n * vector(0). mat部分は繰り返し累乗で32^3 * logNくらい.
	Array vec0(32, 0);
	vec0[0] = 1;
	
	Mat mat(32, Array(32, 0));
	
	//遷移行列の生成. [仕切り数i][個数偶奇j].
	for (i = 0; i <= 15; i++) {
		for (j = 0; j < 2; j++) {
			//仕切る
			if (i < 15 && (i >= 5 || j == 0)) {
				mat[2 * (i + 1) + 0][2 * i + j] += 1;
			}
			//仕切らない
			mat[2 * i + (!j)][2 * i + j] += 1;
		}
	}
	
	//行列計算
	Mat resMat = powmat(mat, n + 10, mod);
	Array resVec = multiply(resMat, vec0, mod);
	
	return (resVec[30] + resVec[31]) % mod;
}

signed main() {
	int T;
	cin >> T;
	while (T--) {
		int n;
		cin >> n;
		cout << solve(n) << endl;
	}
	return 0;
}

Measured memory_bytes: 4652
n = int(input())
h_list = list(map(int,input().split()))	
count = 0
view = True
for index,h in enumerate(h_list):
    target_h = h
    for i in range(index):
        if target_h >= h_list[i]:
            pass
        else:
            view = False
            break
    if view:
        count += 1
    view = True

print(count)

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

using namespace std;

#define long long long
#define INF (long) 1e18
#define MOD 1'000'000'007
#define mll map<long, long>
#define pll pair<long, long>
#define umap unordered_map
#define umll umap<long, long>
#define uset unordered_set
#define pb push_back
#define FOR(i, a, b) \
  for (long i = (a); i < (long) (b); i++)

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

  long h, w, d;
  cin >> h >> w >> d;

  map<long, pll> f;
  FOR (i, 0, h) {
    FOR (j, 0, w) {
      long x;
      cin >> x;
      f[x] = {i, j};
    }
  }
  mll cost;
  FOR (k, 0, d) {
    for (long l = k+d; l <= h*w; l += d) {
      if (k == 0 and l == d) continue;
      cost[l] = cost[l-d];
      cost[l] += abs(f[l].first  - f[l-d].first);
      cost[l] += abs(f[l].second - f[l-d].second);
    }
  }
  long q;
  cin >> q;
  while (q--) {
    long l, r;
    cin >> l >> r;
    long x = cost[r] - cost[l];
    printf("%lld\n", x);
  }
}


Measured memory_bytes: 12416
N = gets.to_i
ABs= readlines.map{|l| l.split.map(&:to_i)}

G = (ABs + ABs.map{|a, b| [b, a]}).group_by(&:first).map{|k, v| [k, v.map(&:last)]}.to_h
b, w, h = G[1], G[N], {1 => :b, N => :w}
until (b + w).empty?
  b = b.reject{|i| h.key?(i)}.each{|i| h[i] = :b}.flat_map{|i| G[i]}
  w = w.reject{|i| h.key?(i)}.each{|i| h[i] = :w}.flat_map{|i| G[i]}
end
puts h.values.count(:b) > N/2 ? 'Fennec' : 'Snuke'

Measured memory_bytes: 68716
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int n;
void dfs(int x){
	if(x==0)return ;
	if(x<0)dfs((x-1)/-2);
	else dfs(-(x/2));
	cout << abs(x%-2);
}
int main(){
	cin >> n;
	if(n==0)cout << 0;
	else dfs(n);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

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

  ll n, x;
  cin >> n >> x;
  ll ans = 1;
  for(ll i = 0; i < n; i++){
    ll a;
    cin >> a;
    if(i == 0) ans = abs(x - a);
    else ans = gcd(ans, abs(x - a));
  }
  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)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

int main(){
  int n;
  cin>>n;
  vector<int>p(n);
  vector<int>q(n);
  vector<int>a(n);
  rep(i,n){
    cin>>p[i];
  }
  rep(i,n){
    cin>>q[i];
  }
  rep(i,n){
    a[i]=i+1;
  }

  int s=0,k,l;
  do{
    s++;
    int cnt=0,cnt2=0;
    rep(i,n){
      if(a[i]==p[i])cnt++;
      if(a[i]==q[i])cnt2++;
    }
    if(cnt==n)k=s;
    if(cnt2==n)l=s;
  }
  while(next_permutation(a.begin(),a.end()));

  cout<<abs(k-l)<<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)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define SORT(s) sort((s).begin(),(s).end())
#define SORTR(s,t) sort((s).begin(),(s).end(),greater<t>())

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000ll;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

int N,K; string S;
void input(){
    cin>>N>>K;
    cin>>S;
    return;
}

void solve(){
    int ans=0;
    rep(i,N-1) if(S[i]==S[i+1]) ++ans;
    // cout<<"defalut: "<<ans<<endl;
    rep(i,K){
        int k=N-1-ans;
        if(k>1) ans+=2;
        else if(k>0) ++ans;
        else break;
    }
    cout<<ans<<endl;
    return;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 512
l =[int(input()) for i in range(5)]
total=[]
sum=0

for i in l:
    if i%10==0:
        num=10
    else:
        num = i%10
    total.append(num)
min_ind=total.index(min(total))
min_num=l[min_ind]
del l[min_ind]

for i in l:
    if i%10==0:
        sum+=i
    else:
        sum+=(int(i/10)+1)*10
sum+=min_num
print(sum)


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <cstdlib>

using namespace std;

int main(int argc, char* argv[])
{
    int in, h, m, s;
    cin >> in;
    if(in < 0 || in > 86400) {
        return 0;
    }
    h = in / 3600;
    m = (in - h * 3600) / 60 ;
    s = in - (h * 3600 + m * 60);
    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> child[N];
  bool seen[N];
  vector<int> Deep(N);
  vector<int> CandParent[N];
  vector<int> num(N);
  
  for (int i = 0; i < N; i++) {
    seen[i] = false;
  }
  for (int i = 0; i < N-1+M; i++) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    child[a].push_back(b);
    CandParent[b].push_back(a);
    num[b]++;
    seen[b] = true;
  }
  int Parent = 0;
  for (int i = 0; i < N; i++) {
    if (!seen[i]) {
      Parent = i;
    }
  }

  for (int i = 0; i < N; i++) {
    Deep[i] = 999999;
  }
  Deep[Parent] = 0;
  int cnt = 0;
  vector<int> vec = {Parent};
  while (!vec.empty()) {
    vector<int> newvec = {};
    for (int j = 0; j < (int)vec.size(); j++) {
      for (int k = 0; k < (int)child[vec[j]].size(); k++) {
        int C = child[vec[j]][k];
        num[C]--;
        if (num[C] == 0) {
          newvec.push_back(C);
          Deep[C] = cnt+1;
        }
      }
    }
    cnt++;
    vec = newvec;
  }
  
  vector<int> ans(N);
  ans[Parent] = -1;
  for (int i = 0; i < N; i++) {
    if (i == Parent) {
      continue;
    }
    for (int j = 0; j < (int)CandParent[i].size(); j++) {
      if (Deep[i] - 1 == Deep[CandParent[i][j]]) {
        ans[i] = CandParent[i][j];
      }
    }
  }

  for (int i = 0; i < N; i++) {
    cout << ans[i] + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 15312
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


int main()
{
    unsigned long long d = 1000000007ULL;
    unsigned long long n, m;
    cin >> n >> m;

    if (n == m || n == m + 1 || n == m - 1) {
        unsigned long long nn = 1;
        for (long long i = 2; i <= n; ++i) {
            nn *= i;
            if (nn >= d) nn %= d;
        }
        unsigned long long mm = 1;
        for (long long i = 2; i <= m; ++i) {
            mm *= i;
            if (mm >= d) mm %= d;
        }
        unsigned long long a = (nn * mm) % d;
        if (n == m) a *= 2;
        if (a >= d) a %= d;
        cout << a << endl;
    } else {
        cout << 0 << 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 P = pair<int, int>;

int main() {
  int n, r, ans;
  cin >> n >> r ;
  if (n < 10) {
   ans =  r  + 100 * (10 - n);
  }else {
    ans = r;
  }

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

Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int a, b, c, d;
	
	scanf("%d %d %d %d" ,&a, &b, &c, &d);
	
	if((abs(a-b)<=d && abs(b-c)<=d) || abs(a-c)<=d)
	{
		printf("Yes");
		return 0;
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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;
}

const int INF = 1e9;
const long long LINF = 1e18;

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

    vector<vector<int>> X(N, vector<int>(D));

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            int dist = 0;
            for (int k = 0; k < D; k++) {
                dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }

            int d = static_cast<int>(sqrt(dist));
            if (d * d == dist) {
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using ll = long long;

int main()
{
    int n;
    string ans = "YES";
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    rep(i,n-1)if(a[i]==a[i+1]) ans = "NO"; 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import Data.List
main = do
  _ <- getLine
  numList <- sort . map read . words <$> getLine
  let result = foldl1' (\acc x -> if acc*x > 10^18 then 0 else acc*x) numList
  print $ if (result==0) && not(elem 0 numList) then -1 else result

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

#define reep(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) reep((i),0,(n))
#define PB push_back
#define mkp make_pair
#define MOD 1000000007

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vint;
typedef vector<vector<long long> > vvll;


int n, q;
vector<ll> p;
vector<vll> vv;
vvll peri;
vll s;

void pre() {
	vv.assign(41, vll(n + 1));
	vll w(n);
	rep(i, n) {
		w[i] = i + 1;
	}
	s = vll(n);
	peri = vvll(41, vll(n));
	rep(i, 40) {
		vll next(n, 0);
		rep(j, n) {
			if(w[j] == 0) continue;
			next[j] = p[w[j] - 1];
		}
		w = next;
		rep(j, n) {
			if(w[j] == 0) continue;
			s[j] += w[j];
			if(w[j] == j + 1) {
				w[j] = 0;
				peri[i + 1][j] = s[j];
			}
		}
	}
	rep(i, n) {
		assert(w[i] == 0);
	}
	rep(i, 41) {
		rep(j, n) {
			if(j) peri[i][j] += peri[i][j - 1];
		}
	}
}

ll powmod(ll x, ll y) {
	ll a = 1;
	while(y) {
		if(y & 1) a = a * x % MOD;
		x = x * x % MOD;
		y >>= 1;
	}
	return a;
}

ll solve(int l, int r) {
	ll G = -1;
	vint L(41);
	reep(i, 2, 41) {
		ll t = peri[i][r];
		if(l) t -= peri[i][l - 1];
		t = (t + MOD) % MOD;
		if(t) {
			ll tt = i;
			reep(j, 2, 41) {
				int cnt = 0;
				while(tt % j == 0) {
					cnt++;
					tt /= j;
				}
				L[j] = max(L[j], cnt);
			}
		}
	}
	ll lcm = 1;
	ll ret = 0;
	rep(i, 41) {
		rep(j, L[i]) lcm *= i;
	}
	rep(i, 41) {
		ll t = peri[i][r];
		if(l) t -= peri[i][l - 1];
		t = (t + MOD) % MOD;
		if(!t) continue;
		ret += (lcm / i) % MOD * t % MOD;
		ret %= MOD;
	}
	return ret;
}


int main() {
	cin >> n >> q;
	p.assign(n, 0);
	rep(i, n) cin >> p[i];
	pre();
	rep(o, q) {
		int l, r;
		cin >> l >> r;
		l--, r--;
		cout << solve(l, r) << endl;
	}
}

Measured memory_bytes: 70228
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=1e5,INF=1e8;
int N;
vector<int> G[MAX_N];
bool exi[MAX_N];
int deg[MAX_N];
string c;
int cst[MAX_N];
bool flg[MAX_N];
void bfs(int s){
	fill(cst,cst+N,INF);
	cst[s]=0;
	queue<int> q;
	q.push(s);
	while(!q.empty()){
		int v=q.front();
		q.pop();
		for(auto e:G[v]){
			if (exi[e] && cst[e]==INF){
				cst[e]=cst[v]+flg[e];
				q.push(e);
			}
		}
	}
}
int main(){
	cin>>N;
	REP(i,N-1){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		G[x].push_back(y);
		deg[y]++;
		G[y].push_back(x);
		deg[x]++;
	}
	memset(exi,true,sizeof(exi));
	cin>>c;
	{
		queue<int> q;
		REP(i,N){
			if (deg[i]<=1 && c[i]=='B'){
				q.push(i);
			}
		}
		while(!q.empty()){
			int v=q.front();
			q.pop();
			exi[v]=false;
			for(auto e:G[v]){
				if (exi[e]){
					deg[e]--;
					if (deg[e]<=1 && c[e]=='B'){
						q.push(e);
					}
				}
			}
		}
	}
	REP(i,N){
		flg[i]=(c[i]=='W') ^ (deg[i]%2);
	}
	int n=0;
	REP(i,N){
		if (exi[i]){
			n++;
		}
	}
	if (n<=1){
		cout<<n<<endl;
	}else{
		int v=0;
		REP(i,N){
			if (exi[i] && deg[i]==1){
				v=i;
			}
		}
		bfs(v);
		v=-1;
		REP(i,N){
			if (exi[i] && deg[i]==1 && (v==-1 || cst[i]>cst[v])){
				v=i;
			}
		}
		bfs(v);
		int ma=0;
		REP(i,N){
			if (exi[i] && deg[i]==1){
				ma=max(ma,cst[i]);
			}
		}
		int ans=2*(n-1);
		REP(i,N){
			if (exi[i] && flg[i]){
				ans++;
			}
		}
		ans-=ma*2;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 7544
#include <iostream>
using namespace std;
int n, a[110000], lar, mid;
int main(void){
    // Your code here!
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) lar = max(lar, a[i]);
    for (int i = 0; i < n; i++) {
        if (a[i] == lar) continue;
        mid = (min(mid, lar - mid) < min(a[i], lar - a[i]) ? a[i] : mid);
    }
    cout << lar << ' ' << mid << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int n, A;
vector<int> a;

int main() {
    while (cin >> n >> A) {
        a.resize(n);
        for (int i = 0; i < n; ++i) cin >> a[i];
        sort(a.begin(), a.end());
        int res = n;
        for (auto ai : a) A -= ai;
        cout << res + A/a[0] << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a , b;
    cin >> a >> b;
    if( a % 500 <= b ) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 3616
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;

struct Road{
	int e,next,v;
}r[1000000];int R[21000],num=1;

int inf=19999;

int n,m,ans;
int si,sj,ti,tj,S,T;
int Q[21000],he,ta,p[21000];
char a[110][110];

int F(int i,int j,int k){
	return (k-1)*n*m+(i-1)*m+j;
}

int SR(int i){
	return 2*n*m+i;
}

int SL(int i){
	return 2*n*m+n+i;
}

void ar(int x,int y,int f){
	r[++num]=(Road){y,R[x],f};R[x]=num;
	r[++num]=(Road){x,R[y],0};R[y]=num;
}

void addr(int i,int j,int k){
	if(k==1){
		ar(SR(i),F(i,j,1),inf);
		ar(SL(j),F(i,j,1),inf);
	}if(k==2){
		ar(F(i,j,2),SR(i),inf);
		ar(F(i,j,2),SL(j),inf);
	}
}

int dfs(int u,int f){
	if(u==T)return f;
	int used=0;
	for(int i=R[u];i;i=r[i].next){
		int v=r[i].e;
		if(p[v]!=p[u]+1||r[i].v==0)continue;
		int w=dfs(v,min(f-used,r[i].v));
		r[i].v-=w;
		r[i^1].v+=w;
		used+=w;
		if(used==f)return used;
	}return used;
}

int bfs(){
	memset(p,-1,sizeof(p));
	he=ta=1;
	p[S]=0;Q[ta]=S;
	while(he<=ta){
		int u=Q[he++];
		for(int i=R[u];i;i=r[i].next){
			int v=r[i].e;
			if(r[i].v==0||p[v]!=-1)continue;
			p[v]=p[u]+1;
			Q[++ta]=v;
		}
	}if(p[T]==-1)return 0;
	return 1;
	
}

int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%s",a[i]+1);
		for(int j=1;j<=m;j++){
			if(a[i][j]=='S')si=i,sj=j;
			if(a[i][j]=='T')ti=i,tj=j;
		}
	}if(si==ti||sj==tj){
		printf("-1\n");
		return 0;
	}for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]=='S')addr(i,j,2);
			if(a[i][j]=='T')addr(i,j,1);
			if(a[i][j]=='o'){
				addr(i,j,1);
				addr(i,j,2);
				ar(F(i,j,1),F(i,j,2),1);
			}
		}
	}S=F(si,sj,2);T=F(ti,tj,1);
	while(bfs()){
		ans+=dfs(S,100000);
	}printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	FOR(i,10000) cout<<-1<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   int a[100010];
   int n;
   cin>>n;int flag=0;
   for(int i=1;i<=n;i++)
   {
       scanf("%d",&a[i]);
       if(a[i]%2){flag=1;break;}
   }
   if(flag)printf("first\n");
   else printf("second\n");
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,i,j,a[1010][1010],k[1010]={},qs,p,q,t=0;
  bool d[1010];
  queue<int> que;
  cin >> n;
  for (i=1;i<=n;i++) for (j=0;j<n-1;j++) cin >> a[i][j];
  for (i=1;i<=n;i++) que.push(i);
  while (!que.empty()){
    qs=que.size();
    for (i=1;i<=n;i++) d[i]=false;
    for (i=0;i<qs;i++){
      p=que.front();
      que.pop();
      q=a[p][k[p]];
      if (!d[p] && !d[q] && a[q][k[q]]==p){
        k[p]++;
        k[q]++;
        if (k[p]!=n-1) que.push(p);
        if (k[q]!=n-1) que.push(q);
        d[p]=d[q]=true;
      }
    }
    t++;
  }
  for (i=1;i<=n;i++) if (k[i]!=n-1) break;
  if (i==n+1) cout << t << endl;
  else cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 4224
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}


int main(void){
    ll N,M;
    cin>>N>>M;
    cout<<(N*(N-1)+M*(M-1))/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    string s;
    cin>>s;

    rep(i,0,s.length())
    {
        if ( s[i] == '?' )
        {
            s[i] = 'D';
        }
    }

    cout<<s<<endl;
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

  function<int(int)> s = [](int n) {
    string s = to_string(n);
    int ret = 0;
    for(const auto& c: s) ret += c-'0';

    return ret;
  };

  if(n % s(n) == 0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

int main(){
  vector<vector<char>> s(3,vector<char>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> s.at(i).at(j);
    }}
  cout << s.at(0).at(0) << s.at(1).at(1) << s.at(2).at(2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <time.h>
#define fin(i,n) for (int i = 0; i < (int)(n); i++)
#define fin2(i,j,m,n) fin(i,m) fin(j,n)
using namespace std;

template <typename T> bool contains(vector<T> list, T value) {
	for (T tmp : list) if (tmp == value) return true;
	return false;
}


int main()
{
	int n; cin >> n;
	int res = 0;
	fin(i, n) {
		int tmp; cin >> tmp;
		res += tmp;
	}
	cout << res - n << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>

#define MOD 1000000007
#define DEBUG 0


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}

	return true;
}








int main()
{
	string s, t;
	cin >> s >> t;

	cout << t << s << endl;
	


	return 0;

}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
        int N;
        int min=10000,sum=0;
        cin >> N;
        for(int i=0 ; i<N ; i++ ){
                int x;
                cin >> x;
                sum+=x;
                if(x%10!=0 && x<min)
                        min=x;
        }
        if(sum%10)
                cout<<sum<<endl;
        else if(min%10)
                cout<<sum-min<<endl;
        else
                cout<<0<<endl;
        return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
 
int main(void) {
    long long int n, i = 2;
     
    scanf("%lld", &n);
    printf("%lld:", n);
    while(i*i <= n){
        if(n % i == 0){
            n /= i;
            printf(" %lld", i);
        }
        else i++;
    }
    if(n != 1) printf(" %lld", n);
    printf("\n");
    return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int A,B;
  cin>>A>>B;
  if((A+B)%2==0)cout<<(A+B)/2<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
  return 0;
}


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

std::vector<int> vec,vv;
int n,t,num;

int main(){
    std::cin>>n;
    for(int i=0;i<n;i++){
        std::cin>>t;
        vec.push_back(t);
    }
    vv=vec;
    std::sort(vv.begin(),vv.end());
    for(int i=0;i<n;i++){
        if(vec[i]!=vv[i])num++;
    }
    if(num==0||num==2)std::cout<<"YES"<<std::endl;
    else std::cout<<"NO"<<std::endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc082.contest.atcoder.jp/tasks/arc082_a>
問題文============================================================
 長さ N の整数列 a1,a2,…,aN が与えられます。
 
 各 1≤i≤N に対し、ai に 1 足すか、1 引くか、なにもしないかの三つの操作からどれか一つを選んで行います。
 
 この操作の後、ある整数 X を選んで、ai=X となる i の個数を数えます。
 
 うまく操作を行い、X を選ぶことで、この個数を最大化してください。
=================================================================

解説=============================================================

 
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> a(N);
    for(auto &in:a) cin >> in;
    const int MAX_V = 10e5;
    vector<ll> X(MAX_V+10,0);
    for(int i = 0; i < N;i++){
        if(a[i] != 0) X[a[i]-1]++;
        X[a[i]]++;
        X[a[i]+1]++;
    }
    cout << *max_element(X.begin(),X.end()) << endl;
	return 0;
}


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

int main() {
   long long x,a,b;
   cin >> x >> a >> b;
   if(a-b>=0){
      cout << "delicious"<<endl;
   }else if(-(a-b)>x){
      cout << "dangerous"<<endl;
   }else{
      cout << "safe" <<endl;
   }
   return 0;
}


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

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)


// #define printf(a,...) if(0){}
using ll = int64_t;
constexpr ll mod = ll(1e9 + 7);

int main () {
  ios::sync_with_stdio(0); cin.tie(0);
  int TT = 1;
  // cin >> TT;
  while (TT--) {
    // ll n;
    // cin >> n;
    // vector<ll> A(n);
    // for (auto& x : A) cin >> x;
    ll x1,x2,x3,x4,x5;
    cin >> x1 >> x2 >> x3 >> x4 >> x5;
    if (x1 == 0) {
      cout << 1 << endl;
    } else if (x2 == 0) {
      cout << 2 << endl;
    } else if (x3 == 0) {
      cout << 3 << endl;
    } else if (x4 == 0) {
      cout << 4 << endl;
    } else if (x5 == 0) {
      cout << 5 << endl;
    }
  }
}


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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;



void one_case() {
    vector<vector<int>> a(3, vector<int>(3));
    for (auto& row : a) {
        for (auto& el : row) {
            cin >> el;
        }
    }
    int ok = 1;
    for (int i = 0; i + 1 < 3; ++i) {
        for (int j = 0; j + 1 < 3; ++j) {
            auto up = a[i][j] - a[i][j + 1];
            auto down = a[i + 1][j] - a[i + 1][j + 1];
            ok &= up == down;
        }
    }
    for (int i = 0; i + 1 < 3; ++i) {
        for (int j = 0; j + 1 < 3; ++j) {
            auto up = a[i][j] - a[i + 1][j];
            auto down = a[i][j + 1] - a[i + 1][j + 1];
            ok &= up == down;
        }
    }
    cout << (ok ? "Yes\n" : "No\n");

}


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


    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


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

int	main()
{
	int	N, K;
	cin >> N >> K;
	vector<int>	l(N);
	for (int i = 0; i < N; ++i)
		cin >> l.at(i);
	sort(l.begin(), l.end(), greater<int>());
	int	sum = 0;
	for (int i = 0; i < K; ++i) {
		sum += l.at(i);
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a,b;
    cin>>a>>b;
    if(a>b){
        cout<<">"<<'\n';
    } else if(b>a){
        cout<<"<"<<'\n';
    }else if(a==b){
        cout<<"="<<'\n';
    }
    return(0);
}

Measured memory_bytes: 256
#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 <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#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 <chrono>
#include <condition_variable>
#include <forward_list>
#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>

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)				// repeat
#define repr(i, begin, end) for (ll i = begin - 1; end <= i; i--)		// repeat reverse

std::chrono::system_clock::time_point  start;

void TimeStart(void)
{
	start = std::chrono::system_clock::now();
}

void TimeEnd(void)
{
	auto time = std::chrono::system_clock::now() - start;
	auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
	cerr << endl << msec << " msec " << endl;
}

#endif

struct ChangePair
{
	ll times;	// 書き換え可能回数
	ll after;	// 書き換え後の数字
	bool operator < (const ChangePair& cp) const
	{
		return after < cp.after;
	};
	bool operator > (const ChangePair& cp) const
	{
		return after > cp.after;
	};
};

class ABC127D
{
public:
	ABC127D()
	{
		cin >> n >> m;

		a.resize(n);
		rep(i, 0, n)
			cin >> a[i];

		cp.resize(m);
		rep(i, 0, m)
			cin >> cp[i].times >> cp[i].after;
	}
	void Run(void)
	{
		sort(all(cp), greater<ChangePair>());

		ll i = 0;
		for (const auto& e : cp)
		{
			rep(i, 0, e.times)
				a.push_back(e.after);
			if (2 * n < a.size())
				break;
		}

		ll ans = 0;
		sort(all(a), greater<ll>());
		rep(i, 0, n)
			ans += a[i];

		cout << ans;
	}
private:
	ll n;
	ll m;
	vector<ll> a;
	vector<ChangePair> cp;
};

int main(void)
{
	ABC127D abc127d;
	abc127d.Run();

	return 0;

}

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

int main() {
	long long n, m;
	cin >> n >> m;
	long long ans = 1;
	if (n == 1) {
		cout << m << endl;
		return 0;
	}
	for (long long i = 2; i*n <= m; i++) {
		if ((m - i * n) % i == 0)ans = i;
	}
	cout << ans << endl;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}
class union_find{
	private:
	vector<int> parent,rank,gs;
    int size;
	public:
    int count_group;
    union_find()=default;
    union_find(int n){ init(n); }
    void init(int n){
		size=n;
		count_group=n;
		parent.resize(size);
		rank.assign(size,0);
        gs.assign(size,1);
		for(int i=0; i<size; ++i) parent[i]=i;
	}
	int find(int x){
		if(parent[x]==x) return x;
		else return parent[x]=find(parent[x]);
	}
	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y]){
			parent[x]=y;
            gs[y]+=gs[x];
		} else {
			parent[y]=x;
            gs[x]+=gs[y];
			if(rank[x]==rank[y]) ++rank[x];
		}
		--count_group;
	}
	bool is_same_group(int x,int y){
		return find(x)==find(y);
	}
    int group_size(int x){
        return gs[find(x)];
    };
};

void solve(){
    int n,m;
    cin >> n >> m;
    union_find uf(n);
    vector<vector<int>> rev(m);
    rep(i,0,n){
        int k;
        cin >> k;
        rep(j,0,k){
            int l;
            cin >> l;
            --l;
            rev[l].push_back(i);
        }
    }

    rep(i,0,m){
        for(int j:rev[i]){
            uf.unite(rev[i].front(),j);
        }
    }
    if(uf.count_group==1) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 4608
#include <stdio.h>

int A[100000];

void Do(int N){
  int i, a[3], j, c, C;
  long long S;
  for(i = 0;i < N;i++) scanf("%d", &A[i]);
  a[0] = a[1] = a[2] = 0;
  S = 1;
  for(i = 0;i < N;i++){
    c = C = 0;
    for(j = 0;j < 3;j++){
      if(A[i] == a[j]){
	c++;
	if(C == 0){
	  a[j]++;
	  C = 1;
	}
      }
    }
    S *= c;
    S %= 1000000007;
    if(S == 0) break;
  }
  printf("%lld\n", S);
}

int main(void){
  int N;
  scanf("%d", &N);
  Do(N);
  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner cin = new Scanner(System.in)) {
			final int num1 = cin.nextInt();
			final int num2 = cin.nextInt();
			final int num3 = cin.nextInt();
			final int num = num1 * 100 + num2 * 10 + num3;

			if (num % 4 == 0) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		} finally {
		}
	}

}


Measured memory_bytes: 22868
#[allow(unused_imports)]
use std::cmp::Reverse;

#[allow(unused_imports)]
use proconio::{fastout, input, marker::Chars};

#[allow(unused_imports)]
use itertools::Itertools;

fn rec(i: usize, j: usize, dp: &mut Vec<Vec<i64>>, a: &Vec<i64>) -> i64 {
    if dp[i][j] != 0 {
        return dp[i][j];
    }

    dp[i][j] = if i == j {
        a[i]
    } else {
        (a[i] - rec(i + 1, j, dp, a)).max(a[j] - rec(i, j - 1, dp, a))
    };
    dp[i][j]
}

#[fastout]
pub fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let mut dp = vec![vec![0; n]; n];
    let result = rec(0, n - 1, &mut dp, &a);
    println!("{}", result);
}


Measured memory_bytes: 72740
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int H, W, D; cin >> H >> W >> D;
    vector<pair<int, int>> place(H*W+1);
    rep(i, 0, H) {
        rep(j, 0, W) {
            int A;
            cin >> A;
            place[A] = make_pair(i, j);
        }
    }

    vector<int> mp(H*W+1, 0);
    rep(i, D+1, H*W+1) {
        int sy = place[i-D].first;
        int sx = place[i-D].second;
        int gy = place[i].first;
        int gx = place[i].second;

        mp[i] = mp[i-D] + abs(gx-sx) + abs(gy-sy);
    }

    int Q; cin >> Q;
    rep(qi, 0, Q) {
        int res = 0;
        int L, R; cin >> L >> R;

        cout << mp[R] - mp[L] << "\n";
    }
}

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

int main(){
	int out[200];
	int n, m;
	int count = 0;
	while(cin >> n >> m){
		for(int i = 0; i < 100; i++){
			if(pow(10.0,i) > n+m){
				out[count] = i;
				break;
			}
		}
		count++;
	}
	for(int i = 0; i < count; i++){
		cout << out[i] << endl;
	}
}

Measured memory_bytes: 1204