akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int M = sc.nextInt();
		List<ex> list = new ArrayList<ex>();
		for (int i = 0; i < N; i++) {
			list.add(new ex(1,sc.nextInt()));
		}
		for (int i = 0; i < M; i++) {
			list.add(new ex(sc.nextInt(), sc.nextInt()));
		}
		list.sort((s1,s2) -> {return s2.v - s1.v;});
		long ans = 0;
		int count = 0;
		for (int i = 0;;i++) {
			long num = list.get(i).q;
			ans += list.get(i).v * num;
			count += num;
			if (count >= N) {
				ans -= list.get(i).v * (long)(count - N);
				break;
			}
		}

		System.out.println(ans);
	}
	static class ex{
		int v;
		int q;
		public ex(int q, int v) {
			this.v = v;
			this.q = q;
		}
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 39996
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

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

ll lcm(ll a, ll b) {
    return a * (b / gcd(a, b));
}

int main(void)
{
    ll a,b;
    cin >> a >> b;
    ll c,d;
    cin >> c >> d;
    auto f = [=](ll n){
        return (n / c) + (n / d) - (n / lcm(c,d));
    };

    pr((b-a+1) - (f(b) - f(a-1)));
}

Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll n;
  cin >> n;
  
  vector<ull> a(n);
  rep(i,n) cin >> a[i];

  vsort(a);

  ll ans = 0;
  rep(i,n)
  {
    ans += a[i] - 1;
  }

  cout << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
/*
Stay innocent, be naive. 
But still dream big. 
Dream big to the point that it is beyond your ability and endeavour to achieve it. 
So dream big and don’t lose your innocence.
*/
import java.util.*;
import java.io.*;

   public class Main
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         PriorityQueue<Double> pq = new PriorityQueue<Double>();
         for(int a: arr)
            pq.add(1.0*a);
         while(pq.size() >= 2)
         {
            double a = pq.poll();
            double b = pq.poll();
            double mean = (a+b)/2.0;
            pq.add(mean);
         }
         System.out.println(pq.poll());
      }
   }

Measured memory_bytes: 21332
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(__,v.size()){rep(_,v[__].size())cout<<" "<<v[__][_];cout<<endl;}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};


signed main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	sort(all(in));
	int s=0;
	rep(i,n)s+=in[i];
	s-=in[n-1]/2;
	cout<<s<<endl;
}


















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
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; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

std::string ReplaceString
(
      std::string String1   // 置き換え対象
    , std::string String2   // 検索対象
    , std::string String3   // 置き換える内容
)
{
    std::string::size_type  Pos( String1.find( String2 ) );
 
    while( Pos != std::string::npos )
    {
        String1.replace( Pos, String2.length(), String3 );
        Pos = String1.find( String2, Pos + String3.length() );
    }
 
    return String1;
}

int main(){
    string Sd;cin >> Sd;
    string T;cin >> T;
    vector<string> L(0);
    int N = Sd.size();
    int Tsize = T.size();
    bool ok = true;
    string tmp = Sd;
    rep(i,N-Tsize+1){
        ok = true;
        rep(j,Tsize) if(ok) if(!(Sd[i+j] == '?' || Sd[i+j] == T[j])) ok = false;
        if(ok){
            tmp = Sd;
            rep(k,Tsize){
                tmp[i+k] = T[k];
            }
            tmp = ReplaceString(tmp,"?","a");
            L.push_back(tmp);
        }
    }
    sort(all(L));
    if(L.size() == 0)cout <<"UNRESTORABLE"<<endl;
    else cout << L[0] << endl;

}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char **argv){
	int x = 0;
	int y = 0;

	while(std::cin >> x >> y, (x != 0 || y != 0)){
		x <= y ? std::cout << x << " " << y : std::cout << y << " " << x;
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3112
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(long long a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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;
}

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    string S;
    cin >> S;
    int ans = 754;
    int N = S.size();
    REP(i, N - 2) {
        int x = (S[i] - '0') * 100 + (S[i + 1] - '0') * 10 + S[i + 2] - '0';
        chmin(ans, abs(x - 753));
    }
    printAns(ans);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(b>=2*a&&b<=4*a&&b%2==0){
		printf("Yes");
	}
	else{
		printf("No");
	}
}


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

#define ll long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define BLOCK 700       // Block Size

const int MAX = 5e5 + 5;

struct query
{
	int l;
	int r;
	int index;
};

query Q[MAX];
int arr[MAX], ans[MAX];     // arr[] is 1 based indexed. Others are 0 based indexed.
int freq[MAX];
int ct = 0;

bool comp(query a, query b)
{
	if(a.l / BLOCK != b.l / BLOCK)
		return a.l / BLOCK < b.l / BLOCK;
	//return a.r < b.r;
	return (a.l / BLOCK & 1) ? (a.r < b.r) : (a.r > b.r);
}

void add(int pos)
{
	freq[arr[pos]] += 1;
	if(freq[arr[pos]] == 1)
		ct += 1;
}

void remove(int pos)
{
	freq[arr[pos]] -= 1;
	if(freq[arr[pos]] == 0)
		ct -= 1;
}

int main()
{
	IOS
	int t = 1;
	//cin >> t;
	while(t--)
	{
		int n, q;
		cin >> n >> q;
		for(int i = 1; i <= n; i++)
		{
			cin >> arr[i];
		}

		for(int i = 0; i < q; i++)
		{
			cin >> Q[i].l >> Q[i].r;
			Q[i].index = i;
		}

		sort(Q, Q + q, comp);  // Sorting all queries on the basis of 'L'. If 'L' is same, then sort on the basis of 'R'.

		int ML = 0, MR = -1;   // ML = MO's Left pointer && MR = MO's Right pointer

		for(int i = 0; i < q; i++)
		{
			int L = Q[i].l;
			int R = Q[i].r;

			while(ML > L)
				ML--, add(ML);

			while(MR < R)
				MR++, add(MR);

			while(ML < L)
				remove(ML), ML++;

			while(MR > R)
				remove(MR), MR--;

			ans[Q[i].index] = ct;        // store answer of each query in the ans[] array.
		}

		for(int i = 0; i < q; i++)
			cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 15432
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979

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; }

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文

int main() {//9765
	int n, k;
	string s;
	cin >> n >> k >> s;
	s.at(k - 1) = s.at(k - 1) - 'A' + 'a' ;
	cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,k;cin>>n>>k;
    std::vector<ll> a(n);
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i];
    }
    std::vector<ll> dp(k+1,0);
    for (int i = 1; i <= k; ++i)
    {
    	for (int j = 0; j < n; ++j)
    	{
    		if(i-a[j]<0)continue;
    		else if(i-a[j]==0)dp[i]=1;
    		else{
    			dp[i]=max(dp[i],(dp[i-a[j]]+1)%2);
    		}
    	}
    }
    if(dp[k]==1)
    cout<<"First\n";
	else cout<<"Second\n";
    
}


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

using ll=long long;

ll solve(ll a,ll b,ll p){
    b++;
    vector<ll> sumv;
    sumv.push_back(0);
    auto sum=[&](ll l,ll r){
        l=max(l,a);
        return r<=l ? 0LL : (sumv[r-a]+p-sumv[l-a])%p;
    };
    for(ll x=a;x<b;x++){
        ll v=sum(a,x)+1;
        ll ten=10;
        for(int i=1;i<10;i++){
            ll y=x/ten;
            ll z=1;
            while(z<=y) z*=10;
            v=(v+p-sum(y+1,z))%p;
            ten*=10;
        }
        sumv.push_back(v+sumv.back());
    }
    return sum(a,b);
}
int main(){
    ll a,b,p;
    while(cin>>a>>b>>p,a){
        cout<<solve(a,b,p)<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 4648
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<map>
#include<set>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define il inline
#define rg register
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define rep(i,st,ed) for(rg int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(rg int i=(ed);i>=(st);--i)
#define rep0(i,n) for(rg int i=0;i<(n);++i)
#define per0(i,n) for(rg int i=(n)-1;i>=0;--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &x,const T &y){return x<y?x:y;}
template<typename T> il T qmax(const T &x,const T &y){return x>y?x:y;}
template<typename T> il void getmin(T &x,const T &y){if(y<x) x=y;}
template<typename T> il void getmax(T &x,const T &y){if(y>x) x=y;}
il void fileio(const string &s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e18+7;
const int N=2e5+7;

int a[N],n;
ll ans=0;

int main(){
//	fileio("test");
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a+i);
	per(i,n,1){
		if(a[i]+1==a[i+1]) continue;
		if(a[i]+1<a[i+1]||a[i]>i-1) return puts("-1"),0;
		ans+=a[i];
	}
	printf("%lld\n",ans);
	return 0;
}


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

typedef long long ll;
typedef vector<ll> vi;

int main(){
	int t=1;
	while(t--){
		int n;
		cin>>n;
		vi a(n);
		rep(i,n) cin>>a[i];
		vi dp(n);
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		else if(n==2){
			cout<<abs(a[1]-a[0])<<endl;
			continue;
		}
		dp[1]=abs(a[1]-a[0]);
		for(int i=3;i<=n;i++){
			dp[i-1]=min(abs(a[i-1]-a[i-2])+dp[i-2],abs(a[i-1]-a[i-3])+dp[i-3]);
		}
		cout<<dp[n-1]<<endl;
	}
	return 0;
}

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

int main() {
	int card[4][13] = { 0 };
	int a,n;
	char s;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s >> a;
		if (s == 'S') card[0][a-1] = 1;
		else if (s == 'H') card[1][a-1] = 1;
		else if (s == 'C') card[2][a-1] = 1;
		else if (s == 'D') card[3][a-1] = 1;
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			if (card[i][j] == 0) {
				if (i == 0) cout << "S " << j+1 << endl;
				else if (i == 1) cout << "H " << j+1 << endl;
				else if (i == 2) cout << "C " << j+1 << endl;
				else if (i == 3) cout << "D " << j+1 << endl;
			}
		}
	}
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    // A * N mod B = C
    // a1 = A mod B
    // a2 = (a1 + A) mod B

    int x = a % b;
    rep(i, b) {
        if (x == c) {
            put("YES");
            return 0;
        }
        x = (x + a) % b;
    }

    put("NO")
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
int main()
{
    char s[3];
    while(cin>>s)
    {
        if(s[0]=='9'||s[1]=='9')
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lll __int128
typedef long long ll; const int inf=2e9;
typedef double lf; const lf err=1e-7;
typedef pair<int,int> pii;
#define repeat(i,a,b) for(int i=(a),iE=(b);i<iE;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,iE=(a);i>=iE;i--)
#define mst(a,x) memset((a),(x),sizeof(a))
#define Clear(a) {a=decltype(a)();}
#define qwq {cerr<<"qwq"<<endl;}
#define orz(x) {cerr<<#x": "<<x<<endl;}
ll read(){ll n; scanf("%lld",&n); return n;}
const int N=2010;
const int mod=1e9+7;
//#define int ll
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int a,b;
	cin>>a>>b;
	if(a>b)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

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

string to_string(string s) {
	return '"' + s + '"';
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
	int n;
	cin >> n;
	map<int, int> cnt;
	for (int i = 1; i <= n; ++i) {
		int x = i;
		for (int f = 2; f * f <= x; ++f) {
			while (x % f == 0) {
				++cnt[f];
				x /= f;
			}
		}
		if (x != 1) {
			++cnt[x];
		}
	}
	debug(cnt);
	vector<pair<int, int>> v_cnt;
	for (auto i : cnt) {
		v_cnt.push_back(i);
	}
	set<long long> unq;
	function<void(int, int, long long)> solve = [&](int ind, int num, long long x) {
		if (num == 1) {
			unq.insert(x);
			return;
		} else if (ind == v_cnt.size()) {
			return;
		}
		long long p = 1; 
		for (int take = 0; take <= v_cnt[ind].second; ++take) {
			if (num % (take + 1) == 0) {
				solve(ind + 1, num / (take + 1), x * p);
			}
			p *= v_cnt[ind].first;
		}
	};
	solve(0, 75, 1);
	cout << unq.size() << "\n";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>                        
#define pb push_back                            
#define mp make_pair                            
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())
#define jonathan ios_base::sync_with_stdio(0)
#define livingston cin.tie(0)
using namespace std;                            
                                                
void yes() {cout << "Yes" << endl;}                                               
void no() {cout << "No" << endl;}                                                        
                                                
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};         
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; 

const int INF = 1e9 + 9;
const long long LINF = 1e18 + 8;
const double EPS = 1e-9;
const long long MOD = 1e9 + 7; //998244353
const double PI = acos(-1);

vector<int> g[100010];
bool used[100010];

void dfs(int v) {
    used[v] = true;
    for (auto to : g[v]) {
        if (!used[to]) {
            dfs(to);
        }
    }
}

void solve() {
    int n, k; cin >> n >> k;
    k = min(n, k);
    vector<int> a(n + 1);
    vector<int> d(n + 1, INF);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int res = (a[1] != 1);
    a[1] = 1;
    for (int i = 1; i <= n; i++) {
        g[a[i]].push_back(i);
    }
    queue<int> q;
    q.push(1);
    d[1] = 0;
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int i = 0; i < sz(g[v]); i++) {
            int to = g[v][i];
            if (d[to] > d[v] + 1) {
                d[to] = d[v] + 1;
                q.push(to);
            }
        }
    }

    vector<int> s(n);
    for (int i = 0; i < n; i++) {
        s[i] = i + 1;
    }
    sort(all(s), [&](int x, int y) {
        return d[x] > d[y];
    });

    for (int i = 0; i < n; i++) {
        int v = s[i];
        if (used[v]) continue;
        for (int j = 0; j < k - 1; j++) {
            v = a[v];
        }
        dfs(v);
        if (a[v] != 1) {
            res++;
        }
    }

    cout << res << endl;
}   

int main() {
    jonathan; 
    livingston;
    solve();
    return 0;
}

Measured memory_bytes: 12948
#include <stdio.h>
// #include <string.h>
// #include <math.h>

int main() {
    int n,i,a[1000];
    scanf("%d",&n);
    
    for(i=0;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(i=n-1;i>=0;i--){
        if(i==0){
            printf("%d",a[i]);
        }else{
            printf("%d ",a[i]);
        }
    }
    printf("\n");
    return 0;
}



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

vector<pair<ll, ll>> factorization(ll n) {
  ll sq = sqrt(n);
  vector<pair<ll, ll>> f;
  for (int i = 2; i <= sq; i++) {
    if (n == 1) break;
    if (n % i) continue;
    int cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    f.emplace_back(make_pair(i, cnt));
  }
  if (n > 1) f.emplace_back(make_pair(n, 1));
  return f;
}

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

  ll N, P; cin >> N >> P;
  vector<pair<ll, ll>> f = factorization(P);

  ll ans = 1;
  for (auto p: f) {
    for (int i = 0; i < p.second / N; i++) {
      ans *= p.first;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
/** 
If comrades that you trust gather around you, hope can take physical form and become visible. That’s what I believe.
*/
#include <bits/stdc++.h>
using namespace std;
/**
(▀̿Ĺ̯▀̿ ̿) (ง ͠° ͟ل͜ ͡°)ง
*/
auto main() -> int {
	ios_base::sync_with_stdio(false); cin.tie(0);
    int s, w; cin >> s >> w;
    if (w  >= s) cout << "unsafe\n";
    else cout << "safe\n";
	return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int sum[510][510];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, Q;
    cin >> N >> M >> Q;
    rep(i, M) {
        int L, R;
        cin >> L >> R;
        L--; R--;
        sum[L][R]++;
    }
    rep(i, N) {
        rep(j, N) {
            sum[i][j + 1] += sum[i][j];
        }
    }
    RREP(i, N - 1, 0) {
        rep(j, N) {
            sum[i][j] += sum[i + 1][j];
        }
    }
    while(Q--) {
        int L, R;
        cin >> L >> R;
        L--; R--;
        cout << sum[L][R] << endl;
    }


    return 0;
}
//  1   2   3
//1 +1 +1  +1
//2    +1
//3        +1

//  1   2   3
//1 1   2   3
//2     1   1
//3         1

//  1   2   3
//1 1   3   5
//2     1   2
//3         1

Measured memory_bytes: 4632
let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let sum = Array.make (n + 1) 0 in
  let pos = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    sum.(i + 1) <- as_.(i) + sum.(i);
    pos.(i + 1) <- max 0 as_.(i) + pos.(i)
  done;
  Printf.printf "%d\n" @@
    Array.fold_left max min_int @@
      Array.init (n - k + 1) @@ fun i ->
        pos.(i) + max 0 (sum.(i + k) - sum.(i)) + pos.(n) - pos.(i + k)


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

int main(){

    int A,B;
    int i,j,k;
    int a,b,c,d;
    int count=0;
    string val;

    cin >> A >> B;

    for(i=A;i<=B;i++){
        a = i / 10000;
        b = ( i / 1000 ) % 10;
        c = ( i % 100 ) / 10;
        d = i % 10; 
        if(a == d && c == b)count ++;
    }

    cout << count << endl;

    return 0;
}

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

#define INF (1e9+5)
using namespace std;
typedef long long ll;

int n, m, R;
int r[10];
int g[205][205];
int ans;

int main(){
  cin >> n >> m >> R;
  for(int i=0; i<R; i++) {
    cin >> r[i];
    r[i]--;
  }
  for (int i=0; i<n; i++)
    for (int j=0; j<n; j++)
      g[i][j] = INF;
  for(int i=0; i<m; i++) {
                int u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    g[u][v] = g[v][u] = w;
  }
  for (int k=0; k<n; k++)
    for (int i=0; i<n; i++)
      for (int j=0; j<n; j++)
        g[i][j] = min(g[i][j], g[i][k]+g[k][j]);

  sort(r, r+R);
  ans = (1<<29);
  do {
    int cost = 0;
    for(int i=1; i<R; i++) {
      cost += g[r[i-1]][r[i]];
    }
    ans = min(ans, cost);
  } while (next_permutation(r, r+R));
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

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

	int N, K; cin >> N >> K;
	vector<int> V;
	for (int i = 0; i < N; i++) {
		int tmp; cin >> tmp; V.push_back(tmp);
	}
	sort(V.begin(), V.end());
	ll ans = 0;
	for (int i = 0; i < N - K; i++) ans += ll(V[i]);
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1400
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int s,cnt=1; cin>>s;
    set<int> st;
    while(1){
        st.insert(s);
        cnt++;
        if(s%2) s=3*s+1;
        else s/=2;
        if(st.count(s)){
            cout<<cnt<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3636
from math import sqrt
for i in range(int(input())):
    a, b = map(int, input().split())
    if not a < b:
        a, b = b, a
    ans = (a-1)*2 + (a < b-1)
    c = int(sqrt(a*b))
    if c**2 == a*b:
        c -= 1
    if a < c:
        if (a*b) % c == 0:
            d = (a*b)//c - 1
        else:
            d = a*b//c
        ans += (c - a) * 2 - (c==d)
    print(ans)




Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;

    bool check =false ;
    for(int i=0;i<s.size();i++){
        int counter=count(s.begin(),s.end(),s[i]);
        if(counter>=2){
            check=true;
            break;
        }
    }
    if(check==false){
            cout<<"yes"<<endl;

    }else{
        cout<<"no"<<endl;

    }

   return 0;
}


Measured memory_bytes: 256
n=int(input())
n+=1
p=[0]*n
a=[0]*n
an=[0]*n
for i in range(1, n):
    p[i],a[p[i]]=map(int,input().split())
mi=n+1
cu=0
for i in range(1,n):
    if mi>a[i]:
        mi=a[i]
    if n-i==mi:
        cn=i-cu
        while cu<i:
            cu+=1
            an[cu]=cn
for i in range(1,n):
    print(an[p[i]])

Measured memory_bytes: 26380
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }

int n,a[N];
#define pb push_back
vector <int> G[N]; bool vis[N];
int deg[N];
void init ()
{
	queue <int> q;
	for (int i=1; i<=n; i++)
		if (deg[i]==1&&!a[i]) q.push (i);
	for (int i=1; i<=n; i++)
		vis[i]=1;
	while (q.size ())
	{
		int u=q.front (); q.pop ();
		vis[u]=0;
		for (int v:G[u])
			if (vis[v]&&--deg[v]==1&&!a[v]) q.push (v);
	}
}
int f[N],ans=0;
void dfs (int u,int fa)
{
	for (int v:G[u]) if (v!=fa&&vis[v])
	{
		dfs (v,u);
		chkmax (ans,f[u]+f[v]+a[u]);
		chkmax (f[u],f[v]);
	}
	f[u]+=a[u];
}
int x[N],y[N];
char s[N];
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	sc(n);
	for (int i=1; i< n; i++)
	{
		sc(x[i]),sc(y[i]);
		G[x[i]].pb (y[i]),G[y[i]].pb (x[i]),++deg[x[i]],++deg[y[i]];
	}
	scanf ("%s",s+1);
	int cnt=0;
	for (int i=1; i<=n; i++)
		cnt+=(a[i]=s[i]=='W');
	if (cnt<=1) return pr(cnt),0;
	init ();
	int rt=0,m=0,g=0;
	for (int i=1; i<=n; i++) if (vis[i])
		++m,g+=(a[i]^=deg[i]&1),rt=i;
	dfs (rt,0);
	pr(2*(m-1)+g-2*ans);

    return 0;
}


Measured memory_bytes: 42496
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}



signed main(){  
  int n,k;cin>>n>>k;
  int lim = (n-1)*(n-2)/2, all = n*(n-1)/2;
  if(lim < k){
    cout << -1 << endl;
    return 0;
  }
  int cnt = 0;
  cout << all - k << endl;
  repd(i,2,n+1){
    cout << 1 << " " << i << endl;
    cnt++;
  }
  repd(i,2,n+1){
    repd(j,i+1,n+1){
      if(all - k <= cnt)return 0;
      cout << i << " " << j << endl;
      cnt++;
    }
  }
}


Measured memory_bytes: 256
#include <stdio.h>

void sort(int num[]);
int main(void){
	int i, N, num[3];
	scanf("%d", &N);
	for(i = 0;i < N;i++){
		scanf("%d %d %d", &num[0], &num[1], &num[2]);
		sort(num);
		if(num[0] * num[0] == num[1] * num[1] + num[2] * num[2]){
			printf("YES\n");
		} else {
			printf("NO\n");
		}
	}

	return 0;
}

void sort(int num[]){
	int i, j, comp;
	for(i = 0;i < 3;i++){
		for(j = 2;j > i;j--){
			if(num[i] < num[j]){
				comp = num[i];
				num[i] = num[j];
				num[j] = comp;
			}
		}
	}
}

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

ll d[1002],c[1002];
ll dp[1002][1002];
const ll INF=1000100010001000100;
int main(){
    int n,m;
    cin>>n>>m;
    rep(i,n) cin>>d[i];
    rep(i,m) cin>>c[i];
    rep(i,n+1)rep(j,m+1) dp[i][j]=INF;
    rep(i,m) dp[0][i]=0;
    rep(i,n)rep(j,m){
        dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+d[i]*c[j]);
        dp[i][j+1]=min(dp[i][j+1],dp[i][j]);
    }
    ll mn=INF;
    rep(i,m+1) mn=min(mn,dp[n][i]);
    cout<<mn<<endl;
    return 0;
}


Measured memory_bytes: 9404
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int x, t;
  cin >> x >> t;
  cout << max(x - t,0) << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define pii pair<ll,ll>
#define ff first
#define ss second
#define mxx 100005
#define endl "\n"
const ll mod=1e9+7;

int main()
{
    ll a;
    double b;
    cin>>a>>b;
    ll x=round(b*100);
    ll ans=x*a;

    cout<<ans/100<<endl;

    return 0;
}


Measured memory_bytes: 3704
n, m = map(int,input().split())

if m//n == m/n:
    print(m//n)
else:
    ans = 1
    for i in range(2,min(m,10**8+1)):
        if m-i*(n-1) < i:
            break
        if m%i == 0:#from (M-i*(N-1))%i==0
            ans = i
    print(ans)

Measured memory_bytes: 63024
#include <iostream>
    #include <vector>
    #include <string>
    #include <bits/stdc++.h>
     
    #define REP(i,n) for(int i = 0; i < (int)(n); i++)
    #define ALL(x) (x).begin(),(x).end()
     
    using namespace std;
    using ll = long long;
     
    int main(){
        cin.tie(0);
        ios::sync_with_stdio(false);
     
        //write here
        //ll X,Y;
        //cin >> X >> Y;
        //cout << X + Y / 2;
        ll N,T,A;
        vector<ll> H;
        cin >> N;
        cin >> T >> A;
     
        REP(i,N){
            ll tmp = 0;
            cin >> tmp;
            H.push_back(tmp);
        }
        double h_diff= (double)(T - A);
        double min = 100000000;
        ll index = -1;
        REP(i,N){
            if(abs(h_diff - 0.006 * H[i]) < min){
                min = abs(h_diff - 0.006 * H[i]);
                index = i;
            }
        }
        cout << index + 1;
     
     
        cout << endl;
        return 0;
    }

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	slice := make([][]int, n)

	for i := range slice {
		slice[i] = make([]int, 3)
		fmt.Scanf("%d %d %d\n", &slice[i][0], &slice[i][1], &slice[i][2])
	}

	flg := true

	t, x, y := 0, 0, 0
	for _, p := range slice {
		dt := p[0] - t
		dx := p[1] - x
		dy := p[2] - y
		dist := int(math.Abs(float64(dx)) + math.Abs(float64(dy)))
		if dist > dt {
			flg = false
			break
		} else {
			if (dt+dist)%2 == 1 {
				flg = false
				break
			}

		}
		t = p[0]
		x = p[1]
		y = p[2]
	}

	if flg {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 10688
#include<iostream>

using namespace std;

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

 if(A-B<=A+B && A*B<=A+B){
   cout << A+B;
 }
 if(A-B<A*B && A+B<A*B){
 cout << A*B;
}
if(A*B<A-B && A+B<A-B){
cout << A-B;
}

 return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    int n,m;
    cin>>n>>m;
//    vector<int> a(n),b(n),parent(n),isroot(n),pcnt(n);
    vector<int> a(100100),b(100100),parent(100100),isroot(100100),pcnt(100100);
    vector<vector<int>> a2b(100100);
    
    for(int i = 0; i < n-1+m; i++)
    {
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
        a2b[a[i]].push_back(b[i]);
        isroot[b[i]]=-1;
        pcnt[b[i]]++;//oya nannnin iruka
    }
    int root;
    
    for(int i = 0; i < n; i++)
    {
        if(isroot[i]==0)
        {
            root=i;
            parent[i]=0;
        }
        else
        {
            parent[i]=-1;
        }
    }
    
    queue<int> qa;
    qa.push(root);
    while(qa.size()>0)
    {
        int nowpar = qa.front();
        qa.pop();
        
        for(int i = 0; i < a2b[nowpar].size(); i++)
        {
            int nowchi = a2b[nowpar][i];
            pcnt[nowchi]--;
            
            if(pcnt[nowchi]==0)
            {
                parent[nowchi]=nowpar+1;
                qa.push(nowchi);
            }
        }
        
    }
    
    
    for(int i = 0; i < n; i++)
    {
        cout<<parent[i]<<endl;
    }
    

    return 0;
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin>>N;
  for(int i=0;i<N;i++){
    string S;
    cin>>S;
    if(S=="Y"){
      cout<<"Four"<<endl;
      return 0;
    }
  }
  cout<<"Three"<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
char s[1000002];
int dp[1000002][3];
int main(){
    scanf("%s", s+1);   
    int n = strlen(s+1), l;
    for(int i=1;i<=n;i++) s[i] -= '0';
    for(int i=n;i>=1;i--){
        if(s[i] == 0) continue;
        l = i;
        break;
    }
    for(int i=0;i<=n;i++) dp[i][0] = dp[i][1] = dp[i][2] = 1e9;
    dp[0][0] = 0;
    dp[0][1] = 1;
    dp[0][2] = 0;
    for(int i=1;i<=n;i++){
        dp[i][0] = min(dp[i][0], dp[i-1][0] + s[i]);
        dp[i][1] = min(dp[i][1], dp[i-1][0] + s[i] + 1);
        dp[i][1] = min(dp[i][1], dp[i-1][1] + 10-s[i]-1);
        dp[i][2] = min(dp[i][2], dp[i-1][1] + 10-s[i]);
        dp[i][2] = min(dp[i][2], dp[i-1][2] + s[i]);
        dp[i][1] = min(dp[i][1], dp[i-1][2] + s[i] + 1);
    }
    printf("%d\n", dp[l][2]);
}

Measured memory_bytes: 12928
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cctype>
#define int long long
#define rg register
using namespace std;
inline int read(){
	rg int s=0,f=0;
	rg char ch=getchar();
	while(!isdigit(ch)) f|=(ch=='-'),ch=getchar();
	while(isdigit(ch)) s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
	return f?-s:s;
}
int a,b;
signed main(){
	a=read(),b=read();
	int aa=1,ans=0;
	while(aa<b){
		aa+=a-1;
		++ans;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  ll x;
  cin >> x;
  ll ans = 0;
  ll y = 100;
  while (y < x) {
    y += y/100;
    //cout << y << endl;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

ll dsum(ll i){
  st sti = to_string(i);
  ll sum = 0;
  vrep(j, sti) sum += j - '0';
  return sum;
}
int main(){
  ll n;
  cin >> n;
  ll ans = mod;
  rep(i, 1, n){
    ll sum = dsum(i) + dsum(n - i);
    if(sum < ans) ans = sum;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
while True:
    n, k = map(int,input().split())
    if n == k == 0:
        break
    data = [int(input()) for _ in range(n)]
    s = sum(data[0:k])
    ss = [s]
    for i in range(k, n):
        s = s + data[i]- data[i-k]
        ss.append(s)
    print(max(ss))


Measured memory_bytes: 11708
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	bool prime[1000000];
	rep(i,1000000)prime[i]=true;
	prime[0]=prime[1]=false;
	for(int i=2;i<1000000;i++){
		for(int j=i*2;j<1000000;j+=i){
			prime[j]=false;
		}
	}
	int n,cnt=0;
	while(cin>>n){
		cnt=0;
		rep(i,n+1){
			if(prime[i])cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 2136
from collections import deque
h,w = [int(i) for i in input().split()]
grid = [input() for _ in range(h)]

visited = [[-1] * w for _ in range(h)]
visited[0][0] = 1

black = 0

for i in grid :
    black += i.count('#')
                     
queue = deque([[0,0]])

while queue:
    x,y = queue.popleft()
    if x == h -1  and y == w - 1:
        break
    for i,j in ([-1,0],[1,0],[0,-1],[0,1]):
        nx,ny = x+i,y+j
        if nx < 0 or ny <0 or nx >= h or ny >= w:
            continue
        if grid[nx][ny] == '.' and visited[nx][ny] == -1:
            visited[nx][ny] = visited[x][y] + 1
            queue.append([nx,ny])
            
ans = h*w - visited[h-1][w-1] - black if visited[h-1][w-1] != -1 else -1


print(ans)


Measured memory_bytes: 3316