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

typedef long long lint;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const lint inv = MOD - 2;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct edge{
    int from, to;
    lint cost;
};

struct node{
    int id;
    lint cost, height;

    bool operator<(const node & right) const {
        return cost > right.cost;
    }
};

int n, m;
lint x;
vector<lint> h;
vector< vector<edge> > g;
vector<lint> dis;
priority_queue<node> que;

lint dijkstra(void){
    dis.resize(n);
    rep(i, n){
        dis[i] = LLINF;
    }
    node now;
    now.id = 0;
    now.cost = 0;
    now.height = x;
    que.push(now);
    while(!que.empty()){
        now = que.top();
        que.pop();
        if(now.id == n-1){
            now.cost += abs(now.height - h[now.id]);
            now.height = h[now.id];
        }else if(now.height < 0){
            now.cost += -now.height;
            now.height = 0;
        }else if(h[now.id] < now.height){
            now.cost += now.height - h[now.id];
            now.height = h[now.id];
        }
        if(now.cost >= dis[now.id]){
            continue;
        }
        dis[now.id] = now.cost;
        rep(i, g[now.id].size()){
            edge e = g[now.id][i];
            node nex;
            nex.id = e.to;
            nex.cost = now.cost + e.cost;
            nex.height = now.height - e.cost;
            if(nex.cost < dis[nex.id]){
                que.push(nex);
            }
        }
    }
    return dis[n-1];
}

int main(){
    cin >> n >> m >> x;
    h.resize(n);
    g.resize(n);
    rep(i, n){
        cin >> h[i];
    }
    rep(i, m){
        edge e;
        cin >> e.from >> e.to >> e.cost;
        e.from--;
        e.to--;
        if(h[e.from] >= e.cost){
            g[e.from].push_back(e);
        }
        swap(e.from, e.to);
        if(h[e.from] >= e.cost){
            g[e.from].push_back(e);
        }
    }
    lint ans = dijkstra();
    if(ans < LLINF){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 31940
#coding: UTF-8
import sys

table = [0]*26

letters = [chr(i) for i in range(97, 97+26)]
input_str = sys.stdin.read()

for A in input_str:
    index = 0
    for B in letters:
        if A == B or A == B.upper():
            table[index] += 1
            break
        index += 1

for i in range(len(letters)):
    print("%s : %d"%(letters[i], table[i]))



Measured memory_bytes: 5568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll N, M;
    cin >> N >> M;
    ll ans;
    ans = 1;
    for (int i = 0; i < M; i++) {
        ans = ans * 2;
    }
    ans = ans * (1800 * M + 100 * N);
    printf("%lld\n", ans);
}

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

int main()
{
  int n, amax = 0, amaxi = 0, asecond = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    if (amax <= a.at(i)) {
      asecond = amax;
      amax = a.at(i);
      amaxi = i;
    } else if (asecond <= a.at(i)) {
      asecond = a.at(i);
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == amaxi) {
      cout << asecond << endl;
    } else {
      cout << amax << endl;
    }
  }
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  if(s.size() % 2 != 0) cout << "No";
  else {
    if(s.substr(0, s.size() / 2) == s.substr(s.size() / 2)) cout << "Yes";
    else cout << "No";
  }
}
  



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

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n;
int w[20];
int h[20];
char field[20][20];
int ok[4][4][4][4];
bool visit[1 << 16];

int main() {
  while (scanf("%d", &n) > 0) {
    MEMSET(ok, false);
    REP(i, n) {
      scanf("%d %d", &h[i], &w[i]);
    }
    REP(y, 4) {
      scanf("%s", field[y]);
    }
    FOREQ(x, -3, 3) {
      FOREQ(y, -3, 3) {
        REP(i, n) {
          int lx = max(0, x);
          int rx = max(0, min(3, x + w[i] - 1));
          int ly = max(0, y);
          int ry = max(0, min(3, y + h[i] - 1));
          ok[lx][ly][rx][ry] = 1;
        }
      }
    }

    MEMSET(visit, false);
    int mapto[3] = { 'R', 'G', 'B' };
    visit[0] = true;
    queue<pair<int, int> > que;
    que.push(make_pair(0, 0));
    while (!que.empty()) {
      const int state = que.front().first;
      const int cost = que.front().second;
      que.pop();
      if (state == (1 << 16) - 1) {
        printf("%d\n", cost);
      }
      REP(lx, 4) REP(rx, 4) REP(ly, 4) REP(ry, 4) {
        if (!ok[lx][ly][rx][ry]) { continue; }
        REP(c, 3) {
          int ncost = cost + 1;
          int nstate = state;
          FOREQ(x, lx, rx) FOREQ(y, ly, ry) {
            if (field[y][x] == mapto[c]) {
              nstate |= 1 << (y * 4 + x);
            } else {
              nstate &= ~(1 << (y * 4 + x));
            }
          }
          if (visit[nstate]) { continue; }
          visit[nstate] = true;
          que.push(make_pair(nstate, ncost));
        }
      }
    }
  }
}

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


template<typename T> struct Edge {
    int from, to;
    T weight;
    Edge() : from(0), to(0), weight(0) {}
    Edge(int f, int t, T w) : from(f), to(t), weight(w) {}
  };
template<typename T> using Edges = vector< Edge< T > >;
template<typename T> using Graph = vector< Edges< T > >;
template<typename T> void     add_edge(Graph< T > &g, int from, int to, T w = 1) { g[from].emplace_back(from,to,w); g[to].emplace_back(to,from,w); }
template<typename T> void      add_arc(Graph< T > &g, int from, int to, T w = 1) { g[from].emplace_back(from,to,w); }
template<typename T> void add_to_edges(Edges< T > &e, int from, int to, T w = 1) { e.emplace_back(from,to,w); }


int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int N,K;
    cin>>N>>K;

    if(N==2){
        if(K>0)cout<<-1<<endl;
        else {
            cout<<1<<endl;
            cout<<1<<" "<<2<<endl;
        }
        return 0;
    }
    // if(N==3 &&K==0){
    //     cout<<3<<endl;
    // }
    
    if(K<=(N-1)*(N-2)/2){
        int t=(N-1)*(N-2)/2 - K;
        int cen=(N+1)/2;

        int total=t+N-1;

        cout<<total<<endl;



        //初手
        for(int i=1;i<cen;i++){
            cout<<i <<" "<<cen<<endl;
        }
        for(int j=cen+1;j<=N;j++)
        {
            cout<<j<<" "<<cen<<endl; 
        }

        if(t==0)goto E;

        for(int ii=1;ii<N;ii++){
            for(int jj=ii+1;jj<=N;jj++){
                if(ii==cen||jj==cen)continue;
                cout<<ii<<" "<<jj<<endl;
                t--;
                if(t==0)goto E;
            }
        }
        E:;
    }else{
        cout<<-1<<endl;
    }
    
}

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

int main() {

	int n;
	cin >> n;
	int arr[n], ar2[n];
	for (int i=0; i<n; i++) {
		cin >> arr[i];
		ar2[i] = arr[i];
	}
	
	sort(ar2, ar2+n);
	
	int mx = ar2[n-1];
	int mx2 = ar2[n-2];
	
	for (int i=0; i<n; i++) {
		if (arr[i] == mx) cout << mx2 << endl;
		else cout << mx << endl;
	}
	
	

}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll A, B;
    cin >> A >> B;
    cout << (A + B) % 24 << endl; 
    return 0;
}


Measured memory_bytes: 3620
# D - Candidates of No Shortest Paths
# ワーシャルフロイド法で、任意の2頂点間の最短距離を求める。
# すべての辺に対して、その距離と、辺の両端間の最短距離を比較し、
# 辺の距離 > 辺の両端間の最短距離なら、その辺は最短経路に使われていないことがわかる。
n,m = map(int,input().split())
e = []
for i in range(m):
  a,b,c = map(int,input().split())
  a -= 1
  b -= 1
  e.append((a,b,c))

INF = float('inf')
d = [[INF for _ in range(n)] for _ in range(n)]
for a,b,c in e:
  d[a][b] = c
  d[b][a] = c
for i in range(n):
  d[i][i] = 0
for k in range(n):
  for i in range(n):
    for j in range(n):
      d[i][j] = min(d[i][k]+d[k][j],d[i][j])
ans = 0
for a,b,c in e:
  if d[a][b] < c:
    ans += 1
print(ans)

Measured memory_bytes: 74912
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define ill long long
#define fcout cout << fixed << setprecision(10)
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int mn = 1001, cnt = 0;
  int ss = s.size(), tt = t.size();
  if(s == t) {
    cout << 0 << "\n";
    return 0;
  }
  rep(i, 0, ss-tt+1) {
    cnt = 0;
    rep(j, 0, tt) {
      if(t[j] != s[i+j]) {
        cnt++;
        //cout << i << " " << j << " " << cnt << "\n";
      }
    }
    if(cnt < mn) {
      mn = cnt;
      //cout << mn << "\n";
    }
  }
  cout << mn << "\n";
}

Measured memory_bytes: 3644
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <limits.h>
#include <map>
#include <numeric>

using namespace std;

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

  int *types = new int[m];
  int k, type;

  for(int i = 0; i < n; i++){
    cin >> k;
    while(k--){
      cin >> type;
      types[type - 1]++;
    }
  }

  int result = 0;

  for(int i = 0; i < m; i++){
    result += (types[i] == n);
  }

  cout << result <<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
#define mod 1000000007
typedef unsigned long long int ull;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ull n,p=1;
	cin>>n;
    for (ull i = 1; i <= n; i++)
	{
		p=(p%mod)*(i%mod);
		p%=mod;
	}
	cout<<p;
	
	

   return 0;
}


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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, T;
  cin >> N >> T;
  int ans = 1001001001;
  bool j = 0;
  rep(i,N) {
    int c, t;
    cin >> c >> t;
    if(t>T) continue;
    ans = min(ans, c);
    j = 1;
  }
  if(j) cout << ans << endl;
  else cout << "TLE" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  // J100           J600
  //          T400           T900 T1000
  //  S150              S799 S899      S2000
  //RR,RL、LR、LLの4つの進みかたのどれか。全部調べてもよさそう
  //JR,TRとTR,JRで違うから8通りか
  //8*10^5ならなんとかなるか
  ll A,B,Q;
  cin>>A>>B>>Q;
  vector<ll> J(A,0), T(B,0), S(Q,0), ans(Q,1e11);
  for(int i=0; i<A; i++){
    ll s;
    cin>>s;
    J[i]=s;
  }
  for(int i=0; i<B; i++){
    ll t;
    cin>>t;
    T[i]=t;
  }
  for(int i=0; i<Q; i++){
    ll x;
    cin>>x;
    S[i]=x;
  }
  //下準備
  vector<ll> JL(Q,0), TL(Q,0);
  for(int i=0; i<Q; i++){
    ll jl=lower_bound(J.begin(), J.end(), S[i])-J.begin();
    ll tl=lower_bound(T.begin(), T.end(), S[i])-T.begin();
    JL[i]=jl;
    TL[i]=tl;
  }
  //神社R→寺Rパターン
  for(int i=0; i<Q; i++){
    ll now=S[i], tmp=0;
    if(JL[i]==A)
      continue;
    tmp+=abs(now-J[JL[i]]);
    now=J[JL[i]];
    ll tl=lower_bound(T.begin(), T.end(), now)-T.begin();
    if(tl==B)
      continue;
    tmp+=abs(now-T[tl]);
    ans[i]=min(ans[i],tmp);
  }
  //神社R→寺Lパターン
  for(int i=0; i<Q; i++){
    ll now=S[i], tmp=0;
    if(JL[i]==A)
      continue;
    tmp+=abs(now-J[JL[i]]);
    now=J[JL[i]];
    ll tl=lower_bound(T.begin(), T.end(), now)-T.begin();
    if(tl==0)
      continue;
    tmp+=abs(now-T[tl-1]);
    ans[i]=min(ans[i],tmp);
  }
  //神社L→寺Rパターン
  for(int i=0; i<Q; i++){
    ll now=S[i], tmp=0;
    if(JL[i]==0)
      continue;
    tmp+=abs(now-J[JL[i]-1]);
    now=J[JL[i]-1];
    ll tl=lower_bound(T.begin(), T.end(), now)-T.begin();
    if(tl==B)
      continue;
    tmp+=abs(now-T[tl]);
    ans[i]=min(ans[i],tmp);
  }
  //神社L→寺Lパターン  
  for(int i=0; i<Q; i++){
    ll now=S[i], tmp=0;
    if(JL[i]==0)
      continue;
    tmp+=abs(now-J[JL[i]-1]);
    now=J[JL[i]-1];
    ll tl=lower_bound(T.begin(), T.end(), now)-T.begin();
    if(tl==0)
      continue;
    tmp+=abs(now-T[tl-1]);
    ans[i]=min(ans[i],tmp);
  }
  
  //寺R→神社Rパターン
  for(int i=0; i<Q; i++){
    ll now=S[i], tmp=0;
    if(TL[i]==B)
      continue;
    tmp+=abs(now-T[TL[i]]);
    now=T[TL[i]];
    ll jl=lower_bound(J.begin(), J.end(), now)-J.begin();
    if(jl==A)
      continue;
    tmp+=abs(now-J[jl]);
    ans[i]=min(ans[i],tmp);
  }
  //寺R→神社Lパターン
  for(int i=0; i<Q; i++){
    ll now=S[i], tmp=0;
    if(TL[i]==B)
      continue;
    tmp+=abs(now-T[TL[i]]);
    now=T[TL[i]];
    ll jl=lower_bound(J.begin(), J.end(), now)-J.begin();
    if(jl==0)
      continue;
    tmp+=abs(now-J[jl-1]);
    ans[i]=min(ans[i],tmp);
  }
  //寺L→神社Rパターン
  for(int i=0; i<Q; i++){
    ll now=S[i], tmp=0;
    if(TL[i]==0)
      continue;
    tmp+=abs(now-T[TL[i]-1]);
    now=T[TL[i]-1];
    ll jl=lower_bound(J.begin(), J.end(), now)-J.begin();
    if(jl==A)
      continue;
    tmp+=abs(now-J[jl]);
    ans[i]=min(ans[i],tmp);
  }
  //寺L→神社Lパターン
  for(int i=0; i<Q; i++){
    ll now=S[i], tmp=0;
    if(TL[i]==0)
      continue;
    tmp+=abs(now-T[TL[i]-1]);
    now=T[TL[i]-1];
    ll jl=lower_bound(J.begin(), J.end(), now)-J.begin();
    if(jl==0)
      continue;
    tmp+=abs(now-J[jl-1]);
    ans[i]=min(ans[i],tmp);
  }
  for(int i=0; i<Q; i++)
    cout<<ans[i]<<endl; 
}


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

int main() {
  int a,b;
  int ans=0;

  cin >> a >> b;

  if(a<b){
    for(int i=0;i<b;i++) {
      ans = ans*10 + a;
    }
  }
  else {
    for(int i=0;i<a;i++) {
      ans = ans*10 + b;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int N, K;
  std::cin >> N >> K;

  int result = K;
  for (int i = 1; i < N; i++) {
    result *= (K-1);
  }
  std::cout << result << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fine cout<<"fine"<<endl;
#define ll long long int
#define pb push_back
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
const ll inf=(ll)2e18;
const int mod=1e9+7;
bool overflow(ll a,ll b){
    if (a <= (inf+b-1)/b) return false;
    return true;
}
int main(){
FASTIO;
int a[3][3],b[3][3],i,j,k,x;
memset(b,0,sizeof(b));
for(i=0;i<3;i++)
    for(j=0;j<3;j++)
        cin>>a[i][j];
int n;
cin>>n;
for(i=0;i<n;i++){
    cin>>x;
    for(j=0;j<3;j++){
        for(k=0;k<3;k++){
            if(a[j][k]==x){
                b[j][k]=1;
                break;
            }
        }
        if(k<3)
            break;
    }
}
for(i=0;i<3;i++){
    int sum=0;
    for(j=0;j<3;j++){
        sum+=b[i][j];
    }
    if(sum==3){
        cout<<"Yes"<<endl;
        return 0;
    }
}
for(j=0;j<3;j++){
    int sum=0;
    for(i=0;i<3;i++){
        sum+=b[i][j];
    }
    if(sum==3){
        cout<<"Yes"<<endl;
        return 0;
    }
}
if(b[0][0]+b[1][1]+b[2][2]==3||b[0][2]+b[1][1]+b[2][0]==3){
    cout<<"Yes"<<endl;
    return 0;
}
cout<<"No"<<endl;
}


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

int a[200010];

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

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

    sort(a, a + n);

    int b = a[n / 2];

    long long ans = 0;

    for (int i = 0; i < n; i++)
        ans += abs(a[i] - b);

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


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<list>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

int main(){
    long long int x;
    double kinli = 1.01;
    double money = 100.0;
    double kiri = floor(money);
    int intm = (int)kiri;
    int nen = 0;
    cin >> x;
    while(x>kiri){
        money *= kinli;
        kiri = floor(money);
        money = kiri;
    
        nen++;
    }
cout << nen << endl;

    return 0;
}

Measured memory_bytes: 3600
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        var nx = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long X = nx[1];
        //ちゅーごくじょーよてーり
        //オーダーによってSの終端が決定する
        //まず影響するのは降順のみなことは自明に分かって、
        //で、「次」を選ぶことができる順番は
        //「確率」「期待値」
        //aを取り除いた場合、その後に適用できるのはそれ以前全て。

        List<int> s = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(x => x).ToList();
        ModInt[] dp = new ModInt[X + 1];
        dp[X] = 1;
        ModInt remain = s.Count - 1;
        foreach (var mod in s)
        {
            ModInt[] newDP = new ModInt[X + 1];

            for (int i = 0; i < dp.Length; i++)
            {
                newDP[i % mod] += dp[i];
                newDP[i] += dp[i] * remain;
            }
            remain--;
            dp = newDP;
        }
        ModInt res = 0;
        for (int i = 0; i < dp.Length; i++)
        {
            res += dp[i] * i;
        }
        Console.WriteLine(res);
    }
}


struct ModInt
{
    const int MOD = 1000000007;
    long Data;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public ModInt(long data) { if ((Data = data % MOD) < 0) Data += MOD; }
    public static implicit operator long(ModInt modInt) => modInt.Data;
    public static implicit operator ModInt(long val) => new ModInt(val);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator +(ModInt a, ModInt b)
    {
        long res = a.Data + b.Data;
        return new ModInt() { Data = res >= MOD ? res - MOD : res };
    }
    public static ModInt operator -(ModInt a, ModInt b)
    {
        long res = a.Data - b.Data;
        return new ModInt() { Data = res < 0 ? res + MOD : res };
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator *(ModInt a, ModInt b) => new ModInt(a.Data * b.Data);
    public static ModInt operator /(ModInt a, ModInt b) => a * Power(b, MOD - 2);

    static ModInt Power(ModInt n, long m)
    {
        ModInt res = 1;
        while (m > 0)
        {
            if ((m & 1) == 1) res *= n;
            n *= n;
            m >>= 1;
        }
        return res;
    }
}


Measured memory_bytes: 32152
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i64,
        k: i64
    }
    let mut beki = Vec::new();
    let mut a = 1;
    for i in 0..k {
        a *= 2;
        beki.push(a);
        if i * i >= k {
            break;
        }
    }

    let mut sum:f64 = 0.0;
    let base = 1.0 / n as f64;
    for i in 1..n + 1{
        if i >= k {
            sum += base;
        } else {
            let aa = ((k as f64 / i as f64) as f64).log(2.0).ceil();

            sum += 1.0 / ((n * beki[aa as usize - 1]) as f64);
        }
    }
    println!("{}", sum);
}


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


    using namespace std;
    typedef long long ll;
    # define M_PI  3.14159265358979323846
    const int MOD=1e9+7;

    void solve(){
        long long a;
        string b;
        cin>>a>>b;
        ll c=(b[0]-'0')*100 + (b[2]-'0')*10 + (b[3]-'0');
        cout<<a*c/100;
    }

    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,x;
  cin>>n;
  vector<vector<int> > a(n,vector<int>(3,0));
  rep(i,n){
    rep(j,3){
      cin>>a[i][j];
    }
  }
  rep(j,3){
    rep(i,n){
      x=a[i][j];
      rep(k,n){
	if(k!=i&&x==a[k][j]){
	  a[i][j]=0;
	  a[k][j]=0;
	}
      }
    }
  }
  rep(i,n)cout<<a[i][0]+a[i][1]+a[i][2]<<endl;
  return 0;
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9 +7;
ll Power(ll x,ll k)
{
	x%=mod;
	ll sss=1;
	while (k)
	{
		if (k%2) sss=sss*x%mod;
		x=x*x%mod;
		k/=2;
	}
	return sss;
}
ll ny(ll x){return Power(x,mod-2);}
int n,q;
ll f[4030][4030];
ll ans;
ll a[5030],b[5][5030];
int main()
{
	scanf("%d%d",&n,&q);
	for (int i=1;i<=n;++i) scanf("%lld",&a[i]);
	for (int i=1;i<=n;++i)
		for (int j=1;j<=n;++j) if (a[i]>a[j]) f[i][j]=1;

	int x,y; ll doe=ny(2);
	for (int i=1;i<=q;++i)
	{
		scanf("%d%d",&x,&y);
		if (x==y) continue;
		for (int j=1;j<=n;++j) 
		{
			b[0][j]=f[j][x];
			b[1][j]=f[x][j];
			b[2][j]=f[j][y];
			b[3][j]=f[y][j];
		}

		for (int j=1;j<=n;++j)
		{
			if (j!=x) (f[j][y]+=b[0][j])%=mod;
			if (j!=x) (f[y][j]+=b[1][j])%=mod;
			if (j!=y) (f[j][x]+=b[2][j])%=mod; 
			if (j!=y) (f[x][j]+=b[3][j])%=mod;
		}
		for (int j=1;j<=n;++j)
		{
			if (j!=x) f[j][y]=f[j][y]*doe%mod;
			if (j!=x) f[y][j]=f[y][j]*doe%mod;
			if (j!=y) f[j][x]=f[j][x]*doe%mod;
			if (j!=y) f[x][j]=f[x][j]*doe%mod;
		}
		ll A=f[x][y],B=f[y][x];
		f[y][x]+=A; f[x][y]+=B;
		f[x][y]=f[x][y]*doe%mod; 
		f[y][x]=f[y][x]*doe%mod;
	}
/*	for (int i=1;i<=n;++i)
	{
		for (int j=1;j<=n;++j)
			printf("%lld ",f[i][j]);
		printf("\n");
	}*/
	for (int i=1;i<=n;++i)
		for (int j=i+1;j<=n;++j) (ans+=f[i][j])%=mod;
	ans=ans*Power(2,q)%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 96128
n = int(input())
a = list(map(int,input().split()))
 
t = 0
for i in range(n):
    if a[i] == i+1:
        t += 1

i = 0
cnt = 0
while i < n-1:
    if a[i] == i+1 and a[i+1] == i+2:
        cnt += 1
        i += 2
    else:
        i += 1

print(t-cnt)

Measured memory_bytes: 14008
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;

class abc100b {
public:
    void solve(istream& in, ostream& out) {
        int D, N;
        in >> D >> N;
        int res = 1;
        for (; N; ++res) {
            bool ok = true;
            int tmp = res;
            for (int j = 0; j < D; ++j) {
                if (tmp % 100) {
                    ok = false;
                }
                tmp /= 100;
            }
            if (tmp % 100 == 0) {
                ok = false;
            }
            N -= ok;
        }
        out << res - 1 << "\n";
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	abc100b solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define elif else if
#define INF 1000000007
using namespace std;
int n,cnt=0;
string s;
signed main(){
	cin>>n;
	s=to_string(n);
	rep(i,s.size()){
		int a=s[i]-48;
		cnt+=a;
	}
	if(n%cnt==0){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main() {
	int N;
	while (~scanf("%d", &N)) {
		vector<int> A(N);
		for (int i = 0; i < N; ++ i)
			scanf("%d", &A[i]);
		ll L = 2, R = 2;
		for (int i = N - 1; i >= 0; -- i) {
			int m = A[i];
			L = (L + m - 1) / m * m;
			R = R / m * m;
			if (L > R) break;
			R += m - 1;
		}
		if (L > R) {
			puts("-1");
		} else {
			printf("%lld %lld\n", L, R);
		}
	}
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define for(i,a,b)      for(int i=a; i<b; i++)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
    int n; cin>>n;
    int a[n+1] ;

    for(i,1,n+1)  cin>>a[i] ;
    a[0] = INT_MAX ;

    int dp[n+1] ;

    dp[0] = 0, dp[1] = 0, dp[2] = abs(a[2]-a[1]);

    for(i,3,n+1) {

        int op1 = abs(a[i]-a[i-1]) + dp[i-1] ;
        int op2 = abs(a[i]-a[i-2]) + dp[i-2] ;
        dp[i] = min(op1,op2) ;

    }

    cout<<dp[n] ;

	return 0;
}

Measured memory_bytes: 5200
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int32_t N = 3;
	int32_t _MAX = 100;

	vector<vector<int32_t>> c;
	c.resize(N);
	for (int32_t row = 0; row < N; row++) {
		c[row].resize(N);
		for (int32_t col = 0; col < N; col++) {
			cin >> c[row][col];
		}
	}

	vector<int32_t> a(3), b(3);
	for (a[0] = 0; a[0] <= _MAX; a[0]++) {
		for (a[1] = 0; a[1] <= _MAX; a[1]++) {
			for (a[2] = 0; a[2] <= _MAX; a[2]++) {
				bool found = true;
				for (int32_t col = 0; col < N; col++) {
					b[col] = c[0][col] - a[0];
					if (b[col] < 0 || b[col] != c[1][col] - a[1] || b[col] != c[2][col] - a[2]) {
						found = false;
						break;
					}
				}
				if (found) {
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    S = input()
    if S == "RRR":
        print(3)
    elif ((S[0] != 'R') ^ (S[2] != 'R')) and S[1]=='R':
        print(2)
    elif S == "SSS":
        print(0)
    else:
        print(1)

if __name__=='__main__':
    main()

Measured memory_bytes: 61716
#include <bits/stdc++.h>
#define mst(a,b) memset(a,b,sizeof(a))
#define ALL(x) x.begin(),x.end()
#define pii pair<int,int>
#define eps 1e-6
#define debug(a) cout << #a": " << a << endl;
#define eularMod(a, b) a < b ? a : a % b + b
inline int lowbit(int x){ return x & -x; }
const int N = 1e5 + 10;
const int mod = (int) 1e8 + 7;
const int INF = 0x3f3f3f3f;
const long long LINF = (1LL << 62);
typedef long long LL;
typedef unsigned long long ULL;
const double PI = acos(-1.0);
using namespace std;

int v[N];

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
//    freopen("out.txt","w",stdout);
#endif
    int n, T, A;
    scanf("%d%d%d", &n, &T, &A);

    for (int i = 1; i <= n; i++) {
        scanf("%d", &v[i]);
    }

    double tag = INF;
    int ans = -1;

    for (int i = 1; i <= n; i++) {
        if (fabs(T - 0.006 * v[i] - A) < tag) {
            ans = i;
            tag = fabs(T - 0.006 * v[i] - A);
        }
    }

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



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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 x;
    cin >> x;
    i64 m = 100;
    i64 ans = 0;
    while (m < x) {
        m *= 1.01, ans++;
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	vector<int> cnt(3, -1);

	ll ans = 1;
	rep(i,n) {
		int x = v[i] - 1;
		int c = 0;
		rep(j,3) {
			if (x == cnt[j]) c++;
			if (c == 1 && x == cnt[j]) cnt[j]++;
		}
		ans *= c;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3728
n,m=map(int,input().split())
s=[]
c=[]
for i in range(m):
    si,ci=map(int,input().split())
    s.append(si)
    c.append(str(ci))
#    c.append(ci)
    
yesno="No"
vmin=1000
if n==1:
    for j in range(10):
        strj=str(j)
        yesnomi="Yes"
        for mi in range(m):
            if len(strj)<s[mi] :
#                print("smi",j,strj,s[mi],c[mi],strj[s[mi]-1],yesnomi,yesno)
                yesnomi="No"
            if strj[s[mi]-1]!=c[mi] :
                yesnomi="No"
#                print("X",j,strj,s[mi],c[mi],strj[s[mi]-1],yesnomi,yesno)
                dmy=1
        if yesnomi=="Yes":
#            print(j,strj,s[mi],c[mi],strj[s[mi]-1])
            if vmin>j:
                yesno="Yes"
                vmin=j
if n==2:
    for j in range(10,100):
        strj=str(j)
        yesnomi="Yes"
        for mi in range(m):
            if len(strj)<s[mi] :
#                print("smi",j,strj,s[mi],c[mi],strj[s[mi]-1],yesnomi,yesno)
                yesnomi="No"
            if strj[s[mi]-1]!=c[mi] :
                yesnomi="No"
#                print("X",j,strj,s[mi],c[mi],strj[s[mi]-1],yesnomi,yesno)
                dmy=1
        if yesnomi=="Yes":
#            print(j,strj,s[mi],c[mi],strj[s[mi]-1])
            if vmin>j:
                yesno="Yes"
                vmin=j
if n==3:
    for j in range(100,1000):
        strj=str(j)
        yesnomi="Yes"
        for mi in range(m):
            if len(strj)<s[mi] :
#                print("smi",j,strj,s[mi],c[mi],strj[s[mi]-1],yesnomi,yesno)
                yesnomi="No"
            if strj[s[mi]-1]!=c[mi] :
                yesnomi="No"
#                print("X",j,strj,s[mi],c[mi],strj[s[mi]-1],yesnomi,yesno)
                dmy=1
        if yesnomi=="Yes":
#            print(j,strj,s[mi],c[mi],strj[s[mi]-1])
            if vmin>j:
                yesno="Yes"
                vmin=j
if yesno=="No":
    print(-1)
else:
    print(vmin)    

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef pair<int,int> pi;
typedef long long int ll;

const int N = (int)1e5+5;

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

    double l;
    cin>>l;
    double ans = l/3;
    ans = ans*ans*ans;
    cout<<fixed<<setprecision(20)<<ans;
}


Measured memory_bytes: 256
N, MIN, MAX = map(int, input().split())

sum_min = (N-1)*MIN + MAX
sum_max = (N-1)*MAX + MIN
# print(sum_max)
# print(sum_min)

if N > 1:
    if sum_max >= sum_min:
        print(sum_max - sum_min + 1)
    else:
        print(0)
elif N == 1:
    if MIN!= MAX:
        print(0)
    else:
        print(1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <string>
using namespace std;

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> L(M);
    vector<int> R(M);
    int L_max =  1;
    int R_min =  N;
    int ans = 0;

    for(int i = 0;i < M;i++){
      cin >> L[i] >> R[i];
      L_max = max(L_max, L[i]);
      R_min = min(R_min, R[i]);
    }

    if(L_max > R_min){
      ans = 0;
    }else{
      ans = R_min - (L_max - 1);
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
N = int(input())
a = list(map(int, input().split()))

def sort_reverse(n):
    n.sort(reverse=True)
    return n

N_Even = list(range(0, N, 2))
N_Odd = list(range(1, N, 2))
a1 = sort_reverse(a)
sum1 = 0
sum2 = 0

for i in N_Even:
    sum1 += a1[i]
for j in N_Odd:
    sum2 += a1[j]

print(sum1 - sum2)

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

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> pr(n + 1);
    for (int i = 2; i <= n; i++) {
        if (pr[i] == 0) {
            for (int j = i; j <= n; j += i)
                pr[j] = i;
        }
    }
    int ans = 1;
    for (int i = 2; i < n; i++) {
        map<int, int> cnt;
        int x = i;
        while (x > 1) {
            cnt[pr[x]]++;
            x /= pr[x];
        }
        int y = 1;
        for (auto p : cnt) {
            y *= p.second + 1;
        }
        ans += y;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 7136
N = int(input())
S = input()
Rc = 0
Gc = 0
Bc = 0
for i in range(N):
    if S[i] == 'R':
         Rc +=1
    elif S[i] == 'G':
         Gc+=1
    elif S[i] == 'B':
         Bc+=1
c = Rc*Gc*Bc

for i in range(N-2):
     for j in range(i+1,N-1):
          if S[i] == S[j]:
               continue
          if j + j - i >= N:
               continue
          if S[i] == S[j+j-i]:
               continue
          if S[j] == S[j+j-i]:
               continue
          c -= 1
print(c)


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

typedef long long ll;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define REPM(i,n) for(ll i=(n-1); 0=<i; i--)
#define VI vector<int>
#define VL vector<ll>
#define VD vector<double>
#define VS vector<string>
#define V_SORT_U(x) sort(x.begin(), x.end());
#define V_SORT_D(x) sort(x.begin(), x.end(),greater<int>());
#define V_SUM(x) accumulate(x.begin(), x.end(), 0)
#define STR_TRANS_UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define STR_TRANS_LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);

int main(void){
    int K;
    string S;

    cin >> K;
    cin >> S;

    if( S.length() <= K )
    {
        cout << S;
    }
    else
    {
        cout << S.substr(0, K) << "...";
    }

    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

//二分探索
int binary_search(const vector<ll>& a ,ll key){
    int ng=-1, ok=(int)a.size();
    while(abs(ok-ng)>1){
        int mid=(ok+ng)/2;
        if(a[mid] <= key){
            ng=mid;
        }else{
            ok=mid;
        }
    }
    return ng;
}

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

    int A, B;
    vector<ll> a(N + 1, 0), b(M + 1, 0);

    //Aの累積和
    rep(i, N){
        cin>> A;
        a[i + 1] = A + a[i];
    }

    //Bの累積和
    rep(i, M){
        cin>> B;
        b[i + 1] = B + b[i];
    }

    //Aを基準にして探索
    int ans = 0;
    int read_A;
    rep(i, N + 1){
        if(a[i] <= K) read_A = i;
        else read_A = 0;
        ans = max(ans, read_A + binary_search(b, K - a[i]));
    }

    cout<< ans << endl;
}


Measured memory_bytes: 6428
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

if A[0] != 0:
    print(0)
    exit()


ans = 1
colors = [0] * 3
for n in A:
    ans *= colors.count(n)
    ans %= MOD
    for i in range(3):
        if colors[i] == n:
            colors[i] += 1
            break
print(ans)


Measured memory_bytes: 53132
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		// input
		final int N = scan.nextInt();
		final int X = scan.nextInt();
		
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			list.add(scan.nextInt());
		}
		
		int index = 0;
		int count = 1;
		for (Integer i : list) {
			index += i;
			if (index <= X) {
				count++;
			}
		}
		
		System.out.println(count);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
 
#define INF (1e9)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int gcd(int a,int b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

int N,M;
int B[100001]={0};
int main()
{
	cin >> N;
	int a[N];
	

	REP(i, N)
	{
		cin >> a[i];
		if(a[i]==0){
			B[a[i]]++;
			B[a[i] + 1]++;
		}else{
			B[a[i] - 1]++;
			B[a[i]]++;
			B[a[i] + 1]++;
		}
	}
	int mx=0;
	REP(i, 100001)
	{
		if(B[i]>mx){
			mx = B[i];
		}
	}

	cout << mx << endl;


	return 0;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
  val A = readInts().sorted()

  var cost1 = 0
  for (i in 1 until A.size) {
    cost1 += Math.abs(A[i] - A[i - 1])
  }

  val B = A.sortedDescending()
  var cost2 = 0
  for (i in 1 until A.size) {
    cost2 += Math.abs(B[i] - B[i - 1])
  }

  println(Math.min(cost1, cost2))
}

fun gcd(a: Int, b: Int): Int = if (a < b) gcd(b, a) else if (b == 0) a else gcd(b, a % b)
fun lcm(a: Int, b: Int): Int = (a * b) / gcd(a, b)

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readInts() = readLine()!!.split(" ").map { it.toInt() }
fun readLongs() = readLine()!!.split(" ").map { it.toLong() }


Measured memory_bytes: 37904
#include <cstdio>
#include <iostream>
#define N 101
using namespace std;
int n,m,X,Y,ans=0,a[N][N],b[N][N];
short f[N][N][N][N];
char map[N][N];
int max(int x,int y){ return x>y?x:y; }
int min(int x,int y){ return x<y?x:y; }
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
	{
        scanf("%s",map[i]+1);
        for (int j=1;j<=m;j++)
		{
            a[i][j]=a[i][j-1]+(map[i][j]=='o'), b[i][j]=b[i-1][j]+(map[i][j]=='o');
            if (map[i][j]=='E') X=i,Y=j;
        }
    }
    for (int i=X;i>=1;i--) for (int j=Y;j>=1;j--) for (int p=X;p<=n;p++) for (int q=Y;q<=m;q++)
	{
        if (i>1&&i-1>p-X) ans=max(ans,f[i-1][j][p][q]=max(f[i-1][j][p][q],f[i][j][p][q]+a[i-1][min(q,m-Y+j)]-a[i-1][max(j-1,q-Y)]));
    	if (p<n&&n-p>X-i) ans=max(ans,f[i][j][p+1][q]=max(f[i][j][p+1][q],f[i][j][p][q]+a[p+1][min(q,m-Y+j)]-a[p+1][max(j-1,q-Y)]));
        if (j>1&&j-1>q-Y) ans=max(ans,f[i][j-1][p][q]=max(f[i][j-1][p][q],f[i][j][p][q]+b[min(p,n-X+i)][j-1]-b[max(i-1,p-X)][j-1]));
    	if (q<m&&m-q>Y-j) ans=max(ans,f[i][j][p][q+1]=max(f[i][j][p][q+1],f[i][j][p][q]+b[min(p,n-X+i)][q+1]-b[max(i-1,p-X)][q+1]));
    }
    printf("%d",ans);
}

Measured memory_bytes: 201088
/* ex4_3
   moka223711 */

#include <stdio.h>
int snow(int h_west, int h_east); // 積雪量を求める関数のプロトタイプ宣言

int main(void){
    // 高さがn(n+1)/2[m](n=1,2,…,999)の999本の塔が西から順に立っている
    // 雪に埋もれていない塔の高さから雪が何m積もっているか求める
    // 雪に埋もれていない西側の塔の高さをh_west、東側の塔の高さをh_eastとする
    
    int h_west, h_east;
    scanf("%d %d", &h_west, &h_east);
    
    // 積雪量を求める関数snow()から返り値を受け取って出力
    printf("%d\n", snow(h_west, h_east));
    
    return 0;
}


    // 積雪量を求める関数の定義
int snow(int h_west, int h_east){
    int dif, ans;
    
    // 東側の塔の高さから西側の塔の高さを引き、差difを求める
    dif = h_east - h_west;
    // ここでdifは東側の塔がdif番目の塔であることを表す
    
    // 差difから東側の塔の高さを求めて、雪に埋もれていない塔の高さを引くことで
    // 雪が何m積もっているかを求める
    ans = dif * (dif + 1) / 2 - h_east;
    
    // ansを返り値として返す
    return ans;
}



Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
        	arr[i] = sc.nextInt();

        long cnt = 0;
        for(int i = 1; i < n; i++) {
        	long sum = arr[i-1] + arr[i];
        	long diff = Math.max(0, sum - x);
        	cnt += diff;
        	arr[i] -= Math.min(arr[i], diff);
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 51932
-- 2X(=すべて鶴) <= Y <= 4X(=すべて亀)
-- Y は偶数である必要がある。(even y)

import Data.Char

main=interact$solve.map read.words

solve[x,y]
 | ((2 * x <= y) && (y <= 4 * x) && (even y)) = "Yes"
 | otherwise = "No"

Measured memory_bytes: 3824
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<int,ii> iii;

long fpb(long a, long b)
{
	return (b == 0)? a : fpb(b, a%b);
}

int main()
{
	//ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);
	long q; scanf("%lld", &q);
	while(q--)
	{
		long a, b, c, d;
		scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
		if(a < b) printf("No\n");
		else if(d < b) printf("No\n");
		else
		{
			a -= (a-c+b-1)/b*b;
			long x = fpb(b,d);
			// printf("%lld %lld\n", a, x);
			if(a < 0) printf("No\n");
			else if(b-c > x) printf("No\n");
			else if(c >= b) printf("Yes\n");
			else if(c%x >= a%x) printf("Yes\n");
			else printf("No\n");
		}
	}
}












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

int i,j;

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

    int mini=a[n-1];
    for(i=0;i<n-1;i++){
        mini=min(mini,k-abs(a[i]-a[i+1]));
    }
    mini=min(mini,abs(a[0]-a[n-1]));

    cout<<mini<<endl;
    return 0;
}

Measured memory_bytes: 1024
"""
高橋君の夏休みは N 日間です。
夏休みの宿題が M 個出されており、
i 番目の宿題をやるには Ai 日間かかります。
複数の宿題を同じ日にやることはできず、また、宿題をやる日には遊ぶことができません。
夏休み中に全ての宿題を終わらせるとき、最大何日間遊ぶことができますか？
ただし、夏休み中に全ての宿題を終わらせることができないときは、かわりに -1 を出力してください。
"""

N, M = map(int, input().split())
data = list(map(int, input().split()))

# 全ての宿題にかかる日数 sum(data)

if N - sum(data) < 0:
    print(-1)
else:
    print(N - sum(data))


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

int main()
{
  string deck,tmp;
  int m,h;

  while( 1 ) 
  {
    cin >> deck;
    if(deck == "-") break;

    cin >> m;
    for(int i=1; i<=m; i++)
    {   
      cin >> h;
      tmp = deck.substr(0,h);
      deck.erase(0,h);
      deck = deck + tmp;
    }   
    cout << deck << endl;
  }

  return 0;
}



Measured memory_bytes: 3156
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl
#define P pair<lint,lint>

int main() {
	lint N;
	cin >> N;
	vector<string>S(N);
	rep(i, N) {
		cin >> S[i];
	}
	lint AC = 0;
	lint WA = 0;
	lint TLE = 0;
	lint RE = 0;
	rep(i, N) {
		if (S[i] == "AC") {
			AC++;
		}
		else if (S[i] == "WA") {
			WA++;
		}
		else if (S[i] == "TLE") {
			TLE++;
		}
		else if (S[i] == "RE") {
			RE++;
		}
	}
	cout << "AC x " << AC << enld;
	cout << "WA x " << WA << enld;
	cout << "TLE x " << TLE << enld;
	cout << "RE x " << RE << enld;
}

Measured memory_bytes: 6412