akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;

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

  int A[3][3];
  bool C[3][3]{};
  rep(i,3){
    rep(j,3){
      cin >> A[i][j];
    }
  }
  int N;
  cin >> N;
  int B[N];
  rep(k,N){
    cin >> B[k];
    rep(i, 3){
      rep(j, 3){
        if(A[i][j] == B[k]){
          C[i][j] = true;
        }
      }
    }
  }
  bool ans{};
  rep(i,3){
    if(C[i][0] && C[i][1] && C[i][2]){
      ans = true;
    }
  }
  rep(i,3){
    if(C[0][i] && C[1][i] && C[2][i]){
      ans = true;
    }
  }
  if(C[0][0] && C[1][1] && C[2][2]){
    ans = true;
  }
  if(C[0][2] && C[1][1] && C[2][0]){
    ans = true;
  }

  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;

}

Measured memory_bytes: 256
n,q=map(int,input().split())
s=[0]*-~n
w=m=0
for _ in[0]*q:
 a,v=map(int,input().split())
 s[a]+=v
 if v<0 and a==w:m=max(s);w=s.index(m)
 elif s[a]>m:w,m=a,s[a]
 elif s[a]==m and a<w:w=a
 print(w,m)


Measured memory_bytes: 13956
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

double a, b, x;

int main()
{
    cin >> a;
    cin >> b;
    cin >> x;
    
    double res;
    double v = a * a * b / 2;
    if (v < x){
        x = 2 * v - x;
        res = atan(2 * x / pow(a, 3)) * 180 / 3.14159265359;
    }
    else{
        // res = asin(a / (pow(4 * x * x / (a*a*b*b) + b*b, 0.5))) * 180 / 3.14159265359;
        res = 90 - atan(2 * x / (a * b * b)) * 180 / 3.14159265359;
    }
    cout <<setprecision(15)<<res;
}

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

int main(){
  int a,b,c,d,ans=0;cin>>a>>b>>c>>d;
  bool f=0;
  while(a>0&&c>0){
    c-=b;
    a-=d;
  }
  if(c<=0) f=1;

  cout<<(f?"Yes":"No");
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;


int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> v(n+2); // 0 v[1] v[2] ... v[n] 0
    vector<int> d(n+1); // v[i] - v[i-1]
    int dsum = 0;
    REP(i,n) {
        cin >> v[i+1];
        d[i] += abs(v[i+1] - v[i]); 
        dsum += d[i];
    }
    d[n] = abs(v[n+1] - v[n]);
    dsum += d[n];



    REP(i,n) {
        cout << dsum - (d[i] + d[i+1]) + abs(v[i+2] - v[i]) << '\n';
    }
    
    return 0;
}

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

using namespace std;

const int N = 1e5 + 100, MODD = 1e9 + 7;

vector <int> g[N];

bool mark[N];

long long dp[N][3];

void DFS(int x) {
	mark[x] = 1;
	dp[x][0] = dp[x][1] = 1;
	for (int e: g[x]) {
		if (!mark[e]) {
			DFS(e);
			dp[x][0] *= dp[e][2];
			dp[x][0] %= MODD;
			dp[x][1] *= dp[e][0];
			dp[x][1] %= MODD;
		}
	}
	dp[x][2] = dp[x][0] + dp[x][1];
	dp[x][2] %= MODD;
}

int main() {
	int n;
	cin >> n;
	for (int i = 1; i < n; ++i) {
		int u, v;
		cin >> u >> v;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	DFS(1);
	cout << dp[1][2] << '\n';
}


Measured memory_bytes: 12288
/*
    talk is cheap
    feelings fade

    love is real
    but so is change
*/

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

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    //int t=1 ; cin>>t ; while(t--)
    {
        int n;
        cin >> n;

        int ans = 0;
        if(n % 2 == 0)
        {
            int x = 10;
            while(n >= x)
            {
                ans += n/x;
                x *= 5;
            }
        } 

        cout << ans << '\n';
        
    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	for (int i = a; i <= b; ++i) {
		if (i % k == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
	double a,b,r,f;
	long long int d;
	cin >> a >> b;
	d=(long long int)a/(long long int)b;
	r=(int)a%(int)b;
	f=a/b;
	cout << d << " " << r << " ";
	printf("%.5f\n",f);
	return 0; 
}

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

int main(){
    int n,l,ans=0;
    cin>>n>>l;
    if(l>=0){
        for(int i=2;i<=n;i++){
            ans+=l+i-1;
        }
    }
    else if(n+l>0){
        for(int i=1;i<=n;i++){
            ans+=l+i-1;
        }
    }
    else {
        for(int i=1;i<n;i++){
            ans+=l+i-1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int x,y,a,b,c;
  cin >> x >> y >> a >> b >> c;
  vector<pair<int,char>> f;
  char cc = 'a';
  for(int i=0;i<a+b+c;i++) {
    if (i == a) cc = 'b';
    if (i == a + b) cc = 'c';
    int e; cin >> e;
    f.push_back({e,cc});
  }
  sort(f.rbegin(),f.rend());
  long long ans = 0;
  vector<int> total;
  int n = x + y;
  for(int i=0;;i++) {
    if (f[i].second == 'a' && x > 0) {
      x--;
      total.push_back(f[i].first);
      ans += f[i].first;
    } else if (f[i].second == 'b' && y > 0) {
      y--;
      total.push_back(f[i].first);
      ans += f[i].first;
    } else if (f[i].second == 'c') {
      total.push_back(f[i].first);
      ans += f[i].first;
    }
    if (total.size() == n) break;
  }
  cout << ans << '\n';
  return 0;
}

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

void insertionSort(int a[],int n){
    for(int i=1;i<n;i++){
        int v=a[i];
        int j=i-1;
        while(j>=0&&a[j]>v){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
        for(int k=0;k<n;k++){
            cout<<a[k]<<((k==n-1)?'\n':' ');
        }
    }
}

int main(){
    int n,a[100];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        cout<<a[i]<<((i==n-1)?'\n':' ');
    }
    insertionSort(a,n);
}


Measured memory_bytes: 3072
N = input()


def f(d, used, next):
    num = len(used | set(next))
    if d == 0:
        if num == 3:
            return 1
        else:
            return 0
    elif num == 3:
        return 3 ** d
    elif num == 2:
        return 3 ** d - 2 ** d
    else:
        return 3 ** d - 2 * (2 ** d) + 1


def high(N, used, ret):
    if N:
        if N[0] > "3":
            ret += f(len(N) - 1, used, "3")
        if N[0] > "5":
            ret += f(len(N) - 1, used, "5")
        if N[0] > "7":
            ret += f(len(N) - 1, used, "7")
    else:
        if len(used) == 3:
            ret += 1
        return ret
    if N[0] in "357":
        ret = high(N[1:], used | set(N[0]), ret)
    return ret


def low():
    ret = 0
    for i in range(len(N) - 1):
        ret += 3 * (3 ** i - 2 ** (i + 1) + 1)
    return ret


def main():
    print(high(N, set(), low()))
    return


main()


Measured memory_bytes: 3064
#include "bits/stdc++.h"
#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##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T1, class T2>bool chmax(T1& a, const T2& b) { return a < b ? a = b, 1 : 0; }
template<class T1, class T2>bool chmin(T1& a, const T2& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) cin >> A[i];

    //vv<ll> dp = vvec(N + 1, 2, LINF);

    //int l = 0, h = N;
    //while (h - l > 1) {
    //    int mid = (l + h) / 2;

    //    rep(i, N + 1) dp[i][0] = dp[i][1] = LINF;

    //    




    //}

    //write(h);

    vll B = { A[0] };
    int ans = 1;

    rep(i, 1, N) {
        

        auto lb = lower_bound(B.rbegin(), B.rend(), A[i]);
        auto ub = upper_bound(B.rbegin(), B.rend(), A[i]);

        if (lb == B.rbegin()) {
            B.push_back(A[i]);

            ans++;
        }
        else {
            *(lb - 1) = A[i];
        }
    }

    write(ans);
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
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;}

int main(){
	string s,t;
	cin >> s >> t;
	vector<vector<int>> a(26);
	
	REP(i,s.size()){
		a[s[i]-'a'].push_back(i);
	}
	
	int count=0;
	int now=-1;
	REP(i,t.size()){
		int sz = a[t[i]-'a'].size();
		if(sz == 0){
			cout << -1 << endl;
			return 0;
		}
		
		int ok = sz;
		int ng = -1;
		while(ok-ng > 1){
			int mid = (ok+ng)/2;
			if(now < a[t[i]-'a'][mid]){
				ok = mid;
			}else{
				ng = mid;
			}
		}
		if(ok==sz){
			count++;
			now = a[t[i]-'a'][0];
		}else{
			now = a[t[i]-'a'][ok];
		}
		
	}
	
	
	cout << (ll)count*(ll)s.size() + (ll)(now+1) << endl;
	
	return 0;
}

Measured memory_bytes: 4208
def main():
    n = int(input())
    h = tuple(map(int, input().split()))
    cost = [0 for _ in range(n)]
    cost[0] = 0
    cost[1] = abs(h[1] - h[0])
    for i in range(2, n):
        cost[i] = min(cost[i-1]+abs(h[i] - h[i-1]), cost[i-2]+abs(h[i] - h[i-2]))
    print(cost[-1])
main()


Measured memory_bytes: 14104
#include<stdio.h>


int main()
{
	int n;
	scanf("%d",&n);
	if(n%10==3) printf("bon");
	else if((n%10==0)||(n%10==1)||(n%10==6)||(n%10==8)) printf("pon");
	else printf("hon");
	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int N;
	cin >> N;
	if (N / 10 == 9 || N % 10 == 9)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    
    d = {'xxxxxxxx': 0}
    for i in range(0, n):
        s = input().strip()
        if s in d.keys():
            d[s] += 1
        else:
            d[s] = 1
    
    m = int(input())
    
    for i in range(0, m):
        s = input().strip()
        if s in d.keys():
            d[s] -= 1
        else:
            d[s] = -1

    print(max(d.values()) )

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
	int A,B,C,coin=0;
	scanf("%d %d %d",&A,&B,&C);
	
	int day=0;
	int next = 0;
	while(1){
		day += (!next)?7:-1;
		coin = A * day + B * (day/7);
		
		if(C <= coin){
			next = 1;
			
		}else if(next){
				day++;
				break;
		}
		 
	}

	printf("%d\n",day);
	
}


Measured memory_bytes: 1976
#include<bits/stdc++.h>
using namespace std;
int n,m,a,b,blocks;
vector<int> toc;
vector< vector<int> > rd;
bool used[100009];
void DFS(int i){
	used[i]=1;
	for(int j=0;j<toc[i];j++){
		if(used[rd[i][j]])continue;
		DFS(rd[i][j]);
	}
}
int main(){
	cin>>n>>m;
	rd.resize(n);toc.resize(n);
	for(int i=0;i<m;i++){
		cin>>a>>b;
		rd[a-1].push_back(b-1);
		rd[b-1].push_back(a-1);
		toc[a-1]++;toc[b-1]++;
	}
	for(int i=0;i<n;i++){
		if(used[i])continue;
		blocks++;
		DFS(i);
	}
	cout<<blocks-1;
	return 0;
}

Measured memory_bytes: 10472
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int n;
string s;
vector<int> hv[2][2];
int ans[200005], cnt;

int main()
{
	cin >> n >> s;
	s = "1" + s + "1";
	rep(i, 2 * n) hv[s[i] - '0'][s[i + 1] - '0'].push_back(i);
	if(hv[1][1].size() % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	rep(i, hv[1][0].size()) ans[hv[1][0][i]] = ans[hv[0][1][i]] = cnt ++;
	rep(i, hv[0][0].size()) {
		ans[hv[0][0][i]] = cnt;
		if(i & 1) cnt ++;
	}
	if(hv[1][1].size() % 4 == 0) {
		rep(i, hv[1][1].size()) {
			ans[hv[1][1][i]] = cnt + (i & 1);
			if((i & 3) == 3) cnt += 2;
		}
		cout << "Yes" << endl;
		rep(i, 2 * n) cout << ans[i] + 1 << ' ';
		return 0;
	}
	int pos = -1;
	for(int i = 1; i < hv[1][0].size(); i ++) if(hv[0][1][i - 1] + 1 < hv[1][0][i]) {
		pos = i;
		break;
	}
	if(pos == -1 || hv[1][1][0] > hv[0][1][pos - 1] && hv[1][1][hv[1][1].size() - 1] < hv[1][0][pos]) {
		cout << "No" << endl;
		return 0;
	}
	swap(ans[hv[0][1][pos - 1]], ans[hv[0][1][pos]]);
	int ct = 0, tot = n;
	rep(i, hv[1][1].size()) {
		if(i + 1 < hv[1][1].size() && hv[1][1][i + 1] == hv[0][1][pos - 1] + 1 ||
		hv[1][1][0] == hv[0][1][pos - 1] + 1 && hv[1][1][i] == hv[1][0][pos] - 1) {
			ans[hv[1][1][i]] = ans[hv[1][1][i + 1]] = -- tot;
			i ++;
			continue;
		}
		ans[hv[1][1][i]] = cnt + (ct & 1);
		if((ct & 3) == 3) cnt += 2;
		ct ++;
	}
	cout << "Yes" << endl;
	rep(i, 2 * n) cout << ans[i] + 1 << ' ';
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int n;
    string s;
    in(n,s);
    //beforeには西を向いている人の人数，afterには東を向いている人の人数をいれる
    int before=0,after=0;
    rep(i,n){
        if(i==0)continue;
        if(s[i]=='E')after++;
    }
    int minv=after;
    for(int i=1;i<n;i++){
        if(s[i-1]=='W')before++;
        if(s[i]=='E')after--;
        minv=min(minv,before+after);
    }
    out(minv);
}


Measured memory_bytes: 3964
from collections import Counter

n = int(input())
s = list(str(input()))
ans = 0


for i in range(n):
    count = 0
    cnt1 = Counter(s[0:i])
    cnt2 = Counter(s[i:n])
    l = []
    for k, j in cnt1.items():
        l.append(k)
    for k, j in cnt2.items():
        l.append(k)
    cnt3 = Counter(l)
    
    for k, j in cnt3.items():
        if j == 2:
            count += 1
    ans = max(ans, count)

print(ans)

Measured memory_bytes: 3316
#include<iostream>

using namespace std;

int main() {
    while (1) {
        int r0, w0, c, r;

        cin >> r0 >> w0 >> c >> r;
        if (r0 == 0) break;

        // (r0 + x r) / w0 >= c
        // r0 + x r >= w0 c
        // x >= (w0 c - r0) / r
        if (r0 / w0 >= c) {
            cout << 0 << endl;
            continue;
        }

        cout << (w0 * c - r0 + r - 1) / r << endl;

    }
}

Measured memory_bytes: 3092
import java.io.*;

import java.util.StringTokenizer;

class Main {

    static void solve() throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        StringTokenizer st = new StringTokenizer(in.readLine());

        int na, nb, budget;

        na = Integer.parseInt(st.nextToken());
        nb = Integer.parseInt(st.nextToken());
        budget = Integer.parseInt(st.nextToken());

        long[] A = new long[na];
        long[] B = new long[nb];

        st = new StringTokenizer(in.readLine());
        for (int i = 0; i < na; i++) {
            A[i] = Long.parseLong(st.nextToken());
        }

        st = new StringTokenizer(in.readLine());
        for (int i = 0; i < nb; i++) {
            B[i] = Long.parseLong(st.nextToken());
        }

        long[] sa = sum(A);
        long[] sb = sum(B);
        int ans = find(sa, sb, budget);

        out.println(ans);
        out.close();

    }

    static long[] sum(long[] a) {
        int n = a.length;
        long[] s = new long[n+1];
        for (int i = 1; i <= n; i++) {
            s[i] = s[i-1] + a[i-1];
        }
        return s;
    }

    static int find(long[] sa, long[] sb, long budget) {
        int na = sa.length;
        int ans = 0;
        int j = sb.length - 1;
        for (int i = 0; i < na; i++) {
            if (sa[i] > budget) continue;
            while (j >= 0) {
                if (sa[i]+sb[j] > budget) {
                    --j;
                } else {
                    break;
                }
            }
            ans = Math.max(ans, i+j);
        }
        return ans;
    }

    public static void main(String[] args) throws IOException {
        solve();
    }
  
}

Measured memory_bytes: 63988
#!/usr/bin/env python3
import sys


def v(a: int, b: int, c: int):
    if a < b:
        a, b = b, a
    if c % a == 0:
        return c
    minr = c
    for va in range(c // a + 1):
        minr = min(minr, (c - va * a) % b)
        if minr == 0:
            break
    return c - minr


def solve(A: int, B: int, C: int, D: int, E: int, F: int):
    ansa = A * 100
    anss = 0
    for w in range(1, F // 100 + 1):
        w2 = v(B, A, w)
        if w != w2:
            continue
        s = min(w2 * E, F - w2 * 100)
        s2 = v(D, C, s)
        a2 = s2 + w2 * 100
        if a2 > F:
            continue
        # anss / ansa < s2 / a2
        if anss * a2 < ansa * s2:
            ansa, anss = a2, s2
    print(ansa, anss)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    E = int(next(tokens))  # type: int
    F = int(next(tokens))  # type: int
    solve(A, B, C, D, E, F)


if __name__ == '__main__':
    main()


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

int main()
{
	long long k;
	cin>>k;
    string s;
	cin>>s;
	if(s.size()>k) 
	{
      string s1(s,0,k);
		cout<<s1<<"...";
		}
	else
    {
      cout<<s;
    }
				return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-8;

struct state{
  double left,right,weight;
};

double r;
int n;
int w[6];

state merge(state a,state b){
  double sum=a.weight+b.weight;
  double aleft=a.left - b.weight/sum;
  double bleft=b.left + a.weight/sum;
  double left=min(aleft,bleft);
  double aright=a.right - b.weight/sum;
  double bright=b.right + a.weight/sum;
  double right=max(aright,bright);
  return (state){left,right,sum};
}

double calc(vector<state> u){
  vector<state> tmp=u;
  
  int t[6]={0,1,2,3,4,5};
  int a[6];
  double res=-1;
  
  do{
    u=tmp;
    
    for(int i=0;i<n-1;i++)a[i]=t[i];
    
    for(int i=0;i<n-1;i++){
      int c=0;
      for(int j=i+1;j<n-1;j++){
        if(a[i]<a[j])c++;
      }
      a[i]=c;
    }

    for(int i=0;i<n-1;i++){
      int id=a[i];
      u[id]=merge(u[id],u[id+1]);
      u.erase( u.begin() + id + 1);
    }
    double value=u[0].right-u[0].left;
    if( value < r + eps )      res=max(res,value);
    
  }while( next_permutation(t,t+n-1) );
  
  return res;
}

double solve(){
  int t[6]={0,1,2,3,4,5};
  double res=-1;
  
  do{
    vector< state > u(n);
    
    for(int i=0;i<n;i++){
      u[i]=(state){ 0.0, 0.0, (double)w[ t[i] ]};
    }


    res=max(res,calc(u));
    
  }while( next_permutation(t,t+n) );

  if(res < r + eps )return res;
  else return -1;
}

int main(){
  int Tc;
  cin>>Tc;
  while(Tc--){
    cin>>r;
    cin>>n;
    for(int i=0;i<n;i++)cin>>w[i];
    double ans=solve();
    if(ans<0){
      cout<<"-1"<<endl;
    }else{
      printf("%.10f\n",ans);
    }
  }
  return 0;
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define F  first
#define S  second
#define ff(i,n) for(i=0;i<n;i++)
ll bg = 10000020930000;
ll prime[1000002],is[1000002];
int main()
{ 
	ll t;
	t=1;
	while(t--)
	{
		ll i,j,n,n1=1000001;
		cin>>n;
		ll arr[n];
		ff(i,n)
		{
			cin>>arr[i];
			is[arr[i]]++;
		}
		for(i=1;i<=n1;i++)
		{
			if(is[i]>0)
			{
				if(is[i]!=1)
					prime[i]=1;
				for(j=2*i;j<=n1;j+=i)
					prime[j]=1;
			}
		}
		ll ans=0;
		ff(i,n)
		{
			if(prime[arr[i]]==0)
				ans++;
		}
		cout<<ans;
	}
	return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#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())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

//main code

int main(int argc, char const* argv[])
{
	string s;
	cin >> s;
	string t;
	for (int i = 0; i < s.size(); i++) {
		if (i+1 != s.size() and s[i] == 'B' and s[i+1] == 'C') {
			t.push_back('D');
			i++;
			continue;
		}
		t.push_back(s[i]);
	}
	LL ans = 0;
	int count = 0;
	for (int i = 0; i < t.size(); i++) {
		if (t[i] == 'A') {
			count++;
		}
		if (t[i] == 'B' or t[i] == 'C') {
			count = 0;
		}
		if (t[i] == 'D') {
			ans += count;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 916
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
const double eps=0.00000001;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}

vector<ll> pw2(51,1);vector<ll> pw10(19,1);
int main(){
    {rep1(i,50) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll A;
    double B;
    cin>>A>>B;
    ll B_100=(ll)(B*100+eps);
    cout<<(A*B_100)/100<<endl;
}



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


class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        long k=sc.nextLong();
        long[]w=new long[n],d=new long[n];
        for(int i=0;i<n;++i){
            w[i]=sc.nextLong();
            d[i]=sc.nextLong();
        }
        long pass=-1,fail=1L<<61;
        while(fail-pass>1){
            long x=(fail+pass)/2;
            long t=0;
            for(int i=0;i<n;++i){
                if(x>=w[i])
                    t+=(x-w[i])/d[i]+1;
            }
            if(t<k)pass=x;
            else fail=x;
        }
        out.println(fail);
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        int[] nextIntArray(int n){
            int[]r=new int[n];
            for(int i=0;i<n;++i)r[i]=nextInt();
            return r;
        }
    }
}


Measured memory_bytes: 45180
N=int(input())
L=[111,222,333,444,555,666,777,888,999]

for i in range(9):
    if(N>L[i] and N<=L[i+1]):
        print(L[i+1])
        break
    elif(N==L[i]):
        print(L[i])
        break
    elif(N<111):
        print(111)
        break
    else:
        continue


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main()
{
    long long int hp;
    int n , dmg_done = 0;
    cin >> hp >> n;
    int arr[n];
    for (int i = 0 ; i < n ; i++)
        cin >> arr[i];
    for (int i = 0 ; i < n ; i++)
        dmg_done += arr[i];
    if (dmg_done >= hp)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 640
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
h,w = readInts()
maze = [input() for _ in range(h)]
dxy = [(-1,0),(1,0),(0,1),(0,-1)]
flag = True
for y in range(h):
    for x in range(w):
        if maze[y][x] == '#':
            ok = False
            for dy,dx in dxy:
                ny = y + dy
                nx = x + dx
                if not(0 <= ny < h and 0 <= nx < w):
                    continue
                if maze[ny][nx] == '#':
                    ok = True
                    break
            if ok:
                flag = True
            else:
                flag = False
                break
    if not flag:
        break
if flag:
    print('Yes')
else:
    print('No')


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

int main(){
    long N, M;
    cin >> N >> M;
    vector<vector<long>> C({{1}});
    for(int i = 1; i <= 2000; ++i){
        C.emplace_back(i + 1, 1);
        for(int j = 1; j < i; ++j)C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % M;
    }
    vector<long> b(2001);
    b[0] = 0;
    for(int i = 1; i <= 2000; ++i){
        b[i] = b[i - 1] * 2 + 1;
        b[i] -= (b[i] > M) * M;
    }
    auto modpow = [&M](long a, long n){
        long ret = 1;
        while(n){
            if(n & 1){
                ret *= a;
                ret %= M;
            }
            a *= a;
            a %= M;
            n >>= 1;
        }
        return ret;
    };
    long ans(0);
    for(long A = 0; A < N; ++A){
        long tmp(0), B(N - A);
        for(long i = 0; i <= B; ++i){
            long t(C[B][i] * modpow(b[B - i], A) % M);
            tmp += (i & 1) ? M - t : t;
        }
        ans += (tmp % M) * C[N][A] % M * modpow(2, A * (A - 1) / 2 + B * (B - 1) / 2) % M;
    }
    cout << ans % M << endl;
    return 0;
}


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

namespace SandboxCSharp
{
    class Solver
    {
        private long Func(long a)
        {
            if (a == 0) return 0;
            return 1 + Func(a / 10);
        }

        public void Solve()
        {
            long n = io.ScanLong();
            long m = (long)(Math.Sqrt(n));

            long best = 99999999;

            for (long a = 1; a <= m; ++a)
            {
                if (n % a > 0) continue;
                long b = n / a;
                best = Math.Min(best, Math.Max(Func(a), Func(b)));
            }

            io.WriteLine(best);
        }

        // =================================================
        // =================================================

        Stdio io;
        bool isjdg;
        static void Main()
        {
            var s = new Solver();
            s.Solve();
            s.io.Flush();
        }
        public Solver(Stdio _io = null)
        {
            isjdg = _io == null;
            io = _io == null ? new Stdio() : _io;
        }

        void Exit()
        {
            if (isjdg)
            {
                io.Flush();
                Environment.Exit(0);
            }
            else
                throw new HaltException();
        }
    }
    class Stdio
    {
        protected string[] stack = new string[0];
        protected int stackptr = 0;
        protected StringBuilder outbuff = new StringBuilder();

        public virtual int ScanInt()
        {
            return Check() ? int.Parse(stack[stackptr++]) : 0;
        }
        public virtual long ScanLong()
        {
            return Check() ? long.Parse(stack[stackptr++]) : 0;
        }
        public virtual string ScanString()
        {
            return Check() ? stack[stackptr++] : string.Empty;
        }
        public virtual double ScanDouble()
        {
            return Check() ? double.Parse(stack[stackptr++]) : 0;
        }
        protected virtual bool Check()
        {
            if (stackptr < stack.Length) return true;
            var l = Console.ReadLine();
            if (l == null) return false;
            stack = l.Split(' ').ToArray(); stackptr = 0;
            return Check();
        }
        public Stdio Write(long v) { return Write($"{v}"); }
        public Stdio WriteLine(long v) { return WriteLine($"{v}"); }
        public Stdio Write(string str)
        {
            outbuff.Append(str);
            return this;
        }
        public Stdio WriteLine(string str = "")
        {
            outbuff.AppendLine(str);
            return this;
        }
        public virtual Stdio Flush()
        {
            Console.Write(outbuff.ToString());
            outbuff.Clear();
            return this;
        }
    }
    class HaltException : Exception { }

}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

int main(){
  ll N; cin >> N;

  bool flag = false;
  for (ll i = 1; i <= 3500; i++){
    for (ll j = i; j <= 3500; j++){
      if (4 * i * j - N * i - N * j > 0){
        if ((N * i * j) % (4 * i * j - N * i - N * j) == 0){
          cout << i << " " << j << " " << (N * i * j) / (4 * i * j - N * i - N * j) << endl;
          flag = true;
          break;
        }
      }
    }
    if (flag == true) break;
  }
  

  return 0;
}


Measured memory_bytes: 256
a,b,c,d = [int(x) for x in input().split()]
x = c-a
y = d-b

ans1=x*"R"+y*"U"
ans2=x*"L"+y*"D"
ans3="D"+(1+x)*"R"+(1+y)*"U"+"L"
ans4="U"+(1+x)*"L"+(1+y)*"D"+"R"


ans = ans1+ans2+ans3+ans4
print(ans)

Measured memory_bytes: 3060
#AGC018 A
import fractions

N,K = map(int,input().split())

A = list(map(int,input().split()))
MAX = max(A)

if K in A:
    print("POSSIBLE")
elif K<=MAX:
    GCD = A[0]
    for a in A[1:]: GCD = fractions.gcd(GCD,a)
    if K%GCD==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 16240
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
const input = fs.readFileSync('/dev/stdin', 'utf8').split('\n');
let h = +input[0];
let cnt = 0;
while (h > 0) {
    h = Math.floor(h / 2);
    cnt++;
}
console.log(Math.pow(2, cnt) - 1);


Measured memory_bytes: 7500
#include<bits/stdc++.h>
using namespace std;
bool sortByVal(const pair<string, int> &a, 
               const pair<string, int> &b) 
{ 
    return (a.second > b.second); 
} 
int main()
{
    int n;string x;
    cin>>n;
    vector<string> v;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        v.push_back(x);
    }
    sort(v.begin(), v.end()); 
     map<string,int> dup;
    for_each( v.begin(), v.end(), [&dup]( string val ){ dup[val]++; } );

    // for( auto p : dup ) {
    //     cout << p.first << ' ' << p.second << endl;
    // }
    
    vector<pair<string, int>> vec;
    vector<string> vec2;
    map<string, int> :: iterator it2;
  for (it2=dup.begin(); it2!=dup.end(); it2++) 
  {
    vec.push_back(make_pair(it2->first, it2->second));
  }
  sort(vec.begin(), vec.end(), sortByVal); 
  int s=vec[0].second;
  for (int i = 0; i < vec.size(); i++)
	{
	    if(vec[i].second==s)
		vec2.push_back(vec[i].first);
		else
		break;
	}
	sort(vec2.begin(), vec2.end());
	for (int i = 0; i < vec2.size(); i++)
	{
		cout<<vec2[i]<<"\n";
	}
	
}

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

int64_t count(int64_t a, int64_t b) {
  int64_t m = min(a, b);
  int64_t M = max(a, b);
  int64_t q = M / m;
  int64_t r = M % m;
  
  int64_t part = 2 * m * q;
  if ( r == 0 ) {
    return part - m;
  }
  else {
    return part + count(m, r);
  }
}

int64_t solve(int64_t N, int64_t X) {
  return N + count(N-X, X);
}

int main() {
  int64_t N, X;
  cin >> N >> X;
  int64_t answer = solve(N, X);
  cout << answer << endl;  
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
cnt = 0
two = 0
for i in a:
    if i % 4 == 0:
        cnt += 1
    elif i % 4 == 2:
        two += 1
if n // 2 <= cnt:
    print("Yes")
elif two >= 2 and (n - (two - 1)) // 2 <= cnt:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14252
import sys,collections as cl
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

n,a,b = m()

k = abs(a-b)
if k == 1:
	print("Borys")
else:
	if k % 2 == 0:
		print("Alice")
	else:
		print("Borys")




Measured memory_bytes: 3316
from sys import stdin

a = int(stdin.readline())
A=stdin.readline().split()

product=1
K=0

for k in range(0,a):
    if int(A[k])==0:
        product=0
        K=1
        break
        
if K==0:
   for b in range(0,a) :
       product=product*int(A[b])
       if product > 10 ** 18:
          product = -1
          break



print(product)

Measured memory_bytes: 19488
import java.util.Scanner;
import java.util.Arrays;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = 0;
    char[] symbols = sc.next().toCharArray();
    for(int i = 0; i < 4; i++){
    if(symbols[i] == '+'){
      a++;
    }else{
      a--;
    }
  }
  System.out.println(a);
    
  }
}

Measured memory_bytes: 21204
N = int(input())
A = list(map(int, input().split()))

mt_rain =[0]*N
mt_all =sum(A)
dam_even = sum(A[1::2]) #偶数番目のダムの増えた水
mt_rain[0] = mt_all - 2*dam_even #1番目の山の降水量

#2番目の山以降
for i in range(1,N):
    mt_rain[i] =2*A[i-1] -mt_rain[i-1]
print(*mt_rain)

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

int k,n,minv=1e9+7,pos;
int a[100005],v[100005];

signed main()
{
	cin>>k>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
		v[a[i]]=1;
	}
	for (int i=0;i<=10000;i++)
	{
		if (v[i]==1)  continue;
		
		if (abs(i-k)<minv)
		{
			minv=abs(i-k);
			pos=i;
		}
		else if (abs(i-k)==minv)
		{
			if (i<pos)  pos=i;
		}
	}
	cout<<pos<<endl;
	
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define maxN 1000000
 
long dp[maxN] = {INT_MAX};
long input[maxN] = {0};
 
int main() {
  int n, k;
  std::cin>>n>>k;
  for(int i =0; i < n;i++) {
  	std::cin>>input[i];
  	dp[i] = INT_MAX;
  }
  dp[0] = 0;
  for(int i = 0; i < n; i++) {
    for(int j =1; j <=k;j++) {
      dp[i + j] = std::min(dp[i] + std::abs(input[i] - input[i+j]), dp[i+j]);
    }
  }
  std::cout << dp[n-1] << std::endl;
}

Measured memory_bytes: 3456
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
#　最初はaでのやつが価値に当たる。
weight = LI()
value = LI()
dp = list(range(n + 1))
for i in range(3):
    for j in range(weight[i], n + 1):
        dp[j] = max(dp[j], dp[j - weight[i]] + value[i])


n = dp[-1]
weight, value = value, weight
dp = list(range(n + 1))
for i in range(3):
    for j in range(weight[i], n + 1):
        dp[j] = max(dp[j], dp[j - weight[i]] + value[i])

print(dp[-1])





Measured memory_bytes: 230936
#include <bits/stdc++.h>
using namespace std;
void YesNo(bool);
void YESNO(bool);


int main(){
    int a, b;
    cin >> a >> b;
    if (b % a == 0) {
        cout << a + b << endl;
    }else{
        cout << b - a << endl;
    }
    
}


void YesNo(bool x){
    if (x) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

void YESNO(bool x){
    if (x) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
}


Measured memory_bytes: 256
n,m=map(int,input().split())
root=[-1]*n
def r(x):
  if root[x]<0:
    return x
  else:
    root[x]=r(root[x])
    return root[x]
def unite(x,y):
  x=r(x)
  y=r(y)
  if x==y:
    return
  root[x]+=root[y]
  root[y]=x
for i in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  unite(a,b)
ans=0
for i in range(n):
  ans=max(ans,-root[i])
print(ans)

Measured memory_bytes: 13424
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <set>
#include <cmath>
#include <math.h>
#include <sstream> 
 
using namespace std;


int main(){
    vector<long int> data(3);
    cin>>data[0]>>data[1]>>data[2];
    sort(data.begin(),data.end());
    
    long int cnt=0;
    while(data[0]!=data[1] || data[0]!=data[2] || data[1]!=data[2]){
        if(data[1]!=data[2]){
            data[0]++;
            data[1]++;
        }else if(data[0]<data[1]){
            data[0]+=2;
        }else{
            data[1]++;
            data[2]++;
        }
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	char b, c[128];
	c['A'] = 'T';
	c['C'] = 'G';
	c['G'] = 'C';
	c['T'] = 'A';

	scanf("%c", &b);

	printf("%c\n", c[b]);

	return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.util.Arrays;

class Main {
	private static final int M = 50000;

	public static void main (String args[]) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf;

		int list[] = new int[M+1];
		for (int i=2;i<=M;i++) list[i] = 0;
		for (int i=2;i<=M;i++) {
			for (int j=2;i*j<=M;j++) {
				list[i*j] = 1;
			}
		}
		int count[] = new int[M+1];
		Arrays.fill(count,0);
		for (int i=2;i<M/2;i++) {
			if (list[i]==0) {
				for (int j=i;j<M;j++) {
					if (i+j>M) break;
					if (list[j]==0) count[i+j]++;
				}
			}
		}


		try {
			while ((buf = br.readLine()).equals("0")==false) {
				int n = Integer.parseInt(buf);
				System.out.println(count[n]);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 25872
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		String s = sc.next();
		boolean flag = true;

		for(int i = 0; i < a; i++) {
			int c = s.charAt(i);
			if(c < 48 || c > 57) flag = false;
		}

		if(s.charAt(a) != '-') flag = false;

		for(int i = a+1; i < a+b+1; i++) {
			int c = s.charAt(i);
			if(c < 48 || c > 57) flag = false;
		}
		System.out.println(flag ? "Yes" : "No");
		sc.close();
	}
}

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

using namespace std;
typedef long long ll;

ll n,w,arrw[105],arrv[105],dp[105][100005];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>w;
    for(int i=1;(int)i<=n;i++)cin>>arrw[i]>>arrv[i];
    for(int i=1;(int)i<=n;i++){
        for(int j=1;(int)j<=w;j++){
            if(j>=arrw[i])dp[i][j]=max(dp[i-1][j],dp[i-1][j-arrw[i]]+arrv[i]);
            else dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][w];
}

Measured memory_bytes: 79360