akhauriyash/Code-Regression huggingface dataset:
// D - Moving Piece

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

ll N, K;
ll P[5000];
ll C[5000];

ll get_max_score(int i, ll k, ll base_score) {
	ll max_score = -INF;
	ll score = base_score;
	int next_i = P[i];
	for (int j=0; j<k; j++) {
		score += C[next_i];
		max_score = max(max_score, score);
		next_i = P[next_i];
		//cout << "  j=" << j << " score=" << score << " max_score=" << max_score << endl; // **** debug ****
	}

	return max_score;
}

// マスiからスタート
ll solve(int i) {
	// まずループの長さと一周した時のスコアをカウント
	int loop_len = 0;
	ll loop_score = 0;
	int next_i = P[i];
	while(1) {
		loop_len++;
		loop_score += C[next_i];
		if (next_i == i) break;
		else next_i = P[next_i];
	}

	//cout << "i=" << i << " loop_len=" << loop_len << " loop_score=" << loop_score << endl; // **** debug ****

	// K = ループs回 + tマス移動 の時、s回目のループ以降をシミュレート
	int s = K / loop_len;
	int t = K % loop_len;

	if (loop_score <= 0) {
		// loop_scoreが0以下の時は高々1回ループを見ればOK
		s = min(s, 1);
	}

	ll max_score = -INF;

	// s回目のループ
	if (s >= 1) {
		ll base_score = (s-1) * loop_score;
		max_score = get_max_score(i, loop_len, base_score);
	}

	// 余りのtマス移動
	ll base_score = s * loop_score;
	if (t > 0) max_score = max(max_score, get_max_score(i, t, base_score));

	return max_score;
}

int main() {
	cin >> N >> K;

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

	ll tot = 0;
	for (int i=0; i<N; i++) {
		cin >> C[i];
		tot += C[i];
	}

	ll ans = -INF;
	for (int i=0; i<N; i++) {
		ans = max(ans, solve(i));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3692
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

string S;
ll mod = 1000000007;
ll dp[100005][13];

int main(void){
    // Your code here!
    cin >> S;
    int n = S.size();
    
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        int c;
        if(S[i] == '?') c = -1;
        else c = S[i] - '0';
        
        for(int j = 0; j < 10; j++){
            if(c != -1 && c != j) continue;
            
            for(int ki = 0; ki < 13; ki++){
                dp[i+1][(10*ki + j) % 13] += dp[i][ki];
                dp[i+1][(10*ki + j) % 13] %= mod;
            }
        }
        
        for(int j = 0; j < 13; j++) dp[i+1][j] %= mod;
    }
    
    cout << dp[n][5] << endl;
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define endl '\n'
#define pii pair<int,int>
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,k; cin>>n>>k;
    ld arr[n],ans1=0,ans=-1;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        if(i<k){
            ld temp=(arr[i]+1)/2;
            ans1+=temp;
        }
    }
    ans=ans1;
    //cerr<<ans1<<endl;
    for(int i=0;i<n-k;i++){
        ld temp1=(arr[i+k]+1)/2,temp2=(arr[i]+1)/2;
        ans1+=(temp1-temp2);
        ans=max(ans,ans1);
        //cout<<ans1<<endl;
    }
    cout<<fixed<<sp(12)<<ans<<endl;
}

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

int main(){
	int N;
	cin >> N;
	int a[N];
	for(int i=0; i<N; i++) cin >> a[i];

	int c=1, Light=a[0];

	if(Light==2){
		cout << 1 << endl;
		return 0;
	}
	while(1){
		c++;
		Light=a[Light-1];
		if(Light==1||c>N){
			cout << -1 << endl;
			break;
		} else if(Light==2){
			cout << c << endl;
			break;
		}
	}
}


Measured memory_bytes: 640
import sys

def main():
    x,n = list(map(int, input().split()))
    if n==0:
        print(x)
        return

    ps = list(map(int, input().split()))

    if not x in ps:
        print(x)
        return

    for i in range(1,int((n+1)/2)+1):
        if not x-i in ps:
            print(x-i)
            return

        if not x+i in ps:
            print(x+i)
            return

main()

Measured memory_bytes: 9192
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int totalTime = 0;
        ArrayDeque<Process> queue = new ArrayDeque<Process>();
        for (int i=0; i<n; i++){
            String name = sc.next();
            int time = sc.nextInt();
            Process process = new Process(name, time);
            queue.offerLast(process);
        }
        while(queue.size() > 0){
            Process process = queue.pollFirst();
            int time = process.getTime();
            if(time <= q){
                totalTime += time;
                System.out.println(process.getName() + " " + totalTime);
            }else{
                totalTime += q;
                process.reduceTime(q);
                queue.offerLast(process);
            }
        }

    }
    static class Process{
        private String name;
        private int time;
        public Process(String name, int time){
            this.name = name;
            this.time = time;
        }
        public int getTime(){
            return this.time;
        }
        public String getName(){
            return this.name;
        }
        public void reduceTime(int q){
            this.time -= q;
        }

    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw`(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;
template<class T> void dprint(T s){
  if(DEBUG){ cout << s << "\n"; }
}

void solve(){
  ll N; cin>>N;
  ll ans = 0LL;
  for(int c=1;c<N;++c){
    ll temp = N-c;
    ll x = 2;
    vector<ll> v;
    map<ll,int> mp;
    while(x<sqrt(temp)+2){
      while(temp%x==0){
        temp /= x;
        ++mp[x];
        if(mp[x]==1){
          v.push_back(x);
        }
      }
      ++x;
    }
    if(temp>1){
      ++mp[temp];
      v.push_back(temp);
    }
    ll semp = 1LL;
    for(auto x:v){
      semp *= (mp[x]+1);
    }
    dprint(semp);
    ans += semp;
  }
  cout << ans << "\n";
}
int main(int argc, char *argv[]){
  if(argc>1 && argv[1][0]=='D'){ DEBUG = 1;}
  solve();
  return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <map>

using namespace std;

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 100000;
map<ll,ll> mp;

ll frec[1 + nmax];

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

  int n, q;
  cin >> n >> q;
  vector<ll> v;
  v.push_back(n);
  for(int i = 1; i <= q; i++){
    ll val;
    cin >> val;
    while(0 < v.size() && val <= v.back())
      v.pop_back();
    v.push_back(val);
  }
  mp[v.back()] = 1;
  mp[0] = 1;

  for(int i = v.size() - 1; 0 < i; i--){
    map<ll,ll>::iterator it = mp.end();
    it--;
    while(v[i - 1] < it->first){
      ll acc = it->first / v[i - 1];
      mp[v[i - 1]] += it->second * acc;
      mp[it->first % v[i - 1]] += it->second;
      mp.erase(it--);
    }
  }
  for(map<ll,ll>::iterator it = mp.begin(); it != mp.end(); it++)
    frec[it->first] += it->second;

  for(int i = nmax - 1; 1 <= i; i--)
    frec[i] += frec[i + 1];

  for(int i = 1;i <= n; i++)
    cout << frec[i] << '\n';
  return 0;
}


Measured memory_bytes: 9460
h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
black = 0
ans = 0

for bit_h in range(2**h):
    for bit_w in range(2**w):
        black = 0
        for i in range(h):
            for j in range(w):
                if ((bit_h >> i) & 1) and ((bit_w >> j) & 1) and c[i][j] == '#':
                    black += 1
        if black == k:
            ans += 1
print(ans)


Measured memory_bytes: 9136
def getWinPoint(c):
    if(c == "r"):
        return P
    elif(c == "p"):
        return S
    elif(c == "s"):
        return R
    else:
        return 0
    return 0

N, K = list(map(int, input().strip().split()))
R, S, P = list(map(int, input().strip().split()))
T = input()

ans = 0
hands = ""
for n in range(N):
    if(K <= n and T[n] == hands[n-K]):
        hands += "_"
        continue    
    ans += getWinPoint(T[n])
    hands += T[n]
print(ans)

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

struct Card{ char suit,value;};

void bubble(struct Card A[],int N){

 for(int i=0;i<N+1;i++){
  for(int j=N-1;j>=i;j--){
 if(A[j].value<A[j-1].value){
   Card t=A[j]; A[j]=A[j-1]; A[j-1]=t;
}  
}
}
}

void selection(struct Card A[],int N){
  for(int i=0;i<N;i++){
 int minj=i;
 for(int j=i;j<N;j++){
 if(A[j].value<A[minj].value)minj=j;
}
Card t =A[i];A[i]=A[minj];A[minj]=t;
}
}
 
void print(struct Card A[],int N){
 for(int i=0;i<N;i++){
 if(i>0) cout <<" ";
cout << A[i].suit <<A[i].value;
}
cout << endl;
}

bool isStable(struct Card C1[],struct Card C2[],int N){
 for(int i=0;i<N;i++){
 if(C1[i].suit !=C2[i].suit) return false;
}
return true;
}

int main(){
 Card C1[100],C2[100];
int N;
char ch;

cin >>N;
for(int i=0;i<N;i++){
 cin >> C1[i].suit >>C1[i].value;
}
for(int i=0;i<N;i++) C2[i]=C1[i];

bubble(C1,N);
selection(C2,N);

print(C1,N);
cout << "Stable" <<endl;	
print(C2,N);
if(isStable(C1,C2,N)){
cout << "Stable" <<endl;
}else{
	cout << "Not stable" << endl;
}

return 0;
}

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

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

void solve() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(m+1), b(m+1);
    rep(i, m) cin >> a[i+1] >> b[i+1];

    vector<ll> ans(m+1);
    ans[m] = n * (n-1) / 2;
    UnionFind uf = UnionFind(n+1);
    for (int i = m; i > 0; i--) {
        if (!uf.same(a[i], b[i])) {
            ans[i-1] = ans[i] - uf.size(a[i]) * uf.size(b[i]);
            uf.unite(a[i], b[i]);
        } else {
            ans[i-1] = ans[i];
        }
    }

    rep(i, m) cout << ans[i+1] << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 4096
n, m = map(int, input().split())
a = []

for i in range(n):
    a.append(list(map(int, input().split())))

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

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


Measured memory_bytes: 6008
#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 <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 <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define MOD 1e+7
#define inf 1e9
#define fi first
#define se second
double pi = acos(-1);
using namespace std;

double degree(double h, double m) {
  cout << prec(20);
  h *= 30;
  h += m / 2;
  m *= 6;
  return abs(h - m);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << prec(20);

  double a, b, h, w, pi = acos(-1);
  cin >> a >> b >> h >> w;
  double A = degree(h, w);
  A *= pi / 180;
  A = min(A, abs(2 * pi - A));
  double ans = a * a + b * b - 2 * a * b * cos(A);
  cout << sqrt(ans) << endl;
  return 0;
}

Measured memory_bytes: 4244
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 100100
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    ll n;cin>>n;
    map<string,ll> m;
    while(n--)
    {
        string s;cin>>s;
        m[s]++;
    }
    cout<<m.size()<<endl;
    return 0;
}


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

int main(){
  int d,n; cin>>d>>n;
  if(d==0){
    if(n==100)cout<<101<<endl;
    else cout<<n<<endl;
  }
  else if(d==1){
    if(n==100) cout<<100*(n+1)<<endl;
    else cout<<100*n<<endl;
  }
  else{
    if(n==100) cout<<100*100*(n+1)<<endl;
    else cout<<100*100*n<<endl;
  }
  return 0;
}

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

int main() {
  int x = 1;
  int N, K;
  cin >> N >> K;

  for(int i = 0; i < N; i++){
    if(x <= K){
    x += x;
  }
  else{
    x += K;
  }
  }
  cout << x << endl;
}

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

using namespace std;

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

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

    vector<int> dis;
    for(int i=0; i<M-1; i++){
        dis.push_back(X[i]-X[i+1]);
    }

    sort(dis.begin(), dis.end(), greater<int>());

    int res = X[0] - X.back();

    for(int i=0; i<min((int)dis.size(), N-1); i++){
        res -= dis[i];
    }

    cout<< res <<endl;
    return 0;
}

Measured memory_bytes: 4204
#include <iostream>
int main(int argc, char *argv[]) {
  int a, b, sum;
  std::cin >> a >> b;
  sum = a + b;
  if (sum % 2 == 0)
    std::cout << sum / 2 << std::endl;
  else
    std::cout << sum / 2 + 1 << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,k;
	cin >> n >> k;
	if(k == 1) cout << 0 << endl;
	else cout << n - k << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int main() {
	int a,b,c;
	// freopen("a.inp", "r", stdin);
	// freopen("a.out", "w", stdout);
	scanf("%d %d %d", &a, &b , &c);
	int n = a * 100 + b * 10 + c;
	if (n % 4 ==0) printf("YES");
	else printf("NO");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 114514
#define MAX_Q 214514
#define fi first
#define sc second
#define pb push_back
typedef pair<int,int> P;
typedef pair<P,int> Pi;
int N,Q,M;
vector<P>G[MAX_N];
int R[MAX_Q];
int S[MAX_N];
int S2[MAX_N];
int cou[MAX_Q];
int main()
{
	clock_t start=clock();clock_t end;
	scanf("%d%d%d",&N,&M,&Q);
	for(int i=0;i<M;i++){
		int A,B;
		scanf("%d%d",&A,&B);A--;B--;
		G[A].pb(P(B,i+1));G[B].pb(P(A,i+1));
	}
	for(int i=0;i<Q;i++){
		int X;scanf("%d",&X);
		R[X]=i+1;
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<(int)G[i].size();j++){
			G[i][j].sc=M+1-R[G[i][j].sc];
			if(G[i][j].sc==M+1){G[i][j].sc=0;}
		}
	}
	//end=clock();
	/*
	if((end-start)/(CLOCKS_PER_SEC)>(double)1.0){
		return 0;
	}
	*/
	for(int i=0;i<N;i++){
		S[i]=N+1;
		S2[i]=M+2;
	}
	priority_queue<P,vector<P>,greater<P> >que;
	que.push(P(0,0));
	while(!que.empty()){
		P p=que.top();que.pop();
		if(S[p.sc]<=p.fi){continue;}
		S[p.sc]=p.fi;
		for(int i=0;i<(int)G[p.sc].size();i++){
			if(S[G[p.sc][i].fi]>p.fi+1){
				que.push(P(p.fi+1,G[p.sc][i].fi));
			}
		}
	}
	priority_queue<Pi,vector<Pi>,greater<Pi> >que2;
	que2.push(Pi(P(0,0),0));
	while(!que2.empty()){
		Pi p=que2.top();que2.pop();
		//printf("%d %d %d\n",p.fi.fi,p.fi.sc,p.sc);
		if(S[p.sc]<p.fi.fi){continue;}
		if(S2[p.sc]<=p.fi.sc){continue;}
		S2[p.sc]=p.fi.sc;
		for(int i=0;i<(int)G[p.sc].size();i++){
			if(S[G[p.sc][i].fi]==p.fi.fi+1){
				que2.push(Pi(P(p.fi.fi+1,max(p.fi.sc,G[p.sc][i].sc)),G[p.sc][i].fi));
			}
		}
	}
	/*
	for(int i=0;i<N;i++){
		printf("%d %d\n",S[i],S2[i]);
	}*/
	
	for(int i=0;i<N;i++){
		//if(S2[i]==-1){continue;}
		cou[M+1-S2[i]]++;
	}
	int ans=0;
	for(int i=1;i<=Q;i++){
		ans+=cou[i];
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 16080
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl

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

  int N; cin>>N;

  int res = 0;
  reps(i,1, N+1) {
    if(i%2==0) continue;
    int cnt = 0;
    reps(j, 1, i+1) {
      if(i%j==0)++cnt;
    }
    if(cnt==8)++res;
  }

  cout << res <<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		
		// 計算
		String result = "bon";
		int i = n%10;
		if(i == 2 || i == 4 || i == 5 || i == 7 || i == 9){
		    result = "hon";
		}else if(i == 0 || i == 1 || i == 6 || i == 8){
		    result = "pon";
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



Measured memory_bytes: 25384
#include<stdio.h>

main(){
 int i,x,y;

while(1){
 scanf("%d %d",&x,&y);

 if(x==0 && y==0){
 break;
 }

 if(x > y){
 printf("%d %d\n",y,x);
 }

 else{ 
 printf("%d %d\n",x,y);
 }

 }
 return 0;
}


Measured memory_bytes: 2048
n = int(input())
curt, curx, cury = 0, 0, 0
ans = 'Yes'
for _ in range(n):
   t, x, y = map(int, input().split())
   d = abs(x - curx) + abs(y - cury)
   if d > (t - curt) or (t - curt) % 2 != d % 2:
      ans = 'No'
      break
   curt, curx, cury = t, x, y

print(ans)


Measured memory_bytes: 9188
#include<iostream>
#include<set>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b){
    if(a%b==0){
        return b;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

ll N;
int main(){
    cin >> N;
    set<ll > s;
    ll t;
    for(ll i=0; i<N; i++){
        cin >> t;
        s.insert(t);
    }

    set<ll >::reverse_iterator iter;
    ll a, b, ans;
    iter = s.rbegin();
    a = *iter;
    iter ++;
    b = *iter;
    ans = lcm(a, b);
    iter ++;
    for(iter; iter!=s.rend(); iter++){
        ans = lcm(ans, *iter);
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
L = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(L[k-1])


Measured memory_bytes: 2940
#include<stdio.h>

#define MAX 100000

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

int main(){

  int H,i,A[MAX+1];

  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }

  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=H)printf("left key = %d, ",A[left(i)]);
    if(right(i)<=H)printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
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;}

int main(){
  ll L; cin >> L;
  double l = L/3.0;
  cout << setprecision(20) << l*l*l << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define INF 1e9
#define LINF 1e18
#define ld double
#define ll long long
#define ull unsigned long long

template <typename T> void read(T &x) {
	x = 0; int f = 1, c = getchar();
	for (;!isdigit(c);c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c);c = getchar()) x = (x<<3) + (x<<1) + (c^48);
	x *= f;
}

const int N = 2e5 + 10;
const int MID = 1e5 + 5;

int n, a[N];
int b[N], sum[N], cnt[N];

struct BIT {
	int SUM[N];
	void init() { memset(SUM, 0, sizeof SUM); }
	void add(int x, int v) { for (; x < N; x += x & -x) SUM[x] += v; }
	int sum(int x) { int ans = 0; for (; x; x -= x & -x) ans += SUM[x]; return ans; }
} bit;

bool check(int m) {
	for (int i = 0; i < n; ++ i) b[i] = a[i] <= m ? 1 : -1;
	sum[0] = 0;
	for (int i = 0; i < n; ++ i) sum[i + 1] = sum[i] + b[i];
	bit.init();
	ll ans = 0;
	for (int i = 0; i <= n; ++ i) {
		ans += bit.sum(N - 1) - bit.sum(sum[i] + MID - 1);
		bit.add(sum[i] + MID, 1);
	}
//	printf("%I64d\n", ans);
	return ans * 2 < 1LL * n * (n + 1) / 2;
}

int main() {
	read(n);
	for (int i = 0; i < n; ++ i) read(a[i]);
//	printf("%d\n", check(30));
	int lb = 0, rb = INF;
	while (lb < rb) {
		int md = (lb + rb) >> 1;
		if (check(md)) rb = md;
		else lb = md + 1;
	}
	printf("%d\n", lb);
	return 0;
}


Measured memory_bytes: 2176
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int s, w; cin >> s >> w;
	if (s <= w)cout << "unsafe" << endl;
	else cout << "safe" << endl;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  while(cin >> n&&n){
    map<char,char> m;
    char b,a;
    rep(i,n){
      cin >> b >> a;
      m[b] = a;
    }
    cin >> n;
    rep(i,n){
      cin >> b;
      if(m.count(b) > 0){
        cout << m[b];
      }
      else
        cout << b;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3136
class Vertex:
    _id = -1
    _children = []
    _parent = -1
    _depth = 0
    _type = "root"

    def __init__(self, i, c):
        self._id = i
        self._children = c

    def getId(self):
        return self._id

    def getChildren(self):
        return self._children

    def getParent(self):
        return self._parent

    def getDepth(self):
        return self._depth

    def getType(self):
        return self._type

    def setParent(self, p):
        self._parent = p

    def setDepth(self, d):
        self._depth = d

    def setType(self, t):
        self._type = t

    def print(self):
        print("node {}: parent = {}, depth = {}, {}, {}".format(self._id, self._parent, self._depth, self._type, self._children))


n = int(input())
tree = [0 for i in range(n)]

# 節点
for i in range(n):
    u = list(map(int, input().split(' ')))
    tree[u[0]] = Vertex(u[0], u[2:u[1]+2])

# 親を設定
for w in tree:
    for c in w.getChildren():
        tree[c].setParent(w.getId())
        tree[c].setType("internal node")

# 葉と親を判定
for w in tree:
    if w.getChildren() == []:
        w.setType("leaf")
    if w.getParent() == -1:
        w.setType("root")

# DFS
def dfs(v, depth):
    v.setDepth(depth)
    for child in v.getChildren():
        dfs(tree[child], depth+1)

# 根を探す
root = tree[0]
for w in tree:
    if w.getType() == "root":
        root = w

dfs(root, 0)

# 回答を出力
for w in tree:
    w.print()


Measured memory_bytes: 39036
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N, K;
	cin >> N >> K;

	vector<ll> S(N+1);
	S[0] = 0;
	for (ll i = 1; i < N+1; i++)
		S[i] = (S[i-1] + i);
	ll sum = 0;
	for (int i = K; i <= N+1; i++)
	{
		int mn_i = i - 1;
		int mx_i = max(0, N - mn_i - 1);
		ll mn = S[mn_i];
		ll mx = S[N] - S[mx_i];
		sum = (sum + (mx - mn + 1)) % 1000000007;
	}
	cout << sum << endl;
}



Measured memory_bytes: 4784
#include <bits/stdc++.h>
#define Joe ios::sync_with_stdio(0); cin.tie(NULL); ios_base::sync_with_stdio(0); cout.tie(NULL);
#define INF 1e9+7
const long long N =1e5+5;
using namespace std;
int main(){
	Joe
	int n,w;
	cin>>n>>w;
	long long weight[n+5],price[n+5];
	long long arr[n+5][w+5];
	for(int i=1;i<=n;i++){
		cin>>weight[i];
		cin>>price[i];
	}
	for(int r=0;r<=n;r++){
		for(int c=0;c<=w;c++){
			if(r==0||w==0)
				arr[r][c]=0;
			else if(weight[r]<=c)
				arr[r][c]=max(arr[r-1][c],price[r]+arr[r-1][c-weight[r]]);
			else
				arr[r][c]=arr[r-1][c];
		}
	}
	cout<<arr[n][w]<<endl;
	return 0;
}


Measured memory_bytes: 80384
#include <stdio.h>
int main(void){
    // Your code here!
    int a;
    int b;
    int c;
    int d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if((abs(a-c)<=d) ||(abs(b-a)<=d) && (abs(c-b)<=d))
        {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
}


Measured memory_bytes: 128
/**
 *    author        : Sudipta Banik Trisha 
 *    created       : September 10, 2020 5:11 PM
 *    Problem Name  : D - Dice in Line
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc154/tasks/abc154_d
 *    @genarated by : ai-virtual-assistant
**/

#include<bits/stdc++.h>
#define ll long long int 
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);

    ll n,k;
    cin >> n >> k;

    vector<ll>v(n);
    for(ll i=0; i<n; i++){
        cin >> v[i];
        v[i] = 1 + v[i];
    }
    for(ll i=1; i<n; i++){
        v[i] = v[i-1] + v[i];
    }
    
    long double mxprob = (long double)v[k-1];
    for(int i=k; i<n; i++) {
        mxprob = max(mxprob , (long double)(v[i] - v[i-k]));
    }

    mxprob = mxprob / (long double)2.0;
    cout << fixed << setprecision(12) << mxprob << endl;

    return 0 ;
}


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

int main() {
 int N;
cin>>N;
string s;
for(int i=0 ; i<N ; i++ ){
cin>>s;
if(s=="Y"){
cout<<"Four"<<endl;
break;
}
if(i==N-1){
cout<<"Three"<<endl;
}
}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
typedef long long int ll;
typedef unsigned long long int ull;
ll gcd(ll x,ll y){if(!y)return x;return gcd(y,x%y);}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
double to_deg(double r){return r*180.0/(atan(1.0)*4.0);}
//Sieve of Eratosthenes
int isprime(int x){
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i<=sqrt((double)x);i++)if(x%i==0)return 0;
    return 1;
}
int asc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}
typedef struct{
    int x;
    int y;
}pair_t;

int main(){
    int k,x;scanf("%d %d",&k,&x);
    printf("%s\n",500*k>=x?"Yes":"No");
    return 0;
}

Measured memory_bytes: 128
L, R = map(int, input().split())
 
# 例：L=3000, R=10000 で考える
# (i,j)=(3000,3001)から始まり、(3000,5018)で最小(=0)
 
# R-L>=2018 のとき、(L,L+1),...,(L,L+2018)の間で最小値0を取れる
# それ以外のとき、全探索してもO((10^3)^2)で間に合う！
if R-L >= 2018:
  print(0)
else:
  m = 2019
  for i in range(L, R):
    for j in range(i+1, R+1):
      m = min(m, i*j % 2019)
  print(m)

Measured memory_bytes: 9172
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int h,w,n;
  cin>>h>>w>>n;
  vector<long long int> a(n);
  for(long long int i=0; i<n; i++){
    cin>>a.at(i);
  }
  queue<int> hoge;
  for(long long int i=0; i<n; i++){
    for(long long int j=0; j<a.at(i); j++){
      hoge.push(i+1);
    }
  }

  vector<vector<int>> grid(h,vector<int> (w));
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      int now=j;
      if(i%2!=0){
        now=w-j-1;
      }
      int num=hoge.front();
      hoge.pop();
      grid.at(i).at(now)=num;
    }
  }

  for(long long int i=0; i<h; i++){
    for(long long int j=0; j<w; j++){
      cout<<grid.at(i).at(j);
      if(j!=w-1){
        cout<<" ";
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define MAX (ll)(1e5 + 7)
#define INF (ll)(3e18)
#define MOD (ll)(998244353)

using namespace std;
using ll = long long;

int main () {
	double pi = 3.14159;
	double r;
	cin >> r;
	cout << setprecision (5) << (2.0 * pi * r) << "\n";
}


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

#define endl '\n'
#define ll long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << endl;

using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
#define scl1(a)             scanf(“%I64d", &a)
#define scl2(a, b)          scanf("%lld %lld", &a, &b)

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
const db pi = acos(-1);
const long long infl = LLONG_MAX;
const int inf = 0x3f3f3f3f;

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase   

int32_t main(){

	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll t,i,x,j,y,z,k,n;

cin>>n;
y=0;
pair<ll,ll> a[n];
rep(i,0,n,1){
	cin>>a[i].ff;
	a[i].ss=i+1;
}
	sort(a,a+n);
rep(i,0,n,1)
	cout<<a[i].ss<<" ";
}


Measured memory_bytes: 2432
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,k,a[maxn],p[maxn],c[maxn];

int main()
{
	n=read(); k=read(); rep(i,1,n) a[i]=read(),p[i]=a[i];
	while(k--)
	{
		rep(i,1,(n+1)) c[i]=0;
		rep(i,1,n) c[max(1ll,i-a[i])]++,c[min(i+a[i]+1,n+1)]--;
		int tmp=0,f=0;
		rep(i,1,(n+1)) tmp+=c[i],a[i]=tmp;
		rep(i,1,n) if(a[i]!=n) f=1;
		if(f==0) break;
	}
	rep(i,1,n) printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 8456
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // boolean flag = false;
        int[] a = new int[3 * 3];

        // String s = sc.next();
        // int cnt = 1;

        for (int i = 0; i < 9; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        int n = Integer.parseInt(sc.next());
        int[] b = new int[n];

        for (int i = 0; i < n; i++) {
            b[i] = Integer.parseInt(sc.next());
            for (int j = 0; j < 9; j++) {
                if (b[i] == a[j]) {
                    a[j] = 0;
                    break;
                }
            }
        }

        if ((a[0] == 0 && a[1] == 0 && a[2] == 0) || (a[3] == 0 && a[4] == 0 && a[5] == 0)
                || (a[6] == 0 && a[7] == 0 && a[8] == 0) || (a[0] == 0 && a[3] == 0 && a[6] == 0)
                || (a[1] == 0 && a[4] == 0 && a[7] == 0) || (a[2] == 0 && a[5] == 0 && a[8] == 0)
                || (a[0] == 0 && a[4] == 0 && a[8] == 0) || (a[2] == 0 && a[4] == 0 && a[6] == 0)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

        sc.close();
    }
}


Measured memory_bytes: 22996
#include <stdio.h>
int partition(int A[],int p,int r);
int A[100000];
int main()
{
int n,i,j,x,ex;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&A[i]);
}
ex=partition(A,0,n-1);
for(i=0;i<ex;i++){
printf("%d ",A[i]);
}
 printf("[%d] ",A[ex]);
 for(i=ex+1;i<n-1;i++){
   printf("%d ",A[i]);
}
 printf("%d\n",A[n-1]);
return 0;
}


int partition(int A[],int p,int r){
int x,i,j,temp1,temp2;
x=A[r];
i=p-1;
for(j=p;j<=r-1;j++){
if(A[j]<=x){
i=i+1;
temp1=A[i];
A[i]=A[j];
A[j]=temp1;
  }
 }
temp2=A[i+1];
A[i+1]=A[r];
A[r]=temp2;

return i+1;
}

Measured memory_bytes: 988
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll N = 3e5+5;
vector<int>adj[N],adj1[N];
vector<pair<int,int>>v;
map<pair<int,int>,int>mp;
bool visited[N];
int height[N],val[N],grid[55][55];



void solve(){
 int n;
 cin>>n;
 ll a[n];
 for(int i=0;i<n;i++)cin>>a[i];
 ll pref[n];
 pref[0]=a[0];
 for(int i=0;i<n-1;i++){
    pref[i+1]=(pref[i]+a[i+1])%MOD;
 }
 ll ans=0;
 for(int i=1;i<n;i++){
    ll t=(pref[i-1]*a[i])%MOD;
    ans=(ans+t)%MOD;
 }
 cout<<ans;
}
int main(){
    int t=1;
    //cin>>t;
   while(t--)solve();
}


Measured memory_bytes: 20796
#include<bits/stdc++.h>
using namespace std;
int main(){int A,B,C;cin>>A>>B>>C;B=abs(A-B);C=abs(A-C);if(B+C==0){cout<<A%2-1<<endl;return 0;}int ans=0;for(;;){if(B%2+C%2>0)break;ans++;B/=2;C/=2;}cout<<ans<<endl;}

Measured memory_bytes: 256
a = [0]*5
a_one = [0]*5
a_ten = [0]*5
for i in range(5):
    a[i] = int(input())
    a_one[i] = a[i]%10
    if a_one[i] == 0:
        a_one[i] = 10
    a_ten[i] = abs(10-a_one[i])

min_one_index = a_one.index(min(a_one))
ans = 0
for i in range(5):
    if i != min_one_index:
        ans += a[i]+a_ten[i]
    else :
        ans += a[i]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>	// upper_bound(A, A+N, num):>, lower_bound(A, A+N, num):>=
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>	// V[i],  push_back(x), pop_back(), insert(index, x), erase(index), sort(v.begin(), v.end(), greater<int>())
#include <list>		// push_front(x), push_back(x), pop_front(), pop_back(), insert(index, x)
#include <queue>	// push(x), front(), pop()
#include <deque>
#include <stack>	// push(x), top(), pop()
#include <map>		// M[key],  insert(key, val), erase(key), find(key), 
#include <set>		// insert(key), erase(key), find(key)

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

#define pi 3.141592653589793)
#define mod 1000000007

const int MAX_N = 100000;
int N, x;
bool num[MAX_N * 2];
bool flag;

void solve() {
	cin >> N >> x;
	if (x == 1 || x == N * 2 - 1) {
		cout << "No" << endl;
		return;
	}
	cout << "Yes" << endl;
	vector<int> ans(2 * N - 1);
	for (int i = 0; i < ans.size(); i++) {
		ans[i] = i + 1;
	}
	swap(ans[x - 1], ans[N - 1]);
	swap(ans[0], ans[N - 2]);
	swap(ans.back(), ans[N]);
	for (int i = 0; i < N * 2 - 1; i++) {
		cout << ans[i] << endl;
	}
	return;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>
  
int main(void){
       int a,i=1;
       while(1){
       scanf("%d",&a);
          if (a == 0){
            break;
          }else{
         printf("Case %d: %d\n" ,i,a);
          i++;
             }
          }
          
         return 0;
          }



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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    int a;
    int b, c;
    cin >> a;

    b = a / 100;
    c = a % 100;

    if (c >= 1 && c <= 12 && b >= 1 && b <= 12) {
        cout << "AMBIGUOUS"
             << "\n";
    } else if (c >= 1 && c <= 12) {
        cout << "YYMM"
             << "\n";
    } else if (b >= 1 && b <= 12) {
        cout << "MMYY"
             << "\n";
    } else {
        cout << "NA"
             << "\n";
    }

    return 0;
}


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

int t_solve(int n, int k, vector<int> h){
    int dp[2000010];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; ++i){
        int minum = 1000000005;
        for(int j = 1; j <= k; ++j){
            if(i - j < 0) break;
            int a = abs(h[i] - h[i - j]) + dp[i - j];
            minum = min(minum, a);
        }
        dp[i] = minum;
    }
    return dp[n - 1];
}
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h;
    for(int i = 0; i < n; ++i){
        int x;
        cin >> x;
        h.push_back(x);
    }
    int ans = t_solve(n, k, h);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3320
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, p, ans = 0;
    bool before = false;
    cin >> N;
    
    REP(i, N) {
        cin >> p;
        if (before) {
            ans++;
            before = false;
        }
        else {
            before = p == i + 1;
        }
    }
    if (before) ans++;
    cout << ans << endl;
    return 0;
}

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

int32_t main(){
	map<int, int> cnt;
	int n; cin>>n;
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		++cnt[x];
		if(cnt[x] >= 2){
			cout<<"NO"<<endl;
			return 0;
		}
		
	}
	cout<<"YES"<<endl;
	return 0;
}


Measured memory_bytes: 9600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int N = Integer.parseInt(tmp[0]);
		int X = Integer.parseInt(tmp[1]);

		List<Integer> m = new ArrayList<Integer>();
		int oneDo = 0;
		for (int n = 0; n < N; n++) {
			m.add(Integer.parseInt(br.readLine()));
			oneDo += m.get(n);
		}

		X -= oneDo;
		int count = N;

		m.sort(null);

		int min = m.get(0);

		while(X >= min){
			X -= min;
			count++;
		}

		System.out.println(count);


	}


}


Measured memory_bytes: 22996
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<LP> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;


void solve() {
	int n, m; cin >> n >> m;
	vector<int> a(n), b(m);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, m) {
		cin >> b[i];
	}
	int k = 500;
	vector<int> c(k + 1);
	rep(i, m) {
		if (b[i] <= k) {
			c[b[i]]++;
		}
	}
	ll ans = 0;
	rep1(i, k) {
		if (c[i] == 0)continue;
		ll sum = 0;
		rep(j, n) {
			sum += a[j] % i;
		}
		ans += sum * c[i];
	}
	sort(a.begin(), a.end());
	vector<ll> ra(n + 1);
	rep(i, n) {
		ra[i + 1] = ra[i] + a[i];
	}
	vector<int> isid(200001);
	int tmp = 0;
	rep(i, 200001) {
		isid[i] = tmp;
		while (tmp < n&&a[tmp] == i) {
			tmp++;
		}
	}
	rep(i, m) {
		if (b[i] > k) {
			int lid = 0;
			for (int j = 0; j <= 200000; j += b[i]) {
				int rid;
				if (j + b[i] > 200000) {
					rid = n;
				}
				else {
					rid = isid[j + b[i]];
				}
				ll sum = ra[rid] - ra[lid];
				sum -= (ll)j * (rid - lid);
				ans += sum;
				lid = rid;
			}
		}
	}
	cout << ans << endl;
}

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

	//cout << fixed << setprecision(10);
	//init();
	solve();
	//stop
	return 0;
}




Measured memory_bytes: 6828