akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;

const int MOD = (int) 1e9 + 7;

void sadd(int &a, int b)
{
    a += b;
    if (a >= MOD)
        a -= MOD;
}
int add(int a, int b)
{
    sadd(a, b);
    return a;
}
void ssub(int &a, int b)
{
    a -= b;
    if (a < 0)
        a += MOD;
}
int sub(int a, int b)
{
    ssub(a, b);
    return a;
}
int mul(int a, int b)
{
    return (a * 1LL * b) % MOD;
}


const int N = (int) 2e5 + 100;
const int MID = 2005;
const int SZ = MID * 2;

int a[N], b[N];

int dp[SZ][SZ];
int fact[2 * SZ], rfact[2 * SZ], ri[2 * SZ];

void init()
{
    fact[0] = rfact[0] = 1;
    ri[1] = 1;
    
    for (int i = 1; i < 2 * SZ; i++)
    {
        if (i != 1)
            ri[i] = sub(0, mul(ri[MOD % i], MOD / i));
        fact[i] = mul(fact[i - 1], i);
        rfact[i] = mul(rfact[i - 1], ri[i]);
    }
}

int C(int n, int k)
{
    if (k < 0 || k > n)
        return 0;
    return mul(fact[n], mul(rfact[k], rfact[n - k]));
}

int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    init();

    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d%d", &a[i], &b[i]);

    int ans = 0;
    for (int i = 0; i < n; i++)
        ssub(ans, C(2 * a[i] + 2 * b[i], 2 * a[i]));

    for (int i = 0; i < n; i++)
        sadd(dp[MID - a[i]][MID - b[i]], 1);

    for (int i = 0; i < SZ - 1; i++)
        for (int j = 0; j < SZ - 1; j++)
        {
            sadd(dp[i + 1][j], dp[i][j]);
            sadd(dp[i][j + 1], dp[i][j]);
        }

    for (int i = 0; i < n; i++)
        sadd(ans, dp[MID + a[i]][MID + b[i]]);

    ans = mul(ans, ri[2]);
    printf("%d\n", ans);

	return 0;
}




Measured memory_bytes: 64768
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sn = new Scanner(System.in);
        String S = sn.next();
        String T = sn.next();
        
        if(S.length() == T.length()-1){
            if(S.equals(T.substring(0, S.length()))){
                System.out.println("Yes");
            }else{System.out.println("No");}
        }else{System.out.println("No");}
    }
}

Measured memory_bytes: 35628
/************************************************
*Author        :  Jack
*Created Time  :  2019.10.27.20:04
*Mail          :  724033213@qq.com
*Problem       :  81
*Extra         :  
************************************************/
#include <bits/stdc++.h>
using namespace std;
int a;
int main() {
//    freopen("81.in","r",stdin);
//    freopen("81.out","w",stdout);
    cin >> a;
	int f = 0;
	for(int i = 1;i <= 9;i ++){
		if(a % i == 0 && a / i <= 9 && a / i >= 1)f = 1;
	}
	if(f == 1){
		printf("Yes\n");
	} else {
		printf("No\n");
	}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int now = 0;
    for(int i=0; ; i++) {
        int sum = i*(i+1)/2;
        if(sum >= X) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
a,b,k = map(int,input().split())
li = []
if a > b:
	for i in range(a):
		if (a % (i+1) == 0) & (b % (i+1) == 0):
			li.append(i+1)
else:
	for j in range(b):
		if (a % (j+1) == 0) & (b % (j+1) == 0):
			li.append(j+1)
li.sort(reverse=True)
print(li[k-1])

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

typedef long long int ll;
typedef long int li;

const ll mod = 1000000007;
const ll inf = 1000000000000000000;

typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vli> vvli;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef map<ll, ll> mll;
typedef map<ll, string> mls;
typedef map<string, ll> msl;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#pragma GCC optimize ("-O3")
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
#define PI 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define all(v) v.begin(), v.end()
#define FOR(i, j, k, in) for(li i=j; i<k; i+=in)
#define RFOR(i, j, k, de) for(li i=j; i>=k; i-=de)
#define rep(i,j,k) FOR(i, j, k, 1)
#define rrep(i,j,k) RFOR(i, j, k, 1)
#define repc(v) for(auto it=v.begin(); it!=v.end(); it++)
#define T ll t; cin>>t; while(t--)

ll gen(){
    ll temp;
    cin>>temp;
    return temp;
}

int main(){
  FAST

  ll n,a;
  cin>>n;
  ll mp[n]={0};
  rep(i,0,n-1){
  	cin>>a;
    mp[a-1]++;
  }
  
    rep(i,0,n)
    cout<<mp[i]<<"\n";

  
  return 0;
}







Measured memory_bytes: 5180
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	class Pair implements Comparable<Pair>{
		int x;
		int y;
		Pair(int x, int y){
			this.x=x;
			this.y=y;
		}
		@Override
		public int compareTo(Pair o) {
			if(this.y==o.y) {
				return Integer.compare(o.x, this.x);
			}
			return Integer.compare(this.y, o.y);
		}


	}
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		ArrayList<Pair> a = new ArrayList<>();
		for(int i=0; i<m; i++) {
			a.add(new Pair(sc.nextInt(), sc.nextInt()));
		}

		Collections.sort(a);

		int t=-1;
		int cnt=0;
		for(int i=0; i<m; i++) {
			Pair p = a.get(i);
			if(t<=p.x) {
				cnt++;
				t=p.y;
			}
		}
		System.out.println(cnt);
		sc.close();
	}


}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> vec){ return (ll)vec.size(); }
ll sz(string s){ return (ll)s.size(); }

ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }


int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll> vec[m+1];
    ll a[n],b[n];
    rep(i,0,n){
        cin >> a[i] >> b[i];
        if(m-a[i] >= 0) vec[m-a[i]].push_back(i);
    }

    priority_queue<ll, llVEC> pq;
    ll ans = 0;
    rrep(i,0,m+1){
        rep(j,0,sz(vec[i])){
            pq.push(b[vec[i][j]]);
        }
        if(!pq.empty()){
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10312
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
int main() {
  int N;
  int sumA = 0;
  int sumB = 0;
  cin >> N;
  vector<int> vec(N);

  for(int i=0;i<N;i++){
      cin >> vec.at(i);
  }

  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
//   for(int i=0;i<N;i++){
//       cout << vec.at(i) << endl;
//   }
  for(int j=0;j<N;j++){
    if(j%2==0)
        sumA += vec.at(j);
    else
        sumB += vec.at(j);

  }
  cout << sumA -sumB << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int H, W; cin >> H >> W;
    vector<vector<int>> coins(H+2, vector<int>(W+2, -1));
    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            cin >> coins[i][j];
        }
    }
    int cnt = 0;
    vector<vector<int>> res;
    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            if(coins[i][j]%2 == 0) continue;
            bool r = false, d = false;
            if(coins[i+1][j] != -1 && coins[i+1][j]%2 == 1) d = true;
            if(coins[i][j+1] != -1 && coins[i][j+1]%2 == 1) r = true;            

            if(d){
                cnt++;
                coins[i+1][j]++; coins[i][j]--;
                res.push_back({i, j, i+1, j});
            }else if(r){
                cnt++;
                coins[i][j+1]++; coins[i][j]--;
                res.push_back({i, j, i, j+1});             
            }else if(coins[i+1][j] != -1){
                cnt++;
                coins[i+1][j]++; coins[i][j]--;
                res.push_back({i, j, i+1, j});                
            }else if(coins[i][j+1] != -1){
                cnt++;
                coins[i][j+1]++; coins[i][j]--;
                res.push_back({i, j, i, j+1});                     
            }
        }
    }
    cout << cnt << ln;
    for(vector<int> v: res){
        cout << v[0] << " " << v[1] << " " << v[2] << " " << v[3] << ln;
    }    
}

Measured memory_bytes: 9904
import sys

class Node():
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left, self.right = None, None

def insert(z):
    global root
    x, y = root, None
    while x:
        y = x
        if z < x.key:
            x = x.left
        else:
            x = x.right
    
    if y == None:
        root = Node(z)
    elif z < y.key:
        y.left = Node(z)
    else:
        y.right = Node(z)
        
def find(z):
    global root
    x, y = root, None
    while x:
        y = x
        if z < x.key:
            x = x.left
        elif z > x.key:
            x = x.right
        else:
            print("yes")
            return
    print("no")
        
def preorder(x):
    return f" {x.key}" + preorder(x.left) + preorder(x.right) if x else ""

def inorder(x):
    return inorder(x.left) + f" {x.key}" + inorder(x.right) if x else ""
        
input()
root = None
for s in sys.stdin:
    if s[0] == "p":
        print(inorder(root))
        print(preorder(root))
    elif s[0] == "f":
        find(int(s[5:]))
    else:
        insert(int(s[7:]))


Measured memory_bytes: 55688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& ai : a) cin >> ai;
    auto b = a;
    sort(all(a));
    for (auto& bi : b) out(a[n / 2 - (bi >= a[n / 2])]);
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int MAX = 2e5+1;

bool ok = true;
vector<vector<int>> g;
vector<ll> a;

ll go(int u, int p) {
    ll sum = 0;
    bool leaf = true;
    vector<ll> d(g[u].size());
    for(int i = 0; i < g[u].size(); i++) {
        int v = g[u][i];
        if(v != p) {
            leaf = false;
            d[i] = go(v, u);
            sum += d[i];
        }
    }
//    cout << u << " - " << sum << endl;
    if(leaf || (p == -1 && g[u].size() == 1)) {
        if(p == -1) ok &= sum == a[u];
        return a[u];
    }
    ll r = 2*a[u] - sum;
//    cout << u << " " << r << " " << sum << endl;
    if(p != -1) ok &= r >= 0;
    if(p != -1) sum += r;
    ok &= sum == 2*a[u];
    ok &= sum % 2 == 0;
    for(int i = 0; i < g[u].size(); i++) {
        ok &= d[i] <= sum/2;
    }
    ok &= r <= sum/2;
    return r;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif

    int n; cin >> n;
    g.assign(n+1, vector<int>());
    a.assign(n+1, 0);

    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    for(int i = 1; i < n; i++) {
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    go(1, -1);

    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;

}


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

int main()
{
    int n;
    cin >> n;
    int maxItem = 0;
    int maxItemIndex = -1;
    int secondMaxItem = 0;

    for (int i = 0; i < n; ++i)
    {
        int input;
        cin >> input;

        if (maxItem < input)
        {
            maxItem = input;
            maxItemIndex = i;
        }
        else
        {
            secondMaxItem = max(input, secondMaxItem);
        }
    }

    if (secondMaxItem == 0)
        secondMaxItem = maxItem;

    for (int i = 0; i < n; ++i)
    {
        if (i != maxItemIndex)
        {
            cout << maxItem << endl;
        }
        else
        {
            cout << secondMaxItem << endl;
        }
    }
}

Measured memory_bytes: 1664
require 'prime'
require 'set'

lr = Array.new(gets.chomp.to_i) { gets.chomp.split.map(&:to_i) }
primes = Set.new(Prime.each(10 ** 5).to_a)

sums = Array.new(10 ** 5 + 1, 0).tap do |y|
  (1..10**5).each do |i|
    y[i] = y[i-1] + (primes.include?(i) && primes.include?((i+1)/2) ? 1 : 0)
  end
end

lr.each do |l, r|
  puts sums[r] - sums[l-1]
end


Measured memory_bytes: 11860
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define io ios_base::sync_with_stdio(false); cin.tie(0);

#define fs first
#define sc second
#define pb push_back

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef pair<int, int> pii;
typedef vector<int> vi;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef long double ld;

const ll LINF = 1e18;
const int INF = 1e9;
const ld EPS = 1e-9;
const int MOD = 1e9+7;

/// Scanf para ler char array separado por espacos -> scanf(" %[^\n]", texto);
 
////////////////////////// Solution starts below. //////////////////////////////

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

int main(){

	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		dp[i] = INF;
		scanf("%d", &v[i]);
	}
	dp[1] = 0;
	for(int i = 2; i <= n; i++){
		dp[i] = min(dp[i], dp[i-1] + abs(v[i-1] - v[i]));
		if(i >= 3){
			dp[i] = min(dp[i], dp[i-2] + abs(v[i-2]-v[i]));
		} 
	}
	printf("%d", dp[n]);
	return 0;
}

Measured memory_bytes: 1024
#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;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


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/abc045/tasks/arc061_a

int main() {
    string S; cin >> S;
    int len = S.length();

    ll ans = 0;
    for (int mask = 0; mask < 1 << (len-1); mask++) {
        ll num = S[0] - '0';
        for (int i = 0; i < len-1; i++) {
            if (mask & 1 << i) {
                ans += num;
                num = 0;
            }
            num = num*10 + (S[i+1] - '0');
        }
        ans += num;
    }

    cout << ans << "\n";

    return 0;
}


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

int main(){
    int N;
    cin >> N;
    string s[N];
    map<string,int> card;
    for(int i=0;i<N;++i) {
        cin >> s[i];
        card[s[i]] += 1;
    }
    int M;
    cin >> M;
    string t[M];
    for(int i=0;i<M;++i) {
        cin >> t[i];
        card[t[i]] -= 1;
    }
    int max = 0;
    for(auto i=card.begin();i!=card.end();++i) {
        if (max<= i->second) max = i->second;
    }
    cout << max << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace::std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define endl "\n"
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
#include <boost/any.hpp>
using namespace::std;
namespace mp = boost::multiprecision;
typedef mp::number<mp::cpp_dec_float<32,int64_t>> cfloat;
typedef mp::cpp_int cint;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
typedef vector<pair<lint,lint>> pvec;
typedef vector<vector<pair<lint,lint>>> pmat;
typedef vector<vector<vector<pair<lint,lint>>>> pmat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"");if(i>INF/2)cout<<"INF";else cout<<i;f=1;}cout<<"\n";}while(0)
#define output2(v) for(auto j:v)output(j);
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define SUM(v) accumulate(all(v),0LL)
#define INF (1LL<<60)
#define IINF (1<<30)
#define LINF 9223372036854775807
#define MOD 1000000007
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
inline lint lcm(lint a,lint b){return a*b/gcd(a,b);}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
inline lint mex(vector<lint> s){
    lint res=0;
    sort(all(s));
    while(binary_search(all(s),res))res++;
    return res;
}
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};
int main(){
    lint n;
    cin>>n;
    vec a(n);
    rep(i,n)cin>>a[i];
    rep(i,n-1)a[i+1]+=a[i];
    lint ans=INF;
    rep(i,n-1){
        lint mn=INF,mn2=INF;
        auto itr=lower_bound(a.begin(),a.begin()+i+1,a[i]*0.5);
        auto itr2=lower_bound(a.begin()+i+1,a.end(),(a[i]+a[n-1])*0.5);
        if(itr<a.begin()+i+1)chmin(mn,abs((*itr)*2-a[i]));
        if(itr>a.begin())chmin(mn,abs(a[i]-*(itr-1)*2));
        if(itr2<a.end())chmin(mn2,abs((*itr2)*2-(a[n-1]+a[i])));
        if(itr2>a.begin()+i+1)chmin(mn2,abs((a[n-1]+a[i])-*(itr2-1)*2));
        chmin(ans,max({(abs(a[i]*2-a[n-1])+mn+mn2)/2,mn,mn2}));
    }
    cout<<ans;
}

Measured memory_bytes: 1792
#include<iostream>  
#include<cstdio>  
#include<cmath>  
using namespace std;  
  
struct Card {  
    char suit, value;  
};  
  
void bubble(struct Card A[], int n) {  
  
    int flag = 1;  
    for (int i = 0; flag; i++) {  
        flag = 0;  
        for (int j = n - 1; j >= i + 1; j--) {  
            if (A[j].value < A[j - 1].value) {  
                swap(A[j], A[j - 1]);  
                flag = 1;  
            }  
        }  
    }  
}  
void selection(struct Card A[], int n) {  
    for (int i = 0; i < n; i++) {  
        int minj = i;  
        for (int j = i; j < n; j++) {  
            if (A[j].value < A[minj].value)  
                minj = j;  
        }  
        if (i != minj)  
            swap(A[i], A[minj]);  
    }  
}  
  
bool isStable(struct Card C1[], struct Card C2[], int n) {  
    for (int i = 0; i < n; i++) {  
        if (C1[i].suit != C2[i].suit)  
            return false;  
    }  
    return true;  
}  
  
void print(struct Card C[], int n) {  
    for (int i = 0; i < n; i++) {  
        printf("%c%c%c", C[i].suit, C[i].value, i == n - 1 ? '\n' : ' ');  
    }  
}  
int main() {  
    Card C1[100], C2[100];  
    int n;  
  
    scanf("%d", &n);  
    getchar();  
    for (int i = 0; i < n; i++) {  
        scanf("%c%c", &C1[i].suit, &C1[i].value);  
        getchar();  
        C2[i] = C1[i];  
    }  
    bubble(C1, n);  
    selection(C2, n);  
  
    print(C1, n);  
    printf("Stable\n");  
    print(C2, n);  
    if (isStable(C1, C2, n))  
        printf("Stable\n");  
    else  
        printf("Not stable\n");  
  
    return 0;  
}  




Measured memory_bytes: 3204
S = input()

s = list(S)
s2 = []

ans = [0]*len(s)
countR = 1
countL = 1
mae = s[0]

for i in range(1,len(s)):
    if mae == 'R' and s[i] == 'R':
        countR += 1
    elif mae == 'L' and s[i] == 'L':
        countL += 1
    elif mae == 'R' and s[i] == 'L':
        s2.append(countR)
        countR = 1
    elif mae == 'L' and s[i] == 'R':
        s2.append(countL)
        countL = 1
    mae = s[i]

s2.append(countL)
now = 0

for i in range(1,len(s)):
    if s[i-1] == 'R' and s[i] == 'L':
        if (s2[now] + s2[now+1]) % 2 == 0:
            ans[i-1] += int((s2[now] + s2[now+1]) / 2)
            ans[i] += int((s2[now] + s2[now+1]) / 2)
        else:
            if s2[now] % 2 != 0:
                ans[i-1] += int((s2[now] + s2[now+1] + 1) / 2)
                ans[i] += int((s2[now] + s2[now+1] - 1) / 2)
            else:
                ans[i-1] += int((s2[now] + s2[now+1] - 1) / 2)
                ans[i] += int((s2[now] + s2[now+1] + 1) / 2)
        now += 2



print(' '.join(map(str, ans)))

Measured memory_bytes: 12056
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ld = long double;
// constexpr auto mod = 1000000007;
using namespace std;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) { cin >> A[i]; }

  vector<ll> cs(N + 1, 0);
  cs[0] = 0;
  for (int i = 1; i <= N; i++) {
    cs[i] = cs[i - 1] + A[i - 1];
  }
  map<ll, ll> m;
  for (int i = 0; i <= N; i++) {
    m[cs[i]] = m[cs[i]] + 1;
  }
  ll answer = 0;
  for (const auto &kv : m) {
    const auto v = kv.second;
    if (v >= 2) {
      answer += v * (v - 1) / 2;
    }
  }
  cout << answer << endl;
  return 0;
}


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

using namespace std;

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

    int n, k;
    cin >> n >> k;

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

    sort(a.begin(), a.end(), greater<int>());

    int sum = 0;
    for(int i=0; i<k; i++) sum += a[i];
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <climits>
#include <cmath>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <stack>
#include <bitset>
using namespace std;
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define fi first
#define se second
#define ll long long
#define ii pair<int, int>
int f[10005];

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	//freopen("Test.inp", "r", stdin);
	//freopen("RATING.out", "w", stdout);
	int h, n;
	cin >> h >> n;
	vector <ii> a(n);
	for (ii &i : a) cin >> i.first >> i.second;
	f[0] = 0;
	rep(i, 1, h) f[i] = INT_MAX;
	rep(i, 1, h) {
		for (ii j : a) {
			f[i] = min(f[i], f[max(0, i - j.fi)] + j.se);
		}
	}
	cout << f[h];
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
    char str[20],copy_str[20];
    int count_str,i,j;
    scanf("%s",str);
    count_str=strlen(str);
    for(i=0,j=count_str;i<count_str;i++,j--){
        copy_str[i]=str[j-1];
    }
    copy_str[count_str]='\0';
    printf("%s\n",copy_str);
    return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,i,ans=0,maxv=100000000000000000,sum=0;
	cin>>n;
	int a[n+1];
	memset(a,0,sizeof(a));
	for(i=1;i<=n;i++)
	cin>>a[i];
	sort(a,a+n+1);
    for(i=1;i<=10000;i++)
    {
    	for(int j=1;j<=n;j++)
    	{
    		if(a[j]<i)
    		sum=sum+(i-a[j])*(i-a[j]);
    		else
    		sum=sum+(a[j]-i)*(a[j]-i);
		}
		if(sum<maxv)
		maxv=sum;
		sum=0;
	 }
	 ans=maxv;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
main :: IO ()
main = do 
  n <- getLine
  let time = read n :: Int
  putStrLn $ show ( hour time ) ++ ":" ++ show (minute time)  ++ ":" ++ show (second time) 


hour :: Int -> Int
hour time = time `div` 3600

minute :: Int -> Int
minute time = (time - (hour time) * 3600 ) `div` 60

second :: Int -> Int
second time = time `mod` 60

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <vector>
using namespace std;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;
	
	return 0;
}

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

int main() {
    init();

    int n; cin >> n;
    vector<vector<pair<int, int>>> g(n);
    FOR(i, 0, n - 1) {
        int a, b; cin >> a >> b;
        --a, --b;
        g[a].push_back({ b, i });
        g[b].push_back({ a, i });
    }

    VI x(n, -1);
    VI ans(n - 1, -1);
    vector<map<int, bool>> used(n);
    vector<bool> ever(n);
    queue<int> bfs;
    bfs.push(0);
    while (!bfs.empty()) {
        int now = bfs.front(); bfs.pop();
        ever[now] = true;
        for (auto next : g[now]) {
            int to, num; tie(to, num) = next;
            if (ever[to])continue;
            for (int i = x[now] + 1;; ++i) {
                if (used[now][i])continue;
                used[now][i] = true;
                used[to][i] = true;
                ans[num] = i;
                x[now] = i;
                bfs.push(to);
                break;
            }
        }
    }

    map<int, int> m;
    FOR(i, 0, n - 1)++m[ans[i]];
    cout << m.size() << "\n";
    FOR(i, 0, n - 1)cout << ans[i] + 1 << "\n";
}


Measured memory_bytes: 21376
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    long long sum=0;
    int a[n];
    long long x[100001]={};
    for(int i=0;i<n;i++){
        cin>>a[i];
        x[a[i]]++;
        sum+=a[i];
    }
    int q;
    cin>>q;
    int b[q],c[q];
    for(int i=0;i<q;i++)cin>>b[i]>>c[i];
    for(int i=0;i<q;i++){
        sum+=(c[i]-b[i])*x[b[i]];
        x[c[i]]+=x[b[i]];
        x[b[i]]=0;
        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 5520
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define per(i,n) for ((i)=n;(i)>=(1);(i)--)
using namespace std;
int n,na,nb,nc,ta,tb,typ[100005];
long long a[100005],b[100005],c[1000005],ans;
priority_queue<pair<long long,int> > qa,qb,qab,qba;
int main()
{
	int i;
	scanf("%d%d%d",&na,&nb,&nc);n=na+nb+nc;
	rep(i,n){scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);ans+=c[i];a[i]-=c[i];b[i]-=c[i];}
	rep(i,n){qa.push(make_pair(a[i],i));qb.push(make_pair(b[i],i));}
	rep(i,na+nb)
	{
		long long ss=-0x3f3f3f3f3f3f3f3fll,way=0;
		while(!qa.empty()&&typ[qa.top().second]!=0) qa.pop();
		while(!qb.empty()&&typ[qb.top().second]!=0) qb.pop();
		while(!qab.empty()&&typ[qab.top().second]!=1) qab.pop();
		while(!qba.empty()&&typ[qba.top().second]!=2) qba.pop();
		if(ta<na&&!qa.empty())
		{
			if(qa.top().first>ss){ss=qa.top().first;way=1;}
		}
		if(tb<nb&&!qb.empty())
		{
			if(qb.top().first>ss){ss=qb.top().first;way=2;}
		}
		if(tb<nb&&!qab.empty()&&!qa.empty())
		{
			if(qab.top().first+qa.top().first>ss){ss=qab.top().first+qa.top().first;way=3;}
		}
		if(ta<na&&!qba.empty()&&!qb.empty())
		{
			if(qba.top().first+qb.top().first>ss){ss=qba.top().first+qb.top().first;way=4;}
		}
		ans+=ss;
		if(way==1)
		{
			int t=qa.top().second;qa.pop();
			typ[t]=1;ta++;
			b[t]-=a[t];a[t]=0;
			qab.push(make_pair(b[t],t));
		}
		if(way==2)
		{
			int t=qb.top().second;qb.pop();
			typ[t]=2;tb++;
			a[t]-=b[t];b[t]=0;
			qba.push(make_pair(a[t],t));
		}
		if(way==3)
		{
			int t;
			t=qab.top().second;qab.pop();
			typ[t]=2;tb++;
			a[t]-=b[t];b[t]=0;
			qba.push(make_pair(a[t],t));
			
			t=qa.top().second;qa.pop();
			typ[t]=1;
			b[t]-=a[t];a[t]=0;
			qab.push(make_pair(b[t],t));
		}
		if(way==4)
		{
			int t;
			t=qba.top().second;qba.pop();
			typ[t]=1;ta++;
			b[t]-=a[t];a[t]=0;
			qab.push(make_pair(b[t],t));
			
			t=qb.top().second;qb.pop();
			typ[t]=2;
			a[t]-=b[t];b[t]=0;
			qba.push(make_pair(a[t],t));
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11492
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int w,h,n;
  cin>>w>>h>>n;
  int field[h][w]={};
  for(int i=0;i<n;i++){
    int x,y,a;
    cin>>x>>y>>a;
    if(a==1){
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if(x>j) field[i][j]++;
        }
      }
    }
    if(a==2){
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if(x<=j) field[i][j]++;
        }
      }
    }
    if(a==3){
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if(y>i) field[i][j]++;
        }
      }
    }
    if(a==4){
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if(y<=i) field[i][j]++;
        }
      }
    }
  }
  int ans=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(field[i][j]==0) ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
  int a, b, c, count = 0;
  scanf("%d %d %d", &a, &b, &c);

  for (int i = a; i <= b; i++)
  {
    if (c % i == 0)
    {
      count++;
    }
  }
  printf("%d\n", count);

  return 0;
}


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

int main() {
int n;
  cin>>n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);}
  long long s=0;
    for(int i=0;i<n-1;i++){
      if(vec.at(i)>vec.at(i+1)){
      int t=vec.at(i)-vec.at(i+1);
          vec.at(i+1)+=t;
        s+=t;}}
      cout<<s<<endl;}
  

Measured memory_bytes: 4052
#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>
#include<numeric>
#include<cassert>

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

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); 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()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int n;
int c[50];
int memo[2000+1];

int normal(int money){
  int ret = 0;
  for(int i = n - 1; i >= 0; i--){
    ret += money / c[i];
    money %= c[i];
    if(money == 0) break;
  }
  return ret;
}

int main(){
  int cc = 0;
  while(n = getInt()){
    bool pay = true;
    bool greedy = true;

    printf("Case #%d: ",++cc);

    REP(i,n) c[i] = getInt();
    sort(c, c+n);

    if(c[0] != 1){
      puts("Cannot pay some amount");
      continue;
    }

    int mm = c[n-1] * 2 + 1;

    REP(i,mm) memo[i] = 0;
    queue<int> q;
    REP(i,n){ q.push(c[i]); memo[c[i]] = 1; }
    while(q.size()){
      int now = q.front(); q.pop();
      REP(i,n){
        if(now + c[i] >= mm) break;
        if(memo[now + c[i]]) continue;
        memo[now + c[i]] = memo[now] + 1;
        q.push(now + c[i]);
      }
    }

    rep(i,1,mm) if(memo[i] != normal(i)){
      puts("Cannot use greedy algorithm");
      goto end;
    }

    puts("OK");
  end:;
  }
  return 0;
}

Measured memory_bytes: 896
function Main(input){
	var N = input.trim();
	var l = N.length - 1;
	var lt = parseInt(N.substr(0,1));
	var rt = N.substr(1).match(/9/g);
	var ans;
	if(rt) rt = rt.length;
	else rt = -1;
	
	if(l === 0)ans = parseInt(N);
	else if(rt === l) ans = l * 9 + lt;
	else ans = l * 9 + lt - 1;
	
	console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
const Main = (input) => {
  const holidays = parseInt(input.split('\n')[0].trim().split(' ')[0])
  const tasks = input
    .split('\n')[1]
    .trim()
    .split(' ')
    .map((n) => parseInt(n))

  let sum = 0
  tasks.forEach((element) => {
    sum += element
  })

  let result
  result = holidays - sum

  if (result < 0) {
    result = -1
  }

  console.log(result)
  return result
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 30696
fn main() {
    let s = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s = s.trim_right().to_owned();
        s.chars().collect::<Vec<_>>()
    };

    let t = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s = s.trim_right().to_owned();
        s.chars().collect::<Vec<_>>()
    };

    let mut dp = vec![vec![0; t.len() + 1]; s.len() + 1];

    for i in 0..s.len() {
        for j in 0..t.len() {
            if s[i] == t[j] {
                dp[i + 1][j + 1] = std::cmp::max(dp[i + 1][j + 1], dp[i][j] + 1);
            }
            dp[i + 1][j + 1] = std::cmp::max(dp[i + 1][j + 1], dp[i + 1][j]);
            dp[i + 1][j + 1] = std::cmp::max(dp[i + 1][j + 1], dp[i][j + 1]);
        }
    }

    let mut r = String::new();
    let mut i = s.len();
    let mut j = t.len();

    while i > 0 && j > 0 {

        if dp[i][j] == dp[i - 1][j] {
            i -= 1;
            continue;
        }

        if dp[i][j] == dp[i][j - 1] {
            j -= 1;
            continue;
        }

        r.push(s[i - 1]);
        i -= 1;
        j -= 1;
    }

    unsafe {
        let vec = r.as_mut_vec();
        vec.reverse();
    }

    println!("{}", r);
}


Measured memory_bytes: 41212
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
  -- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative
import           Debug.Trace


readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons

main = do
  k <- readLn :: IO Int
  s <- getLine

  let ans = if (length s) <= k then s else (take k s) ++ "..."
  putStrLn ans


Measured memory_bytes: 3892
s = input()
ans = [0 for i in range(len(s)+1)]
for i in range(len(s)):
    if s[i:i+1] == "<":
        ans[i+1] = max(ans[i],ans[i]+1)
for i in range(len(s)):
    if s[len(s)-i-1:len(s)-i] == ">":
        ans[len(s)-i-1] = max(ans[len(s)-i-1],ans[len(s)-i]+1)
print(sum(ans))

Measured memory_bytes: 77388
#include <iostream>

using namespace std;

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

    int n_man, n_gosen, n_sen;
    for ( n_man=0; n_man<=N; n_man++ ) {
        for ( n_gosen=0; n_gosen<=N; n_gosen++ ) {
            n_sen = N - n_man - n_gosen;
            if ( n_sen < 0 )
                continue;
            if ( n_man * 10000 + n_gosen * 5000 + n_sen * 1000 == Y ) {
                cout << n_man << " " << n_gosen << " " << n_sen << endl;
                goto END;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
END:
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,x,l[100],ans=1,cnt=0;
  cin >> n >> x;
  for(int i=0; i<n; i++) {
    cin >> l[i];
  }
  for(int i=0; i<n; i++) {
    cnt+=l[i];
    if(cnt<=x) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

#define M 1000000007
#define INF 999999999
#define EPS 1e-9
#define pb push_back
#define mp make_pair
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
 #define MAX 100005
using namespace std;
 typedef pair<int,int> ii;
 typedef vector <ii> vii;
 typedef vector <int> vi;
 typedef long long int ll;

int main()
{
//  freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);

 ll n;
 cin>>n;
 ll num,c=0;
 int arr[1000];
 arr[1]=0;
 for(int i=2;i<=n;i++)
 {
    num = i;
    c=0;
    while(num%2==0)
        c++,num/=2;
    arr[i]=c;
 }
 int maxx=-1,ind;
 for(int i=1;i<=n;i++)
 {
    //cout<<arr[i]<<" ";
    if(maxx<arr[i])
        ind= i,maxx=arr[i];
 }
 cout<<ind<<endl;
return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm> 
#include <cmath>
//#include <bitset>
//#include <deque>
#include <iterator>
#include <map> 
//#include <queue>
//#include <stack>
#include <string>
#include <vector>
#include <array>
//#include <tuple>
#include <unordered_map>
//#include <unordered_set>

using namespace std;

typedef long long ll;
struct __{__(){ios_base::Init i;ios_base::sync_with_stdio(0);cin.tie(0);}}__; 



int main() {
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	string ans = "";
	string z = "abcdefghijklmnopqrstuvwxyz";
	for (int i = 0; i < 26; ++i) {
		int minn = 1e9 + 7;
		for (int j = 0; j < n; ++j) {
			int p = 0;
			for (int k = 0; k < (int)s[j].size(); ++k) {
				if (s[j][k] == z[i]) {
					p++;
				}
			}
			minn = min(minn,p);
		}
		for (int j = 0; j < minn; ++j) {
			ans += z[i];
		}
	}
	cout << ans;
} 











Measured memory_bytes: 3656
#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>

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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 mo 998244353
#define inf 1000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define eps 0.000001
#define ms 16
#define endl '\n'

 
using namespace std ;
 
#define N 400005

typedef tree<lli,null_type,less<lli>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

lli ans[10001],ptr=0;
vll c;
vll v[10001];
bool vis[10001];

void dfs(lli q)
{
    vis[q]=1;
    ans[q]=c[ptr];
    ptr++;

    for(auto x:v[q])
    {
        if(!vis[x])
            dfs(x);
    }

}

int main()
{
    
///////////////////////////////////////////
    fastio;

    lli n;
    cin>>n;

    loopl(i,0,n-1)
    {
        lli x,y;
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

    lli sum=0;
    loopl(i,0,n) 
    {
        lli x;
        cin>>x;
        sum+=x;
        c.pb(x);
    }

    sort(c.begin(),c.end());
    reverse(c.begin(),c.end());

    sum-=c[0];
    dfs(1);

    cout<<sum<<endl;

    loopl(i,1,n+1)
    cout<<ans[i]<<" ";



}

Measured memory_bytes: 1536
import sys
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]

print(((ri()) ** 2) * 3)

Measured memory_bytes: 38256
N = gets.to_i
A = gets.split(" ").map(&:to_i)
cnt=flg=0
while flg == 0
  N.times do |i|
    if A[i-1] %2 != 0
      flg = 1
      break
    else
  	  A[i-1] = A[i-1] /2
    end
    cnt += 1 if N-1 == i
  end
end
puts cnt 

Measured memory_bytes: 1788
// Sky's the limit :)
#include<bits/stdc++.h>
using namespace std;
#define int long long

const int N = 4e5 + 5;
int n;
int a[N], b[N], c[N];

bool solve(int k) {
	int x = (1 << k);
	for(int i = 0; i < n; i++)
		c[i] = b[i] % (2 * x);
	sort(c, c + n);

	bool f = 0;
	for(int i = 0; i < n; i++)
    {
        int y = a[i] % (2 * x);
        int l = lower_bound(c, c + n, x - y) - c;
        int r = lower_bound(c, c + n, 2 * x - y) - c - 1;

        if(l <= r)
            f ^= (r - l + 1) & 1;

        l = lower_bound(c, c + n, 3 * x - y) - c;
        r = lower_bound(c, c + n, 4 * x - y) - c - 1;
        if(l <= r)
            f ^= (r - l + 1) & 1;
    }
	return f;
}

signed main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    //int t = 1; cin >> t; while(t--)
    {
    	cin >> n;
    	for(int i = 0; i < n; i++)
    		cin >> a[i];
    	for(int i = 0; i < n; i++)
    		cin >> b[i];

    	int ans = 0;
    	for(int i = 0; i < 30; i++) {
    		if(solve(i))
    			ans |= (1 << i);
    	}

    	cout << ans << '\n';

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



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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int a[3];

int main() {
	inc(i, 3) { cin >> a[i]; }
	
	sort(a, a + 3);
	
	cout << a[2] - a[0] << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define SF scanf
#define PF printf
#define MAXN 300010
#define INF 0x3FFFFFFF
#define MOD 998244353
using namespace std;
typedef long long ll;
typedef map<ll,ll>::iterator mit;
int n,q;
ll qx[MAXN];
map<ll,ll> mp;
ll used[MAXN];
int main(){
	SF("%d%d",&n,&q);
	if(q==0){
		for(int i=1;i<=n;i++)
			PF("1\n");
		return 0;	
	}
	for(int i=1;i<=q;i++)
		SF("%lld",&qx[i]);
	mp[qx[q]]++;
	qx[0]=n;
	for(int i=q-1;i>=0;i--){
		while(mp.rbegin()->first>qx[i]){
			mit it=mp.end();
			it--;	
			mp[it->first%qx[i]]+=it->second;
			mp[qx[i]]+=it->second*(it->first/qx[i]);
			mp.erase(it);
		}
	}
	mit it=mp.begin();
	for(;it!=mp.end();it++)
		used[it->first]+=it->second;
	for(int i=n;i>=1;i--)
		used[i]=used[i]+used[i+1];
	for(int i=1;i<=n;i++)
		PF("%lld\n",used[i]);
}

Measured memory_bytes: 10624
#[allow(dead_code)]
fn main() {
    let n: u32 = read();
    println!("{}", n *n * n);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0054
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line)) return;

                int[] items = Array.ConvertAll(line.Trim().Split(' '), e => int.Parse(e));
                string div = (items[0] / (decimal)items[1] - Math.Floor(items[0] / (decimal)items[1])).ToString("0." + new string('0',100)).Replace("0.","");

                Console.WriteLine(div.Take(items[2]).Select(x => int.Parse(x.ToString())).Sum());
            }              
        }
    }

}



Measured memory_bytes: 14284