akhauriyash/Code-Regression huggingface dataset:
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<climits>
#include<vector>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<sstream>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

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

#define MAX 100010
int N, a[MAX], in_deg[MAX];
//int maxi[MAX];
int battle[MAX];
vector<int> G[MAX];

int dfs(int cur,int prev) {
  vector<int> vec;
  rep(i,(int)G[cur].size()) {
    int next = G[cur][i];
    if( next == prev ) continue;
    int tmp = dfs(next,cur);
    vec.push_back(tmp);
  }
  if( vec.empty() ) {
    //cout << "** cur = " << cur << endl;
    //cout << "leaf" << endl;
    return 0;
  }
  sort(vec.begin(),vec.end());
  int bias = battle[cur];
  int ret = -IINF;
  //cout << "** cur = " << cur << endl;
  rep(i,(int)vec.size()) {
    //cout << "ret = min(" << ret << "," << vec[i] << " + " << bias << " - " << i << " = " << vec[i] + bias - i << ")" << endl;
    ret = max(ret,vec[i]+bias-i);
  }
  //puts("");
  return ret;
}

// i が戦う数
void init_battle() {
  battle[0] = 0;
  //REP(i,1,N) battle[i] = 1;
  REP(i,1,N) ++battle[a[i]];
}

void init_graph() {
  REP(i,1,N) {
    G[i].push_back(a[i]);
    G[a[i]].push_back(i);
    ++in_deg[a[i]];
  }
}

void compute() {
  init_graph();
  init_battle();
  /*
  rep(i,N) {
    cout << "battle[" << i << "] = " << battle[i] << endl;
  } puts("");
  */
  cout << dfs(0,-1) << endl;
}

int main() {
  if( 0 ) {
    cout << 100000 << endl;
    rep(i,100000-1) {
      cout << 1 << endl;
    }
    return 0;
  }
  cin >> N;
  a[0] = -1;
  REP(i,1,N) {
    cin >> a[i];
    --a[i];
  }
  compute();
  return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

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

    if(N[N.size() - 1] == '3') {
        cout << "bon" << endl;
        exit(0);
    } else if(N[N.size() - 1] == '0' || N[N.size() - 1] == '1' ||
              N[N.size() - 1] == '6' || N[N.size() - 1] == '8') {
        cout << "pon" << endl;
        exit(0);
    } else {
        cout << "hon" << endl;
        exit(0);
    }

    return 0;
}

Measured memory_bytes: 3604
n = int(input())
A = list(map(int, input().split()))

d = {}
res = 0
for _i, a in enumerate(A):
    i = _i + 1
    if i - a in d:
        res += d[i - a]
    d[a + i] = 1 if a + i not in d else d[a+i] + 1

print(res)


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

int main(){
  int A,B;
  cin >> A >> B;
  if(A!=1&&B!=1){
    cout << 1 << endl;
  }else if(A!=2&&B!=2){
    cout << 2 << endl;
  }else{
    cout << 3 << endl;
  }
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL a, b; cin >> a >> b;
	if (a > b)swap(a, b);
	if (a*b < 0) {
		cout << "Zero" << endl;
	}
	else if(a<0){
		int is_minus = 0;
		if (b < 0) {
			is_minus = abs(b - a)%2;
			is_minus = !is_minus;
		}
		else {// b>0 // いやこれないわ
			is_minus = abs(a) % 2;
		}
		cout << (is_minus ? "Negative" : "Positive") << endl;
	}
	else {
		cout << "Positive" << endl;
	}

	return 0;
}


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

int main(){
  int n,weight;

  cin >> n >> weight;

  int v[n],w[n];

  int dp[n+1][weight+1];

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

  for(int i=0; i<weight+1; i++){
    dp[0][i] = 0;
  }

  for(int i=1; i<n+1; i++){
    for(int j=0; j<weight+1; j++){
      if(j<w[i-1]){
        dp[i][j] = dp[i-1][j];
      }

      else{
        dp[i][j] = max(dp[i-1][j] , dp[i][j-w[i-1]] + v[i-1]);
      }
    }
  }

  cout << dp[n][weight] << endl;

  return 0;
}

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

typedef pair<int,int> P;

int main(){
	int n;
	while(cin >> n,n){
		vector<P> vec;
		for(int i = 0;i < n;i++){
			int a,b;
			cin >> a >> b;
			vec.push_back(P(b,a));
		}
		sort(vec.begin(),vec.end());
		bool flag = true;
		int now = 0;
		for(int i = 0;i < n;i++){
			now += vec[i].second;
			if(now > vec[i].first) flag = false;
		}
		if(flag) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
#include<stdio.h>
int main(void){
  int i,n,x;
  scanf("%d",&n);

  for(i=1;i<=n;i++){
    x=i;
    if ( x % 3 == 0 ){
      printf(" %d",i);
    }else{
      do{
        if ( x % 10 == 3 ){
          printf(" %d",i);
          x=0;
        }
        x /= 10;
      }while( x );
    }
  }
  printf("\n");
  return 0;
}



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


#define MAX 100000

using namespace std;


vector<int> S(MAX * 4, 0);


int N;
void update(int i, int x)
{
    i += (N - 1);
    S[i] += x;

    while (i > 0) {
        i = (i - 1) / 2;
        S[i] += x;
    }
}


int find(int s, int t, int k, int l, int r)
{
    if (r <= s || t <= l)
        return 0;

    if (s <= l && r <= t)
        return S[k];

    int u, v;
    u = find(s, t, k * 2 + 1, l, (l + r) / 2);
    v = find(s, t, k * 2 + 2, (l + r) / 2, r);
    return u + v;
}


int main()
{
    int n, q;
    cin >> n >> q;
    N = 1;
    while (N < n)
        N *= 2;

    for (int i = 0; i < q; i++) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            update(x - 1, y);
        } else {
            int ret = find(x - 1, y, 0, 0, N);
            cout << ret << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 4244
#include<stdio.h>
#include <stdlib.h>
#define rep( i, n ) for(((i) = 0); ((i) < (n)); ((i)++))

/* 値を入れ替える関数 */
void swap( int *x, int *y)
{
  int temp; /* 値を一時保存する */
  
  temp = *x;
  *x = *y;
  *y = temp;
}


int main(void)
{
    int n;
    scanf("%d\n", &n);

    int p[n];
    int i;
    rep(i, n)
    {
        scanf("%d", &p[i]);
    }

    int cnt = 0;
    rep(i,n)
    {
        if((i+1) != p[i])
        {
            cnt++;
        }
    }

    if(cnt <= 2 )
    {
        printf("YES");
    }
    else
    {
        printf("NO");
    }
    

    return 0;
}


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

int main(){
  int A,B,C,X;cin>>A>>B>>C>>X;
  int count=0;
  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
        if(500*i+100*j+50*k==X) count++;
      }
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 3540
//#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define int long long

int n, c, k;
int T[101010];
//bool Tv[101010] = { false };

signed main() {
	cin >> n >> c >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> T[i];
	}

	sort(T, T + n);

	int busCnt = 0,
		cur = 0,
		capa = 0;
	for (int i = 0; i < n; i++)
	{
		if (T[i] > cur || capa == 0) {
			cur = T[i] + k;
			busCnt++;
			capa = c;
		}
		capa--;
	}
	cout << busCnt << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>

using namespace std;

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

  for (int i = y / 10000; i >= 0; i--) {
    for (int j = (y - i * 10000) / 5000; j >= 0; j--) {
      int l = (y - i * 10000 - j * 5000) / 1000;
      if (i + j + l == n) {
        cout << i << ' ' << j << ' ' << l << endl;
        return EXIT_SUCCESS;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return EXIT_SUCCESS;
}


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

int main() {
	int a[4], b[4];
	while (cin >> a[0] >> a[1] >> a[2] >> a[3]) {
		int hit = 0, blow = 0;
		set<int> S;
		for (int i = 0; i < 4; i++) {
			S.insert(a[i]);
		}
		for (int i = 0; i < 4; i++) {
			cin >> b[i];
			if (b[i] == a[i]) hit++;
			if (S.find(b[i]) != S.end()) {
				blow++;
			}
		}
		cout << hit << " " << blow - hit << endl;
	}
}


Measured memory_bytes: 3068
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int main() {

	int n, k;
	cin >> n >> k;
	vector<int> x;
	FOR(i, n) {
		int a;
		cin >> a;
		if (a == 0)k--;
		else x.push_back(a);
	}

	if (k == 0)cout << 0 << endl;
	else {
		int size = x.size(), zero = 0, ans = INF;
		FOR(i, size) {
			if (i == 0) {
				if (x[i] > 0) {
					x.insert(x.begin(), 0);
					zero = i;
					break;
				}
			}
			else if (i == size - 1) {
				x.insert(x.begin() + i + 1, 0);
				zero = i + 1;
				break;
			}
			else {
				if (x[i] < 0 && x[i + 1]>0) {
					x.insert(x.begin() + i + 1, 0);
					zero = i + 1;
					break;
				}
			}
		}
		size++;

		int t = min(min(size - k, k + 1), min(size - zero, zero + 1));
		FOR(i, t) {
			int len = min(k, zero);
			int a = zero - len + i, b = zero - len + k + i;
			ans = min(ans, min(x[b] - x[a] * 2, x[b] * 2 - x[a]));
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
signed main(){
	string s;
  int h=0,e=0,n,i=0;
  cin >> s;
  n = s.size();
  while(s[i]!='A'){
	h++;
    i++;
  }
  while(s[n]!='Z'){
    e++;
    n--;
  }
  e = s.size() - e + 1;
  h++;
  cout << e - h + 1 << "\n";
  return(0);
}    

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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000001
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<int, int>

int main() {
  ll n, m;
  cin >> n >> m;
  vector<int> G[n];
  REP(i, m){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].pb(b);
    G[b].pb(a);
  }
  int b[n] = { };
  b[0] = 1;
  queue<int> que;
  que.push(0);
  while(que.size()){
    int x = que.front();
    que.pop();
    for(int i: G[x]){
      if(b[i] == 0){
        b[i] = -b[x];
        que.push(i);
      }
      else{
        if(b[i]+b[x] != 0){
          cout << n*(n-1)/2 - m << endl;
          return 0;
        }
      }
    }
  }
  ll w = 0, c = 0;
  REP(i, n){
    if(b[i] == 1) w++;
    else c++;
 }
 cout << w*c-m << endl;
  return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

vector<int> mod0_collect(int a) {
    vector<int> mod0;
    for (int i = 1; i <= a; i++) {
        if (a % i == 0) {
            mod0.push_back(i);
        }
    }
    return mod0;
}

vector<int> get_dup(const vector<int>& a, const vector<int>& b) {
    map<int, int> counter;
    for (const auto value : a) {
        counter[value]++;
    }
    for (const auto value : b) {
        counter[value]++;
    }
    
    vector<int> dup;
    for_each(cbegin(counter), cend(counter), [&dup](auto kvp){
        if (kvp.second > 1) {
            dup.push_back(kvp.first);
        }
    });
    
    return dup;
}

int main(void){
    int a = 0;
    int b = 0;
    int k = 0;
    cin >> a >> b >> k;
    
    const auto mod0_a = mod0_collect(a);
    const auto mod0_b = mod0_collect(b);

    auto dup = get_dup(mod0_a, mod0_b);
    
    sort(begin(dup), end(dup), greater<>());
    
    cout << dup[k - 1] << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {

    public static void main(String[] args) {
	    InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        TaskA solver = new TaskA();
        solver.solve(in, out);

        out.close();
    }

    static class TaskA {
        public void solve(InputReader in, PrintWriter out) {
            String date = in.next();
            out.println(date.replace("2017","2018"));
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public String[] input;
        public int current;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            input = null;
            current = 0;
        }

        public String next() {
            while (input == null || current == input.length) {
                try {
                    current = 0;
                    input = reader.readLine().split("\\s");
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }

            return input[current++];
        }

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

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

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

  int a = n % 10;
  switch (a) {
    case(3):
      cout << "bon" << endl;
      break;
    case(0):
    case(1):
    case(6):
    case(8):
      cout << "pon" << endl;
      break;
    default:
      cout << "hon" << endl;
  }
  return 0;
}


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

int main(){
    int h ,w;

    std::cin >> h >> w;

    std::vector<std::string> s;
    s.assign(h + 2 ,std::string(w + 2 ,'\0'));
    std::vector<std::vector<int>> vec;
    vec.assign(h + 2, std::vector<int>(w + 2, 0));

    for(int a = 1; a <= h; a++){
        std::cin >> s[a];
        s[a] = '\0' + s[a];
    }

    for(int a = 1; a <= h; a++){
        for(int b = 1; b <= w; b++){
            if(s[a][b] == '#'){
                for(int c = a - 1; c <= a + 1; c++){
                    for(int d = b - 1; d <= b + 1; d++){
                        vec[c][d] += 1;
                    }
                }
            }
        }
    }

    for(int a = 1; a <= h; a++){
        for(int b = 1; b <= w; b++){
            if(s[a][b] == '#'){
                std::cout << s[a][b];
            }else{
                std::cout << vec[a][b];
            }
        }
        std::cout << "\n";
    }

    return 0;
}


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

using namespace std;
char a[50][50];
int main()
{
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; ++i) {
		string str;
		cin >> str;
		for (int j = 0; j < w; ++j) {
			a[i][j] = str[j];
		}
	}
	
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (a[i][j] != '.')
				continue;
			int cnt = 0;
			for (int di = -1; di <= 1; ++di) {
				for (int dj = -1; dj <= 1; ++dj) {
					int ni = i + di;
					int nj = j + dj;
					if (0 > ni || 0 > nj || ni >= h || nj >= w)
						continue;
					if (a[ni][nj] == '#')
						++cnt;
				}
			}
			a[i][j] = (char)(cnt+'0');
		}
	}

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			cout << a[i][j];
		}
		cout << endl;
	}

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

//using namespace __gnu_pbds;
using namespace std;

typedef  long long ll;
typedef long double ld;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define endl "\n"
#define ioss ios::sync_with_stdio(0);cin.tie(0);
#define pb push_back
#define eb emplace_back



double startTime;
double gct()//get_current_time
{
    return ((double)clock()-startTime)/CLOCKS_PER_SEC;
}

void suraj();

int main()
{
    startTime=(double)clock();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt,"w",stdout);
    //ioss
    //int t;cin>>t;while(t--)
    suraj();
    //suraj2();
    //suraj3();
    //suraj4();
    return 0;
}































const int n_max=100,k_max=1e5,a_max=k_max;




void suraj(){
int n,k;
scanf("%d%d",&n,&k);
vector<int>a(n);
for(int &i:a){
    scanf("%d",&i);
}
vector<bool>dp(k+1);
//if dp[i] is true than the player playing that turn wins if i stones are left
//hence ans will be dp[k].if(dp[k]==true)then the player playing that turn wins...i.e.first wins if dp[k]is false then playe 2 wins

//dp[a[0]]=true;

for(int stones=0;stones<=k;stones++){
for(int i:a){
    if(stones-i>=0&&(dp[stones-i]==false)){
        dp[stones]=true;//cz the person playing the dp[stone] turn will choose this i and the next player faces stones-i and we know since dp[stones-i]==false the player looses
    }
}
}

if(dp[k]==true)cout<<"First"<<endl;
else cout<<"Second"<<endl;



}//













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

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans = 0;
int N, M, cnt = 0, k;
vi A, B, C;

map<ll, int, greater<int>> mp;

void solve(){
    rep(i, N){
        mp[A[i]]++;
    }

    rep(i, M){
        if(mp.count(C[i])) mp[C[i]] += B[i];
        else mp[C[i]] = B[i];
    }

    for( auto i = mp.begin(); i != mp.end() ; ++i ) {
        if(cnt == N) break;
        k = min(N - cnt, i->second);
        ans += i->first*k;
        cnt += k;

        // std::cout << i->first << " " << i->second << "\n";
    }

    cout << ans << endl;
}

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

    rep(i, N) cin >> A[i];

    rep(i, M) cin >> B[i] >> C[i];

    solve();
}


Measured memory_bytes: 13952
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n+1), b(n);
    REP(i, n+1)
        cin >> a[i];
    REP(i, n)
        cin >> b[i];

    ll ans = 0;
    RFOR(i, n-1, 0){
        if(b[i] <= a[i+1]){
            ans += b[i];
            continue;
        }
        else {
            ans += a[i+1];
            b[i] -= a[i+1];
            ans += min(b[i], a[i]);
            a[i] = max(0LL, a[i]-b[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(void) {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += d[i] * d[j];
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < ((int)(b)); ++i)
#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)
#define sz(c) ((int)c.size())
#define all(c) c.begin(), c.end()

int S(int N) {
    string s = to_string(N);
    int r = 0;
    for (char x : s) {
        r += x - '0';
    }
    return r;
}

signed main() {
    int N;
    cin >> N;
    cout << (N % S(N) == 0 ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include "stdio.h"
#include <string>
int si[10];
bool stack(int left, int right, int i){
	if (i == 9){
		if (left < si[i] || right < si[i]){
			return true;
		}
		else return false;
	}
	else if (left <= si[i]){
		return stack(si[i], right, i + 1);
	}
	else if (right <= si[i]){
		return stack(left, si[i], i + 1);
	}
	else return false;
}
int main(){
	int n;
	std::cin >> n;
	for (int e = 0; e<n; e++){
		for (int ai = 0; ai<10; ai++){
			std::cin >> si[ai];
		}
		if (stack(0, 0, 0) == true){
			std::cout << "YES\n";
		}
		else {
			std::cout << "NO\n";
		}
	}
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    string s;
    cin >> s;
    int ans;
    if(s=="SSS"){
        ans = 0;
    }else if(s=="SSR"){
        ans = 1;
    }else if(s=="SRS"){
        ans = 1;
    }else if(s=="RSS"){
        ans = 1;
    }else if(s=="RRS"){
        ans = 2;
    }else if(s=="SRR"){
        ans = 2;
    }else if(s=="RSR"){
        ans = 1;
    }else if(s=="RRR"){
        ans = 3;
    }
    cout<<ans<<endl;
}


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

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

Measured memory_bytes: 3592
#include<iostream>
using namespace std;
int check(int cc[10])
{
    int temp,z=0,x=0;
    for(int i=0;i<10;i++){
	if(cc[i]<x)return 10;
	else if(cc[i]>z)z=cc[i];
	else if(cc[i]<z&&cc[i]>x)x=cc[i];
    }
    return 1;
}

int main()
{
    int log,N,bb[10];
    cin>>N;    
    for(int i=0;i<N;i++){
    	for(int k=0;k<10;k++)cin>>bb[k];
    	log=check(bb);
	if(log==10)cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

bool isRowWhite(const vector<char>& vA){
    for(uint i=0; i<vA.size(); ++i){
        if( vA[i]!='.' ){ return false; }
    }
    return true;
}

vector<vector<char>> Tr(const vector<vector<char>>& vvA){
    vector<vector<char>> vvR(vvA[0].size(), vector<char>(vvA.size()));
    for(uint p=0; p<vvA.size(); ++p){
        for(uint q=0; q<vvA[0].size(); ++q){
            vvR[q][p] = vvA[p][q];
        }
    }
    return vvR;
}

vector<vector<char>> compress_row(const vector<vector<char>>& vvA){
    vector<vector<char>> vvR;
    for(uint i=0; i<vvA.size(); ++i){
        if(isRowWhite(vvA[i])){ continue; }
        vvR.push_back(vvA[i]);
    }
    return vvR;
}
vector<vector<char>> compress_col(const vector<vector<char>>& vvA){
    return Tr(compress_row(Tr(vvA)));
}

void print_vv(const vector<vector<char>>& vvA){
    for(uint p=0; p<vvA.size(); ++p){
        for(uint q=0; q<vvA[0].size(); ++q){
            cout << vvA[p][q];
        }
        cout << endl;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint H, W; cin >> H >> W;
    vector<vector<char>> vvA(H, vector<char>(W));
    for(uint h=0; h<H; ++h){
        for(uint w=0; w<W; ++w){
            cin >> vvA[h][w];
        }
    }
    
    uint prev_H, prev_W;
    do{
        prev_H = vvA.size();
        prev_W = vvA[0].size();
        vvA = compress_row(vvA);
        vvA = compress_col(vvA);
    }while(prev_H!=vvA.size() || prev_W!=vvA[0].size());
    
    print_vv(vvA);
    
    return 0;
}


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

#define vint vector<int>
#define vvint vector<vint>
#define sint stack<int>
#define qint queue<int>
#define rep(i, n) for(int i=0;i<(int)(n);i++) // 繰り返し処理
#define all(x) (x).begin(),(x).end() // 全体 こんな感じで使う→sort(all(a));
#define ct(a) cout << a << endl
#define iceil(a,b) (a+(b-1))/b //int ceil : 繰り上げの割り算 通常のceilではceil((7.0/2.0))のようにしなければならなかった。
vint CinLine(int N){vint v(N);for(int i=0;i<N;i++){cin >> v.at(i);}return v;}//cin line 連続でvectorに格納
void CoutLine(vint v){for(int i=0;i<v.size()-1;i++){cout<<v.at(i)<<" ";}cout << v.at(v.size()-1)<<endl;}
// str.substr(開始位置, 取り出す長さ);

int vector_finder(std::vector<int> vec, int 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 main() {
    int x,n;
    cin >> x >> n;
    vint p(n);
    p = CinLine(n);
    int ans = x;
    int i = 0;
    bool isPlus = true;
    while(true){
        if(isPlus) ans += i;
        else  ans -= i;
        //ct(ans);
        if(vector_finder(p,ans) == 0){
            break;
        }
        i++;
        if(isPlus) isPlus = false;
        else isPlus = true;
    }
    ct(ans);

}

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

int main(){
	int n;
	cin >> n;
	vector<int> data1(n);
	int tmp;
	for(auto &a:data1){
		cin >> a;
	}
	int m;
	cin >> m;
	int count = 0;
	for(int i = 0; i < m; i++){
		int left = 0, right = n;
		cin >> tmp;
		while(left <= right){
			int center = (left + right) / 2;
			if(data1[center] == tmp){
				count++;
				left = 1;
				right = 0;
			}else if(data1[center] > tmp){
				right = center - 1;
			}else{
				left = center + 1;
			}
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin>>N>>K;
    vector<int>l(N);
    for(int i=0;i<N;i++){
        cin>>l[i];
    }
    sort(l.begin(),l.end());
    reverse(l.begin(),l.end());
    int ans=0;
    for(int i=0;i<K;i++)ans +=l[i];
    cout<<ans<<endl;

}

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 999999999
using namespace std;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

bool shortestPath(const Graph g, int s, vector<Weight> &dist) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  bool negative_cycle = false;
  REP(k, n) REP(i, n) if(dist[i]<INF) FOR(e,g[i]) {
    if (dist[e->dst] > dist[e->src] + e->weight) {
      dist[e->dst] = dist[e->src] + e->weight;
      if (k == n-1) {
        dist[e->dst] = -INF;
        negative_cycle = true;
      }
    }
  }
  return !negative_cycle;
}

int main(){
  int r,T,V,E,s,t,e,i;
  scanf("%d%d%d",&V,&E,&r);
  Graph g(V);
  vector<Weight> dist;
  for(;E--;)scanf("%d%d%d",&s,&t,&e),g[s].push_back(Edge(s,t,e));
  if(!shortestPath(g,r,dist))puts("NEGATIVE CYCLE");
  else for(i=0;i<V;i++){
    if(dist[i]>=INF)puts("INF");
    else printf("%d\n",dist[i]);
  }
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  string s, t;
  cin >> s >> t;

  VSORT(s);
  VSORT(t);
  reverse(t.begin(), t.end());
  if(s < t) cout << "Yes";
  else cout << "No";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string s;
    cin >> s;
    
    int l = s.length();
    char tmp;
    for(int i=0;i<26;i++){
        tmp = 'a' + i;
        bool flag = true;
        for(int j=0;j<l;j++){
            if(s[j] == tmp)
                flag = false;
        }
        if( flag ){
            cout << tmp << endl;
            return 0;
        }
    }
    
    cout << "None" << endl;

}

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

int main() {
	int N, ans = 0, i, l, r;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d %d", &l, &r);
		ans += r - l + 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n, co[maxn + 10], rt, ans, mx;
int f[maxn + 10], h[maxn + 10];
vector<int> g[maxn + 10];
char s[maxn + 10];
bool ban[maxn + 10];

void dfs(int p, int fa) {
	ban[p] = !co[p];
	for (int i = 0; i < (int)g[p].size(); ++i) {
		int e = g[p][i];
		if (e != fa) {
			dfs(e, p); ban[p] &= ban[e];
		}
	}
}

void dfs2(int p, int fa) {
	for (int i = 0; i < (int)g[p].size(); ++i) {
		int e = g[p][i];
		if (!ban[e]) {
			++ans; co[p] ^= 1;
		}
	}
	ans += co[p]; 
	for (int i = 0; i < (int)g[p].size(); ++i) {
		int e = g[p][i];
		if (!ban[e] && e != fa) dfs2(e, p);
	}
}

void dfsans(int p, int fa) {
	f[p] = co[p]; h[p] = 0;
	for (int i = 0; i < (int)g[p].size(); ++i) {
		int e = g[p][i];
		if (!ban[e] && e != fa) {
			dfsans(e, p);
			mx = max(mx, f[p] + h[e]);
			mx = max(mx, f[e] + h[p]);
			f[p] = max(f[p], f[e] + co[p]);
			h[p] = max(h[p], h[e] + co[p]);
		}
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int l, r; scanf("%d%d", &l, &r);
		g[l].push_back(r); g[r].push_back(l);
	}
	scanf("%s", s + 1);
	for (int i = 1; i <= n; ++i) co[i] = s[i] == 'W';
	for (int i = 1; i <= n; ++i)
		if (co[i]) {
			rt = i; break;
		}
	if (!rt) {
		printf("0"); return 0;
	}
	dfs(rt, 0);
	dfs2(rt, 0);
	dfsans(rt, 0);
	printf("%d", ans - mx * 2);
}


Measured memory_bytes: 14848
#include <stdio.h>
int main() {
	int m, f, r, g;
	scanf("%d %d %d", &m, &f, &r);
	while (m != -1 || f != -1 || r != -1) {
		g = m + f;
		if (m == -1 || f == -1)
			printf("F\n");
		else if (g >= 80)
			printf("A\n");
		else if (g >= 65 && g<80)
			printf("B\n");
		else if (g >= 50 && g<65)
			printf("C\n");
		else if (g >= 30 && g<50) {
			if (r >= 50)
				printf("C\n");
			else
				printf("D\n");
		}
		else if (g<30)
			printf("F\n");
		scanf("%d %d %d", &m, &f, &r);
	}
}


Measured memory_bytes: 2052
#include<iostream>
using namespace std;
 main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;
    int dpl[n + 1], dpr[n + 1];
    dpl[0] = 0;
    dpr[0] = 0;
    int last = -10000000;
    for (int i = 1; i <= n; ++i) {
        if (s[i - 1] == 'x') dpl[i] = dpl[i - 1];
        else if (last + c < i) {
            last = i;
            dpl[i] = dpl[i - 1] + 1;
        }
        else dpl[i] = dpl[i - 1];
    }
    last = -10000000;
    for (int i = 1; i <= n; ++i) {
        if (s[n - i] == 'x') dpr[i] = dpr[i - 1];
        else if (last + c < i) {
            last = i;
            dpr[i] = dpr[i - 1] + 1;
        }
        else dpr[i] = dpr[i - 1];
    }
    //for (int i = 0; i <= n; ++i) cout << dpr[i] << " ";
    for (int i = 0; i < n; ++i) {
        int left = i;
        int right = n - i - 1;
        if (s[i] == 'o' && dpl[left] + dpr[right] < k && dpl[left] + dpr[right] + 1 >= k) cout << i + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3476
#include <iostream>                                             
#include <cstdio>                                               
#include <cmath>                                                
using namespace std;                                            
                                                                
int main() {                                                    
  double x1, y1, x2, y2;                                        
  cin >> x1 >> y1 >> x2 >> y2;                                  
  double P1_P2 = sqrt(pow(x2-x1,2)+pow(y2-y1,2));               
  printf("%.8f\n", P1_P2);                                      
  return 0;                                                     
}                                                               
                                                                
                                                                
                                                                
                                                                
                       

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

int main(){
  int K,X;
  cin >> K >> X;
  int len = 2*K-1;
  int left = X-K+1;
  for(int i=left; i<left+len-1; i++){
    cout << i << " ";
  }
  cout << left+len-1 << endl;
  return 0;
}

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

using namespace std;

const int N = 1000, M = 1000;

char cc[N][M + 1];
int qu[N * M];
int dd[N][M];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, m; cin >> n >> m;
	int i1, j1; cin >> i1 >> j1, i1--, j1--;
	int i2, j2; cin >> i2 >> j2, i2--, j2--;
	for (int i = 0; i < n; i++)
		cin >> cc[i];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			dd[i][j] = n * m;
	int head = 0, cnt = 0;
	qu[head + cnt++] = i1 * m + j1, dd[i1][j1] = 0;
	while (cnt) {
		int x = qu[cnt--, head++];
		int i = x / m, j = x % m;
		for (int di = -2; di <= 2; di++)
			for (int dj = -2; dj <= 2; dj++)
				if (di || dj) {
					int i_ = i + di, j_ = j + dj;
					if (0 <= i_ && i_ < n && 0 <= j_ && j_ < m && cc[i_][j_] == '.')
						if (abs(di) + abs(dj) <= 1) {
							if (dd[i_][j_] > dd[i][j])
								qu[cnt++, --head] = i_ * m + j_, dd[i_][j_] = dd[i][j];
						} else {
							if (dd[i_][j_] > dd[i][j] + 1)
								qu[head + cnt++] = i_ * m + j_, dd[i_][j_] = dd[i][j] + 1;
						}
				}
	}
	int ans = dd[i2][j2];
	cout << (ans != n * m ? ans : -1) << '\n';
	return 0;
}


Measured memory_bytes: 10324
#include <stdio.h>
int main(){
    int N;
    int x[50];
    int y[50];
    scanf("%d",&N);
    int i;
    for(i=0;i<N;i++){
        scanf("%d",&x[i]);
        scanf("%d",&y[i]);
    }
    int p;
    int q;
    int j;
    int k;
    int l;
    int m;
    int c;
    m=0;
    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            if(i-j!=0){
                p=x[i]-x[j];
                q=y[i]-y[j];
                c=0;
                for(k=0;k<N;k++){
                    for(l=0;l<N;l++){
                        if((x[k]+p==x[l])&&(y[k]+q==y[l])){
                            c=c+1;
                        }
                    }
                }
                if(c>m){
                    m=c;
                }
            }
        }
    }
    printf("%d",N-m);
}

Measured memory_bytes: 128
inpl = lambda: list(map(int,input().split()))
MOD = 10**9+7

def inv_mod(a, p=MOD):
    def inv_mod_sub(a, p):
        if a == 1:
            return 1, 0
        else:
            d, r = p//a, p%a
            x, y = inv_mod_sub(r, a)
            return y-d*x, x
    if p < 0: p = -p
    a %= p
    return inv_mod_sub(a,p)[0] % p

def comb_mod(n,k):
    if k < 0 or k > n:
        return 0
    else:
        return factorial_mod[n]*factorial_inv_mod[k]*factorial_inv_mod[n-k] % MOD

N, K = inpl()
inv = [1]*(N+1)
factorial_mod = [1]*(N+1)
factorial_inv_mod = [1]*(N+1)
for n in range(1,N+1):
    inv[n] = inv_mod(n)
    factorial_mod[n] = factorial_mod[n-1]*n % MOD
    factorial_inv_mod[n] = factorial_inv_mod[n-1]*inv[n] % MOD

for i in range(1,K+1):
    print((comb_mod(K-1,i-1)*comb_mod(N-K+1,i)) % MOD)

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(x)             cout <<#x<<": "<<x<<endl;
#define debug2(x, y)         cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define debug3(x, y, z)      cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define debug4(a, b, c, d)   cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
template <typename T>  using orderedSet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key find_by_order

int main() {
    FAST
    ll a;
    cin>>a;
    cout<<a*(1+a+a*a);
}

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

int main(){
    int n,k;
    string s;
    cin >> n >> k >> s;
    k=k-1;
    if(s.at(k)=='A') s.at(k)='a';
    else if(s.at(k)=='B') s.at(k)='b';
    else s.at(k)='c';
    cout << s << endl;
    }

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

char Map[1111][1111];
int v[1111][1111];
vector<pair<int,int> >vec;

struct node {
    int x,y,s;
};
queue<node>que;
int dir[4][2] = {0,1,0,-1,1,0,-1,0};
int main() {
    memset(v,0,sizeof(v));
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) {
        for(int j=1; j<=m; j++) {
            cin>>Map[i][j];
            if(Map[i][j]=='#') {
                v[i][j]=1;
                node p;
                p.x=i,p.y=j,p.s=0;
                que.push(p);
            }
        }
    }

    int ans = 0;
    while(!que.empty()) {
//        cout<<que.size()<<endl;
        node p = que.front();
//        cout<<p.x<<"   "<<p.y<<"    "<<p.s<<endl;
        que.pop();
        ans = p.s;
        int x=p.x,y=p.y;
        for(int i=0;i<4;i++) {
            int dx = x+dir[i][0];
            int dy = y+dir[i][1];

            if(dx>=1 && dx<=n && dy>=1 && dy<=m && !v[dx][dy]) {
                node dp;
                dp.x = dx,dp.y=dy,dp.s=p.s+1;
                v[dx][dy]=1;
                que.push(dp);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 18320
import sys
input = sys.stdin.readline
from collections import *

H, W = map(int, input().split())
A = [list(input()[:-1]) for _ in range(H)]
l = []

for i in range(H):
    for j in range(W):
        if A[i][j]=='#':
            l.append((i, j))
    
ans = 0

while True:
    nl = []
    
    for x, y in l:
        for nx, ny in [(x-1, y), (x+1, y), (x, y-1), (x, y+1)]:
            if 0<=nx<H and 0<=ny<W and A[nx][ny]=='.':
                nl.append((nx, ny))
                A[nx][ny] = '#'
    
    if len(nl)==0:
        break
    
    l = nl
    ans += 1

print(ans)

Measured memory_bytes: 167212
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		MyString str = new MyString(br.readLine());
		int q = Integer.parseInt(br.readLine());
		for (int i = 0; i < q; i++) {
			String[] line = br.readLine().split(" ");
			String command = line[0];
			if (command.equals("print")) {
				str.print(Integer.parseInt(line[1]), Integer.parseInt(line[2]));
			} else if (command.equals("reverse")) {
				str.reverse(Integer.parseInt(line[1]), Integer.parseInt(line[2]));
			} else if (command.equals("replace")) {
				str.replace(Integer.parseInt(line[1]), Integer.parseInt(line[2]), line[3]);
			}
		}
	}

}

class MyString {
	private String value;

	public MyString() {
		value = "";
	}

	public MyString(String value) {
		this.value = value;
	}

	public void print(int a, int b) {
		System.out.println(value.substring(a, b + 1));
	}

	public void reverse(int a, int b) {
		StringBuilder sb = new StringBuilder();

		sb.append(value.substring(0, a));
		sb.append((new StringBuilder()).append(value.substring(a, b + 1))
				.reverse().toString());
		sb.append(value.substring(b + 1));

		this.value = sb.toString();
	}

	public void replace(int a, int b, String p) {
		StringBuilder sb = new StringBuilder();

		sb.append(value.substring(0, a));
		sb.append(p);
		sb.append(value.substring(b + 1));

		this.value = sb.toString();
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}
}

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

int main() {
  string str;
  cin >> str;
  if (str == "SUN") {
    cout << '7';
  } else if (str == "MON") {
    cout << "6";
  } else if (str == "TUE") {
    cout << "5";
  } else if (str == "WED") {
    cout << "4";
  } else if (str == "THU") {
    cout << "3";
  } else if (str == "FRI") {
    cout << "2";
  } else if (str == "SAT") {
    cout << "1";
  }

  return 0;
}

Measured memory_bytes: 256
import math
from collections import Counter
n, m = map(int, input().split())

prime_count = Counter()
for i in range(2, math.ceil(math.sqrt(m))+1):
    while m % i == 0:
        m /= i
        prime_count[i] += 1
if m > 1:
    prime_count[int(m)] += 1    

def ncr(n, r, p):
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den, p - 2, p)) % p
p=10**9+7 

ans = 1 
for k, v in prime_count.items():
    ans *= ncr(n-1+v, n-1, p)
    ans %= p
print(ans)

Measured memory_bytes: 39152
import java.util.*;

public class Main{
	public static void main(String[]args){

		Scanner sc=new Scanner(System.in);

		int a[]=new int[3];
		for(int i=0;i<3;i++){
			a[i]=sc.nextInt();
		}
		Arrays.sort(a);

		System.out.println(a[2]-a[0]);


	}
}


Measured memory_bytes: 22740
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  vll M(9, 0);
  REP(i, 0, N) {
    ll a;
    cin >> a;
    if (a < 400) {
      M[0]++;
    } else if (a < 800) {
      M[1]++;
    } else if (a < 1200) {
      M[2]++;
    } else if (a < 1600) {
      M[3]++;
    } else if (a < 2000) {
      M[4]++;
    } else if (a < 2400) {
      M[5]++;
    } else if (a < 2800) {
      M[6]++;
    } else if (a < 3200) {
      M[7]++;
    } else {
      M[8]++;
    }
  }

  bool all_none = true;
  ll min = 0, max = 0;
  REP(i, 0, 8) {
    if (M[i] > 0) {
      all_none = false;
      min++;
      max++;
    }
  }
  if (all_none) {
    ll m8 = M[8];
    if (m8 <= 8) {
      cout << "1 " << M[8] << endl;
    } else {
      cout << "1 8" << endl;
    }
    return 0;
  }

  max += M[8];
  cout << min << " " << max << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n,d,x;
    cin >> n >> d >> x;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    int cnt = 0;
    rep(i,n){
        cnt += (d-1)/a[i]+1;
    }
    cout << cnt + x << endl;
    return 0;
}

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

int main() {
	int A, B;
	cin >> A >> B;
	int i = 0;

	if(B !=1){
		while (A + (A-1)*(i-1) < B) {
			i++;
		}
	}
	cout << i << endl;
}

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

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  cout << abs((n - 2) * (m - 2)) << '\n';
  return 0;
}

Measured memory_bytes: 3588
#include<stdio.h>
#include<string.h>
 
int main(){
int a[51],b[51];
int n,m;
scanf("%d %d",&n,&m);

    for(int i=0;i<m;i++){
        scanf("%d %d",&a[i],&b[i]);
    }
    for(int j=1;j<=n;j++){
        int yes=0;
        for(int i=0;i<m;i++){
            if(a[i]==j||b[i]==j){yes++;}
        }
        printf("%d\n",yes);
    }
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  ll n;
  cin >> n;

  vll a(n);
  rep(i, n) {
    cin >> a[i];
  }

  ll minus_cnt = 0;
  bool exist_zero = false;

  rep(i, n) {
    if (a[i] < 0) {
      minus_cnt++;
    }
    if (a[i] == 0) {
      exist_zero = true;
    }
  }

  rep(i, n) {
    a[i] = abs(a[i]);
  }

  if (minus_cnt % 2 && !exist_zero) {
    auto it = min_element(all(a));
    *it *= -1;
  }

  ll ans = accumulate(all(a), 0ll);

  cout << ans << endl;

  return 0;
}


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

int main(){
  int p,q;
  cin >>p>>q;
  if((p+q)%2==0){
  cout << (p+q) / 2<< endl;
  }
  else{
  cout << (p+q+1) / 2 << endl;
  }
}

Measured memory_bytes: 3532