akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int N;
int V[20];
int C[20];

int f(int index, int value, int cost)
{
	int op1, op2;

	if (index == N) return value - cost;

	op1 = f(index + 1, value + V[index], cost + C[index]);
	op2 = f(index + 1, value, cost);

	return max(op1, op2);
}

int main()
{
	int ans;

	cin >> N;
	rep(i, N) cin >> V[i];
	rep(i, N) cin >> C[i];

	ans = f(0, 0, 0);

	cout << ans << endl;

	return 0;
}

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

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


int main() {
	int h, n;
	cin >> h >> n;
	vector<int> a(n), b(n);
	rep(i, n) cin >> a[i] >> b[i];
	const int inf = 1001001001; 
	vector<int> dp(h+1, inf); // HPがdp[i]のときの最小消費魔力
	dp[h] = 0;
	for(int i = h; i >= 0; i--){ // 各HPについて
		rep(j, n){ // 各魔法を試す
			int next_hp = i - a[j];
			if(next_hp < 0) next_hp = 0;
			chmin(dp[next_hp], dp[i] + b[j]);
		}
	}
	
	cout << dp[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

bool has_cycle(int max_v, int cur_v, vvi& adj_list, bool base1 = false) {
    if (base1) max_v++;
    static vi visited; if (visited.size() != max_v)visited.resize(max_v, 0);
    function<bool(int)> dfs = [&](int cur_v) -> bool {
        if (visited[cur_v]) {
            if (visited[cur_v] == -1) return true;
            return false;
        }
        visited[cur_v] = -1;
        for (int adj : adj_list[cur_v]) {
            if (dfs(adj)) {
                return true;
            }
        }
        visited[cur_v] = 1;
        return false;
    };
    return dfs(cur_v);
}

int main()
{
    int N, M; cin >> N >> M;
    vector<vector<int>> adj_list(N);
    for (int i = 0; i < M; i++) {
        int u, v; cin >> u >> v;
        adj_list[u].push_back(v);
    }

    bool ans = false;
    for (int i = 0; i < N; i++) {
        if (has_cycle(N, i, adj_list)) { ans = true; break; }
    }

    printf("%d\n", ans ? 1 : 0);
    return 0;
}


Measured memory_bytes: 3304
parseInt(x::Union{AbstractString,Char}) = parse(Int, x)
parseInt(x::Real) = trunc(Int, x)
parseBigInt(x::Union{AbstractString,Char}) = parse(BigInt, x)
parseBigInt(x::Real) = trunc(BigInt, x)
parseFloat(x::Union{AbstractString,Char}) = parse(Float64, x)
parseFloat(x::Real) = trunc(Float64, x)
parseBigFloat(x::Union{AbstractString,Char}) = parse(BigFloat, x)
parseBigFloat(x::Real) = trunc(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
parseMapBig(x::Array{SubString{String},1}) = map(parseBigInt, x)

function main()
    s=[string(chomp(readline())) for i in 1:3]
    now=1
    while length(s[now])>0
        next=s[now][1]-'a'+1
        s[now]=s[now][2:end]
        now=next
    end
    println((now-1+'A'))
end
main()

Measured memory_bytes: 110204
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<bitset>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#define ll long long
#define PI acos(-1.0)
#define pb push_back
#define mp mack_pair
#define fi first
#define se second
#define esp 1e-7
#define lowbit(x) x & (-x)

using namespace std;

const int maxx = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;

int n, m, T, tot;
int l, r, ans, fath;
int fa[maxx + 5], a[maxx + 5];

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

Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


int main()
{
    int r,c; cin >> r >> c;
    int f[r][c];
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> f[i][j];
        }
    }
    int sum = 0;
    int a[r];
    int b[c];
    for(int i = 0; i < r; i++){
        a[i] = 0;
    }
    for(int i = 0; i < c; i++){
        b[i] = 0;
    }
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            a[i] += f[i][j];
            sum += f[i][j];
        }
    }
    for(int i = 0; i < c; i++){
        for(int j = 0; j < r; j++){
            b[i] += f[j][i];
        }
    }
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cout << f[i][j] << ' ';
        }
        cout << a[i] << endl;
    }
    for(int i = 0; i < c; i++){
        cout << b[i] << ' ';
    }
    cout << sum << endl;
}


Measured memory_bytes: 3116
#include<stdio.h>
int main(void)
{ 
	int i,j,cnt=0,flg=0,x[12];
	for(i=0;i<12;i++){
		scanf("%d",&x[i]);
	}
	for(i=0;i<12;i++){
		for(j=0;j<12;j++){
			if(x[i]==x[j]){
				cnt++;
			}
		}
		if(cnt%4!=0){
			flg=1;
		}
		cnt=0;
	}
	if(flg==0){
		printf("yes\n");
	}
	else printf("no\n");
	return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <iostream>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;

//typedef long long int i64; // 9e18
typedef long long int i64; // 9e18

typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

//const double PI = 3.141592653589793238463;
//const int MAXN = 1000500;
//const int MAXVALUE = 1000000500;
//const long double EPS = 1e-7;
const i64 INF = 1e18;
i64 mod = 1e9 + 7;


i64 T, n, m, k;
//vector <vector<i64>> a;
//vector <i64> b;
//vector <i64> dp;

vector <vector<i64>> dp;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(16);

    T = 1;
    //cin >> T;

    for (i64 tt = 0; tt < T; ++tt) {

        string s;
        cin >> s;

        cout << s;
        if (s[s.size() - 1] == 's') {
            cout << "es" << endl;
        }
        else {
            cout << "s" << endl;
        }

    }
    return 0;
}

Measured memory_bytes: 3032
#include<bits/stdc++.h>
using namespace std;
#define Endl '\n'
typedef long long int lli;
void solve();
int main(int argc, char const *argv[]){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
    solve();
}
void solve(){
  int S, W;
  cin>>S>>W;
  if(W>=S){
    cout<<"unsafe"<<Endl;
  }else{
    cout<<"safe"<<Endl;
  }
}


Measured memory_bytes: 3652
import sys
def input(): return sys.stdin.readline().rstrip()
from fractions import gcd
def prime_fact(m):
    pf={}
    for i in range(2,int(m**0.5)+1):
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:pf[m]=1
    return list(pf)
def main():
    a,b=map(int,input().split())
    print(1+len(prime_fact(gcd(a,b))))

if __name__=='__main__':
    main()

Measured memory_bytes: 5304
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;
    int val = 1000;
    while(val < n)  val += 1000;
    cout << val - n << endl;
}

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

using namespace std;

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

  int answer = 1000000000;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;

    int count = 0;
    while (A % 2 == 0) {
      A /= 2;
      count += 1;
    }

    answer = min(answer, count);
  }

  cout << answer << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"Yes\n";
#define no cout<<"No\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int n,k;cin>>n>>k;
    vector<int>a(n);in(a,n);
    for(int i=k;i<n;i++)
    {
        yesno(a[i] > a[i-k]);
    }
    return 0;
}

Measured memory_bytes: 4780
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
#include <cstdint>

typedef long long int llint;

void solve(void){

  int x;
  std::cin >> x;

  int aaa = std::gcd(x, 360);

  std::cout << 360/aaa << std::endl;
  
}

int main(void){

  solve();
  
  return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>

int main(void){

  long x,a,b;
  scanf("%ld %ld %ld", &x, &a, &b);
  if (b <= a) {
    printf("delicious\n");
  } else if (b <= a+x) {
    printf("safe\n");
  } else {
    printf("dangerous\n");
  }

  return 0;
}

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

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MOD = 1e9+7;

ll t, d, s;

int main(){
  // freopen("input.txt", "r", stdin); 
  // freopen("output.txt", "w", stdout);
  cin.sync_with_stdio(0); cin.tie();
  cin.exceptions(cin.failbit);

  cin >> d>>t>>s;
  cout << (s*t>=d? "Yes":"No");
}

Measured memory_bytes: 3592
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

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

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;
    
    lint ans = 0;
    lint mb = LLINF;
    rep(i, n){
        lint a, b;
        cin >> a >> b;
        ans += a;
        if(a > b){
            chmin(mb, b);
        }
    }

    if(mb < LLINF){
        ans -= mb;
    }else{
        ans = 0;
    }

    cout << ans << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define forn(a,b,c) for(int a=b;a<=c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
#define f first
#define s second
typedef pair<int,int> pii;
const int N=16;
const int mod=1e9+7;
ll a[N][N],dp[(1<<N)],cost[(1<<N)];int n;bool vis[(1<<N)];
int main()
{
    scanf("%d",&n);
    forn(i,0,n-1){
        forn(j,0,n-1){
            scanf("%lld",&a[i][j]);
        }
    }
    forn(x,1,(1<<n)-1){
        forn(i,0,n-1){
            forn(j,i+1,n-1){
                if((x&(1<<i))&&(x&(1<<j))){
                    cost[x]+=a[i][j];
                }
            }
        }
        dp[x]=cost[x];
    }
    forn(x,0,(1<<n)-1){
        for(int i=x;i;i=(i-1)&x){
            dp[x]=max(dp[x],dp[i]+cost[x^i]);
        }
    }
    printf("%lld",dp[(1<<n)-1]);
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N,Q; cin >> N >> Q;
    string S; cin >> S;

    vector<int> AC(N,0);
    FOR(i,1,N){
        if(S[i-1]=='A' && S[i]=='C'){
            AC[i] += 1;
        }
        AC[i] += AC[i-1];
    }


    REP(i,Q){
        int l,r; cin >> l >> r;
        l--;
        r--;
        cout << AC[r] - AC[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 3816
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] xt = scanner.nextLine().split(" ", 2);
        long x = Long.parseLong(xt[0]);
        long t = Long.parseLong(xt[1]);

        System.out.println(Math.max(x - t, 0));
    }
}


Measured memory_bytes: 23764
n = int(input())
arr = [int(x) for x in input().split()]
c0 = 0
c1 = 0
for i in range(n):
        if arr[i] % 2 == 1:
                c1 = c1 + 1
        else:
                c0 = c0 + 1
if c0 == 0 or c1 == 0:
        print(0)
else:
        if c1 % 2 == 0:
                print(n-2)
        else:
                print(n-1)




Measured memory_bytes: 27372
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

long long pow_mod(long long n,long long k,long long m){
    if (k == 0){
        return 1;
    } else if (k % 2 == 1){
        return pow_mod(n,k-1,m)*n % m;
    } else {
        long long t = pow_mod(n,k/2,m);
        return t*t % m;
    }
}


int main(){
    long long s; cin >> s;
    const int v = 1e9;

    int x = (v-s%v)%v;
    int y = (s+x)/v;
    cout << "0 0 1000000000 1 " << x << " " << y << endl;
}
  



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

struct point{
    double x, y;
};

double distance(double x1, double y1, double x2, double y2){
    double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    return ans;
}
bool compare(struct point p1, struct point p2){
    if (p1.x != p2.x)
        return p1.x < p2.x;
    return p2.y > p1.y;    
}

int main(){
    
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<point> p(n);
    for(int i = 0; i < n; ++i)
        cin >> p[i].x >> p[i].y;
    
    double long sum = 0;
    int counter = 0;
    sort(p.begin(), p.end(), compare);
    do{
        for(int i = 0; i < n - 1; ++i)
            sum += distance(p[i].x, p[i].y, p[i + 1].x, p[i + 1].y);
        counter++;
    }while(next_permutation(p.begin(), p.end(), compare));    
    cout << fixed << setprecision(9) << sum * 1.0 / counter << '\n';
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long[] ai = new long[n];
        for(int i=0; i<n; i++) {
            ai[i] = in.nextLong();
        }
        long ans = 0;
        for(int i=1; i<n; i++) {
            if(ai[i] < ai[i-1]) {
                ans += ai[i-1] - ai[i];
                ai[i] = ai[i-1];
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 61660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

//LCA(Lowest Common Ancestor):根付き木の2頂点の共通祖先で最も近いもの
//AOJ(Lowest Common Ancestor)

#define MAX_V 100005
#define MAX_LOG_V 50
vei G[MAX_V]; //隣接リスト表現
int root = 0; //根ノード番号

int parent[MAX_LOG_V][MAX_V]; //親を2^k回辿って到達する頂点
int depth[MAX_V]; //根からの深さ

void dfs(int v, int p, int d) {
    parent[0][v] = p;
    depth[v] = d;
    rep(i,G[v].size()) {
        if(G[v][i] != p) dfs(G[v][i], v, d + 1);
    }
}

//初期化
void init(int V) {
    //parent[0], depthの初期化
    dfs(root, -1, 0);
    //parentの初期化
    for(int k = 0; k + 1 < MAX_LOG_V; k++) {
        for(int v = 0; v < V; v++) {
            if(parent[k][v] < 0) parent[k + 1][v] = -1;
            else parent[k + 1][v] = parent[k][parent[k][v]];
        }
    }
}

//uとvのLCA
int lca(int u, int v) {
    //uとvの深さが同じになるまで親を辿る
    if(depth[u] > depth[v]) swap(u, v);
    rep(k, MAX_LOG_V) {
        if( (depth[v] - depth[u]) >> k & 1 ) {
            v = parent[k][v];
        }
    }
    if(u == v) return u;
    for(int k = MAX_LOG_V - 1; k >= 0; k--) {
        if(parent[k][u] != parent[k][v]) {
            u = parent[k][u];
            v = parent[k][v];
        }
    }
    return parent[0][u];
}

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

    int n; cin >> n;
    
    rep(i,n) {
        int k; cin >> k;
        rep(j,k) {
            int c; cin >> c;
            G[i].pub(c);
        }
    }

    init(n);

    int q; cin >> q;
    rep(i,q) {
        int u, v; cin >> u >> v;
        cout << lca(u, v) << endl;
    }
    return 0;
}




Measured memory_bytes: 36328
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int H[] =new int[N];
    int view = 0;
    int cnt = 0;
    
    for(int i=0; i<N; i++){
      H[i]=sc.nextInt();
      if(H[i]>=view){
        cnt++;
        view=H[i];
      }
    }
    System.out.println(cnt);
  }
}
    
    

Measured memory_bytes: 35696
score = []
while True:
    a = list(map(int, input().split()))
    if a[0] == -1 and a[1] == -1 and a[2] == -1:
        break
    else:
        score.append(a)

for i in range(len(score)):
    m, f, r = score[i][0], score[i][1], score[i][2]
    if m == -1 or f == -1:
        print("F")
    elif m + f >= 80:
        print("A")
    elif 65 <= m + f < 80:
        print("B")
    elif 50 <= m + f < 65:
        print("C")
    elif 30 <= m + f < 50:
        if r >= 50:
            print("C")
        else:
            print("D")
    elif m + f < 30:
        print("F") 



Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
template<class T> T read(){
	T x=0,w=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-') w=-w;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*w;
}
template<class T> T read(T&x){
	return x=read<T>();
}
#define CO const
#define IN inline
typedef long long LL;

CO int N=100000+10;
struct edge {int u,v,c;}e[N];
IN bool operator<(CO edge&a,CO edge&b){
	return a.c<b.c;
}

int fa[N];
int find(int x){
	return fa[x]==x?x:fa[x]=find(fa[x]);
}

bool vis[N];

int main(){
	int n=read<int>();
	LL m=read<LL>();
	int q=read<int>();
	for(int i=1;i<=q;++i){
		int u=read<int>()+1,v=read<int>()+1;
		e[i]=(edge){u,v,read<int>()};
	}
	sort(e+1,e+q+1);
	for(int i=1;i<=n;++i) fa[i]=i;
	bool valid=1,more=1;
	for(int i=1;i<=q;++i){
		if(e[i].c==0){
			int fu=find(e[i].u),fv=find(e[i].v);
			if(fu!=fv) fa[fu]=fv;
		}
		else{
			more=0;
			int fu=find(e[i].u),fv=find(e[i].v);
			if(fu==fv) {valid=0;break;}
		}
	}
	if(!valid) return puts("No"),0;
	int cnt=0;
	for(int i=1;i<=n;++i) cnt+=find(i)==i;
	puts(n-more<=m and m<=n+(LL)cnt*(cnt-1)/2-cnt?"Yes":"No");
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define MOD 1000000007

using namespace std;
typedef long long int ll;

int main(void){
	// #ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// #endif
	fast;
	int n; cin >> n;
	ll a[n];
	ll ans = 0;
	for (int i = 0; i < n; ++i){
		cin >> a[i];
		ans += a[i]-1;
	}
	cout << ans << '\n';
	// ll lim = *max_element(a, a+n);
	// for (int i = 1; i <= lim; ++i){
	// 	cur += n;
	// 	cur -= 
	// }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  long long n, k, ans = 1000000000, dis;
  cin >> n >> k;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n-k+1; i++) {
    // cout << x[i] << ' ' << x[i+k-1] << endl;
    if (x[i]<0) {
      if (x[i+k-1]<0) {
        dis = -1*x[i];
      } else {
        dis = -1*x[i] + x[i+k-1] + min(-1*x[i],x[i+k-1]);
      }
    } else {
      dis = x[i+k-1];
    }
    ans = min(dis, ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  long long b, n;
  long long ans;
  cin >> a >> b >> n;
  if(n>=b-1) ans = a*(b-1)/b;
  else ans = a*n/b;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3576
#include <iostream>
using namespace std;
using uint = unsigned int;

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

	uint X = N * 100 / 108;
	
	if ((uint)(X * 1.08) == N) {
		cout << X;
	} else if((uint)((X + 1) * 1.08) == N ) {
		cout << X + 1;
	} else {
		cout << ":(";
		//cout << X;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return r;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

void solve(void){
    string s;
    cin >> s;
    if((s[5] == '0' && s[6] == '1') || (s[5] == '0'&& s[6] =='2')|| s[6] =='3' ||s[6] == '4') cout << "Heisei" <<endl;
    else cout << "TBD"<< endl;

}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}

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

result = 0

for i in range(1,N+1):
    x = i
    sum = 0
    while x > 0:
        sum += int(x%10)
        x = int(x/10)
    if sum >= A and sum <= B:
        result += i

print(result)

Measured memory_bytes: 3060
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<long long int>v(N);
	for (auto &i : v)cin >> i;
	vector<vector<vector<long long int>>>dp(N, vector<vector<long long int>>(3, vector<long long int>(3, MOD*MOD)));
	dp[0][0][0] = v[0];
	dp[0][1][0] = v[0] % 2;
	if (!v[0])dp[0][1][0] = 2;
	dp[0][1][1] = (v[0] + 1) % 2;
	dp[0][1][2] = v[0] % 2;
	if (!v[0])dp[0][1][2] = 2;
	dp[0][2][0] = v[0];
	for (int i = 1; i < N; i++) {
		dp[i][0][0] = dp[i - 1][0][0] + v[i];
		long long int add = v[i] % 2;
		if (!v[i])add = 2;
		dp[i][1][0] = min(dp[i - 1][1][0] + add, dp[i - 1][0][0] + add);
		add = (v[i] + 1) % 2;
		dp[i][1][1] = min({ dp[i - 1][1][1] + add,dp[i - 1][1][0] + add,dp[i - 1][0][0] + add });
		add = v[i] % 2;
		if (!v[i])add = 2;
		dp[i][1][2] = min({ dp[i - 1][1][2],dp[i - 1][1][1],dp[i - 1][1][0],dp[i - 1][0][0] }) + add;
		dp[i][2][0] = min({ dp[i-1][0][0], dp[i-1][1][0], dp[i-1][1][1], dp[i-1][1][2], dp[i-1][2][0] }) + v[i];
	}
	long long int ans = MOD * MOD;
	for (auto i : dp.back()) {
		for (auto j : i)ans = min(ans, j);
	}
	cout << ans << endl;
}

Measured memory_bytes: 40832
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

typedef vector<long double> Cell;

long double cost(Cell &a, Cell &b)
{
    long double dist = sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]) + (a[2] - b[2]) * (a[2] - b[2]));
    return max(dist - a[3] - b[3], (long double)0.0);
}
void solve(int n)
{
    vector<Cell> v(n);
    rep(i, n)
    {
        long double x, y, z, r;
        cin >> x >> y >> z >> r;
        v[i] = Cell({x, y, z, r});
    }
    vector<bool> used(n, false);
    long double ans = 0;
    used[0] = true;
    bool isupdate = true;

    while (isupdate)
    {
        long double bestdist = 1 << 20;
        int best = -1;
        rep(i, n)
        {

            if (used[i] == false)
            {
                continue;
            }
            rep(j, n)
            {

                if (used[j] == true)
                {
                    continue;
                }
                if (cost(v[i], v[j]) < bestdist)
                {
                    bestdist = cost(v[i], v[j]);
                    best = j;
                }
            }
        }
        if (best == -1)
            break;
        ans += bestdist;
        used[best] = true;
        isupdate = false;
        rep(i, n)
        {
            isupdate |= !used[i];
        }
    }
    printf("%.3Lf\n", ans);
}

int main()
{

    int n;
    while (cin >> n, n)
    {
        solve(n);
    }
    return 0;
}


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

int main() { /* ここに書く */
  
  int N,M,m,A,Sum;
  Sum = 0;
  
  cin >> N >> M;
  
  vector<int>vec(N);
  
  for(int i = 0; i<N ; i++){
    cin >> A;
    vec.at(i) = A;
    Sum = Sum + A;
  }
  
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  m = vec.at(M-1) * 4 * M;
  
  if(m < Sum){
    cout << "No" <<endl;}
  
  else{
    cout << "Yes" <<endl;}
  
  
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

dp_table = [10**4 for i in range(N)]
dp_table[0] = 0
dp_table[1] = abs(H[1] - H[0])

for i in range(2, N):
    dp_table[i] = min(dp_table[i - 1] + abs(H[i] - H[i - 1]), dp_table[i - 2] + abs(H[i] - H[i - 2]))

print(dp_table[-1])

Measured memory_bytes: 13924
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =2e5+10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
//unordered_map
typedef long long ll;
ll a[MAXN];
int cmp(int f,int s)
{
	return abs(f)>abs(s);
}
int main()
{
	int n,k,vis=0,zheng=0,fu=0;
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++) 
	{
	    scanf("%lld",&a[i]);
	    if(a[i]<0)	fu++;
		else zheng++;
	}
	ll ans=1;
	//判断答案是正负  觉得先判负 wa了8个数据 可能wa在负数取模上 
	if(n==k)
	{
		for(int i=1;i<=n;i++)
		{
			ans=a[i]*ans%mod;
		}
		printf("%lld\n",(ans%mod+mod)%mod);
	}
	else
	{
    	if(k%2&&zheng==0)//负 
    	{
    		sort(a+1,a+1+n,cmp);
    		for(int i=n;i>=n-k+1;i--)
    		{
    			ans=a[i]*ans%mod;
			}
			printf("%lld\n",(ans%mod+mod)%mod);
    	} 
    	else
    	{
    		sort(a+1,a+1+n);
    		int r=n,l=1;
    		if(k%2) ans=(ans%mod*a[r]%mod)%mod,r--,k--;
    		while(k>0)
    		{
    			ll sum1=a[l]*a[l+1],sum2=a[r]*a[r-1];
    			if(sum1>=sum2)
    			{
    				ans=ans*a[l]%mod*a[l+1]%mod;
    				l+=2;
    				k-=2;
				}
				else
				{
					ans=ans*a[r-1]%mod*a[r]%mod;
    				r-=2;
    				k-=2;
				}
			}
			printf("%lld\n",(ans%mod+mod)%mod);
    	}
	} 
}

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

typedef  long long ll;
typedef long double ld;
using namespace std;
const int N=1e5+5;

#define endl "\n"
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define point complex<double>
ll mod=1e9+7;
ll inf=2e18;
double eps=1e-10;
double pi=acos(-1);
double dot(point a, point b)
{
    return (conj(a)*b).real();
}
double cross(point a, point b)
{
    return (conj(a)*b).imag();
}

int arr[N];
int main()
{
 int n,k;
 cin>>n>>k;
 for(int i=0;i<n;i++)
        cin>>arr[i];
 sort(arr,arr+n);
 int ans=1e9;
 for(int i=k-1;i<n;i++)
    ans=min(ans,arr[i]-arr[i-k+1]);
 cout<<ans;


    return 0;
}


Measured memory_bytes: 4008
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (ll i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << (x) << endl
#define debug2(x, y) cerr << #x << ": " << (x) << " " << #y << ": " << y << endl;
#define int long long
using namespace std;
using II = pair<int, int>;
using VII = vector<II>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { int n = d.size(); REP (i, n) s << d[i] << " "; return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& dd) { for (vector<T> d: dd) s << d << endl; return s; }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
const int MOD = 1e9 + 7;

// Dinic法 O(E * V^2)
class Graph {
  int t; // ゴール
  VI level, iter;
  void bfs(int s) {
    for (int i = 0; i < level.size(); i++) level[i] = -1;
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
      int v = que.front(); que.pop();
      for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
  }
  int dfs(int v, int f) {
    if (v == t) return f;
    for (int &i = iter[v]; i < G[v].size(); i++) {
      edge &e = G[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
        int d = dfs(e.to, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
public:
  int V;
  struct edge {int to, cap, rev; };
  vector<vector<edge>> G;
  Graph(int V) : V(V), G(V), level(V), iter(V) {}

  void add_edge(int from, int to, int cap) {
    G[from].push_back(edge{ to, cap, (int)G[to].size() });
    G[to].push_back(edge{ from, 0, (int)G[from].size() - 1 });
  }

  int max_flow(int s, int t) {
    int flow = 0;
    this->t = t;
    while (1) {
      bfs(s);
      if (level[t] < 0) return flow;
      for (int i = 0; i < iter.size(); i++) iter[i] = 0;
      int f;
      while ((f = dfs(s, (1LL << 60))) > 0) {
        flow += f;
      }
    }
  }
};

signed main() {
  int X, Y, E; cin >> X >> Y >> E;
  Graph g(X + Y + 2);
  while (E--) {
    int x, y; cin >> x >> y;
    g.add_edge(x, X + y, 1);
  }
  int s = X + Y;
  int t = X + Y + 1;
  REP (i, X) {
    g.add_edge(s, i, 1);
  }
  REP (i, Y) {
    g.add_edge(X + i, t, 1);
  }
  cout << g.max_flow(s, t) << endl;
}


Measured memory_bytes: 3412
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

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

	for(int i=1; i<=9; i++)
	{
		for(int j=1; j<=9; j++)
		{
			if(i*j == N)
			{
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()
#define SORT(a) sort(all(a))
using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;

using namespace std;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	long long g = gcd(a, b);
	return a / g * b;
}

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

	SORT(l);

	int cnt = 0;

	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			for (int k = j + 1; k < n; k++) {
				if (l[i] + l[j] > l[k]) {
					cnt++;
				}
				else {
					break;
				}
			}
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
from collections import deque

def main():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    ans = 0
    dh = [0,1,0,-1]
    dw = [1,0,-1,0]
    for h in range(H):
        for w in range(W):
            if S[h][w] == '#':
                continue
            dist = [[-1] * W for _ in range(H)]
            dist[h][w] = 0
            Q = deque([(h,w)])
            while Q:
                y, x = Q.popleft()
                for i in range(4):
                    nh = y + dh[i]
                    nw = x + dw[i]
                    if 0 <= nh < H and 0 <= nw < W and dist[nh][nw] == -1 and S[nh][nw] == '.':
                        dist[nh][nw] = dist[y][x] + 1
                        Q.append((nh,nw))
            for i in range(H):
                ans = max(ans, max(dist[i]))
                
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 45020
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define pi 3.141592653589793
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define sz size()
#define cu cout<<
#define en endl
#define sp " "
#define RE(i,n) for(int i=0,_n=(n);i<_n;++i)
#define RI(i,n) for(int i=1,_n=(n);i<=_n;++i)
#include<cstdio>
#include<cstring>
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll modd = (ll)1e9 + 7;
const int mod = 10000007;
#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            for (ll j=i*i; j<=N; j += i)
                prime[j] = false;
        }
    }
}
/*bool isprime(ll n)
{
    if(n<2) return 0;
    if(n==2) return 1;
    else
    {
        for(int i=2; i*i<=n; i++)
            if(n%i==0) return 0;
    }
    return 1;
}*/
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
int cnt[20000];
int main()
{
    fast;
  ll a,b,c,x,y,n,m,k;
  cin >> n;
  if(n%1000==0)
  {
      cout << 0 <<endl;
  }
  else
  {
      x = n/1000;
      x++;
      cout << (1000*x)-n<<endl;
  }
}






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

int A[100010];
bool ext[40];

int main() {
	int N;
	cin >> N;
	int ax=0;
	for(int i=0; i<N; ++i){
		cin >> A[i];
		ax ^= A[i];
		int t=0;
		while(!((A[i])&(1<<t))) ++t;
		ext[t]=1;
	}
	int ans=0;
	for(int d=29; d>=0; --d){
		if(ax&(1<<d)){
			if(ext[d]){
				++ans;
				for(int i=0; i<=d; ++i) ax ^= (1<<i);
			}else{
				cout << -1 << endl;
				return 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
using std::cin;using std::cerr;
using std::max;using std::min;
#define N 200005
#define ll long long
#define db double
#define pb push_back
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
int n,a,b,ecnt,last[N],fa[N],flag;ll Max1,Max2,l,r,mid,Min[N];
struct node
{
	ll x,y;
	friend bool operator==(node t1,node t2) {return t1.x==t2.x&&t1.y==t2.y;}
};
std::vector<node>S[N];
struct road{int to,v,nex;}e[N];
void adde(int u,int v,int w) {e[++ecnt]=(road){v,w,last[u]},last[u]=ecnt;}
bool cmp1(node t1,node t2) {return t1.x<t2.x||t1.x==t2.x&&t1.y<t2.y;}
bool cmp2(node t1,node t2) {return t1.y<t2.y||t1.y==t2.y&&t1.x<t2.x;}
void dfs(int x,ll d=0)
{
	if(d>Max1) Max2=Max1,Max1=d;
	else Max2=max(Max2,d);
	for(int k=last[x];k;k=e[k].nex) dfs(e[k].to,d+e[k].v);
}
void Solve(int x)
{
	if(flag) return;
	int to1=0,to2=0;S[x].clear();
	for(int k=last[x];k;k=e[k].nex)
	{
		to1?to2=e[k].to:to1=e[k].to;
		for(int i=0,sz=S[e[k].to].size();i<sz;i++)
			S[e[k].to][i].x+=e[k].v,S[e[k].to][i].y+=e[k].v;
	}
	if(!to1) return void(S[x].pb({0,0}));
	int sz1=S[to1].size(),sz2=S[to2].size();
	if(sz1>sz2) std::swap(to1,to2),std::swap(sz1,sz2);
	std::sort(S[to1].begin(),S[to1].end(),cmp1);
	std::sort(S[to2].begin(),S[to2].end(),cmp2);
	sz1=std::unique(S[to1].begin(),S[to1].end())-S[to1].begin();
	sz2=std::unique(S[to2].begin(),S[to2].end())-S[to2].begin();
	S[to1].resize(sz1),S[to2].resize(sz2);
	Min[0]=S[to2][0].x;
	for(int i=1;i<sz2;i++) Min[i]=min(Min[i-1],S[to2][i].x);
	for(int i=0,j=sz2-1;i<sz1;i++)
	{
		for(;~j&&S[to1][i].x+S[to2][j].y>mid;j--);
		if(~j) S[x].pb((node){Min[j],S[to1][i].y});
	}
	
	std::sort(S[to1].begin(),S[to1].end(),cmp2);
	std::sort(S[to2].begin(),S[to2].end(),cmp1);
	Min[0]=S[to2][0].y;
	for(int i=1;i<sz2;i++) Min[i]=min(Min[i-1],S[to2][i].y);
	for(int i=0,j=sz2-1;i<sz1;i++)
	{
		for(;~j&&S[to1][i].y+S[to2][j].x>mid;j--);
		if(~j) S[x].pb({S[to1][i].x,Min[j]});
	}
	if(S[x].empty()) flag=1;
}
bool Judge()
{
	flag=0;
	for(int i=n;i;i--) Solve(i);
	return !flag;
}
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++) scanf("%d%d",&a,&b),adde(a,i,b);
	dfs(1);
	for(l=0,r=Max1+Max2;l<r;) mid=l+r>>1,Judge()?r=mid:l=mid+1;
	printf("%lld\n",l);
	return 0;
}

Measured memory_bytes: 30580
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        ArrayList<String> result = new ArrayList<String>();
 
        while(sc.hasNextLine()){
            int a = sc.nextInt();
            int b = sc.nextInt();
 
            if(a == 0 && b == 0){
                break;
            }
 
            if(a > b){
                int tmp = a;
                a = b;
                b = tmp;
            }   
 
            result.add(a + " " + b);
        }
 
        for(int i = 0; i < result.size(); i++){
            System.out.println(result.get(i));
        }
    }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  string S;
  cin >> S;
  bool ans = true;
  for(int i=0;i<N;i++) {
    if(S[i] == '-') {
      ans = false;
      break;
    }
  }
  if(S[N] != '-') ans = false;
  for(int i=N+1;i<N+M+1;i++) {
    if(S[i] =='-') {
      ans = false;
      break;
    }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	
	string ss = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	
	vector<char> t(s.size());
	rep(i,s.size()){
		t[i] = ss[(s[i]-'A' + n)%26];
	}
	
	rep(i,t.size()) cout << t[i];

	return 0;
}

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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;

string alphabet = "abcdefghijklmnopqrstuvwxyz";

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> S;
    vector<int> Snum(S.size());
    for (int i=0;i<S.size();i++){
        for (int j=0;j<alphabet.size();j++){
            if (S[i] == alphabet[j]) {
                Snum[i] = j;
            }
        }
    }
    if (Snum.size() < alphabet.size()){
        vector<bool> flag(26);
        for (int i=0;i<Snum.size();i++) {
            flag[Snum[i]] = true;
        }
        int add;
        for (int i=0;i<flag.size();i++){
            if (!flag[i]) {
                add = i;
                break;
            }
        }
        S.push_back(alphabet[add]);
        cout << S << "\n";
        return 0;
    } else {
        int pos = 0;
        for (int i=Snum.size()-1;i>0;i--){
            if (Snum[i] > Snum[i-1]) {
                pos = i;
                break;
            }
        }
        if (pos == 0) {
            cout << -1 << "\n";
            return 0;
        }
        string ans;
        for (int i=0;i<pos-1;i++){
            ans.push_back(S[i]);
        }
        vector<bool> flag(26);
        for (int i=pos;i<Snum.size();i++){
            flag[Snum[i]] = true;
        }
        int add;
        for (int i=Snum[pos-1];i<26;i++){
            if (flag[i]) {
                add = i;
                break;
            }
        }
        ans.push_back(alphabet[add]);
        cout << ans << "\n";
        return 0;
    }
}

Measured memory_bytes: 256