akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll H, W;
    cin >> H >> W;
    ll ans = INF;
    repd(i, 1, H) {
        ll A = i * W;
        ll B = (H - i) * (W / 2);
        ll C = H * W - A - B;
        ll max_S = max(A, max(B, C));
        ll min_S = min(A, min(B, C));
        ans = min(ans, max_S - min_S);
        if (i != H - 1) {
            B = W * ((H - i) / 2);
            C = H * W - A - B;
            ll max_S = max(A, max(B, C));
            ll min_S = min(A, min(B, C));
            ans = min(ans, max_S - min_S);
        }
    }
    repd(i, 1, W) {
        ll A = i * H;
        ll B = (W - i) * (H / 2);
        ll C = H * W - A - B;
        ll max_S = max(A, max(B, C));
        ll min_S = min(A, min(B, C));
        ans = min(ans, max_S - min_S);
        if (i != W - 1) {
            B = H * ((W - i) / 2);
            C = H * W - A - B;
            ll max_S = max(A, max(B, C));
            ll min_S = min(A, min(B, C));
            ans = min(ans, max_S - min_S);
        }
    }

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

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int n=stdIn.nextInt(),a,s=0,i,j;
		for(i=0;i<n;i++) {
			a=stdIn.nextInt();
			if(a==1) continue;
			for(j=2;j<=(int)Math.sqrt(a);j++) if(a%j==0) break;
			if(j==(int)Math.sqrt(a)+1) s++;
		}
		System.out.println(s);
	}
}


Measured memory_bytes: 40996
A,B = map(long,raw_input().split())

sum = B-A+1

if sum % 2 == 0:
  if A % 2 == 0:
    if sum/2%2 == 0:
      print "0"
    else:
      print "1"
  else:
    if sum/2%2 == 1:
      print A^B^0
    else:
      print A^B^1
else:
  if A % 2 == 0:
    if sum/2%2 == 0:
      print 0^B
    else:
      print 1^B
  else:
    if sum/2%2 == 1:
      print 1^A
    else:
      print 0^A
    


Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	N %= 500;

	if (N <= A) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3608
N = int(input())
A = list(map(int,input().split()))
S = sum(A)//2
S = 2*(S - sum(A[1::2]))
ans = [S]
for i in range(1,N):
  ans.append(2*A[i-1]-ans[i-1])
print(' '.join(map(str,ans)))
  

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

int main()
{
	int h,w;

	cin>>h>>w;	// w>h
	while(w!=0 || h!=0){
		int aw=0,ah=0;
		int t =w*w +h*h;
		//同じ対角線の長さを調べる。
		for(int i=1;i<150;i++){
			for(int j=1;j<i;j++){
				if(t==(i*i+j*j) && j>h){
					aw=i;
					ah=j;
				}
			}
		}
		//異なる対角線の長さを調べる
		int plus=1;
		while(ah==0 && aw==0){
			for(int i=1;i<150;i++){
				for(int j=1;j<i;j++){
					if((t+plus)==(i*i+j*j)){
						aw=i;
						ah=j;
					}
				}
			}
			plus++;
		}
		cout<<ah<<" "<<aw<<endl;
		cin>>h>>w;
	}
}

Measured memory_bytes: 1160
#include<stdio.h>
int main()
{
    long long n,m,a,sum=0;
    int i;
    scanf("%lld%lld",&n,&m);
    for(i=0;i<m;i++)
    {
        scanf("%lld",&a);
        sum=sum+a;
    }
    if(sum>n)
        printf("-1");
    else
        printf("%lld",n-sum);
    return 0;
}


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

struct node{
	char *word;
	int frequency;
	struct node *left;
	struct node *right;
};

int Word_Length(char *str){
	int length = 0;
	while(*str++ != '\0')
		length++;
	return length;
}
void Copy_Str(char *from, char *to){
	while(*to++ = *from++)
		;
}
int Comp_Strs(char *str1, char *str2){
	for(; *str1 == *str2; str1++, str2++)
		if(*str1 == '\0')
			return 0;
	return *str1 - *str2;
}
struct node *Create_bTree(struct node *root, char *str, int *count_words){
	int distance;
	if(root == NULL){
		(*count_words)++;
		root = (struct node *) malloc(sizeof(struct node));
		root->word = (char *) malloc(sizeof(char) * (Word_Length(str)+1));
		Copy_Str(str, root->word);
		root->frequency = 1;
		root->right = root->left = NULL;
	}
	else if((distance = Comp_Strs(root->word, str)) == 0){
		root->frequency++;
	}
	else if(distance > 0){
		root->right = Create_bTree(root->right, str, count_words);
	}
	else{
		root->left = Create_bTree(root->left, str, count_words);
	}
	return root;
}
void Free_bTree(struct node *root){
	if(root != NULL){
		Free_bTree(root->left);
		free(root->word);
		free(root);
		Free_bTree(root->right);
	}
}
int main(){
	int n_words, count_words = 0;
	scanf("%d", &n_words);
	char str_temp[11];
	struct node *root;
	root = NULL;
	for(int str_i = 0; str_i < n_words; str_i++){
		scanf("%s", str_temp);
		root = Create_bTree(root, str_temp, &count_words);
	}
	printf("%d", count_words);
	Free_bTree(root);
	return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) for(int i=0;i<=(n);++i)
#define ALL(v) (v).begin(),(v).end()

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

ll q,h,s,d,n;
priority_queue<P,vector<P>,greater<P> > pq;

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

	cin>>q>>h>>s>>d>>n;
	if(n==1) {
		ll mi=min(q*4,min(h*2,s));
		cout<<mi<<endl;
		return 0;
	}
	pq.push(P(q*8,1)); pq.push(P(h*4,1)); pq.push(P(s*2,1)); pq.push(P(d,2));
	ll two=n/2;
	ll one=n%2;
	if(one==0) {
		P p=pq.top();
		cout<<n/2*p.first<<endl;
		return 0;
	}
	else {
		ll ans=0;
		P p=pq.top();pq.pop();
		if(p.second==2) {
			ans+=n/2*p.first;
			P q=pq.top();
			ans+=q.first/2;
		}
		else {
			ans+=n*p.first/2;
		}
		cout<<ans<<endl;
		return 0;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>

#include <climits>

using namespace std;


int main(){
	string s;
	cin >> s;

	vector<int> arr(26);

	for (int i = 0; i < s.size(); i++) {
		int num = s[i] - 'a';
		arr[num]++;
	}

	int ans = -1;
	for (int i = 0; i < 26; i++) {
		if (arr[i] == 0) {
			ans = i;
			break;
		}
	}

	if (ans == -1)cout << "None" << endl;
	else {
		int num2 = ans + 'a';
		char numnum = num2;
		cout << numnum << endl;
	}

	return 0;
}

Measured memory_bytes: 3756
while gets
  n, a, b, c, x = $_.split.map(&:to_i)
  break if n == 0
  res = gets.split.map(&:to_i).reduce(0) do |cnt, i|
    if x != i && cnt != -1
      until x == i
        x = (a * x + b) % c
        cnt += 1
        break if cnt > 10000
      end
    end
    x = (a * x + b) % c
    if cnt < 0 || 10000 < cnt then -1
    else cnt + 1
    end
  end
  p res >= 0 ? res - 1 : res
end

Measured memory_bytes: 8804
/* 
Mohit Dhattarwal
*/
#include <bits/stdc++.h>
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
#define gcd(a,b) __gcd(a,b)
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define filewr() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
 
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,ll> psl;
typedef pair<ll,string> pls;
 
template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}
 
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
 
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
 
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
 
const ld PI = 3.1415926535897932384626433832795;
 
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;

void solve()
{
	ll n;
	cin>>n;
	ll a[n];
	ll num = 0;
	for(ll i =0; i<n; i++)
	{
		cin>>a[i];
		num ^= a[i];
	}
	for(ll i =0; i<n; i++)
	{
		cout<<(num^a[i])<<" ";
	}
	cout<<'\n';

}

int main(){
	fastio();
	ll t;
	t=1;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 5140
import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.Queue;
public class Main{
    public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        int height=scan.nextInt();
        int width=scan.nextInt();
        String[] str=new String[height];
        Queue<String> queue=new ArrayDeque<>();
        int i,j;
        for(i=0;i<height;i++){
            str[i]=scan.next();
            queue.add(str[i]);
        }
        //System.out.println(queue);
        for(i=0;i<height;i++){
            System.out.println(queue.peek());            
            System.out.println(queue.poll());
        } 
    }
}

Measured memory_bytes: 23300
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {

	int h, w;
	cin >> h >> w;

	vector< vector<long long int> > mp(10, vector<long long int>(10, 0));

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

	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				mp[i][j] = min(mp[i][j], mp[i][k] + mp[k][j]);
			}
		}
	}

	int b;

	long long int ans = 0;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> b;
			if (b != -1) {
				ans += mp[b][1];
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if (A<=9 && B<=9) {
    cout << A*B << endl;
  }
  else {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<a;i++)
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
    int h,n;
    cin>>h>>n;
    int a=0;
    rep(i,n){
        int enter;
        cin>>enter;
        a+=enter;
    }
    if(a>=h) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
// Problem : A - Frog 1
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void solve()
{
	int n;
	cin >> n;
	int a[n],dp[n];
	rep(i,0,n)
		dp[i]=INT_MAX;
	rep(i,0,n)
		cin >> a[i];
	dp[0]=0;
	rep(i,1,n)
	{
		dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
		if(i > 1)
			dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout << dp[n-1];
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 5180
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn main() {
    // 入力
    let (A, B) = get!(i64, i64);

    let ans = vec![A + B, A - B, A * B].into_iter().max().unwrap();

    // 出力
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    vector<char> vec;
    ll ans = 0;
    for(auto c : s) {
        if (vec.size() == 0 || vec.back() == c) {
            vec.push_back(c);
        } else {
            vec.pop_back();
            ans += 2;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
int main(){
    vector<int> list;
    int x,n,i,s,sum;
    while(1){
        cin >> n;
        if(n==0){break;}
        for(i=0;i<n;i++){
            cin >> x; 
            list.push_back(x);
        }
        sum=0;
        i=0;
        for(int j=0; j<list.size()-1; j++){
        for(i=0; i<list.size()-1; i++){
            if(list[i]>list[i+1]){
                s=list[i];
                list[i]=list[i+1];
                list[i+1]=s;
                sum++;
            }
        }
        }
        cout << sum << endl;
        list.clear();
    }
}

Measured memory_bytes: 1216
#include<iostream>
using namespace std;
int main(){
    int a,b,c,t;
    cin>>a>>b>>c;
    if(a>b){
        t=a;
        a=b;
        b=t;
    }
    if(b>c){
        t=b;
        b=c;
        c=t;
    }
    if(a>b){
        t=a;
        a=b;
        b=t;
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}
    


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
ll M = 1000000007;

ll count(ll v, ll n) {
  ll ret = 0;
  for (int i = 0; i < n; i++) {
    if ((v >> i) & 0x1) {
      ret++;
    }
  }
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vl a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  vl cnt(60, 0);
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < 60; j++) {
      cnt[j] += (a[i] >> j) & 0x1;
    }
  }
  ll ans = 0;
  ll b = 1;
  for (ll i = 0; i < 60; i++) {
    // cout << b << endl;
    ans += (((cnt[i] * (n - cnt[i])) % M) * b) % M;
    ans %= M;
    b = (b * 2) % M;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int (i) = (N)-1; (i) >= 0; (i)--)
#define REP(i, N) for(int (i) = 0; (i) < (int)(N); (i)++)
 
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

long long n,m;

void solve(istream& cin, ostream& cout) {
	cin >> n;
	long double X = n/3.0L;
	cout.precision(17);
	cout << fixed << X*X*X << endl;
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define ld long double
#define zeros(x) x^(x-1)&x
#define pii pair<ll,ll>
#define cd complex<double>
#define dbg(x) cerr<<x<<endl;
#define Nmax 500005
using namespace std;

ll n, s, v[Nmax];


int main()
{
    cin >> n;
    for (int i=1;i<=n;i++) cin >> v[i], s += v[i];
    sort(v+1,v+n+1);

    for (int i=n;i>=1;i--){
        s -= v[i];
        if (s * 2 < v[i]){
            cout << n-i+1 << '\n';
            return 0;
        }
    }

    cout << n << '\n';

    return 0;
}


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

struct UnionFind{
    int num;
    vector<int> par,rank;
    UnionFind(int n):num(n),par(n),rank(n,1){
        iota(par.begin(),par.end(),0);
    }
    int root(int x){
        return (par[x]==x?x:par[x]=root(par[x]));
    }
    bool merge(int x, int y){
        x=root(x),y=root(y);
        if (x==y) return false;
        if (rank[x]<rank[y]) swap(x,y);
        par[y]=x;
        rank[x]+=rank[y];
        --num;
        return true;
    }
    bool same(int x, int y){return root(x)==root(y);}
    int size(int x){return rank[root(x)];}
    int count(){return num;}
};

// https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/1/DSL_1_A

void DSL_1_A(){
    int n,q; cin >> n >> q;
    UnionFind uf(n);
    for (;q--;){
        int c,x,y; cin >> c >> x >> y;
        if (!c) uf.merge(x,y);
        else cout << uf.same(x,y) << '\n';
    }
}

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


Measured memory_bytes: 3264
N, W, H = map(int, raw_input().split())

E = [[] for i in range(N)]
lst = []
flag = True

for i in range(N):
    x, y = map(int, raw_input().split())
    if x == 1 or y == 1 or x == W or y == H:
        flag = False
    lst.append((x, y, i))

lst.sort()
for i in range(N):
    if lst[i][0] == lst[i - 1][0]:
        E[lst[i][2]].append(lst[i - 1][2])
        E[lst[i - 1][2]].append(lst[i][2])

lst2 = []

for i in range(N):
    x, y, index = lst[i]
    lst2.append((y, x, index))

lst = lst2
lst.sort()
for i in range(N):
    if lst[i][0] == lst[i - 1][0]:
        E[lst[i][2]].append(lst[i - 1][2])
        E[lst[i - 1][2]].append(lst[i][2])

used = [False for i in range(N)]

def func(num, pre):
    if used[num]:
        return
    used[num] = True
    for to in E[num]:
        if to != pre:
            func(to, num)

cnt = 0

for i in range(N):
    if not used[i]:
        func(i, -1)
        cnt += 1

if cnt > 1 and flag:
    cnt += 1
print N - 2 + cnt


Measured memory_bytes: 19704
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main(){
	int reservation[1001];
	for(int i = 0; i < 1001; i++){
		reservation[i] = 0;
	}
	int a, b;
	cin >> a >> b;
	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		int s, f;
		cin >> s >> f;
		for(int j = s; j < f; j++){
			reservation[j] = 1;
		}
	}
	int flag = 0;
	for(int i = a; i < b; i++){
		if(reservation[i] == 1){
			flag = 1;
			break;
		}
	}
	cout << flag << "\n";
}



Measured memory_bytes: 3116
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <cstdio>
#include <iostream>
#include <string>
#include <string.h>
#include <stdio.h>
#include <complex>

using namespace std;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
#define PB push_back
#define MP make_pair
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

typedef struct{
	int to, dist, cost;
}edge;

vector<vector<edge> > g;
vector<bool> visit;

int main(){
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0)return 0;
		g.clear();
		g=vector<vector<edge> >(n);
		visit=vector<bool>(n,false);
		REP(i,m){
			int u,v,d,c;
			scanf("%d%d%d%d", &u,&v,&d,&c);
			u--,v--;
			edge e1 = {v,d,c};
			edge e2 = {u,d,c};
			g[u].PB(e1);
			g[v].PB(e2);
		}
		priority_queue<TIII, vector<TIII>, greater<TIII> > q;
		q.push(MT(0,0,0));
		int ret = 0;
		while(!q.empty()){
			TIII tmp = q.top();
			q.pop();
			if(visit[tmp.T3])continue;
			ret += tmp.T2;
			visit[tmp.T3] = true;
			REP(i,g[tmp.T3].size())q.push(MT(tmp.T1+g[tmp.T3][i].dist, g[tmp.T3][i].cost, g[tmp.T3][i].to));
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 2924
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner (System.in);
		int k = in.nextInt();
		int[] primes = new int[k];
		int item = 0;
		String numString = "";
		for ( int i = 3; i < 55555; i++ ) {
			if (item == k)
				break;
			numString = Integer.toString(i);
			if (isPrime(i) && numString.charAt(numString.length()-1) == '1' ) {
				primes[item] = i;
				item++;
			}
		}
		
		String fin = "";
		
		for ( int i = 0; i < k; i++ ) {
			fin += primes[i];
			if ( i != k-1 )
				fin += " ";
		}
		System.out.println(fin);
		// System.out.println(Arrays.toString(primes));
	}
	
	public static boolean isPrime(int n) {
		// for ( int i = 2; i*i <= n; i++ ) {
		for ( int i = 2; i < n ; i++ ) {
			if ( n%i == 0 )
				return false;
		}
		return true;
	}

}

Measured memory_bytes: 21840
import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int K = in.nextInt();
        int h[] = new int[N];
        for(int i=0;i<N;i++){
            h[i] = in.nextInt();
        }
        in.close();
        long dp[] = new long[N+1];
        for(int i=0;i<N;i++){
            if(i==0){
                dp[i] = 0;
            }
            else{
                dp[i] = 1010101010;
            }
        }
        for(int i=0;i<N;i++){
            for(int j=0;j<Math.min(K+1,N-i);j++){
                if (dp[i+j] >= dp[i]+Math.abs(h[i+j]-h[i])){
                    dp[i+j] = Math.min(dp[i]+Math.abs(h[i+j]-h[i]),dp[i+j]);
                }
            }
        }
        System.out.println(dp[N-1]);
    }
}

Measured memory_bytes: 50940
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,k;
    cin>>n>>k;
    vi x(n),y(n);
    vi xx(n),yy(n);
    rep(i,n){
        cin>>x[i]>>y[i];
        xx[i]=x[i],yy[i]=y[i];
    }
    SORT(xx);
    SORT(yy);
    int ans=LLONG_MAX;
    rep(a,n){
        Rep(b,a+1,n){
            rep(c,n){
                Rep(d,c+1,n){
                    int x1=xx[a],x2=xx[b];
                    int y1=yy[c],y2=yy[d];
                    int c=0;
                    rep(i,n){
                        c+=x1<=x[i]&&x[i]<=x2&&y1<=y[i]&&y[i]<=y2;
                    }
                    if(c>=k)ans=min(ans,(x2-x1)*(y2-y1));
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace ABC_prac
{
    public class Program
    {
        #region templete

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        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); }

        /// <summary>
        /// 最小公倍数
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        static long Gcd(long a, long b)
        {
            var v = new[] { a, b };
            while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
            return v[0];
        }
        /// <summary>
        /// 最小公約数
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        static long Lcm(long a, long b)
        {
            return a / Gcd(a, b) * b;
        }
        public static void Main(string[] args)
        {
            new Program().Solve();
            Read();
        }

        #endregion

        public void Solve()
        {
            var ab = ReadInts();
            var s = Read();
            int a = ab[0];
            int b = ab[1];

            if (s[a] != '-')
            {
                WriteLine("No");
                return;
            }

            var sa = s.Substring(0, a);
            int num = 0;
            if (!int.TryParse(sa, out num))
            {
                WriteLine("No");
                return;
            }

            var sb = s.Substring(a + 1, b);
            if (!int.TryParse(sb, out num))
            {
                WriteLine("No");
                return;
            }


            WriteLine("Yes");

        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <string>

using namespace std;

long long n;
string ans;

int main(){

  cin >> n;
  if(!n){
    cout << 0 << '\n';
    return 0;
    
  }
  while(n){
    if(n % 2){
      ans = '1' + ans;
      n--;
    }
    else{
      ans = '0' + ans;
    }
      n /= -2;
  }

  cout << ans << '\n';

}


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

long f(long x){
  string s = std::to_string(x);
  int n = s.size();
  long y = 0;
  for(int i = 0;i < s.size();i++){
    y += (s.at(i) - '0');
  }
  long ans = x;
  for(int i = n-2;i >= 0;i--){
    for(int j = n-1;j >= i+1;j--){
      s.at(j) = '9';
    }
    for(char j = s.at(i);j <= '9';j++){
      s.at(i) = j;
      //cout << s << endl;
      double x2 = std::stod(s);
      double y2 = 0;
      for(int k = 0;k < s.size();k++){
        y2 += (s.at(k) - '0');
      }
      double x3 = x;double y3 = y;
      //cout << x2 << ' ' << y2 << ' ' << x3 << ' ' << y3 << endl; 
      if(x3/y3 > x2/y2){
        ans = x2;
        x = x2;
        y = y2;
        //cout << ans << endl;
      }
    }
  }
  return ans;
}
int main(){
  long k;
  cin >> k;
  long x = 2;
  cout << 1 << endl;
  for(int i = 0;i < k-1;i++){
    long y = f(x);
    cout << y << endl;
    x = y+1;
  }
}

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

int main(){
  int N;
  cin >> N;
  vector<int64_t> vec(3*N);
  int64_t former = 0;
  int64_t latter = 0;
  priority_queue<int64_t> F;
  priority_queue<int64_t> L;
  for(int i=0; i<3*N; i++){
    cin >> vec.at(i);
    if(i < N){
      former += vec.at(i);
      F.push(vec.at(i)*-1);
    }
    if(i >= 2*N){
      latter += vec.at(i);
      L.push(vec.at(i));
    }
  }
  
  vector<int64_t> f_sum(N+1);
  vector<int64_t> l_sum(N+1);
  
  f_sum.at(0) = former;
  for(int i=0; i<N; i++){
    F.push(vec.at(i+N)*-1);
    int64_t x = F.top();
    F.pop();
    f_sum.at(i+1) = f_sum.at(i) + vec.at(i+N) + x;
  }
  
  l_sum.at(N) = latter;
  for(int i=N-1; i>=0; i--){
    L.push(vec.at(N+i));
    int64_t x = L.top();
    L.pop();
    l_sum.at(i) = l_sum.at(i+1) + vec.at(i+N) - x;
  }
  
  int64_t ans = -100000000000000000;
  
  for(int i=0; i<N+1; i++){
    ans = max(ans,f_sum.at(i) - l_sum.at(i));
  }
  cout << ans << endl;
  
}



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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

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

    int n;
    cin >> n;

    int ans = 0;

    ans = 180 * (n - 2);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int a,b; cin >> a >> b;
    int res=0;
    int cnt=1;
    if(b==1){cout<<0<<endl; return 0;}
    while(1){
        cnt=cnt-1+a;
        res++;
        if(cnt>=b){cout<<res<<endl; return 0;}
    }
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(){
  int dum,n,i,j,minj,ct;
  int A[100];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<n;i++){
    minj = i;
    for(j=i;j<n;j++){
      if(A[j]<A[minj]){
	minj = j;
      }
    }
    if(i!=minj)ct++;
      dum = A[i];
      A[i]=A[minj];
      A[minj]=dum;
      
  }
  
  for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
      }
  printf("%d\n",A[n-1]);
  printf("%d\n",ct);
  return 0;
}



Measured memory_bytes: 2136
//
//AtCoder Beginner Contest 166
//E
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>
#include <numeric>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<int> a(n);
    REP(i, n) cin >> a[i];

    map<int,int> cnt;
    ll ans = 0;
    REP(i,n){
        int sa = i - a[i];
        ans += cnt[sa];
        int wa = i + a[i];
        cnt[wa]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 21216
#include "bits/stdc++.h"
using namespace std;
using ld = long double;
const ld eps = 1e-7;

ld getans(ld l,ld r, int b,ld c) {
	if (b == 0||abs(r-l)<eps) {
		return (1-l)*(r - l);
	}
	ld aa = getans(l,(1-c)*l+c*r, b - 1, c);
	ld ab = getans((1 - c)*l + c*r,r, b - 1, c);
	return aa + ab;
}

ld get() {
	int m, n, x; cin >> m >> n >> x;
	ld c = (ld(m)) / (m + n);
	return getans(0,1, x, c);
}

int main() {
	cout << setprecision(10) << fixed << get()*get() << endl;
	return 0;
}

Measured memory_bytes: 3256
import Data.List

solve :: Int -> [(Int,Int)] -> Int
solve k ab = fst $ so!!i
  where
    i  = fst . last . takeWhile (\t -> snd t < k) $ zip [0..] sl
    sl = scanl (\a t -> a + snd t) 0 so
    so = sortOn fst ab

main :: IO ()
main = do
    [n,k] <- map read . words <$> getLine :: IO [Int]
    ab <- map ((\[a,b] -> (a,b)) . (map read . words))
        . lines <$> getContents :: IO [(Int,Int)]
    print $ solve k ab

Measured memory_bytes: 79100
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vs vector<string>
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
#define q_type vector<ll>
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main()
{
    int n;
    cin>>n;
    string s1, s2;
    cin>>s1>>s2;
    string ans;
    for(int i = 0; i<n; ++i)
    {
        ans.insert(ans.end(), 1, s1[i]);
        ans.insert(ans.end(), 1, s2[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N int64
	var K int64
	fmt.Scanf("%v %v", &N, &K)

	var ans int64
	for i := K; i <= N+1; i++ {
		m1 := min(i)
		m2 := max(N, i)
		ans += (m2 - m1) + 1
//		fmt.Printf("m1=%v m2=%v, ans=%v\n", m1, m2, ans)
	}
	fmt.Printf("%v\n", ans % (1000000000 + 7))

}

func min(num int64) int64 {
	sum := 0 + (num-1)
	ret := sum * (num / 2)
	if num % 2 != 0 {
		ret += sum / 2
	}
	return ret
}

func max(a int64, num int64) int64 {
	sum := (a - num + 1) + a
	ret := sum * (num / 2)
	if num % 2 != 0 {
		ret += sum / 2
	}
	return ret
}


Measured memory_bytes: 1832
import Control.Monad
import Control.Applicative

main :: IO ()
main = do
  [m, n] <- getInts
  if (m == 0 && n == 0) then return ()
  else do
    ss <- getIntLines n
    print $ rolve m ss
    main

rolve m ss = bin_search (kuwa ss m) 1 1500000

kuwa xs m n = func xs m n n
  where
    func (x:xs) m n l
      | m <= 0 = False
      | m > 0 && xs == [] && n - x >= 0 = True
      | n - x >= 0 = func xs m (n - x) l
      | n - x < 0 = func (x:xs) (m - 1) l l

bin_search func min max
  | (max - min == 1) && (func min) = min
  | (max - min == 1) && (func max) = max
  | func center = bin_search func min center
  | not (func center) = bin_search func center max
  where
    center = div (min + max) 2
---

getInt :: IO Integer
getInt = read <$> getLine

getInts :: IO [Integer]
getInts = map read . words <$> getLine

getIntLines :: Integral a => a -> IO [Integer]
getIntLines n = replicateM (fromIntegral n :: Int) getInt

Measured memory_bytes: 4104
fun main(args : Array<String>) {
    while (true) {
        val variables = readLine()!!.split(" ")
        val a = variables[0].toInt()
        val op = variables[1]
        val b = variables[2].toInt()

        if ("?" == op) {break}

        when (op) {
            "+" -> println("%d".format(a + b))
            "-" -> println("%d".format(a - b))
            "*" -> println("%d".format(a * b))
            "/" -> println("%d".format(a / b))
        }
    }
}



Measured memory_bytes: 31892
import java.util.Scanner;
 
class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
        if(str.equals("Sunny")){
            System.out.println("Cloudy");
        }else if(str.equals("Cloudy")){
            System.out.println("Rainy");
        }else{
            System.out.println("Sunny");
        }
    }
}

Measured memory_bytes: 21332
n, m, l = gets.split.map(&:to_i)

a = []
n.times do
  a << gets.split.map(&:to_i)
end

b = []
m.times do
  b << gets.split.map(&:to_i)
end

c = Array.new(n).map{Array.new(l).map{0}}
n.times do |i|
  m.times do |k|
    l.times do |j|
      c[i][j] += a[i][k] * b[k][j]
    end
  end
end

puts c.map{|_| _.join(" ")}.join("\n")



Measured memory_bytes: 7588
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(i64, X);
    print((X / 500) * 1000 + (X % 500) / 5 * 5);

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int N;
    int count=0;
    int A[100]={0};
    scanf("%d",&N);
    for(int i=0;i<N;i++)
    {
        scanf("%d",&A[i]);
    }
    for(int i=0;i<N;i++)
    {
        for(int j=N-1;j>0;j--)
        {
            if(A[j]<A[j-1])
                {
                    int flag;
                    flag=A[j];
                    A[j]=A[j-1];
                    A[j-1]=flag;
                    count++;
                }
        }
    }
    for(int i=0;i<N;i++)
    {
        if(i==0)
            printf("%d",A[i]);
        else
            printf(" %d",A[i]);
    }
    printf("\n");
    printf("%d\n",count);
    return 0;
}



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

signed main(){
  int n;
  cin>>n;
  int lst=n+1,ans=0;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    if(a<lst) lst=a,ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <memory>

//#define int long long

using namespace std;

void Main()
{
	string s;
	cin >> s;

	for (int i = 0; i < s.length() - 1; i++) {
		if (s[i] == s[i + 1]) {
			cout << "Bad" << endl;
			return;
		}
	}

	cout << "Good" << endl;
}

int32_t main()
{
	Main();
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, l;
  cin >> n >> l;
  int sum = 0;
  int absmin = 50000;
  int mintemp = 50000;
  for (int i = l; i < l + n; i++) {
    sum +=i;
    if (chmin(absmin, abs(i))) {
      mintemp = i;
    }
  }
  cout << sum - mintemp << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/B-TwoAnagrams.py
#
s = input()
t = input()

s_sorted = sorted(s)
t_sorted = sorted(t, reverse=True)

for i in range(min(len(s), len(t))):
    if s_sorted[i] == t_sorted[i]:
        continue
    elif ord(s_sorted[i]) < ord(t_sorted[i]):
        print("Yes")
        exit()
    else:
        print("No")
        exit()

if len(s) < len(t):
    print("Yes")
else:
    print("No")





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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N; cin >> N;
	vector<int> H(N);

	REP(i,N) cin >> H[i];


	int ans = 0;
	int maxnum = -1;
	// FOR(i,1,N+1){
	REP(i,N){
		if(H[i] >= maxnum){
			ans++;
			maxnum = H[i];
		}
	}
		
	cout << ans << endl;


	return 0;

}


Measured memory_bytes: 256
MAX_N = 100000


def main():
    N, *B = map(int, open(0).read().split())
    B.insert(0, MAX_N)
    B.insert(N, MAX_N)
    print(sum(min(b1, b2) for b1, b2 in zip(B[:-1], B[1:])))
    return


main()


Measured memory_bytes: 2940
#include<iostream>
#include<queue>
using namespace std;
typedef pair<pair<int,int>,int> pa;
#define ff first.first
#define fs first.second
#define f(a,b) for(int a=0;a<b;a++)

int h,w,sx,sy,gx,gy,i,j,go,m = 999999;
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};
int co[20][20];
char ma[20][20];
string pat;

int main(){
    while(cin>>h>>w,h){
        f(i,h){
            f(j,w){
                co[i][j]=m;
                cin>>ma[i][j];
                if(ma[i][j]=='A')
                    sx=j,sy=i;
                else if(ma[i][j]=='B')
                    gx=j,gy=i;
            }
        }
        queue<pa>q;
        q.push(make_pair(make_pair(sx, sy), 0));
        while(q.size()){
            pa p = q.front();
            q.pop();
            if(co[p.fs][p.ff]!=m)
                continue;
            co[p.fs][p.ff]=p.second;
            f(i,4){
                int nx=p.ff+dx[i];
                int ny=p.fs+dy[i];
                if(nx>=0&&nx<w&&ny>=0&ny<h&&ma[ny][nx]!='#'&&co[ny][nx]==m)
                    q.push(make_pair(make_pair(nx, ny), p.second+1));
            }
        }
        cin>>pat;
        for(j=0,go=0;;j++,go++){
            i=j%pat.length();
            if(co[gy][gx]<=go){
                cout<<go<<" "<<gy<<" "<<gx<<endl;
                break;
            }
            if(go>700){
                cout<<"impossible"<<endl;
                break;
            }
            if(pat[i]=='8')
                gy--;
            else if(pat[i]=='6')
                gx++;
            else if(pat[i]=='4')
                gx--;
            else if(pat[i]=='2')
                gy++;
            gy=max(0,min(h-1,gy));
            gx=max(0,min(w-1,gx));
        }
    }
}

Measured memory_bytes: 1224