akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define mod 1000000007
 
#define p(x) cout<<x<<" ";
#define p2(x,y) cout<<x<<" "<<y<<" "
#define p3(x,y,z) cout<<x<<" "<<y<<" "<<z<<" "
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
 
#define ff first
#define ss second
#define mp(x,y) make_pair(x,y)
#define pi pair<ll,ll>
#define ppi pair<ll,pi>
#define pb push_back
#define all(v) v.begin(), v.end() 

ll power(ll a,ll b){
  ll result=1;
  while(b){
    if(b&1)
      result=(result*a)%mod;
      a=(a*a)%mod;
      b=b/2;
  }
  return result;
}

ll gcd(ll a,ll b){
  if(b==0)
    return a;
  return gcd(b,a%b);
}


vi v(105),wt(105);
ll dp[105][100005];

ll solve(ll n,ll capacity){
  if(capacity<0)
    return INT_MIN;
  if(n<=0||capacity==0)
    return 0;
  if(dp[n][capacity]!=-1)
    return dp[n][capacity];
  // if(wt[n-1]>capacity)
  //   dp[n][capacity]=solve(n-1,capacity);
  // else
  dp[n][capacity]=max(v[n-1]+solve(n-1,capacity-wt[n-1]),solve(n-1,capacity));
  return dp[n][capacity];

}


int main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout<<fixed<<setprecision(6);

// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
  
    ll t=1;
    //cin>>t;
    
    while(t--)
    {
      ll n,capacity;
      cin>>n>>capacity;
      F(i,0,n-1) cin>>wt[i]>>v[i];
      memset(dp,-1,sizeof(dp));
      cout<<solve(n,capacity)<<"\n";
    }
        
}

Measured memory_bytes: 82304
import java.util.Scanner;



public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		//
		//        int a = scan.nextInt();
		//        int b = scan.nextInt();
		//        int c = scan.nextInt();

		String s = scan.next();
		char[] c = s.toCharArray();

		int cunt = 0;

	//	for (int i = 0; i < c.length; i++) {
			if (c[0] == '1') // looking for 'a' only
				cunt++;
			if (c[1] == '1')
				cunt++;
			if (c[2] == '1') {
				cunt++;
			}
		//}
		System.out.println(cunt);
	}
}

Measured memory_bytes: 20692
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cctype>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <set>
#include <deque>
#include <map>
#include <bitset>
#include <functional>
#include <cmath>

#define INF 1000000000
using namespace std;

int main() {
	long long n, k;
    cin >> n >> k;
    long long a[n];
    long long b[n];

    long long i, j;
    for(i = 0; i < n; i++){
        cin >> a[i];
    }

    int flag = 0;
    int cnt = 0;
    while(!flag && cnt != k){
        flag = 1;

        if(cnt != 0){
            for(i = 0; i < n; i++){
                a[i] = b[i];
            }
        }

        for(i = 0; i < n; i++) b[i] = 0;

        for(i = 0; i < n; i++){
            b[max((long long)0, i-a[i])]++;
            if(i+a[i]+1 < n) b[i+a[i]+1]--;
        }

        if(b[0] != n) flag = 0;
        for(i = 1; i < n; i++){
            b[i] += b[i-1];
            if(b[i] != n) flag = 0;
        }

        cnt++;
    }

    //cout << cnt << endl;
    for(i = 0; i < n; i++){
        cout << b[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 6712
$n, $k = gets.split.map(&:to_i)
$ai = gets.split.map(&:to_i)

# Aiの各桁（0～40くらい）のビットが立っている個数
$ci = (0..39).map{|i|
    sum = 0
    for a in $ai
        sum += 1 if (a >> i) & 1 > 0
    end
    sum
}

$x_max = 0

# ub_k : Kの最上位ビット（0～40くらい）
ub_k = 0
for i in (0..39).to_a.reverse
    if ($k >> i) & 1 > 0
        ub_k = i
        break
    end
end

def xxor(x)
    $ai.map{|a| a^x}.inject(:+)
end

# Kを気にする探索
def find(i, x)
    if i < 0
        xmax = xxor(x)
        $x_max = xmax if xmax > $x_max
        return
    end

    # i桁目に0を選ぶ
    if ($k >> i) & 1 > 0
        find2(i-1, x)  # Kのi桁目が1なので、以降は全探索
    else
        find(i-1, x)
    end

    # i桁目に1を選ぶ
    # ※Kのi桁目が0の場合は1を選べない
    if ($k >> i) & 1 > 0
        find(i-1, x | (1 << i))
    end
end

# Kを気にせず探索
def find2(i, x)
    for j in (0..i).to_a.reverse
        x = $ci[j] > $n - $ci[j] ? x : x | (1 << j)
    end
    xmax = xxor(x)
    $x_max = xmax if xmax > $x_max
end


find(ub_k, 0)
puts $x_max


Measured memory_bytes: 25740
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        class Work
        {
            public readonly long A;
            public readonly long B;
            public Work(long[] args)
            {
                A = args[0];
                B = args[1];
            }
        }

        static bool Solve(int N, Work[] works)
        {
            long sum = 0;
            foreach (var work in works)
            {
                sum += work.A;
                if (sum > work.B) { return false; }
            }
            return true;
        }

        static void Main(string[] args)
        {
            int N = ReadInt();
            var works = new Work[N];
            for (int i = 0; i < N; ++i) { works[i] = new Work(ReadLongs()); }
            Console.WriteLine(Solve(N, works.OrderBy(work => work.B).ThenBy(work => work.A).ToArray()) ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 36388
#include <bits/stdc++.h>
 
using namespace std;
 
int main(int argc,char* argv[]){
  int D;
  cin >> D;
  if(D>23){
    if(D==25) cout << "Christmas" << endl;
    else cout << "Christmas Eve" << endl;
  }else{
    if(D==23) cout << "Christmas Eve Eve" << endl;
    else cout << "Christmas Eve Eve Eve" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

let n:Int=Int(readLine()!)!
let per=readInts()
var ans=0;
for i in 0..<n-2{
  if((per[i]<per[i+1]&&per[i+1]<per[i+2])||(per[i]>per[i+1]&&per[i+1]>per[i+2])){ans+=1}
}

print(ans)

Measured memory_bytes: 8200
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int x = a*b;
		int y = 2*a + 2*b;
		System.out.println(x+ " "+ y);
	}
}

Measured memory_bytes: 26096
#include<iostream>
#include<string>
using namespace std;
int main(){string s;
	while(cin>>s&&s!="#"){
		int a=1,b=(s[s.size()-4]=='o')?0:90,i;
		for(i=s.size()-5;i>0;i--){
			if(s[i]=='o')a*=2,b=2*b-90;
			if(s[i]=='e')a*=2,b=2*b+90;
		}while(!(a%2|b%2))a/=2,b/=2;
		cout<<b;if(a-1&&b)cout<<"/"<<a;cout<<endl;
	}return 0;
}

Measured memory_bytes: 3120
#include <iostream>
 using namespace std ;
 int main()
{
 int a,b, c, d,e;
 cin>>a;
cin>>b;
 c=(a*2-1);
 d=(b*2-1);
 e=(a+b);
 if (a > b)
 {
   cout<<c<<endl;
 }
 if  (a < b)
 {
   cout<<d<<endl;
 }
  if (a == b)
{
  cout<<e<<endl;
}
return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define mod 998244353ll
#define mxn 400005
using namespace std;
ll sum[mxn];
void add(int x, int n, ll val)
{
    while(x<=n)
    {
        sum[x]+= val;
        sum[x]%= mod;
        x+= (x&-x);
    }
    return;
}
ll query(int x)
{
    ll ret= 0;
    while(x)
    {
        ret+= sum[x];
        ret%= mod;
        x-= (x&-x);
    }
    return ret;
}
int lft[12], rght[12];
int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i=0; i<k; i++)
    scanf("%d %d", &lft[i], &rght[i]);
    int N= 2*n;
    add(n, N, 1);
    ll res;
    for(int i=n-1; i>=1; i--)
    {
        ll tot= 0;
        for(int j=0; j<k; j++)
        {
            int l= i+lft[j];
            int r= i+rght[j];
            tot+= query(r);
            tot-= query(l-1);
            tot%= mod;
            tot+= mod;
            tot%= mod;
        }
        res= tot;
        add(i, N, tot);
    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 5308
#include <stdio.h>
#include <stdlib.h>


int main(){
    long N,M, i;
    long A;

    scanf("%ld %ld", &N, &M);

    for (i = 0; i < M; i++){
        scanf("%ld", &A);
        N = N - A;
        if(N < 0){
            printf("-1");
            return 0;
        }
    }
    printf("%ld", N);

    return 0;
}


Measured memory_bytes: 1732
#pragma GCC optimize ("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<cmath>
#include<cstdio>
#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<utility>
#include<valarray>
#include<vector>
#include<array>
#include<forward_list>
#include<random>
#include<ratio>
#include<tuple>
#include<unordered_map>
#include<unordered_set>
#include<cstring>

using namespace std;
using Int = long long; using uint = unsigned int; using uInt = unsigned long long;
typedef pair<int,int> Pi; typedef pair<Int,Int> Pl;
constexpr int mod = 998244353;
constexpr int INF32 = numeric_limits<int>::max();
constexpr Int INF64 = numeric_limits<Int>::max();
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int(i)=0; i<n; ++i)
#define rer(i,l,r) for(int i=l; i<=r; ++i)
#define gnr(i,l,r) for(int i=r; i>=l; --i)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(i,n-1)cout<<a[i]<<' '; if(n)cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
#define priend(a) {cout<<(a)<<'\n'; return 0;}
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

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

	cin>>n>>m; int imo[200001]={},su[200001]; V(Pi)ba[m];
  rep(i,n){
    cin>>x>>y>>q; q--;
    ba[q].eb(x,y);
  }
  rep(i,m)sort(ALL(ba[i])); V(Pi)use;
  rep(i,m)rep(j,ba[i].size()){
    if(j!=ba[i].size()-1&&ba[i][j].se==ba[i][j+1].fi){
      ba[i][j+1].fi=ba[i][j].fi;
    }else use.eb(ba[i][j]);
  }
  for(Pi p:use){
    imo[p.fi*2-1]++; imo[p.se*2]--;
  }
  su[0]=0,m=0;
  rer(i,1,200000){su[i]=su[i-1]+imo[i]; cmax(m,su[i]);}
  priend(m);
}

Measured memory_bytes: 3956
n,k=map(int,input().split())
A=list(map(int,input().split()))

last=[-1]*(2*10**5+1)
nex=[-1]*n
prog=[0]*n

for i,a in enumerate(A*2):
    l=last[a]
    last[a]=i%n
    if nex[l]==-1 and l!=-1:
        nex[l]=(i+1)%n
        if i>=n or i+1==n:
            prog[l]=1
if nex[-1]==0:
    prog[-1]+=1

flag=False #いっぱいループ済か
stage=0
now=0
roop=[-1]*n
while True:
    if roop[now]!=-1 and flag==False:
        flag=True
        rr=stage-roop[now]
        stage=k-1-(k-1-stage)%rr
    if stage+prog[now]>=k:
        break
    roop[now]=stage
    stage+=prog[now]
    now=nex[now]

A=A[now:]+A if k-1-stage else A[now:]
check=[0]*(2*10**5+1)
stack=[]
for a in A:
    if check[a]:
        while check[a]:
            check[stack.pop()]=0
        continue
    stack.append(a)
    check[a]=1

print(*stack)

Measured memory_bytes: 106192
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1000000000
#define MOD 1000000007
#define mod(x) ((x % MOD) + MOD) % MOD
#define MAX_N 5001
#define MAX_K 5001

using namespace std;

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

ll N, K, a[MAX_N];
bool s[2*MAX_K];

bool C(ll i) {
  // カードiが必要かどうかを判定
  fill(s, s + 2*MAX_K, false);
  s[0] = true;
  for (ll j = 0; j < N; j++) {
    if (i == j) {
      continue;
    }
    for (ll k = K-1; k >= 0; k--) {
      s[k + a[j]] = s[k + a[j]] || s[k];
    }
  }

  for (ll k = max((ll)0, K - a[i]); k < K; k++) {
    if (s[k]) {
      return true;
    }
  }
  return false;
}

ll binary() {
  ll lb = -1, ub = N;

  while (ub - lb > 1) {
    ll mid = (lb + ub) / 2;
    if (C(mid)) {
      ub = mid;
    } else {
      lb = mid;
    }
  }
  return ub;
}

int main() {

  cin >> N >> K;
  for (ll i = 0; i < N; i++) {
    ll x;
    cin >> x;
    a[i] = min(x, K);
  }
  sort(a, a + N);

  cout << binary() << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int find(int x,vector<int>&root){
    if(root[x]==x)return x;
    else return root[x]=find(root[x],root);
}
int main(){
    int n,m,k;
    cin>>n>>m>>k;
    vector<vector<int>>f(n);
    vector<vector<int>>b(n);
    int f1[m],f2[m],b1[k],b2[k],rank[n];
    vector<int>root(n);
    for(int i=0;i<n;i++){
        root[i]=i;
        rank[i]=0;
    }
    for(int i=0;i<m;i++){
        cin>>f1[i]>>f2[i];
        f[f1[i]-1].push_back(f2[i]-1);
        f[f2[i]-1].push_back(f1[i]-1);
        int x=find(f1[i]-1,root),y=find(f2[i]-1,root);
        if(x==y)continue;
        if(rank[x]<rank[y])root[x]=y;//xをyに併合
        else root[y]=x;//yをxに併合
        if(rank[x]==rank[y])rank[x]++;
    }
    for(int i=0;i<k;i++){
        cin>>b1[i]>>b2[i];
        b[b1[i]-1].push_back(b2[i]-1);
        b[b2[i]-1].push_back(b1[i]-1);
    }
    int tree_size[n]={};
    for(int i=0;i<n;i++)tree_size[find(i,root)]++;
    int kouho[n];
    for(int i=0;i<n;i++){
        kouho[i]=tree_size[find(i,root)];
        for(int j=0;j<f[i].size();j++)if(find(i,root)==find(f[i][j],root))kouho[i]--;
        for(int j=0;j<b[i].size();j++)if(find(i,root)==find(b[i][j],root))kouho[i]--;
        cout<<kouho[i]-1<<" ";
    }
    return 0;
}

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

int main() {
	int n,m;
	cin >> n >> m;
	vector<int> h(n);
	vector<bool> good(n,true);
	rep(i,n) cin >> h[i];
	rep(i,m) {
		int a,b;
		cin >> a >> b;
		a--;b--;
		if (h[a]>=h[b]) good[b] = false;
		if (h[a]<=h[b]) good[a] = false;
	}
	int ans = 0;
	rep(i,n) if (good[i]) ans++;
	cout << ans << endl;
	return 0;
}


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

const ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

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

    int n;
    cin >> n;
    rep(i, n) {
        int a;
        cin >> a;
        if(a % 2 == 0 && a % 3 != 0 && a % 5 != 0) {
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        double [] P = new double[N];
        double [] L = new double[N];
        double p_sum = 0;
        double max = 0;
        for(int i=0;i<N;i++){
            int p = sc.nextInt();
            double sum = 0;
            for(int j=1;j<=p;j++) sum+=j;
            sum/=p;
            P[i] = sum;
            if(K>i){
                p_sum+=P[i];
                max+=P[i];
            }
            else{
                p_sum=p_sum-P[i-K]+P[i];
                if(max<p_sum) max = p_sum;
            }
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 75524
//file_name:ABC53_C.cpp
#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 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 sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<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 vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    ll n;
    scanf("%lld",&n);


    ll ans = 0;

    ans += (n/11)*2;

    n %= 11;

    if(n==0){
        ;
    }else{
        ans++;
        if(n>6)ans++;
    }



    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> pii;
map<pii,int> mp;
int n,m,x,y,u,v,cost,dis[1610000];
int edgenum,vet[1610000],val[1610000],Next[1610000],Head[1610000];
bool vis[1610000];
void addedge(int u,int v,int cost){
    vet[++edgenum]=v; val[edgenum]=cost;
    Next[edgenum]=Head[u]; Head[u]=edgenum;
}
struct node{
    int dis,num;
    bool operator<(const node &x) const{
        return dis<x.dis;
    }
} Heap[3210000];
void update(int i){
    while (i!=1){
        Heap[i>>1]=min(Heap[i],Heap[i^1]);
        i>>=1;
    }
    return;
}
void dijkstra(int n,int s){
    for (int i=1;i<(n<<1);i++){
        dis[i]=Heap[i].dis=INF;
        Heap[i].num=i;
    }
    dis[s]=0; Heap[s+(n-1)].dis=0; update(s+(n-1));
    while (Heap[1].dis!=INF){
        int num=Heap[1].num,u=num-(n-1);
        Heap[num].dis=INF;
        update(num);
        for (int e=Head[u];e;e=Next[e]){
            int v=vet[e];
            if (dis[v]>dis[u]+val[e]){
                dis[v]=dis[u]+val[e];
                Heap[v+(n-1)].dis=dis[u]+val[e];
                update(v+(n-1));
            }
        }
    }
}
int cnt;
int hs(int u,int c){
    pii t; t.first=u; t.second=c;
    if (mp.find(t)!=mp.end()) return mp[t];
    else mp[t]=++cnt;
    return cnt;
}

int main() {
    scanf("%d%d",&n,&m);
    cnt=n;
    for (int i=1;i<=m;i++){
        scanf("%d%d%d",&u,&v,&cost);
        x=hs(u,cost); y=hs(v,cost);
        addedge(x,y,0); addedge(y,x,0);
        addedge(u,x,1); addedge(x,u,1);
        addedge(v,y,1); addedge(y,v,1);
    }
    dijkstra(cnt,1);
    if (dis[n]<INF) printf("%d\n",dis[n]>>1);
    else puts("-1");
    return 0;
}


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

int main(){
  int r;
  int D;
  int x2000;
  int x;
  
  cin >> r >> D >> x2000;
  x = x2000;
  for(int i=0;i<10;i++){
    x = r*x - D;
    cout << x << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair

using namespace std;

int main()
{
   FAST/**/
   
   ll n;
   cin>>n;
   
   ll arr[n];
   ll len[3005];
   memset(len,0,sizeof(len));
   
   for(ll i=0;i<n;i++)
        cin>>arr[i], len[arr[i]]++;
   
   for(ll i=2;i<3005;i++)
        len[i]+=len[i-1];
   
   ll ans = 0;
   
   for(ll i=0;i<n;i++)
   {
       for(ll j=i+1;j<n;j++)
       {
           ll low = abs(arr[i] - arr[j]) + 1;
           ll hi = arr[i] + arr[j] - 1;
           
           ll temp = len[hi];
           temp-=len[low-1];
           if(arr[i]>=low && arr[i]<=hi)
                temp--;
           if(arr[j]>=low && arr[j]<=hi)
                temp--;
           
           ans+=temp;
       }
   }
   
   cout<<ans/3;
   
   return 0;
}

Measured memory_bytes: 256
x,y=map(int,input().split())
if abs(x)==abs(y):
    print(1)
elif x*y<0:
    print(abs(abs(x)-abs(y))+1)
elif x<y:
    print(abs(abs(x)-abs(y)))
elif x*y!=0:
    print(abs(abs(x)-abs(y))+2)
else:
    print(abs(abs(x)-abs(y))+1)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    int h[100000];
    for(int i = 0; i < N; i++) cin >> h[i];
    sort(h, h + N, greater<int>());
    int ans = h[0] - h[K - 1];
    for(int i = 1; i < N - K + 1; i++)
    {
        ans = min(ans, h[i] - h[K - 1 + i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
    int h,w;
    cin >> h >> w;
    int si,sj;
    cin >> si >> sj;
    int ti,tj;
    cin >> ti >> tj;
    si--;sj--;ti--;tj--;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    vector<vector<int>> dist(h,vector<int>(w,1e9));
    deque<P> q;
    dist[si][sj] = 0;
    q.emplace_back(si,sj); //後ろから入れる
    while(!q.empty()){
        int i = q.front().first; //前から取り出す
        int j = q.front().second;
        int d = dist[i][j]; //(i,j)でのコスト
        q.pop_front(); //取り出したやつを消す
        rep(v,4){ //歩き（コスト０）
            int ni = i+di[v], nj = j+dj[v];
            if(ni<0 || ni>=h || nj<0 || nj>=w) continue;
            if(s[ni][nj]  == '#') continue;
            if(dist[ni][nj] <= d) continue; //コストがd以下ならそのまま
            dist[ni][nj] = d;
            q.emplace_front(ni,nj); //歩きの場合、前から入れる
        }
        for(int ei = -2; ei <= 2; ei++){ //魔法
            for(int ej = -2; ej <= 2; ej++){
                int ni = i+ei, nj = j+ej;
                if(ni<0 || ni>=h || nj<0 || nj>=w) continue;
                if(s[ni][nj] == '#') continue;
                if(dist[ni][nj] <= d+1) continue;
                dist[ni][nj] = d+1; //コストは１
                q.emplace_back(ni,nj); //魔法の場合、後ろから入れる
            }
        }
    }
    int ans = dist[ti][tj];
    if(ans == 1e9) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9572
#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;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n) a[i]--;
  vector<int> idx(n);
  rep(i,n) idx[a[i]] = i;
  set<int> s;
  ll ans = 0;
  for (int x = n-1; x >= 0; --x) {
    int i = idx[x];
    ll c = 0;
    { // calc c
      s.insert(i);
      vector<int> l(2,-1);
      vector<int> r(2,n);
      { // calc l
        auto it = s.find(i);
        rep(j,2) {
          if (it == s.begin()) break;
          --it;
          l[j] = *it;
        }
      }
      { // calc r
        auto it = s.find(i);
        rep(j,2) {
          ++it;
          if (it == s.end()) break;
          r[j] = *it;
        }
      }
      vector<int> ls(2);
      ls[0] = i-l[0]; ls[1] = l[0]-l[1];
      vector<int> rs(2);
      rs[0] = r[0]-i; rs[1] = r[1]-r[0];
      c = (ll)ls[0]*rs[1] + (ll)ls[1]*rs[0];
    }
    ans += c*(x+1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int n,t,m = 10000;
  cin >> n >> t;
  vector<int> c(n),u(n);
  for (int i = 0; i < n; i++){
    cin >> c[i] >> u[i];
    if (u[i] <= t && c[i] < m){
      m = c[i];
    }
  }
  if (m != 10000){
    cout << m << '\n';
  }
  else{
    cout << "TLE\n";
  }
  return 0;
}

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

using namespace std;


int main(void){

    int n;
    cin >> n;

    int counts[9] = {0};
    for(int i=0; i<n; i++) {
        int temp;
        cin >> temp;
        if(temp<400) counts[0]++;
        else if(temp<800) counts[1]++;
        else if(temp<1200) counts[2]++;
        else if(temp<1600) counts[3]++;
        else if(temp<2000) counts[4]++;
        else if(temp<2400) counts[5]++;
        else if(temp<2800) counts[6]++;
        else if(temp<3200) counts[7]++;
        else counts[8]++;
    }
    
    int count = 0;
    for(int i=0; i<8; i++) {
        if(counts[i]>0) {
            count++;
        }
    }
    
    int min, max;

    if(counts[8]>0) {
        min = count==0?1:count;
        max = count + counts[8];
    }
    else {
        min = count;
        max = count;
    }
    
    cout << min << " " << max << endl;

    return 0;
}


Measured memory_bytes: 384
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let (a, b): (Vec<usize>, Vec<usize>) = {
        let (mut a, mut b) = (vec![], vec![]);
        for _ in 0..(N - 1) {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            a.push(iter.next().unwrap().parse().unwrap());
            b.push(iter.next().unwrap().parse().unwrap());
        }
        (a, b)
    };

    let G = {
        let mut G = vec![std::collections::HashSet::new(); N + 1];
        for i in 0..(N - 1) {
            G[a[i]].insert(b[i]);
            G[b[i]].insert(a[i]);
        }
        G
    };

    let mut parent = vec![N + 1; N + 1];
    let mut children = vec![std::collections::HashSet::new(); N + 1];
    parent[1] = 1;
    fn construct_tree(
        i: usize,
        parent: &mut Vec<usize>,
        children: &mut Vec<std::collections::HashSet<usize>>,
        G: &Vec<std::collections::HashSet<usize>>,
    ) {
        for &j in &G[i] {
            if parent[j] == G.len() {
                parent[j] = i;
                children[i].insert(j);
                construct_tree(j, parent, children, &G);
            }
        }
    }
    construct_tree(1, &mut parent, &mut children, &G);

    let mut res = std::collections::HashMap::new();
    fn f(
        i: usize,
        prev: usize,
        res: &mut std::collections::HashMap<(usize, usize), usize>,
        children: &Vec<std::collections::HashSet<usize>>,
    ) -> usize {
        let mut x = 0;
        let mut K = 0;
        for &c in &children[i] {
            x += if x + 1 == prev { 2 } else { 1 };
            res.insert((std::cmp::min(i, c), std::cmp::max(i, c)), x);
            K = std::cmp::max(K, f(c, x, res, children));
        }
        std::cmp::max(K, x)
    }
    let K = f(1, 0, &mut res, &children);
    let ans = format!(
        "{}\n{}",
        K,
        (0..(N - 1))
            .map(|i| res[&(a[i], b[i])].to_string())
            .collect::<Vec<_>>()
            .join("\n")
    );

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


Measured memory_bytes: 106620
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     makep        make_pair
#define     maket        make_tuple
#define     show(x)      for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

const int inf=1e18,M=1e9+7;
const int N=1;

const int SZ=52;

void disp(int mat[SZ][SZ])
{
    for(int i=0;i<SZ;++i)
    {
        for(int j=0;j<SZ;++j)
            cout<<mat[i][j]<<" ";
        cout<<"\n";
    }
}

void mul(int a[SZ][SZ], int b[SZ][SZ])
{
    int res[SZ][SZ];
    for(int i=0;i<SZ;++i)
    {
        for(int j=0;j<SZ;++j)
        {
            res[i][j]=0;
            for(int k=0;k<SZ;++k)
                res[i][j]=( res[i][j]%M + (a[i][k]%M*b[k][j]%M)%M )%M;
        }
    }

    for(int i=0;i<SZ;++i)
    {
        for(int j=0;j<SZ;++j)
            a[i][j]=res[i][j];
    }
}

void power(int x[SZ][SZ], int n)
{
    int res[SZ][SZ];
    mem(res,0);

    for(int i=0;i<SZ;++i)
        res[i][i]=1;

    for(;n;n/=2)
    {
        if(n%2)
            mul(res,x);

        mul(x,x);
    }

    for(int i=0;i<SZ;++i)
    {
        for(int j=0;j<SZ;++j)
            x[i][j]=res[i][j];
    }
}

void solve()
{
    int n,k;
    cin>>n>>k;

    int mat[SZ][SZ];
    mem(mat,0);

    for(int i=0;i<n;++i)
    {
        for(int j=0;j<n;++j)
            cin>>mat[i][j];
    }

    power(mat,k);

    int ans=0;
    for(int i=0;i<n;++i)
    {
        for(int j=0;j<n;++j)
            ans=(ans+mat[i][j])%M;
    }

    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}




Measured memory_bytes: 384
#include <stdio.h>
#include <vector>
#include <string>

using namespace std;

string input_str, now_str;
vector<string> src_str;
int seen[26];


void getSourceString(int i) {
	
	if(i >= (int)input_str.size()){
		src_str.push_back(now_str);
		return;
	}
	
	char c = input_str[i];
	if(c == 'a'){
		
		now_str.push_back('a');
		seen[0] = 1;
		getSourceString(i+1);
		seen[0] = 0;
		now_str.erase( now_str.begin() + (int)now_str.size() - 1 );
		
	}
	if(seen[c - 'a']){
		
		now_str.push_back(c);
		getSourceString(i+1);
		now_str.erase( now_str.begin() + (int)now_str.size() - 1 );
		
	}if(c != 'z' && seen[ (c+1) - 'a' ] == 0){
		
		now_str.push_back(c+1);
		seen[ (c+1) - 'a' ] = 1;
		getSourceString(i+1);
		seen[ (c+1) - 'a' ] = 0;
		now_str.erase( now_str.begin() + (int)now_str.size() - 1 );
		
	}
	
}

int main(void)
{
	char input[25];
	
	while(1){
		scanf("%s", input);
		if( input[0] == '#' ) break;
		input_str = (string)input;
		src_str.clear();
		
		for(int i = 0; i < 26; i++) seen[i] = 0;
		now_str.clear();
		
		
		getSourceString(0);
		int num = (int)src_str.size();
		
		printf("%d\n", num);
		if(num <= 10){
			for(int i = 0; i < num; i++) printf("%s\n", src_str[i].c_str());
		}else{
			for(int i = 0; i < 5; i++) printf("%s\n", src_str[i].c_str());
			for(int i = num-5; i <= num-1; i++) printf("%s\n", src_str[i].c_str());
		}
	}
	
	return 0;
}

Measured memory_bytes: 3892
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>

using namespace std;

int main(){
	int a;
	int b;
	int c;
	int d;
	cin >> d;
	for (int i = 0; i < d; i++){
		cin >> a >> b >> c;
		int e = a*a;
		int f = b*b;
		int g = c*c;
		if ( e + f== g || e + g == f || f + g == e){
			cout << "YES" << endl;
		}
		else cout << "NO" << endl;
	}

	return 0;
}

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(),x.end()
auto& errStream=cerr;
#ifdef LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll read(){
	ll i;
	scanf("%"  SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

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

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

signed main(){
	int n=read();
	vi a(n);
	REP(i,n)a[i]=read();
	
	set<int> pos;
	REP(i,n)
		pos.insert(i);
	
	priority_queue<pi> pq;
	REP(i,n)
		pq.push(pi(a[i],i));
	
	int ans=0,w=1;
	while(!pq.empty()){
		int i=pq.top().second;pq.pop();
		auto itr=pos.find(i);
		if(itr==pos.end())
			continue;
		if(itr==pos.begin()||next(itr)==pos.end()){
			ans+=w*a[i];
			w*=-1;
			pos.erase(itr);
		}else{
			auto x=prev(itr);
			auto y=next(itr);
			a[i]=a[*x]+a[*y]-a[i];
			pq.push(pi(a[i],i));
			pos.erase(x);
			pos.erase(y);
		}
	}
	print(ans);
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	long a,b;cin>>a>>b;
	cout<<a*b/__gcd(a,b)<<endl;
}

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

#define INF 100000000
#define ABS(a) (a<0?-(a):a)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define REP(i,a) for(int i=0;i<a;i++) 

using namespace std;
int main(){
  int N, M;
  cin >> N >> M;

  long long total1, total2, total;

  if(ABS(N-M) > 1){
    cout << 0 << endl;
    return 0;
  }

  total1 = 1;
  REP(i , N){
    total1 = (total1 * (i+1) % (1000000007));
  }

  total2 = 1;
  REP(i , M){
    total2 = (total2 * (i+1) % (1000000007));
  }
  total =((ABS(N-M)==1?1:2) * total1* total2 )% 1000000007;
  cout << total << endl;
}



Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
#define CIN(s) int (s);cin>>(s);
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 (b<a) { a=b; return 1; } return 0; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF =1e18;
V vec1;
V vec2;
ld n,k;
bool Judge(ll f){
    //int res=k;
    V vec3(n);
    rep(i,n){
        vec3[i]=f/vec2[i];
    }
    ll res=k;
    rep(i,n){
        res-=max((ll)0,vec1[i]-vec3[i]);
    }
   /* rep(i,n){
        if(vec1[i]*vec2[i]>f){
            if(f%vec2[i]==0){
                res-=vec1[i]-(f/vec2[i]);
            }else{
                res-=(vec1[i]-(f/vec2[i]));
            }
        }
    }*/
    if(res>=0){
        return true;
    }else{
        return false;
    }
}
int main(){
    cin>>n>>k;
    vec1.resize(n);
    rep(i,n)cin>>vec1[i];
    sort(all(vec1));
    vec2.resize(n);
    rep(i,n)cin>>vec2[i];
    sort(all(vec2),greater<ll>());
    ll Max=1e18;
    ll Min=0;
    rep(i,200){
        ll Half=(Max+Min)/2;
        if(Judge(Half)){
            Max=Half;
        }else{
            Min=Half;
        }
    }
    cout<<Max<<endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	for(int i = n - 1; i >= 0; i -= 2) {
		cout << a[i] << " ";
	}
	
	for(int i = n % 2; i < n; i += 2) {
		cout << a[i] << " ";
	}
	
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 2944
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll ld=0,ans=0;
	string s;
	cin>>s;
	for (ll i=0;i<s.size();i++){
		if (s[i]=='W')
			ans+=i-ld,ld++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int W = scan.nextInt();
		int H = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		int r = scan.nextInt();
		
		if((x+r) > W || (x-r) < 0 || (y+r) > H || (y-r) < 0){
		    System.out.println("No");
		    }
		else{
			System.out.println("Yes");
		    }
	}
}

Measured memory_bytes: 26340
#include<iostream>
#include<map>
#include<vector>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    vector<int> sale;
    map<int, long long> comp;
    int a;
    long long b,c;
    bool f = true;
    while(n--){
      cin >>a>>b>>c;
      if(!comp[a]){sale.push_back(a);}
      comp[a]+=b*c;
    }
    for(int i=0; i<sale.size(); i++){
      if(comp[sale[i]] >= 1000000){cout <<sale[i]<<endl;f =false;}
    }
    if(f){cout <<"NA"<<endl;}
  }
  return 0;
}

Measured memory_bytes: 1288
#include <stdio.h>
#include <math.h>

int main(void) {

  long n;
  scanf("%ld", &n);
  long t_max[n],a_max[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &t_max[i]);
  }
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a_max[i]);
  }
  long mod = pow(10,9)+7;
  long t_min[n],a_min[n];
  for (long i = 0; i < n; i++) {
    t_min[i] = 1;
    if (i == 0) {
      t_min[i] = t_max[i];
    } else {
      if (t_max[i] != t_max[i-1]) {
        t_min[i] = t_max[i];
      }
    }
  }
  for (long i = n-1; i >= 0; i--) {
    a_min[i] = 1;
    if (i == n-1) {
      a_min[i] = a_max[i];
    } else {
      if (a_max[i] != a_max[i+1]) {
        a_min[i] = a_max[i];
      }
    }
  }
  long ans = 1;
  long min,max;
  for (long i = 0; i < n; i++) {
    if (a_max[i] < t_min[i] || t_max[i] < a_min[i]) {
      printf("0\n");
      return 0;
    }
    max = t_max[i];
    if (a_max[i] < max) {
      max = a_max[i];
    }
    min = t_min[i];
    if (a_min[i] > min) {
      min = a_min[i];
    }
    ans *= max-min+1;
    ans %= mod;
  }
  printf("%ld\n", ans);

  return 0;
}

Measured memory_bytes: 3328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {

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

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());
      String line = in.readLine();
      int nHalf = n >> 1;

      int[] seqA = new int[nHalf];
      int[] seqB = new int[nHalf];

      Integer num;
      List<Integer> listA = new ArrayList<>();
      List<Integer> listB = new ArrayList<>();
      Map<Integer,Integer> mapA = new HashMap<>();
      Map<Integer,Integer> mapB = new HashMap<>();
      int offset=0,next=0;
      char regx = ' ';
      for(int i=0, j=0; i<n; i++, j= i >> 1) {
        if((next = line.indexOf(regx,offset)) == -1)
          next = line.length();
        num = new Integer(line.substring(offset, next));
        offset = ++next;

        if((i & 1) == 0) {
          seqA[j] = num;
          if(mapA.containsKey(num)) {
            mapA.replace(num, mapA.get(num) + 1);
          } else {
            mapA.put(num, 1);
            listA.add(num);
          }
        }
        else {
          seqB[j] = num;
          if(mapB.containsKey(num)) {
            mapB.replace(num, mapB.get(num) + 1);
          } else {
            mapB.put(num, 1);
            listB.add(num);
          }
        }
      }

      int vma,vmb,xa,xb;
      vma = vmb = xa = xb =0;
      for (Integer var : listA) {
        int ma = mapA.get(var);
        if(vma < ma) {
          vma = ma;
          xa = var;
        }
      }
      for (Integer var : listB) {
        int mb = mapB.get(var);
        if(vmb < mb) {
          vmb = mb;
          xb = var;
        }
      }

      int cca = nHalf - vma;
      int ccb = nHalf - vmb;

      int vma2,vmb2,xa2,xb2;
      vma2 = vmb2= xa2 = xb2 =0;
      int cca2,ccb2;
      cca2 = ccb2 = 0;
      int ans = 0;
      if(xa == xb) {
        for (Integer var : listA) {
          int ma = mapA.get(var);
          if(var != xa && vma2 < ma) {
            vma2 = ma;
            xa2 = var;
          }
        }
        for (Integer var : listB) {
          int mb = mapB.get(var);
          if(var != xb && vmb2 < mb) {
            vmb2 = mb;
            xb2 = var;
          }
        }
      
        cca2 = nHalf -vma2;
        ccb2 = nHalf -vmb2;

        ans = cca2 > ccb2 ? cca + ccb2 : cca2 + ccb;
      }
      else {
        ans = cca + ccb;
      }

      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 46164
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	A = getlist()
	judge = "APPROVED"
	for i in range(N):
		if A[i] % 2 == 0:
			if A[i] % 5 != 0 and A[i] % 3 != 0:
				judge = "DENIED"
				break

	print(judge)


if __name__ == '__main__':
	main()

Measured memory_bytes: 38384
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, h = ns()
    a = []
    b = []
    for i in range(n):
        ai, bi = ns()
        a.append((ai, i))
        b.append((bi, i))

    a = sorted(a, key=lambda x: x[0], reverse=True)
    b = sorted(b, key=lambda x: x[0], reverse=True)

    a_max = a[0][0]
    a_max_idx = a[0][1]

    sum_b = 0
    b_cnt = 0
    for i in range(n):
        if b[i][0] > a_max:
            b_cnt += 1
            sum_b += b[i][0]

    cnt = 0
    if sum_b <= h:
        cnt += (h - sum_b + a_max - 1) // a_max
        cnt += b_cnt
    else:
        for i in range(n):
            h -= b[i][0]
            cnt += 1
            if h <= 0:
                break

    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 31240
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,result,highest;
  cin >> n;
  result = 0;
  highest = 0;
  vector<int> hotel(n);
  for(int i = 0;i<n;i++){
    cin  >> hotel[i];
  }
  
  for(int i = 0;i<n;i++){
    if(hotel[i] >= highest){
      result += 1;
      highest = hotel[i];
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
/*
 *Author - Abhas Jain
 */
 
#include <bits/stdc++.h>
 
#define F first
#define S second
#define all(c) c.begin(), c.end()
#define endl '\n'
#define pb push_back
 
 
typedef long long ll;
typedef long double ld;
 
using namespace std;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
 
const ld PI = 3.141592653589793;
const ll INF = 9223372036854775807ll;
const ll mod = 1e9 + 7;
 
void solve() 
{
    ll s;
    cin >> s;
    ll x2 = 1e9;
    ll y1 = s / (1e9);
    if (s % 1000000000) y1++;
    ll x1 = 1;
    ll y2 = x2 * y1 - s;
    cout << "0 0" << endl;
    cout << x1 << " " << y1 << endl;
    cout << x2 << " " << y2 << endl;
}
 
int main( )
{   
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    solve();
    return 0;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;

/**
 * Created by Seiya on 2016/10/16.
 */
public class Main {
     static final long MOD = 1000000007;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String s = scanner.next();

        System.out.println(s.replaceAll(","," "));


    }





}




Measured memory_bytes: 10064