akhauriyash/Code-Regression huggingface dataset:
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*; 
import java.util.*;
import java.util.regex.*;

/*
			  br = new BufferedReader(new FileReader("input.txt"));
			  pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
			  br = new BufferedReader(new InputStreamReader(System.in));
			  pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
 */

public class Main {
	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter pw;

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		//int qq = 1;
		int qq = Integer.MAX_VALUE;
		//int qq = readInt();
		for(int casenum = 1; casenum <= qq; casenum++) {
			int n = readInt();
			int m = readInt();
			State[] l = new State[n];
			for(int i = 0; i < n; i++) {
				l[i] = new State(readLong(), readLong(), readLong());
			}
			long ret = 0;
			for(int mask = 0; mask < 8; mask++) {
				if((mask&1)!=0) for(int i = 0; i < n; i++) l[i].x *= -1;
				if((mask&2)!=0) for(int i = 0; i < n; i++) l[i].y *= -1;
				if((mask&4)!=0) for(int i = 0; i < n; i++) l[i].z *= -1;
				Arrays.sort(l);
				long xx = 0;
				long yy = 0;
				long zz = 0;
				for(int i = 0; i < m; i++) {
					xx += l[i].x;
					yy += l[i].y;
					zz += l[i].z;
				}
				ret = Math.max(ret, Math.abs(xx) + Math.abs(yy) + Math.abs(zz));
				if((mask&1)!=0) for(int i = 0; i < n; i++) l[i].x *= -1;
				if((mask&2)!=0) for(int i = 0; i < n; i++) l[i].y *= -1;
				if((mask&4)!=0) for(int i = 0; i < n; i++) l[i].z *= -1;
			}
			pw.println(ret);
		}
		exitImmediately();
	}

	static class State implements Comparable<State> {
		public long x, y, z;

		public State(long x, long y, long z) {
			super();
			this.x = x;
			this.y = y;
			this.z = z;
		}
		public long sum() {
			return x + y + z;
		}
		public int compareTo(State s) {
			return Long.compare(s.sum(), sum());
		}
	}
	
	private static void exitImmediately() {
		pw.close();
		System.exit(0);
	}

	private static long readLong() throws IOException {
		return Long.parseLong(readToken());
	}

	private static double readDouble() throws IOException {
		return Double.parseDouble(readToken());
	}

	private static int readInt() throws IOException {
		return Integer.parseInt(readToken());
	}

	private static String readLine() throws IOException  {
		String s = br.readLine();
		if(s == null) {
			exitImmediately();
		}
		st = null;
		return s;
	}

	private static String readToken() throws IOException  {
		while(st == null || !st.hasMoreTokens())  {
			st = new StringTokenizer(readLine().trim());
		}
		return st.nextToken();
	}
}

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

using namespace std;

int main(){
  int t,d,l;
  while(cin >> t >> d >> l && (t||d||l)){
  int x,cnt=0,flag=0;;
  for(int i=0;i<t;++i) {
    cin >> x;
    if(flag){
      flag--; cnt++;
    }
    if(x>=l)flag=d;
  }
  cout << cnt << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3012
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>
#include<bits/stdc++.h> 
using namespace std; 

int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n, c=0, i;
    string s;
    cin>>n>>s;
    for(i=0; i<s.length()-2; i++)
    {
    	if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')c++;
	}
	cout<<c<<endl;
    
	return 0;
}

Measured memory_bytes: 256
s = input()
s = list(s)
cnt = []
for i in range(len(s)):
  c = 0
  j = i
  while s[j] == 'A' or s[j] == 'T' or s[j] == 'C' or s[j] == 'G':
    c +=1
    j += 1
    cnt.append(c)
    if j == len(s):
      break
if not cnt:
  print(0)
else:
  print(max(cnt))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int i,j,k,n;
	bool q=true;
	string t;
	vector<string> g;
	cin>>n;
	for (i=0;i<n;i++){
		cin>>t;
		g.push_back(t);
	}
	for (i=0;i<n;i++){
		for (j=i+1;j<n;j++){
			if (g[i]==g[j]){
				q=false;
				break;
			}
		}
		if (q==false){
			break;
		}
	}
	for (i=1;i<n;i++){
		if (g[i-1][g[i-1].size()-1]!=g[i][0]){
			q=false;
			break;
		}
	}
	if (q==true){
		cout<<"Yes";
	}
	else {
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;


int main(void) {
	int x, y;
	int total=2000000000;
	int p, q, r, s;
	cin >> x >> y;
	
	if (x <= y) {
		total = min(total, y - x);
	}
	if (-x <= y) {
		total = min(total, 1 + y + x);
	}
	if (x <= -y) {
		total = min(total, 1 + -y - x);
	}
	if (-x <= -y) {
		total = min(total, 2 - y + x);
	}
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

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

}


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

using namespace std;

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int inf = 2e18;
const ld eps = 1e-9;
const int NN = 2e5 + 2;

vvi g(NN);

int pow(int a, int b, int m) {
	a %= m;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}

void solve() {
	int i = 0, j = 0, k = 0, n = 0, m = 0;
	string s;
	cin >> s;
	n = sz(s);
	vi vec(2019, 0);
	int ans = 0;
	for(i = 0; i < n; i++) {
		vi newVec(2019, 0);
		for(j = 0; j < 2019; j++) {
			int ne = (j * 10 + (s[i] - '0'))% 2019;
			newVec[ne] = vec[j];
		}
		newVec[s[i] - '0']++;
		ans += newVec[0];
		vec = newVec;
	}

	cout << ans << endl;
}

int32_t main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int T = 1;
	// cin >> T;
	for(int tc = 1; tc <= T; tc++) {
		solve();
	}

	return 0;
}

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

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

  vector<int> s;

  while(n){
    if (n % k == 0)
    {
      s.push_back(0);
    } else {
      s.push_back(1);
    }
    n /= k;
  }

  cout << s.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAXN=100009;
ll a[100];
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
 
	int n;
	cin>>n;
	a[0]=2;a[1]=1;
	for(int i=2;i<=n;i++) a[i]=a[i-1]+a[i-2];
	cout<<a[n]<<endl;
	return 0;
}


Measured memory_bytes: 256
// IOI 2021
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 998244353;
 
////////////////////////////////////////////////////////////////////
 
const int N = 1e7 + 5;

int F[N], I[N];

int Power(int a, int b) {
	int res = 1;
	for (; b; b >>= 1, a = 1LL * a * a % MOD) if (b & 1) res = 1LL * res * a % MOD;
	return res;
}
int C(int n, int r) { 
	if (n < 0 || n < r) return 0;
	return 1LL * I[r] * I[n - r] % MOD * F[n] % MOD;
}

int main() {
 
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));

	F[0] = 1;
	for (int i = 1; i < N; i++) F[i] = 1LL * i * F[i - 1] % MOD;
	I[N - 1] = Power(F[N - 1], MOD - 2);
	for (int i = N - 1; i > 0; i--) I[i - 1] = 1LL * i * I[i] % MOD;

	int n; cin >> n;
	int ans = Power(3, n);
	for (int i = n / 2 + 1; i <= n; i++) ans = (ans - 2LL * C(n, i) * Power(2, n - i) % MOD + MOD) % MOD;
	cout << ans << endl;	

	return 0;
}


Measured memory_bytes: 81816
let () = Scanf.scanf "%d\n" @@ fun n ->
  let ss = Array.init n @@ fun _ -> Scanf.scanf "%s\n" @@ fun s -> s in
  Printf.printf "%d\n" @@
    Array.fold_left (List.fold_left (fun acc (a, b, w) ->
      if
        List.for_all (fun i ->
          List.for_all (fun j ->
            ss.((i + a) mod n).[(j + b) mod n] = ss.((j + a) mod n).[(i + b) mod n]) @@
            Array.to_list @@
              Array.init i @@ fun j -> j) @@
            Array.to_list @@
              Array.init (n - 1) @@ fun i -> i + 1
      then acc + w
      else acc)) 0 @@
    Array.init n @@ function
      | 0 -> [(0, 0, n)]
      | i -> [(i, 0, n - i); (0, i, n - i)]

Measured memory_bytes: 6528
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	l := 0
	for s[l] != 'A' {
		l++
	}
	r := len(s) - 1
	for s[r] != 'Z' {
		r--
	}
	fmt.Println(r - l + 1)
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>n;
    vi a(n);
    cin>a;
    int sum=accumulate(all(a),0);
    int mi=INF;
    int mii;
    REP(i,n){
        if(chmin(mi,abs(sum-a[i]*n))){
            mii=i;
        }
    }
    cout<mii<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.nextLine());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(scan.next());
        }

        boolean flag = true;
        int count = 0;
        while (true) {
            for (int i = 0; i < n; i++) {
                if (a[i] % 2 != 0) {
                    flag = false;
                }
            }
            if (flag) {
                count++;
                for (int i = 0; i < n; i++) {
                    a[i] = a[i] / 2;
                }
            } else {
                break;
            }
        }
        System.out.println(count);

    }
}

Measured memory_bytes: 22484
#include <stdio.h>

int bubble_sort(int *A, int N)
{
	int i, cnt = 0, flag = 1;
	while (flag) {
		flag = 0;
		for (i = N - 1; i > 0; i--) {
			if (A[i] < A[i - 1]) {
				int tmp = A[i];
				A[i] = A[i - 1];
				A[i - 1] = tmp;
				flag = 1;
				cnt++;
			}
		}
	}
	return cnt;
}

int main(int argc, char** argv)
{
	int i, num, arr[100];

	scanf("%d", &num);
	for (i = 0; i < num; i++) {
		scanf("%d", &arr[i]);
	}

	int cnt = bubble_sort(arr, num);

	for (i = 0; i < num; i++) {
		if (i == num - 1) {
			printf("%d\n", arr[i]);
		}
		else {
			printf("%d ", arr[i]);
		}
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> sushi;
  for (int i = 0; i < n; i++) {
    int t, d;
    cin >> t >> d;
    t--;
    sushi.push_back({d, t});
  }
  sort(sushi.begin(), sushi.end());
  reverse(sushi.begin(), sushi.end());
  vector<bool> usd(n, false);
  long long ans = 0;
  long long score = 0;
  int cnt = 0;
  priority_queue<int> unused_repr;
  priority_queue<int, vector<int>, greater<int>> used_subj;
  for (int i = 0; i < n; i++) {
    auto sus = sushi[i];
    int d = sus.first;
    int t = sus.second;
    if (usd[t]) {
      if (i < k) {
        score += d;
        used_subj.push(d);
      }
    } else {
      usd[t] = true;
      if (i < k) {
        score += d + 2 * cnt + 1;
        cnt++;
      } else {
        unused_repr.push(d);
      }
    }
  }
  ans = score;
  while (!unused_repr.empty() && !used_subj.empty()) {
    int repr = unused_repr.top();
    unused_repr.pop();
    int subj = used_subj.top();
    used_subj.pop();
    score += (long long)repr - subj + 2 * cnt + 1;
    cnt++;
    ans = max(ans, score);
  }
  cout << ans << '\n';
  return 0;
}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main() {
    string s,t;
    cin>>s>>t;
    int ans=INF;
    rep(i,0,s.size()-t.size()+1){
        string ss=s.substr(i,t.size());
        int cnt=0;
        rep(j,0,t.size()){
            if(ss[j]!=t[j])cnt++;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int n , x;
	cin >> n >> x;
	int l=1,r=2*n-1;
	vector<int> v(1,x);	
	bool f = 0;
	while( l < r ){
		if( l == x ) l++;
		if( r == x ) r--;
		
		if(f){
			v.insert(v.begin() , l++ );
			v.push_back(r--);
			f = 0;
		}
		else{
			v.insert(v.begin() , r-- );
			v.push_back(l++);
			f = 1;
		}
	}

	vector<int> ori = v;
	
	bool flag = 1;

	if( x == 1 || x == 2*n-1 ) flag = 0;

	/*
	rep(i,0,n-1){
		vector<int> v2;
		rep(j,0,v.size()-2){
			vector<int> v3(3);
			rep(k,0,3) {
				v3[k] = v[k+j];
			}
			vsort(v3);
			v2.push_back(v3[1]);			
		}
		v = v2;
	}
	*/
	
	if( /*v[0] == x*/ flag  ){
		Yes;
		rep(i,0,ori.size()) cout << ori[i] << endl;
	}
	else No;

	ret 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin>>N;
  int counter;
  for (int i =0 ;i<N;i++) {
    int l,r;
    cin >>l>>r;
    counter+=r-l+1;
  }
  cout << counter <<endl;
}

Measured memory_bytes: 256
'use strict';

function Main(input) {
  var ATGC_STR = 'ATGC';
  var max_len = 0;
  for (var i in input) {
    if (ATGC_STR.indexOf(input[i]) >= 0) {
      var ct = 0;
      for (var j = i; j < input.length; j++) {
        if (ATGC_STR.indexOf(input[j]) < 0) {
          break;
        }
        ct++;
      }
      max_len = max_len < ct ? ct : max_len;
    }
  }
  console.log(max_len);
};
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

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

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  int64 N, W;
  while (cin >> N >> W && N + W) {
    map<int64, int64> mp;
    int64 num = 0, maxi = 0;
    REP(i, N) {
      int64 x;
      cin >> x;
      mp[x/W]++;
      chmax(num, x/W); chmax(maxi, mp[x/W]);
    }
    num++;
    double res = 0;
    for (auto x : mp) {
      res += (1.0 - (double)(x.fs)/(double)(num-1)) * (double)x.sc / (double)maxi;
    }
    cout << fixed << setprecision(10) << res+0.01 << endl;
  }
}


Measured memory_bytes: 3240
#include <iostream>
#include <bitset>
#include <fstream>
#include <math.h>

using namespace std;

#define NUM_LIMIT 1000000   // numbers < NUM_LIMIT

int getNumOfPrimes(bitset<NUM_LIMIT> &isPrime, int last_limit, int limit){
    int cnt = 0;
    for (int i = 2; i <= limit; i++){
        if (!isPrime[i]) continue;  // skip non prime numbers
        cnt ++;
        // cross out the multiples of the number
        for (int j = max(2.0,ceil((double)last_limit/i)); i*j <= limit; j++){
            isPrime[i*j] = 0;
        }
    }
    return cnt;
}

int main(){
    //ifstream cin("input.txt");
    bitset<NUM_LIMIT> isPrime;
    isPrime.set();  // set all bits to 1
    
    // input data
    int number;
    int max_num = 0;
    while(cin >> number){
        int cnt = 0;
        if (number > max_num){
            cnt = getNumOfPrimes(isPrime, max_num+1, number);
            max_num = number;
        } else {
            cnt = getNumOfPrimes(isPrime, number+1, number);
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 1284
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define mod  1000000007
ll modpow(ll x,ll n)
{
	ll res=1;
	while(n>0)
	{
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[1000005],R[1000005],th[1000005],tw[1000005];
void make(){
	F[0] = th[0] = tw[0] = 1;
	for(int i=1;i<1000005;i++){
		F[i] = F[i-1]*i%mod;
		th[i]  = th[i-1]*3LL%mod;
		tw[i] = tw[i-1]*2LL%mod;
	}
	for(int i=0;i<1000005;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int n,int m){
	return F[n] * R[m] % mod * R[n-m] % mod;
}
int main(){
	int n,m,k; cin >> n >> m >> k;
	if(m>k) swap(m,k);
	make();
	ll ret = 0;
	for(int i=0;i<=m;i++){
		//for(int j=0;j<=k;j++){
			ll sum = C(n+i-1,n-1) * tw[i] % mod;
			sum *= th[m+k-i];
			sum %= mod;
			ret += sum;
	//	}
	}
	ll beg = tw[m];
	for(int i=m+1;i<=k;i++){
		//for(int j=0;j<=k;j++){
			beg = beg*2LL-C(i-1,m);
			beg = (beg%mod+mod)%mod;
			ll sum = C(n+i-1,n-1) * beg % mod;
			sum *= th[m+k-i];
			sum %= mod;
			ret += sum;
	//	}
	}
	for(int i=k+1;i<=m+k;i++){
		//for(int j=0;j<=k;j++){
			beg = beg*2LL-C(i-1,m)-C(i-1,i-k-1);
			beg = (beg%mod+mod)%mod;
			ll sum = C(n+i-1,n-1) * beg % mod;
			sum *= th[m+k-i];
			sum %= mod;
			ret += sum;
	//	}
	}
	cout << ret%mod << endl;
}

Measured memory_bytes: 32120
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  LL X, Y; cin >> X >> Y;

  int cnt = 0;
  while (X <= Y) {
    X *= 2;
    ++cnt;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <cstddef>
#include <cstdint>
#include <vector>

namespace null_null {

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

template <typename T>
std::vector<T> make_v(usize a) { return std::vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(usize a, Ts... ts) {
  return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename std::enable_if<std::is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename std ::enable_if<std::is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
  for (auto &e : t) fill_v(e, v);
}

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

} // namespace null_null

#include <algorithm>
#include <iostream>
#include <utility>

namespace null_null {

void main_() {
  i64 K, A, B;
  std::cin >> K >> A >> B;

  if (A >= K) {
    std::cout << 1 << std::endl;
  } else if (A <= B) {
    std::cout << -1 << std::endl;
  } else {
    std::cout << (K - A + (A - B - 1)) / (A - B) * 2 + 1 << std::endl;
  }
}

} // namespace null_null

int main() {
  null_null::main_();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==1&&b==1||c==1) o("Open");
	else o("Close");
}

Measured memory_bytes: 1160
N,X = map(int,input().split())
x = list(map(int,input().split()))
for i in range(N):
    x[i] = abs(x[i]-X)
y = x[0]
for i in range(N):
    if x[i]%y == 0:
        continue
    while x[i] != 0:
        y, x[i] = x[i], y % x[i]
print(y)

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


bool comparep(const pair<long,long> a, const pair<long, long> b){
  if(a.first!= b.first){
    return a.first<b.first;
  }
  return a.second>b.second;
}

vector<pair<long, long> > drink;

int main(){
  long N, M;
  cin >> N >> M;
  for(long i=0; i<N; i++){
    long a, b;
    cin >> a >> b;
    pair<long, long> p = make_pair(a,b);
    drink.push_back(p);
  }
  sort(drink.begin(), drink.end(), comparep);
  long long cost=0;
  for(long i=0; i<N; i++){
    if(drink[i].second>=M){
      cost+= M*drink[i].first;
      break;
    }else{
      cost+=drink[i].second*drink[i].first;
      M-=drink[i].second;
    }
  }
  cout << cost << endl;
  return 0;
}

Measured memory_bytes: 2420
N,W=map(int,input().split())

wvlist=[]
for i in range(N):
  w,v=map(int,input().split())
  wvlist.append((w,v))
  
#normalize
w1=wvlist[0][0]

w2vlist=[]
for i in range(N):
  w,v=wvlist[i]
  w2vlist.append((w,w-w1,v))
#print(w2vlist)

dp=[[[0 for _ in range(3*N+1)] for _ in range(N+1)] for _ in range(N+1)]
#print(dp)

for i in range(1,N+1):
  w,wd,v=w2vlist[i-1]
  for j in range(N+1):
    for k in range(3*N+1):
      dp[i][j][k]=dp[i-1][j][k]
      if j>0 and k-wd>=0:
        dp[i][j][k]=max(dp[i][j][k],dp[i-1][j-1][k-wd]+v)

max_answer=0
for j in range(N+1):
  for k in range(3*N+1):
    if w1*j+k<=W:
      max_answer=max(max_answer,dp[N][j][k])
      #print(j,k,dp[N][j][k])
      
print(max_answer)

Measured memory_bytes: 69724
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as VU
import Data.Array.Unboxed
import Data.Array.IO
import Control.Monad
import Data.Char
import Data.Maybe

solve :: Int -> VU.Vector Int -> IO Int 
solve n xs = do
    dp <- newArray ((0,0),(n,n)) 0 :: IO (IOUArray (Int,Int) Int)
    forM_ [1..n] $ \l ->
       if even $ n-l 
           then
                forM_ [0..n-l] $ \i -> do
                    let j = i + l
                    a <- (+ (xs VU.! i)) <$> readArray dp (i+1,j) 
                    b <- (+ (xs VU.! (j-1))) <$> readArray dp (i,j-1) 
                    writeArray dp (i,j) $! max a b
           else
                forM_ [0..n-l] $ \i -> do
                    let j = i + l
                    a <- (flip (-) (xs VU.! i)) <$> readArray dp (i+1,j) 
                    b <- (flip (-) (xs VU.! (j-1))) <$> readArray dp (i,j-1) 
                    writeArray dp (i,j) $! min a b
    readArray dp (0,n)
                   
main = do
    n <- readLn :: IO Int
    as <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    solve n as >>= print

Measured memory_bytes: 71676
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N;
    cin >> N;
    vector<int>as(N);
    int odds = 0;
    int even = 0;
    for(int i=0; i<N; i++){
        cin >> as.at(i);
        if (as.at(i)%2 == 1){
            odds++;
        }
        else even++;
    }
    if(even==N)cout << "second" << endl;
    else cout << "first" << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define y1 __y1__
using namespace std;

int N;
char A[105];

int main() {
	scanf("%d %s", &N, A);
	if(strlen(A) > N) {
		for(int j=0; j<N; j++) printf("%c", A[j]);
		puts("...");
	} else {
		puts(A);
	}
}

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

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

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

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) os << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,L,Q;
vector<ll> X,A,B;


void input(){
  #ifdef __LOCAL
      fs::path p = __FILE__;
      fs::path input,output;
      input = output = p.parent_path();
      input += string("/input/") + string(p.stem()) + string(".txt");
      output += string("/output/") + string(p.stem()) + string(".txt");
      freopen(input.c_str(), "r", stdin);
      freopen(output.c_str(), "w", stdout);
  #endif

  fast_io();
  cin >> N;
  X = fetch_vec<ll>(N);
  cin >> L >> Q;
  for (int i = 0; i < Q; i++)
  {
    ll a,b;
    cin >> a >> b;
    a--,b--;
    if(a>b) swap(a,b);
    A.push_back(a);
    B.push_back(b);
  }
  

}



int solve(){
  int LogN = floor(log2(N));
  vector<vector<int>> next(LogN+1,vector<int>(N,0));
  for (int j = 0; j < N; j++)
  {
    auto itr = upper_bound(X.begin(),X.end(),L+X[j]);
    itr--;
    next[0][j] = itr-X.begin();
  }
  DBG(next[0])
  for (int k = 0; k < LogN; k++)
  {
    for (int i = 0; i < N; i++)
    {
      next[k+1][i] = next[k][next[k][i]];
    }
  }

  for (int i = 0; i < Q; i++)
  {
    int a=A[i],b=B[i];
    int ans=0;

    for(;;){
      int ng=-1,ok=LogN+1;
      while(ok-ng>1){
        int mid=(ng+ok)/2;
        if(next[mid][a]>=b) ok=mid;
        else ng=mid;
      }
      if(ng==-1){ans+=1; cout << ans << endl; break;}
      else{
        a = next[ng][a];
        ans += (1<<ng);
        }
    }

  }
  


  return 0;
}

int main()
{
  input();
  solve();
  return 0;
}


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

int main(){
  ll K; cin>>K;
  ll A[50];
  rep(i,50) A[i]=49-(K%50)+K/50;
  rep(i,K%50) A[i]+=50;
  cout<<50<<endl;
  rep(i,49) cout<<A[i]<<" ";
  cout<<A[49]<<endl;
  return 0;
}


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

using namespace std;

int main() {
    int n,flag=0;
    cin>>n;
    int a[n] , b[n] ;
    for(int i=0;i<n;i++) cin>>a[i]>>b[i] ;
    for(int i=0;i<n-2;i++)
    {
        if((a[i]==b[i])&(a[i+1]==b[i+1])&(a[i+2]==b[i+2])){ flag=1 ; break ; }
    }
    if(flag)cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct edge {
  int to, cost;
  edge() {}
  edge(int to, int cost): to(to), cost(cost) {}
};

const ll INF = 1LL << 50;
int N;
int a[100010], b[100010], c[100010];
int Q, K;
vector<edge> G[100010];
ll dis[100010];

void bfs() {
  fill_n((ll*)dis, 100010, INF);
  dis[K] = 0;
  queue<int> que;
  que.emplace(K);
  while (!que.empty()) {
    int cur = que.front();
    que.pop();
    for (edge &e : G[cur]) {
      if (dis[e.to] == INF) {
        dis[e.to] = dis[cur] + e.cost;
        que.emplace(e.to);
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--, b[i]--;
    G[a[i]].emplace_back(b[i], c[i]);
    G[b[i]].emplace_back(a[i], c[i]);
  }
  cin >> Q >> K;
  K--;
  bfs();
  for (int i = 0; i < Q; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    cout << dis[x] + dis[y] << endl;
  }

  return 0;
}

Measured memory_bytes: 9972
num = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(num-1):
    min_j = i
    for j in range(i+1, num):
        if A[min_j] > A[j]:
            min_j = j
    if min_j != i:
        a = A[i]
        A[i] = A[min_j]
        A[min_j] = a
        count += 1
A_str = [str(k) for k in A]
print(' '.join(A_str))
print(count)


Measured memory_bytes: 5604
#include <stdio.h>
#define MAX 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];

int prim(){
  int i,v,u,minv;
  int d[MAX],p[MAX],color[MAX];

  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }

  d[0]=0;

  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv > d[i] && color[i] != BLACK){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1) break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v] != BLACK && M[u][v] != INFTY){
	if(d[v]>M[u][v]){
	  d[v]=M[u][v];
	  p[v]=u;
	  color[v]=GRAY;
	}
      }
    }
  }
  int sum=0;
  for(i=0;i<n;i++)
    if(p[i]!=-1) sum+=M[i][p[i]];


  return sum;
}

int main(){
  int i,j,e;
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      if(e==-1) M[i][j]=INFTY;
      else M[i][j]=e;
    }
  }

  printf("%d\n",prim());

  return 0;
}



Measured memory_bytes: 2112
import java.util.Scanner;

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

        int A = sc.nextInt();
        int B = sc.nextInt();

        System.out.println(solve(A, B) ? "Possible" : "Impossible");

        sc.close();
    }

    static boolean solve(int A, int B) {
        return A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0;
    }
}

Measured memory_bytes: 21332
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
    
   int n;
   cin >> n;
   int i;
   char txt[100];
   int ac,wa,tle,re;
   ac=wa=tle=re=0;
   for(i=0;i<n;i++){
       cin >> txt;
       switch (txt[0])
       {
       case 'A':
           ac++;
           break;
              case 'W':
           wa++;
           break;
              case 'T':
           tle++;
           break;
              case 'R':
           re++;
           break;
       
       }
   }
   cout << "AC x "<<ac<<"\n";
   cout << "WA x "<<wa<<"\n";
   cout << "TLE x "<<tle<<"\n";
   cout << "RE x "<<re<<"\n";
   
}

Measured memory_bytes: 3632
#include <stdio.h>
#include<math.h>
int main(void){
    int n,i;
    scanf("%d",&n);
    double a[n],b[n],p1=0,p2=0,p3=0,p=0;
    for(i=0;i<n;i++){
        scanf("%lf",&a[i]);
    }
    for(i=0;i<n;i++){
        scanf("%lf",&b[i]);
    }
    for(i=0;i<n;i++){
        double x;
        x=fabs(a[i]-b[i]);
        
        p1+=x;
        p2+=pow(x,2);
        p3+=pow(x,3);
        if(p<x)
        p=x;
    }
    p2=sqrt(p2);
    p3=cbrt(p3);
    printf("%lf\n%lf\n%lf\n%lf\n",p1,p2,p3,p);
  return 0;
}

Measured memory_bytes: 2980
# O(K log K) solution

require 'set'

_, _, _, k = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)
cs = gets.split.map(&:to_i)

as.sort!.reverse!
bs.sort!.reverse!
cs.sort!.reverse!

# priority queue like
comb = Set.new
ans = []

# init
comb << [0, 0, 0]

score = ->(a, b, c) { as[a] + bs[b] + cs[c] }

k.times do
  t = comb.max_by(&score)
  comb.delete(t)
  ans << t

  a, b, c = t
  opts = [
    [a + 1, b, c],
    [a, b + 1, c],
    [a, b, c + 1],
  ]
  opts.select! { |a, b, c| as[a] && bs[b] && cs[c] }
  comb.merge(opts)
end

ans.map!(&score)
p(*ans)


Measured memory_bytes: 4600
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <random>

using namespace std;

vector<long long> inp;
long long cnt(bool oddPos){
    long long ret = 0;
    long long sum = 0;
    bool odd = true;
    for(long long i:inp){
        sum += i;
        if(sum == 0 || (sum <= 0) == (odd == oddPos)){
            ret += (abs(sum) + 1); 
            sum = (odd == oddPos) ? 1 : -1;
        }
        odd = !odd;
    }
    return ret;
}
int main(){
    long long n;
    cin >> n;
    for(long long i=0;i < n; i++){
        long long buf;
        cin >> buf;
        inp.push_back(buf);
    }
    cout << min(cnt(false), cnt(true)) << endl;
}


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

//main関数
int main() {
    //入力
    long A,B;
    cin>>A>>B;
    //計算
    
    //出力
    if(B%A==0){
        cout<<A+B<<endl;
    }else{
        cout<<B-A<<endl;
    }
}


Measured memory_bytes: 764
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

ll N,W,dp[101][100100],w,v;

int main(){
    cin>>N>>W;
    rep(i,100100)dp[0][i]=0;
    repi(i,1,N+1){
        cin>>w>>v;
        rep(j,W+1){
            if(j<w)dp[i][j]=dp[i-1][j];
            else{
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v);
            }
        }
    }
    out(dp[N][W]);
}


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

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    int a,b,i;
    cin >> a >> b;
    if(b==1)
    {
        cout << '0';
        return 0;
    }
    for(i=1;i<=100000;i++)
    {
        if(((a*i)-i+1)>=b)
            break;
    }
    cout << i;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	sort(begin(s),end(s));
	sort(begin(t),end(t),greater<char>());
	if(s<t) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3656
#include <stdio.h>

int main (){
    int x1,y1,x2,y2,x3,y3,x4,y4, side1, side2, rev1, rev2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    side1=x2-x1; side2=y2-y1;
    rev1=(-1)*side2; rev2=side1;
    x3=rev1+x2; y3=rev2+y2;
    x4=rev1+x1; y4=rev2+y1;
    printf("%d %d %d %d\n", x3, y3, x4, y4);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

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

  ll a, b;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      a = i;
      b = n / i;
    }
  }
  cout << a + b - 2 << endl;

  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			int x = int.Parse(Console.ReadLine());



			int ans = x / 100;
				
			int mod = x % 100;

			if (ans > 0 && mod <= 5 * ans)
			{
				Console.WriteLine(1);
			}
			else
			{
				Console.WriteLine(0);
			}

		}

		//static (int ans, int mod) Divide(int n, int d)
		//{
		//	int ans = n / d;
		//	int mod = n % d;
		//	return (ans, mod);
		//}

	}


}


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

int main()
{
  int n;
  cin>>n;;
  int a[n];
  long long height = 0;
  for(int i=0;i<n;i++)
     cin>>a[i];
    if(n==1)
    {
      cout<<0<<endl;
      return 0;
    }
  for(int i = 1;i<n;i++)
  {
    if(a[i]<a[i-1])
    {
      height = height+a[i-1]-a[i];
      a[i] = a[i-1];
    }
  }
  cout<<height<<endl;
  return 0;
}


Measured memory_bytes: 4396
n, k = map(int, input().split())
A = [0] + list(map(int, input().split()))
now = 1
used = [-228] * (n + 191)
used[1] = -1
cn = -292
ahah = 1
for _ in range(k):
    now = A[now]
    if used[now] != -228:
        cn = _ + 1 - used[now] - 1
        break
    used[now] = _
    ahah += 1
if cn == -292:
    print(now)
    exit(0)
for i in range((k - ahah) % cn):
    now = A[now]
print(now)


Measured memory_bytes: 32376
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int max_n=100010;
int main()
{
    int n,k,hand[max_n],feet[max_n],hn,fn;
    char s[max_n];
    cin>>n>>k;
    scanf("%s",s);
    int len;
    len = strlen(s);
    hn = 0;fn = 0;
    int nw=1;
    int cnt = 0;
    for(int i=0;i<n;i++)
    {
        s[i]=s[i]-'0';
        if (nw==0 && s[i]==0)
        {
            cnt++;
            if(i==n-1)feet[fn++] = cnt;
        }
        else if (nw==1&&s[i]==1)
        {
            cnt++;
            if(i==n-1)hand[hn++] = cnt;
        }
        else if (nw==0 && s[i]==1)
        {
            feet[fn++] = cnt;
            cnt = 1;
            nw = 1;
            if(i==n-1)hand[hn++] = cnt;
        }
        else if (nw==1 & s[i]==0)
        {
            hand[hn++] = cnt;
            cnt = 1;
            nw = 0;
            if(i==n-1)feet[fn++] = cnt;
        }
        s[i] = s[i] + '0';
    }
    if(hn==fn)
        hand[hn++] = 0;
    /*cout<<s<<endl;
    for(int i=0;i<hn;i++)cout<<hand[i]<<' ';
    cout<<endl;
    for(int i=0;i<fn;i++)cout<<feet[i]<<' ';
    cout<<endl;
*/
    int ans = 0;
    int sum = 0;

    if(k>=fn)cout<<len;
    else
    {

        for(int i=0;i<=fn-k;i++)
        {
            if(i==0)
            {
                for(int j=0;j<k;j++)
                {
                    sum += hand[j]+feet[j];

                }
                sum += hand[k];
                ans = sum;
                //cout<<"ans="<<ans<<endl;
            }
            else
            {
                sum = sum + feet[i+k-1] + hand[i+k] - feet[i-1] - hand[i-1];
                if(sum>ans) ans = sum;
                //cout<<"ans="<<ans<<endl;
            }

        }
        cout<<ans<<endl;
    }


    //system("pause");


}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;

// 辺に重みをつける場合 
struct Edge{
    int to;
    int cost;
    Edge(int t,int c) : to(t), cost(c) { }
};

using Graph = vector<vector<Edge>>;


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

    int N, M, L, Q, a, b, c;
    cin >> N >> M >> L;
    Graph G(N);
    rep(i,M){
        cin >> a >> b >> c;
        if(c > L) continue;
        --a; --b;
        G[a].push_back(Edge(b, c));
        G[b].push_back(Edge(a, c));
    }
    
    int dist[N][N];
    rep(i,N){
        rep(j,N){
            dist[i][j] = INF;
        }
    }
    rep(i,N){
        priority_queue<P, vector<P>, greater<P>> que;
        dist[i][i] = 0;
        que.push(P(0, i));
        while(!que.empty()){
            P p = que.top();
            que.pop();
            int x = p.first / MOD;
            int y = p.first %= MOD;
            int u = p.second;

            if(p.first > dist[i][u]) continue;

            for(auto e : G[u]){
                int nx, ny;
                if(y + e.cost > L){
                    nx = x+1;
                    ny = e.cost;
                }
                else{
                    nx = x;
                    ny = y + e.cost;
                }
                int nc = nx * MOD + ny;
                if(nc < dist[i][e.to]){
                    dist[i][e.to] = nc;
                    que.push(P(nc, e.to));
                }
            }
        }
    }
    cin >> Q;
    rep(i,Q){
        cin >> a >> b;
        --a; --b;
        if(dist[a][b] == INF) cout << -1 << endl;
        else cout << dist[a][b] / MOD << endl;
    }
}

Measured memory_bytes: 4488
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[3005][3005];
signed main() {
    string s,t;cin>>s>>t;
    for(int i = 1; i < s.size()+1; i++)
    {
        for(int j = 1; j < t.size()+1; j++)
        {
            if (s[i-1] == t[j-1])
            {
                dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1);
            }
            else
            {
                dp[i][j] = max(dp[i][j-1],dp[i-1][j]);                
            }
            
        }
        
    }
    int i = s.size();
    int j = t.size();
    string ans = "";
    while(i+j)
    {
        if (i&&dp[i][j] == dp[i-1][j]) i--;
        else if(j&&dp[i][j] == dp[i][j-1])j--;
        else
        {
            ans += s[i-1];
            i--,j--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 70656
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;



int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a+b+c>=22){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }
}

Measured memory_bytes: 256
#if 0
time: 20min
using pair to store the edges' number, making it easier to find their nodes.					
#endif
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;

int m,n,x,ans;
int P[100+10],edge1[10000+10],edge2[10000+10];


int root(int a){
	if (P[a] == a) return a;
	return (P[a] = root(P[a]));
}

bool same(int a, int b){
	return root(a)==root(b);
}
	
void unite(int a, int b){
	P[root(a)] = root(b);
}

int main() {
	pair<int,int> edges[10000+10];
	cin >> n;
	
	for (int i=1; i<=n; i++){
		P[i] = i;
	}
	
	m = 0;
	for (int i=1; i<=n; i++){
		for (int j=1; j<=n; j++){
			cin >> x;
			if (x>-1){
				edge1[m] = i;
				edge2[m] = j;
				edges[m] = make_pair(x, m);
				m+=1;
			}
		}
	}
	
	sort(edges, edges+m);
	n=1;
	for (int i=0; i<m; i++){
		if (n>=m) break;
		if (!same(edge1[edges[i].second], edge2[edges[i].second])){
			unite(edge1[edges[i].second], edge2[edges[i].second]);
			ans += edges[i].first;
			n+=1;
		}
	}
	
	cout << ans << endl;
	
}

Measured memory_bytes: 3208