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

using namespace std;

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

#ifdef LUCARIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif

typedef int intt;
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;

#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define int long long
#define pb push_back
#define bs binary_search
#define up upper_bound
#define fs first 
#define sd second 
#define mp make_pair    
#define endl "\n"

#define fore(i,a,b) for(ll i = a; i < b; i++)
#define rfore(i, a, b) for(ll i = a - 1; i >= b; i--)
#define forev(a,b) fore(i,0,b)cout<<a[i]<<" "; 
#define ing(g,u,v)  g[u].pb(v); g[v].pb(u);
#define ingp(g,u,v,c) (g[u].pb({v,c});g[v].pb({u,c});)
#define mm(a,b) memset(a , b , sizeof a) 
#define ALL(a) a.begin(),a.end() 
#define SZ(n) ((ll) (n).size())
#define sfind(s,t) (s.find(t) != string::npos)

#define infll (ll)1e15
#define infi  (int)(1e9+1)
#define PI 3.14159265359 
#define mod (ll)(1e9+7)
#define eps  1e-6

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

int n;
vector<int> g[100001];
int dp[100001];

int solve(int i){
    if(~dp[i])return dp[i];
    int &r = dp[i];
    r =0;
    for(auto x : g[i]){
        r = max(r,1+solve(x));
    }

    return r;
}


int32_t main(int32_t argc, char const *argv[]){
    FIN;
    mm(dp,-1);
    int m;
    cin>>n>>m;

    fore(i,0,m){
        int u,v;cin>>u>>v;u--;v--;
        g[u].pb(v);
    }
    int r =0;
    fore(i,0,n){
        r = max(r,solve(i));
    }

    cout<<r;   

    return 0;
}



















Measured memory_bytes: 7936
#include<stdio.h>

int isPrime(int x){
  int i;
  if(x<2)return 0;
  else if(x==2)return 1;
  if(x%2==0)return 0;
  for(i=3; i*i<=x; i+=2){
    if(x%i==0)
      return 0;
  }
  return 1;
}

int main(){
  int n,x,i;
  int cnt =0;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&x);
    if(isPrime(x))
      cnt++;
  }
  printf("%d\n",cnt);

  return 0;
}



Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String s = sc.next();

			char[] cs = s.toCharArray();

			char before = '\0';
			for (char c : cs) {
				if(c == before) {
					System.out.println("Bad");
					return;
				}
				before = c;
			}
			System.out.println("Good");
		}
	}

}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a,one;
  cin>>n;
  cin>>a;
  one=n%500;
  if(one<=a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
const ld pi = acos(-1);
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll n, m; cin >> n >> m;
    VL a(n); cin >> a;
    SORT(a);
    VL r = a;
    reverse(all(r));
    FOR(i, 0, n - 1)r[i + 1] += r[i];

    auto check = [&](ll x) {
        ll ret = 0;
        FOR(i, 0, n)ret += a.end() - lower_bound(all(a), x - a[i]);
        return ret < m;
    };

    ll ok = LLINF, ng = 0;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        if (check(mid))ok = mid;
        else ng = mid;
    }

    ll ans = 0;
    FOR(i, 0, n) {
        ll num = a.end() - lower_bound(all(a), ok - a[i]);
        ans += a[i] * num;
        if (0 < num)ans += r[num - 1];
        m -= num;
    }
    ans += ng * m;

    cout << ans << "\n";

}


Measured memory_bytes: 1792
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;

bool heiho(long x){
	long a=(int)sqrt(x);
	if(a*a==x){
		return true;
	}else{
		return false;
	}
}

int main(){
	long n;
	cin >> n;
	for(long i=n;i>0;i--){
		if(heiho(i)==true){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void insertionSort(int *,int,int);
void shellSort(int *,int);

int m=1;
int cnt;
int G[100]={1};

int main(){
  int i,j,N,k;
  int A[1000000];

  scanf("%d",&N);

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  cnt=0;

  for(i=1,j=0;i<=N;i=i*3+1,j++){G[j]=i;}
  for(i=0;i*2<j;i++){
    k=G[j-i-1];
    G[j-i-1]=G[i];
    G[i]=k;
  }
  m=j;
  
  shellSort(A,N);

  printf("%d\n",m);
  for(i=0;i<m;i++){
    if(i)printf(" ");
    printf("%d",G[i]);
  }
  printf("\n");
  printf("%d\n",cnt);

  for(i=0;i<N;i++){
    printf("%d\n",A[i]);
  }

  return 0;
}

void insertionSort(int A[],int N,int g){
  int i,j,v;

  for(i=g;i<N;i++){
    v = A[i];
    j = i - g;

    while(j >= 0 && A[j] > v){
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
  }
}

void shellSort(int A[],int N){
  int i;

  for(i=0;i<m;i++)insertionSort(A,N,G[i]);
}




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

#define endl '\n'
#define LL long long
#define MP make_pair
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define FORR(i, a, b) for(int i = b - 1; i >= a; --i)
#define EB emplace_back
#define ST first
#define ND second
#define S size()
#define RS resize

using VI = vector<int>;
using VVI = vector<VI>;
using PI = pair<int, int>;
using VPI = vector<PI>;
using VVPI = vector<VPI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VB = vector<bool>;

int main()
{ 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<vector<double> > dp(n + 1);
    REP(i, n + 1)
        dp[i].RS(n + 1);
    vector<double> m(n + 1);
    REP(i, n)
        cin >> m[i + 1];
    dp[0][0] = 1;
    FOR(i, 1, n + 1)
    {
        dp[0][i] = 0;
        dp[i][0] = dp[i - 1][0] * (1 - m[i]);
    }
    FOR(i, 1, n + 1)
        FOR(j, 1, n + 1)
            dp[i][j] = dp[i - 1][j] * (1 - m[i]) + dp[i - 1][j - 1] * m[i];
    double suma = 0;
    FOR(i, n / 2 + 1, n + 1)
        suma += dp[n][i];
    cout << setprecision(10) << fixed;
    cout << suma;
}

Measured memory_bytes: 70656
n,m=map(int,input().split())

X=[]

for i in range(m):
    a=i
    b,c=map(int,input().split())
    X.append([a,b,c])

sort_X=sorted(X,key=lambda x:(x[1],x[2]))
sort_X[0].append(1)

for i in range(1,m):
    if sort_X[i][1]!=sort_X[i-1][1]:
        sort_X[i].append(1)
    else:
        sort_X[i].append(sort_X[i-1][3]+1)
   
X=sorted(sort_X,key=lambda x:x[0])
for i in range(m):
    count=X[i][3]
    first_num="000000"
    last_num="000000"
    
    
    first_num=first_num[:6-len(str(X[i][1]))]+str(X[i][1])
    last_num=last_num[:6-len(str(count))]+str(count)
    print(first_num+last_num)

Measured memory_bytes: 37156
#include <iostream>
using namespace std;
 
int main(){
    int ans=0;
    string s;
    string list[4] = {"dream", "dreamer", "erase", "eraser"};
    int len[4] = {5, 7, 5, 6};
    
    cin >> s;
 
    int max_iter = 200000;
 
    string pre_str = s;
    bool flag = false;
    bool flag2 = false;
    int ptr = 4;
 
    for(int i=0; i<max_iter; i++){
 
        flag = false;
 
        for(int j=0; j<4; j++){
 
            if(flag2){
                flag2 = false;
                if(ptr > 3){
                    break;
                }
                j = ptr;
            }
            
            if(s.compare(0,len[j],list[j]) == 0){
                pre_str = s;
                s.erase(0,len[j]);
                flag = true;
                ptr = j+1;
                break;
            }
        }
 
        if(s.compare("") == 0){
            cout << "YES" << endl;
            return 0;
        }
 
        if(s.compare(pre_str) == 0){
            cout << "NO" << endl;
            return 0;
        }
 
        if(flag == false){
            s = pre_str;
            flag2 = true;
            i -= 1;
        }
    }
 
    
    
    return 0;
}

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

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define REV(i,j,k) for(int i=j;i>=k;i--)
#define FORR(i,j,k,l) for(int i=j;i<=k;i+=l)
#define inf         freopen("in.txt", "r", stdin)
#define outf        freopen("out.txt", "w", stdout)
#define pf          printf
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c)    scanf("%d %d %d", &a, &b, &c)
#define clean(mat,n)   FOR(i,0,n) mat[i].clear()
#define minn          (long long)-1000000000000000000
#define maxx          (long long) 1000000000000000000
#define mod          1000000007
#define M_PI           3.14159265358979323846  /* pi */
#define LL           long long
#define NL '\n'
#define cnd tree[idx]
#define lnd (idx<<1)
#define rnd ((idx<<1)+1)
#define PB push_back
#define F first
#define S second
#define MAX 2000010
#define MP make_pair
#define valid(nx,ny)  ((nx >= 0) && (nx < row) && (ny >= 0) && (ny < col))
typedef pair<int,int> pr;

int cnt[MAX];
int ar[MAX];

int main()
{
    ios::sync_with_stdio(false);
    //inf;
    //outf;
    int i,j,n,m=0,c=0,k,a;

    cin>>n>>k;
    FOR(i,0,n-1) cin>>a, cnt[a]++;

    FOR(i,1,n)
    {
       /// cout<<cnt[i]<<NL;
        if(cnt[i])
        {
            ar[m++]=cnt[i];
        }
    }
    sort(ar,ar+m);
   /// cout<<m<<NL;
    i=0;
    while(k<m)
    {
       c+=ar[i];
       i++;
       m--;
    }

    cout<<c<<NL;
    return 0;
}




Measured memory_bytes: 5120
s = input()
q = int(input())

for i in range(q):
    inp = input().split()
    com = inp[0]
    a = int(inp[1])
    b = int(inp[2])+1
    if com =="print":
        print(s[a:b])
    elif com =="reverse":
        s_rev = s[a:b]
        s = s[:a] + s_rev[::-1] + s[b:]
    elif com =="replace":
        s = s[:a] + inp[3] + s[b:]

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  ll n;
  cin >> n;
  ll k = n - 1;
  ll d = 26;
  vector<ll> v;
  while(true) {
    //cout << k << ":" << k%d<< endl;
    v.push_back(k % d);
    if (k / d > 0) {
      k -= k%d;
      k /= d;
      k--;
    } else {
      break;
    }
  }
  rev(v);
  for(ll i = 0; i < v.size(); ++i) {
      cout << char(int (v[i]) + 'a');
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3624
#高橋君は金色の硬貨が好きです。自分が持っている 
#500 円硬貨 1 枚につき 1000、5 円硬貨 1 枚につき 5の 嬉しさ を得ます。
#高橋君は X円を持っています。適切に両替したとき、嬉しさは最大でいくらになりますか？
#(なお、利用できる硬貨は 500円玉、100 円玉、50 円玉、10 円玉、5 円玉、1 円玉の 6 種類とします。)
#500:2
#5:1
a=int(input())
b=a//500
a=a-b*500
if a>0:
  c=a//5
else:
  c=0
print(1000*b+5*c)

Measured memory_bytes: 2940
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')
# ----------------------------------------------------------- #

s = S()
y = int(s[:4])
m = int(s[5:7])
d = int(s[8:])
if y < 2019 or (y == 2019 and m < 5):
    print("Heisei")
else:
    print("TBD")

Measured memory_bytes: 63852
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

LL N, K, S;

int main() {
	cin >> N >> K >> S;
	vector<LL>ans;
	LL oath = S == 1000000000 ? 999999999 : 1000000000;
	for (int i = 0; i < K; ++i) {
		ans.push_back(S);
	}
	for (int i = 0; i < N - K; ++i) {
		ans.push_back(oath);
	}
	for (int i = 0; i < N; ++i) {
		cout << ans[i] << " \n"[i == N - 1];
	}
	return 0;
}

Measured memory_bytes: 2164
#include<cstdio>;
//入出力を行う関数が使える(scanf,printf)//
#include<cstring>;
//char型の配列で構成された文字列を操作するための様々な関数が使える//

int main(){
    char str[1001];
    
    while(true){
        scanf("%s",str);
        if (str[0]=='0') break;
        int sum = 0;
        //sumの初期化//
        for (int i=0; i<strlen(str); i++){
            //文字列strの長さを返す//
            sum += (str[i]-'0');
            //0の文字コードを引いている（0=48になっている)//
        }
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

ll mod_div(ll a,ll b){
  ll tmp=MOD-2,c=b,ret=1;
  while(tmp>0){
    if(tmp&1){
      ret*=c;ret%=MOD;
    }
    c*=c;c%=MOD;tmp>>=1;
  }
  return a*ret%MOD;
}
 
#define MAX_K 200100
vector<ll> kaijo(MAX_K);
ll combination(ll n, ll r){
  if(n<r||n<0||r<0)
    return 0;
  if(kaijo[0]!=1){
    kaijo[0]=1;
    for(ll i=1;i<MAX_K;i++)kaijo[i]=(kaijo[i-1]*i)%MOD;
  }
  ll ret=kaijo[n];
  long long tmp = (kaijo[r] * kaijo[n-r]) % MOD;
  return mod_div(ret,tmp);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n+1);
  ll cnt[111111]={};
  for(auto &a:A){
    cin>>a;
    cnt[a]++;
  }
  ll dist;
  for(int i=0;i<111111;i++){
    if(cnt[i]==2){
      ll po=-1;
      for(int j=0;j<n+1;j++){
	if(A[j]==i){
	  if(po<0)po=j;
	  else{
	    dist=n+1-(j-po);
	    break;
	  }
	}
      }
      break;
    }
  }
  dist--;
  for(int i=0;i<n+1;i++){
    cout<<(combination(n+1,i+1)-combination(dist,i)+MOD)%MOD<<endl;
  }
  return 0;
}
  


Measured memory_bytes: 4480
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n;
	cin >> n;

	ll cnt = 0;
	map<ll,ll> mp;
	mp[0] = 1;
	ll sum = 0;
	for(int i = 0;i < n;i++){
		ll a;
		cin >> a;
		sum += a;
		cnt += mp[sum];
		mp[sum]++;
	}

	cout << cnt << endl;
}


Measured memory_bytes: 15992
import java.io.*;
import java.util.*;

class Main {

  public static void main(String[] args) {
  
  	try {
    
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      String strLine = br.readLine();
      String[] nwInput = strLine.split(" ");
      int n = Integer.parseInt(nwInput[0]);
      int W = Integer.parseInt(nwInput[1]);
      int[][] wv = new int[n][2];
      int vsum = 0;
      for(int i = 0 ; i < n ; i++) {
      	strLine = br.readLine();
        wv[i][0] = Integer.parseInt(strLine.split(" ")[0]);
        wv[i][1] = Integer.parseInt(strLine.split(" ")[1]);
        vsum += wv[i][1];
      }
      long[] dp = new long[vsum+1];
      for(int i = 0 ; i <= vsum ; i++) {
      	dp[i] = Integer.MAX_VALUE;
      }
      dp[0] = 0;
      for(int i = 1 ; i <= n; i++) {
        int w = wv[i-1][0];
        int v = wv[i-1][1];
        for(int j = vsum ; j >= v ; j--) {
          	dp[j] = Math.min(dp[j], dp[j-v] + w);
        }
      }
      long maxValue = Integer.MIN_VALUE;
      for(int i = vsum ; i >= 0 ; i--) {
        if(dp[i] <= W) {
        	System.out.println(i);
            break;
        }
      }
      
    } catch(Exception ex) {
    
    }
  }
}

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

int main(){
    while(1){
        int n,q; cin>>n>>q;
        if(n == 0 && q == 0) break;
        vector<int> day(101,0);
        for(int i=0; i<n; i++){
            int k; cin>>k;
            for(int j=0; j<k; j++){
                int d;  cin>>d;
                day[d]++;
            }
        }

        int ans=0,lim=0;

        for(int i=0; i<101; i++){
            if(day[i] > lim){
                ans = i+1;
                lim = day[i];
                if(q > lim) ans = 0;
            }

            if(day[i] == lim){
                ans = min(ans,i);
                if(q > lim) ans = 0;
            }
        }

        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3084
def selectionSort(a):
    count = 0
    for i in range(len(a)):
        mini = i
        for j in range(i,len(a)):
            if a[j] < a[mini]:
                mini = j
        if i != mini:
            ret = a[i]
            a[i] = a[mini]
            a[mini] = ret
            count += 1
    print(" ".join(map(str,a)))
    print(count)
n = int(input())
a = list(map(int,input().split()))
selectionSort(a)

Measured memory_bytes: 7788
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int a[100002];
int main(){
        int N,L;
	cin>>N>>L;
	REP(i,N){
            cin>>a[i];
	}
        int ans=-1;
        REP(i,N-1){
            if(a[i]+a[i+1]>=L){
               ans=i+1;
               break;
            }
        }
        if(ans==-1){
           cout<<"Impossible"<<endl;
        }else{
           cout<<"Possible"<<endl;
           for(int i=1;i<ans;i++){
               cout<<i<<endl;
           }
           for(int i=N-1;i>ans;i--){
               cout<<i<<endl;
           }
           cout<<ans<<endl;
        }
	return(0);
}

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int main(){
	int h, w;
	cin >> h >> w;
	while (h != 0){
		int i, j;
		for (i = 0; i < h; i++){
			for (j = 0; j < w; j++){
				cout << "#";
			}
			cout << endl;
		}
			cout << endl;
			cin >> h >> w;
		}
	return 0;
}


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

#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	int n = in();
	vi a;
	rep(i, n) a.pb(in());

	sort(all(a));

	if (a.rbegin()[0] - a[0] > 1) {
		cout << "No" << endl;
	}

	else if (a.rbegin()[0] - a[0] == 0) {
		cout << (a[0] == n - 1 || a[0] * 2 <= n ? "Yes" : "No") << endl;
	}
	else {
		int cnt = 0;
		rep(i, n) {
			if (a[i] == a[0]) cnt++;
		}

		int g = a[0] - cnt + 1;
		cout <<  (g > 0 && 2 * g <= (n - cnt) ? "Yes" : "No") << endl;
	}
}



Measured memory_bytes: 1020
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,W;
LL w[100],v[100];

LL ans = 0;

void solve(){
	//前からi個見た時、
	//とった物の総重量がjのときの
	//最大の総価値をdp[i][j]とおく
	vector<map<LL,LL>> dp(N+1);
	//i個目の物について見ていく
	//ばらまくDP
	for(int i=0;i<N;i++){
		dp[i][0] = 0;
		for(auto iter=dp[i].begin();iter!=dp[i].end();iter++){
			LL j = iter->first;
			//i個目をとるとき
			if(j+w[i]<=W) dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]],dp[i][j]+v[i]);
			//i個目を取らないとき
			dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
		}
	}
	// for(int i=0;i<=N;i++){
	// 	for(auto iter=dp[i].begin();iter!=dp[i].end();iter++){
	// 		printf("dp[%d][%lld]=%lld,",i,iter->first,iter->second);
	// 	}
	// 	cout << endl;
	// }
	for(auto iter=dp[N].begin();iter!=dp[N].end();iter++){
		ans = max(ans,iter->second);
	}
}
 
int main(){
    cin >> N >> W;
    for(int i=0;i<N;i++){
    	cin >> w[i];
    	cin >> v[i];
    }
 
    solve();

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

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

int main() { 
    long long n;
    cin >> n;
    long long A, B, out=1000000000000000, tmp=0,d_A=0, d_B=0;
    for (long long i = 1; i*i<=n; i++) {
      A = i;
      B = n / A;
      if (n != A * B) continue;
      string A_t = to_string(A);
      string B_t = to_string(B);
      d_A = A_t.length();
      d_B = B_t.length();
      tmp = max(d_A, d_B);
      out = min(out, tmp);
    }
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 3692
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,x,y] <- getIntList
    let d i j = minimum [abs (j-i), abs (x-i) + abs (j-y) + 1, abs (y-i) + abs (j-x) + 1]
    VU.mapM_ print $ VU.accum (+) (VU.replicate (n-1) (0 :: Int)) [(d i j - 1, 1) | i <- [1..n-1], j <- [i+1..n]]

Measured memory_bytes: 2428
# AC by Pypy3, not Python3

import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = tuple(map(int, input().split()))

dp = [0] + [float("inf")] * (n-1)
#print(dp)

for i in range(1,n):
    K = max(0, i - k) # K: 'i' ループ目の最大ジャンプ幅 'k' 
    H = h[i]          # H: 'i' ループ目の足場の高さ'h'
    for j in range(K, i):
        dp[i] = min(dp[i], dp[j]+abs(H - h[j]))
#print(dp)

print(dp[-1])

Measured memory_bytes: 58588
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a+b==15)
    cout<<"+"<<endl;
  else if(a*b==15)
    cout<<"*"<<endl;
  else
    cout<<"x"<<endl;
  return(0);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a[30];

	for (int i = 0; i < 30; i++){
		a[i] = 0;
	}
	for (int k = 0; k < 28; k++){
		int b = 0;
		scanf("%d", &b);
		a[b - 1] = 1;
	}
	int aa = 0;
	int bb = 0;
	for (int i = 0; i < 30; i++){
		if (a[i] == 0){
			if (aa == 0){
				aa = i + 1;
			}
			else{ bb = i + 1;
			}if (aa > bb){
				int s;
				s = aa;
				aa = bb;
				bb = s;
			}
		}
	}
	printf("%d\n", aa);
	printf("%d\n", bb);
	return 0;
}

Measured memory_bytes: 2732
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

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




const int mod = 1e9 + 7;



int main(void){
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    rep(i,n) cin >> s[i] >> t[i];
    string x;
    cin >> x;
    bool flag = false;
    int ans = 0;
    rep(i,n){
      if(flag) ans += t[i];
      if(s[i] == x) flag = true;
    }
    print(ans);
}

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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/
int64_t INF = 1000000000000000000;
int main(){
  string s,t;
  cin >> s >> t;
  string ss = s + s;
  vector<vector<int64_t>> ch(26);
  rep(i,ss.size()){
    ch.at(ss.at(i) - 'a').push_back(i);
  }
  vector<vector<int64_t>> CH(26,vector<int64_t>(s.size(),-1));
  rep(i,26){
    rep(j,s.size()){
      auto itr = lower_bound(ch.at(i).begin(),ch.at(i).end(),j);
      if(itr != ch.at(i).end()){
        CH.at(i).at(j) = *itr;
      }
    }
  }
 /*rep(i,26){
   rep(j,s.size()){
     if(CH.at(i).at(j) != -1){
       cout << CH.at(i).at(j);
     }else{
       cout << "D/";
     }
   }
   cout << endl;
 }*/
  int64_t benow = 0;
  int64_t result = 0;
  bool failure = false;
  rep(i,t.size()){
    //cout << benow << "->";
    if(CH.at(t.at(i)-'a').at(benow) != -1){
      result += CH.at(t.at(i)-'a').at(benow)+1 - benow;
      benow = (CH.at(t.at(i)-'a').at(benow) + 1)% s.size();
    }else{
      failure = true;
      break;
    }
    //cout << benow << endl;
  }
  if(!failure){
    cout << result << endl;
  }else{
    cout << -1 << endl;
  }
    
  
   
  
      
      
    
  
  
      
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;

ll mpow(ll x, ll n, ll m){
  if(m<=0){ return 0;}
  ll r = 1;
  while(n>0){
    if(n&1){ r = r*x%m; }
    x = x*x%m;
    n >>= 1;
  }
  return r;
}

int popcount(ll n){
  n =(n&0x55555555)+(n>>1&0x55555555);
  n =(n&0x33333333)+(n>>2&0x33333333);
  n =(n&0x0f0f0f0f)+(n>>4&0x0f0f0f0f);
  n =(n&0x00ff00ff)+(n>>8&0x00ff00ff);
  n =(n&0x0000ffff)+(n>>16&0x0000ffff);
  return n;
}

int func(ll n){
  if(n==0){ return 0;}
  else{ return func(n%popcount(n))+1; }
}


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

  ll p = count(ALL(s),'1');
  ll x1 = 0; //必要な値を前処理
  ll x2 = 0;
  REP(i,N){
    char c = s[i];
    if(c=='1'){
      if(p==1){
        x1 = 0;
      }else{
        x1 += mpow(2,N-i-1,p-1);
        x1 %= (p-1);
      }
      x2 += mpow(2,N-i-1,p+1);
      x2 %= (p+1);
    }
  }
  REP(i,N){
    char c = s[i];
    ll ans;
    if(c=='1'){ //前処理の値を使ってステップ1用の値を作り計算
      if(p==1){
        ans = 0;
      }else{
        ans = 1 + func( (x1-mpow(2,N-i-1,p-1)+p-1)%(p-1) );
      }
    }else{
      ans = 1 + func(  (x2+mpow(2,N-i-1,p+1))%(p+1) );
    }
    cout << ans << "\n";
  }
  
}

Measured memory_bytes: 3724
#include <iostream>

using namespace std;

int main(void){

  int n,q;
  while(cin >> n >> q , n + q){

    int dn, day[101] = {0};
    while(n--){
      cin >> dn;
      for(int i = 0 ; i < dn ; i++){
	int a;
	cin >> a;
	day[a]++; 
      }
    }
    int ans = 0, ANS = 0;
    for(int i = 1 ; i <= 100 ; i++){
      if(day[i] >= q && ANS < day[i]){
	ans = i;
	ANS = day[i];
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
from collections import Counter

N = int(input())
As = list(map(int, input().split()))

cnt = Counter(As)
As.sort(reverse=True)

Ps = [2]
for i in range(29):
    Ps.append(Ps[-1] * 2)

ans = 0
for A in As:
    if cnt[A] <= 0: continue
    cnt[A] -= 1

    while Ps[-1] > 2 * A:
        Ps.pop()

    if cnt[Ps[-1] - A] > 0:
        ans += 1
        cnt[Ps[-1] - A] -= 1

print(ans)


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

int main() {
    int n; cin >> n;
    vector<long long> a(n+1, 0), b(n+1, 0);
    for (int i = 0; i < n; i++) {
        int c; cin >> c;
        a[i+1] = a[i] ^ c;
        b[i+1] = b[i] + c;
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        int left = i; int right = n;
        while (right - left > 1) {
            int mid = (left + right) / 2;
            if ((a[mid+1]^a[i]) == (b[mid+1]-b[i])) left = mid;
            else right = mid;
        }
        ans += left - i + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9+7;



int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,m;
	cin>>n>>m;
	int score = 0, ss = 0;
	vector<int> a(n+1,0);
	vector<int> pen(n+1,0);
	for(int i=1;i<=m;i++){
		int x;
		string s;
		cin>>x>>s;
		if(a[x]) continue;
		if(s == "WA") pen[x]++;
		else {
			a[x] = 1;
			score++;
			ss += pen[x];
		}
	}
	cout<<score<<" "<<ss;
	
	
	
	
	return 0;
}
	
	
	
	
	
	
	
	
	
	
	

























Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define GRAYCODE(i) ((i) ^ ((i) >> 1))

using ll = long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;

const int MOD = 1000000007;
const int INF = 1000000000;

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




int main(){
    int n, maxv = 0; cin >> n;
    VI A(n), B(n);
    REP(i, n){
        cin >> A[i]; chmax(maxv, A[i]);
    }
    VI C(maxv+1);
    REP(i, n) ++C[A[i]];
    FORS(i, 1, maxv) C[i] += C[i-1];
    RREP(i, n-1){
        B[C[A[i]]-1] = A[i];
        --C[A[i]];
    }
    REP(i, n){
        if(i) cout << " ";
        cout << B[i];
    }
    cout << "\n";
    return 0;
}


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

using namespace std;

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

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

int n, A;
int a[51];
long long ways[51][11000];

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

    REP(i,n) {
        scanf("%d", &a[i]); 
        a[i]-=A;
    }   

    ways[0][5000] = 1;
    for (int i = 0; i < n; i++) {
        for (int w = -2500; w <= 2500; w++) {
            ways[i+1][w+5000] += ways[i][w+5000];
            ways[i+1][w + 5000] += ways[i][w+5000 - a[i]];
        }
    }

    printf("%lld\n", ways[n][5000]-1);
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n,m;
  cin >> n >> m;
  unordered_map<int, int> ac;
  unordered_map<int, int> penalty;
  
  int p;
  string s;
  
  for(int i=0;i<m;i++){
    cin >> p >> s;
    if(s=="AC"){
      ac[p] = 1;
    }
    else{ // s=="WA"
      if(ac.count(p)==0){
        penalty[p]++;
      }
    }
  }
  
  int numAc = 0;
  for(auto a:ac){
    numAc++;
  }

  int numPenalty = 0;
  for(auto p:penalty){
    if(ac.count(p.first)!=0) numPenalty += p.second;
  }
  
  cout << numAc << " " << numPenalty << endl;
  
  return 0;
}




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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  string str; cin >> str;
  set<int> s = {'A', 'C', 'G', 'T'};
  int ans = 0, cnt = 0;
  for (auto &i : str) {
    if (s.count(i)) cnt++; else cnt = 0;
    ans = max(ans, cnt);
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

vector<pair<ll, ll> > prime; 

void prime_fuct(ll x){
    for (ll i = 2; i * i <= x; i++){
        if(x % i == 0){
            pair<ll, ll> p = make_pair(i, 0);
            while (x % i == 0){
                x /= i;
                p.second++;
            }
            prime.push_back(p);
        }
    }
    if(x > 1){
        pair<ll, ll> p = make_pair(x, 1);
        prime.push_back(p);
    }
}

ll gcd(ll  x, ll y){
    if(y == 0) return x;
    else  return gcd(y, x % y);
}




int main(){
    ll a, b;
    cin >> a >> b;
    ll n = gcd(a, b);
    prime_fuct(n);
    ll ans = (ll)prime.size() + 1;
    cout << ans << endl;
}

Measured memory_bytes: 3620
N=int(input())

A=list(map(int, input().split()))
B=list(map(int, input().split()))
ans=0
for i in range(N):
    ans+=min(A[i], B[i])
    nex=max(B[i]-A[i],0)
    ans+=min(nex, A[i+1])
    A[i+1]=max(A[i+1]-nex,0)

print(ans)

Measured memory_bytes: 18476
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数
static FILE *szpFpI;											// 入力

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// 次の値 - 取得
long long
fGetNext(
	long long plNow				// <I> 現在値
	, long long plPos			// <I> 位置
	, int *pipCnt				// <IO> 数字数
)
{
	// 対象値・対象外値
	long long llValT = plNow / plPos;
	long long llValU = llValT / 10;
	llValT %= 10;
	long long llValD = plNow % plPos;

	// 下１桁をチェック
	switch (llValT) {
	case 0:
		pipCnt[0]++;
		return (llValU * 10 + 3) * plPos + llValD;

	case 3:
		pipCnt[0]--;
		pipCnt[1]++;
		return (llValU * 10 + 5) * plPos + llValD;

	case 5:
		pipCnt[1]--;
		pipCnt[2]++;
		return (llValU * 10 + 7) * plPos + llValD;

	case 7:
		pipCnt[2]--;
		pipCnt[0]++;
		return fGetNext((llValU * 10 + 3) * plPos + llValD, plPos * 10, pipCnt);
	}

	return -1;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 上限 - 取得
	long long llLimit;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%lld", &llLimit);

	// 個数 - 取得
	int liCnt = 0;
	long long llNow = 0;
	int li1Cnt[3];
	memset(li1Cnt, 0, sizeof(li1Cnt));
	while (1) {

		// 次の値 - 取得
		llNow = fGetNext(llNow, 1, li1Cnt);
		if (llNow > llLimit) {
			break;
		}

		// 対象チェック
		for (i = 0; i < 3; i++) {
			if (li1Cnt[i] < 1) {
				break;
			}
		}
		if (i == 3) {
			liCnt++;
		}
	}

	// 結果 - セット
	sprintf(lc1Out, "%d\n", liCnt);

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

int main()
{
    ll n;
    cin >> n;
    int k = (ll)sqrt(2 * n);
    while ((ll)k * (k + 1) / 2 < n) k++;
    while (n > 0)
    {
        printf("%lld\n", min((ll)k, n));
        n -= min(n, (ll)k);
        k--;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define INF 100000000

int n;
int size[100];
int to[100][100];
int cost[100][100];
int dist[100];

void dfs(int p, int c){
  int i;
  dist[p] = c;
  for(i=0;i<size[p];i++){
    if(dist[to[p][i]] > c + cost[p][i]) dfs(to[p][i], c + cost[p][i]);
  }
}

main(){
  int i, j;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    int u;
    scanf("%d", &u);
    scanf("%d", &size[u]);
    for(j=0;j<size[u];j++){
      scanf("%d", &to[u][j]);
      scanf("%d", &cost[u][j]);
    }
  }
  for(i=0;i<n;i++) dist[i] = INF;
  dfs(0, 0);
  for(i=0;i<n;i++){
    printf("%d %d\n", i, dist[i]);
  }
  return 0;
}

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

int main(void)
{
	int i, j;
	int a, flag;
	char in[100];
	
	while (scanf("%d", &a) != EOF){
		
		i = 0;
		
		memset(in, '\0', sizeof(a));
		
		while (a != 0){
			in[i] = a % 2 + '0';
			a /= 2;
			i++;
		}
		in[i] = '\0';
		
		i = flag = 0;
		j = 1;
		while (in[i] != '\0'){
			if (flag != 0 && in[i] == '1') printf(" ");
			if (in[i] == '1'){
				printf("%d", j);
				flag = 1;
			}
			i++;
			j *= 2;
		}
		printf("\n");
	}
	return (0);
	
}

Measured memory_bytes: 0
n = int(input())

dp = [[0] * 3 for _ in range(n)]

for i in range(n):
    a = list(map(int, input().split()))
    if i == 0:
        dp[i] = a
    else:
        for j in range(3):
            for k in range(3):
                if k != j:
                    dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[j])

print(max(dp[n - 1]))

Measured memory_bytes: 22832
#include<stdio.h>
int pace[500010],low[500010],at[500010];
int abs(int x){return x>0?x:-x;}
int min(int a,int b){return a<b?a:b;}
int main(){
	int n,m,i;
	scanf("%d%d",&n,at);
	for(i=1;i<=n;i++){
		scanf("%d",pace+i);
		at[i]=min(at[i-1],abs(at[i-1]-pace[i]));
	}
	low[n+1]=1;
	for(i=n;i>0;i--){
		low[i]=low[i+1];
		if(pace[i]<(low[i]<<1))low[i]+=pace[i];
	}
	scanf("%d",&m);
	while(m--){
		scanf("%d",&i);
		puts(at[i-1]>=low[i+1]?"YES":"NO");
	}
}

Measured memory_bytes: 7680
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main() {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long a, b, c, d; cin >> a >> b >> c >> d;

    cout << max({a * c, a * d, b * c, b * d});

    return 0;
}


Measured memory_bytes: 3652