akhauriyash/Code-Regression huggingface dataset:
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
  int n;
  int k;
  int h;
  int ans = 0;
  cin >> n >> k;
  for(int i = 0; i < n; i++){
    cin >> h;
    if(h >= k) ans++;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	double a,l,x;
	while(cin>>a>>l>>x){
		double ans=a*sqrt(4*l*l-a*a)/4+l*sqrt(x*(2*l+x))/2;
		printf("%.9f\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (2e9)

struct Edge {
  int to;
};
using Graph = vector<vector<Edge>>;

int N, M, K;

int id;
vector<int> group;
vector<int> group_size;

void dfs(const Graph &G, int v, int &cnt) {
  group[v] = id;
  cnt++;
  for(auto e : G[v]) {
    if(group[e.to] == -1) {
      dfs(G, e.to, cnt);
    }
  }
}

int main() {
  cin >> N >> M >> K;
  Graph G(N);
  vector<int> A(M), B(M);
  for(int i = 0; i < M; ++i) {
    cin >> A[i] >> B[i];
    A[i]--, B[i]--;
    G[A[i]].push_back({B[i]});
    G[B[i]].push_back({A[i]});
  }
  vector<int> C(K), D(K);
  for(int i = 0; i < K; ++i) {
    cin >> C[i] >> D[i];
    C[i]--, D[i]--;
  }

  group.assign(N, -1);
  id = 0;
  for(int i = 0; i < N; ++i) {
    if(group[i] == -1) {
      int cnt = 0;
      dfs(G, i, cnt);
      group_size.push_back(cnt);
      id++;
    }
  }

  vector<int> ans(N);
  for(int i = 0; i < N; ++i) ans[i] = group_size[group[i]] - 1 - G[i].size();
  for(int i = 0; i < K; ++i) {
    if(group[C[i]] == group[D[i]]) {
      ans[C[i]]--;
      ans[D[i]]--;
    }
  }

  cout << ans[0];
  for(int i = 1; i < ans.size(); ++i) {
    cout << " " << ans[i];
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 9600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace paiza2
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine();
            var split = read.Split(' ');
            int N = Int32.Parse(split[0]);
            int K = Int32.Parse(split[1]);
            read = Console.ReadLine();
            split = read.Split(' ');
            int[] D = new int[K];
            for (int c = 0; c < K; c++)
            {
                D[c] = Int32.Parse(split[c]);
            }
            int looking = N;
            while (true)
            {
                int flag = 0;
                for (int keta = 0; keta < looking.ToString().Length; keta++)
                {
                    for (int c_k = 0; c_k < K; c_k++)
                    {
                        
                        if (looking.ToString()[keta] == D[c_k].ToString()[0])
                        {
                            flag = 1;
                            break;
                        }

                    }
                    if (flag == 1) break;
                    
                }
                if (flag == 1)
                {
                    looking++;
                }
                else break;
            }
            Console.WriteLine(looking);

        }
    }
}


Measured memory_bytes: 15164
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

int main() {
	int r, D, x; cin >> r >> D >> x;
	long long ans=x;
	for (int i = 0; i < 10; i++) {
		ans = r * ans - D;
		cout << ans << endl;
	}
}



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


using namespace std;
int N;
int main()
{
	cin>>N;
	int sqt = sqrt(N);
	int ans = 0;
	for(int A = 1; A <= N; ++A)
	{
		int B = N / A;
		if(A * B == N)
			ans += (B - 1);
		else
			ans += B;
	}
	cout<<ans<<endl;
	
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    int n;
    cin >> n;
    vector<int> a((n + 1) / 2, 0);
    rep (i, n) {
        int tmp;
        cin >> tmp;
        if ((n - tmp) % 2 == 0) {
             cout << 0 << endl;
             exit(0);
        }
        a[tmp / 2]++;
    }
    ll ans = 1;
    ll mod = 1e9 + 7;
    if (n % 2 == 1 && a[0] != 1) {
        cout << 0 << endl;
        exit(0);
    }
    rep (i, (n + 1) / 2) {
        ans *= a[i];
        ans %= mod;
    }
    cout << ans << endl;

}


Measured memory_bytes: 384
def main():
    from itertools import zip_longest
    N = int(input())
    ans = 1 << 60
    for i in range(1, N//2 + 2):
        c1 = str(i)
        c2 = str(N-i)
        cur = 0
        for s1, s2 in zip_longest(c1, c2, fillvalue=0):
            cur += int(s1) + int(s2)
        ans = min(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41196
#include<iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char const *argv[])
{
    int X;

    cin>>X;
    if(X==7||X==5||X==3){
    cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm> 
#include <cmath> //pow

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

using namespace std;

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

	priority_queue<int> que;
	rep(i, n) {
		int a;
		cin >> a;
		que.push(a);
	}

	rep(i, m) {
		int max = que.top();
		que.pop();
		que.push(max/2);
	}

	long long int ans = 0;
	while (!que.empty()) {
	  ans += que.top();
	  que.pop();
	}
	 cout << ans << endl;
}


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

int main() {
  int N,K;
  cin >> N >> K;
  string s;
  cin >> s;
  K--;
  if(s.at(K)=='A') s.at(K)='a';
  if(s.at(K)=='B') s.at(K)='b';
  if(s.at(K)=='C') s.at(K)='c';  
  cout << s << endl;
}


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

ll f(ll p, ll x)
{
    if(p<0) return 0;
    else return p/x+1;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,x;
    cin >> a >> b >> x;
    cout << f(b,x)-f(a-1,x) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
using namespace std;
int main(void){
    double T,X;
    cin>>T>>X;
    double ans=T/X;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(b)]
d=[[]for i in range(a+1)]
for i,k in enumerate(c):
  d[k[0]].append([i,k[1]])
  
e=[[]for i in range(b)]  
for i in range(a+1):
  d[i]=sorted(d[i], key=lambda x: x[1])
  for j,k in enumerate(d[i]):
    e[k[0]]=[i,j+1]
    
for i in range(b):
  print(str(e[i][0]).zfill(6)+str(e[i][1]).zfill(6))


Measured memory_bytes: 60908
N, K = map(int, input().split())

A = list(range(N+1))
ans = 1
left = A[:K]
right = A[-K:]
nextleft = left[-1]
nextright = right[0]
left = sum(A[:K])
right = sum(A[-K:])
for i in range(K, N+1):
    ans += right - left + 1
    nextleft += 1
    nextright -= 1
    left += nextleft
    right += nextright
print(ans%(10**9+7))
    


Measured memory_bytes: 70892
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	vector<vector<int>>edge(N);
	vector<set<int>>ie(N);
	vector<int>dp(N);
	for (int i = 0; i < M; i++) {
		cin >> L >> R;
		L--;
		R--;
		edge[L].push_back(R);
		ie[R].insert(L);
	}
	queue<int>Q;
	for (int i = 0; i < N; i++) {
		if (ie[i].empty()) {
			Q.push(i);
		}
	}
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (auto i : edge[cn]) {
			dp[i] = max(dp[i], dp[cn] + 1);
			ie[i].erase(cn);
			if (ie[i].empty())Q.push(i);
		}
	}
	cout << *max_element(dp.begin(), dp.end()) << endl;
	return 0;
} 

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

int main() {
    int N,K;
    cin>>N>>K;
    vector<int> d(K);
    vector<vector<int>> data(K,vector<int>(N,0));
    
    for(int i=0;i<K;i++){
        cin>>d.at(i);
        for(int j=0;j<(d.at(i));j++){
            cin>>data.at(i).at(j);
        }
    }
    set<int> s;
    for(int i=0;i<K;i++){
        for(int j=0;j<(d.at(i));j++){
            s.insert(data.at(i).at(j));
        }
    }
    cout<<N-s.size()<<endl;
}

Measured memory_bytes: 3652
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!.split(" ").map { it.toInt() }.toTypedArray()

    var c = 0
    for(i in 1 until n - 1){
        if(isSecond(s[i-1], s[i], s[i+1])) c++
    }
    println(c)
}

fun isSecond(n1: Int, n2: Int, n3: Int): Boolean{
    val list = listOf(n1, n2, n3)
    val sortedArray = list.sorted().toTypedArray()
    return sortedArray[1] == n2
}

Measured memory_bytes: 36032
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var A = ReadLong();
            if(N % 500 <= A)
            {
                return "Yes";
            }
            else
            {
                return "No";
            }
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 27448
#include<stdio.h>
 int main(void)
 {
     int N,i=1;
     int a,b,c,S;

     scanf("%d",&N);

     a=N/100;
     b=(N%100)/10;
     c=(N%100)%10;

     if((a==b)&&(b==c)) printf("%d\n",N);

     else{
       while(S<=N){
         S=111*i;
         if(S>=N){
           printf("%d\n",S);
           return 0;
         }
         i++;
       }
     }

     return 0;
 }


Measured memory_bytes: 1720
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<pair<ll, ll>> x(n);
  for (int i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;
    x[i] = make_pair(a, b);
  }
  ll ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    ll a = ans + x[i].first;
    ll b = x[i].second;
    if (a % b == 0) continue;
    ans += b - (a % b);
  }
  cout << ans << endl;
  return 0;
}

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

typedef struct{
	int num[6];
}saikoro;



saikoro s_1,s_2;

void n(saikoro *a){
	int tmp;
	tmp=a->num[4];
	a->num[4]=a->num[0];
	a->num[0]=a->num[1];
	a->num[1]=a->num[5];
	a->num[5]=tmp;
}

void s(saikoro *a){
	int tmp;
	tmp=a->num[1];
	a->num[1]=a->num[0];
	a->num[0]=a->num[4];
	a->num[4]=a->num[5];
	a->num[5]=tmp;
}

void e(saikoro *a){
	int tmp;
	tmp=a->num[2];
	a->num[2]=a->num[0];
	a->num[0]=a->num[3];
	a->num[3]=a->num[5];
	a->num[5]=tmp;
}

void w(saikoro *a){
	int tmp;
	tmp=a->num[3];
	a->num[3]=a->num[0];
	a->num[0]=a->num[2];
	a->num[2]=a->num[5];
	a->num[5]=tmp;
}

int rota(saikoro *a){
	int tmp;
	tmp=a->num[1];
	a->num[1]=a->num[2];
	a->num[2]=a->num[4];
	a->num[4]=a->num[3];
	a->num[3]=tmp;
	
}

int check(){
	int i;
	for(i=0;i<6;i++){
		if(s_1.num[i]!=s_2.num[i]){
			return 1;
		}
	}
	return 0;
}

int main(){
	int i,j,k,f_br=0;
	char input[128];
	
	fgets(input,sizeof input,stdin);
	sscanf(input,"%d %d %d %d %d %d",&s_1.num[0],&s_1.num[1]
		,&s_1.num[2],&s_1.num[3],&s_1.num[4],&s_1.num[5]);
	
	fgets(input,sizeof input,stdin);
	sscanf(input,"%d %d %d %d %d %d",&s_2.num[0],&s_2.num[1]
		,&s_2.num[2],&s_2.num[3],&s_2.num[4],&s_2.num[5]);
	
	
	
	
	for(i=0;i<4;i++){
		for(j=0;j<4;j++){
			for(k=0;k<4;k++){
				if(check()==0){
					f_br=1;
					break;
				}
				rota(&s_1);
			}
			if(f_br==1){
				break;
			}
			e(&s_1);
		}
		if(f_br==1){
			break;
		}
		n(&s_1);
	}
	
	if(f_br==1){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        vector<int> A(N); cin >> A;
        deque<int> B;
        rep(i, N) {
            if(i % 2 == 0) B.push_back(A[i]);
            else B.push_front(A[i]);
        }
        if(N % 2) reverse(all(B));
        rep(i, N) cout << B[i] << (i == N - 1 ? "\n" : " ");
        return 0;
    }
};

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


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<ll,ll> mp;
ll a[300005];
int main()
{
	ll n;cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	ll ans=0;
	for(map<ll,ll>::iterator it=mp.begin();it!=mp.end();it++){
		if(it->second<2)continue;
		ans+=it->second*(it->second-1)/2;
	}
	for(int i=1;i<=n;i++){
		
		printf("%lld\n",ans-(mp[a[i]]-1));
	}
}

Measured memory_bytes: 13212
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n, c = 0, ans = 0;
  string s;
  cin >> n >> s;
  for(int i = 0; i < n; i++)
  {
    if(s[i] == 'I')c++;
    else c--;
    ans = max(ans, c);
  }
  printf("%d", ans);
  return 0;
}

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

using lint = long long;

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

int main() {
    lint N, X; cin >> N >> X;

    lint r = gcd(N, X);
    N /= r; X /= r;

    lint ans = (N - 1)*3*r;

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
ll a[300010];

int main () {
  cin >> N;
  N = 3 * N;
  for (auto i = 0; i < N; ++i) {
    cin >> a[i];
  }
  sort(a, a+N);
  reverse(a, a+N);
  ll ans = 0;
  int M = N/3;
  int cnt = 0;
  for (auto i = 0; i < N; ++i) {
    if (i%2 == 1) {
      ans += a[i];
      ++cnt;
      if (M == cnt) break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
N = int(input())
songs = []
times = []
for _ in range(N):
  song,time = input().split()
  songs.append(song)
  times.append(int(time))
start = input()
number = songs.index(start)
if number == len(songs):
  print(0)
else:
  print(sum(times[number+1:]))

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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

const int N = 100005, MAX = 1000000000;
char s[N];
int dp[N], nxt[N];

int main() {
    int n, m;
    scanf("%d %d\n%s", &n, &m, s);
    set <pair <int, int> > st;
    dp[n] = 0;
    nxt[n] = -1;
    st.insert({dp[n], n});
    for (int i = n - 1; i >= 0; i--) {
        dp[i] = MAX;
        nxt[i] = -1;
        if (s[i] == '0') {
            auto it = st.begin();
            if (it->fi + 1 < dp[i]) {
                dp[i] = it->fi + 1;
                nxt[i] = it->se;
            }
        }
        st.insert({dp[i], i});
        if ((int)st.size() > m) {
            st.erase({dp[i+m], i+m});
        }
    }
    if (dp[0] == MAX) {
        printf("-1");
    } else {
        int x = nxt[0], pre = 0;
        while (x != -1) {
            printf("%d ", x - pre);
            pre = x;
            x = nxt[x];
        }
    }
    return 0;
}


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

const int MAX = 25605;

int a[85][85], b[85][85];
bool dp[85][85][MAX];

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

    int h, w;
    cin >> h >> w;
    for (int i=0; i<h; i++)
        for (int j=0; j<w; j++)
            cin >> a[i][j];
    for (int i=0; i<h; i++)
        for (int j=0; j<w; j++)
            cin >> b[i][j];

    dp[0][0][abs(a[0][0] - b[0][0])] = true;
    for (int i=0; i<h; i++)
        for (int j=0; j<w; j++)
            for (int k=0; k<MAX; k++)
                if (dp[i][j][k]) {
                    if (i + 1 < h) {
                        int val = abs(a[i+1][j] - b[i+1][j]);
                        if (k + val < MAX) dp[i+1][j][k+val] = true;
                        dp[i+1][j][abs(k-val)] = true;
                    }
                    if (j + 1 < w) {
                        int val = abs(a[i][j+1] - b[i][j+1]);
                        if (k + val < MAX) dp[i][j+1][k+val] = true;
                        dp[i][j+1][abs(k-val)] = true;
                    }
                }

    int ret = 0;
    while (!dp[h-1][w-1][ret])
        ret++;
    cout << ret << "\n";

    return 0;
}

Measured memory_bytes: 69112
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int 

//-4%3=-1
        lld n,w;
        lld wt[101],val[101],dp[100001][101];
lld min(lld a,lld b)
{
    if(a<b)
    return a;
    else
    return b;
}
        
lld fun(lld sval,lld i)
{
    if(sval<=0)
    return 0;
    if(i==n+1)
    return 1e9;
    if(dp[sval][i]!=-1)
    return dp[sval][i];
    else
    return dp[sval][i]=min(fun(sval,i+1),wt[i]+fun(sval-val[i],i+1));
}
int main() {
	// your code goes here
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t;
    //cin>>t;
    t=1;
    while(t--)
    {
        lld sum=0,r,mval=INT_MAX;
        cin>>n>>w;
        for(int i=1;i<=n;i++)
        {
            cin>>wt[i]>>val[i];
            sum+=val[i];
            //mval=min(val[i],mval);
        }
        memset(dp,-1,sizeof(dp));
        for(r=sum;r>=0;r--)
        if(fun(r,1)<=w)
        {
            cout<<r;
            break;
        }
    }
}



Measured memory_bytes: 79360
/* ****GT_18**** */

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define INF			1000000000000000
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
using namespace __gnu_pbds;

#define N  100005

ll mxs[4];// 0->++, 1->+-, 2-> -+, 3-> --

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll n;
		vector<pii> points;
		cin>>n;
		rep(i,0,n){
			ll x,y;
			cin>>x>>y;
			points.pb({x,y});
		}
		rep(i,0,4){
			mxs[i]=points[0].F*(-1 +2*(!(i&2))) + points[0].S*(-1 + 2*(!(i&1)));
			// cerr<<mxs[i]<<endl;
		}
		ll ans[4];
		memset(ans,0,sizeof(ans));
		rep(i,1,n){
			ll temp[4];
			rep(j,0,4){
				ll curr = points[i].F*(-1 +2*(!(j&2))) + points[i].S*(-1 + 2*(!(j&1)));
				ans[j]=max(ans[j],curr+ mxs[3^j]);
				temp[j]=curr;
			}
			rep(j,0,4){
				mxs[j]=max(mxs[j],temp[j]);
			}
		}
		ll fin=0;
		rep(i,0,4)fin=max(fin,ans[i]);
		// rep(i,0,4)cerr<<ans[i]<<" "<<endl;
		cout<<fin<<endl;

	}
	return 0;
}

Measured memory_bytes: 7396
A = input()
B = input()
C = input()

S = dict()
S['a'] = list(A[::-1])
S['b'] = list(B[::-1])
S['c'] = list(C[::-1])

next_p = 'a'
while S[next_p]:
    next_p = S[next_p].pop()
print(next_p.upper())


Measured memory_bytes: 3060
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int A, B, C, D, E, F;
	
	cin >> A >> B >> C >> D >> E >> F;

	int max_A = F / A;
	int max_B = F / B;

	int max_ws = 0;
	int max_s = 0;

	for(int i = 0; i <= max_A; i++)
	{
		for (int j = 0; j <= max_B; j++)
		{
			int w = i*A+j*B;
			int l = w * 100;
			for (int p = 0; p <= w * E / C; p++)
			{
				if (l + p*C > F)
				{
					break;
				}
				for (int q = 0; q <= (w * E - p * C) / D; q++)
				{
					
					if ((l + p * C + q * D) > F)
					{
						break;
					}

					if ((max_ws == 0 && (max_s == 0)) || (max_ws * (p*C+q*D) > max_s*(l + q*D + p*C)))
					{
						max_ws = l + q * D + p * C;
						max_s = p * C + q * D;
						//cout << i << " " << j << " " << p << " " << q << endl;
					}
					
				}
			}
		}
	}

	cout << max_ws << " " << max_s << endl;


	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,kk,kkk,ans,sum,a[1000000],b[1000000];
signed main(){
	ios::sync_with_stdio(false);
	cin>>n>>k;for (int i=1;i<=n;i++)cin>>a[i]>>b[i];
	for (int i=40;i>=0;i--)
		if (k&(1ll<<i)){
			sum=0;kkk+=1ll<<i;
			for (int j=1;j<=n;j++)
				if ((a[j]&kkk)==(a[j]&kk))sum+=b[j];
			kk+=1ll<<i;ans=max(ans,sum);
		}else kkk+=1ll<<i;
	sum=0;for (int j=1;j<=n;j++)
		if ((a[j]&kkk)==(a[j]&kk))sum+=b[j];
	ans=max(ans,sum);
	cout<<ans<<endl;
}

Measured memory_bytes: 5120
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main() {
	LL N;
	cin >> N;
	
    int n = 1;
    for (; n * (n + 1) / 2 < N; n++) {
    }
    if (n * (n + 1) / 2 > N) {
        cout << "No" << endl;
        return 0;
    } else {
		cout << "Yes" << endl;
	}
	cout << (n + 1) << endl;

	VVI ans;
	ans.resize(n + 1);
	REP(i, SZ(ans)) {
		ans[i].resize(n);
	}
	REP(i, n) {
		ans[0][i] = i + 1;
	}

	LL val = n + 1;
	for (int i = 1; i < SZ(ans); i++) {
		for (int j = 0; j < i; j++) {
			ans[i][j] = ans[j][i - 1];
		}
		for (int j = i; j < n; j++){
			ans[i][j] = val;
			val++;
		}
	}

	REP(i, SZ(ans)) {
		cout << n << " ";
		REP(j, SZ(ans[i]) - 1) {
			cout << ans[i][j] << " ";
		}
		cout << ans[i][SZ(ans[i]) - 1] << endl;
	}

	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

ll Count(ll n){
    ll cnt = 0;
    while(n){
        n = n%__builtin_popcount(n);
        cnt++;
    }
    return cnt;
}

int main(){
    Init();
    ll n, bitCnt = 0; string s;
    cin >> n >> s;
    rep(i, n) if(s[i] == '1') bitCnt++;

    ll a = bitCnt+1;
    ll b = bitCnt-1;
    vi p(n); p[n-1] = 1;
    vi q(n); q[n-1] = 1;
    for(ll i=n-2; i>=0; i--){
        if(a) p[i] = p[i+1]*2%a;
        if(b) q[i] = q[i+1]*2%b;
    }
    ll sp = 0, sm = 0;
    rep(i, n) if(s[i] == '1') sp += p[i], sm += q[i];

    rep(i, n){
        if(s[i] == '1'){
            // 反転する箇所が1の場合
            if(b <= 0) cout << 0 << endl;
            else cout << (1 + Count((sm-q[i]+b)%b)) << endl;
        }
        else{
            // 反転する箇所が0の場合
            cout << (1 + Count((sp+p[i])%a)) << endl;
        }
    }
}

Measured memory_bytes: 6748
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;


#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define MUL(a,b) a=(a*b)%mod

ll N;
struct St{
    ll val;
    string str;
    ll pos;
    St(ll a, string b, ll c){
        val=a; str=b; pos=c;
    }
    bool operator<(const St &a) const{
        if(val != a.val) return val<a.val;
        return str!=a.str ? str<a.str : pos<a.pos;
    }
    bool operator>(const St &a) const{
        if(val != a.val) return val>a.val;
        return str!=a.str ? str>a.str : pos>a.pos;
    }
    //posが0なら頭から、1なら後ろから、-1ならアカン、2ならクリア
    void PRINT() {cout<<val<<' '<<str<<' '<<pos<<endl;}
};
vector<St> F,G;
set<string> SET;

bool kaibun(string S){
    ll n=S.size();
    rep(i,n){
        if(i>=n-1-i) return true;
        if(S[i]!=S[n-1-i]) return false;
    }
    return true;
}


St ABLE(St x, St y){
    St akan(x.val+y.val,x.str+y.str,-1);
    if(x.pos==y.pos) return akan;
    if(x.pos==1) return ABLE(y,x);
    St iketa(x.val+y.val,x.str+y.str,2); 
    ll X=x.str.size(), Y=y.str.size();
    if(X>Y){
        rep(i,Y) if(x.str[i]!=y.str[Y-1-i]) return akan;
        string kari=x.str.substr(Y);
        if(kaibun(kari)) return iketa;
        St ret(x.val+y.val,kari,0);
        return ret;
    }
    rep(i,X) if(x.str[i]!=y.str[Y-1-i]) return akan;
    string kari=y.str.substr(0,Y-X);
    if(kaibun(kari)) return iketa;
    St ret(x.val+y.val,y.str.substr(0,Y-X),1);
    return  ret;
}

ll Solve(){
    cin>>N;
    priority_queue<St,vector<St>,greater<St> > Q;
    rep(i,N){
        string S; ll C; cin>>S>>C;
        St f(C,S,1), g(C,S,0), h(C,S,2);
        if(!kaibun(S)) Q.push(f); 
        else Q.push(h);
        F.pb(f); G.pb(g);
    }
    sort(ALL(F)); sort(ALL(G));
    while(!Q.empty()){
        St f=Q.top();
        Q.pop();
        if(f.pos==2) return f.val;
        else if(!SET.count(f.str)){
            SET.insert(f.str);
            if(f.pos==1){
                rep(i,N) {
                    St p=ABLE(f,G[i]);
                    if(p.pos>=0) Q.push(p);
                }
            }
            else{
                rep(i,N) {
                    St p=ABLE(f,F[i]);
                    if(p.pos>=0) Q.push(p);
                }
            }
        }
    }
    return -1;

}
int main(){
    cout<<Solve()<<endl;
}


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


public class Main {
	private	static	BufferedReader	m_stdin = null;

	static {
		m_stdin = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		while (parseMatrix());
	}

	private static boolean parseMatrix() {
		boolean	loop = false;
		String	line = null;

		try {
			line = m_stdin.readLine();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			line = null;
		}

		if (line != null) {
			if (!line.isEmpty()) {
				String[]	lines = line.split(",");
				double[]	da    = { Double.parseDouble(lines[0]), Double.parseDouble(lines[1]) };
				double[]	db    = { Double.parseDouble(lines[2]), Double.parseDouble(lines[3]) };
				double[]	dc    = { Double.parseDouble(lines[4]), Double.parseDouble(lines[5]) };
				double[]	dd    = { Double.parseDouble(lines[6]), Double.parseDouble(lines[7]) };
				int			n1    = getCrossSign(da, db, dd);
				int			n2    = getCrossSign(db, dc, da);
				int			n3    = getCrossSign(dc, dd, db);
				int			n4    = getCrossSign(dd, da, dc);

				if ((n1 == n2) && (n2 == n3) && (n3 == n4)) {
					System.out.println("YES");
				}
				else {
					System.out.println("NO");
				}

				loop = true;
			}
		}

		return loop;
	}

	private static int getCrossSign(double[] da, double[] db, double[] dp) {
		double[]	dab = { db[0] - da[0], db[1] - da[1] };
		double[]	dap = { dp[0] - da[0], dp[1] - da[1] };
		return ( getCross(dab, dap) >= 0.0 ) ? 1 : -1;
	}

	private static double getCross(double[] d1, double[] d2) {
		return d1[0] * d2[1] - d1[1] * d2[0];
	}
}

Measured memory_bytes: 16928
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>
#include <numeric>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define rpt(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

int main()
{
    IO;

    long double N, K; cin >> N >> K;
    cout << ceil((N - 1) / (K - 1)) << endl;
}

Measured memory_bytes: 3228
#include <iostream>

using namespace std;
int main(){
	int a,b,c;
	while(1){
		cin >> a >> b >> c;
		if(a==-1 && b==-1 && c==-1){
			break;
		}
		else if(a==-1 || b==-1){
			cout << "F" << endl;
		}
		else if(a+b>79){
			cout << "A" << endl;
		}
		else if(a+b>64){
			cout << "B" << endl;
		}
		else if(a+b>49){
			cout << "C" << endl;
		}
		else if(a+b>29){
			if(c>49){
				cout << "C" << endl;
			}
			else{
				cout << "D" << endl;
			}
		}
		else{
			cout << "F" << endl;
		}
	}
}


Measured memory_bytes: 3100
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner stdin=new Scanner(System.in);
		int H;
		int W;
		
		while(true){
			H=stdin.nextInt();
			W=stdin.nextInt();
			if(H==0 && W==0) {break;}
			for(int i=1;i<=H;i++){
				if(i==1||i==H){
					for(int j=1;j<=W;j++){
						System.out.print("#");
					}}
				else{
					for(int j=1;j<=W;j++){
						if(j==1 || j==W)System.out.print("#");
						else System.out.print(".");	}}
				System.out.print("\n");
		}
		System.out.print("\n");
	}
	}
}



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

#define Nmax int(1e5 + 1)
using namespace std;

typedef long long ll;
struct can {
    ll quantity,price;
} a[Nmax];

ll N,M,i;
ll S,cnt;

inline bool cmp(can a, can b) {
    return ((a.price < b.price) ? true : false);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> N >> M;
    for(i = 1; i <= N; ++i)
        cin >> a[i].price>> a[i].quantity;
    sort(a + 1, a + N + 1,cmp);
    for(i = 1; i <= N && M > 0; ++i) {
        cnt = min(M,a[i].quantity);
        S += cnt * a[i].price;
        M -= cnt;
    }
    cout << S;
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
  int n,x,count,i,j;

  while(1){
    scanf("%d %d",&n,&x);
    if(n==0 && x==0) break;
    else{
      count=0;
      for(i=1;i<n;i++){
	for(j=i+1;j<n;j++){
	  if(j+1<=x-i-j && x-i-j<=n) count++;
	}
      }
    }
  printf("%d\n",count);
  }

  return 0;
}

Measured memory_bytes: 600
a = int(input())
b = list(map(int, input().split()))
b.insert(0, 0)
b.insert(len(b), 0)
f = 0

while True:
    s = -1
    e = -1
    for i in range(len(b)):
        if b[i] != 0 and s == -1:
            s = i
        elif b[i] == 0 and s != -1 and b[i-1] == 0:
            s = i
        elif b[i] == 0 and s != -1:
            e = i
            break
    if s != -1 and e != -1:
        f += 1
        for i in range(s, e):
            b[i] -= 1
    elif s == -1 and e == -1:
        print(f)
        exit()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int const MAXN = 1e5+9;
int vis[MAXN];
int main(){
    int n,m;
    cin >> n >> m;
    priority_queue<long long  int> pq;
    for (int i  = 0; i < n;i++){
       long long int x;
        cin >> x;
        pq.push(x);
    }
   while (m && !pq.empty()){
        m--;
        long long int x =  pq.top();
        pq.pop();
        x/=2;
        if (x) pq.push(x);
   }
   long long int ans = 0;
   while (!pq.empty()){
        ans += pq.top();
        pq.pop();
   }
   cout << ans << endl;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(int i = (int)k; i < (int)n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(int i = (int)n-1; i > (int)k-1; i--)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl;

typedef long long ll;

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

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

    int N;
    ll K;
    cin >> N >> K;
    vector<pair<int, int> > ab = vector<pair<int, int> >(N);
    rep(i,N) {
        int a, b;
        cin >> a >> b;
        ab[i] = make_pair(a,b);
    }

    sort(ALL(ab));

    rep(i,ab.size()) {
        K -= ab[i].second;
        if(K<=0) {
            cout << ab[i].first << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 1024
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		FastScanner fs = new FastScanner();

		int N = fs.nextInt();

		Long sum = 0L;
		for(int i = 1; i <= N; i++) {
			if(i % 3 == 0 || i % 5 == 0) continue;
			sum += i;
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 38328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    long a, b, k;
    cin >> a >> b >> k;
    if ((a-k) < 0) {
        b = b-(k-a);
        a = 0;
    }
    else a = a-k;
    if (b < 0) b = 0;
    cout << a << ' '<< b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <stack>
#include <queue>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main(){
    ll h,n;
    cin>>h>>n;
    ll a[n];
    ll ans=0;
    for(ll i=0;i<n;++i){
        cin>>a[i];
        ans+=a[i];
    }
    if(ans>=h){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 1024
s=input()
cnt=0;a=0
res = []
for i in s:
    if i not in res:
        res.append(i)
if len(res)!=2:
    print("No")
    exit()
else:
    for i in s:
        if res[0] == i:
            cnt += 1
        if res[1] == i:
            a += 1
    if a == 2 and cnt == 2:
        print("Yes")
    else:
        print("No")


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

using namespace std;

#define int long long

int N, W;
int w[101], v[101];

signed main()
{
	cin >> N >> W;

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

	vector<int> dp(W+5), tmp;

	for (int i = 1; i <= N; ++i) {
		tmp = vector<int>(W+5);
		
		for (int j = 0; j <= W; ++j) {
			tmp[j] = max(tmp[j], dp[j]);
			if (j + w[i] > W) continue; // ←単調性を仮定していましたね…
			tmp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
		}

		dp = tmp;
	}

	int ans = 0;
	for (int i = 0; i <= W; ++i) ans = max(ans, dp[i]);

	cout << ans << endl;
}


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

using namespace std;

vector <int> V[101010];
int K[101010];
int n, ans;

int dfs(int p, int r)
{
	int k, f1, f2;
	
	f1 = f2 = 0;
	
	for(int &t: V[p]){
		if(t != r){
			k = dfs(t, p);
			f2 |= (f1 & k);
			f1 |= k;
		}
	}
	
	return (f1 | K[f2]) + 1;
}

int main()
{
	int i, a, b, s, k;
	
	scanf("%d", &n);
	
	for(s=0, i=1; i<=n; i++){
		if(!(i & (i-1))) s ++;
		K[i] = (1 << s) - 1;
	}
	
	for(i=1; i<n; i++){
		scanf("%d%d", &a, &b);
		V[a].push_back(b);
		V[b].push_back(a);
	}
	
	k = dfs(1, 0);
	
	for(i=0; i<20; i++){
		if(k & (1 << i)){
			ans = i;
		}
	}
	
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 10752
N, K = gets.split.map(&:to_i)
S = gets.chomp.chars.take(N)
zero_list = []
zero_start = nil
S.each.with_index do |ch, i|
  if ch == '0'
    zero_start = i unless zero_start
    if i == S.size - 1
      zero_list.push([zero_start, i])
    end
  else
    if zero_start
      zero_list.push([zero_start, i - 1])
      zero_start = nil
    end
  end
end

if zero_list.empty?
  puts N
  exit
end
ans = 0
(0..(zero_list.size - 1)).each do |i|
  s = if i == 0
    0
  else
    zero_list[i - 1][1] + 1
  end
  e = if i + K > zero_list.size - 1
    N - 1
  else
    zero_list[i + K][0] - 1
  end
  count = (e - s) + 1
  ans = count if count > ans
end
puts ans


Measured memory_bytes: 13180
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define init(c) memset(c,0,sizeof c)
#define S second
#define F first
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=20000005;
int n,k,x,t,a,b,m;
string s;
vi v,w;
int main(){

	cin >> n >> k;
	v.resize(n+10);
	w.resize(n+10);
	for(int i =0;i<n;i++){
		cin>>w[i]>>v[i];
	}
	vl dp(n*1000+5,1e18+5);
	set<ll>st;
	dp[0]=0;
	for(int i =0;i<n;i++){
		for(int j=n*1000-v[i];j>=0;j--){
			dp[v[i]+j] = min(dp[v[i]+j],dp[j]+w[i]);

			st.insert(dp[v[i]+j]);
		}

	}
	int mx = 0;
	for(int i =0;i<dp.size();i++){
		if(dp[i]<=k*1ll){
			mx = max(i,mx);
		}
	}
	cout << mx;


	
	return 0;
}

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

namespace {

int combination(int a, int b, int c, int d)
{
  // (a,a,a,a)
  if (a == d) {
    return 1;
  }
  // (a,a,a,d) or (a,b,b,b)
  else if (a == c || b == d) {
    return 4;
  }
  // (a,a,c,c)
  else if (a == b && c == d) {
    return 6;
  }
  // (a,a,c,d) or (a,b,b,d) or (a,b,c,c)
  else if (a == b || b == c || c == d) {
    return 12;
  }
  // (a,b,c,d)
  else {
    return 24;
  }
}

int calc(int n)
{
  int com = 0;
  int a, b, c, d;

  for (a = 0; a <= 9; ++a) {
    if (a > n) break;
    for (b = a; b <= 9; ++b) {
      if (a + b > n) break;
      for (c = b; c <= 9; ++c) {
        if (a + b + c > n) break;
        for (d = c; d <= 9; ++d) {
          const int sum = a + b + c + d;
          if (sum == n) {
            com += combination(a, b, c, d);
          }
          else if (sum > n) {
            break;
          }
        }
      }
    }
  }

  return com;
}

} // unnamed namespace

int main()
{
  int n;
  while (std::cin >> n) {
    std::cout << calc(n) << std::endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main()
{
	long long int a, v, b, w, t;
	scanf("%lld%lld%lld%lld%lld", &a, &v, &b, &w, &t);
	b -= a;
	if (b < 0)
		b *= -1;
	if (v * t < b + w * t)
		printf("NO\n");
	else
		printf("YES\n");
	return 0;
}

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

using namespace std;

typedef long long int ll;
#define inf 0x3f3f3f3f
#define endl '\n'
// #define case(i) "Case #" << i << ": "

vector<int> v, dp;

int solve(int i) {
    if(i == 0) return 0;
    if(i == 1) return abs(v[1] - v[0]);
    else {
        if(dp[i-1] == -1) dp[i-1] = solve(i-1);
        if(dp[i-2] == -1) dp[i-2] = solve(i-2);
        return min(abs(v[i] - v[i-1]) + dp[i-1], abs(v[i] - v[i-2]) + dp[i-2]);
    }
}

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

    int n;
    cin >> n;
    v.resize(n);
    dp.resize(n, -1);

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

    cout << solve(n-1) << endl;
}

Measured memory_bytes: 5760