akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc093/tasks/abc093_b

int main() {
    int A, B, K; cin >> A >> B >> K;
    set<int> ans;
    for (int i = A; i < A+K; i++) {
        if (i > B) break;
        ans.insert(i);
    }
    for (int i = B; i > B-K; i--) {
        if (i < A) break;
        ans.insert(i);
    }

    for (int t : ans) {
        cout << t << "\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 ll long long
ll INF = 10001000100;

int main() {
	int n; cin >> n;
	vector<int> v(n);
	vector<int> c(n);
	rep(i,n) cin >> v[i];
	rep(i,n) cin >> c[i];

	 bitset<20> sum;
	 int ans = 0;
	 rep(i,n) {
	 		if(v[i]>c[i]) ans+=v[i]-c[i];	 	
	 }
	 cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
lst = list(map(int, input().split()))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(x, y):
    return (x * y) // gcd(x, y)

koubai = lst[0]
for i in range(n):
    if i != 0:
        koubai = lcm(lst[i], koubai)
vol = 0        
for i in range(n):
    vol += (koubai - 1) % lst[i]
print(vol)

Measured memory_bytes: 3316
<>=~$";$G=$';map{$i+=100;for$k(reverse@a=//..1e3){$p[$k]+=$-=$_>$k?0:$p[$k-$_]+$i*$_+($_==$`&&$')-$p[$k]for 1..$`}}<>;printf grep$p[$_]>=$G,@a

Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vi in(m);
		rep(i,m)cin>>in[i];
		int r=0,l=15000001;
		int out;
		bool H=0;
		while(1){
			if(l-r<=1)H=true;
			int h=(r+l)/2;
			int c=1;
			int sum=0;
			rep(i,m){
				if(sum==0&&in[i]>h){
					c=1e9;
					break;
				}else if(sum+in[i]>h){
					c++;sum=0;
					i--;
				}else{
					sum+=in[i];
				}
			}
			if(H){
				if(c<=n)out=r;
				else out=l;
				break;
			}
			if(c<=n)l=h;
			else r=h;
		}
		cout<<out<<endl;
	}
}

Measured memory_bytes: 1196
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int suma = 0;
		int[][] sheet = new int[r][c];

		for(int i=0; i<r; i++){
			for(int s=0; s<c; s++){
				sheet[i][s] = scan.nextInt();
			}
		}
		for(int i=0; i<r; i++){
			int sumw = 0;
			for(int s=0; s<c; s++){
				sumw += sheet[i][s];
				System.out.print(sheet[i][s] + " ");
				if(s == c-1){
					System.out.print(sumw + "\n");
					sumw = 0;
				}
			}
		}
		for(int i=0; i<c; i++){
			int sumh= 0;
			for(int s=0; s<r; s++){
				suma += sheet[s][i];
				sumh += sheet[s][i];
			}
			System.out.print(sumh + " ");
			if(i == c-1)
				System.out.print(suma + "\n");
		}

	}

}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#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 (ll i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n;
    string s[105], ans = "Yes";
    set<string> used;
    cin >> n;
    REP(i,n){
        cin >> s[i];
    }
    used.insert(s[0]);
    REP(i,n-1){
        if(s[i][s[i].size()-1]!=s[i+1][0])ans = "No";
        if(used.count(s[i+1])>0)ans = "No";
        used.insert(s[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n){
    cin >> p[i];
  }
  int max = *max_element(p.begin(),p.end()); 
  int sum = accumulate(p.begin(),p.end(),0);
  cout << sum-(max/2) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tokenizer = null;
    int totalCases, testNum;

    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    void solve() throws IOException {

    }

    void execute() throws IOException {
        long n = nl();
        StringBuilder sb = new StringBuilder();
        while (n > 0) {
            n--;
            sb.append((char)(n%26 + 'a'));
            n /= 26;
        }
        out.println(sb.reverse().toString());

        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().execute();
    }

    void debug(Object... os) {
        System.out.println(Arrays.deepToString(os));
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String ns() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(br.readLine());
        }
        return tokenizer.nextToken();
    }

    String nline() throws IOException {
        tokenizer = null;
        return br.readLine();
    }

    boolean input() throws IOException {
        return true;
    }

}


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


void solve(long long N, std::vector<long long> X){
    int mean = round(accumulate(X.begin(), X.end(), 0) / (double)X.size());
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans += pow((X[i] - mean), 2.0);
    }
    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> X(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&X[i]);
    }
    solve(N, std::move(X));
    return 0;
}


Measured memory_bytes: 3756
import sys
input = sys.stdin.readline

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

a.sort(reverse = True)

subtotal = 0
need = 0
for i in range(N):
    if subtotal + a[i] < K:
        subtotal += a[i]
    else:
        need = i+1
print(N - need)

Measured memory_bytes: 3572
using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;
    
    int s,w;
    cin>>s>>w;

    if (w>=s)
    cout<<"unsafe"<<endl;
    else
    cout<<"safe"<<endl;    
       
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#define INF 1000000009
#define LINF 1000000000000000009
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmax(T &a, const T&b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T&b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 1000000007;

ll fac[1000010];

ll modinv(ll a) {
	ll b = mod, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= mod;
	if (u < 0) u += mod;
	return u;
}

void modfac() {
	fac[0] = 1;
	for (ll i = 1; i < 1000010; i++) {
		fac[i] = (fac[i - 1] * i) % mod;
	}
}

ll modperm(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	else return (fac[n] * modinv(fac[n - k])) % mod;
}

ll modcomb(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	else return ((fac[n] * modinv(fac[k])) % mod*modinv(fac[n - k])) % mod;
}

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

int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<char>> a(h, vector<char>(w));
	for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> a[i][j];
	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '.') {
				vector<vector<int>> cnt(h, vector<int>(w));
				vector<vector<bool>> flag(h, vector<bool>(w));
				queue<P> que;
				que.push(P(i, j));
				flag[i][j] = true;
				while (!que.empty()) {
					P p = que.front(); que.pop();
					for (int x = 0; x < 4; x++) {
						if (0 <= p.first + dx[x] && p.first + dx[x] < h && 0 <= p.second + dy[x] && p.second + dy[x] < w&&a[p.first + dx[x]][p.second + dy[x]] == '.' && !flag[p.first + dx[x]][p.second + dy[x]]) {
							cnt[p.first + dx[x]][p.second + dy[x]] = cnt[p.first][p.second] + 1;
							flag[p.first + dx[x]][p.second + dy[x]] = true;
							que.push(P(p.first + dx[x], p.second + dy[x]));
						}
					}
				}
				int dis = 0;
				for (int x = 0; x < h; x++) {
					for (int y = 0; y < w; y++) {
						chmax(dis, cnt[x][y]);
					}
				}
				chmax(ans, dis);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
vector<string>split(string s, char c = ' ') {
	vector<string>vec;
	string h = "";
	for (int i = 0; i < s.size();) {
		int j = i;
		while (j < s.size() && s[j] != ' ') {
			h += s[j++];
		}
		if (h.size() > 0) vec.push_back(h);
		h = "";
		i = j + 1;
	}
	return vec;
}
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
signed main() {
	string s;
	int k;
	cin >> s >> k;
	for (int i = 0; i < k; i++) {
		if (s[i] != '1') {
			cout << s[i] << endl;
			return 0;
		}
	}
	cout << 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
//using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
using pii=pair<ll,ll>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__);


int main(){
    dcl(k,t);
    vi c(t);
    rep(i,t)cin>>c[i];
    sort(rall(c));
    int ans=c[0]-accumulate(all(c),-c[0]);
    if(ans-1>0)cout<<ans-1<<endl;else cout<<0<<endl;
}


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

#define fastio {\
    ios::sync_with_stdio(0);\
    cin.tie(0);\
}

#define file {\
    freopen("io\\in.txt", "r", stdin);\
    freopen("io\\out.txt", "w", stdout);\
    freopen("io\\err.txt", "w", stderr);\
}

#ifdef LOCAL
#define debug(args...) {\
    string _s(#args);\
    replace(_s.begin(), _s.end(), ',', ' ');\
    stringstream _ss(_s);\
    istream_iterator<string> _it(_ss);\
    debug1(_it, args);\
}

#pragma GCC diagnostic ignored "-Wunused-parameter"
void debug1(istream_iterator<string> it) {
    cerr << endl;
}
#pragma GCC diagnostic pop

template<class T, class... Args>
void debug1(istream_iterator<string> it, T a, Args... args) {
    cerr << '>' << *it << " = " << a << "; ";
    debug1(++it, args...);
}
#else
#define debug(args...)
#define cerr if (false) cerr
#endif

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n)   for (int i = 0; i < n; i++)
#define dotc()      int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second

const int inf(0x3fffffff);
const int mod(1000000007);
const double pi(acos(-1.0));

signed main() {
    fastio;
#ifdef LOCAL
    file;
#endif

    int n;
    cin >> n;
    vi a(n);
    map<int, int> m;
    rep(i, n) {
        cin >> a[i];
        m[a[i]]++;
    }

    ll c = 0;
    for (auto& i : m) {
        c += 1ll * i.se * (i.se - 1) / 2;
    }

    rep(i, n) {
        cout << c - m[a[i]] + 1 << '\n';
    }

    return 0;
}


Measured memory_bytes: 10080
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int n = s.length();
    char[] ss = new char[n];
    int i;
    int total = 0;
    for(i=0;i<n;i++){
      ss[i] = s.charAt(i);
    }    
    for(i=0;i<n-1;i++){
      if(ss[i]!=ss[i+1]){
        continue;
      }else{
        total = total + 1;
        if(ss[i+1]=='0'){
          ss[i+1]='1';
          continue;
        }else{
          ss[i+1]='0';
          continue;
        }
      }
    }
    System.out.println(total); 
 }
}

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

using namespace std;

struct Node {
  int p, l, r;
  Node(int p = -1, int l = -1, int r = -1): p(p), l(l), r(r) {}
};

vector<Node> v;
vector<int> D;

void getDepth(int u, int d) {
  D[u] = d;
  if (v[u].r != -1) {
    getDepth(v[u].r, d);
  }
  if (v[u].l != -1) {
    getDepth(v[u].l, d + 1);
  }
}

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

  v.resize(n);
  D.resize(n);
  
  int id, k, c, a;
  for (int i = 0; i < n; i++) {
    cin >> id >> k;
    for (int j = 0; j < k; j++) {
      cin >> c;
      if (j) {
        v[a].r = c;
      } else {
        v[id].l = c;
      }
      v[c].p = id;
      a = c;
    }
  }

  int r;
  for (int i = 0; i < n; i++) {
    if (v[i].p == -1) {
      r = i;
    }
  }

  getDepth(r, 0);

  for (int i = 0; i < n; i++) {
    cout << "node " << i << ": ";
    cout << "parent = " << v[i].p << ", ";
    cout << "depth = " << D[i] << ", ";
    
    if (v[i].p == -1) {
      cout << "root, ";
    } else if (v[i].l == -1) {
      cout << "leaf, ";
    } else {
      cout << "internal node, ";
    }

    cout << "[";
    if (v[i].l != -1) {
      for (int j = v[i].l; j != -1; j = v[j].r) {
        if (j != v[i].l) {
          cout << ", ";
        }
        cout << j;
      }
    }
    cout << "]\n";
  }

  return 0;
}


Measured memory_bytes: 7484
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;



public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   List<String> list = new ArrayList<>();
   for(int i=0; i<N; i++) {
	   list.add(sc.next());
   }
   Collections.sort(list);
   boolean flag = true;
   for(int i=0; i<list.size()-1; i++) {
   if(list.get(i).equals(list.get(i+1))) {
	   flag = false;
	   break;
   }
   }
   if(flag == true) {
       System.out.print("YES");
   }else {
	   System.out.print("NO");
   }
  }
 }



Measured memory_bytes: 71880
N = int(input())
lis = []
for i in range(N):
    lis.append(list(map(int,input().split())))
lis = sorted(lis, key = lambda x:x[1])
a = 0
for j in range(N):
    a += lis[j][0]
    if a > lis[j][1]:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 55256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

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

  string S;
  cin >> S;

  vector<long long> cnt(200);
  for (int i = 0; i < N; i++) {
    cnt.at(S.at(i))++;
  }

  long long ans = 1;
  for (int i = 0; i < 200; i++) {
    if(cnt.at(i) == 0) continue;
    cnt.at(i)++;
    ans *= cnt.at(i);
    ans %= MOD;
  }

  cout << ans - 1 << endl;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	ll x, cnt;
	cin >> x;
	cnt = 2 * (x / 11);
	x %= 11;
	if (0 < x && x <= 6) cnt++;
	else if (x != 0) cnt += 2;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 20000000
#define mod 1000000007
#define INF2 1000000000000000000

int dp[41][410][410];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    int a[41], b[41], c[41];
    rep(i, N) {
        cin >> a[i] >> b[i] >> c[i];
    }
    rep(i, 41) rep(j, 410) rep(k, 410) dp[i][j][k] = INF;
    dp[0][0][0] = 0;
    rep(i, N) {
        REP(j, 0, 400) {
            REP(k, 0, 400) {
                dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
                if (j - a[i] >= 0 && k - b[i] >= 0) {
                    dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
                }
            }
        }
    }
    int ans = INF;
    REP(j, 1, 400) {
        REP(k, 1, 400) {
            if (j * Mb == k * Ma) {
                ans = min(ans, dp[N][j][k]);
            }
        }
    }
    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 27136
import sys

tmp = list(sys.stdin.readline().strip())
nums = list(map(int, tmp))

for a in range(2):
    for b in range(2):
        for c in range(2):
            tmp = nums[0]
            exp = str(nums[0])
            if a == 0:
                tmp += nums[1]
                exp += "+"
            else:
                tmp -= nums[1]
                exp += "-"
            exp += str(nums[1])
            if b == 0:
                tmp += nums[2]
                exp += "+"
            else:
                tmp -= nums[2]
                exp += "-"
            exp += str(nums[2])
            if c == 0:
                tmp += nums[3]
                exp += "+"
            else:
                tmp -= nums[3]
                exp += "-"
            exp += str(nums[3])
            if tmp == 7:
                print(exp + "=7")
                sys.exit()

Measured memory_bytes: 9220
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rep2(i,s,t) for(int i = s; i <= t; ++i)
#define rev(i,n) for(int i = n-1; i >= 0; --i)
#define rev1(i,n) for(int i = n; i > 0; --i)
#define rev2(i,s,t) for(int i = s; i >= t; --i)
#define F first
#define S second
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
template <typename F,typename T>
struct SegTree{
  // 二項演算merge,単位元identify
  T identity;
  F merge; 
  int size;
  vector<T> dat;
  
  // 二項演算fと単位元idを渡して宣言する
  SegTree(F f,T id):merge(f),identity(id){}

  // データの要素の数nを渡して初期化、sizeはnより大きい2の冪乗
  void init(int n){
    size = 1;
    while(size<=n) size *= 2;
    dat.resize(size*2-1,identity);
  }

  // 配列を渡して0(n)で初期化
  void build(vector<T> vec){
    rep(i,vec.size()) dat[size-1+i] = vec[i];
    dfs(0);
  }
  
  T dfs(int k){
    if(k>=size-1) return dat[k];
    else return dat[k] = merge(dfs(2*k+1),dfs(2*k+2));
  }

  // index kの要素をaに変更
  void update(int k,T a){
    k += size - 1;
    dat[k] += a;
    while(k > 0){
      k = (k-1)/2;
      dat[k] = merge(dat[2*k+1],dat[2*k+2]);
    }
  }

  // 区間[a,b)に対するクエリに答える。(k,l,r)=(0,0,size)
  T query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return identity;
    
    if(a<=l&&r<=b) return dat[k]; 
    else return merge(query(a,b,2*k+1,l,(l+r)/2),query(a,b,2*k+2,(l+r)/2,r));
  }
  
  void show(){
    int index = 0;
    int num = 1;
    while(index<size){
      rep(i,num){
	if(dat[i+index]==identity) cout << "e ";
	else cout << dat[i+index] << " ";
      }
      cout << "\n";
      num *= 2;
      index = index*2+1;
    }
  }
  
};

int main()
{
  int n,q; scanf("%d %d", &n, &q);
  vl a(n); rep(i,n) scanf("%lld", &a[i]);
  auto f = [](ll a, ll b){ return a+b;};
  ll id = 0;
  SegTree<decltype(f), ll> seg(f, id);
  seg.init(n);
  seg.build(a);
  while(q-- > 0) {
    ll t, x, y; scanf("%lld %lld %lld", &t, &x, &y);
    if(t == 0) {
      seg.update(x, y);
    }
    else {
      printf("%lld\n", seg.query(x, y, 0, 0, seg.size));
    }
  }
  return 0;
}


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

#define ff first
#define ss second

typedef long long ll;
typedef pair<ll,ll> pL;

const int MX=200000;
const ll inf=1e9;
double interP[MX];
pL st[MX];
int top;

double intersect(pL a, pL b)
{
    return (b.ss-a.ss+0.0)/(a.ff-b.ff);
}
void insert(pL candidate)
{
    while(top>0 && intersect(st[top-1],st[top])>= intersect(st[top-1],candidate)) top--;
    st[++top]=candidate;
    interP[top]=intersect(st[top-1],candidate);
}
ll Q(ll x)
{
    int up=upper_bound(interP+1,interP+top+1,x)-interP-1;
    return st[up].ff*(x)+st[up].ss;
}

//for minimam candidate = {inf,0}, for maximum candidate = {-inf,0}

void init(pL candidate={inf,0}, double base = -inf)
{
    top=0;
    st[0]=candidate;
    interP[0]=base;
    insert({0,0});    //inserting {0,dp[0]}
}

ll h[MX], dp[MX];

int main()
{

    ll n, c;
    cin>>n>>c;
    init();

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

    insert({-2*h[0], h[0]*h[0]});
    for(int i=1; i<n; i++)
    {
       dp[i]=Q(h[i])+c+h[i]*h[i];
       insert({-2*h[i],h[i]*h[i]+dp[i]});
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


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

d=[]
for i in range(n):
    d.append(list(map(int,input().split())))

dd=sorted(d)   
ans=0
for i in range(n):
    if dd[i][1]<m:
        ans+=dd[i][0]*dd[i][1]
        m-=dd[i][1]
    
    else:
        ans+=int(dd[i][0]*m)
        print(ans)
        exit()

Measured memory_bytes: 28656
X, N = map(int, input().split())

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

tmp = 1

if X not in PList or N == 0:
    print(X)

else:
    while 'true':
        if X - tmp not in PList:
            print(X - tmp)
            break
        elif X + tmp not in PList:
            print(X + tmp)
            break
        else:
            tmp += 1

Measured memory_bytes: 9184
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 101010;
int main(){
	 
	 int total;
	 int n=2000000000;
	 cin>>total;
	 int a,b;
	 for(int i=0;i<total;i++){
	 	cin>>a>>b;
	 	if(a+b<n)n=a+b;
	 }
	 cout<<n;
	return 0;
} 

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

int main()
{
    int H, W;
    cin >> H >> W;
    char map[55][55];
    for (int y = 0; y < H; ++y)
    {
        for (int x = 0; x < W; ++x)
        {
            cin >> map[y][x];
        }
    }

    int YY[8] = {0, 0, 1, -1, 1, 1, -1, -1};
    int XX[8] = {1, -1, 0, 0, 1, -1, 1, -1};
    int yy, xx, ct;
    for (int y = 0; y < H; ++y)
    {
        for (int x = 0; x < W; ++x)
        {
            if (map[y][x] != '#')
            {
                ct = 0;
                for (int i = 0; i < 8; ++i)
                {
                    yy = y + YY[i];
                    xx = x + XX[i];
                    if (0 <= yy && yy < H && 0 <= xx && xx < W) if (map[yy][xx] == '#') ct++;
                }
                map[y][x] = '0' + ct;
            }
        }
    }
    for (int y = 0; y < H; ++y)
    {
        for (int x = 0; x < W; ++x)
        {
            cout << map[y][x];
        }
        cout << endl;
    }

    return 0;
}


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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 1e5 + 10;

struct UF{
	vector<int> UNF;
	vector<int> Ans;
	vector<ll> Sum;
	UF(int n, int a[], int b[]) {
		UNF = vector<int>(n, 0);
		Ans = vector<int>(n, 0);
		Sum = vector<ll>(n, 0);
		for(int i=0; i<n; i++) UNF[i] = i;
		for(int i=0; i<n; i++) Ans[i] = max(0, a[i] - b[i]);
		for(int i=0; i<n; i++) Sum[i] = b[i];
	}
	int F(int v) {return UNF[v] == v ? v : UNF[v] = F(UNF[v]);}
	bool U(int a, int b, int Ab, int Bb) { // b have bigger A[]
		a = F(a); b = F(b);
		if(a == b) return false;
		UNF[a] = b;
		Sum[b] += Sum[a];
		int ans = Ans[a];
		if(Ans[a] + Sum[a] >= max(0, Ab - Bb)) Ans[b] = min(Ans[b], Ans[a]);
		else Ans[b] = min(1ll * Ans[b], Ans[a] + (max(0, Ab - Bb) - Ans[a] - Sum[a]));
		return true;
	}
};
struct ND{
	int ix, a, b;
	ND(int ix_, int a_, int b_) : ix(ix_), a(a_), b(b_) {}
};
int N, M;
int A[MAX_N], B[MAX_N];
vector<ND> Ns;
vector<int> Ed[MAX_N];

int main() {
	scanf("%d%d", &N, &M);
	for(int i=0; i<N; i++) {
		scanf("%d%d", &A[i], &B[i]);
		Ns.emplace_back(i, A[i], B[i]);
	}
	sort(ALL(Ns), [&](ND &x, ND &y) {return max(0, x.a-x.b) < max(0, y.a-y.b);});
	for(int i=0; i<M; i++) {
		int x, y; scanf("%d%d", &x, &y); x--; y--;
		Ed[x].push_back(y);
		Ed[y].push_back(x);
	}
	
	UF uf = UF(N, A, B);
	vector<bool> vis(N, false);
	for(int n=0; n<N; n++) {
		int v = Ns[n].ix, a = Ns[n].a, b = Ns[n].b;
		for(int w : Ed[v]) if(vis[w]) uf.U(w, v, A[v], B[v]);
		//printf("v %d : Ans %d Sum %lld\n", v, uf.Ans[v], uf.Sum[v]);
		vis[v] = true;
	}
	printf("%lld\n", uf.Ans[uf.F(0)] + uf.Sum[uf.F(0)]);
	return 0;
}


Measured memory_bytes: 9460
#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	S = []
	for i in range(N):
		s = input()
		S.append(s)
	ans = 0
	for k in range(N):
		judge = "Yes"
		for i in range(N):
			for j in range(N):
				if S[i][(j + k) % N] != S[j][(i + k) % N]:
					judge = "No"
					break
		if judge == "Yes":
			ans += 1
	print(ans * N)

if __name__ == '__main__':
	main()

Measured memory_bytes: 40432
#include<iostream>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if((a+b)%2) cout<<(a+b)/2+1<<endl;
    else cout<<(a+b)/2<<endl;
    return 0;
}


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

int main(){
  int a[3][3];
  rep(i,3) rep(j,3) cin >> a[i][j];
  bool f=true;
  rep(i,2){
    if(a[0][i]-a[1][i]!=a[0][i+1]-a[1][i+1]) f=false;
    if(a[1][i]-a[2][i]!=a[1][i+1]-a[2][i+1]) f=false;
    if(a[i][0]-a[i][1]!=a[i+1][0]-a[i+1][1]) f=false;
    if(a[i][1]-a[i][2]!=a[i+1][1]-a[i+1][2]) f=false;
  }
  if(f) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
#include <cmath>
#include <numeric>
using namespace std;

int inf = (1 << 30);
int mod = 1e9 + 7;
int64_t inf64 = (1LL << 60);
int64_t mod64 = 1e9 + 7;

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    int N, M;
    cin >> N >> M;
    vector<int64_t> a(M);
    for(int i = 0; i < M; i++) cin >> a[i];

    vector<int64_t> fib(N + 10); fib[0] = 0; fib[1] = 1;
    for(int i = 2; i < fib.size(); i++){
        fib[i] = fib[i - 1] + fib[i - 2];
        fib[i] %= mod64;
    }

    // error
    for(int i = 0; i < M - 1; i++){
        if(a[i + 1] - a[i] == 1){
            cout << 0 << endl;
            return 0;
        }
    }
    if(M == 0){
        cout << fib[N + 1] << endl;
        return 0;
    }

    int64_t state = 0;
    int64_t ans = 1;
    for(int i = 0; i < M; i++){

        ans *= fib[a[i] - state];
        
        state = a[i] + 1;
        ans %= mod64;
    }

    ans *= fib[N + 1 - state];
    ans %= mod64;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k;cin>>k;
  if(k%2==0) print(-1);
  else {
    ll ans=-1,num=7,rem;
    for(ll i=1;i<1e7;++i) {
      rem+=num;
      if(rem%k==0) {ans=i;break;}
      else num=(num*10)%k;
    }
    print(ans);
  }
  return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
using namespace std;
string str,in;
char t[200];
int I;
int l,r,pos;
int main(){
  cin>>I;
  while(I--){
    cin>>str;
    l=100;
    r=100;
    t[100]=str[0];
    pos=100;

    for(int i=1;i<(int)str.size();i+=3){
      in=str.substr(i,3);

      if(in[0]=='<'){
	pos--;
	t[pos]=in[2];
	l=min(l,pos);
      }else{
	pos++;
	t[pos]=in[2];
	r=max(r,pos);
      }

    }
    
    for(int i=l;i<=r;i++){
      cout<<t[i];
    }
    cout<<endl;
    
  }
  return 0;
}

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

#define INF 1000000007
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define ppb pop_back
#define vll vector<ll>
#define vi vector<int>
#define endl << "\n" ;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--){
		ll n,k;
		cin >> n >> k;
		ll ans=n%k;
		ans = min(ans,k-ans);
		cout << ans endl
	}
	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 rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N, C, K;
    cin >> N >> C >> K;
    vector<ll> T(N);
    rep(i,N)cin >> T[i];
    sort(all(T));
    int r = 0;
    int ans = 0;
    for(int l = 0; l < N;){
        while(r < N && r+1 - l + 1 <= C && T[r+1] <= T[l] + K){
            r++;
        }
        l = r+1;
        ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){
	int N;
	scanf("%d", &N);
	int x = 0;
	for (int i = 0; i < N; i++) {
		int aux;
		scanf("%d", &aux);
		if (aux % 2 == 0) {
			if (aux % 3 == 0 || aux % 5 == 0) {
				x++;
			}
		} else {
			x++;
		}
 	}
 	if (x == N) {
 		printf("APPROVED\n");
 	} else {
 		printf("DENIED\n");
 	}
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, k;
int a[200];
signed main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; i + j <= n; j++) {
			//左からi個選ぶ
			//右からj個取り出す
			if (i + j > k) break;
			priority_queue<int, vector<int>, greater<int>>p;
			int sum = 0;
			for (int z = 0; z < i; z++) {
				p.push(a[z]);
				sum += a[z];
			}
			for (int z = n - 1; z >= n - j; z--) {
				p.push(a[z]);
				sum += a[z];
			}
			chmax(ans, sum);
			int t = i + j;
			while (t < k && !p.empty() && p.top() < 0) {
				sum -= p.top();
				p.pop();
				t++;
				chmax(ans, sum);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	int d = c - (a - b);
	cout << (d < 0 ? 0 : d) << endl;
}

Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String str = br.readLine();
        String str1 = br.readLine();
        for(int i = 0;i < n;i++){
            boolean flag = true;
            for(int j = 0;j + i < n;j++){
                if(str1.charAt(j) == str.charAt(j + i))continue;
                flag = false;
                break;
            }
            if(flag){
                System.out.println(n + i);
                return;
            }
        }
        System.out.print(2*n);
    }
}

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

#define MOD 1000000007

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const vector<vector<T>>&obj) {
    o << "[" << endl; for (int i = 0; i < (int)obj.size(); ++i) o << "  " << obj[i] << endl; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const queue<T>&obj) {
    queue<T> obj_cp = obj;
    bool first = true;
    o << "{";
    while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; }
    o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}


int main(int argc, char const *argv[]) {
    ll A;
    string B_str;
    cin >> A >> B_str;
    ll B_ = stoi(B_str.substr(0, 1)) * 100 + stoi(B_str.substr(2, 2));
    // print(A, B_);

    cout << (A * B_) / 100 << endl;

    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    vector<pair<ll, ll>> reds(n);
    rep(i, n) {
        ll a, b; cin >> a >> b;
        reds[i] = make_pair(a, b);
    }
    vector<pair<ll, ll>> blues(n);
    rep(i, n) {
        ll c, d; cin >> c >> d;
        blues[i] = make_pair(c, d);
    }
    sort(all(blues));
    ll count = 0;
    vector<bool> used(n, false);
    rep(i, n) {
        auto blue = blues[i];
        ll max_y = -inf;
        ll max_index = -1;
        for (ll j = n-1; j >= 0; j--) {
            auto red = reds[j];
            if (used[j]) continue;
            if (red.first < blue.first) {
                if (red.second < blue.second && red.second > max_y) {
                    max_y = red.second;
                    max_index = j;
                }
            }
        }

        if (max_y > -inf) {
            count++;
            used[max_index] = true;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>
    #include<cstdint>

    #define INF 1e7
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;

    int main(){
       int a,b;cin>>a>>b;
       if(a<=2*b)cout<<0;
       else cout<<a-2*b;
    }
    


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int N;
ll H;
vector<ll> a, b;

int main(void){
	cin >> N >> H;
	REP(i, N){
		ll s, t;
		cin >> s >> t;
		a.push_back(s); b.push_back(t);
	}

	sort(all(a), greater<ll>());
	sort(all(b), greater<ll>());
	int cnt = 0;
	ll sum = 0;
	REP(i, b.size()){
		if(b[i] >= a[0]){
			cnt++;
			sum += b[i];
			if(sum >= H){
				cout << cnt << endl;
				return 0;
			}
		}else
			break;
	}
	cout << (H-sum+a[0]-1)/a[0]+cnt << endl;
}


Measured memory_bytes: 2036
N = int(input())
XYH = []
for n in range(N):
  x, y, h = [int(xyh) for xyh in input().split()]
  if h > 0:
    XYH.append([x, y, h])

l_XYH = len(XYH)

if l_XYH == 1:
  cx, cy, ans_H = XYH[0]
else:
  HH = []
  ans_H = 0
  for cx in range(0, 101):
    for cy in range(0, 101):
      for k in range(l_XYH):
        xk, yk, hk = XYH[k]
        H = hk + abs(xk - cx) + abs(yk - cy)
        if k < l_XYH - 1:
          HH.append(H)
        elif HH.count(H) == l_XYH - 1:
          ans_H = H
          break
        else:
          HH = []
          break
      else:
        continue
      if ans_H == H:
        break
    else:
      continue
    break

ans = str(cx) + " " + str(cy) + " " + str(ans_H)
print(ans)

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

int main() {
    int N;
    int a[3 * 100000];
    cin >> N;
    for (int i = 0; i < 3 * N; ++i) cin >> a[i];
  
    sort(a, a + 3 * N, greater<int>());
    long sum = 0;
    for (int i = 1; i <= N; ++i) {
      sum += a[i*2 - 1];
    }
    cout << sum << endl;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		sc.close();

		int cnt = 0;
		for (int i = Math.max(a, b); ; i--) {
			if (a % i == 0 && b % i == 0) {
				cnt++;
				if (cnt == k) {
					System.out.println(i);
					return;
				}
			}
		}
	}
}


Measured memory_bytes: 22608