akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
using namespace std;

const int MAX = 110;
int mat[MAX][MAX];
int dist[MAX], done[MAX];
int n;

void bfs(int s)
{
  int t = 0;
  queue<int> que;
  que.push(s);
  dist[s] = 0;
  while (!que.empty()) {
    int i = que.front(); que.pop();
    if (done[i]) continue;
    done[i] = 1;
    for (int j = 0; j < n; j++) {
      if (mat[i][j]) {
        dist[j] = min(dist[j], dist[i]+1);
        que.push(j);
      }
    }
  }
}

int main()
{
  cin >> n;

  memset(mat, 0, sizeof(mat));
  for (int i = 0; i < n; i++) {
    int u; cin >> u; u--;
    int k; cin >> k;
    for (int j = 0; j < k; j++) {
      int v; cin >> v; v--;
      mat[u][v] = 1;
    }
  }

  fill(dist, dist+MAX, INT_MAX);
  memset(done, 0, sizeof(done));
  bfs(0);
  for (int i = 0; i < n; i++)
    printf("%d %d\n", i+1, (dist[i]==INT_MAX?-1:dist[i]));

  return EXIT_SUCCESS;
}


Measured memory_bytes: 3272
s=input()
x,y=map(int,input().split())
ct=0
XY=[]
for i in range(len(s)):
  if s[i]=="F":
    ct+=1
  else:
    XY.append(ct)
    ct=0
XY.append(ct)
x-=XY[0]
X=XY[2::2]
Y=XY[1::2]


def chk(Z,z):
  tot,nz=sum(Z),len(Z)
  if tot==0:
    if z==0:
      return True
    else:
      return False
  elif abs(z)>tot:
    return False
  else:
    DP=[[False]*(2*tot+1) for _ in range(nz+1)]
    DP[0][tot]=True
    for i in range(nz):
      zz=Z[i]
      for j in range(2*tot+1):
        if j+zz<2*tot+1 and DP[i][j+zz]==True:
          DP[i+1][j]=True
        if j-zz>=0 and DP[i][j-zz]==True:
          DP[i+1][j]=True
    return DP[nz][z+tot]

if chk(X,x) and chk(Y,y):
  print("Yes")
else:
  print("No")

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

vector<Int> G[100001];

int main() {
    Int n;
    cin >> n;
    vector<bool> v(n + 1, true);
    vector<Int> a(n - 1), b(n - 1);
    for (Int i = 0; i < n - 1; i++) {
        cin >> a[i] >> b[i];
        G[a[i]].push_back(b[i]);
        v[b[i]] = false;
    }
    Int r = 1;
    for (Int i = 1; i <= n; i++) {
        if (v[i]) {
            r = i;
            break;
        }
    }
    //dump(r);
    map<pair<Int, Int>, Int> mp;
    Int ma = 0;
    queue<pair<Int, Int>> q;
    q.push({r, 0});
    while (!q.empty()) {
        pair<Int, Int> v = q.front();
        q.pop();
        if (v.fi == r) {
            ma = max(ma, (Int)G[v.fi].size());
        }
        else {
            ma = max(ma, (Int)G[v.fi].size() + 1);
        }
        Int color = 1;
        for (Int i = 0; i < G[v.fi].size(); i++) {
            if (color == v.se) {
                color++;
            }
            mp[{v.fi, G[v.fi][i]}] = color;
            q.push({G[v.fi][i], color});
            color++;
        }
    }
    dump(ma);
    for (Int i = 0; i < n - 1; i++) {
        dump( mp[make_pair(a[i], b[i])] );
    }
    return 0;
}

Measured memory_bytes: 12544
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int D; cin>>D;
	vector<int> cs(26);
	vector<vector<int>> s(D,vector<int> (26));
	vector<int> last(26,-1);
	rep(i,26)cin>>cs[i];
	rep(i,D)rep(j,26)cin>>s[i][j];
	ll sum = 0;

	vector<int> ans(D);
	rep(d, D){
		int m_type;
		ll m_plus = -INF;
		rep(t, 26){
			int e_ans = s[d][t];
			rep(k, 26){
				if(t == k)continue;
				e_ans -= cs[k] * (d - last[k]);
			}
			if(e_ans > m_plus){
				m_plus = sum + e_ans;
				m_type = t;
			}
		}
		sum = m_plus;
		last[m_type] = d;
		ans[d] = m_type + 1;
	}
	// cout<<sum<<endl;
	rep(i,D)cout<<ans[i]<<endl;
	// cout<<sum<<endl;
	return 0;
}

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


signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
 
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll mod=1e9+7;
    ll dp[n+1][n+1][256]={};
    dp[0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int t=0;t<256;t++){
                dp[i+1][j][t] += dp[i][j][t];
                dp[i+1][j+1][t] += dp[i][j][t^a[i]];
                dp[i+1][j][t]%=mod;
                dp[i+1][j+1][t]%=mod;
            }
        }
    }

    ll ans=0;
    ll perm=1;
    for(int i=1;i<=n;i++){
        perm *= i;
        perm%=mod;
        ans += (perm * dp[n][i][k])%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
    

}


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

int n, m;
vector<vector<int>> graph;
int cnt = 0;
vector<bool> seen;

void dfs (int now) {
    for (int next: graph[now]) {
        if (seen[next]) continue;
        else {
            seen[next] = true;
            dfs(next);
            seen[next] = false;
        }
    }
    bool all_seen = true;
    for (int i=0; i<n; ++i) {
        if (!seen[i]) all_seen = false;
    }
    if (all_seen) cnt++;
}

int main() {
    cin >> n >> m;
    graph.resize(n);
    seen.resize(n);
    for (int i=0; i<m; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    seen[0] = true;
    dfs(0);
    cout << cnt << endl;
}

Measured memory_bytes: 256
/*
Miles Morales : When will I know I'm ready?
Peter B. Parker : You won't. It's a leap of faith. That's all it is, Miles. A leap of faith.
*/
//KEEP IT SIMPLE STUPID

#include <bits/stdc++.h>

// #pragma GCC optimize("O3")
// #pragma GCC target("avx")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ll long long
#define MP make_pair
#define ERR cout << "================================================\n"
#define fi first
#define se second
#define PB push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define print(v)          \
	for (auto x : v)      \
	{                     \
		cout << x << " "; \
	}
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define SP << " " <<
#define W(t)  \
	ll t;     \
	cin >> t; \
	while (t--)
#define FIO                           \
	freopen("input.txt", "r", stdin); \
	freopen("output.txt", "w", stdout);
#define FAST                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);

using namespace std;

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

const ll INF = 1e18;
const ll NEG_INF = -1 * (1e18);
const ll MOD = 1e9 + 7;
using namespace std;

void usaco(string prob)
{
	freopen((prob + ".in").c_str(), "r", stdin);
	freopen((prob + ".out").c_str(), "w", stdout);
}

/* Function to check primality in O(sqrt(n)) */
bool prime(int n)
{
	if (n < 2)
		return false;
	for (int x = 2; x * x <= n; x++)
	{
		if (n % x == 0)
			return false;
	}
	return true;
}

/* Function to get prime factorization of n */
vector<int> getFactors(int n)
{
	vector<int> f;
	for (int x = 2; x * x <= n; x++)
	{
		while (n % x == 0)
		{
			f.push_back(x);
			n /= x;
		}
	}
	if (n > 1)
		f.push_back(n);
	return f;
}

void solve()
{
	/* Write Solution Here */
	ll n;
	cin >> n;
	vll a(n);
	forn(i, n) cin >> a[i];
	// sort(all(a));
	vll p(n, 0);
	p[n - 1] = a[n - 1];
	for (ll i = n - 2; i >= 0; i--)
	{
		p[i] = (p[i + 1] + a[i]) % MOD;
	}
	ll sum = 0;

	forn(i, n - 1)
	{
		sum = (sum % MOD + (a[i] * p[i + 1]) % MOD) % MOD;
	}
	cout << sum << "\n";
}

int main()
{
	//FIO
	FAST

		//usaco("cowlands");

		ll TC = 1;
	/*
	Uncomment when multiple test cases
	*/

	// cin>>TC;
	for1(tt, TC)
	{
		solve();
	}
	return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


Measured memory_bytes: 6328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());
      String line = in.readLine();
      int nHalf = n >> 1;

      int[] seqA = new int[nHalf];
      int[] seqB = new int[nHalf];

      Integer num;
      List<Integer> listA = new ArrayList<>();
      List<Integer> listB = new ArrayList<>();
      Map<Integer,Integer> mapA = new HashMap<>();
      Map<Integer,Integer> mapB = new HashMap<>();
      int offset=0,next=0;
      char regx = ' ';
      for(int i=0; i<n; i++) {
        if((next = line.indexOf(regx,offset)) == -1)
          next = line.length();
        num = new Integer(line.substring(offset, next));
        offset = ++next;

        if((i & 1) == 0) {
          seqA[i>>1] = num;
          if(mapA.containsKey(num)) {
            mapA.replace(num, mapA.get(num) + 1);
          } else {
            mapA.put(num, 1);
            listA.add(num);
          }
        }
        else {
          seqB[i>>1] = num;
          if(mapB.containsKey(num)) {
            mapB.replace(num, mapB.get(num) + 1);
          } else {
            mapB.put(num, 1);
            listB.add(num);
          }
        }
      }

      int vma,vmb,xa,xb;
      vma = vmb = xa = xb =0;
      for (Integer var : listA) {
        int ma = mapA.get(var);
        if(vma < ma) {
          vma = ma;
          xa = var;
        }
      }
      for (Integer var : listB) {
        int mb = mapB.get(var);
        if(vmb < mb) {
          vmb = mb;
          xb = var;
        }
      }

      int cca = nHalf - vma;
      int ccb = nHalf - vmb;

      int vma2,vmb2;
      vma2 = vmb2 = 0;
      int ans = 0;
      if(xa == xb) {
        for (Integer var : listA) {
          int ma = mapA.get(var);
          if(vma2 < ma && var != xa) {
            vma2 = ma;
          }
        }
        for (Integer var : listB) {
          int mb = mapB.get(var);
          if(vmb2 < mb && var != xb) {
            vmb2 = mb;
          }
        }
      
        int cca2 = nHalf -vma2;
        int ccb2 = nHalf -vmb2;

        ans = cca2 > ccb2 ? cca + ccb2 : cca2 + ccb;
      }
      else {
        ans = cca + ccb;
      }

      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    char a, b; cin >> a >> b;
    cout << ((a == b) ? "H" : "D") << endl;
    return 0;
}


Measured memory_bytes: 256
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_097_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 A      PIC 9(18).

    01 b      PIC 9(4).
    01 p      PIC 9(4).

    01 bp     PIC 9(18).

    01 tmp    PIC 9(18).
    01 ans    PIC Z(18).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT A.

    MOVE 1 TO tmp.

    PERFORM VARYING b FROM 2 BY 1 UNTIL A < b
        PERFORM VARYING p FROM 2 BY 1 UNTIL A < p
            COMPUTE bp = b ** p

            IF A < bp THEN
                EXIT PERFORM
            END-IF

            COMPUTE tmp = FUNCTION MAX(tmp, bp)
        END-PERFORM
    END-PERFORM.

    MOVE tmp TO ans.

    DISPLAY ans.
    STOP RUN.


Measured memory_bytes: 636
# D - Dice in Line

N, K = map(int, input().split())
P = list(int(x) for x in input().split())

S = [0]

for i in range(N):
    S.append(S[i]+P[i])

ans = 0

for j in range(K, N+1):
    if S[j]-S[j-K]>ans:
        ans = S[j]-S[j-K]

print(0.5*(K+ans))

Measured memory_bytes: 24804
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n+1), t(n+1);
    rep(i, n+1)cin >> a[i];
    ll now = 2;
    t[0] = 1;
  if(n == 0 && a[0] != 1){cout << -1; return 0;}
    if(a[0] > 0 && n != 0){cout << -1 << endl; return 0;}
    REP(i, n){
        if(t[i-1] >= 1000000000000000010){
            t[i] = inf;
            continue;
        }
        t[i] = 2*(t[i-1]) - a[i];
    }
    vector<ll> dp(n+1), m(n+1);
    dp[0] = 1; m[0] = 1;
    dp[n] = a[n]; m[n] = a[n];
    if(m[n] > t[n] + a[n]){cout << -1 << endl; return 0;}
    for(int i = n-1; i >= 1; i--){
        ll now = m[i+1] + a[i];
        if((now+1)/2 > 2 * (t[i-1])){cout << -1 << endl; return 0;}
        dp[i] = min(dp[i+1] + a[i], 2 * (t[i-1]));
        m[i] = ((m[i+1]+1)/2 + a[i]);
    }
    //rep(i, n+1)cout << t[i] << " "; cout << endl;
    //rep(i, n+1)cout << dp[i] << " "; cout << endl;
    cout << accumulate(all(dp), 0LL) << endl;
}


Measured memory_bytes: 6428
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

int main(){
	int a,b,c,d,k;
	cin>>a>>b>>c>>d>>k;
	a=a*60+b,c=c*60+d;
	a=c-a;
	a-=k;
	if(a<0)a=0;
	cout<<a<<endl;
}


Measured memory_bytes: 3544
import itertools
N, M, Q = map(int, input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
     a[i], b[i], c[i], d[i] = map(int, input().split())
ans = 0
for A in itertools.combinations_with_replacement(range(1, M+1), N):
    tmp = 0
    for i in range(Q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            tmp += d[i]
    ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 9220
N=int(input())
P=list(map(int, input().split()))
Q=list(map(int, input().split()))
base=sorted(Q.copy())
import itertools
count=1
for L in itertools.permutations(base):
    isp=True
    isq=True
    for i in range(N):
        if L[i]!=P[i]:
            isp=False
        if L[i]!=Q[i]:
            isq=False
    if isp:
        p=count
    
    if isq:
        q=count
    #print(L)
    count+=1

print(abs(p-q))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<int, pii> ppiii;
typedef vector<int> vi;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RREP(i,x) for(int i=(x)-1;i>=0;i--)
#define RFOR(i,c) for(auto i=(c).rbegin();i!=(c).rend();++i)
#define ALL(container) container.begin(), container.end()
#define SZ(container) ((int)container.size())

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;



int t, n;
int x, y;

int d[6][2] = {{0, 1},{1, 0},{0, -1},{-1, 0},{1,1},{-1,-1}};

main(){
	while(cin >> t >> n, t){
		set<pii> obst;
		REP(i, n){
			cin >> x >> y;
			obst.insert(pii(x, y));
		}
		int ans = 0;
		queue<ppiii> q;
		cin >> x >> y;
		q.push(ppiii(0, pii(x, y)));
		obst.insert(pii(x, y));
		while(!q.empty()){
			int c = q.front().first;
			pii s = q.front().second;q.pop();
			ans ++;
			if(c < t) REP(i, 6){
				pii t(s.first + d[i][0], s.second + d[i][1]);
				if(!obst.count(t)){
					q.push(ppiii(c+1, t));
					obst.insert(t);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1364
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

#define Min(a, b) (a < b ? a : b)

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  int c[10][10], a[h][w];
  for (int i=0; i<10; i++)
    for (int j=0; j<10; j++)
      scanf("%d", c[i]+j);
  for (int i=0; i<h; i++)
    for (int j=0; j<w; j++)
      scanf("%d", a[i]+j);
  int cost[10];
  for (int i=0; i<10; i++)
    cost[i] = c[i][1];
  for (int i=0; i<10; i++) {
    for (int j=0; j<10; j++) {
      for (int k=0; k<10; k++) {
        cost[j] = Min(cost[j], cost[k]+c[j][k]);
      }
    }
  }
  int ans = 0;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (a[i][j] == -1)
        continue;
      else
        ans += cost[a[i][j]];
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
left = 0
right = n-1
l = 0
r = 0
flag = false
until left>right
  if (l+a[left]-r).abs < (l-r-a[right]).abs
    l += a[left]
    left += 1
  else
    r += a[right]
    right -= 1
  end
end
p (l-r).abs


Measured memory_bytes: 16132
import sys
from math import sqrt, floor

def divisors(n):
    res = set()
    for i in range(1, floor(sqrt(n)) + 1):
        if n % i == 0:
            res.add(i)
            res.add(n // i)
    return res

n = int(sys.stdin.readline().rstrip())

def main():
    res = divisors(n - 1)
    cnt = len(res) - 1 + 1
    for i in range(2, floor(sqrt(n)) + 1):
        if i in res: continue
        m = n
        while m % i == 0:
            m //= i
            if (m - 1) % i == 0:
                cnt += 1
    print(cnt)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 3064
#include <stdio.h>

int main() {
	int sum, border, i, cnt = 0;
	int h;

	scanf("%d %d", &sum, &border);
	for (i = 0; i < sum; i++) {
		scanf("%d", &h);
		if (border <= h) {
			cnt++;
		}
	}

	printf("%d\n", cnt);

	return 0;
}

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

#define ll long long
#define ld long double
typedef vector <ll> vi;                 // Vector of long long
typedef vector <vi> vvi;                // Vector of vi
typedef vector <pair<ll,ll>> ii;        // Vector of pairs
#define ff first                        // For pairs
#define ss second                       // For pairs
#define sz(a) int((a).size())           // Function to determine size of any container
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define MAXK (ll)((1e5 * 3) + 5)
#define MAXN (ll)(1e2 + 10)
#define MOD (ll)(1e9 + 7)

#define mod(a) (((a % MOD) + MOD) % MOD)

ll dp[MAXN][MAXK];
ll n;
vi arr;

int main(void)
{
    memset(dp, 0, sizeof(dp));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll k;
    cin >> n >> k;
    arr.resize(n);
    for (int i = 0; i < n; i++)
        cin >> arr[i];    

    for (int i = k; i >= 0; i--)
            if (k - i <= arr[0])
                dp[0][i] = mod(dp[0][i + 1] + 1);
            else
                dp[0][i] = dp[0][i + 1];
        
    for (int i = 1; i < n; i++)
        for (int j = k; j >= 0; j--)
            dp[i][j] =  mod(dp[i][j + 1] + mod(dp[i - 1][j] - dp[i - 1][j + arr[i] + 1]));

    cout << mod(dp[n - 1][0] - dp[n - 1][1]) << "\n";
}

Measured memory_bytes: 258048
import sys
input=sys.stdin.readline
n=int(input())
a_list=list(map(int,input().split()))
rate=[False]*8
free=0
for i in a_list:
    if i<3200:
        rate[i//400]=True
    else:
        free+=1
count=0
for i in rate:
    if i:
        count+=1
if count==0:
    Min=1
else:
    Min=count
Max=count+free
print(Min,Max)








Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int n;
	cin>>n;
	ll money=1000;
	vector<ll>a(n);
	ll stock=0;
	vector<ll>trend;
	rep(i,n){
		cin>>a[i];
		if(i){
			if(a[i-1]<a[i]){
				trend.push_back(a[i-1]);
				trend.push_back(a[i]);
			}
		}
	}
	rep(i,trend.size()){
		if(i%2==0){
			stock=money/trend[i];
			money=money-stock*trend[i];
		}else{
			money+=stock*trend[i];
			stock=0;
		}
	}
	cout<<money<<endl;
	
}

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


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include<stdint.h>
using namespace std;
#define vi vector<int> 
#define pb push_back
#define w(t)   int t;cin>>t;while(t--) 
#define show(ar) for(int i=0;i<ar.size();i++) cout<<ar[i]<<" "; cout<<endl;
#define mod 1e9+7
#define ff first
#define ss second 
#define fio ios::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL);
#define all(x) (x.begin(),x.end())
#define inf 1e9+7


vi inp(int n)
{
	vi v; int x;
	for(int i=0;i<n;i++) {
		cin>>x; v.pb(x);
	}
	return v; 
}


int main()
{
	string s1,s2;
	cin>>s1>>s2;
	if(s1.size()+1!=s2.size())
	{
		cout<<"No\n"; return 0;
	}
	for(int i=0;i<s1.size();i++)
	{
		if(s1[i]!=s2[i])
		{
			cout<<"No\n"; return 0;
		}
	}
	cout<<"Yes\n";
}

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

int main(){
  	ll n,r=0,g=0,b=0;
    string s;
    cin>>n>>s;
    for(ll i=0; i<n; i++) {
        if(s[i]=='R') r++;
        if(s[i]=='G') g++;
        if(s[i]=='B') b++;
    }
  	ll ans=r*g*b;
    for(ll i=0; i<n; i++) {
        for(ll j=i+1; j<n; j++) {
            ll k=2*j-i;
            if(k>=n) break;
            if(s[j] != s[k] && s[i] != s[k] && s[i] != s[j]) ans--;
        }
    }
	cout<<ans;
}

Measured memory_bytes: 3620
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

ll dp[110][4][4][4] = {};


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

    ll a = 0;
    ll g = 1;
    ll c = 2;
    ll t = 3;

    // input
    ll N;
    cin >> N;

    FOR(i, 0, 4){
        FOR(j, 0, 4){
            FOR(k, 0, 4){
                dp[2][i][j][k] = 1;
            }
        }
    }
    // agc
    dp[2][a][g][c] = 0;
    dp[2][a][c][g] = 0;
    dp[2][g][a][c] = 0;

    FOR(i, 2, N){
        FOR(l, 0, 4){
            FOR(m, 0, 4){
                FOR(n, 0, 4){
                    FOR(o, 0, 4){
                        if(l==a && m==g && n==c) continue;
                        if(l==a && m==c && n==g) continue;
                        if(l==g && m==a && n==c) continue;
                        
                        // A*GC
                        if(o==c && l==a && n==g) continue;
                        // AG*C
                        if(o==c && l==a && m==g) continue;

                        dp[i][m][n][o] += dp[i-1][l][m][n];
                        dp[i][m][n][o] %= mod;
                    }
                }
            }
        }

        dp[i][a][g][c] = 0;
        dp[i][a][c][g] = 0;
        dp[i][g][a][c] = 0;
    }

    ll sum = 0;
    FOR(l, 0, 4){
        FOR(m, 0, 4){
            FOR(n, 0, 4){
                sum += dp[N-1][l][m][n];
                sum %= mod;
            }
        }
    }

    p(sum);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for (int i=(a); i>=(b); --i)
#define REP(i,b) for (int i=0; i<(b); ++i)
#define endl '\n'
#define sz(x) (int) x.size()
#define mod %
#define fillchar(x,y,z) memset(x,z,y)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define sqr(x) ((x)*(x))
typedef long long int64;
typedef unsigned long long qword;
using namespace std;
const int maxn=3005;
const int base=1e9+7;
int n;
int f[maxn][maxn];
char a[maxn];
void Input()
{
    cin >> n;
    cin >> (a+1);
}
void Solve()
{
    f[1][1]=1;
    FOR(i,2,n) {
        FOR(j,1,i) {
            if (a[i-1]=='<')  //x[i-1]<x[i]
                f[i][j]=f[i-1][j-1];
            else
                f[i][j]=f[i-1][i-1]-f[i-1][j-1];
            f[i][j]+=f[i][j-1];
            if (f[i][j]>=base) f[i][j]-=base;
            if (f[i][j]<0) f[i][j]+=base;
        }
    }
    cout << f[n][n];
}
int main()
{
    #ifdef meomeomeooooo
        freopen("input.txt","r",stdin);
        //freopen(".out","w",stdout);
    #endif // meomeomeooooo
    iostream::sync_with_stdio(false);
    cin.tie(0);
    Input();
    Solve();
    return 0;
}


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

int main() {
  int x,y,z;cin>>x>>y>>z;
  x-=z;
  int ans=x/(y+z);
  cout<<ans<<endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define fin(x) cout << x << endl;

using namespace std;
using ll = long long;

bool check(int a, int b, int c, string s, int n) {
  int v[3] = {a, b, c};
  int cnt = 0;
  rep(i, n) {
    int num = (int)(s[i] - '0');
    if (v[cnt] == num) {
      cnt++;
    }
  }
  if (cnt >= 3) {
    return true;
  } else {
    return false;
  }
}

int main(void) {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i, 10) {
    rep(j, 10) {
      rep(k, 10) {
        if (check(i, j, k, s, n)) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, K;
  cin >> N >> K;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> P(N);
  for (int64_t i = 0; i < N; ++i) {
    cin >> P[i];
  }
  sort(P.begin(), P.end());
  int64_t result = 0;
  for (int64_t i = 0; i < K; ++i) {
    result += P[i];
  }
  cout << result << endl;
  return 0;
}


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

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<vector<int>> A(N, vector<int>(M));
    vector<int> C(N);
    int ans = INFINITY;
    bool exist = 0;

    for (int i = 0; i < N; i++) {
        cin >> C.at(i);
        for (int j = 0; j < M; j++) {
            cin >> A.at(i).at(j);
        }
    }

    for (int bit = 0; bit < (1<<N); bit++) {
        int price = 0;
        vector<int> understand(M, 0);
        for (int i = 0; i < N; i++) {
            if (bit & (1<<i)) {
                price += C.at(i);
                for (int j = 0; j < M; j++) {
                    understand.at(j) += A.at(i).at(j);
                }
            }
        }
        bool next = 0;
        for (int i = 0; i < M; i++) {
            if (understand.at(i) < X) {
                next = 1;
                break;
            }
        }
        if (next == 0) {
            exist = 1;
            ans = min(ans, price);
        }
    }
    if (exist == 0) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 3548
open System

let modConst = 1e9+7. |> int64

let modadd x y = (x + y) % modConst

let modsub x y = (x + modConst - y) % modConst

let N = stdin.ReadLine() |> int64

let modpow x y =
    let rec submodpow accum index =
        match index with
        | _ when index = y -> accum
        | _ -> submodpow (accum * x % modConst) (index + 1L)

    submodpow 1L 0L

let solveF x = modpow x N

printfn "%d" ((modadd (modsub (modsub (solveF 10L) (solveF 9L)) (solveF 9L)) (solveF 8L)) % modConst)

Measured memory_bytes: 29980
N, M = map(int, input().split())
inputs = [[int(i) for i in input().split()] for _ in range(N)]

inputs.sort()
count = 0
ans = 0
for A, B in inputs:
    if M < 0:
        break
    ans += A * min(B, M)
    M -= B

print(ans)


Measured memory_bytes: 21608
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
 
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
 
typedef long long ll;
typedef complex<double> P;
typedef complex<double> Vec;
typedef pair<int, int> pii;
typedef pair<int, pii> p;
 
#define INF (1<<29)
#define INFL (1ll<<60)
#define EPS (1e-10)
#define PI (acos(-1))
const ll MOD = 1000000007ll;

int main() {
	ll s, c;
	cin >> s >> c;
	
	ll ans;
	
	ans = min(s, c / 2);
	c -= ans * 2;
	ans += c / 4;
	
	cout << ans << endl;
	return 0;
}


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

int main(){
    int N, a;
    bool r = true;
    cin >> N;
    
    for (int i = 0; i < N; i++)
    {
        cin >> a;
        if (a % 2 == 0) {
            if (a % 3 != 0 and a % 5 != 0){
                r = false;
                break;
            } 
            
        }
    }

    if (r) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;

}

Measured memory_bytes: 256
module mod_selection_sort
  implicit none
  integer, private, parameter :: intkind = 4
contains
  logical function less(a, b) result(res)
    integer(intkind), intent(in) :: a, b
    res = a <= b
  end
  subroutine swap(a, b)
    integer(intkind), intent(inout) :: a, b
    a = xor(a, b)
    b = xor(a, b)
    a = xor(a, b)
  end
  subroutine selection_sort(a)
    integer(intkind), intent(inout) :: a(:)
    integer :: n, i, j, m
    n = size(a)
    do i = 1, n - 1
      m = i
      do j = i + 1, n
        if (.not.less(a(m), a(j))) m = j
      end do
      if (i /= m) call swap(a(i), a(m))
    end do
  end
end module mod_selection_sort
program brave_chain
  use mod_selection_sort
  implicit none
  integer, parameter :: inf = 1e9
  integer :: n, a(6000) = 0, t, dp(2000, 2000) = -inf, m = 0, b(3) = 0, v, i, j
  integer, dimension(2000) :: dp0 = 0, mv = -inf, mv0 = 0
  read(*,*) n
  t = 3 * n
  read(*,*) a(1:t)
  call update(a(1), a(2), 0)
  do i = 3, t - 2, 3
    if (a(i) == a(i + 1) .and. a(i) == a(i + 2)) then
      m = m + 1
      cycle
    end if
    call selection_sort(a(i:i + 2))
    if (a(i + 1) == a(i + 2)) call swap(a(i), a(i + 2))
    do j = 1, n
      dp0(j) = dp(min(a(i), j), max(a(i), j))
    end do
    mv0(1:n) = mv(1:n)
    v = max(0, maxval(mv(1:n)))
    do j = 1, 3
      b(j) = dp(a(i + j - 1), a(i + j - 1))
    end do
    if (a(i) == a(i + 1)) then
      do j = 1, n
        call update(a(i + 2), j, dp0(j) + 1)
      end do
    end if
    call update(a(i + 1), a(i + 2), b(1) + 1)
    call update(a(i), a(i + 2), b(2) + 1)
    call update(a(i), a(i + 1), b(3) + 1)
    call update(a(i + 1), a(i + 2), v)
    call update(a(i), a(i + 2), v)
    call update(a(i), a(i + 1), v)
    do j = 1, n
      call update(a(i), j, mv0(j))
      call update(a(i + 1), j, mv0(j))
      call update(a(i + 2), j, mv0(j))
    end do
  end do
  write(*,'(i0)') max(dp(a(t), a(t)) + 1, maxval(mv(1:n))) + m
contains
  subroutine update(a, b, z)
    integer, intent(in) :: a, b, z
    integer :: x, y
    if (a > b) then
      x = b
      y = a
    else
      x = a
      y = b
    end if
    if (dp(x, y) >= z) return
    dp(x, y) = z
    mv(x) = max(mv(x), z)
    mv(y) = max(mv(y), z)
  end
end program brave_chain

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

int Solve(int n,int a[]) {
	int Alice = 0;
	int Bob = 0;
	int rinji,i,j;
	for (i = 0;i < n;i++) {
		for (j = i;j < n;j++) {
			if (a[i] < a[j]) {
				rinji = a[i];
				a[i] = a[j];
				a[j] = rinji;
			}
		}
	}
	for (i = 0;i < n;i++) {
		if (i % 2 == 0)
			Alice += a[i];
		else
			Bob += a[i];
	}
	return Alice - Bob;
}
int main() {
	int n;
	scanf("%d", &n);
	int a[100];
	for (int i = 0;i < n;i++) {
		scanf("%d", &a[i]);
	}
	printf("%d",Solve(n,a));
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)

const double PI=4*atan(1.0);

int main(){

    double r;
    while(cin>>r&&!EQ(r,0)){
        bool f=false;
        for(int i = 1; ; i++){
            for(int j = i*2; !(((double)j/i)>PI+r+EPS); j++){
                if(EQ(abs(((double)j/i)-PI),r)||abs(((double)j/i)-PI)<r){
                    f=true;
                    cout<<j<<"/"<<i<<endl;
                    break;
                }
            }
            if(f)
                break;
        }
    }
    return 0;
}

Measured memory_bytes: 952
#include <stdio.h>

void call(int n)
{
    int i = 1;

    do {
        int x = i;
        if(x % 3 == 0) {
            printf(" %d", x);
            continue;
        }
        while(x > 0) {
            if(x % 10 == 3) {
                printf(" %d", i);
                break;
            }
            x /= 10;
        }
    } while(++i <= n);
    putchar('\n');
}

int main(void)
{
    int n;

    scanf("%d", &n);

    call(n);

    return 0;
}

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

int main(){
  string x;
  cin >> x;
  int s = 0, t = 0;
  for(int i = 0 ; i < x.size(); ++ i){
    if(x[i] == 'S'){
      s++;
    }
    else{
      if(s != 0){
	s--;
      }else t++;
    }

  }

  cout << s + t << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;



int main() {

  int N;
  cin >> N;

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

  int cnt = 0;
  for(int i = 0; i < N-1; ++i) {
    if(a[i]==a[i+1]) {
      cnt += 1;
      i += 1;
    }
  }

  cout << cnt << endl;

}


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

int main(void){
    int N;
    cin >> N;
    int w[N];
    int s1 = 0, s2 = 0;
    
    for (int i = 0; i < N; i++){
        cin >> w[i];
        s2 += w[i];
    }

    int tmp = s2;

    for(int i = 0; i< N; i++){
        if(tmp > abs((s1+w[i])-(s2-w[i]))){
            tmp = abs((s1+w[i])-(s2-w[i]));
            s1 += w[i];
            s2 -= w[i];
        }else{
            break;
        }
        
    }


    cout << tmp << endl;

    return 0;
}

Measured memory_bytes: 256
n=input().split()
m=input().split()

N=n[0]
Nn=n[1]
l = 0
a = 0

for k in range(int(N)):
    a+=int(m[k])

for i in range(int(N)):
    if int(m[i])/(a/(int(Nn)*4)) >= 1:
        l+=1

if l >= int(Nn) :
    print("Yes")
else :
    print("No")

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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BAtCoderBeginnerContest111 {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int n;
	    in >> n;
	    int res;
	    for(int i=n; i<=999; i++){
	        if(i >= n){
	            int buf = i;
	            int a = buf % 10; buf /= 10;
	            int b = buf%10; buf /= 10;
	            int c = buf%10; buf /= 10;
	            if(a == b && b == c){
	                res = i;
	                break;
	            }
	        }
	    }

	    out << res << endl;
	}
};


int main() {
	BAtCoderBeginnerContest111 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 rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  vector<string> s(3);
  rep(snip_i, 3) cin >> s.at(snip_i);
  vector<vector<int>> v(3);
  rep(i, 3){
    rep(j, s.at(i).size()){
      v.at(i).push_back(s.at(i).at(j) - 'a');
    }
  }
  int tr = 0;
  vector<int> index(3, 0);
  while(1){
    if(index.at(tr) == s.at(tr).size()){
      char ans = tr + 'A';
      cout << ans << endl;
      return 0;
    }
    int nx = v.at(tr).at(index.at(tr));
    index.at(tr)++;
    // cerr << tr << " " << nx << endl;
    tr = nx;
  }

  return 1;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int bai,hiku,moto,i;
  scanf("%d %d %d",&bai,&hiku,&moto);
  for(i=0;i<10;i++){
    moto*=bai;
    moto-=hiku;
    printf("%d\n",moto);
  }
  return 0;
}
  


Measured memory_bytes: 128
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
ll gcd(ll a, ll b)
{
	for (;;)
	{
		if (a < b)swap(a, b);
		a %= b;
		if (a == 0)return b;
	}
}
int main()
{
	int num, way;
	scanf("%d%d", &num,&way);
	set<int>se;
	for (int i = 0; i < way; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		int x = -1;
		if (za == 1)x = zb;
		if (zb == num)x = za;
		if (x != -1)
		{
			if (se.find(x) != se.end())
			{
				printf("POSSIBLE\n");
				return 0;
			}
			se.insert(x);
		}
	}
	printf("IMPOSSIBLE\n");
}

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

using namespace std;
using ll = unsigned long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 998244353;

const int CASES = 3;

void solve() {
    ll N; cin >> N;
    ll ans = N/2;
    if(N % 2 == 0){
        --ans;
    }
    cout << ans << endl;

    return ;
}

int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,x;
  cin >>n>>x;
  vector<int>L(n);
  for(int i=0;i<n;i++){
    cin>>L.at(i);
  }
  int count=1;
  int d=0;
  while(x>d){
    int tmp=d;
    d=tmp+L.at(count-1);
    if(d>x)break;
    //cout<<d<<endl;
    count++;
    if(count>n)break;
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
def postorder(g):
    parent_stack = []
    dfs_stack = [(0, None)]            
    while dfs_stack:
        u, prev = dfs_stack.pop()
        dfs_stack.extend((t, u) for d, t in g[u])
        while parent_stack and parent_stack[-1] != prev:
            yield parent_stack.pop()
        parent_stack.append(u)
    while parent_stack:
        yield parent_stack.pop()

from sys import stdin
from collections import defaultdict
readline = stdin.readline

n = int(readline())
g = defaultdict(list)
for _ in range(n - 1):
    s, t, d = map(int, readline().split())
    g[s].append((d, t))
diameter = [0]
dp = [0] * n
for i in postorder(g):
    if len(g[i]) == 0:
        continue
    candidate = sorted(d + dp[t] for d, t in g[i])
    dp[i] = candidate[-1]
    diameter.append(dp[i] if len(candidate) == 1 else sum(candidate[-2:]))

print(max(diameter))

Measured memory_bytes: 46652
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[5];
int main(){
//	freopen("b.in","r",stdin);
//	freopen("b.out","w",stdout);
	cin>>a[1]>>a[2]>>a[3];
	sort(a+1,a+1+3);
	int ans=0;
	ans+=(a[3]-a[1])/2;
	a[1]+=ans*2;
	ans+=(a[3]-a[2])/2;
	a[2]+=(a[3]-a[2])/2*2;
	if(a[1]==a[2] && a[2]==a[3]) cout<<ans;
	else if(a[1]==a[2]) cout<<ans+1;
	else cout<<ans+2;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int left[n][31],right[n][31];
    rep(i,n)rep(j,31)left[i][j]=right[i][j]=0;
    rep(i,n){
        for(ll bit=0;bit<31;bit++){
            if(a[i]&(1ull<<bit)) left[i][bit]++;
        }
        for(ll bit=0;bit<31;bit++){
            if(a[n-1-i]&(1ull<<bit)) right[n-1-i][bit]++;
        }
    }
    rep(i,n-1){
        rep(j,31){
            left[i+1][j]+=left[i][j];
            right[n-2-i][j]+=right[n-1-i][j];
        }
    }
    rep(i,n){
        ll ans=0;
        if(i==0){
            rep(j,31){
                if(right[1][j]%2==1) ans+=(1ull<<j);
            }
        }else if(i==n-1){
            rep(j,31){
                if(left[n-2][j]%2==1) ans+=(1ull<<j);
            }
        }else{
            rep(j,31){
                if((left[i-1][j]+right[i+1][j])%2==1) ans+=(1ull<<j);
            }
        }
        cout << ans << " ";
    }
    
}


Measured memory_bytes: 52500
N, M = (int(x) for x in input().split())
edge = [tuple(int(x) for x in input().split()) for _ in range(M)]

import numpy as np
from scipy.sparse.csgraph import floyd_warshall
INF = 100
tmpl_graph = [[INF if i != j else 0 for j in range(N)] for i in range(N)]

ans = 0
for E in edge:
    edgeWithoutE = edge.copy()
    edgeWithoutE.remove(E)
    graph = np.array(tmpl_graph)
    for x in edgeWithoutE:
        graph[x[0]-1,x[1]-1] = 1
        graph[x[1]-1,x[0]-1] = 1
    graph = floyd_warshall(graph,directed=False)
    if len(graph[graph == 100]) > 0:
        ans += 1
print(ans)

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define INF 1000000007
#define N 510
int n;
string a[N];

int main() {
	cin >> n;
	for (int i = 0; i < n; i ++) cin >> a[i];
	int U = 0;
	for (int j = 0; j < n; j ++) {
		bool F = false;
		for (int i = 0; i < n; i ++)
			if (a[i][j] == '.') F = true;
		if (F) U++;
	}
	
	bool E = true;
	for (int i = 0; i < n; i ++)
		for (int j = 0; j < n; j ++)
			if (a[i][j] == '#') E = false;
	if (E) {
		puts ("-1");
		return 0;
	}
	
	int S = INF;
	
	for (int i = 0; i < n; i ++) {
		int T = U;
		bool F = false;
		for (int k = 0; k < n; k ++)
			if (a[k][i] == '#') F = true;
		if (!F) T++;
		for (int j = 0; j < n; j ++)
			if (a[i][j] == '.') T++;
		S = min(S, T);
	}
	if (S == INF) puts ("-1");
	else printf ("%d\n", S);
	return 0;
}

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

struct info{

    int a, b, c; // c means a + b
    info(int a, int b, int c):a(a),b(b),c(c){}
    info(){}

    bool operator<(const info& t) const{ return c > t.c; }
    bool operator>(const info& t) const{ return c < t.c; }
};

signed main(){


    int n; cin >> n;
    vector<info> vec(n); 
    for(int i = 0; i < n; i++){
        int a, b; cin >> a >> b;
        vec[i] = info(a, b, a + b);
    }

    sort(vec.begin(), vec.end());
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(i % 2 == 0) ans += vec[i].a;
        else ans -= vec[i].b;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560