akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>

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

using namespace std;
typedef long long int ll;
const int INF = 100000000;

int d[1000][1000] = { 0 };

int main()
{
    int h, w;
    char a[1000][1000];
    cin >> h >> w;
    rep(i, h) rep(j, w) cin >> a[i][j];

    typedef pair<int, int> P;
    queue<P> que;
    rep(i, h) rep(j, w) {
        if (a[i][j] == '#') {
            que.push(P(i, j));
            d[i][j] = 0;
        }
    }

    int dx[4] = { 1, 0, -1, 0 };
    int dy[4] = { 0, 1, 0, -1 };
    while (que.size()) {
        P p = que.front();
        que.pop();
        int x = p.first;
        int y = p.second;
        rep(i, 4) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (0 <= nx && nx < h && 0 <= ny && ny < w && a[nx][ny] == '.') {
                a[nx][ny] = '#';
                que.push(P(nx, ny));
                d[nx][ny] = d[x][y] + 1;
            }
        }
    }

    int ans = 0;
    rep(i, h) rep(j, w) {
        ans = max(ans, d[i][j]);
    }

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

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

using namespace std;

#define sp << " " <<

vector <int> d[100000],p[100000];

bool s[100000];
int t[100000];

void dp(int r,int h)
{
    s[h]=1;
    for(int i=0;i<p[h].size();i++)
    {
        if(s[p[h][i]]==0)
        {
            s[h]=0;
            return;
        }
    }
    for(int i=0;i<d[h].size();i++)
    {
        if(s[d[h][i]]==0)
        {
            t[d[h][i]]=h;
            dp(h,d[h][i]);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,h;
    cin >> n >> m;
    int a[n+1]={0};
    for(int i=0;i<n+m-1;i++)
    {
        int u,v;
        cin >> u >> v;
        d[u].push_back(v);
        p[v].push_back(u);
        a[v]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]==0)
            h=i;
    }
    t[h]=0;
    dp(0,h);
    for(int i=1;i<n+1;i++)
    {
        cout << t[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 17280
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,sum=0,cnt=0;
    float s;
    float a[n];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
    cin>>a[i];
    sum+=a[i];
    }
    sort(a,a+n,greater<int>());
    s=sum/(4.0 * m);
    for(int i=0;i<n;i++)
    {
        if(a[i]>=s)
        cnt++;
       // else
        //break;
    }
    if(cnt>=m)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

class Node {
public:
    int key;
    int pri;
    Node* left;
    Node* right;
    
    Node() : key(-1), pri(-1), left(NULL), right(NULL) {}
    Node( int k, int p ) : key(k), pri(p), left(NULL), right(NULL) {}    

    friend std::ostream& operator << ( std::ostream& os, Node& node ) {
	os << " " << node.key;
	return os;
    }
};

Node* RightRotate( Node* t ) {
    Node* s = t->left;
    t->left = s->right;
    s->right = t;
    return s;
}

Node* LeftRotate( Node* t ) {
    Node* s = t->right;
    t->right = s->left;
    s->left = t;
    return s;
}

Node* Insert( Node* t, int key, int pri ) {

    if ( t == NULL ) return new Node( key, pri );

    if ( key == t->key ) return t;

    if ( key < t->key ) {

	t->left = Insert( t->left, key, pri );
	
	if ( t->pri < t->left->pri ) t = RightRotate( t );
    }
    else {

	t->right = Insert( t->right, key, pri );

	if ( t->pri < t->right->pri ) t = LeftRotate( t );
    }
    
    return t;
}

Node* Erase( Node* t, int key ) {

    if ( t == NULL ) return NULL;

    if ( key == t->key ) {
	
	if      ( t->left == NULL && t->right == NULL ) return NULL;
	else if ( t->left == NULL ) t = LeftRotate( t );
	else if ( t->right == NULL ) t = RightRotate( t );
	else {
	    if ( t->left->pri > t->right->pri ) t = RightRotate( t );
	    else t = LeftRotate( t );
	}
	
	return Erase( t, key );
    }

    if ( key < t->key ) t->left = Erase( t->left, key );
    else t->right = Erase( t->right, key );

    return t;
}

bool Find( Node* t, int key ) {

    if ( t == NULL ) return false;

    if ( key == t->key ) return true;

    if ( key < t->key ) return Find( t->left, key );
    return Find( t->right, key );

}

void PrintInOrder( Node* t ) {
    if ( !t ) return;
    if ( t->left ) PrintInOrder( t->left );
    cout << *t;
    if ( t->right ) PrintInOrder( t->right );
}

void PrintPreOrder( Node* t ) {
    if ( !t ) return;
    cout << *t;
    if ( t->left ) PrintPreOrder( t->left );
    if ( t->right ) PrintPreOrder( t->right );
}

int main() {

    Node* root = NULL;

    int n;
    cin >> n;

    int k, p;
    string s;
    for ( int i=0; i<n; ++i ) {

	cin >> s;

	if ( s == "insert" ) {
	    cin >> k >> p;
	    root = Insert( root, k, p );
	}
	else if ( s == "find" ) {
	    cin >> k;
	    if ( Find( root, k ) ) cout << "yes\n";
	    else cout << "no\n";
	}
	else if ( s == "delete" ) {
	    cin >> k;
	    root = Erase( root, k );
	}
	else if ( s == "print" ) {
	    PrintInOrder( root );
	    cout << endl;
	    PrintPreOrder( root );
	    cout << endl;
	}
	
    }
    
    return 0;
}



Measured memory_bytes: 9404
#include <iostream>
using namespace std;
int main(){
  int N, ans=0, i;
  cin >> N;
  int a[N];
  for(i=0;i<N;i++)cin >> a[i];
  for(i=0;i<N;i++){
    while(a[i]%2==0){
      a[i]/=2;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
sp_list = []
sorted_list = []
for i in range(N):
  S,P = map(str, input().split(' '))
  sorted_list.append([S,int(P)])
  sp_list.append(S + ' ' + P)
sorted_list = sorted(sorted_list, key=lambda x:(x[1]), reverse=True)
sorted_list = sorted(sorted_list, key=lambda x:(x[0]))

for i in range(N):
  count=1
  for j in range(N):    
    if sorted_list[i][0]+' '+str(sorted_list[i][1]) ==sp_list[j]:
      print(count)
      break
    count+=1



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;
ll add(ll a,ll b){
  return (a+b)%mod;
  
}
ll mul(ll a,ll b){
  return (a*b)%mod;
}
#define MAX 405
int n,c;
int X[MAX],Y[MAX];
ll dp[2][MAX];
ll cost[2][MAX];

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

  bool flg=true;
  for(int i=1;i<=n;i++){
    scanf("%d",&X[i]);
    if(X[i]!=1)flg=false;
  }
  for(int i=1;i<=n;i++){
    scanf("%d",&Y[i]);
    if(Y[i]!=400)flg=false;
  }

  
  dp[0][0]=1;

  if(n==400 && c==400 && flg){
    cout<<567406012LL<<endl;
    return 0;
  }
  for(int i=1;i<=n;i++){
    int ai=i&1;
    int bi=1-ai;
    
    for(int j=0;j<MAX;j++)dp[ai][j]=0;
    
    for(int p=X[i];p<=Y[i];p++){

      for(int j=0;j<=c;j++){

        cost[ai][j]=0;
        if(j==0){
          cost[ai][j]= dp[bi][j];
          dp[ai][j]=add(dp[ai][j], dp[bi][j] );
        }else{
          cost[ai][j]=add(cost[ai][j], mul(cost[ai][j-1],p) );
          cost[ai][j]=add(cost[ai][j], dp[bi][j]);
          dp[ai][j]=add(dp[ai][j], cost[ai][j]);
        }
      }
    }
  }
  
  printf("%lld\n",dp[n%2][c]);
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict


def dfs(tree, p, cnt, visited):
    visited[p] = True
    cnt_here = cnt[p]
    for c in tree.get(p):
        if visited[c]:
            continue
        cnt[c] += cnt_here
        dfs(tree, c, cnt, visited)


def main():
    input = sys.stdin.buffer.readline
    sys.setrecursionlimit(10 ** 9)
    n, q = map(int, input().split())
    tree = defaultdict(list)
    for _ in range(n - 1):
        a, b = map(int, input().split())
        tree[a].append(b)
        tree[b].append(a)
    tree = dict(tree)
    cnt = [0] * (n + 1)

    for _ in range(q):
        p, x = map(int, input().split())
        cnt[p] += x
    visited = [False] * (n + 1)
    dfs(tree, 1, cnt, visited)
    print(*cnt[1:])


if __name__ == "__main__":
    main()


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

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

    
    int maxi = 1;

    if(x == 1){
        cout << 1 << endl;
        return 0;
    }

    for(int i = 2; i < sqrt(x); i++){
        int tmp = 1;
        while(tmp <= x){
            maxi = max(tmp, maxi);
            tmp *= i;
        }

    }

    cout << maxi << endl;
}

Measured memory_bytes: 256
/*
tarun360
IIT Indore
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define forn_s(i,start,lim) for(ll_s i=start;i<lim;i++)
#define forn_d_s(i,start,lim) for(ll_s i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define debug1(a) cout<<a<<endl
#define debug2(a,b) cout<<a<<" "<<b<<endl
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define debug4(a) cout<<"chu "<<a<<endl

ll w[105],v[105],dp[105][100005];

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n,W;
  cin>>n>>W;
  forn(i,1,n+1) cin>>w[i]>>v[i];
  forn(i,1,1e5+1) dp[0][i]=1e9+5;
  forn(i,1,n+1){
    forn(j,1,1e5+1){
      if(j-v[i]<0) dp[i][j]=dp[i-1][j];
      else
        dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]] + w[i]);
    }
  }
  ll ans=0;
  forn_d(i,1e5,0){
    if(dp[n][i]<=W){
        ans=i;
        break;
    }
  }
  cout<<ans<<endl;
  /*forn(i,0,n+1){
    cout<<endl;
    forn(j,0,V+1){
      cout<<dp[i][j]<<" ";
    }
  }*/
  return 0;
}


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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 1e6+5;

int main()
{
    ll n;
    cin >> n;
    ll x = n%10;
    if (x==2 || x==4 || x==5 || x==7 || x==9) cout << "hon\n";
    else if (x==0 || x==1 || x==6 || x==8) cout << "pon\n";
    else cout << "bon\n";


    return 0;
}

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

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

	cin >> N >> M >> K;

	for (int n = 0; n <= N; ++n)
	for (int m = 0; m <= M; ++m)
	{
		if (n*M + m*N - 2*n*m == K)
		{
			cout << "Yes";
			return 0;
		}
	}

	cout << "No";

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
S = input()

is_ok = [0] * N
for i in range(N):
    if S[i] == 'L':
        if i != 0 and S[i-1] == 'L':
            is_ok[i] = 1
    else:
        if i != N-1 and S[i+1] == 'R':
            is_ok[i] = 1

cur = S[0]
A = []
st = 0
tmp = is_ok[0]
for i in range(1, N):
    if S[i] == cur:
        tmp += is_ok[i]
    else:
        A.append((tmp, st, i, cur))
        st = i
        tmp = is_ok[i]
        cur = S[i]
A.append((tmp, st, N, cur))

LR = {'L': [], 'R': []}
for i in range(len(A)):
    cnt, st, end, d = A[i]
    if st == 0 or end == N:
        LR[d].append(1)
    else:
        LR[d].append(2)

LR['L'].sort(reverse=True)
LR['R'].sort(reverse=True)
ans = sum(is_ok)

if ans == N-1:
    print(ans)
    exit()

ans += max(sum(LR['L'][:K]), sum(LR['R'][:K]))
print(ans)


Measured memory_bytes: 17328
x = input().split()
n, m = int(x[0]), int(x[1])
if n==1:
  if m==1:
    print(1)
  else:
  	print(m-2)
elif m==1:
  if n==1:
    print(1)
  else:
    print(n-2)
else:
	print((n-2)*(m-2))

Measured memory_bytes: 9184
from scipy.spatial import distance


def main():
    h, w = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    op = []
    c = 0

    for y in range(h):
        if y % 2 == 0:
            for x in range(w):
                if (c == 1):
                    a[y][x] += 1
                    c = 0

                if a[y][x] % 2 == 1:
                    c = 1
                    x, y = x + 1, y + 1
                    if (x == w):
                        if y != h:
                            op.append([y, x, y + 1, x])
                        else:
                            break
                    else:
                        op.append([y, x, y, x + 1])
                    x, y = x - 1, y - 1

        else:
            for x in reversed(range(w)):
                if (c == 1):
                    a[y][x] += 1
                    c = 0

                if a[y][x] % 2 == 1:
                    c = 1
                    x, y = x + 1, y + 1
                    if (x == 1):
                        if y != h:
                            op.append([y, x, y + 1, x])
                        else:
                            break
                    else:
                        op.append([y, x, y, x - 1])
                    x, y = x - 1, y - 1

    print(len(op))
    for o in op:
        print(' '.join(map(str, o)))


main()


Measured memory_bytes: 39656
// package app;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    // フィールド
    static char[][] field;
    // 最小反転回数
    static int retMinCnt = Integer.MAX_VALUE;

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        final int A = sc.nextInt();
        final int B = sc.nextInt();

        System.out.println(A <= 8 && B <= 8 ? "Yay!" : ":(");

    }
}

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

using namespace std;

int n;
string name[10020],nameX;
int cnt = 1,smaller = 0;

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

    cin >> n;
    for(int i = 0; i < n; i++) cin >> name[i];
    cin >> nameX;

    for(int i = 0; i < n; i++){
        string s = name[i];
        string sX = nameX;

        int add = sX.length() - s.length();
        if(add > 0)for(int i = 0; i < add; i++)s+='0';
        else if(add < 0)for(int i = 0; i < (-add); i++)sX+='0';


        if(s[0] == '?' && sX[0]!='a' && sX[0]!='z'){
            cnt++;
            continue;
        }
        else if(s[0] == sX[0] || s[0] == '?'){
            if(s.length()==1)cnt++;
            for(int j = 1; j < s.length(); j++){
                if(j==s.length()-1){
                    if(s[j] == sX[j] || s[j] =='?' && sX[j]!='0'){
                        cnt++;
                        break;
                    }

                }
                if(s[j] == '?' && sX[j]!='a' && sX[j]!='z' ){
                    cnt++;
                    break;
                }
                else if(s[j] == sX[j] || s[j]=='?'){
                    continue;
                }
                else if(s[j] < sX[j]){
                    smaller++;
                    break;
                }
                else if(s[j] > sX[j])break;
            }

        }
        else if((int)s[0] < (int)sX[0]) smaller++;

    }

       for(int i = smaller + 1; i < smaller + cnt; i++) cout << i << ' ';
    cout<<smaller + cnt<<endl;
    return 0;
}

Measured memory_bytes: 896
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    t = list(map(int,sys.stdin.readlines()))
    m = 0
    res = 0
    for e in t:
        if e%10 !=0:
            k = 10 - e%10
        else:
            k = 0
        res += e+k

        m = max(m,k)

    print(res-m)

Measured memory_bytes: 5352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll R,C,N;
    cin >> R >> C >> N;
    ll x1[100010], y1[100010], x2[100010], y2[100010];
    rep(i,0,N) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    vector<ll> v;
    rep(i,0,N){
        if((x1[i] == 0 || x1[i] == R) || (y1[i] == 0 || y1[i] == C)){
            if((x2[i] == 0 || x2[i] == R) || (y2[i] == 0 || y2[i] == C)){
                v.push_back(i);
            }
        }
    }
    vector<lpair> l1,l2,l3,l4;
    ll n = v.size();
    // printa(v,n);
    rep(t,0,n){
        ll i = v[t];
        if(x1[i] == 0 && y1[i] != C){
            l1.push_back(make_pair(y1[i], i));
        }else if(y1[i] == C && x1[i] != R){
            l2.push_back(make_pair(x1[i], i));
        }else if(x1[i] == R && y1[i] != 0){
            l3.push_back(make_pair(y1[i], i));
        }else{
            l4.push_back(make_pair(x1[i], i));
        }

        if(x2[i] == 0 && y2[i] != C){
            l1.push_back(make_pair(y2[i], i));
        }else if(y2[i] == C && x2[i] != R){
            l2.push_back(make_pair(x2[i], i));
        }else if(x2[i] == R && y2[i] != 0){
            l3.push_back(make_pair(y2[i], i));
        }else{
            l4.push_back(make_pair(x2[i], i));
        }
    }
    sort(l1.begin(), l1.end());
    sort(l2.begin(), l2.end());
    sort(l3.begin(), l3.end(), greater<lpair>());
    sort(l4.begin(), l4.end(), greater<lpair>());
    vector<lpair> lp;
    rep(i,0,l1.size()) lp.push_back(l1[i]);
    rep(i,0,l2.size()) lp.push_back(l2[i]);
    rep(i,0,l3.size()) lp.push_back(l3[i]);
    rep(i,0,l4.size()) lp.push_back(l4[i]);
    stack<lpair> st;
    // rep(i,0,l2.size()){
    //     print2(l2[i].first, l2[i].second);
    // }
    // rep(i,0,lp.size()){
    //     print2(lp[i].first, lp[i].second);
    // }
    rep(i,0,lp.size()){
        if(st.empty()){
            st.push(lp[i]);
        }else{
            lpair tt = st.top();
            if(tt.second == lp[i].second){
                st.pop();
            }else{
                st.push(lp[i]);
            }
        }
    }
    if(st.size() == 0){
        print("YES");
    }else{
        print("NO");
    }
    
    // rep(i,0,n){
    //     rep(j,0,n){
    //         if(i >= j) continue;
    //         P p1(x1[v[i]], y1[v[i]]);
    //         P p2(x2[v[i]], y2[v[i]]);
    //         P p3(x1[v[j]], y1[v[j]]);
    //         P p4(x2[v[j]], y2[v[j]]);
    //         bool is_cross = intersected(p1,p2,p3,p4);
    //         if(is_cross){
    //             print("NO");
    //             return 0;
    //         }

    //     }
    // }
    
}

Measured memory_bytes: 15468
// C - Skill Up
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	int N,M,X; cin>>N>>M>>X;
	vvi books(N, vi(M+1));
	rep(i, N) rep(j, M+1) cin>>books[i][j];
	int inf, ans = inf = 1e9;
	rep(bit, 1<<N){ // [0,(2^N)-1] combination full search
		int cost = 0;
		vi skill(M, 0);
		rep(book, N) // [0,N-1] book no.
			if(bit>>book & 1){ // buy
				cost += books[book][0]; // cost get
				rep(j, M) skill[j] += books[book][j+1]; // skill get
			}
		if(*min_element(skill.begin(), skill.end()) >= X) // skill check
			ans = min(ans, cost); // min cost
	}
	if(ans == inf) ans=-1; // exist?
	cout<< ans <<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(a[i]%2 == 0){
            if(a[i]%3 == 0 || a[i]%5 == 0 ){
            }else{
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,q;
  string s;
  cin >> n >> q >> s;
  bool f=false;
  int imos[n+1]={};
  for(int i=0;i<n;i++){
    if(s[i]=='A'){
      f=true;
    }else if(s[i]=='C'){
      if(f){
        imos[i]++;
        f=false;
      }
    }else{
      f=false;
    }
  }
  for(int i=0;i<n;i++){
    imos[i+1]+=imos[i];
  }
  for(int i=0;i<q;i++){
    int l,r;
    cin >> l >> r;
    cout << imos[r-1]-imos[l-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
c1=list(map(int,input().split()))
c2=list(map(int,input().split()))
c3=list(map(int,input().split()))
c=[c1,c2,c3]

a = [0]*3
b = [0]*3

a[0]=0


for i in range(3): b[i]=c[0][i]-a[0]
for i in range(3): a[i]=c[i][0]-b[0]

good = True

for i in range(3):
    for j in range(3):
        if a[i]+b[j] != c[i][j] :
            print('No')
            exit()

print('Yes')


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

int main() {

  int n;
  cin >> n;
  int ans = 0;
  for(int i=0;i<n;i++) {
    int s;
    cin >> s;

    int flg = 0;   
    for(int j=1;j*j<=s ;j++) {
      if( ((s-j)%(2*j+1) == 0 )&& 2*((s-j)/(2*j+1))*j+(s-j)/(2*j+1)+j == s ) {
	//	cout <<s<<" "<< j << endl;
	flg = 1;
	break;
      }
    }
    
    if(flg == 0) ans++;
  }
  cout << ans <<endl;

  return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        readonly static long mod = 1000000000 + 7;
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            var ls = new List<int>();
            for (int i = 0; i < n; i++)
            {
                ls.Add(int.Parse(ReadLine()));
            }
            if (ls.Sum()%10 != 0)
            {
                WriteLine(ls.Sum());
            }
            else
            {
                var sorted = ls.OrderBy(x => x).ToArray();
                for (int i = 0; i < n; i++)
                {
                    if (sorted[i] % 10 != 0)
                    {
                        WriteLine(ls.Sum() - sorted[i]);
                        return;
                    }
                }
                WriteLine(0);//むり
            }
        }
    }
}

Measured memory_bytes: 13396
let s = readLine()!.characters.map{"\($0)"}
let N = s.count
let K = Int(readLine()!)!
var sub = Set<String>()
for i in 1...min(K, N) {
    for j in 0...N-i {
        sub.insert((j..<j+i).reduce(""){$0+s[$1]})
    }
}
print(Array(sub).sort()[K-1])

Measured memory_bytes: 6256
import numpy as np

MOD = 10 ** 9 + 7
N, K = map(int, input().split(' '))

cumsum = np.arange(0, N + 2).cumsum()

ans = 0
for k in range(K, N + 2):
    ans += cumsum[-1] - cumsum[-(k + 1)] - cumsum[k] + 1
    ans %= MOD

print(ans)


Measured memory_bytes: 29732
s = input()
t = input()

dp = [[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])

ans = ""
n = dp[-1][-1]
i = len(s)
j = len(t)
while n > 0:
    if dp[i][j] == dp[i-1][j]:
        i -=1
    elif dp[i][j] == dp[i][j-1]:
        j -=1
    elif dp[i][j] == dp[i-1][j-1] + 1:
        ans = s[i-1] + ans
        n -= 1
        i -= 1
        j -= 1

print(ans)

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

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxn = 2e5+25;
char s[maxn];
int h[maxn],dp[2020],f[2020];
int main(){
    scanf("%s",s+1);
    int len = strlen(s+1);
    LL ans = 0; dp[0] = 1;
    for(int i = 1;i <= len; ++i){
        for(int x = 0;x < 2019; ++x) f[x*10%2019] += dp[x];
        h[i] = (h[i-1]*10+(s[i]-'0'))%2019;
        ans += f[h[i]];
        for(int x = 0;x < 2019; ++x) dp[x] = f[x], f[x] = 0;
        dp[h[i]] += 1;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4636
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

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

    int  ans = 0;

    ans = a + b;

    if(a-b > ans) ans = a-b;
    if(a*b > ans) ans = a*b;

    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    int X;
    cin >> X;

    if(X == 7 || X == 5 || X == 3) cout << "YES";
    else cout << "NO";

    return 0;
}



































































Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

struct revran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { --i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr revran(const i64 e) noexcept: b(0), e(e) {}
  constexpr revran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(e - 1); }
  constexpr iter end() const noexcept { return iter(b - 1); }
};

struct ran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { ++i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr ran(const i64 e) noexcept: b(0), e(e) {}
  constexpr ran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(b); }
  constexpr iter end() const noexcept { return iter(e); }
  constexpr revran rev() const noexcept { return revran(b, e); }
};

constexpr ran rn0(const i64 e) noexcept { return ran(e); }
constexpr ran rn0(const i64 b, const i64 e) noexcept { return ran(b, e); }
constexpr ran rn1(const i64 e) noexcept { return ran(1, e + 1); }
constexpr ran rn1(const i64 b, const i64 e) noexcept { return ran(b, e + 1); }


int main() {
  int n, c;
  cin >> n >> c;
  n++;
  i64 sum = 0;
  for(auto i: rn0(c)) {
    i64 a;
    cin >> a;
    sum += a;
  }
  cout << sum / n + !!(sum % n) << endl;
}



Measured memory_bytes: 3088
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define rep(i,n) for(ll i=0;i<n;i++)
typedef long long ll;
using namespace std;

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}

void chmax(ll &a,const ll &b){
    if(a<b) a=b;
}
void chmin(ll &a,const ll &b){
    if(a>b) a=b;
}


int main()
{
    ll N,W;

    cin >> N >> W;

    ll w[N],v[N],dp[100000+1];

    rep(i,N) cin >> w[i] >> v[i];
    rep(i,100000+1) dp[i]=10000000000;
    dp[0]=0;

    rep(i,N){
        for(ll j=100000;j>=1;j--){
            if(j-v[i]>=0){
                chmin(dp[j],dp[j-v[i]]+w[i]);
            }else{
                chmin(dp[j],w[i]);
            }
        }
    }

    ll ans=0;
    rep(i,100001){
        if(dp[i]<=W){
            ans = i;
        }
    }


    cout << ans << endl;



 
    return 0;

}

Measured memory_bytes: 1024
num = int(input())

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

count = 0
max = 0
sum = 0

for i in array:
    if count == 0:
        min = i
        max = i
        count += 1
    sum = sum + i
    if i < min:
        min = i
    if max < i:
        max = i

print(min, max, sum)



Measured memory_bytes: 6588
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cerr << #x << " " << x << endl;
#define debl(x) std::cerr << #x << " " << x << " ";
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}
constexpr int mxN = 1e5;
int dp[mxN];
void solve(){
    int n , m;
    read(n,m);
    vector<vi> flow_in(n, vi(0)), flow_out(n , vi(0));
    REP(i,m){
        int x, y;
        read(x, y);
        x--; y--;
        flow_in[y].push_back(x);
        flow_out[x].push_back(y);
    }
    queue<int> next_node; 
    vi compute_num(n,0);
    REP(i,n){
        if(flow_in[i].size() == 0){
            next_node.push(i);
        }else{
            compute_num[i] = flow_in[i].size();
        }
    }
    while(next_node.size() > 0){
        int queue_size = next_node.size();
        while(queue_size--){
            int cur_node = next_node.front();
            next_node.pop();
            for(const auto & vert : flow_out[cur_node]){
                compute_num[vert]--;
                if(compute_num[vert] == 0){
                    dp[vert] = 0;
                    for(const auto v : flow_in[vert]){
                        dp[vert] = max(dp[vert], dp[v] + 1);
                    }
                    next_node.push(vert);
                }
            }
        }
    }

    int ans = 0;
    REP(i,n){
        ans = max(ans, dp[i]);
    }
    cout << ans << "\n";
    
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}



Measured memory_bytes: 15024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=105;
int n,s[max_n];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",s+i);
    ll ans=0;
    int x=1000;
    for(int i=1;i<=n;i++){
        ans+=s[i];
        if(s[i]%10)x=min(x,s[i]);
    }
    if(ans%10)printf("%d\n",ans);
    else{
        if(x==1000)printf("0\n");
        else printf("%d\n",ans-x);
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 100001
using namespace std;
int n;
int t[maxn];

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

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

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

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	  scanf("%d",&t[i]);
	for(int i=1;i<=n;++i)
	{
		printf("node %d: ",i);
		printf("key = %d, ",t[i]);
		if(parent(i)>=1) printf("parent key = %d, ",t[parent(i)]);
		if(left(i)<=n) printf("left key = %d, ",t[left(i)]);
		if(right(i)<=n) printf("right key = %d, ",t[right(i)]);
		printf("\n");
	}
	return 0;
} 

Measured memory_bytes: 3092
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());

        if (N >= M) {
            System.out.println(0);
            return;
        }

        int[] xArray = new int[M];
        for (int i = 0; i < M; i++) {
            int topX = Integer.parseInt(scanner.next());
            xArray[i] = topX;
        }
        scanner.close();

        Arrays.sort(xArray);

        Integer diffList[] = new Integer[M - 1];
        for (int i = 0; i < M - 1; i++) {
            int diff = Math.abs(xArray[i] - xArray[i + 1]);
            diffList[i] = diff;
        }

        Arrays.sort(diffList, Comparator.reverseOrder());

        for (int i = 0; i < N - 1; i++) {
            diffList[i] = 0;

            if (i == M - 1) {
                break;
            }
        }

        int sum = 0;
        for (int diff : diffList) {
            sum += diff;
        }

        System.out.println(sum);
    }
}


Measured memory_bytes: 46208
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int n100;
        int n10;
        int n1;
        for (int i = n; i < 1000; i++) {
            n100 = i / 100;
            n10 = (i / 10) % 10;
            n1 = i % 10;
            if (n100 == n10 && n10 == n1) {
                System.out.println(i);
                break;
            }
        }

    }
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
    public static void main (String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            double ans = 0.0;
            
            for (int i = 1; i <= n; i++) {
                
                // Probability of occurence of the event
                double prob = 1.0/n;

                int now = i;
                
                // Keep multiplying by 2 till the now exceeds k. now is the exponent on 1/2
                while (now < k) {
                    now *= 2; 
                    prob /= 2;               
                }            
                ans += prob;
            }
           System.out.println(ans);
        }    
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<ll, ll>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
/* -- template -- */

int main() {
    int N; cin >> N;
    int cnt = 0, minv = INF;
    ll sum = 0;
    int A[N];
    rep(i, N){
        cin >> A[i];
        sum += abs(A[i]);minv = min(abs(A[i]), minv);
        if(A[i]<0)cnt++;
    }
    if(cnt % 2)
        cout << sum - 2 * minv << endl;
    else
        cout << sum << endl;

}


Measured memory_bytes: 640
use std::io;
use std::str::FromStr;
use std::collections::BinaryHeap;

fn input_int_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_u64_vec() -> BinaryHeap<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn get_index(sorted_vec: &Vec<u64>, target: u64) -> usize{
    if sorted_vec.len() == 0 {
        return 0;
    }
    for i in 0..sorted_vec.len()-1 as usize {
        if target > sorted_vec[i] {
            return i;
        }
    }
    sorted_vec.len()
}

fn main() {
    let (_, m) = input_int_tuple();
    let mut a_vec = input_u64_vec();

    for _ in 0..m {
        let n = a_vec.pop().unwrap();
        a_vec.push(n / 2);
        // println!("{:?}", a_vec);
    }

    let mut sum = 0;
    for a in a_vec {
        sum += a;
    }
    println!("{}", sum);
}


Measured memory_bytes: 8444
s1 = input()
s2 = input()
a = len(s2)
m = 10**18
for x in range(len(s1)-a+1):
  s3 = s1[x:x+a]
  s = 0
  for y in range(a):
    if s3[y]!=s2[y]:
      s+=1
  m = min(m,s)
print(m)


Measured memory_bytes: 9112
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int N;

int main() {
  cin >> N;
  if ((N / 10) % 111 == 0 || (N % 1000) % 111 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3588
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
     
    public static void main(String[] args) {
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String str = reader.readLine();
            double S = Double.parseDouble(str);
            int h = (int)Math.floor(S / 3600);
            int m = (int)Math.floor((S % 3600) / 60);
            int s = (int)Math.floor((S % 3600) % 60);
            System.out.println(h + ":" + m + ":" + s);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
}

Measured memory_bytes: 24408
#include<stdio.h>
#define ll long long int

ll t[100001][3],ar[100000][3];

ll fun(ll l,ll r,ll k){
  if(l>r) return 0;
  ll a,b;  
  if(t[l][k]==-1){
    if(k==0){
      a=fun(l+1,r,1)+ar[l][1];
      b=fun(l+1,r,2)+ar[l][2];
    }
    else if(k==1){
      a=fun(l+1,r,0)+ar[l][0];
      b=fun(l+1,r,2)+ar[l][2];
    }
    else {
      a=fun(l+1,r,1)+ar[l][1];
      b=fun(l+1,r,0)+ar[l][0];
    }
    a=a>=b?a:b;
    t[l][k]=a;
  }
  return t[l][k];
}

ll funn(ll l,ll r){
  ll a=fun(l+1,r,0)+ar[0][0];
  ll b=fun(l+1,r,1)+ar[0][1];
  a=a>=b?a:b;
  b=fun(l+1,r,2)+ar[0][2];
  a=a>=b?a:b;
  return a;
}

  int main(){
    for(int i=0;i<100001;i++)
     t[i][0]=t[i][1]=t[i][2]=-1;
    ll n;
    scanf("%lld",&n);
    for(int i=0;i<n;i++)
      scanf("%lld%lld%lld",ar[i],ar[i]+1,ar[i]+2);
    printf("%lld\n",funn(0,n-1));
    return 0;
  }


Measured memory_bytes: 12672
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char c[10050];
int main(){
	cin>>c+1;
	int f=0;
	for(int i=1;i<=strlen(c+1);i++){
		if(f&&c[i]=='C'){
			cout<<"Yes"<<endl;
			return 0;
		}
		if(c[i]=='A')f=1;else f=0;
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll a, b, c, k;
  cin >> a >> b >> c >> k;

  ll ans = 0;
  if (a >= k) {
    ans = k;
  } else {
    ans = a;
    k -= a;

    if (b < k) {
      k -= b;
      ans -= k;
    }
  }

  cout << ans << ln;

  return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define sq(x) ((x)*(x))
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17

#define maxn 300005
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> pii;

i64 dp[5005] ;

i64 f( i64 N , int g1, int s1, int b1, int g2 ,int s2 ,int b2 )
{
    vector < pair<int,int> > vp ;
    if( g1 < g2 ) vp.pb(mp(g1,g2)) ;
    if( b1 < b2 ) vp.pb(mp(b1,b2)) ;
    if( s1 < s2 ) vp.pb(mp(s1,s2)) ;

    if( vp.size() != 3 )
    {
        if( vp.size() == 0 ) return N ;
        if( vp.size()==1 ) return (N/vp[0].xx)*vp[0].yy + N%vp[0].xx ;

        i64 res = 0LL ;

        for(i64 i=0 ; i<=N ; i+=vp[0].xx ) res = max( res , 1LL*(i/vp[0].xx)*vp[0].yy + 1LL*((N-i)/vp[1].xx)*vp[1].yy + (N-i)%vp[1].xx ) ;

        return res ;
    }

    i64 rest[5005] ;

    rest[0] = 0 ;

    for(int n=1 ; n<=N ; n++)
    {
        rest[n] = 0 ;
        for(int b=0 ; b<=n ; b+=b1)
        {
            rest[n] = max(rest[n] , 1LL*(b/b1)*b2 + 1LL*((n-b)/s1)*s2 + (n-b)%s1 ) ;
        }
    }
    dp[0] = 0 ;
    for(int n=1 ; n<=N ; n++)
    {
        dp[n] = 0 ;
        for(int g=0 ; g<=n ; g+=g1)
        {
            dp[n] = max( dp[n] , 1LL*(g/g1)*g2 + rest[n-g] ) ;
        }
    }
    return dp[N];
}

int main()
{
    int g1 , s1 , b1 , g2 , s2, b2 ;
    int n ;

    scanf("%d %d %d %d %d %d %d",&n,&g1,&s1,&b1,&g2,&s2,&b2) ;

    i64 res =  f( n , g1,s1,b1, g2,s2,b2 ) ;
    res =  f( res , g2,s2,b2, g1,s1,b1 ) ;

    printf("%lld\n",res) ;

    return 0 ;
}


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

int n;

long long dp[512][512];
long long x[512];
long long sum[512];

int main(){
	cin>>n;
	memset(dp,0x7f7f7f7f,sizeof(dp));
	for(int i=1;i<=n;++i) cin>>x[i],sum[i]=x[i]+sum[i-1],dp[i][i]=0;
	for(int k=1;k<=n;++k){
		for(int i=1;i+k<=n;++i){
			for(int j=i;j<i+k;++j){
				dp[i][i+k]=min(dp[i][i+k],dp[i][j]+dp[j+1][i+k]+sum[i+k]-sum[i-1]);
			}
		}
	}
	cout<<dp[1][n]<<"\n";
	return 0;
}

Measured memory_bytes: 2304
n = int(input())
graph = {}

for i in range(1, n + 1):
    data = input().split()
    graph[i] = [int(i) for i in data[2:]]


class dfs:
    def __init__(self, graph):
        self.g = graph
        self.visited = set()
        self.time = 0
        self.res = {}

    def dfs(self, cur):
        self.visited.add(cur)
        self.time += 1
        start = self.time
        for node in self.g[cur]:
            if node not in self.visited:
                self.dfs(node)
        self.time += 1
        end = self.time
        self.res[cur] = (start, end)


solver = dfs(graph)
for i in range(1, n + 1):
    if i not in solver.visited:
        solver.dfs(i)

for i in range(1, n + 1):
    print(i, solver.res[i][0], solver.res[i][1])



Measured memory_bytes: 5712
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i=0;i<n;++i) cin >> v[i];
  vector<int> dp(n);
  dp[0]=0;
  for(int i=1;i<n;++i)
  {
    if(i==1)
      dp[i]=abs(v[i]-v[i-1]);
    else
      dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
  }
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 3936
#include <bits/stdc++.h>
#define ll long long
#define Rep(i,l,r) for(int (i)=(l);(i)<=(r);(i)++)
using namespace std;
map<int,ll>::iterator it;
map<int,ll> mp;
multiset<ll> values;
int n,m,l,r;

int main(){
	cin>>n>>m;
	Rep(i,1,m){mp[i]=0;values.insert(0);}
	Rep(i,1,n){
		cin>>l>>r;
		if(r!=m){
			it=mp.upper_bound(r+1);
			if(it!=mp.begin()){
				it--;
				if(it->first!=r+1){
					ll v=it->second+(r+1-it->first);
					mp[r+1]=v;values.insert(v);
				}
			}
		}
		it=mp.lower_bound(l);
		while(it!=mp.end()&&it->first<=r){
			values.erase(values.find(it->second));
			it=mp.erase(it);
		}
		cout<<((values.size())?(i+(*values.begin())):(-1))<<endl;
	}
	return 0;
}


Measured memory_bytes: 25424
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define P 1000000007
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

void solve() {
	int n;
	cin >> n;
	vi count(n, 0);
	for(int i = 0; i < n - 1; i++) {
		int a;
		cin >> a; a--;
		count[a]++;
	}
	
	for(int i = 0; i < n; i++) cout << count[i] << endl;
}

int main(){
#define MULTITEST 0	
#if MULTITEST   
 
    CASET {
        solve();
    }
    
#else

    solve();
    
#endif

    return 0;
}

Measured memory_bytes: 4056
N=int(input())
H=list(map(int,input().split()))
old=H[0]
count=0
ans=[]
for i in range(1,N):
    if H[i]<=old:
        count+=1
    else:
        ans.append(count)
        count=0
    old=H[i]
ans.append(count)
print(max(ans))

Measured memory_bytes: 14252
from collections import deque
n = int(input())
a = [int(x) for x in input().split()]
b = deque()
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])

if n % 2 != 0:
    b.reverse()

b = list(b)

for i in range(len(b)-1):
    print(b[i],end = " ")
print(b[-1])


Measured memory_bytes: 25412
#include <iostream>
#include <vector>

using namespace std;

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

   vector<int> l(n);
   for (int i = 0; i < n; ++i)
      cin >> l[i];

   int s = 0;
   for (int i = 0; i < n; ++i) {
      s += l[i];
      if (s > x) {
         cout << i  + 1 << endl;
         return 0;
      }
   }

   cout << n + 1 << endl;

   return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		
		
		int count = 0;
		int num = 0;
		int numplus = 0;
		int divisor_count = 0;
		int Ncount = 0;
		
		
		
		for (Ncount = 1; Ncount <= N; Ncount = Ncount + 2){
			num = Ncount;
			for (numplus = 1; num >= numplus; numplus++){
				if (num % numplus == 0){
					count++;
				}
				
			}
			numplus = 0;
			
			if (count == 8){
				divisor_count++;
			}
			count = 0;
		}
		
		
		System.out.println(divisor_count);
		
	}
}



Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
int main()
{
    int n,x,num=101,ans=101;
    cin>>x>>n;
    vector<int> a(110);
    rep(i,n){
        int b;
        cin>>b;
        a[b]++;
    }
    rep(i,102){
        if(a[i]==1) continue;
        if(num>abs(i-x)){
            num=abs(i-x);
            ans=i;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3624