akhauriyash/Code-Regression huggingface dataset:
import sys
import collections


input = sys.stdin.readline


def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    c = collections.Counter(a)
    s = list(c.keys())
    v = list(c.values())
    if (len(c) == 3) and (s[0] == s[1] ^ s[2]) and (v[0] == v[1] == v[2]):
        print("Yes")
    elif len(c) == 1 and s[0] == 0:
        print("Yes")
    elif len(c) == 2 and 0 in s and (c[0] == n/3):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


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

int N;
vector<vector <pair <int,int>>> singi(15,vector<pair<int,int>>());

int dfs(int i,int mark){
    int mark_2 = mark | (1 << i);  
    if(i==N){
        int sum=0;
        int count=0;
        int flag[N];
        rep(i,N) {
            flag[i] = mark & (1<<i);
          	if(flag[i]>0) count++;
            sum += flag[i];
        }
        rep(i,N){
            if(flag[i]){
                for(auto temp : singi.at(i)){
                    if(flag[temp.first]>0 && temp.second==0 ||
                       flag[temp.first]==0 && temp.second>=1){
                        return 0;
                    }

                }
            }
        }
        return count;
    }
    else return max(dfs(i+1,mark),dfs(i+1,mark_2));
}

int main(){
  	int ans;
    cin >> N;
  	rep(i,N){
      int kosu;
      cin >> kosu;
      rep(j,kosu){
        	int temp,temp2;
        	cin >> temp >> temp2;
        	singi.at(i).emplace_back(make_pair(temp-1,temp2));
        }
    }
    ans = dfs(0,0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

x_diff = abs(B - A)
v_diff = V - W

if v_diff > 0:
    if x_diff/v_diff <= T:
        print('YES')
    else:
        print('NO')
else:
    if x_diff == 0:
        print('YES')
    else:
        print('NO')
    

Measured memory_bytes: 61680
#define _USE_MA_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi h(n);
    rep(i,n)cin>>h[i];
    int ans=0;
    int max=0;
    rep(i,n){
        if(h[i]>=max)max=h[i],ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define Rd(a) (a=read())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int read(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	if(c^'-')k=1,x=c&15;else k=x=0;
	while(isdigit(Gc(c)))x=(x<<1)+(x<<3)+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
int a,b,la,ra,lb,rb;
signed main(){
	Rd(a),Rd(b);
	la=ceil(a/0.08),ra=ceil((a+1)/0.08-1);
	lb=ceil(b/0.1),rb=ceil((b+1)/0.1-1);
	wr(ra<lb||rb<la?-1:max(la,lb)),exit(0);
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;



int main(void){
    int n;
    cin>>n;
    vector<pair<int,int>>p(n);
    vector<int>index(n);
    for(int i=0;i<n;i++)cin>>p[i].first>>p[i].second;
    for(int i=0;i<n;i++)index[i]=i;
    double ans=0.0;
    do{
        double x1=(double)p[index[0]].first;
        double y1=(double)p[index[0]].second;
        for(int i=1;i<n;i++){
            int k1=(p[index[i]].first-x1)*(p[index[i]].first-x1);
            int k2=(p[index[i]].second-y1)*(p[index[i]].second-y1);
            ans+=(double)sqrt((double)k1+k2);
            double x1=(double)p[index[i]].first;
            double y1=(double)p[index[i]].second;
        }

    }while(next_permutation(index.begin(),index.end()));
    int l=1;
    for(int i=1;i<=n;i++)l*=i;
    printf("%.10lf\n",(double)ans/l);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
const int maxs = 1e5 + 4;
long long dp[maxs][3];
long long a[maxs],b[maxs],c[maxs];
long long go(int pos,int state)
{
    if(pos == (n + 1))
        return 0;
    if(dp[pos][state] != -1)
        return dp[pos][state];
    
    long long ans = 0;
    
    if(state == 1)
    {
        ans = max(ans,go(pos + 1,state));
        ans = max(ans,b[pos] + go(pos + 1,2));
        ans = max(ans,c[pos] + go(pos + 1,3));
    }
    else if(state == 2)
    {
        ans = max(ans,go(pos + 1,state));
        ans = max(ans,a[pos] + go(pos + 1,1));
        ans = max(ans,c[pos] + go(pos + 1,3));
    }
    else
    {
        ans = max(ans,go(pos + 1,state));
        ans = max(ans,b[pos] + go(pos + 1,2));
        ans = max(ans,a[pos] + go(pos + 1,1));
    }
    
    return dp[pos][state] = ans;
    
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    memset(dp,-1,sizeof dp);
    
    int i;
    cin >> n;// >> w;
    for(i = 1;i <= n;++i)
        cin >> a[i] >> b[i] >> c[i];
    
    long long ans = max(go(1,1),max(go(1,2),go(1,3)));
    
    cout << ans;
    
}

Measured memory_bytes: 12996
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
//deque/functional/iterator/list/map/memory/numeric/queue/set/stack/utility/vector
//#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[10100];
int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int m;
	cin>>m;
	int s,b;
	for(int i=0;i<m;i++)
	{
		int sum=0;
		cin>>s>>b;
		for(int j=1;j<=n;j++){
			if(j!=s)
				sum+=a[j];
			else{
				sum+=b;
			}
		}
		cout<<sum<<endl;
	}

	
return 0;
}



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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;


int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> hs(n);
    rep(i, n) {
        cin >> hs[i];
    }
    sort(hs.begin(), hs.end());

    ll ans = INF;
    for (int i = 0; i < n - k + 1; i++) {
        ll h = hs[i + k - 1];
        ll m = hs[i];
        ll now = h  - m ;
        ans = min(ans, now);
    }

    cout << ans << endl;

}



Measured memory_bytes: 1024
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_14_B&lang=jp
#  String Search : python3
#  2018.11.26 yonezawa

import sys
input = sys.stdin.readline
#import cProfile

def main():
    s1  = str(input()).rstrip('\n')
    s2  = str(input()).rstrip('\n')
    
    s1_len = len(s1)
    s2_len = len(s2)
    sc = 1
    for k in range(1,len(s2)):
        if s2[0] != s2[k]:
            break
        sc += 1
    tc = len(set(s2))

    if (tc == 1 and s2_len > 1):
        cnt = 0
        for k in range(s1_len ):
            if (s1[k] == s2[0]):
                cnt += 1
            else:
                cnt = 0
            if (cnt >= s2_len ):
                print (cnt - s2_len)
    else:
        i = s1.find(s2)
        while i != -1 :
            print (i)
            i = s1.find(s2,i+1)


if __name__ == '__main__':
    main()
    #pr = cProfile.Profile()
    #pr.runcall(main)
    #pr.print_stats()



Measured memory_bytes: 7520
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int n,m,k;
  cin >> n >> m >> k;
  vi a(n,0);
  vi b(m,0);
  rep(i,n) cin >> a.at(i);
  rep(i,m) cin >> b.at(i);

  int tot = 0;
  int ans = 0;
  int mans = 0;
  int ni = n-1;
  rep(i,n) {
    tot += a.at(i);
    if(tot>k) {
      tot -= a.at(i);
      break;
    }
    ans++;
    ni = i;
  }
  mans = ans;

  int nj = 0;
  while(true) {
    srep(j,nj,m) {
      tot += b.at(j);
      if(tot>k) {
        tot -= b.at(j);
        nj = j;
        break;
      }
      ans++;
    }
    mans = max(ans,mans);
    if(ni < 0) break;
    tot -= a.at(ni);
    ans--;
    ni--;
  }

  cout << mans << endl;

  return 0;
}


Measured memory_bytes: 4848
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
   int A, B, C, D;
   cin >> A >> B >> C >> D;
   int L = A + B;
   int R = C + D;
   if (L < R)
   cout << "Right" << endl;
   if(L > R)
   cout << "Left" << endl;
   if (L == R)
   cout << "Balanced" << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
char a[101][101];
int b[101][101]= {0};
int n,m,i,j;
int dx[8]= {1,0,-1,0,-1,1,1,-1};
int dy[8]= {0,1,0,-1,-1,-1,1,1};
void dfs(int x,int y) {
	int nx,ny,k;
	for (k=0; k<8; k++) {
		nx=x+dx[k];
		ny=y+dy[k];
		if (nx>=1&&nx<=n&&ny>=1&&ny<=m)
			b[nx][ny]++;
	}
}
int main() {
	cin>>n>>m;
	for (i=1; i<=n; i++)
		for (j=1; j<=m; j++) {
			cin>>a[i][j];
			if (a[i][j]=='#')
				dfs(i,j);
		}
	for (i=1; i<=n; i++) {
		for (j=1; j<=m; j++)
			if (a[i][j]=='#')
				cout<<a[i][j];
			else
				cout<<b[i][j];
		cout<<endl;
	}
	cout<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 1e6 + 123;
const ll LINF = (ll) 1e18 + 1e9 + 123;
const ld EPS = (ld) 1e-7;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (int i = f; i < t; i++)
#define per(i, f, t) for (int i = f; i >= t; i--)

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

void add(ll &x, ll y) {
	x += y;
	if (x >= MOD) x -= MOD;
	if (x < 0) x += MOD;
}

ll mult(ll x, ll y) {
	return x * y % MOD;
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

const int N = 2005;

int n;
int a[N];
bitset<N * N> can;

void run() {
	cin >> n;
	int s = 0;
	can[0] = 1;
	rep(i, 0, n) {
		cin >> a[i];
		s += a[i];
		can |= (can << a[i]);
	}
	s = (s + 1) / 2;
	while (!can[s]) {
		s++;
	}
	cout << s << "\n";
}


Measured memory_bytes: 1792
# https://atcoder.jp/contests/abc134/tasks/abc134_e
import sys
read = sys.stdin.readline


def read_a_int():
    return int(read())


from bisect import bisect_left, bisect_right, insort_left
from collections import deque
from array import array


class BinarySearchTree:
    def __init__(self, ls: list = []):
        '''
        C++でいうsetを実装する。二分探索木をガチで実装しようとすると大変なので、ここでは配列二分法を用いる。
        pythonの標準ライブラリがヨイショに抱っこしてくれるおかげで楽に実装できる。
        https://docs.python.org/ja/3/library/bisect.html


        ls ... 渡す初期配列
        '''
        self.bst = array('l',sorted(ls))  # insertをO(1)にするためにlistの代わりにdequeを用います

    def __len__(self):
        return len(self.bst)

    def __getitem__(self, idx):
        return self.bst[idx]

    def size(self):
        return len(self.bst)

    def insert(self, x):
        idx = self.bisect_left(x)
        self.bst.insert(idx, x)
        # insort_left(self.bst, x)

    def pop_left(self):
        x = self.bst[0]
        del self.bst[0]
        return x

    def pop_right(self):
        x = self.bst[-1]
        del self.bst[-1]
        return x

    def remove(self, x):
        '''
        xを取り除く。xがself.bstに存在することを保証してください。
        同一のものが存在した場合は左から消していく
        '''
        del self.bst[self.find(x)]

    def bisect_left(self, x):
        '''
        ソートされた順序を保ったまま x を self.bst に挿入できる点を探し当てます。
        lower_bound in C++
        '''
        return bisect_left(self.bst, x)

    def bisect_right(self, x):
        '''
        bisect_left() と似ていますが、 self.bst に含まれる x のうち、どのエントリーよりも後ろ(右)にくるような挿入点を返します。
        upper_bound in C++
        '''
        return bisect_right(self.bst, x)

    def find(self, x):
        '''
        xのidxを探索
        '''
        idx = bisect_left(self.bst, x)
        if idx != len(self.bst) and self.bst[idx] == x:
            return idx
        raise ValueError

    def insert_replace_left(self, x):
        '''
        xを挿入して、xの左の数字(次に小さい)を削除する。idxがはみ出す場合は挿入だけ
        '''
        idx_del = self.bisect_left(x) - 1
        if idx_del + 1 == 0:  # xがどの要素よりも小さい
            self.insert(x)
        if idx_del < len(self.bst):
            self.insert(x)
            del self.bst[idx_del]

    def insert_replace_right(self, x):
        '''
        xを挿入して、xの右の数字(次に大きい)を削除する。idxがはみ出す場合は挿入だけ
        '''
        idx_del = self.bisect_right(x) + 1  # xと同じ大きさも削除したいならbisect_left
        if idx_del - 1 == len(self.bst):  # xがどの要素よりも大きい
            self.insert(x)
        else:
            self.insert(x)
            del self.bst[idx_del]


N = read_a_int()
bst = BinarySearchTree([-1])
for n in range(N):
    a = read_a_int()
    # すべてより小さかったら、新しく追加
    if bst.bst[0] >= a:
        bst.insert(a)
    else:
        # bstのなかで、aより小さく且つ一番大きい要素をaに書き換えていく
        idx = bst.bisect_left(a) - 1
        bst.bst[idx] = a

print(len(bst))


Measured memory_bytes: 4240
import std.conv, std.stdio;
import std.algorithm, std.array, std.range, std.string;
void main()
{
    readln;
    auto buf = cast(ubyte[][])(readln.chomp.split);
    (cast(string)(buf[0].zip(buf[1]).map!(_=> [_[0], _[1]]).joiner.array)).writeln;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>

int main() {
	long long a, b, c;

	std::cin >> a >> b >> c;
	
	if (a > b) std::swap(a, b);
	if (b > c) std::swap(b, c);
	if (a > b) std::swap(a, b);

	int red = c / 2;
	int blue = c - red;

	std::cout << std::abs((red * a * b) - (blue * a * b)) << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    ll N, M;
    cin >> N >> M;
    ll sum = 0;
    rep(i, M){
        ll a; cin >> a;
        sum += a;
    }
    if(sum > N) cout << -1 << endl;
    else cout << N-sum << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
//int dx[4] = { 1,0,0,-1 };
//int dy[4] = { 0,1,-1,0 };
#define MOD 1000000007
#define ARRAY_MAX 50

const int INF = 1e9 + 7;


int main() {


	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, m, c;
	cin >> n >> m >> c;
	int b[ARRAY_MAX];
	int a[ARRAY_MAX][ARRAY_MAX];
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		int cnt = 0;
		for (int j = 0; j < m; j++) {
			cnt += a[i][j] * b[j];
		}
		//cout << "cnt=" << cnt << endl;
		if (cnt + c > 0) {
			ans++;
		}
	}
	cout << ans << endl;




	return 0;
}

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

int main(){
  
  long long Xfmin = 0, N, i, ix = 0, cnt = 1;
  cin >> N;
  
  vector<pair<long long, long long>> SF(N);
  for(i = 0; i < N; i++){
    long long X, L; 
    cin >> X >> L;
    SF[i].second = X - L; SF[i].first = X + L;
  }
  sort(SF.begin(), SF.end());
    
  Xfmin = SF[0].first;
  while(true){
    
    bool flag = false;
    for(i = ix + 1; i < N; i++){
      if(Xfmin <= SF[i].second){
        ix = i;
        Xfmin = SF[i].first;
        cnt++;
        flag = true;
        break;
      }
    }
    if(!flag)break;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 4816
MAXC = 10000

def solve(n,ma,mb,list)
  dp = []

  #init dp
  all_a = 0
  all_b = 0
  list.each do |a,b,c|
    all_a += a
    all_b += b
  end

  dp[0] = []
  (0..all_a).each do |a|
    # dp[0][a] = Array.new(all_b+1,MAXC)
    dp[0][a] = []
  end
  dp[0][0][0] = 0

  (1..n).each do |k|
    dp[k] = []
    ea,eb,ec = list[k-1]

    (0..all_a).each do |a|
      dp[k][a] = []
      (0..all_b).each do |b|
        nosel = dp[k-1][a][b]
        unless (a >= ea && b >= eb)
          dp[k][a][b] = nosel
        else
          sel = nil
          sel = (dp[k-1][a - ea][b - eb] + ec) if dp[k-1][a - ea][b - eb] != nil
          if sel == nil
            dp[k][a][b] = nosel
          elsif nosel == nil || sel < nosel
            dp[k][a][b] = sel
          else
            dp[k][a][b] = nosel
          end
        end
      end
    end

  end

  ans = nil
  f = 0
  loop do
    f += 1
    ta = f * ma
    tb = f * mb
    break if ta > all_a || tb > all_b
    next if dp[n][ta][tb] == nil
    if ans == nil || ans > dp[n][ta][tb]
      ans = dp[n][ta][tb]
    end
  end

  return -1 if ans == nil
  return ans
end

def main
  n,ma,mb = gets.split.map(&:to_i)
  list = []
  n.times do
    list << gets.split.map(&:to_i)
  end
  puts solve(n,ma,mb,list)
end

main


Measured memory_bytes: 23676
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    vector<bool> d(10);
    int n, k;
    cin >> n >> k;
    rep(i, 0, k) {
        int now;
        cin >> now;
        d.at(now) = true;
    }
    for (int i = n;; i++) {
        int now = i;
        bool ans = true;
        while (now != 0) {
            int next = now % 10;
            if (d.at(next))
                ans = false;
            now /= 10;
        }
        if (ans) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("Ofast")
#define ll long long
#define MAX(A,B) ((A)>(B)?(A):(B))
#define MIN(A,B) ((A)<(B)?(A):(B))
#define gcd(A,B) (__gcd(A,B))
#define lcm(A,B) A/(__gcd(A,B))*B
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define ld long double
#define mod 1000000007LL
#define all(x) x.begin(), x.end()
#define usecppio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

typedef pair<int,int> pii;
vector <pii> arr;
int tot;
int main()
{
    int n, l;
    scanf("%d %d",&n,&l);
    for (int i = 1; i<=n; i++)
    {
        arr.push_back({abs(l+i-1),l+i-1});
        tot += (l+i-1);
    }
    sort(all(arr));
    tot-=(arr[0].second);
    cout << tot;
}

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

using namespace std;

typedef long long int ll;
typedef vector<ll> vll;

#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define fin(ans) cout << (ans) << endl;

template <typename T>
void V(T &n)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i];
  }
}

template <typename T>
void Sort(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (sort(n.begin() + a, n.end()));
  }
  else
  {
    return (sort(n.begin() + a, n.begin() + b));
  }
}

void Main()
{
  ll a, p; cin >> a >> p;
  a *= 3;
  fin((a + p) / 2)
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int INF = 1e9 + 239;

int can(vector<int> a, int l, int r, int q, int k) {
	int n = (int)a.size();
	int c = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] < l) {
			continue;
		} else {
			int p = i;
			int cnt_less_r = 0;
			if (a[i] <= r) cnt_less_r++;
			vector<int> sb = {a[i]};
			while (p + 1 < n && a[p + 1] >= l) {
				if (a[p + 1] <= r) {
					cnt_less_r++;
				}
				sb.push_back(a[p + 1]);
				p++;
			}
			int len = p - i + 1;
			if (len >= k) {
				c += min(len - k + 1, cnt_less_r);
			}
			i = p;
		}
	}
	return c >= q;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k, q;
	cin >> n >> k >> q;
	if (q == 1) {
		cout << 0 << endl;
		exit(0);
	}
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}	
	int ans = INF;
	vector<int> sn = a;
	sort(sn.begin(), sn.end());
	for (int i = 0; i < n; i++) {
		vector<int> na = a;
		na.erase(na.begin() + i);
		{
			int l = -1;
			int r = n - 1;
			while (r - l > 1) {
				int m = (r + l) >> 1;
				if (can(na, a[i], sn[m], q - 1, k)) r = m;
				else l = m;
			}
			if (can(na, a[i], sn[r], q - 1, k)) ans = min(ans, sn[r] - a[i]);
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx,tune=native")

#include <bits/stdc++.h>

using namespace std;

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

template<typename T>
using pq_gt = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using pq_lt = priority_queue<T, vector<T>, less<T>>;

#define se second
#define fi first
#define pb push_back

void getTwo(int x) {
	int cur = 2;
	while(x>2) {
		cout<<cur<<" "<<cur+2<<" "<<cur+4<<" ";
		cur +=6;
		x-=3;
	}
	if(x==1) {
		cout<<cur+4<< " ";
	} else if(x==2){
		cout<<cur<<" "<<cur+2<<" ";
	}
}

void getThree(int x) {
	for(int i = 0; i < x; ++i) {
		cout<<3+i*6<<" ";
	}
	cout<<endl;
}

int main() {
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    if(N==3) {
    	cout<<"2 5 63"<<endl;
    	return 0;
    }
    if(N==4) {
    	cout<<"2 5 20 63"<<endl;
    	return 0;
    }
    if(N%2==1) {
    	if(N>15000) {
    		getTwo(14999);
    		getThree(N-14999);
    	} else {
    		getTwo(N-2);
    		getThree(2);
    	}
    } else {
    	if(N>15002) {
    		getTwo(15000);
    		getThree(N-15000);
    	} else {
    		getTwo(N-2);
    		getThree(2);
    	}
    }
}

Measured memory_bytes: 384
sx,sy,tx,ty = map(int,input().split())
ans = []
for i in range(ty-sy):
    ans.append("U")
for i in range(tx-sx):
    ans.append("R")
for i in range(ty-sy):
    ans.append("D")
for i in range(tx-sx):
    ans.append("L")
ans.append("L")
for i in range(ty-sy+1):
    ans.append("U")
for i in range(tx-sx+1):
    ans.append("R")
ans.append("D")
ans.append("R")
for i in range(ty-sy+1):
    ans.append("D")
for i in range(tx-sx+1):
    ans.append("L")
ans.append("U")



print("".join(ans))

Measured memory_bytes: 3188
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    
    double a = sc.nextInt();
    double odd1 = 0;
    double odd2 = 0;
    
    for(int i=1 ; i<=a ; i++){
      if(i%2==0){
        odd2++;
      }else{
        odd1++;
      }
    }
    
    System.out.println(odd1/a);
  }
}
  	
    

Measured memory_bytes: 22740
#include <iostream>
using namespace std;
int main(){
  int N;
  while(cin >> N, N){
    int r[N], w[N], s_r = 0, M = 0, s = 0, id;
    for(int i = 0; i < N; ++i){
      cin >> r[i] >> w[i];
      //M = max(max(M,r[i]),w[i]);
      if(r[i] > M){
	M = r[i];
	id = i;
      }
      s_r += r[i];
      s += r[i] + w[i];
    }
    if(M*2 > s_r){
      int t = 2*M - s_r;
      //cout << "t = " << t << endl;
      bool k[t+1];
      fill(k,k+t+1,false);
      k[0] = true;
      for(int i = 0; i < N; ++i){
	if(i == id) continue;
	for(int j = t; j >= 0; --j){
	  if(!k[j] && j >= w[i] && k[j-w[i]]) k[j] = true;
	}
	if(k[t]) break;
      }
      /*
      for(int i = 0; i <= t; ++i){
	cout << k[i] << " ";
      }cout << endl;
      */
      int a;
      for(int i = t; i >= 0; --i){
	if(k[i]){
	  a = i;
	  break;
	}
      }
      cout << s + t - a << endl;
    }else{
      cout << s << endl;
    }
  }
  return 0;
}

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

int main(){
  int a,i;
  double b;
  b=0;
  a>=1;
  
  cin >> a;
  
  vector<double> vec(a);
  
  for(i=0;i<a;i++){
    cin >> vec[i];
  }
  
  for(i=0;i<a;i++){
    vec[i] = 1/vec[i];
  }
  for(i=0;i<a;i++){
    b=b+vec[i];
  }
  cout << 1/b;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    string a,b;cin>>a>>b;
    int ans = 0;
    rep(i,0,a.size()){
        if (a[i]!=b[i]) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3780
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const char *data = "abcdefghijklmnopqrstuvwxyz.?! ";
int main(){
  string str;
  while(getline(cin,str)){
    string ans;
    int pos = 0;
    //printf("pos = %d, str.size()=%d\n",pos,str.size());
    while(true){
      if(pos != str.size()){
        if(pos + 1 == str.size())
          goto na;

        int a = str[pos++] - '0';
        int b = str[pos++] - '0';
        //printf("a = %d, b = %d\n",a,b);
        if(a < 1 || a > 6) goto na;
        if(b < 1 || b > 5) goto na;
        a--; b--;
        ans += data[a*5 + b];
      }else{
        cout << ans << endl;
        break;
      }
    }
    continue;
  na:
    cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
n,k,q = map(int,input().split())
a = list(int(input()) for i in range(q))
z = [0] * n
for i in range(q):
    z[a[i]-1] += 1
for i in range(n):
    if z[i] >= q - k + 1:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 13680
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long a,b,k;
   while(scanf("%lld %lld",&a,&b)!=EOF)
   {
       if((a+b)%2!=0)
       {
           printf("IMPOSSIBLE\n");
       }

       else
       {
           k=(a+b)/2;
       long long r=abs(k);
           printf("%lld\n",r);
       }
   }

return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
std::vector<int>t,o;
const int N=1000000,V=1<<9;
int a[N],b[N];
int main()
{
	int i,j,n;
	for(i=1;i<N;++i)a[i]=b[i]=V;
	for(i=1;n=(i*(i+1)*(i+2))/6,n<N;++i)if(a[n]=1,t.push_back(n),n&1)b[n]=1,o.push_back(n);
	for(i=t.size()-1;i>=0;--i)
	{
		a[t[i]]=1;
		for(j=t[i];j+t[i]<N;++j)if(a[j]+1<a[j+t[i]])a[j+t[i]]=a[j]+1;
	}
	for(i=o.size()-1;i>=0;--i)
	{
		b[o[i]]=1;
		for(j=o[i];j+o[i]<N;++j)if(b[j]+1<b[j+o[i]])b[j+o[i]]=b[j]+1;
	}
	while(scanf("%d",&n),n)printf("%d %d\n",a[n],b[n]);
	return 0;
}

Measured memory_bytes: 8500
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n)-1;i>=(j);i--)
using ll=long long;
using namespace std;
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; }
const ll INF=1LL<<60;

int r,g,b,n;

int main(){
    cin>>r>>g>>b>>n;
    int num;
    int ans=0;
    rep(i,0,3001){
        rep(j,0,3001){
            num=(n-i*g-j*b);
            if(num>=0 && num%r==0) ans++;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define N	    100001
#define rep(i,a,b)  for(int i=a;i<b;i++)
typedef long long ll;
void self_max(ll  &a, ll b) {
	a = max(a, b);
}
int main() {
	int n, w;
	cin>>n>>w;
	vector<ll> dp(w + 1);
	for(int i = 0; i < n; ++i) {
		int weight, value;
		cin>>weight>> value;
		for(int wt = w - weight;   wt >= 0; wt--) {
				if(!wt || dp[wt])
                    self_max(dp[wt + weight], dp[wt] + value);		}
	}
	ll ans = 0;
	for(int i = 0; i <= w; i++) 
		self_max(ans, dp[i]);
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        if (a.Length == 1) { Console.WriteLine(a[0]); goto end; }
        Console.Write(a[0]);
        var pre = a[0];
        for (int i = 1; i < n; i++)
        {
            if (a[i] != pre) Console.Write(" {0}", a[i]);
            pre = a[i];
        }
        Console.WriteLine();
        end:;
    }
}




Measured memory_bytes: 17400
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            double D = in.nextInt();

            int cnt = 0;
            while (N > 0)
            {
                double X = in.nextInt();
                double Y = in.nextInt();
                if (Math.sqrt(X * X + Y * Y) <= D)
                {
                    cnt++;
                }
                N--;
            }
            out.print(cnt);
        }

    }
}



Measured memory_bytes: 49076
import math
from collections import Counter
from collections import defaultdict

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N = int(input())
MOD = 10 ** 9 + 7
d = defaultdict(int)
for i in range(2, N+1):
    ar = factorization(i)
    for k, v in ar:
        d[k] += v
answer = 1
for k, v in d.items():
    answer *= (v+1)
    answer %= MOD
print(answer)


Measured memory_bytes: 3444
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

const int MOD = 1000000007;
typedef long long ll;

int main()
{
  int N,r=0,l=0;
  string S,ans="";
  cin>>N>>S;
  for(int i=0;i<N;i++){
    if(S[i]=='('){
      l++;
      ans.push_back('(');
    }else{
      r++;
      if(l<r){
        l++;
        ans.insert(0,"(");
        ans.push_back(')');
      }else{
        ans.push_back(')');
      }
    }
  }
  for(int i=0;i<l-r;i++){
    ans.push_back(')');
  }
  cout << ans << endl;
}


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

int bubbleSort(int A[], int N) {
  int sw = 0;
  bool flag = 1;
  for ( int i = 0; flag; i++ ) {
    flag = 0;
    for ( int j = N - 1; j >= i + 1; j-- )
      if ( A[j] < A[j - 1] ) {
        swap(A[j], A[j - 1]);
        flag = 1;
        sw++;
      }
  }
  return sw;
}

int main() {
  int A[100], N, sw;
  cin >> N;
  for ( int i = 0; i < N; i++ ) cin >> A[i];

  sw = bubbleSort(A, N);

  for ( int i = 0; i < N; i++ ) {
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

  return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
#define MAX 100000

ll n,x[MAX],l[MAX];
P xl[MAX] ;

int main(){

    cin>>n;
    
    rep(i,n){
        cin>>x[i];
        cin>>l[i+1];
        xl[i].first=x[i]+l[i+1];
        xl[i].second=x[i]-l[i+1];
        //cout<<xl[i].first<<" "<<xl[i].second<<endl;
    }
    sort(xl,xl+n);
    
    int count=0;
    ll  a=INT_MIN;
    rep(i,n){

        //cout<<xl[i].first<<" "<<xl[i].second<<endl;
        if(a<=xl[i].second){
            a=xl[i].first;
            
            count++;
        }
    }

    cout<<count;
    return 0;
    
}



Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 1000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define stp setprecision(15)
#define eps 0.000001
#define endl '\n'
#define ll lli
 
using namespace std ;
 
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
#define N 8
  
int main() 
{ 

/////////////////////////////////////
    
    fastio;

  lli n;
  cin>>n;
  lli a[n],b[n],cnt=0;

  loopl(i,0,n)
  {
    cin>>a[i];
    b[i] = a[i];
    }

    sort(b,b+n);

    loopl(i,0,n)
    {
        if(b[i]!=a[i]) cnt++;
    }
    if(cnt <=2) cout<<"YES";
    else cout<<"NO";
 
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static final int MAX_LEN = 50;
    void run() {
        Scanner scan = new Scanner(System.in);
        long k = scan.nextLong();
        long[] a = new long[MAX_LEN];
        for (int i = 0; i < MAX_LEN; i++)
            a[i] = i;
        long n = k / MAX_LEN;
        for (int i = 0; i < MAX_LEN; i++)
            a[i] += n;
        n = k % MAX_LEN;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < MAX_LEN; j++) {
                if (j == i)
                    a[j] += MAX_LEN;
                else
                    a[j] -= 1;
            }
        }
        System.out.println(MAX_LEN);
        for (int i = 0; i < MAX_LEN - 1; i++)
            System.out.print(a[i] + " ");
        System.out.println(a[MAX_LEN - 1]);
    }
    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>

using namespace std;
typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }
  int ans = 0;
  int r = min(N, K);
  for (int a = 0; a <= r; a++) {
    for (int b = 0; b <= r - a; b++) {
      int tmp = 0;
      vector<int> minus;
      for (int i = 0; i < a; i++) {
        tmp += vec[i];
        if (vec[i] < 0) {
          minus.push_back(vec[i]);
        }
      }
      for (int i = 0; i < b; i++) {
        tmp += vec[N - 1 - i];
        if (vec[N - 1 - i] < 0) {
          minus.push_back(vec[N - 1 - i]);
        }
      }
      sort(minus.begin(), minus.end());
      int d = min(K - a - b, (int)minus.size());
      for (int i = 0; i < d; i++) {
        tmp -= minus[i];
      }
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstring>

using namespace std;

int main()
{
	char a,b;
	cin>>a>>b;
	if(a=='H')
	{
		cout<<b<<endl;
	}
	else
	{
		if(b=='H')cout<<"D\n";
		else cout<<"H\n";
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
int n;
int x[30], y[30],h1,h2,d1,d2;
  
double dist(int a, int b){
    return sqrt(a*a+b*b+0.0);
}  
int main(){
    while(1){
		bool ok=true;
        cin >> n;
        if(n == 0) break;
        cin >>h1>>h2>>d1>>d2;
        for(int i=0;i<n;i++){
            cin >> x[i] >> y[i];
			if(dist(h1-x[0],h2-y[0])+dist(x[0]-x[i],y[0]-y[i]) >= dist(d1-x[i],d2-y[i]))ok=false;
        }
  
        if(ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)

typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e5 + 5;
int v[N];
int n;

int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
	//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#endif

    sfi1(n);
    range(i,1,n)sfi1(v[i]);
    int ans = 0;
    range(i,1,n){
        if(i == n){
            if(i == v[i])
                ans++;
        }else{
            if(v[i] == i && v[i+1] == i+1){
                ans++;
                i++;
            }else if(v[i] == i){
                ans++;
            }
        }
    }

    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 640
def grid(mat: list):
    m = len(mat)
    n = len(mat[0])
    dp = [[0 for _ in range(n)] for _ in range(m)]
    dp[0][0] = 1
    for i in range(m):
        for j in range(n):
            if mat[i][j] == '.':
                if i > 0:
                    dp[i][j] = dp[i - 1][j]
                if j > 0:
                    dp[i][j] += dp[i][j - 1]
    return dp[m - 1][n - 1]%1000000007


if __name__ == '__main__':
    m, n = list(map(int, input().split()))
    mat = [[]] * m
    for i in range(m):
        mat[i] = [c for c in input()]
    print(grid(mat))


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

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

  bool findFlag = false;
  for(int i='a';i<='z';i++){
    for(long j=0;j<s.length();j++){
      if(s[j] == i){
	findFlag = true;
      }
    }
    if(findFlag == false){
      cout << (char)i << endl;
      return 0;
    }
    findFlag = false;
  }
  cout << "None" << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int	main(void)
{
	int n;
	int r;
	int l;
	int	seats[100000] = {0};
	int result = 0;

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d %d", &l, &r);
		for (int j = l; j <= r; j++)
		{
			seats[j - 1] = 1;
		}
	}
	for (int i = 0; i < 100000; i++)
	{
		if (seats[i])
		{
			result++;
		}
	}
	printf("%d\n", result);
	return (0);
}


Measured memory_bytes: 512
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int a,b,c,d,e,k;
	cin>>a>>b>>c>>d>>e>>k;
	if(e-a<=k)cout<<"Yay!"<<endl;
	else cout<<":("<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	int a, b, c, x;
	int count = 0;
	int y;

	cin >> a >> b >> c >> x;
	FOR(i, 0, a) {
		FOR(t, 0, b) {
			FOR(u, 0, c) {
				if (500 * i + 100 * t + 50 * u == x) {
					count++;
				}
			}
		}
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var X, Y uint64
	fmt.Scan(&X)
	fmt.Scan(&Y)

	po := Y / X

	ans := 1
	var check uint64
	check = 2
	for po >= check {
		ans++
		check = check * 2
	}
	fmt.Println(ans)
}


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

int main()
{




	ll n, k, ans;
	cin >> n >> k;

	if (n == k || n == 0)
		ans = 0;

	else if (k == 0 && n != 0)
		ans = n;

	else if (n > k && k == 1)
		ans = 0;

	else if (n % k == 0 || k % n == 0)
		ans = min(n, k);


	else if (n > k && k != 1)
		ans = k - n % k;

	else if (k > n)
		ans = min(n, k - n);

	cout << ans << "\n";





	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool 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 digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
//struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;


void solve(std::string S, std::string T){
	string res;
	res = T+S;
	cout << res << "\n";
}

int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 256
import itertools
N = int(input().strip())
C = [list(map(int, input().strip().split(' '))) for _ in range(N)]
ans = 0
def dist(t1, t2):
  return (((t1[0]-t2[0])**2) + ((t1[1]-t2[1])**2))**0.5

for i,j in itertools.combinations(range(N), 2):
  ans += dist(C[i], C[j])
ans = ans*2/N
print(ans)

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

int main() {
	int n;
	long long gcd, num;
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> num;
		if(i) gcd = __gcd(num, gcd);
		else gcd = num;
	}
	cout << gcd;
	return 0;
}

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

int main() {
	int N, K;
	cin >> N >> K;
	int A[N];
	for (int a = 0; a < N; a++)
		cin >> A[a];
	for (int a = 0; a < K; a++) {
		int numN = 0;
		int prefix[N + 1];
		memset(prefix, 0, sizeof(prefix));
		for (int b = 0; b < N; b++) {
			prefix[max(0, b - A[b])]++;
			prefix[min(N, b + A[b] + 1)]--;
		}
		int sum = 0;
		for (int b = 0; b < N; b++) {
			sum += prefix[b];
			A[b] = sum;
			if(A[b] == N)
				numN++;
		}
		if(numN == N)
			break;
	}
	for (int a = 0; a < N; a++)
		cout << A[a] << " ";
	cout << endl;
}


Measured memory_bytes: 5176