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

using namespace std;

typedef long long ll;
typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define contains(c, i) ((c).find(i) != (c).end())
#define present(i, c) (find(all(c), i) != (c).end())

#define rep(i, n) for(int i = 0; i < n; i++)
#define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e)))

#define dbg(x) cerr << #x << " = " << x << endl;
#define dbgall(x) cerr << #x << " = "; for(auto i_ : x) cerr << i_ << " "; cerr << endl;
#define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); }
void cerr_(istream_iterator<string> it) { (void) it; }
template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); }

template<class T, class S>  ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; }
template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }

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

const int MAXN = (int) 1e7;

vector<int> numdiv; 

void getnumdiv() {
    if(sz(numdiv) > 0) return;
    numdiv = vector<int>(MAXN+1, 2);
    numdiv[1] = 1;
    for(int i = 2; i <= MAXN; i += 1)
            for(int j = i + i; j <= MAXN; j += i)
                numdiv[j]++;
}

void run_test() {
    int n; cin >> n;
    getnumdiv();
    ll ans = 0;
    repa(k, 1, n+1) ans += (ll) k * numdiv[k];
    cout << ans << endl;
}

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

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); }
	// int t_; cin >> t_; while(t_--) run_test();
	run_test();
	return 0;	
}


Measured memory_bytes: 42240
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

pub fn bsearch<F>(ok: i64, ng: i64, pred: F) -> Option<i64>
where
    F: Fn(i64) -> bool,
{
    let orig_ok = ok;
    let mut ok = ok;
    let mut ng = ng;
    while (ok - ng).abs() > 1 {
        let mid = (ok + ng) / 2;
        if pred(mid) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    if ok == orig_ok {
        None
    } else {
        Some(ok)
    }
}

fn solve() {
    input! {
        n: usize, m: usize, k: usize,
        av:[usize; n],
        bv:[usize; m],
    };

    let acusum = av
        .into_iter()
        .scan(0, |acc, x| {
            *acc += x;
            Some(*acc)
        })
        .collect::<Vec<_>>();
    let bcusum = bv
        .into_iter()
        .scan(0, |acc, x| {
            *acc += x;
            Some(*acc)
        })
        .collect::<Vec<_>>();
    let mut res = 0;
    for i in 0..=n {
        let asum = if i == 0 { 0 } else { acusum[i - 1] };
        if asum > k {
            continue;
        }
        let rest = k - asum;
        let j = bsearch(-1, m as i64, |x| {
            let x = x as usize;
            bcusum[x] <= rest
        });
        let sum = i + j.map(|j| j as usize + 1).unwrap_or(0);
        if sum > res {
            res = sum;
        }
    }
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 10952
word = gets.chomp
result = 0

loop do
    sentence = gets.chomp.split(" ").map do |s| s.to_s end
    if sentence[0] == "END_OF_TEXT"
        break
    else
        sentence.each do |n|
            if n.downcase == word
                result += 1
            end
        end
    end
end

puts result

Measured memory_bytes: 8632
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}

signed main() {
	int n;
	cin >> n;
	int a[100005];
	int mi = INF, ans = -1;
	rep(i, n) {
		cin >> a[i];
		if (a[i] < mi) {
			mi = a[i];
			ans = i + 1;
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3876
N, K = map(int, input().split())

if N%K == 0:
    print(0)

elif N<K and N<=K-N:
    print(N)

elif N<K and N>K-N:
    print(K-N)

elif N>K:
    if K-(N%K)>N%K:
        print(N%K)
    else:
        print(K-(N%K))


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

ll calc_pow(ll x, ll y) {
    ll z = 1;
    while (y > 0) {
        if (y & 1) {
            z *= x;
        }
        x *= x;
        y /= 2;
    }
    return z;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll cumsum = 1;
    ll len = 1;
    ll pow = 26;
    while (true) {
        if (N >= cumsum && N < cumsum + pow) {
            break;
        }
        ++len;
        cumsum += pow;
        pow *= 26;
    }
    string ans;
    rep(i, 0, len) {
        ll cnt = calc_pow(26, len - i - 1);
        rep(j, 0, 26) {
            if (N < cumsum + cnt) {
                ans += 'a' + j;
                break;
            } else {
                cumsum += cnt;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long LL;

#define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; i++)
#define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; i--)

template <typename Tp> void in(Tp &x) {
	char ch = getchar(), f = 1; x = 0;
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') ch = getchar(), f = -1;
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= f;
}

template <typename Tp> void out(Tp x) {
	if (x > 9) out(x / 10);
	putchar(x % 10 + '0');
	return;
}

template <typename Tp> Tp Max(const Tp &x, const Tp &y) {return x > y ? x : y;}
template <typename Tp> Tp Min(const Tp &x, const Tp &y) {return x < y ? x : y;}
template <typename Tp> bool chkmax(Tp &x, Tp y) {return x >= y ? 0 : (x=y, 1);}
template <typename Tp> bool chkmin(Tp &x, Tp y) {return x <= y ? 0 : (x=y, 1);}

const int MAXN = 500010;

int n, q;
char s[MAXN];

int f[MAXN][30];
int nxt[MAXN][30];

int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);

	FOR(i, 1, n) s[i] = s[i] - 'a';

	memset(f, 0x3f, sizeof f);
	
	DNF(i, n, 1) {
		f[i][s[i]] = i;
		for (int j = s[i] + 1; j <= 26; j++) {
			if (f[i][j - 1] == 0x3f3f3f3f) break;
			f[i][j] = f[f[i][j - 1] + 1][j - 1];
		}
		if (f[i][26] != 0x3f3f3f3f)
			for (int j = 0; j < s[i]; j++)
				f[i][j] = f[f[i][26] + 1][j];
	}

	memset(nxt, 0x3f, sizeof nxt);
	
	DNF(i, n, 1) {
		nxt[i][0] = f[i][26];
		for (int j = 1; nxt[i][j - 1] != 0x3f3f3f3f; j++) {
			nxt[i][j] = nxt[nxt[i][j - 1] + 1][j - 1];
		}
	}
	
	in(q);
	while (q--) {
		int l, r; in(l); in(r);
		DNF(i, 29, 0) if (nxt[l][i] <= r) l = nxt[l][i] + 1;
		if (l == r + 1) puts("Yes");
		else puts("No");
	}
	
	return 0;
}


Measured memory_bytes: 118272
H,W,A,B=map(int,input().split())
Ans=[["0"]*W for _ in range(H)]
if B>0:
    for i in range(A, W):
        for j in range(B):
            Ans[j][i]="1"
if A>0:
    for i in range(A):
        for j in range(B,H):
            Ans[j][i]="1"
for a in Ans:
    moji="".join(a)
    print(moji)

Measured memory_bytes: 48624
x, y = map(int, input().split())
abs_x = abs(x)
abs_y = abs(y)

if 0 <= x < y:
    print (y - x)
    exit()
if 0 < y < x:
    print (x - y + 2)
    exit()
if y == 0 and 0 < x:
    print (x + 1)
    exit()

if x < y <= 0:
    print (y - x)
    exit()
if y < x < 0:
    print (x - y + 2)
    exit()
if x == 0 and y < 0:
    print (abs_y + 1)
    
if x < 0  < y:
    print (abs(abs_y - abs_x) + 1)
    exit()
if y < 0 < x:
    print (abs(abs_y - abs_x) + 1)
    exit()




Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;
int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
    stack<int> S;
    S.push(r);
    color[r] = c;
    while ( !S.empty() ) {
        int u = S.top();
        S.pop();
        for ( int i = 0; i < G[u].size(); i++ ){
            int v = G[u][i];
            if ( color[v] == NIL ) {
                color[v] = c; S.push(v);
            }
            
        }
    }
        }

void assignColor() { int id = 1;
    for(int i=0; i<n; i++) color[i]=NIL;
    for(int u=0; u<n; u++){
        if(color[u] ==NIL) dfs(u,id++);
    }
    }

int main() {
    int s, t, m, q;
    cin >> n >> m;

    for ( int i = 0; i<m; i++){
         cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
         }
    assignColor();
    cin >> q;
    
         for ( int i = 0; i < q; i++ ) {
             cin >> s >> t;
             if ( color[s] == color[t] ) {
                 cout << "yes" << endl;
                 
             } else {
                     cout << "no" << endl;
                 
             }
         }
         return 0;
    
}



Measured memory_bytes: 8932
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


N, K = lmi()
tmp = N % K

print(min(abs(tmp - K), tmp))


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    ll S = 0;
    for (int i=0; i<N; i++) {
        cin >> A.at(i);
        S += A.at(i);
    }
    vector<int> X(N);
    X.at(0) = S;
    for (int i=1; i<N; i += 2) X.at(0) -= 2*A.at(i);
    cout << X.at(0);
    for (int i=1; i<N; i++) {
        X.at(i) = 2*A.at(i-1) - X.at(i-1);
        cout << " " << X.at(i);
    }
    cout << endl;
}

Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <cstring>

const int N = 1e6+100;
char s[N];
void solve(){
    scanf("%s", s+1);
    s[0] = 0;
    int n = strlen(s+1), p = 0;
    for(int i = 1; i <= n; i++) s[i] = (s[i]-'0')*9;
    for(int i = n; i > 0; i--){
        s[i-1] += s[i]/10;
        s[i] %= 10;
        p += s[i];
    }
    int x = 10-s[n];
    s[n] += x;
    p += (x);
    p += (s[0]);
    while(1){
         for(int i = n; i > 0; i--) {
            if(s[i] > 9){
                p -= 9;
                s[i-1]++;
                s[i] -= 10;
            }
            else break;
         }
         if(p <= x) {
            int ans = x / 9; if(x%9) ans++;
            printf("%d\n", ans);
            return;
        }
        s[n] += 10;
        p += 10;
        x += 10;
    }   return;
}

int main(){
    int t; //scanf("%d", &t);
    t = 1;
    while(t--) {
        solve();
    }
    return 0;
}



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

const int MAXN = 100010;
typedef long long LL;
struct node {
	int v, bel, typ;
	bool operator < (const node & b) const { return v < b.v; }
} ps[MAXN << 1];
int bak;
int A[MAXN], B[MAXN];
int n;
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) {
		std::cin >> A[i] >> B[i];
		ps[++bak] = (node) {A[i], i, 0};
		ps[++bak] = (node) {B[i], i, 1};
	}
	std::sort(ps + 1, ps + 1 + bak);
	auto solve = [] () {
		static bool app[MAXN][2];
		memset(app, 0, sizeof app);
		int C[2] = {0, 0};
		for (int i = 1; i <= n; ++i) {
			++C[ps[i].typ];
			app[ps[i].bel][ps[i].typ] = true;
		}
		bool can = false;
		for (int i = 1; i <= n; ++i)
			can |= app[i][0] && app[i][1];
		if (can || C[0] == n || C[1] == n) return 
			std::accumulate(ps + 1, ps + 1 + n, 0ll, [] (LL x, node a) {
				return x + a.v;
			});
		return std::numeric_limits<LL>::max();
	};
	LL ans = solve();
	std::swap(ps[n], ps[n + 1]);
	ans = std::min(ans, solve());
	std::swap(ps[n], ps[n + 2]);
	ans = std::min(ans, solve());
	std::swap(ps[n], ps[n + 2]);
	std::swap(ps[n], ps[n + 1]);
	std::swap(ps[n - 1], ps[n + 1]);
	ans = std::min(ans, solve());
	std::cout << ans << std::endl;
	return 0;
}


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

int main() {
	int n,m,x,y;
	bool nowar=true;
	cin>>n>>m>>x>>y;
	int xinv[n+1],yinv[m+1];
	for(int i=0;i<n;i++){
	    cin>>xinv[i];
	    xinv[n]=x;
	}
	for(int j=0;j<m;j++){
	    cin>>yinv[j];
	    yinv[m]=y;
	}
	for(int k=0;k<=n;k++){
	    for(int l=0;l<=m;l++){
	        if(xinv[k]>=yinv[l])nowar=false;
	    }
	}
	if(nowar)cout<<"No War";
	else cout<<"War";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e5 + 5;
const ll MOD = 1e9 + 7;
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pis pair<ll,string>
#define F first
#define S second
#define LCM(a,b) ((a*b)/__gcd(a,b))
#define inf 1e15
#define test ll cse;cin>>cse;for(ll _i=1;_i<=cse;_i++)
#define PI 3.14159265
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const double EPS = 1E-9;
typedef vector< vector<double> > matrix;
typedef vector<int> vi;


int ar[N];
int main() {
    fast;

    string s, t;
    cin >> s;
    cin >> t;

    int n = s.size();
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        if( s[i] != t[i]) cnt++;
    }

    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 3764
#include<cstdio>

using namespace std;

int main(){
	int x1, y1, x2, y2; scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
	int dx = x2 - x1, dy = y2 - y1;
	int x3 = x2 - dy, y3 = y2 + dx;
	int x4 = x3 - dx, y4 = y3 - dy;
	printf("%d %d %d %d\n", x3, y3, x4, y4);
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define endl "\n"     
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=(1<<16)+5;

int n,a[17][17],cost[N],cache[N];

int dp(int mask)
{
     if(mask==0)
          return 0;
     int &ans=cache[mask];
     if(ans!=-1)
          return ans;
     vector <int> v;     
     for(int i=0;i<n;i++)
     {
          if(mask&(1<<i))
               v.pb(i);
     }
     int num=v.size();
     ans=-1e18;
     for(int i=0;i<(1<<num);i++)
     {
          int submask=0;
          for(int j=0;j<num;j++)
               if(i&(1<<j))
                    submask|=(1<<v[j]);
          ans=max(ans,cost[submask]+dp(mask & (~submask)));     
     }
     return ans;
}

int32_t main()
{
     IOS;
     memset(cache,-1,sizeof cache);
     cin>>n;
     for(int i=0;i<n;i++)
     {
          for(int j=0;j<n;j++)
               cin>>a[i][j];
     }
     int total=(1<<n);
     for(int i=0;i<total;i++)
     {
          vector <int> v;
          for(int j=0;j<n;j++)
               if(i&(1<<j))
                    v.pb(j);
          int num=v.size();
          for(int j=0;j<num;j++)
          {
               for(int k=j;k<num;k++)
                    cost[i]+=a[v[j]][v[k]];
          }
     }
     total--;
     cout<<dp(total);
}


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

public class MainClass
{
	public static void Main(string[] args)
	{
		int[] anntenas = new int[5];
		for(int i = 0; i < anntenas.Length; i++)
		{
			string input = Console.ReadLine();
			anntenas[i] = int.Parse(input);
		}
		int k = int.Parse(Console.ReadLine());
		for(int i = 0; i < 5; i++)
		{
			for(int j = 0; j < 5; j++)
			{
				if(Math.Abs(anntenas[i]-anntenas[j]) > k) 
				{
					Console.WriteLine(":(");
					return;
				}
			}
		}
		Console.WriteLine("Yay!");
		
	}
	
	public static int Clamp(int val, int max, int min = 0)
	{
		return Math.Min(max, Math.Max(min, val));
	}


}

Measured memory_bytes: 11092
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[1010][1010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc;

int main(){
    cin>>y>>x>>b>>a;
    C max((y-b)*(x-a),ll(0)) E;
}

Measured memory_bytes: 256
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    ll n,m,i,j,cc=0,ans=100000LL;
    cin>>n>>m;
    j=n+2019;
    for(i=n;i<=min(j,m);i++){
        for(ll k=i+1;k<=min(j,m);k++){
            cc=(i*k)%2019;
            //cout<<cc<<endl;cout<<i<<spc<<j<<endl;
            ans=min(cc,ans);
        }
    }
    cout<<ans<<endl;
return 0;
}


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

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

int main()
{   
    int n, k;

    cin >> n >> k;
    vector<int> a(n);
    set<int> len;

    REP(i ,n){
        int A;
        cin >> A;

        a[A-1]++;
        len.insert(A);
    }

    sort(a.rbegin(), a.rend());
    a.resize(len.size());
    sort(a.begin(), a.end());

    int s = len.size();
    int cnt = 0;

    REP(i, a.size()){
        if (k >= s)  break;

        cnt += a[i];
        --s;
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 10368
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
#define N 100010
ll n,a[N];
vector<ll> e,v;
ll ans[N];
int main(){
  cin>>n;
  ll ma=0;
  a[0]=0; v.push_back(0); e.push_back(0);
  for(int i=1;i<=n;i++){
      cin>>a[i];
      v.push_back(a[i]);
      if(ma<a[i]){
	  ma=a[i];
	  e.push_back(i);
      }
      ans[i]=0;
  }
  sort(v.begin(),v.end());
  reverse(e.begin(),e.end());
  ll cnt=0;
  for(int i=0;i<e.size()-1;i++){
      ans[e[i]]+=cnt*(a[e[i]]-a[e[i+1]]);
      while(v.size()>0&&v.back()>=a[e[i+1]]){
	  cnt++;
	  ans[e[i]]+=v.back()-a[e[i+1]];
	  v.pop_back();
      }
  }
  for(int i=1;i<=n;i++)cout<<ans[i]<<endl;
  return 0;
}


Measured memory_bytes: 4460
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
  int n,z,w,i;
  int a[3000];
  scanf("%d%d%d",&n,&z,&w);
  for(i=1;i<=n;i++)
  {
     scanf("%d",&a[i]);
  }  
  int mmax=0;
  if(n==1) printf("%d\n",abs(a[1]-w));
  else
  {
    // for(i=1;i<n;i++)
   //  {
        mmax=max(mmax,abs(a[n]-a[n-1]));
   //  }
     mmax=max(mmax,abs(a[n]-w));
     printf("%d\n",mmax);
  }
}


Measured memory_bytes: 128
s = raw_input()
if len(s) < 26:
    l = [ chr(ord('a') + i) for i in range(26) ]
    for c in s:
        l.remove(c)
    print s + l[0]
else:
    l = []
    p = -1
    for i in range(25, 0,-1):
        l.append(s[i])
        if s[i-1] < s[i]:
            l.append(s[i-1])
            p = i-1
            break
    if p == -1:
        print -1
    else:
        l.sort()
        print s[:p] + l[l.index(s[p]) + 1]


Measured memory_bytes: 2568
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1 
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n = int(input())
ans = 0
for i in range(1,n+1,2):
    num = make_divisors(i)
    if len(num) == 8:
        ans += 1
print(ans)

Measured memory_bytes: 9140
#include<stdio.h>
int main(){
          int S,h,m,s,S1,S2;
          scanf("%d", &S);
          if(S>=3600){ 
                 h = S/3600;
                 S1 = S%3600;
          }else{
                 h=0;
                 S1 = S;
          }
          if(S1>=60){      
                 m = S1/60;
                 S2 = S1%60;
          }else{ 
                 m=0;
                 S2 = S1;
          } 
                s = S2%60;
                printf("%d:%d:%d\n", h, m, s);
          return 0;
}

Measured memory_bytes: 2664
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var H = input[0];
            var W = input[1];
            var N = ReadInt();
            var a = ReadArrayInt();
            var grid = new int[H, W];
            var idx = 0;
            for (int i = 0; i < H; i++)
            {
                if (i % 2 == 0)
                {
                    for (int j = 0; j < W; j++)
                    {
                        grid[i, j] = idx + 1;
                        a[idx]--;
                        if (a[idx] == 0) idx++;
                    }
                }
                else
                {
                    for (int j = W - 1; j >= 0; j--)
                    {
                        grid[i, j] = idx + 1;
                        a[idx]--;
                        if (a[idx] == 0) idx++;
                    }
                }
            }

            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    Console.Write(grid[i, j] + " ");
                }
                Console.WriteLine();
            }

            Console.WriteLine();
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 10000000000

int main() {
	char alpha;
	string ans;
	cin >> alpha;
	if (isupper(alpha)) ans = "A";
	else ans = "a";
	cout << ans;
	return 0;
}

Measured memory_bytes: 3604
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

int main(void){

    int N; cin>>N;

    vector<ll> MARCH(5,0);
    for (int i = 0; i < N; ++i) {
        string tmp; cin>>tmp;
        if(tmp[0]=='M') MARCH[0]++;
        if(tmp[0]=='A') MARCH[1]++;
        if(tmp[0]=='R') MARCH[2]++;
        if(tmp[0]=='C') MARCH[3]++;
        if(tmp[0]=='H') MARCH[4]++;
    }
    ll ans = 0;
    for (int i = 0; i < 3; ++i) {
        for (int j = i+1; j < 4; ++j) {
            for (int k = j+1; k < 5; ++k) {
               ans += MARCH[i]*MARCH[j]*MARCH[k];
            }
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
import Data.List
import Data.Maybe

data Record = Record Int Int Int deriving Eq

instance Ord Record where
 (<=) (Record tid1 pid1 pena1) (Record tid2 pid2 pena2)
  = pid1 > pid2 || (pid1 == pid2 && pena1 < pena2) || (pid1 == pid2 && pena1 == pena2 && tid1 < tid2)

instance Show Record where
 show (Record tid pid pena) = show tid ++ " " ++ show pid ++ " " ++ show pena

main = interact $ unlines . map (init . unlines . map show . record . judge) . read' . lines
 where
  read' ("0 0 0":_) = []
  read' (tpr:xs) = (t,p,logs) : read' xs'
   where
    [t,p,r] = map read (words tpr)
    (logs',xs') = splitAt r xs
    logs = map ((\[tid,pid,time,stat] -> (read tid, read pid, read time, stat)) . words) logs'
  record = sort . map (\(t,pr,pe,ws) -> Record t pr pe) 

judge (t,p,logs) = foldl' total initr logs
 where
  initr = [(tid,0,0,replicate p 0) | tid<-[1..t]]
  total acc (tid,pid,time,stat)
   | stat == "CORRECT" = let (t,pr,pe,ws) = query tid acc in (t,pr+1,pe+time+(ws!!(pid-1)*1200),ws) : (filter ((/=tid).fst') acc)
   | stat == "WRONG" = let (t,pr,pe,ws) = query tid acc in (t,pr,pe,wrong pid ws) : (filter ((/=tid).fst') acc)
   where
    wrong pid = map (\(i,n) -> if i==pid then n+1 else n) . zip [1..]
    query i = fromJust . find ((==i) . fst')
  fst' (x,_,_,_) = x

Measured memory_bytes: 6640
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<size_t I,class H,class...T>struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template<class H,class...T>struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class...T>istream&operator>>(istream&i,tuple<T...>&t){t=TupleReaderWriter<sizeof...(T),T...>::r(i);return i;}
template<class...T>ostream&operator<<(ostream&o,tuple<T...>&t){string delim=" ";TupleReaderWriter<sizeof...(T)-1,T...>::w(o,t,delim);return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }

// 最短距離、位置、出目
using Data = tuple<int, int, int>;

int main() {
    const int INF = 1e8;
    int N, M;
    cin >> N >> M;
    string S;
    cin >> S;
    vector<Data> v;
    set<Data> s;
    v.emplace_back(0, 0, 0);
    s.insert(v.back());
    for(int i = 1; i <= N; i++) {
        Data f;
        if(s.empty()) {
            f = make_tuple(INF, 0, 0);
        } else {
            f = *s.begin();
        }
        v.emplace_back(get<0>(f) + 1, i, i - get<1>(f));
        if (S[i] == '0') s.insert(v.back());
        if (M <= i) {
            s.erase(v[i - M]);
        }
    }
    if(get<0>(v[N]) >= INF) {
        cout << -1 << endl;
        return 0;
    }
    int t = N;
    vector<int> ans;
    while(t) {
        int d = get<2>(v[t]);
        ans.push_back(d);
        t -= d;
    }
    reverse(WHOLE(ans));
    cout << ans << endl;
    return 0;
}



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

int main() {
  int h, w;
  while (true) {
    cin >> h >> w;
    if (h == 0 & w == 0) break;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3080
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

class SegmentTree {
	int[] node;
	int d = 0;
	int n;

	public SegmentTree(int[] arr) {
		int s = arr.length;
		int m = 2;
		while (s > m) {
			m *= 2;
		}
		this.n = m;
		node = new int[2 * n - 1];

		Arrays.fill(node, d);
		System.arraycopy(arr, 0, node, n - 1, arr.length);
		for (int i = n - 2; i >= 0; i--) {
			node[i] = node[2 * i + 1] + node[2 * i + 2];
		}
	}

	public void add(int i, int val) {
		int x = n - 1 + i;
		node[x] += val;

		while (x > 0) {
			x = (x - 1) / 2;
			node[x] = node[2 * x + 1] + node[2 * x + 2];
		}

	}

	// [a,b) の合計を返す
	public int getSum(int a, int b) {
		return getSum(a, b, 0, 0, n);
	}

	private int getSum(int a, int b, int k, int l, int r) {
		// 範囲がかぶっていなければ、単位元を返す
		if (r <= a || l >= b) {
			return d;
		}

		// 範囲が一致していれば、node[k]を返す
		if (a <= l && r <= b) {
			return node[k];
		}

		int vl = getSum(a, b, 2 * k + 1, l, (r + l) / 2);
		int vr = getSum(a, b, 2 * k + 2, (r + l) / 2, r);
		return vl + vr;
	}

}

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int q = sc.nextInt();

		SegmentTree seg = new SegmentTree(new int[n]);

		for (int i = 0; i < q; i++) {
			int com = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();

			if (com == 0) {
				seg.add(x-1, y);
			} else { // com == 1
				int ans = seg.getSum(x-1, y);
				out.println(ans);
			}

		}

		sc.close();

	}

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



Measured memory_bytes: 105260
n,g=map(int,input().split())
ans=0
basis=1/n
if g==1:
  print(1)
  exit()
  
A=[1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072]

for i in range(1,n+1):
  A.append(g/i)
  A.sort()
  k=A.index(g/i)
  ans+=basis*(0.5**k)
  del A[k]
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<double,double> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const LL INF=1<<30;

LL a[50],b[50];
LL asum[51],bsum[51];
LL memo[51][51][51][51][2][3];
int n,m;

LL dfs(int l,int r,int i,int j,int c,int k,LL sum){
    if(k==3){
        return sum;
    }
    if(memo[l][r][i][j][c][k]!=LINF) return memo[l][r][i][j][c][k];
    if(!c){
        LL ret=-LINF;
        if(i==n) return memo[l][r][i][j][c][k]=sum+dfs(i,j,i,j,c^1,k+1,0);
        ret=max(ret,sum+dfs(i,j,i,j,c^1,k+1,0));
        if(a[i]==-1){
            ret=max(ret,dfs(l,j,i+1,j,c^1,0,sum+(bsum[j]-bsum[r])));
        }
        else{
            ret=max(ret,dfs(l,r,i+1,j,c^1,0,sum+a[i]));
        }
        return memo[l][r][i][j][c][k]=ret;
    }
    else{
        LL ret=LINF;
        if(j==m) return memo[l][r][i][j][c][k]=sum+dfs(i,j,i,j,c^1,k+1,0);
        ret=min(ret,sum+dfs(i,j,i,j,c^1,k+1,0));
        if(b[j]==-1){
            ret=min(ret,dfs(i,r,i,j+1,c^1,0,sum-(asum[i]-asum[l])));
        }
        else{
            ret=min(ret,dfs(l,r,i,j+1,c^1,0,sum-b[j]));
        }
        return memo[l][r][i][j][c][k]=ret;
    }
}

int main(){
    cin >> n >> m;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]==-1) asum[i+1]=asum[i];
        else asum[i+1]=a[i]+asum[i];
    }
    for(int i=0;i<m;i++){
        cin >> b[i];
        if(b[i]==-1) bsum[i+1]=bsum[i];
        bsum[i+1]=b[i]+bsum[i];
    }
    for(int c=0;c<2;c++){
        for(int i=0;i<51;i++){
            for(int j=0;j<51;j++){
                for(int l=0;l<51;l++){
                    for(int r=0;r<51;r++){
                        for(int k=0;k<3;k++){
                            memo[l][r][i][j][c][k]=LINF;
                        }
                    }
                }
            }
        }
    }
    cout << dfs(0,0,0,0,0,0,0) << endl;
    return 0;
}



Measured memory_bytes: 320260
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);
    string s;
    int N,tx,ty;
    cin >> s;
    cin >> tx >> ty;
    N = s.size();
    int nowx = 0,nowy = 0;
    // T が来たら xとyを入れ替えて
    int p = N;
    rep(i,N){
        if(s[i]=='F' && i < N)nowx++;
        else {
            p = i + 1; // s[i + 1]  から y軸に振っていく感じ
            break;
        }
    }
    vector<int> x,y;
    int now = 1; // now = 1 のとき y 方向に進む　now = 0 のとき x 方向に進む
    for(int i=p;i<N;i++){
        int cnt = 0;
        while(s[i]== 'F' && i<N){
            i++;
            cnt++;
        }
        if(now==1)y.push_back(cnt);
        else x.push_back(cnt);
        now = (now+1)%2;
    }
    vector<vector<bool>> xcan(x.size()+1,vector<bool>(16002));
    // xcan[i][j] := xをi番目まで見たときにjに行けたら 1
    // 今回はマイナスの座標も扱うので開始地点を8000にする
    // 
    xcan[0][8000+nowx] = 1;
    for(int i=0;i<x.size();i++){
        for(int j=0;j<16002;j++){
            if(xcan[i][j]){
                xcan[i+1][j+x[i]]=1;
                xcan[i+1][j-x[i]]=1;
            }
        }
    }

    vector<vector<bool>> ycan(y.size()+1,vector<bool>(16002));
    ycan[0][8000] = 1;
    for(int i=0;i<y.size();i++){
        for(int j=0;j<16002;j++){
            if(ycan[i][j]){
                ycan[i+1][j+y[i]]=1;
                ycan[i+1][j-y[i]]=1;
            }
        }
    }
    if(xcan[x.size()][tx+8000] &&  ycan[y.size()][ty+8000] )cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 16256
using System;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int[] ans = new int[S.Length];

            int idx = 0;
            char lastLetter = 'N';
            int index = 0;
            for (var i = 0; i < S.Length; i++)
            {
                // 前の文字と比較して計算量を減らす
                if (lastLetter == S[i])
                {
                    int distance = idx - i;
                    if (S[i] == 'R')
                    {
                        index = (distance % 2 == 0) ? idx : idx - 1;
                    }
                    else
                    {
                        index = (distance % 2 == 0) ? idx : idx + 1;
                    }
                    ans[index]++;
                    continue;
                }

                idx = i;
                if (S[i] == 'R')
                {
                    while (S[idx] != 'L')
                    {
                        idx++;
                    }
                    int distance = idx - i;
                    index = (distance % 2 == 0) ? idx : idx - 1;
                    ans[index]++;
                }
                else
                {
                    while (S[idx] != 'R')
                    {
                        idx--;
                    }
                    int distance = i - idx;
                    index = (distance % 2 == 0) ? idx : idx + 1;
                    ans[index]++;
                }
                lastLetter = S[i];
            }

            for (var i = 0; i < S.Length - 1; i++)
            {
                Console.Write($"{ans[i]} ");
            }
            Console.Write(ans[S.Length - 1]);
        }
    }
}


Measured memory_bytes: 15968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n,k;
    cin>>n>>k;
    int ans=0;
    while(n>0){
        ans++;
        n/=k;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n,w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]
dp = [[0]*(w+1) for _ in range(n)]

dp[0][wv[0][0]] = wv[0][1]

for i in range(1,n):
  for j in range(w+1):
    if j < wv[i][0]:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = max(dp[i-1][j-wv[i][0]]+wv[i][1],dp[i-1][j])
      
print(max(max(dp)))

Measured memory_bytes: 120044
#include <cstdio>
#define min(a,b) a>b ? b : a
int main(){
 
int a,b,c;
 
scanf("%d %d %d",&a,&b,&c);
 
int A,B,C;
 
A = a+b;
B = b+c;
C = a+c;
 
int ans = min(A,B);
printf("%d\n",min(ans,C));
 
 return 0;

}

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

int n;
vector<int> G[101];

void add_edge(int u, int v){
	G[u].push_back(v);
	G[v].push_back(u);
}

void dfs(int u, int cost, vector<bool> &visited, int &res){
	bool flag = false;
	res = max(res, cost);
	for(int i = 0; i < G[u].size(); i++){
		int v = G[u][i];
		if( !visited[v] ){
			visited[v] = true;
			dfs(v, cost + 1, visited, res);
			visited[v] = false;
			
		}
	}
}

int solve(const vector<int> &s){
	int res = 2;
	for(int v = 0; v < 101; v++){
		if( !s[v] ) continue;
		
		vector<bool> visited(101, false);
		visited[v] = true;
		dfs(v, 1, visited, res);
	}
	return res;
}

int main(){
	while( cin >> n, n ){
		for(int i = 0; i < 101; i++) G[i].clear();
		vector<int> s(101, 0);
		
		for(int i = 0; i < n; i++){
			int u, v;
			cin >> u >> v;
			add_edge(u, v);
			s[u] = s[v] = 1;
		}
		cout << solve(s) << endl;
	}
}

Measured memory_bytes: 1224
n,m,x = map(int,input().split())
li1 = []
li2 = []
for i in range(n):
    li1.append(list(map(int,input().split())))
for i in range(2**n):
    b = '0'*(n-len(bin(i))+2)+bin(i)[2:]
    total = 0
    li3 = [0]*m
    f = 1
    for j in range(n):
        if b[j] == "1":
            total += li1[j][0]
            for k in range(m):
                li3[k] += li1[j][k+1]
    for j in range(m):
        if li3[j] < x:
            f = 0
    if f == 1:
        li2.append(total)
if len(li2) >= 1:
    print(min(li2))
else:
    print(-1)

Measured memory_bytes: 9244
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */

    //#pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(int i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(int i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(int i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    #define te  ll ti;   cin >> ti;  while(ti--) solve();  
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 103000;

    void solve() {
      ll n, k, cnt=0;
      cin >> n >> k;
      ll a[n+1];
      map<ll, ll> mp;
      rep(i, n+1) a[i] = 1;
      mp[1] = 1;
      rep(i, k) {
        ll x, y;
        cin >> x >> y;
        a[x]--;
        a[y]++;
        if(mp[x]) mp[y] = 1;
        if(!a[x]) mp[x] = 0; 
      }
      repA(i, 1, n) if(mp[i]) cnt++;
      cout << cnt << endl;
    }

    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      //te
      solve();
      return 0;
    } 

Measured memory_bytes: 7296
(N, K), As = readlines.map{|l| l.split.map(&:to_i)}

M = Math.log2(1e12).ceil
cs = (0 .. M).map{|i| [i, As.count{|a| a[i] == 1}]}
ans = ([-1] + (0 .. M).select{|k| K[k] == 1}).map do |i|
  cs.inject(0) do |n, (j, c)|
    m = case i <=> j
        when -1; K[j] == 1 ? N - c : c
        when  0; c
        when  1; [c, N - c].max
        end
    n + (m << j)
  end
end.max
puts ans

Measured memory_bytes: 8964
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct pkt
{
    int x, y;
};

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

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<string> G(n);
    int bi = 0;
    for (int i = 0; i < n; ++i)
        cin >> G[i];
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            if (G[i][j] == '.')
                ++bi;
    queue<pkt> Q;
    vector< vector<bool> > odw(n, vector<bool>(m, false));
    vector< vector<int> > odl(n, vector<int>(m, -1));
    Q.push({0, 0});
    odw[0][0] = true;
    odl[0][0] = 1;
    while (!Q.empty())
    {
        pkt akt = Q.front();
        Q.pop();
        for (int i = 0; i < 4; ++i)
        {
            pkt nowy = {akt.x + dx[i], akt.y + dy[i]};
            if (nowy.x >= 0 && nowy.x < n && nowy.y >= 0 && nowy.y < m && !odw[nowy.x][nowy.y] && G[nowy.x][nowy.y] == '.')
            {
                odw[nowy.x][nowy.y] = true;
                Q.push(nowy);
                odl[nowy.x][nowy.y] = odl[akt.x][akt.y] + 1;
            }
        }
    }
    if (odl[n - 1][m - 1] == -1)
        cout << "-1";
    else
        cout << bi - odl[n - 1][m - 1];
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define INF 1e9
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

class TaskA {
public:
    void solve() {
        set<char> S;
        string s;
        cin >> s;
        for (int i = 0; i < s.size(); i++) S.insert(s[i]);
        cout << (S.size() > 1 ? "Yes" : "No");
    }
};

int main() {
//    freopen("absum.in","r",stdin);
//    freopen("absum.out","w",stdout);
    TaskA solver;
    solver.solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int a,b;
  cin >> a >> b;
  cout<<a*b<<endl;
  return 0;
}

Measured memory_bytes: 3624
k, n = map(int, input().split())
a = list(map(int, input().split()))

res = []
for i in range(n-1):
  j = a[i+1] - a[i]
  res.append(j)
l = k + a[0] - a[n-1]
res.append(l)
m = max(res)
print(k - m)

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; ++i)
    cin >> a[i];
  int sum = 0;
  for (int i = 0; i < N; ++i)
    if (a[i] == sum + 1)
      ++sum;
  if (sum != 0)
    cout << N - sum << endl;
  else
    cout << -1 << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    ll k;
    cin >> k;

    ll a[n];
    int flag[n];
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        a[i]--;
        flag[i] = 0;
    }

    ll now = 0;
    ll q = 0;
    for(ll i = 0; i < n; i++){
        if(flag[now] == 1){
            break;
        }else{
            ll t = a[now];
            flag[now] = 1;
            now = t;
            q++;
        }
    }

    ll cou = 0;
    ll poj = now;
    while(1){
        ll t = a[poj];
        cou++;

        if(t == now){
            break;
        }else{
            poj = t;
        }
    }

    ll ans = 0;
    q -= cou;
    if(k >= q){
        k -= q;
        ll b = k % cou;

        ans = now;
        for(ll i = 0; i < b; i++){
            ll t = a[ans];
            ans = t;
        }
        cout << ans + 1 << endl;
    }else{
        for(ll i = 0; i < k; i++){
            ll t = a[ans];
            ans = t;
        }
        cout << ans + 1 << endl;
    }
}

Measured memory_bytes: 5980
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
typedef long long int lli;
using namespace std;

int main(){
	string str;
	getline(cin,str);
	for(int i=0; i<str.size(); ++i){
		if(str[i]-3<'A'){
			str[i]='Z'+str[i]-'A'-3+1;
		} else {
			str[i]=str[i]-3;
		}
	}
	cout << str << "\n";
	return 0;
}

Measured memory_bytes: 1176