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

int main() {
    ll n;
    std::cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        sum += a[i];
    }
    sort(a.begin(),a.end());
    if(a[0]==a[n-1]){
        if(a[0]==n-1){
            std::cout << "Yes" << std::endl;
            return 0;
        }
        if(a[0]*2<=n){
            std::cout << "Yes" << std::endl;
            return 0;
        }
        std::cout << "No" << std::endl;
        return 0;
    }
    
    if(a[0]==a[n-1]-1){
        ll x = a[n-1]*n-sum;
        if(a[n-1]-x<=0){
            std::cout << "No" << std::endl;
            return 0;
        }
        if((a[n-1]-x)*2<=n-x){
            std::cout << "Yes" << std::endl;
        }else{
            std::cout << "No" << std::endl;
        }
    }else{
        std::cout << "No" << std::endl;
        return 0;
    }
}

Measured memory_bytes: 4028
n,m = map(int,input().split())
x = []
for _ in range(n):
  a,b = map(int,input().split())
  x.append([a,b])
sx = sorted(x,key=lambda x:x[0])
money = 0
i = 0
for i in range(n):
  a,b = sx[i]
  if m > b:
    money += a*b
    m -= b
  else:
    money += a*m
    print(money)
    exit()
  

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

#define fastio 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ld long double
#define forn(low,high,i) for(i = low; i < high; i++)
#define forrev(high,low,i) for(i = high; i >= low; i--)
#define all(v) v.begin(),v.end()
#define decimal_digits cout << fixed << setprecision(15);

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(long long a, long long b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(long long a, long long b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(long long a, long long b){a %= mod; b %= mod; return (int)((long long) a * b % mod);}
inline int modexpo(long long a, long long b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(long long a, long long b){return mul(a, modexpo(b, mod - 2));}
inline int inv(long long a){return modexpo(a, mod - 2);}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre(){ // Reset each global variable (esp. for graphs)
  
}

void solve(){
  int n, i, j, k;
  cin >> n;
  long long sum = 0;
  for(i = 1; i <= n; i++){
    if(i % 3 and i % 5)
      sum += i;
  }
  cout << sum << '\n';
}

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

  pre();

  int t = 1, T;
  // cin >> t;
  T = t;
  while(t--){
    // cout << "Case #" << T - t << ": ";
    solve();
  }

  ktj();
}


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

using namespace std;

int main()
{
	int a,b;
	while(1){
		cin >> a >> b;
		if(a == 0 && b==0 ) break;
		else {
			if (a>b)	cout << b << " " << a <<endl;
			else cout << a << " " <<b <<endl;
		}
	
	}
	return 0;
}

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

#define pb push_back
#define ll long long

void solution(int n, int w, vector<vector<int> >& wv);
void solution1();

int main(void){
	int n, w;
	cin >> n >> w;
	vector<vector<int> > wv(n, vector<int>(2));
	for(int i = 0;i < n;i++){
		cin >> wv[i][0];
		cin >> wv[i][1];
	}
	solution(n, w, wv);
	// solution1(n, w, wv);
}

void solution(int n, int W, vector<vector<int> >& wv){
	vector<ll> dp(W+1, -1);
	dp[0] = 0;
	for(int i = 0;i < n;i++){
		int w = wv[i][0];
		for(int j = W-w;j >= 0;j--){
			if(dp[j] != -1)
				dp[j+w] = max(dp[j+w], dp[j] + (ll)wv[i][1]);
		}
	}
	for(int i = 1;i <= W;i++){
		dp[i] = max(dp[i], dp[i-1]);
	}
	cout << dp[W] << endl;
	return;
}

Measured memory_bytes: 1024
A,B,C=map(int,input().split())

ans=0
lst=[]
l=[A,B,C]
l.sort()
lst.append(l)
while(1):
    if A%2==1 or B%2==1 or C%2==1:
        print(ans)
        exit()
    a=A
    b=B
    c=C
    A=(b+c)//2
    B=(a+c)//2
    C=(a+b)//2
    ans+=1
    l=[A,B,C]
    #print(l)
    l.sort()
    for i in range(len(lst)):
        cnt=0
        for j in range(3):
            if lst[i][j]==l[j]:
                cnt+=1
        if cnt==3:
            print(-1)
            exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.first << ' ' << p.second << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define MOD 1000000007
#define zeros(x) x&(x-1)^x
#define fi first
#define se second
#define NMAX 500005
const long double PI = acos(-1);


int n;
int main(){
  ios::sync_with_stdio(false);
  cin >> n;
  ll x = 2;
  for (int i=1;i<=n;i++){
    x = 1 + x + x + 1;
  }
  cout << x << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main()
{
    while(true){
        int H, W;
        cin >> H >> W;
 
        if(H==0 && W==0)
            break;
 
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if((i+j)%2==0){
                    cout << '#';
                }
                else{
                    cout << '.';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
 
    return 0;
}


Measured memory_bytes: 3036
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define ALL(a) (a).begin(),(a).end()
#define EACH(e,v) for(auto& e:v)
#define SORT(v) sort(ALL(v))
#define PERM(v) SORT(v);for(bool c##p=1;c##p;c##p=next_permutation(ALL(v)))
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = 1000'000'007;

ll dp[2123][2123];
ll sum[2123][2123];
int s[2123],t[2123];
signed main(){
    int N,M;
    cin>>N>>M;
    rep(i,N)cin>>s[i];
    rep(i,M)cin>>t[i];
    dp[0][0]=1;
    rep(i,N+1)
    {
        rep(j,M+1)
        {
            if(s[i]==t[j]){
                dp[i+1][j]+=dp[i][j]%mod;
                dp[i][j+1]+=dp[i][j]%mod;
            }else{
                dp[i+1][j]+=dp[i][j]%mod;
                dp[i][j+1]+=dp[i][j]%mod;
                dp[i+1][j+1]+=mod;
                dp[i+1][j+1]-=dp[i][j]%mod;

            }
        }
    }
    cout<<dp[N][M]%mod<<endl;
 
}

Measured memory_bytes: 35072
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void)
{
  int n, k;
  char s[MAX];
  scanf("%d %d %s", &n, &k, s);

  int nsize = 0, num[MAX]; // 1-0-...-0-1と並ぶ配列
  int now = 1;              // 今見ている数
  int cnt = 0;              // 今見ている数の連続して並んでいる数
  rep(i, 0, n) {
    if (s[i] == (char)('0' + now)) cnt++;
    else {
      num[nsize++] = cnt;
      now = 1 - now;
      cnt = 1;
    }
  }
  num[nsize++] = cnt;

  // 最後が0で終わっている場合(1-0-...1-0)
  // 最後を1で終わっている配列にする(1-0-...-0-1)
  if (nsize % 2 == 0) num[nsize++] = 0;

  /********** 尺取法 ***********/

  // int range = 2 * k + 1; // 尺
  // int ans = 0;

  // int left = 0;
  // int right = 0;
  // int tmp = 0; // [left, right)のsum(仮ans)

  // for (int i = 0; i < nsize; i += 2) { // 左端に合わせてループ
  //   int nleft = i;
  //   int nright = min(nleft + range, nsize);

  //   // 左差分を計算
  //   while (left < nleft) {
  //     tmp -= num[left];
  //     left++;
  //   }

  //   // 右差分を計算
  //   while (right < nright) {
  //     tmp += num[right];
  //     right++;
  //   }
  //   ans = max(ans, tmp);
  // }

  /********** 累積和 ***********/

  // 累積和を計算
  // sum: 0 2 3 5 7
  // num:  2 1 2 2
  // num[left, right)の和 = sum[right] - sum[left] 
  int sum[MAX];
  sum[0] = 0;
  rep(i, 0, nsize + 1) {
    sum[i + 1] = sum[i] + num[i];
  }

  int ans = 0;
  int range = 2 * k + 1;
  //　1-0-1-...-0-1の1に着目するため、2ずつ足していく
  for (int i = 0; i < nsize; i += 2) {
    int left = i;
    int right = min(i + range, nsize);
    ans = max(ans, sum[right] - sum[left]);
  }

  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

int main(){
	int H, A, mod, attack;
	scanf("%d %d", &H, &A);
	getchar();
	
	mod = H % A;
	attack = H / A;
	mod == 0 ? printf("%d", attack) : printf("%d", attack+1); 
	
	return 0;
}

Measured memory_bytes: 1732
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll r,d,x;cin>>r>>d>>x;
  rep(i,10){
    x=r*x-d;
    cout<<x<<endl;
  }
}

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

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

const ll MOD = 1000 * 1000 *1000 + 7 ;
inline void chadd(ll &a, const ll b) { a = (a + b) % MOD;}
inline ll add(const ll a, const ll b){ return (a + b) %  MOD;}
inline void chsub(ll &a, const ll b) { a = (a - b + MOD) % MOD;}
inline ll sub(const ll a, const ll b){ return (a - b + MOD) % MOD; }
inline void chmul(ll &a, const ll b) { a = (a * b) %  MOD;}
inline ll mul(const ll a, const ll b){ return (a * b) %  MOD;}

const int MOD_TABLE_SIZE = 1000000 + 10;
ll inv[MOD_TABLE_SIZE];
ll fac[MOD_TABLE_SIZE];
ll facinv[MOD_TABLE_SIZE];

void mod_table_init() {
  inv[1] = 1;
  for(int i = 2; i < MOD_TABLE_SIZE; i++) {
    inv[i] = MOD - (MOD / i) * inv[(int)MOD % i] % MOD;
  }
  fac[0] = facinv[0] = 1;
  for(int i = 1; i < MOD_TABLE_SIZE; i++) {
    fac[i] = (fac[i-1] * (ll)i) % MOD;
    facinv[i] = (facinv[i-1] * inv[i]) % MOD;
  }
}

inline ll P(int a, int b) {
  if(a<b) return 0LL;
  return fac[a] *  facinv[a-b] % MOD;
}

inline ll C(int a, int b) {
  if(a<b) return 0LL;
  return (fac[a] * facinv[b] % MOD) * facinv[a-b] % MOD;
}

inline ll H(int a, int b) {
  return C(a+b-1,b);
}

ll dp1[100000 + 100];
ll dp2[100000 + 100];

int main() {
  mod_table_init();
  int N; cin>>N;
  vector<ll> x(N, 0), d(N-1, 0);
  REP(i,N) cin>>x[i];
  REP(i,N-1) d[i] = x[i+1] - x[i];

  dp1[0] = fac[N-1];
  for(int i = 0; i < N-1; i++) {
    ll tmp = dp1[i];
    int a = 1;
    int b = i+1;
    int c = a + b;
    ll d = mul(tmp, inv[c]);
    dp1[i+1] = mul(d, b);
  }

  ll ans = 0;
  dp2[0] = dp1[0];
  for(int i = 1; i < N; i++) dp2[i] = add(dp2[i-1], dp1[i]);
  for(int i = 0; i < N-1; i++) {
    ll tmp = dp2[i];
    chmul(tmp, d[i]);
    chadd(ans, tmp);
      //      cout << i << " " << j << " " << dp[i][j] << " " << ans << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 26752
"""
Writer: SPD_9X2
https://atcoder.jp/contests/abc044/tasks/arc060_b

f(b,n)ってbが大きくなるほど大きくなる？(単調増加になる?)
→そんなことはない
nより大きかったら不可能。最小はn進法で桁和1

3桁以上になる物は全探索する
2桁は、良い感じにすべて調べ上げる
実装だるそ～

2桁の時 xyとなるとする
n//b = x
n%b  = y

n = bx+y
x+y = s

(n-S)//x+1 = b
かつ S >= x >= S-b

xについてn-sの約数を全列挙して、bを求める & 下の条件を満たしているか確認すればよい？
上の条件を満たしているbが必ずしも元の条件を満たすわけではなさそう？
ちゃんと満たしているか確認してあげる
"""

def f(b,n):

    if n < b:
        return n
    else:
        return f(b,n//b) + (n%b)

import sys
n = int(input())
s = int(input())

if s > n:
    print (-1)
    sys.exit()
elif s == n:
    print (n+1)
    sys.exit()

for b in range(2,int(n**0.5+10)):

    if f(b,n) == s:
        print (b)
        sys.exit()

#ここからだるいパート
ans = float("inf")

for x1 in range(1,10**6):

    if (n-s) % x1 == 0:

        x2 = (n-s)//x1

        b1 = (n-s)//x1+1
        if b1 ** 2 > n and s >= x1 >= s-b1 and f(b1,n) == s:
            ans = min(ans , b1)

        b2 = (n-s)//x2+1
        if b2 **2 > n and s >= x2 >= s-b2 and f(b2,n) == s:
            ans = min(ans , b2)

if ans == float("inf"):
    print (-1)
else:
    print (ans)


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

#define endl '\n'
#define int long long

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

	int n, k; cin >> n >> k;
	vector<int> vec(n);
	for(int &i : vec) cin >> i;
	sort(vec.begin(), vec.end());
	int sum = 0;
	for(int i = 0; i < k; i ++) sum += vec[i];
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cout.precision(10);
    int n, a;
    cin >> n >> a;
    cout << n * n - a << endl;
    return 0;
}

Measured memory_bytes: 256
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
    int n;
    cin>>n;
    bool flag=false;
    for(int i=1;i<10;i++){
       if(n%i==0 && n/i<10){
         flag=true;
       }
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int MAX_N = 100000;
int MAX_W = 100000;

int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  std::priority_queue<
    int,                // 要素の型はint
    std::vector<int>,   // 内部コンテナはstd::vector (デフォルトのまま)
    std::greater<int>   // 昇順 (デフォルトはstd::less<T>)
  > ans;
  int A,B,S;
  A = 0;
  B = 0;
  S = 0;
  REP(i,N){
    cin >> v.at(i);
    S += v.at(i);
  }
  std::vector<int> T(N);
  REP(i,N){
    A += v.at(i);
    B = S - A;
    T.at(i) = abs(A - B);
    ans.push(T.at(i));
  }
  cout << ans.top() << endl;

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

const int MAXN= 100+10;
string s[MAXN],t[MAXN];

map<string,int> m1;
map<string,int>::iterator it;

int main(){
	int N,M;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		cin >> s[i];
		it=m1.find(s[i]);
		if(it!=m1.end()){it->second++;}
		else{m1.insert(pair<string,int>(s[i],1));}
	}
	scanf("%d",&M);
	for(int i=0;i<M;i++){
		cin >> t[i];
		it=m1.find(t[i]);
		if(it!=m1.end()){it->second--;}
	}
	
	it = m1.begin();
	
	int max = 0;
	for(it;it!=m1.end();it++){
		if(it->second > max)	max = it->second;
	} 
	printf("%d\n",max);
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n;cin>>n;
  vector<ll> a(n);rep(i,n)cin>>a[i];
  vector<ll> b(n+1);
  rep(i,n)b[i+1] = (b[i] + a[i]);
  
  ll ans = 0;
  rep(i,n-1){
    ll tmp = b[n] - b[i+1];
    tmp %= INF;
    ans += a[i]*tmp%INF;
    ans %= INF;
  }

  print(ans);
  return 0;
}

Measured memory_bytes: 6360
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

void bra(char ch, int &r, int &c, int &s)
{
  if(ch == '(') r=r+1; if(ch == ')') r=r-1;
  if(ch == '{') c=c+1; if(ch == '}') c=c-1;
  if(ch == '[') s=s+1; if(ch == ']') s=s-1;
}

int check(int r, int c, int s, vector<int> exp[4]){
  rep(i, exp[0].size()){
    //    cout << exp[0][i]*r + exp[1][i]*c + exp[2][i]*s << " " << exp[3][i] << endl;
    if(exp[0][i]*r + exp[1][i]*c + exp[2][i]*s != exp[3][i]) return 0;
  }
  return 1;
}

int main()
{
  int p, q;
  while(1){
    cin >> p >> q;
    if(!q && !p) return 0;
    set<int>R, C, S;
    vector<int> exp[4];
    map<pii, int>tuple;
    int r=0, c=0, s=0;    
    rep(i, p){
      string P; cin >> P;
      int peri = 0;
      rep(j, P.size()){
	if(P[j] != '.'){
	  exp[0].push_back(r); exp[1].push_back(c); exp[2].push_back(s);
	  exp[3].push_back(peri);
	  tuple[pii(r,pi(c,s))] = peri;
	  //	  cout << r << " " << c << " " << s << " " << peri << endl;
	  for(;j<P.size();j++)
	    bra(P[j], r, c, s);
	  break;
	}
	peri++;
      }
    }

    rep(r,20) rep(c,20) rep(s,20){
      if(check(r+1, c+1, s+1, exp)){
	R.insert(r+1);
	C.insert(c+1);
	S.insert(s+1);
      }
    }

    //    cout << R.size() << endl;
    //    for(auto r: R) cout << r << " "; cout << endl;
    //    for(auto r: C) cout << r << " ";cout << endl;
    //    for(auto r: S) cout << r << " ";cout << endl;
    //    Cout << *R.begin() << " " << *C.begin() << " " << *S.begin() << endl;
    r=0, c=0, s=0;
    rep(i, q){
      if(i!=0) cout << " ";
      string Q; cin >>Q;
      if(tuple.find(pii(r,pi(c,s))) != tuple.end())
	cout << tuple[pii(r,pi(c,s))];
      else if(R.size() != 1 && r || C.size() != 1 && c || S.size() != 1 && s)
	cout << -1;
      else
	cout << (*R.begin())*r + (*C.begin())*c + (*S.begin())*s;
      for(auto x: Q)
	bra(x, r, c, s);
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3064
N,M = map(int, input().split())
K_A = [list(map(int, input().split())) for _ in range(N)]
 
tmp = set(K_A[0][1:K_A[0][0]+1])
for i in range(1,N):
    tmp = tmp & set(K_A[i][1:K_A[i][0]+1])
print(len(tmp))

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include<complex>

using namespace std;

typedef long long            ll;
typedef unsigned             ui;
typedef unsigned long long   ull;
typedef pair<int,int>        i_i;
typedef pair<ll,int>         ll_i;
typedef pair<ll,ll>          ll_ll;
typedef pair<double,int>     d_i;
typedef pair<double,double>  d_d;
typedef vector<int>          vi;
typedef vector<vector<int> > vii;

#ifdef DEBUG
#define dprintf      printf
#define dputs        puts
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dputs        (1)?0:puts
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      x.begin(),x.end()
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__)
#define array(T,id,n) T id[(n)]; for(int i=0;i<(n);i++)cin>>id[i]
#define putv(n)     cout<<(n)<<endl

//#define int long long
#ifndef int
#define INF __INT32_MAX__
#else
#define INF __INT64_MAX__
#endif

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  in(int,n);
  array(int,v,n);
  array(int,c,n);
  int i;
  int sum=0;
  rep(i,n){
    int x = v[i] - c[i];
    if(x > 0)
      sum +=x;
  }
  putv(sum);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<functional>
#include<string>
#include<cmath>

using namespace std;
using ll  = long long;
template <typename T> T In() {
    T t;
    cin >> t;
    return t;
}
template <typename T> vector<vector<T>> Vec2(int i, int j, T ini = 0) {
    vector<vector<T>> vec(i, vector<T>(j, ini));
    return move(vec);
}
template <typename T> vector<vector<vector<T>>> Vec3(int i, int j, int k, T ini = 0) {
    vector<vector<vector<T>>> vec(i, vector<vector<T>>(j, vector<T>(k, ini)));
    return move(vec);
}

int main() { 
    int N = In<int>();
    vector<pair<int,int>> AIs(N);
    for(int i = 0; i < N; i++){
        int a = In<int>();
        AIs[i] = make_pair(a, i);
    }
    sort(AIs.begin(), AIs.end(), greater<pair<int,int>>());
    for(int i = 0; i < N; i++) {
        if(i==AIs[0].second)
            cout << AIs[1].first << endl;
        else
            cout << AIs[0].first << endl;
    }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
template<typename T>
struct edge{
    int f,t;
    T c;
    int id;
    edge(){};
    edge(int f,int t,T c,int id = 0):f(f),t(t),c(c),id(id){};
    bool operator< (const edge &s){
        return c < s.c;
    }
};

template<typename T>
struct graph{
    std::vector<std::vector<edge<T> > > data;
    graph(int v):data(v){};
    void add_edge(edge<T> &e){
        data[e.f].push_back(e);
    }
    void add_edge(int f,int t,T c){
        data[f].emplace_back(f,t,c);
    }
    size_t size(){
        return data.size();
    }
    std::vector<edge<T>> make_edges(){
        std::vector<edge<T>> r;
        for(auto &i:data)std::copy(i.begin(),i.end(),std::back_inserter(r));
        return r;
    }
};

template<typename T>
std::vector<T> dijkstra(graph<T> &g,int s){
    using state = std::pair<T,int>;
    //priority_queue
    std::priority_queue<state,std::vector<state>,std::greater<state>> q;
    q.emplace((T)0,s);
    //data init
    std::vector<T> data(g.size(),std::numeric_limits<T>::max()/4);
    data[s] = (T)0;
    //solve
    while(!q.empty()){
        state cur = q.top();q.pop();
        T c = cur.first; int pos = cur.second;
        if(data[pos] < c)continue;
        for(auto &e : g.data[pos]){
            if(c + e.c < data[e.t]){
                data[e.t] = c + e.c;
                q.emplace(c + e.c, e.t);
            }
        }
    }
    return data;
}

int main(){
    using namespace std;
    using i64 = long long int;
    int v,e,r;
    cin >> v >> e >> r;
    graph<i64> g(v);
    int f,t;i64 d;
    for(int i=0;i<e;++i){
        cin >> f >> t >> d;
        g.add_edge(f,t,d);
    }
    vector<i64> res = dijkstra(g,r);
    i64 INF = numeric_limits<i64>::max()/4;
    for(auto &x:res){
        if(x!=INF)cout << x << endl;
        else cout << "INF" << endl;
    }
}


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

long dp[1001][1001];
int h,w;
string s[1001];
/*
int solve(int i,int j)
{
    
    
    if(i==-1 || j==-1 || s[i][j]=='#'){return 0;}
    else if(dp[i][j]) {return dp[i][j];} 
    else if(i==0 && j==0) {dp[i][j]=1;return 1;}
    else {
        
        (dp[i][j]+= solve(i-1,j))%=1000000007;
        (dp[i][j]+= solve(i,j-1))%=1000000007;
        return dp[i][j];
    }
}*/
int main() {
	cin>>h>>w;for(int i=0;i<h;++i)cin>>s[i];
	dp[0][0]=1;
	for(int i=1;i<h;++i)
	    if(s[i][0]=='.')dp[i][0]=dp[i-1][0];
	for(int j=1;j<w;++j)
	    if(s[0][j]=='.')dp[0][j]=dp[0][j-1];
	for(int i=1;i<h;++i)
	 {   for(int j=1;j<w;++j)
	        {     if(s[i][j]=='.')
	              dp[i][j]= (dp[i-1][j]+dp[i][j-1])%1000000007;
	              
	        }
    }
	        
	cout<<dp[h-1][w-1];
	return 0;
}

Measured memory_bytes: 9088
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
int n,a[200010],ans;
bool p[200010];
bool check(int mid){
	for(int i=1;i<=n*2-1;i++)
		p[i]=(a[i]<=mid);
	for(int i=0;i<n-1;i++){
		if(p[n-i]==p[n-i-1])
			return p[n-i];
		if(p[n+i]==p[n+i+1])
			return p[n+i+1];
	}
	return p[1];
}
int rd(){
	int x=0;
	char c;
	do c=getchar();
	while(!isdigit(c));
	do{
		x=(x<<1)+(x<<3)+(c^48);
		c=getchar();
	}while(isdigit(c));
	return x;
}
int main(){
	n=rd();
	for(int i=1;i<=n*2-1;i++)
		scanf("%d",a+i);
	int l=2,r=n*2-2;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid)){
			ans=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	printf("%d",ans);
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll T;
ll a,b,c,d;

int main(){
  cin>>T;
  while(T--){
    cin>>a>>b>>c>>d;
    if(d<b){
      cout<<"No"<<endl;
      continue;
    }
    if(a-b>c){
      ll x=(a-c+b-1)/b;
      x--;
      a-=x*b;
    }
    if(a-b<0){
      cout<<"No"<<endl;
      continue;
    }
    if(d==b){
      cout<<"Yes"<<endl;
      continue;
    }
    ll dlt=d-b;
    ll g=__gcd(dlt,b);
    //dbg(dlt); dbg(g);
    if(c+g<b)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;    
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    int N, K;
    
    cin >> N >> K;
    
    int n=1;
    while(n<K) {
        n *= 2;
    }
    
    double ans=0;
    for(int i=1; i<N+1; i++) {
        if(n==1) {
            ;
        } else if(i*(n/2)>=K) {
            n/=2;
        }
        ans += (double)1/(double)(n*N);
    }
    
    cout << setprecision(15) << 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)
using Graph = vector<vector<int>>;

int main() {
    int N,Q,a,b,p,x;
    queue<int> q;
    cin >> N >> Q;
    Graph G(N);
    vector<int> c(N,0);
    vector<bool> seen(N,0);

    rep(i,N-1) {
        cin >> a >> b;
        a--, b--;
        G.at(a).push_back(b);
        G.at(b).push_back(a);
    }
    rep(i,Q) {
        cin >> p >> x;
        p--;
        c.at(p) += x;
    }

    q.push(0);
    while(!q.empty()) {
        int x = q.front();
        q.pop();
        seen.at(x) = 1;

        for(auto nx : G.at(x)) {
            if(seen.at(nx))
                continue;
            c.at(nx) += c.at(x);
            q.push(nx);
        }
    }

    rep(i,N)
        cout << c.at(i) << " ";
    cout << endl;
}

Measured memory_bytes: 15604
#![allow(unused_imports)]
#![allow(dead_code)]
use datastructure::*;
use grapth::*;
use input_scanner::*;
use math::*;
use string_algorithm::*;
use util::*;

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};

fn main() {
    let mut scan = Scanner::new();
    let n:usize = scan.next();
    let (mut a,mut b,mut c,mut d) = (0,0,0,0);

    for _ in 0..n {
        let s: String = scan.next();
        if s == "AC"{
            a+=1;
        } else if s=="WA"{
            b+=1;
        }else if s=="TLE"{
            c+=1;
        }else{
            d+=1;
        }
    }
    println!("AC x {}", a);
    println!("WA x {}", b);
    println!("TLE x {}", c);
    println!("RE x {}", d);
}

mod datastructure {}
mod grapth {}
mod math {}
mod string_algorithm {}
mod util {}
mod input_scanner {
    pub struct Scanner {
        bytes: Vec<u8>,
        begin: usize,
        end: usize,
    }

    impl Scanner {
        pub fn new() -> Self {
            use std::io::Read;
            let mut buffer: Vec<u8> = Vec::new();
            std::io::stdin().read_to_end(&mut buffer).unwrap();
            let end = (0..buffer.len())
                .find(|i| buffer[*i].is_ascii_whitespace())
                .unwrap_or(buffer.len());
            Scanner {
                bytes: buffer,
                begin: 0,
                end: end,
            }
        }
        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            let s: &str =
                unsafe { std::str::from_utf8_unchecked(&self.bytes[self.begin..self.end]) };
            let ret: T = s.parse::<T>().ok().expect("Parse error.");
            self.skip();
            ret
        }
        pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
        pub fn next_word(&mut self) -> Vec<u8> {
            let r = Vec::from(&self.bytes[self.begin..self.end]);
            self.skip();
            r
        }
        fn skip(&mut self) {
            self.begin = (self.end..self.bytes.len())
                .find(|i| !self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
            self.end = (self.begin..self.bytes.len())
                .find(|i| self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
        }
    }
}


Measured memory_bytes: 2420
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

X = n()
max_beki = 1

for b in range(2, X):
    num = b * b
    while num <= X:
        if num > max_beki:
            max_beki = num
        num *= b
print(max_beki)


Measured memory_bytes: 3060
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
n,k = map(int, stdin.readline().rstrip().split())
#numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
#word = [stdin.readline().rstrip() for _ in range(n)]
#number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
#zeros = [[0] * w for i in range(h)]

win = 0

if n>k:
    win += (n-k) / n
    limit = k
else:
    limit = n

base = 1 / n
for i in range(1,limit+1):
    u = i
    j = 0
    while u < k:
        u *= 2
        j += 1
    win += base * (1/2)**j

print(win)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int d[105];

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  int n, k; read(n), read(k);
  for (RI i = 1; i <= k; ++i) {
    int x; read(x);
    for (RI j = 1, y; j <= x; ++j)
      read(y), ++d[y];
  }
  int ans = 0;
  for (RI i = 1; i <= n; ++i) ans += !d[i];
  printf("%d\n", ans);

  return 0;
}

// created by Daniel yuan


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

int main() {
  int N;
  cin >> N;
  int dmin = 1000;
  
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    int d = 0;
    while (A % 2 == 0) {
      A /= 2;
      d++;
    }
    dmin = min(dmin, d);
  }
  cout << dmin << endl;
}
    

Measured memory_bytes: 256
while gets
  l=$_.split.map(&:to_i)
  fj=[1,4,1,4,1,2,1,2]
  max,ans=0,[0]
  8.times do |i|
    count=0
    8.times do |j|
      count+=[fj[j],l[j]].min
    end
    fj.rotate!(1)
    if count > max
      max = count
      ans = [i]
    elsif count == max
      ans << i
    end
  end
  if ans.size > 1
    mnum = []
    ans.each do |a|
      mnum << fj.rotate(a).join.to_i
    end
    puts "#{fj.rotate(ans[mnum.index(mnum.min)]).join(" ")}"
  else
    puts "#{fj.rotate(ans[0]).join(" ")}"
  end
end

Measured memory_bytes: 8744
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll inf = numeric_limits<ll>::max()/3;

int main(void){
  int n;
  cin >> n;
  if(n == 3){
    cout << "2" << " "
         << "5" << " "
         << "63" <<endl;
    return 0;
  }else if(n == 4){
    cout << "2" << " "
         << "3" << " "
         << "4" << " "
         << "9" <<endl;
    return 0;
  }else if(n == 5){
    cout << "2" << " "
         << "3" << " "
         << "4" << " "
         << "6" << " "
         << "9" <<endl;
    return 0;
  }
  set< ll > ans;
  int cnt = 0;
  ll calc = 0,last = 0,lap = 0;
  ll a[] = {2,3,4,6};  
  while(cnt < n){
    for(int i = 0;i < 4;++i){
      if(cnt == n)break;
      ans.insert(a[i]);
      calc += a[i];
      a[i] += 6;
      ++cnt;
    }
    ++lap;
  }
  ll base = (last/6)*6;
  if(calc % 6 == 1){
    ans.erase(9);
    ans.insert(a[0]);
  }else if(calc % 6 == 2){
    ans.erase(8);
    ans.insert(a[3]);    
  }else if(calc % 6 == 3){
    ans.erase(9);
    ans.insert(a[3]);    
  }else if(calc % 6 == 4){
    ans.erase(6);
    ans.insert(a[0]);    
  }else if(calc % 6 == 5){
    ans.erase(8);
    ans.insert(a[1]);    
  }
  int f = 0;
  for(ll x : ans){
    if(f){
      cout << " " << x;
    }else{
      cout << x;
      f = 1;
    }
  }
  cout << endl;
  return 0;
}


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

int main(){
    int N,K;cin>>N>>K;
    int info[N];
    rep(i,N)cin>>info[i];
    cout<<(N-2)/(K-1)+1<<endl;
    return 0;
}

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = 1;
    fact[1] = 1;
    for(int i=2; i<=num; i++){
        fact[i] = fact[i-1] * i % MOD;
    }
}

void create_seq_inv_mod(int num){
    seq_inv[0] = 1;
    seq_inv[1] = 1;
    for(int i=2; i<=num; i++){
        seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
    }
}

void create_fact_inv_mod(int num){
    fact_inv[0] = 1;
    fact_inv[1] = 1;
    for(int i=2; i<=num; i++){
        fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
    }
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t dp[3002];

int main(){
    int H, W, N;
    cin >> H >> W >> N;
    vector<pair<int, int>> pts = {{0, 0}, {H-1, W-1}};
    for(int i=0; i<N; i++){
        int x, y;
        cin >> x >> y;
        pts.push_back({x-1, y-1});
    }
    sort(pts.begin(), pts.end());

    create_mod_tables(H+W);
    
    dp[0] = 1;
    for(int i=1; i<=N+1; i++){
        for(int j=0; j<i; j++){
            int xi = pts[i].first, yi = pts[i].second;
            int xj = pts[j].first, yj = pts[j].second;
            if(xj <= xi && yj <= yi) add(dp[i], MOD - dp[j] * comb_mod(xi-xj+yi-yj, yi-yj) % MOD);
        }
    }
    cout << (MOD-dp[N+1]) % MOD << endl;
    return 0;
}

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

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

        vector<int> a(n);
        rep (i, n) {
                cin >> a[i];
                a[i]--;
        }

        vector<int> mp(n, -1);
        int i = 0, m = 0;
        for (; mp[i] == -1; i = a[i], m++) {
                mp[i] = m;
        }

        if (k < mp[i]) {
                int s = 0;
                rep (j, k) {
                        s = a[s];
                }
                cout << s + 1 << endl;
        } else {
                int s = 0;
                rep (j, mp[i] + (k - mp[i]) % (mp[i] - m)) {
                        s = a[s]; 
                }
                cout << s + 1 << endl;
        }

        return 0;
}


Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
 string s;
 int count=0,i;
 cin>>n;
 cin>>s;
 for(i=0;i<=n-3;i++)
   if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
      count++;
    cout<<count;  
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] aArr = new int[n];

        for (int i = 0; i < n; i++) {
            aArr[i] = sc.nextInt();
        }

        Arrays.sort(aArr);

        System.out.println(aArr[aArr.length - 1] - aArr[0]);
    }
}


Measured memory_bytes: 23252
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
#include <queue>
#include <functional>
#include <iterator>
#include <list>
#include <unordered_map>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int
#define pint pair<int, int>

#define M_DEBUG 1
#define PI 3.141592653589793

#define E '\n'

#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define INF (1e18)

const ll MAX = 1000000000;
const ll MOD = 1e9 + 7;

ull a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

ll aabs(ll a) {
    if (a < 0) return -a;
    return a;
}

int main(void) {
    cin >> a >> b >> c;
    if ((a == b && a != c && b != c) || (a != b && a == c && b != c) || (a != b && a != c && b == c) || (a != b && a == c && b != c)) cout << "Yes" << endl; 
    else cout << "No" << endl; 

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int s;
  scanf("%d",&s);
  int h=s/3600;
  int m=(s-h*3600)/60;
  s=s-(h*3600+m*60);
  printf("%d:%d:%d\n",h,m,s);
  return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;

int main() {
  vector< vector<int> > c(3, vector<int>(3));
  vector<int> a(3);
  a[0] = 0;
  vector<int> b(3);  
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> c[i][j];
      if (i == 0) {
	b[j] = c[i][j];
      } else {
	a[i] = c[i][j] - b[j];
      }
    }
  }

  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (c[i][j] != a[i] + b[j]) {
	cout << "No" << endl;
	return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <cstring>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <stack>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int maxn = 1000050;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const ll linf = 2e18;
ll power(ll x, ll y)
{
    ll ans = 1;
    while (y)
    {
        if (y & 1)
            ans = ans * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return ans;
}

ll gcd(ll x, ll y)
{
    if (x % y == 0)
        return y;
    return gcd(y, x % y);
}

vector<int> G[maxn];
int vis[maxn];
queue<int> q;

int main()
{
    int i, j, k, t, n, m, x, y;
    scanf("%d %d", &n, &m);
    for (i = 0; i < m; i++)
    {
        scanf("%d %d", &x, &y);
        G[x].push_back(y);
        G[y].push_back(x);
    }
    k = 0;
    vis[1] = 1;
    q.push(1);
    while (!q.empty())
    {
        x = q.front();
        q.pop();
        for (auto v : G[x])
        {
            if (vis[v])
                continue;
            k++;
            vis[v] = x;
            q.push(v);
        }
    }
    if (k != n - 1)
        printf("No\n");
    else
    {
        printf("Yes\n");
        for (i = 2; i <= n; i++)
            printf("%d\n", vis[i]);
    }
    return 0;
}


Measured memory_bytes: 31676