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

using namespace std;


int main()
{
    std::ios::sync_with_stdio(false);
  
    int n;
    cin>>n;

    int a[n+1],b[n+1],c[n];
    for(int i = 1;i <= n;i++)
    {
        cin>>a[i];

    }
    for(int i = 1;i <= n;i++)
    {
        cin>>b[i];
    }
    for(int i = 1;i < n;i++)
    {
        cin>>c[i];
    }
    int sum = 0;
    for(int i = 1;i <= n;i++)
    {
        sum += b[a[i]];
        //cout<<b[a[i]]<<endl;
        if(a[i] >= 2&&a[i] == a[i-1] + 1)
        {
            //cout<<c[a[i]]<<endl;
            sum += c[a[i-1]];
        }
    }
    cout<<sum;
        return 0;
}


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

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int n; cin >> n;
  vector<pair<int,int> > p;
  
  ll res = 0;
  rep(i,n) {
    int x,y; cin >> x >> y;
    p.pb(make_pair(x,y));
  }

  sorti(p);
  

  res += p[p.size()-1].first - p[0].first + 1;
  res += p[0].first - 1;
  res += p[p.size()-1].second - 0;

  cout << res << endl;
}


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

template <class InputIterator1, class InputIterator2>
ll f(ll N, InputIterator1 it1, InputIterator2 it2)
{
    auto first = *it1;
    auto last = *it1;
    ll res = 0;
    while (true) {
        res += abs(*it1 - last);
        last = *it1;
        it1++;
        N--;
        if (N == 1) {
            break;
        }
        res += abs(*it2 - last);
        last = *it2;
        it2++;
        N--;
        if (N == 1) {
            break;
        }
    }
    res += max(abs(first - *it1), abs(last - *it1));
    return res;
}

void main_()
{
    ll N;
    cin >> N;
    vector<ll> As;
    As.reserve(N);
    copy_n(istream_iterator<ll>(cin), N, back_inserter(As));

    sort(begin(As), end(As));

    ll ans = max(f(N, begin(As), rbegin(As)), f(N, rbegin(As), begin(As)));
    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,(e))
#define irp(i,s,e) for(int i=(s);i>(e);--i)
#define irpz(i,s) irp(i,(s),-1)
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(b<a){a=b;return 1;}return 0;}

int N,K;
ll solve(){
	ll ans = 0;
	while(N){
		N/=K;
		ans++;
	}

	return ans;
}

int main(){
	cin>>N>>K;
	cout<< solve() <<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
int main()
{
	ll n;
	cin>>n;
	bool flag=0;
	ll rem=7%n;
	for(int i=0;i<=1e7;i++){

		//cout<<nrem<<endl;

		if(rem==0){
			cout<<i+1<<endl;
			flag=1;
			break;
		}
		
		rem=((rem*10)+7)%n;

	}


	if(!flag)
	{
		cout<<-1<<endl;
	}
	return 0;
}

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, int> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

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

    if (n == 1) {
        cout << "a" << endl;
        ret();
    }
    queue<string> q;
    q.push("a");

    vector<string> ans;

    while (!q.empty()) {
        string t = q.front();
        q.pop();
        if (t.size() == n) {
            ans.push_back(t);
        } else {
            char max_c = *max_element(t.begin(), t.end());
            for (char b = 'a'; b <= max_c+1; b++) {
                string u = t + b;
                q.push(u);
            }
        }
    }
    sort(ans.begin(), ans.end());

    for (string s : ans) cout << s << endl;

}

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

using namespace std;

int main(){  
  int H, W;
  while(1){
    cin >> H >> W;
    if( (H == 0) && (W == 0)){
      break;  
    }
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        cout << "#";
      }
      cout << "" << endl;
    }
    cout << "" << endl;
  }
  return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;
ll A[MAX_N];
ll S[MAX_N];

int main2() {
  int N = nextInt();
  int M = nextInt();
  REP(i, N) A[i] = nextInt();
  REP(i, N) S[i+1] = S[i] + A[i];

  map<ll, int> count;
  ll ans = 0;
  REP(i, N+1) {
    ans += count[ S[i]%M ];
    count[S[i]%M]++;
  }

  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
const int loose = 0;
const int tight = 1;

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n;
	cin >> n;

	bool flag = true;
	REP(i, n) {
		ll a;
		cin >> a;
		if (a % 2 == 0) {
			if (a % 3 != 0 && a % 5 != 0) {
				flag = false;
			}
		}
	}

	cout << ((flag) ? "APPROVED" : "DENIED") << en;

	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	static Scanner in = new Scanner(System.in);
	public static void main(String[] args){
		int n = in.nextInt();
		int[] color = new int[9];
		Arrays.fill(color, 0);
 
		for(int i = 0; i < n; i++){
			int a = in.nextInt();
			if(a > 3199){
				color[8]++;
			}else if(a > 2799){
				color[7]++;
			}else if(a > 2399){
				color[6]++;
			}else if(a > 1999){
				color[5]++;
			}else if(a > 1599){
				color[4]++;
			}else if(a > 1199){
				color[3]++;
			}else if(a > 799){
				color[2]++;
			}else if(a > 399){
				color[1]++;
			}else{
				color[0]++;
			}
		}
		int s = 0;
		for(int i = 0 ; i < 8; i++){
			if(color[i] != 0){
				s++;
			}
		}
		if(s != 0){
			System.out.println(s + " " + (s+color[8]));
		}else{
			System.out.println("1 " + Math.min(color[8], 8));
		}
	}
 
}

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

static const int MAX = 51;
ll dp[MAX][2*MAX*MAX];
int x[MAX];

int main(){
    int n, a;
    cin >> n >> a;
    for(int i = 0; i < n; i++){
        cin >> x[i];
        x[i] -= a;
    }
    dp[0][n*50] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= 2*n*50; j++){
            dp[i][j] = dp[i-1][j];
            if(j >= x[i-1] && j - x[i-1] <= 2*n*50)
                dp[i][j] += dp[i-1][j-x[i-1]];
        }
    }
    cout << dp[n][n*50]-1 << endl;
    return 0;
}

Measured memory_bytes: 5656
while 1:
  try:
    c=[0]*101
    while 1:
      a,b=map(int,raw_input().split())
      if a==b==0: break
      c[a]+=1
      c[b]+=1
    c=map(lambda x:x%2,c)
    if c[1]==1==c[2] and sum(c[3:])==0: print"OK"
    else: print"NG"
  except: break

Measured memory_bytes: 4216
import sys
s = input()
K = int(input())

a_list = sorted(set(s))
for i in a_list:
  if K == 1:
    print(i)
    sys.exit()
  p = []
  for j, x in enumerate(s):
    if x == i:
      p.append(s[j:min(j+K,len(s))])
  p.sort()
  t = K
  for j in range(len(p)):
    if j != len(p) - 1:
      if p[j] == p[j+1][0:len(p[j])]:
        continue
    if len(p[j]) < t:
      t -= len(p[j]) - 1
    else:
      print(p[j][0:t])
      sys.exit()
  K = t - 1

Measured memory_bytes: 9412
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
typedef long long lint;
const int N=1e5+5;
int n,q,lim,val[N];

namespace utils{
	template <class T> inline void apn(T &x,const T y){x>y?x=y:0;}
	template <class T> inline void apx(T &x,const T y){x<y?x=y:0;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	n=nxi(),q=nxi(),lim=nxi();
	for(int i=1; i<=n; ++i)
		val[i]=nxi();
	std::sort(val+1,val+n+1);
	int ans=0;
	for(int i=1,r=-1,c=0; i<=n; ++i){
		if(val[i]>r||c>=q)
			++ans,r=val[i]+lim,c=0;
		++c;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 640
a = 2, 3, 5

def f(n):
  m = memo.get(n)
  if m is None:
    nd = m = n * d
    for p, c in zip(a, b):
      p *= d
      k, r = divmod(nd, p);
      m = min(m, f(k) + r + c, f(k + 1) + p - r + c if r else m)
    memo[n] = m
  return m

t = int(input())
for _ in range(t):
  n, *b, d = map(int, input().split())
  memo = {0: 0, 1: d}
  print(f(n))


Measured memory_bytes: 10788
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    int a, b;
    cin >> a >> b;
    cout << (a + b) % 24 << endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
from collections import deque
n = int(stdin.readline())
M = [[0] * (n + 1) for _ in range(n + 1)]
d = [200] * (n + 1)
def bfs():
    d[1] = 0
    dq = deque()
    dq.append(1)
    while len(dq) > 0:
        u = dq.popleft()
        for v in range(1, n + 1):
            if M[u][v] == 0 or d[v] != 200: continue
            d[v] = d[u] + 1
            dq.append(v)
    for i in range(1, n + 1):
        print(i, (-1 if d[i] == 200 else d[i]))
for u in range(1, n + 1):
    U = [int(j) for j in stdin.readline().split()]
    for v in U[2:]:
        M[u][v] = 1
bfs()

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

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

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

int main(){
  int H,W,A,B;
  cin >> H >> W >> A >> B;
  vector<vector<int>> mat(H, vector<int>(W));

  for(int i = 0;i<H;i++){
    if(i < H-B){
      for(int j = 0;j<W;j++){
        if(j < A) mat[i][j] = 1;
        else mat[i][j] = 0;
      }
    }
    else if(i >= H-B){
      for(int j = 0;j<W;j++){
        if(j < A) mat[i][j] = 0;
        else mat[i][j] = 1;
      }
    }

  }
  rep(i,H){
    rep(j,W){
      cout << mat[i][j];
      if(j == W-1) cout << endl;
    }
  }
  
}

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

int MOD(int a, int b){
  int x = a % b;
  if(x >= 0)
    return (x);
  else
    return (x + b);
}

int main(){
  int N, K;
  int mod = 998244353;
  cin >> N >> K;
  vector<int> L(K);
  vector<int> R(K);
  for(int i = 0; i < K; i++)
    cin >> L[i] >> R[i];
  vector<int> dp(N+1);
  vector<int> s(N+1);
  dp[1] = 1;
  s[1] = 1;
  for(int i = 2; i <= N; i++){
  	for(int j = 0; j < K; j++){
      int l = max(i - R[j], 1);
      int r = i - L[j];
      if(r < 1)	continue;
      dp[i] = MOD(dp[i] + s[r] - s[l-1], mod);
    }
    s[i] = MOD(s[i-1] + dp[i], mod);
  }
  cout << dp[N] << endl;
  return 0;
}

Measured memory_bytes: 4824
#include <bits/stdc++.h>
 
//LIFE IS NOT A PROBLEM TO BE SOLVED
 
#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define REP(i,a,b) for( int i = (int) a; i <= (int) b; i++ )
#define PER(i,a,b) for( int i = (int) a; i >= (int) b; i-- )
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugP(a) cout << a.F << " " << a.S << endl;
#define debugV(v, n) { rep( i, 0, n ) { if(i) printf(" "); printf("%d", v[i]); } printf("\n"); }
#define debugM(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) { if(j) printf(" "); printf("%d", mat[i][j]); } printf("\n"); }
#define debugMD(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) { if(j) printf(" "); printf("%.2lf", mat[i][j]); } printf("\n"); }
 
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair <double, double> ii;
typedef pair <double, ii> iii;
 
const int MAX = 2e3+3;
const int mod = 1e9+7;
 
 
int main(){
	
	char c; cin >> c;
	if(c>='a' && c<='z') cout << (char) 'a';
	else cout << (char) 'A' ;
	
	
	
	
	
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int X[99999],DP[2000000];
vector<int> Y,E[2000000];
int main() {
    int N,M;
    scanf("%d %d",&N,&M);
    for(int i=0;i<M;i++) {
          int D,P;
          scanf("%d %d",&D,&P);P--;
          X[P]=D;
    }
    for(int i=M;i<N;i++) {
        int D;
        scanf("%d",&D);
        Y.push_back(D);
    }
    int k=N;
    for(int i=0;i+3<=k;i+=3) {
        E[k].push_back(i);
        E[k].push_back(i+1);
        E[k].push_back(i+2);
        k++;
    }
    int l=0,r=1000000001;
    while(r-l>1) {
        int m=(l+r)/2;
        int high=0;
        for(int i=0;i<Y.size();i++) {
            if(Y[i]>=m) high++;
        }
        fill(DP,DP+2000000,1<<25);
        for(int i=0;i<k;i++) {
            if(i<N) {
                if(X[i]==0) {
                    DP[i]=1;
                }else if(X[i]>=m) {
                    DP[i]=0;
                }
            }else {
                int a=DP[E[i][0]];
                int b=DP[E[i][1]];
                int c=DP[E[i][2]];
                DP[i]=a+b+c-max(a,max(b,c));
            }
        }
        if(DP[k-1]<=high) l=m; else r=m;
    }
    printf("%d\n",l);
}

Measured memory_bytes: 58056
#include <iostream>

using namespace std;

int main(){
    // int x = 10;
    // while (x*x*x*x*x - (x-1)*(x-1)*(x-1)*(x-1)*(x-1) < 1000000000){
    //     x++;
    // }
    // cout << x;
    int x;
    cin >> x;
    
    for (int a = 1; a < 120; a++){
        for (int b = -100; b < 120; b++){
            if (a*a*a*a*a - b*b*b*b*b == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3172
from math import gcd

N = int(input())
A = list(map(int, input().split()))
sieve = [1] * (10**6+1)
for i in range(2, 10**6 + 1):
	if sieve[i] == 1:
		sieve[i] = i
		j = 2
		while(j * i <= 10**6):
			sieve[j * i] = i
			j += 1

g = A[0]
for i in range(1, N):
	g = gcd(g, A[i])
	
if g != 1:
	print("not coprime")
else:
	s = set()
	for i in range(N):
		st = set()
		while(A[i] > 1):
			d = sieve[A[i]]
			st.add(d)
			A[i] //= d
		for p in st:
			if p in s:
				print("setwise coprime")
				exit()
			s.add(p)
	print("pairwise coprime")

Measured memory_bytes: 189220
#include <bits/stdc++.h>
#define F(i,n) for (int i=1; i<=(int)n; i++)
#define FF(i,n) for (int i=0; i<(int)n; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pi pair < int , int >
#define re(x) (int)x.size()
#define y1 u228
using namespace std;
typedef long long ll;
const int N = 2e5+228;
const int big = 2e9;
const int md = 1e9 + 7;
int n,a[N],ps,ans,k;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    //freopen("input.txt","r",stdin);
    cin>>n>>k; ans=1e9;
    F(i,n) cin>>a[i];
    F(i,n) if (a[i]==1) {ps=i; break;}
    F(i,n-k+1){
        if (ps<i || ps>i+k-1) continue;
        int tex=1+(i-1+k-2)/(k-1);
        tex+=(n-(i+k-1)+k-2)/(k-1);
        ans=min(ans,tex);
    }
    cout<<ans<<endl;
    return 0;
}







Measured memory_bytes: 640
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstring>
#include <set>
#include <map>
using namespace std;
#define ld long double
#define F first
#define S second
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define p1 1000000007
#define p 998244353
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int ll
const int N=1e5+10;
const int inf=1e17+10;
int dp[N][3];
int n;
int arr[N][3];
 
int k;
int rec(int i,int x)
{
    if(i>n) return 0;
    if(dp[i][x]!=-inf) return dp[i][x];
    if(x==0)
    return dp[i][x]=max(rec(i+1,1),rec(i+1,2))+arr[i][x];
    if(x==1)
     return dp[i][x]=max(rec(i+1,2),rec(i+1,0))+arr[i][x];
     else
     return dp[i][x]=max(rec(i+1,0),rec(i+1,1))+arr[i][x];
}
int32_t main()
{
   
    cin>>n;
    
     
    for(int i=1;i<=n;i++)
      for(int j=0;j<=2;j++){
        cin>>arr[i][j];
        dp[i][j]=-inf;
      }
    
    int  ans=max(rec(1,0),max(rec(1,1),rec(1,2)));
    cout<<ans;
}


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

public class Main 
{
	public static void main(String args[])throws IOException
	{
		BufferedReader BR=new BufferedReader (new InputStreamReader(System.in));
		
		int n=Integer.parseInt(BR.readLine());
		StringTokenizer st=new StringTokenizer(BR.readLine());
		
		int x=-1;
		int y=1;
		int c=0;
		for(int i=0;i<n;i++)
		{
			int a=Integer.parseInt(st.nextToken());
			if(a!=x)
			{
				x=a;
				if(y>1)
				{
					int p;
					if(y%2==0)
					{
						p=y/2;
						//System.out.println("Even");
					}
					else
					{
						p=(y-1)/2;
						//System.out.println("Odd");
					}
					//System.out.println(y+"-"+p);
					c=c+p;
				}
				y=1;
			}
			else
			{
				//System.out.println(a);
				y++;
			}
		}
		if(y>1)
		{
			int p;
			if(y%2==0)
			{
				p=y/2;
				//System.out.println("Even");
			}
			else
			{
				p=(y-1)/2;
				//System.out.println("Odd");
			}
			c+=p;
		}
		System.out.println(c);
		
	}
}


Measured memory_bytes: 22740
while True:
    try:
        N = float(input())
    except EOFError:
        break
    if N <= 48.0:
        print('light fly')
    elif N <= 51.0:
        print('fly')
    elif N <= 54.0:
        print('bantam')
    elif N <= 57.0:
        print('feather')
    elif N <= 60.0:
        print('light')
    elif N <= 64.0:
        print('light welter')
    elif N <= 69.0:
        print('welter')
    elif N <= 75.0:
        print('light middle')
    elif N <= 81.0:
        print('middle')
    elif N <= 91.0:
        print('light heavy')
    else:
        print('heavy')

Measured memory_bytes: 7364
N = int(input())
a = list(map(int,input().split()))
total=0

list.sort(a, reverse=True)

if N %2== 0:
	for i in range(int(N/2)):
		if i == 0:
			total += a[i]
		else:
			total += a[i]*2
else:
	for i in range(int((N-1)/2)):
		if i == 0:
			total += a[i]
		else:
			total += a[i]*2
	total += a[int((N-1)/2 )]
print(total)


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

int s=0;
int num=0;
int a[10000005]={};

int func(int x){
	if(x%2) x=3*x+1;
	else x/=2;
  	return x;
}

int main(){
	cin >>s;
  	a[0]=s;
  	bool flag=0;
  	while (!flag)
    {	
      	a[num+1]=func(a[num]);
        if(a[num]==4 || a[num]==2 || a[num]==1) 
        {
          num+=4;
          flag=1;
        }
      	else if(a[num+1]==4 || a[num+1]==2 || a[num+1]==1) 
        {  	
             num+=5;
         	 flag=1;
        }
       	else num++;     
    }
  
  	cout <<num <<endl;
  	

}

Measured memory_bytes: 256
#include<stdio.h>
using namespace std;
int main()
{
    char str[2000];
    int m,tmp,length;
    while(true)
    {
        scanf("%s",str);
        if(str[0]=='-') break;
        length =0;
        for(int k=0;str[k]!='\0';k++) length++;
        scanf("%d",&m);
        int index=0;
        for(int i=0;i<m;i++)
        {
            scanf("%d",&tmp);
            for(int j=0;j<tmp;j++)
            {
                str[index+length]=str[index];
            index++;
            }
        }
        for(int p=0;p<length;p++)
        {
            printf("%c",str[index+p]);
        }
        printf("\n");
    }


}



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

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

    vector<int> t(n);
    for (auto i = 0; i < n; i++) cin >> t[i];
    sort(t.begin(), t.end());

    int front = 0, count = 1, ans = 0;
    for (auto i = t[0]; i <= t[t.size() - 1] + k; i++) {
        while(front + count <= t.size() - 1 and t[front + count] == i) count++;
        while (front <= t.size() - 1 and t[front] + k == i) {
            ans++;
            front += min(c, count);
            count -= min(c, count);
        }
        // cout << i << " " << front << " " << count << " " << ans << endl;
    }

    cout << ans << endl;
    return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

char C[2];
char ans[5];
int main(){
	int n,m;cin>>n>>m;
	rep(i,m){
		int a;scanf("%d%s",&a,C);a--;
		char c=C[0];
		if(ans[a]&&ans[a]!=c){
			puts("-1");return 0;
		}
		ans[a]=c;
	}
	if(n!=1&&ans[0]=='0'){
		puts("-1");
		return 0;
	}
	rep(i,n){
		if(!ans[i]){
			if(n!=1&&i==0)ans[i]='1';
			else ans[i]='0';
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    x = int(input())

    tmp = x // 100
    for i in range(8):
        if tmp ==  4+2*i or tmp == 4+2*i+1:
            print(8-i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62736
a11,a12,a13=map(int,input().split())
a21,a22,a23=map(int,input().split())
a31,a32,a33=map(int,input().split())

n=int(input())

card=[a11,a12,a13,a21,a22,a23,a31,a32,a33]
def isBingo():
   if ( (card[0] == -1 and card[1] == -1 and card[2] == -1) \
      or (card[3] == -1 and card[4] == -1 and card[5] == -1) \
      or (card[6] == -1 and card[7] == -1 and card[8] == -1) \
      or (card[0] == -1 and card[3] == -1 and card[6] == -1) \
      or (card[1] == -1 and card[4] == -1 and card[7] == -1) \
      or (card[2] == -1 and card[5] == -1 and card[8] == -1) \
      or (card[0] == -1 and card[4] == -1 and card[8] == -1) \
      or (card[2] == -1 and card[4] == -1 and card[6] == -1) \
      ):
      return True
   else:
      return False
    
for i in range(n):
  i= int(input())
  if i in card:
    card[card.index(i)]=-1
if( isBingo()):
    print("Yes")
else:
    print("No")
    
       
       
       
       
       

Measured memory_bytes: 3188
#include<cstdio>
using namespace std;
int a,b;
int main(){
    scanf("%d%d",&a,&b);
    if(a>0)puts("Positive");               
    else if(b>=0)puts("Zero");             
    else if((a&1)^(b&1))puts("Positive");  
    else puts("Negative");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  bool even = true;
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
    if(vec.at(i) %2 != 0){
      even = false;
    }
  }
  if(even){
    cout << "second" << endl;
  }
  else{
    cout << "first" << endl;
  } 
} 

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Text;

class Program
{
    public void Proc()
    {
        int itemCount = int.Parse(Console.ReadLine());
        int[] numList = new int[itemCount];
        int sosuCount = 0;
        for(int i=0; i<itemCount; i++)
        {
            int num = int.Parse(Console.ReadLine());
            numList[i] = num;
            if(this.IsSosu(num))
            {
                sosuCount++;
            }
        }
        Console.WriteLine(sosuCount);
    }

    private bool IsSosu(int num)
    {
        if(num == 2)
        {
            return true;
        } else if(num < 2 || num % 2 == 0)
        {
            return false;
        }
        int max = (int)( Math.Sqrt(num)) + 1;
        for (int i = 2; i <= max; i++) {
            if(num % i == 0)
            {
                return false;
            }
        }
        return true;
    }

    static void Main(string[] args)

    {

        Program prg = new Program();
        prg.Proc();

    }
}

Measured memory_bytes: 9236
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var h     = int.Parse(spl[0]);
        var w     = int.Parse(spl[1]);
        var k     = int.Parse(spl[2]);

        var ss = new int[h][];
        for(int i=0; i<h; i++) {
            var s = input.ReadLine();
            ss[i] = new int[w];
            for (int j = 0; j < w; j++)
                ss[i][j] = s[j] - '0';
        }

        Func<HashSet<int>, HashSet<int>> VerticalCutt = (cutH) => {
            var cutV = new HashSet<int>();
            var counts = new int[cutH.Count()+1];
            
            for(int i=0; i<w; i++) {
                var idx = 0;
                for (int j = 0; j < h; j++) {
                    counts[idx] += ss[j][i];
                    if(counts[idx] > k) {
                        if (cutV.Contains(i)) {
                            return null;
                        }
                        cutV.Add(i);
                        counts = new int[counts.Length];
                        i--;
                        break;
                    }
                    if (cutH.Contains(j)) idx++;
                }
            }

            return cutV;
        };

        var min = int.MaxValue;

        foreach (var cutH in Next(h)) {
            //Debug.WriteLine(string.Join(",", cutH.ToArray()));

            var cutV = VerticalCutt(cutH);
            if (cutV == null) continue;

            min = Math.Min(min, cutV.Count() + cutH.Count());
        }

        return min;
    }

    public static IEnumerable<HashSet<int>> Next(int h) {
        var b = (int)Math.Pow(2, h - 1);

        for (int bb = 0; bb < b; bb++) {
            var r = new HashSet<int>();
            for (int i = 0; i < h; i++) {
                if ((bb >> i) % 2 == 1) {
                    r.Add(i);
                }
            }
            yield return r;
        }
    }
}

Measured memory_bytes: 13524
#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 N;

ll dp[105][4][4][4];

int main(){
  cin >> N;

  rep(i,0,4) rep(j,0,4) rep(k,0,4) {
    dp[3][i][j][k] = 1;
  }
  dp[3][0][2][1] = 0;
  dp[3][2][0][1] = 0;
  dp[3][0][1][2] = 0;

  rep(i,3,N){
    rep(j,0,4) rep(k,0,4) rep(l,0,4) {
      dp[i+1][k][l][0] = (dp[i+1][k][l][0]+dp[i][j][k][l])%MOD;
      
      if(!((j==0&&l==2) || (k==2&&l==0) || (j==0&&k==2) || (k==0&&l==2))){
        dp[i+1][k][l][1] = (dp[i+1][k][l][1]+dp[i][j][k][l])%MOD;
      }

      if(!(k==0&&l==1)){
        dp[i+1][k][l][2] = (dp[i+1][k][l][2]+dp[i][j][k][l])%MOD;
      }

      dp[i+1][k][l][3] = (dp[i+1][k][l][3]+dp[i][j][k][l])%MOD;

    }
  }


  ll ans = 0;
  rep(i,0,4) rep(j,0,4) rep(k,0,4) {
    ans += dp[N][i][j][k];
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}


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

#define rep(i, n) for(int i = 0, i_length = (n); i < i_length; i++)
#define MOD 1000000007

using ll = long long;

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

int main() {
	ll a, b;
	cin >> a >> b;

	ll x = GCD(a, b);
	ll xx = x;

	set<ll> prime;

	for (ll i = 2; i * i <= xx; i++) {
		while (x % i == 0) {
			prime.insert(i);
			x /= i;
		}
	}
	if(x!=1) prime.insert(x);

	cout << prime.size() + 1 << endl;

	return 0;
}

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

int main() {
  vector<int> v;
  int x;
  cin >> x;
  v.push_back(x);
  cin >> x;
  v.push_back(x);
  cin >> x;
  v.push_back(x);
  sort(v.begin(), v.end());
  cout<<v[0] +v[1];
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define mod ((int)1e9+7)
using namespace std;
typedef long long int ll;
typedef pair<int,int> pi;

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

void solve() {
  int n;
  cin>>n;
  string verdict;
  map<string,int> mp;
  while(n--) {
    cin>>verdict;
    mp[verdict]++;
  }
  cout<<"AC x "<<mp["AC"]<<"\n";
  cout<<"WA x "<<mp["WA"]<<"\n";
  cout<<"TLE x "<<mp["TLE"]<<"\n";
  cout<<"RE x "<<mp["RE"]<<"\n";
}

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

    int t=1;
    //cin>>t;
    for(int i=1;i<=t;i++) {
      //cout<<"Case #"<<i<<": ";
      solve();
      cout<<"\n";
    }
}


Measured memory_bytes: 3664
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int a,b;
	cin>>a>>b;
	int cnt=0;
	for(;a<=b;a++) {
		if(a%10==a/10000&&(a/1000)%10==(a/10)%10)cnt++;
	}
	cout<<cnt;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3604
using System;

namespace AtCoder20200322
{
    class Program
    {
        static void Main(string[] args)
        {
            TheNumberOfEvenPairs();
        }
        
        public static void TheNumberOfEvenPairs()
        {
            String[] inputs = Console.ReadLine().Split(' ');
            int n = int.Parse(inputs[0]);
            int m = int.Parse(inputs[1]);

            int sum = nCm(n, 2) + nCm(m, 2);
            Console.WriteLine(sum);
        }

        public static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define int long long
#define maxn 100005
#define pii pair<int,int>
using namespace std;
int N;
pii arr[maxn];
int sz[maxn];
vector<int> G[maxn];
int dfs(int u,int pa) {
	int ret = 0;
	for(int v:G[u])
		if(v!=pa)
			ret += sz[v]+dfs(v,u);
	return ret;
}
main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for(int i=1;i<=N;i++)
		cin >> arr[arr[i].second=i].first;
	sort(arr+1,arr+1+N);
	for(int i=1;i<=N;i++)
		sz[i] = 1;
	for(int i=N;i>1;i--) {
		int val = arr[i].first;
		int idx = arr[i].second;
		int pa_val = val-(N-sz[idx])+(sz[idx]);
		int tem = lower_bound(arr+1,arr+1+N,pii{pa_val,-1})-arr;
		if(tem>=i || arr[tem].first!=pa_val) {
			cout << -1 << endl;
			return 0;
		}
		int pa = arr[tem].second;
		sz[pa] += sz[idx];
		G[pa].emplace_back(idx);
	}
	if(dfs(arr[1].second,arr[1].second)==arr[1].first) {
		for(int u=1;u<=N;u++)
			for(int v : G[u])
				cout << u << " " << v << endl;
	}
	else
		cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 12288
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		
		int N = stdIn.nextInt();
		
		if(N / 10 == 9 || N % 10 == 9)
		{
			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 35744
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	int N, K;

	cin >> N >> K;

	if(N > (K-1)*2){
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(int i=start;i<end;i++)
#define N 100001
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl;
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<endl;
#define pi M_PI

const int INF = 1e9 + 5;
int main()
{
	fastio();
	int n;cin>>n;
	int h[n];
	loop(i,0,n)
	{
		cin>>h[i];
	}
	vector<int> dp(n, INF);
	dp[0] = 0;
	loop(i,0,n)
	{
		loop(j,i+1,i+3)
		{
			if(j<n)
				dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n-1]<<endl;

	return 0;
}	

Measured memory_bytes: 1024
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}


fn main() {
    let line = read_line();
    let s: Vec<char> = line.trim().chars().collect();
    let n = s.len();
    let mut ans = None;
    for i in 0..26 {
        let tar = ('a' as u8 + i) as char;
        let mut count = -1;
        let mut pos = 0;
        let mut l = 0;
        while pos < n {
            if s[pos] == tar {
                if count < 0 {
                    l = pos;
                    count = 0;
                }
                count += 1;
                if pos-l >= 1 && count > 0 {
                    ans = Some((l+1, pos + 1));
                    break;
                }
            } else {
                count -= 1;
            }
            pos += 1;
        }
    }
    if let Some((l, r)) = ans {
        println!("{} {}", l, r);
    } else {
        println!("-1 -1");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;


int main()
{
    int N, M;
    cin >> N >> M;
    priority_queue<int> q;
    vint tmp[100000 + 1];
    int a, b;
    while(N--)
    {
        cin >> a >> b;
        tmp[a].push_back(b);
    }

    int ans = 0;
    for (int i = 1; i <= M;i++)
    {
        for(int j:tmp[i])
        {
            q.push(j);
        }
    
    if (!q.empty())
    {
        ans += q.top();
        q.pop();
    }
    }
    cout << ans;
    return 0;
}

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

int main(){
    int t,c=0;
    cin>>t;
    int a1[t],a2[t];
    for(int i=0;i<t;i++) cin>>a1[i];
    //sort(a1,a1+t);
    for(int i=0, j=1;i<=t;i++,j++) a2[i]=j;
    //sort(a2,a2+t);
    for(int i=0;i<t;i++){
        if(a1[i]!=a2[i]) c++;
    }
     (c==2||c==0)? cout<<"YES"<<endl :cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
 
int A[100000], n;
 
int Partition(int p, int r){
    int x = A[r - 1], j = 0;
    for(int i = 0;i < n;i++){
        if(A[i] <= x) {
            int tmp = A[j];
            A[j++] = A[i];
            A[i] = tmp;
        }
    }
    return j - 1;
}
 
main(){
    scanf("%d", &n);
    for(int i = 0;i < n;i++)scanf("%d", &A[i]);
    int j = Partition(0, n);
    for(int i = 0;i < n - 1;i++){
        if(i)printf(" ");
        if(i == j)printf("[");
        printf("%d", A[i]);
        if(i == j)printf("]");
    }
    printf(" %d\n", A[n - 1]);
}

Measured memory_bytes: 3524
#include<stdio.h>
#define N 100002
typedef struct {
  char n[100];
  int ti;
} a;
a c[N];
int h,z,n;
a de(){
  a i = c[h];
  h = (h+1)%N;
  return i;
}
void en(a x){
  c[z] =x;
  z = (z+1)%N;
}

int kei(int x,int y){
  if(x<y)return x;
  else return y;
}
int main(){
  int k=0,m;
 int t,i;
   a de2;
   scanf("%d %d",&n,&t);
   for(i=1;i<=n;i++){
     scanf("%s",c[i].n);
     scanf("%d",&c[i].ti);
   }
   h=1;z=n+1;
   while(h != z){
     de2 = de();
     m=kei(t,de2.ti);
     de2.ti-=m;
     k+=m;
     if(de2.ti>0) en(de2);
     else{
       printf("%s %d\n",de2.n,k);
     }
   }   
return 0;
}



Measured memory_bytes: 11884
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
ll gcd(ll x, ll y) {
	if (x < y)swap(x, y);
	if (y == 0)return abs(x - y);
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;
ll mypow(ll x, ll n, ll m) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return mypow(x*x%m, n / 2, m);
	}
	else {
		return x * mypow(x, n - 1, m) % m;
	}
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
///////////////////////////////////////

int main() {
	ll N, K; cin >> N >> K;
	if (N <= K) {
		cout << min(N, K - N) << endl;
	}
	else {
		cout << min(N%K, K - (N%K)) << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;

ll n, sum;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (ll i = 1; i <= n; i ++)
        for (ll j = 1; j <= n; j ++)
            for (ll t = 1; t <= n; t ++)
                sum += __gcd(i, __gcd(j, t));
    cout << sum;
    return 0;
}


Measured memory_bytes: 3612
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}

int a[26];
int b[26];
int main(){
    string s;
    cin >> s;
    int n = s.size();
    for(int i=0;i<n;i++){
        a[s[i]-'a']++;
    }
    if(n!=26){
        cout << s;
        rep(i,26){
            if(a[i]==0){
                cout << (char)('a'+i) << endl;
                return 0;
            }
        }
    }else{
        if(s=="zyxwvutsrqponmlkjihgfedcba"){
            cout << -1 << endl;
            return 0;
        }
        int k = 0;
        for(int i=n-1;i>=0;i--){
            if(s[i]>s[i-1]){
                k = i;
                break;
            }
        }
        for(int i=0;i<k-1;i++){
            cout << s[i];
            b[s[i]-'a']++;
        }
        int x = s[k-1]-'a';
        for(int i=0;i<26;i++){
            if(i > x && b[i]==0){
                cout << (char)('a'+i) << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 100000

typedef struct
{
  int parent;
  int left;
  int right;
} node;

int finddepth(int);
int findheight(int);

node T[N];

int main()
{
  int pa, x, y, i, j, n, k, c;

  scanf("%d", &n);
  for(i=0; i<n; i++)
    {
      T[i].parent = -1;
      T[i].left = -1;
      T[i].right = -1;
    }
  

  for(i=0; i<n; i++)
    {
      scanf("%d", &pa);

	  scanf("%d%d", &x, &y);
	  T[x].parent = pa;
	  T[y].parent = pa;
	  T[pa].left = x;
	  T[pa].right = y;
	
    }
  for(i=0; i<n; i++)
    {
      c=0;
      printf("node %d: parent = %d, ", i, T[i].parent);
      if(T[i].parent == -1)
	{
	  printf("sibling = -1, ");
	}
      else if(T[T[i].parent].left == i)
	{
	  printf("sibling = %d, ", T[T[i].parent].right);
	}
      else
	{
	  printf("sibling = %d, ", T[T[i].parent].left);
	}

      if(T[i].left != -1) c++;
      if(T[i].right != -1) c++;

      printf("degree = %d, depth = %d, height = %d, ", c, finddepth(i), findheight(i));
      
      if(T[i].parent == -1)
	{
	  printf("root\n");
	}
      else if(T[i].left != -1 || T[i].right != -1)
	{
	  printf("internal node\n");
	}
      else
	{
	  printf("leaf\n");
	}
    }
      
  return 0;
}

int finddepth(int x)
{
  int c=0;
  while(T[x].parent >= 0)
    {
      c++;
      x = T[x].parent;
    }
  return c;
}
int findheight(int x)
{
  int l=0, r=0;

  if(T[x].left != -1)
    {
      l = findheight(T[x].left)+1;
    }
  if(T[x].right != -1)
    {
      r = findheight(T[x].right)+1;
    }
  if(l > r)
    {
      return l;
    }
  else
    {
      return r;
    }
}

Measured memory_bytes: 612
n = int(input())
d, x = map(int, input().split())
a = [int(input()) for _ in range(n)]
total = 0
for i in range(len(a)):
  eat = 0
  count = 0
  while eat <= d:
    count += 1
    eat = a[i] * count + 1
  total += count
print(total + x)

Measured memory_bytes: 9168
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    string S;
    cin >> S;
    set<char> s;
    for (const char c : S)
    {
        s.insert(c);
    }
    cout << (s.size() == 2 ? "Yes" : "No") << endl;
}


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

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

  int a = 0, z = 0;
  bool flag_a = false;
  rep(i, str_input.size()) {
    if (flag_a == false && str_input[i] == 'A') {
      flag_a = true;
      a = i;
    }
    if (flag_a == true && str_input[i] == 'Z') {
      z = i;
    }
  }

  cout << z - a + 1 << endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

int main() {
    int n,c[3] = {0,0,0};
    cin >> n;
    for(int i = 0;i < n;i++) {
        int a;
        cin >> a;
        if(a % 4 == 0) c[2]++;
        else if(a % 2 == 0) c[1]++;
        else c[0]++;
    }
    if(c[1] != 0) c[0]++;
    if(c[0] - c[2] <= 1) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256