akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;

inline bool IN(int x, int y, int w, int h)
{
    return 0 <= x && x < w && 0 <= y && y < h;
}


int main()
{
	int n;
	cin >> n;
	long long int ans=1;
	while(n){
		ans*=n;
		n--;
	}
	cout << ans << endl;

}

Measured memory_bytes: 1156
#include <stdio.h>
int main(void){
  
  int N,a,b;
  int sum;
  scanf("%d\n",&N); 
  if(N==1){
    printf("Hello World\n");
  }
  else if(N==2){
    scanf("%d\n %d\n",&a,&b);
    sum=a+b;
    printf("%d\n",sum);
  }
    
    
    
  
  
  
  
  
  
  
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

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

#define INF 99999999
#define MOD (int)1e9 + 7
#define rep(i,n) for(int i = 0;i<n;i++)

int main() {

	int k;
	string s;

	cin >> s;
	cin >> k;

	rep(i, s.length()) {
		if (s[i] == 'a')continue;
		if (k >= 26- (s[i] - 'a')) {
			k -= 26 - (s[i] - 'a');
			s[i] = 'a';
		}
	}

	if (k > 0) {
		rep (i, k) {
			if (s[s.length() - 1] == 'z') s[s.length() - 1] = 'a';
			else s[s.length() - 1] += 1;
		}
	}

	cout << s << endl;
	
	return 0;
}

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

class Program
{
    static void Main()
    {
        var mod = (long)1e9 + 7;
        var NM = ReadLine().Split().Select(int.Parse).ToArray();
        var N = NM[0];
        var M = NM[1];
        var a = new int[M];
        for (int i = 0; i < M; i++)
        {
            a[i] = int.Parse(ReadLine());
        }

        var dp = new long[N + 100];

        for (int i = 0; i < M; i++)
        {
            dp[a[i]] = -1;
        }
        dp[0] = 1;
        dp[1] = dp[1] == -1 ? 0 : 1;

        for (int i = 2; i <= N + 10; i++)
        {
            if (dp[i] == 0) dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
            else dp[i] = 0;
        }
        WriteLine(dp[N]);
    }
}

Measured memory_bytes: 16352
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(b%a==0){
      System.out.println(a+b);
    }else{
      System.out.println(b-a);
    }
  }
  

  
}

Measured memory_bytes: 21972
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int n;
    cin>>n;
    n%=10;
    if(n==2 || n==4 || n==5 || n==7 || n==9){
        cout<<"hon"<<endl;
    }else if(n==0 || n==1 || n==6 || n==8){
        cout<<"pon"<<endl;
    }else{
        cout<<"bon"<<endl;
    }
    
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
int n,m;
ll x,sum,ans;
map<ll,int>mmp;
int main()
{
    scanf("%d%d",&n,&m);
    sum=0;
    ans=0;
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&x);
        sum+=x;
        ans+=mmp[sum%m];
        if(sum%m==0) ans++;
        mmp[sum%m]++;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 7612
#include <bits/stdc++.h>
#include <chrono>
using namespace std::chrono;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
#define pb push_back
#define int long long
#define ios std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define fill(x, v) memset(x, v, sizeof(x))
const ll mod = 1000000007;
const double pi = 3.14159265359; // PI
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
/*
std::cout << std::setprecision(9) << f << '\n';//3.141590000;
map<char,int>::reverse_iterator rit;
for(rit = mp.rbegin(); rit!=mp.rend(); rit++)
    auto start = high_resolution_clock::now();
    // Call the function, here
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<milliseconds>(stop - start);
    cout << "Time taken by function: "<< duration.count() << " milliseconds" << endl;
*/

int32_t main()
{
    int n;
    cin >> n;
    unsigned int mul = 1, pre = 0;
    bool f = 0, z = 0;
    for (int i = 0; i < n; i++)
    {
        unsigned int h;
        cin >> h;
        if (h == 0)
            z = 1;
        mul *= h;
        if (mul < pre || mul > 1000000000000000000)
            f = 1;
        pre = mul;
    }
    if (z)
        cout << 0;
    else if (f)
        cout << -1;
    else
        cout << mul;
    return 0;
}


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


int main() {
    std::string S;
    std::cin >> S;

    int size = S.length();
    int count = 0;
    for (int i = 0; i < size; i++) {
        char c = i % 2 == 0 ? '0' : '1';
        if (S[i] != c) {
            count++;
        }
    }

    count = std::min(size - count, count);
    std::cout << count << std::endl;
}


Measured memory_bytes: 512
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.HashMap;


public class Main
{
    int n, m;
    int a[] = new int[51];
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();
	
	out();
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);

	n = sc.nextInt();
	m = sc.nextInt();

	int f, t;
	for(int i = 0; i < m; i++) {
	    f = sc.nextInt(); a[f]++;
	    t = sc.nextInt(); a[t]++;
	}
    }

    void out()
    {
	for(int i = 1; i <= n; i++) out(a[i]);
    }
    
    void out(int ans)
    {
	System.out.println(ans);
    }
    
    void out(String ans)
    {
	System.out.println(ans);
    }
}


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

int main () {

    std::string n;
    std::cin >> n;
    if(n[0] == '7' || n[1] == '7' || n[2] == '7') std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;

    return 0;
}

Measured memory_bytes: 3136
X,N=map(int,input().split())
if(N==0):
  print(X)
else:
  p=list(map(int,input().split()))
  x=0
  while(True):
      if(X-x not in p):
          print(X-x)
          break
      if(X+x not in p):
          print(X+x)
          break
      x+=1

Measured memory_bytes: 9168
#include <iostream>
using namespace std;
typedef long long ll;
#define M 1000000007
int n,q[100005];
ll dp[2][100005];
bool s[1000005];
int main(void){
    cin>>n;
    for(int i=0;i<n;i++)cin>>q[i];
    for(int i=2;i<=1000;i++){
        if(!s[i]){
            for(int j=i*2;j<=1000000;j+=i)s[j]=true;
        }
    }
    if(!s[q[0]])dp[1][1]=1;
    for(int i=1;i<n;i++){
        dp[0][i+1]=dp[1][i];
        if(!s[q[i]]){
            if(i>0&&q[i-1]<q[i])dp[1][i+1]=dp[1][i];
            if(i>1&&q[i-2]<q[i])dp[1][i+1]=(dp[1][i+1]+dp[0][i])%M;
        }
    }
    cout<<(dp[0][n]+dp[1][n])%M<<endl;
}


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


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

    int k;cin>>k;
    int a;cin>>a;
    int b;cin>>b;
    int aux;
    aux=b/k;
    aux=aux*k;
    if(aux>=a && aux<=b) cout<<"OK\n";
    else cout<<"NG\n";

    return 0;
}


Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
static class Extensions
{
    public static int ToInt(this string s) => int.Parse(s);
    public static long ToLong(this string s) => long.Parse(s);
    public static char ToChar(this string s) => char.Parse(s);
    public static double ToDouble(this string s) => double.Parse(s);
    public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
    public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
    public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
}

class Program
{
    static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();

    static void Main()
    {
        int[] nabcd = Console.ReadLine().ToIntArray();
        int N = nabcd[0];
        int A = nabcd[1] - 1;
        int B = nabcd[2] - 1;
        int C = nabcd[3] - 1;
        int D = nabcd[4] - 1;


        int a = A;
        int b = B;

        string S = Console.ReadLine();
        Func<int, bool> isEmpty = n =>
        {
            return (S[n] != '#' && a != n && b != n);
        };

        if (C < D)
        {
            //BをDにうつ移す
            //これは、BからDまでに#が2連続の箇所がなければ可能
            if (S.Substring(B, D - B + 1).Contains("##"))
            {
                Console.WriteLine("No");
                return;
            }
            b = D;

            //次にAをCに移す
            //これは、AからCまでに#が2連続の箇所がなければ可能
            if (S.Substring(A, C - A + 1).Contains("##"))
            {
                Console.WriteLine("No");
                return;
            }

            Console.WriteLine("Yes");
            return;
        }
        else
        {
            
            if (S.Substring(B, D - B + 1).Contains("##"))
            {
                Console.WriteLine("No");
                return;
            }

            //次にAをCに移す
            //これは、AからCまでに#が2連続の箇所がなければ可能
            if (S.Substring(A, C - A + 1).Contains("##"))
            {
                Console.WriteLine("No");
                return;
            }

            //AがBを追い抜けるか
            if ((S[B - 1] == '.' && S[B + 1] == '.')
                || (S[B + 1] == '.' && S[B + 2] == '.')
                || (S.Substring(B, D - B + 1).Contains("..."))
                || (S[D - 1] == '.' && S[D + 1] == '.'))
            {
                Console.WriteLine("Yes");
                return;
            }

            Console.WriteLine("No");
            return;
        }
    }
}

Measured memory_bytes: 14304
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,d;
cin>>n>>d;
int count=0;
while(n--)
{
long long int a,b;
cin>>a>>b;
double ans=sqrt((a*a)+(b*b));
if(ans<=d){
   count++;
   }
}
cout<<count;
}

Measured memory_bytes: 3600
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int X=s.nextInt();
        int A=s.nextInt();
        int B=s.nextInt();
        int ans=X-A;
        int N=ans/B;
        for(int i=0;i<N;i++){
            ans=ans-B;
        }
        System.out.print(ans);
    }
    
}

Measured memory_bytes: 21716
import heapq
N, M = list(map(int, input().split()))
jobs = [[] for _ in range(M)]

for i in range(N):
    d, r = list(map(int, input().split()))
    if d-1 < M:
        jobs[d-1].append(-r)
rewords = 0
heap = []
for i in range(M):
    for reword in jobs[i]:
        heapq.heappush(heap, reword)
    if len(heap) >0:
        reword = heapq.heappop(heap)
        rewords += -reword

print(rewords)

Measured memory_bytes: 23752
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
    int n, k, i;
    cin >> n >> k;
    vi a(n, 0);
    rep(i,n){
        int t;
        cin >> t;
        t--;
        a[t]++;
    }
    sort(all(a));
    int ans = 0 ;
    rep(i,n-k) ans += a[i];
    cout << ans << endl;
}


Measured memory_bytes: 1024
s = input()
l = len(s)

def check_kaibun(s):
    if s == s[::-1]:
        return 1
    else:
        return -1

if check_kaibun(s) == -1:
    print('No')
    exit(0)

mae = s[0: int(l/2)]
ushiro = s[int(l/2)+1:]

if mae == ushiro:
    print('Yes')
else:
    print('No')




Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<int>;
using vec2 = vector<vector<int>>;
ll inf = pow(2,62);

int main(){
    ll n;cin >> n;
    vec a(n, -1);vec b(n,-1);vec c(n,-1);
    cin >> a[0] >> b[0] >> c[0];
    for(ll i = 1;i < n;i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i] += max(b[i-1],c[i-1]);
        b[i] += max(a[i-1],c[i-1]);
        c[i] += max(b[i-1],a[i-1]);
    }
    cout << max(a[n-1],max(b[n-1],c[n-1]));
}

Measured memory_bytes: 4300
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    int a,b; cin>>a>>b;
    if(a+b>=24){
        cout<<a+b-24<<endl;
    }
    else cout<<a+b<<endl;
}



























Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define INF 1<<30
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int d, e;
	while(cin >> d >> e) {
		if(d == 0 && e == 0) break;

		double ans = INF;
		rep(i, d + 1) {
			int y = i;
			int x = d - i;

			ans = min(ans, abs(sqrt(x * x + y * y) - e));
		}

		cout << ans << endl;
	}

	

	return 0;
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 1e9 + 7;

void solve() {
    ll n, d, res = 0;
    cin >> n >> d;
    for(ll i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        if(sqrt(x * x + y * y) <= d) res++;
    }
    cout << res << "\n";
}       

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3668
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

vector<ll> divisor(ll n)
{
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

int main(void)
{
    ll n;
    ll ans = 0;
    cin >> n;

    vector<ll> x, y;
    set<ll> p;

    x = divisor(n);
    y = divisor(n - 1);

    for (auto a : x)
    {
        p.insert(a);
    }

    for (auto b : y)
    {
        p.insert(b);
    }

    for (auto k : p)
    {
        ll n_ = n;

        if (k == 1)
        {
            continue;
        }

        while (n_ != 1)
        {
            if (n_ % k == 0)
            {
                n_ /= k;
            }
            else
            {
                n_ %= k;
            }

            if (n_ < k)
            {
                break;
            }
        }

        if (n_ == 1)
        {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int X;
  cin>>X;

  int A=1999-X;
  cout<<1+A/200<<endl;

  return 0;
}


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


int main() {
    int n ; cin >> n;
    string s; cin >> s;
    int mx = 0;
    int i = 0;
    for (char c : s){
        if (c == 'I'){
            i++;
        }else{
            i--;
        }
        mx = max(mx , i);
    }
    cout << mx;

}



Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
using namespace std;

int main() {

	long long N;
	cin >> N;

	vector<long long> A(N, 0);
	for (long long i = 0; i < N; i++) {
		cin >> A[i];
	}

	sort(A.begin(), A.end(), greater<long long>());

	long long bA;
	vector<long long> v;
	long long cnt = 0;
	for (long long i = 0; i < N - 1; i++) {
		if (A[i] == A[i + 1]) {
			bA = A[i];
			v.push_back(bA);
			if (v.size() == 2) {
				break;
			}
			for (long long j = i + 1; j < N; j++) {
				i = j;
				if (bA != A[j]) {
					i--;
					break;
				}
				else {
					cnt += 1;
				}
			}
			if (cnt >= 4) {
				v.push_back(bA);
				break;
			}
		}
	}

	if (v.size() == 2) {
		cout << v[0] * v[1] << endl;
	}
	else {
		cout << 0 << endl;
	}
	

	return 0;
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
long long n,ans=0,cnt=0;
string s,t;
int main(){
	cin >> n;
	long long m=n;
	while(1){
		if(m==0){
			break;
		}
		cnt+=m%10;
		m/=10;
	}
	if(n%cnt==0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
 
 
int main(void)
{
  int n;
  cin>>n;
  ll ans = 1;
  bool ng = 0;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    if(a == 0){
    	cout << 0 << endl;
    	return 0;
    }
    // (a*ans > INF) -> NG
    // INF/a == (INF - INF%a) / a
    if(INF%a == 0 && ans > INF/a){
    	ng = 1;
    }
    else if(INF % a && ans >= (double)(1000000000000000000/a)) {
    	ng = 1;
    }
    cerr << ans << " " << INF%a << " " << (INF/a)<<" "<<(INF/a)*ans << " " << endl;
    ans *= a;
  }
  if(ng)ans=-1;
  cout << ans << endl;
}


Measured memory_bytes: 5988
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define debug(x) cerr<<#x<<" -> "<<x<<'\n'
#define debug2(x,y) cerr<<#x<<" -> "<<x<<" "<<#y<<" -> "<<y<<'\n'
#define debug3(x,y,z) cerr<<#x<<" -> "<<x<<" "<<#y<<" -> "<<y<<" "<<#z<<" -> "<<z<<'\n'

 
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;

using ordered_set = tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T>
struct CMP {
	bool operator() (const T& lhs, const T& rhs) const{
		return lhs < rhs;
	}
};

template <typename T>
T power(T a, T n){
	T res = 1;
	while(n > 0){
		if(n & 1) res = (res * a);
		a = (a * a);
		n >>= 1;
	}
	
	return res;
}

template <typename T>
T power(T a, T n, long long mm){
	T res = 1;
	while(n > 0){
		if(n & 1) res = (res * a) % mm;
		a = (a * a) % mm;
		n >>= 1;
	}
	
	return res;
}

const ll N = 2e5+7;
const ll MOD = 1e9+7;
const ll INF = 2e14+7;

int h, w;

string grid[1005];
ll dp[1005][1005];

ll solve(int i, int j){
	
	if(i == h - 1 && j == w - 1){
		return 1;
	}
	
	if(i >= h || j >= w || grid[i][j] == '#') return 0;
	
	if(dp[i][j] != -1) return dp[i][j];
	
	return dp[i][j] = (solve(i + 1, j) + solve(i, j + 1)) % MOD;
	
}

void testcase(){
	cin>>h>>w;
	
	for(int i = 0; i < h; i++){
		cin>>grid[i];
	}
	
	memset(dp, -1, sizeof(dp));
	
	ll ans = solve(0, 0);
	cout<<ans<<'\n';
}

signed main(){
	fast;
	
	int t = 1;
	//cin>>t;
	while(t--){
		testcase();
	}
	
	return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int k,n;
    cin>>k>>n;
    vi a(n);
    rep(i,n)cin>>a[i];

    sort(all(a));

    int ans=0;
    
    repa(i,1,n){
        cmax(ans,a[i]-a[i-1]);
    }
    cmax(ans,a[0]+k-a[n-1]);

    cout<<k-ans<<"\n";

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
string st;
int n,m,i,j,f[200005],g[200005];
int main()
{
	rdst(st,200005);
	n=st.length();st=" "+st;
	memset(f,-0x18,sizeof(f));
	memset(g,-0x18,sizeof(g));
	f[0]=g[0]=0;
	f[1]=1;
	for(i=2;i<=n;i++){
		f[i]=g[i-1];
		if(st[i]!=st[i-1]) f[i]=max(f[i],f[i-1]);
		g[i]=f[i-2];
		if(i<4||st[i]!=st[i-2]||st[i-1]!=st[i-3]) g[i]=max(g[i],g[i-2]);
		f[i]++;g[i]++;
	}
	cout<<max(f[n],g[n])<<endl;
	return 0;
}

Measured memory_bytes: 2364
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
a = [int(item) for item in input().split()]
max_node = []
current = 1
for i, item in enumerate(a):
    max_node.append(current)
    current = (current - item) * 2

a.reverse()
max_node.reverse()

prev = 0
ans = 0
for i, (item, mx_nd) in enumerate(zip(a, max_node)):
    lower_bound = item + (prev + 1) // 2
    upper_bound = item + prev
    if lower_bound > mx_nd:
        print(-1)
        exit()
    prev = min(upper_bound, mx_nd)
    ans += prev
print(ans)

Measured memory_bytes: 674444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int n;
vector<int> g[MAX_N];
ll dp[MAX_N][2];

ll rec(int i, int p, bool f){
    if(g[i].size()==1 && p>=0) return 1;
    if(dp[i][f]>0)return dp[i][f];
    ll res = 1;
    for(auto to : g[i]){
        if(to==p)continue;
        ll tmp = 0;
        if(!f) tmp += rec(to,i,true);
        tmp += rec(to,i,false);
        tmp %= MOD;
        res *= tmp;
        res %= MOD;
    }
    dp[i][f] = res;
    return res;
}

int main() {
    cin >> n;
    if(n==1){
        cout << 2 << endl;
        return 0;
    }
    REP(i,n-1){
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    cout << (rec(0,-1,true) + rec(0,-1,false))%MOD << endl;
    return 0;
}

Measured memory_bytes: 15616
#include <iostream>
#include <map>
using namespace std;
#define ll long long

int main () {
  ll h, w, n;
  cin >> h >> w >> n;
  ll a[n], b[n];
  for (ll i = 0; i < n; i++) {
    cin >> a[i] >> b[i];  
    a[i]--;
    b[i]--;
  } 
   
  // m[i][j] i, jの位置が3 * 3の正方形の中心となる.
  map<ll, map<ll, ll> > m; 
  ll va[3] = {0, 1, -1};
  ll vb[3] = {0, 1, -1};
  for (ll i = 0; i < n; i++) {
    
    // 上からa[i], 左からb[i]について  
    for (ll p = 0; p < 3; p++) {
      for (ll q = 0; q < 3; q++) {
        ll y = a[i] + va[p];
        ll x = b[i] + vb[q];
        
        // 上からy，右からxについてそれを中心とする3 * 3の正方形ができるか考える
        if (y >= 1 && x >= 1 && y <= (h - 2) && x <= (w - 2)) {
          m[y][x]++;  
        }    
      }  
    }
  }
  ll sum[10];
  for (ll i = 0; i <= 9; i++) {
    sum[i] = 0;  
  }
  for (auto i : m) {
    for (auto j : i.second) {
      sum[j.second]++;
    }
  }
  ll res = 0;
  for (ll i = 1; i <= 9; i++) {
    res += sum[i];    
  }
  sum[0] = (h - 2) * (w - 2) - res;
  for (ll i = 0; i <= 9; i++) {
    cout << sum[i] << endl;  
  }
}

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

void spiral(int n);

int main(void){
  int d;
  cin>>d;
  int n;
  for(int i=0;i<d;i++){
    cin>>n;
    spiral(n);
    cout<<endl;
    if(i<d-1){
      cout<<endl;
    }
  }
  return 0;
}

void spiral(int n){
  int paper[n+4][n+4];
  for(int i=0;i<n+4;i++){
    for(int j=0;j<n+4;j++){
      paper[i][j]=0;
    }
  }
  for(int i=0;i<n+4;i++){
    paper[0][i]=1;
    paper[i][0]=1;
    paper[n+3][i]=1;
    paper[i][n+3]=1;
  }

  int now_x=2;
  int now_y=n+1;
  int forward=0;
  for(int _=0;_<n*n;_++){
    if(paper[now_y-1][now_x]+paper[now_y][now_x-1]+paper[now_y+1][now_x]+paper[now_y][now_x+1]<2){
      paper[now_y][now_x]=1;
    }
    if(forward==0){
      if(paper[now_y-2][now_x]==1){
        forward=1;
      }
      else{
        now_y-=1;
      }
    }
    else if(forward==1){
      if(paper[now_y][now_x+2]==1){
        forward=2;
      }
      else{
        now_x+=1;
      }
    }
    else if(forward==2){
      if(paper[now_y+2][now_x]==1){
        forward=3;
      }
      else{
        now_y+=1;
      }
    }
    else{
      if(paper[now_y][now_x-2]==1){
        forward=0;
      }
      else{
        now_x-=1;
      }
    }
  }

  for(int i=2;i<n+2;i++){
    for(int j=2;j<n+2;j++){
      if(paper[i][j]==1){
        cout<<"#";
      }
      else{
        cout<<" ";
      }
    }
    if(i<n+1){
      cout<<endl;
    }
  }
}



Measured memory_bytes: 3044
#include <iostream>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  int ans = 0;
  int flag = 1;
  for (int i = 0; i < N-1; i++) {
    int n = S[i] - '0';
    switch(n){
    case 0:
    case 1:
    case 2:
    case 3:
      if (flag == -1) {
        ans += n + 1;
      } else {
        ans += n;
      }
      flag = 1;
      break;
    case 4:
      if (flag == -1) {
        ans += 5;
        flag = 0;
      }
      else {
        ans += 4;
        flag = 1;
      }
      break;
    case 5:
      if (flag == 1) {
        ans += 5;
        flag = 0;
      } else {
        ans += 4;
        flag = -1;
      }
      break;
    case 6:
    case 7:
    case 8:
    case 9:
      if (flag == 1) {
        ans += 10 - n;
      }
      else {
        ans += 9 - n;
      }
      flag = -1;
      break;
    }
  }
  int last = S[N - 1] - '0';
  if(last <= 4) {
    if(flag == -1) {
      ans += last + 1;
    } else {
      ans += last;
    }
  } else if (last == 5) {
    ans += 5;
  } else {
    if(flag == 1) {
      ans += 11 - last;
    } else {
      ans += 10 - last;
    }
  }
  printf("%d\n", ans);
  return 0;
}
 

Measured memory_bytes: 1412
import collections

n, k = map(int, input().split())
alis = list(map(int, input().split()))

c = collections.Counter(alis)

jun = c.most_common()[::-1]

total = len(jun)
rem = total - k


ret = 0
if rem < 0:
    print(0)
else:
    for i in range(rem):
        ret += jun[i][1]
    print(ret)


Measured memory_bytes: 39344
import java.util.Scanner;

public class Main{
  public static void main(String[]args){
  	Scanner sc=new Scanner(System.in);
  	int w=sc.nextInt();
  	int n=sc.nextInt();
  	int[] values=new int[w];
  	for(int i=0;i<values.length;i++){
  		values[i]=i+1;
  	}

  	for(int i=0;i<n;i++){
  		String str=sc.next();
  		String[] ab=str.split(",");
  		int a=Integer.parseInt(ab[0])-1;
  		int b=Integer.parseInt(ab[1])-1;
  		int c=values[a];
  		values[a]=values[b];
  		values[b]=c;
  	}
  	for(int i=0;i<w;i++){
  		System.out.println(values[i]);
  	}
  }
}

Measured memory_bytes: 17196
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
using namespace std;
const int MAX = 1e5 + 10; //N
const ll MOD = 1e9 + 7;
int N, M, K, Q;

int main()
{
	int i, j, k;
	int a, b;
	scanf("%d%d%d", &a, &b, &k);
	vector<int> vec;
	for (i = 1; i <= min(a, b); ++i) {
		if (a%i == 0 && b %i == 0) vec.push_back(i);
	}
	reverse(vec.begin(), vec.end());
	printf("%d", vec[k - 1]);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    ll a, b;
    cin >> a >> b;
    ll num = b - a + 1;
    ll ans = 0;
    if (a%2==0 && b%2==1) {
        ans = (num/2)%2;
    }
    if (a%2==0 && b%2==0) {
        ans = ((num-1)/2)%2;
        ans ^= b;
    }
    if (a%2==1 && b%2==0) {
        ans = ((num-2)/2)%2;
        ans ^= a;
        ans ^= b;
    }
    if (a%2==1 && b%2==1) {
        ans = ((num-1)/2)%2;
        ans ^= a;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;

    cin >> a >> b >> c;

    int max;
    max = a;
    if(max < b){
        max = b;
    }
    if(max < c){
        max = c;
    }

    cout << max * 9 + a + b + c; 
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
#include<algorithm>
#include<iso646.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<n;i++)

int main(){
int a,b;
cin>>a>>b;
if(a<=8&&b<=8)
cout<<"Yay!";
else
cout<<":(";


return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int  INF = (1 << 30) - 1;
const ll INFL = 1LL << 60;
const ll mod = 10000000007;


std::chrono::system_clock::time_point start;
std::chrono::system_clock::time_point owari;

double calc_time() {
	owari = std::chrono::system_clock::now();
	return std::chrono::duration_cast<std::chrono::milliseconds>(owari - start).count();
}

/*
inline unsigned long long xor128() {
	static unsigned long long rx = 411111789, ry = 9471111169, rz = 5212488629, rw = 886575123;
	unsigned long long rt = (rx ^ (rx << 11));
	rx = ry;
	ry = rz;
	rz = rw;
	return (rw = (rw ^ (rw >> 19)) ^ (rt ^ (rt >> 8)));
}
*/
inline uint32_t xor128() {

	static uint32_t seed = 2;
	seed = seed ^ (seed << 7);
	seed = seed ^ (seed >> 12);
	return seed = seed & (~1);
}

double rand128() {
	return (double)(xor128() & 0xFFFF) / 0xFFFF;
}

int D;


int pena[26];
int s[365][26];
int ans[365];
int pe[26];
int score = 0;

inline int calc() {
	int cur = 0;
	REP(i, 365) {
		cur += s[i][ans[i]];
	}
	VI a(26, -1);
	REP(i, 365) {
		cur -= (i - a[ans[i]])*(i - a[ans[i]] - 1) / 2 * pena[ans[i]];
		a[ans[i]] = i;
	}
	REP(i, 26) {
		cur -= (365 - a[i])*(364 - a[i]) / 2 * pena[i];
	}
	return cur;

}


int main() {
	cin >> D;

	start = std::chrono::system_clock::now();
	REP(i, 26)cin >> pena[i];
	REP(i, 365)REP(j, 26) {
		cin >> s[i][j];
	}



	REP(i, D) {
		ans[i] = i % 26;
	}


	score = calc();

	REP(_, 2) {
		REP(i, 365) {
			REP(j, 26) {
				int tmp = ans[i];
				ans[i] = j;
				int cur = calc();
				if (cur < score) {
					ans[i] = tmp;
				}
				else score = cur;
			}
		}
	}


	REP(i, 365) {
		FOR(j, 1, 7) {
			if (calc_time() > 1900)break;
			if (j > 364)continue;
			REP(k, 26)REP(l, 26) {
				int tmp1 = ans[i];
				int tmp2 = ans[i + j];
				ans[i] = k;
				ans[i + j] = l;
				int cur = calc();
				if (cur < score) {
					ans[i] = tmp1;
					ans[i + j] = tmp2;
				}
				else score = cur;
			}
		}
	}
	cerr << score << endl;

	REP(i, 365) {
		cout << ans[i] + 1 << endl;
	}

}


Measured memory_bytes: 3676
#include<bits/stdc++.h>
#define P pair<int,int>
#define fr first
#define se second
using namespace std;
typedef long long ll;
const int maxx=1e5+10;
const ll mod=1e9+7;
int main(){
    int n; cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++){
        if(i%3==0||i%5==0) continue;
        ans+=i;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
#define INF 1e+14

struct edge
{
    ll to;
    ll cost;
};

vector<ll> dist(100010, INF);
vector<vector<edge>> G(100010, vector<edge>());

void dijkstra(const vector<vector<edge>> &G, int s)
{
    priority_queue<Pl, vector<Pl>, greater<Pl>> que;
    dist[s] = 0;
    que.push(P(0, s));

    while (!que.empty())
    {
        Pl p1 = que.top();
        que.pop();
        ll v = p1.second;
        if (dist[v] < p1.first)
            continue;

        for (auto e : G[v])
        {
            if (dist[e.to] > dist[v] + e.cost)
            {
                dist[e.to] = dist[v] + e.cost;
                que.push(P(dist[e.to], e.to));
            }
        }
    }
}

int main() {
    int N;
    cin >> N;
    vector<vector<edge>> G(N);
    REP(i,N-1) {
        ll a,b,c; cin >> a >> b >> c;
        --a; --b;
        G[a].push_back(edge{b, c});
        G[b].push_back(edge{a, c});
    }
    ll Q,K; cin >> Q >> K;
    K--;
    dijkstra(G, K);
    REP(i, Q)
    {
        ll x, y; cin >> x >> y;
        --x; --y;
        cout << dist[x] + dist[y] << endl;
    }
}

Measured memory_bytes: 13424
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N, S[2], T[2];
int X[1009], Y[1009], R[1009];
ld G[1009][1009];

ld dijkstra(int s, int t) {
    int range = N+2;
    vector<ld> d(range,LLINF);
    bool visited[range+9];
    mem( visited, false);
    int u = s;
    d[u] = 0;
    
    while(u!=t){
        
        ld minv = LLINF;
        visited[u] = true;
        
        for(int i=0; i<range; i++){
            if( d[i]>d[u]+G[u][i] ){
                d[i] = d[u]+G[u][i];
            }
        }
        
        for(int i=0; i<range; i++){
            if( !visited[i] && d[i]<minv ) {
                u = i;
                minv = d[i];
            }
        }
    }
    return d[N+1];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    rep(i,2) cin>>S[i];
    rep(i,2) cin>>T[i];
    
    cin>>N;
    X[0] = S[0];
    Y[0] = S[1];
    R[0] = 0;
    X[N+1] = T[0];
    Y[N+1] = T[1];
    R[N+1] = 0;
    rep1(i,N) cin>>X[i]>>Y[i]>>R[i];
    
    for(int u=0; u<=N+1; u++){
        for(int v=u+1; v<=N+1; v++){
            ld d = sqrt( pow(X[u]-X[v],2) + pow(Y[u]-Y[v],2) );
            d -= R[u] + R[v];
            if(d<0) d=0;
            G[u][v]=G[v][u]=d;
        }
    }
    
    printf("%.10llf\n",dijkstra(0,N+1));
    
}

Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N;
	cin>>N;
	vector<int> h(N);
	int ans = 0;
	rep(i,N){
		cin>>h[i];
	}
	rep(i,N){
		if(i == N-1)ans+=h[i];
		else{
			if(h[i]>h[i+1])ans+=h[i]-h[i+1];
		}		
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    X = int(input())
    luck = (X // 500) * 1000 + (X % 500) // 5 * 5
    print(luck)

if __name__ == '__main__':
    main()
    

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

int main() {
	int H, N;
	cin >> H >> N;
	vector<int> A(N);
	for(int i = 0; i < N; i++)
		cin >> A.at(i);

	int sum = 0;
	for(int i = 0; i < N; i++)
		sum += A.at(i);

	if(sum >= H)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 640
//Heaplax
//别让自己后悔
#include<bits/stdc++.h>
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
const int mod=1000000007;
int n,m,k,len,ans,f[4001][2001];
int main()
{
	re(n),re(m),re(k);
	len=(n+m-1)/(k-1);
	for(int j=1;j<k;++j)f[1][j]=1;
	for(int i=2;i<=len;++i)
		for(int j=1;j<=m;++j)
		{
			f[i][j]=(f[i-1][j]+f[i][j-1])%mod;
			if(j>=k)f[i][j]=(f[i][j]-f[i-1][j-k]+mod)%mod;
		}
	for(int i=1;i<=len;++i)
	{
		int limit=max(1,i*(k-1)-n+1);
		for(int j=m;j>=limit;j-=k-1)
			ans=(ans+f[i][j])%mod;
	}
	ans=(ans+mod)%mod;
	printf("%d\n",ans);
}


Measured memory_bytes: 31488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

ll a[200005],b[200005];

int main()
{
	ios::sync_with_stdio(false);
	int n,m,q,ans=0;
	ll w,k;
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>w;
		a[i]=a[i-1]+w;
	}
	for(int i=1;i<=m;i++)
	{
		cin>>w;
		b[i]=b[i-1]+w;
	}
	for(int i=0;i<=n;i++)
	{
		w=k-a[i];
		if(w<0) break;
		q=upper_bound(b+1,b+1+m,w)-b-1;
		ans=max(ans,i+q);
	}
	cout<<ans;
	return 0;
}




Measured memory_bytes: 6776
#include <iostream>
#include <queue>
#include <utility>
using namespace std;

int main() {
    int N;
    int G[101][101];

    cin >> N;
    for (int j = 0; j <= N; ++j) for (int k = 0; k <= N; ++k) G[j][k] = 0;
    for (int _ = 0; _ < N; ++_) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            int v; cin >> v;
            G[u][v] = 1;
        }
    }

    int min_dist[101];
    for (int j = 0; j <= N; ++j) min_dist[j] = -1;

    queue<int> que;
    que.push(1); min_dist[1] = 0;
    while (!que.empty()) {
        int v = que.front(); que.pop();

        for (int j = 1; j <= N; ++j) {
            if (G[v][j] && min_dist[j] == -1) {
                min_dist[j] = min_dist[v]+1;
                que.push(j);
            }
        }
    }

    for (int j = 1; j <= N; ++j) {
        cout << j << " " << min_dist[j] << endl;
    }

    return 0;
}

Measured memory_bytes: 3108
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
#define For(i,u) for(int i=hed[u],v=e[i].to;i;i=e[i].nex,v=e[i].to)
using namespace std;
typedef long long ll;
const int N=1e5+10;
int n,m,u,v,vis[N],f[N],hed[N],ed,eg,sz,col,cn;ll ans;
struct edge{
    int to,nex,val;
    edge(int _=0,int __=0,int ___=0):to(_),nex(__),val(___){}
}e[N<<1];
inline void add(int u,int v,int w){e[++ed]=edge(v,hed[u],w);hed[u]=ed;}
void dfs(int u,int c){
    !f[c]&&++col,vis[u]=c,++f[c],++sz;
    For(i,u){
        if(e[i].val==1) ++eg;
        if(!(~vis[v])) dfs(v,(c+e[i].val)%3);
        else if(vis[v]!=(c+e[i].val)%3) cn=0;
    }
}
int main(){
    scanf("%d%d",&n,&m);
    rep(i,1,m) scanf("%d%d",&u,&v),add(u,v,1),add(v,u,2);
    memset(vis,-1,sizeof(vis));
    rep(i,1,n) if(!(~vis[i])){
        sz=eg=col=0;cn=1;f[0]=f[1]=f[2]=0;dfs(i,0);
        ans+=cn?(col==3?(1ll*f[0]*f[1]+1ll*f[1]*f[2]+1ll*f[2]*f[0]):eg):(1ll*sz*sz);
    }
    printf("%lld\n",ans);
    return 0;
}

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

const int maxn=1e5+6;
int cnt[maxn],n,k,a;
long long tot,t;

int main()
{
	scanf("%d %d %lld",&n,&k,&t);
	tot=t;
	while(t--) {
		scanf("%d",&a);
		cnt[a]++;
	}
	for(int i=1;i<=n;++i) {
		if(k+cnt[i]-tot<=0) printf("No\n");
		else printf("Yes\n");
	}
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>

int main()
{
  const int cof[] = {10, 50, 100, 500};
  bool first = true;

  int pay;
  while (~scanf("%d",&pay)) {
    if (pay == 0)
      break;

    if (!first)
      puts("");
    first = false;

    int sum = 0;
    std::vector<int> c(4);
    for (int i = 0; i < 4; ++i) {
      scanf("%d", &c[i]);
      sum += c[i] * cof[i];
    }

    sum -= pay;
    for (int i = 3; i >= 0; --i) {
      int n = sum / cof[i];
      if (n > 0) {
	c[i] -= n;
	sum -= cof[i]*n;
      }
    }

    for (int i = 0; i < 4; ++i) {
      if (c[i] > 0)
	printf("%d %d\n", cof[i], c[i]);
    }
  }
  return 0;
}

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

#define SORT(v) sort(v.begin(),v.end())
#define si(n) scanf("%d",&n)
#define sii(n,m) scanf("%d %d",&n,&m)
#define sl(n) scanf("%lld",&n)
#define sll(n,m) scanf("%lld %lld",&n,&m)
#define ss(cad) scanf("%s",cad)
#define fst first
#define scn second
#define DBG(x) cerr << #x << " = " << (x) << endl; 
#define M 1000000007
#define N_MAX 100010

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vp;

char cad1[3010];
char cad2[3010];
int dp[3010][3010];
pi ant[3010][3010];

int main(){
	int t1, t2;
	ss(cad1);
	ss(cad2);
	t1 = strlen(cad1);
	t2 = strlen(cad2);
	for(int i = 1; i <= t1; i++)
		for(int j = 1; j <= t2; j++){
			if(cad1[i-1] == cad2[j-1]){
				dp[i][j] = 1 + dp[i-1][j-1];
				ant[i][j] = {i-1, j-1};
			}
			else{
				if(dp[i-1][j] < dp[i][j-1])
					ant[i][j] = {i, j-1};
				else
					ant[i][j] = {i-1, j};
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);			
			}
		}
	vector<char> ans;
	int x = t1, y = t2;
	while(dp[x][y] != 0){
		if(cad1[x-1] == cad2[y-1])
			ans.push_back(cad1[x-1]);
		pi tmp = ant[x][y];
		x = tmp.fst;
		y = tmp.scn;
	}
	reverse(ans.begin(), ans.end());
	for(int i = 0; i < (int)ans.size(); i++)
		printf("%c", ans[i]);
	printf("\n");
    return 0;
}

Measured memory_bytes: 109388
#include<stdio.h>
using namespace std;
int a[105];
int selectionsort(int a[],int n)
{
    int i,j,sum=0,minj;
    for(int i=0;i<n-1;i++)
    {
        minj=i;
        for(int j=i;j<n;j++)
        {
            if(a[j]<a[minj])
                minj=j;
        }
        int t=a[i];a[i]=a[minj];a[minj]=t;
        if(i!=minj)//最小?得下?不在未排序的第一个才++
        sum++;
    }
    return sum;
}
int main()
{
    int n,sum;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sum=selectionsort(a,n);
    for(int i=0;i<n;i++)
    {
        if(i)
            printf(" ");
        printf("%d",a[i]);
    }
    printf("\n");
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 2712