akhauriyash/Code-Regression huggingface dataset:
// 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(int 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(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}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};
struct UnionFind{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return 0;
		if(x>y)swap(x,y);
//        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
        return 1;
    }
    bool findSet(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
signed main(){
	int n;
	cin>>n;
	vi par(n);
	rep(i,n-1){
		int a;
		cin>>a;
		par[i+1]=a-1;
	}
	vvi v(n,vi(2));
	rep(i,n){
		int a;
		cin>>a;
		v[i][a]++;
	}

	auto c=[](vi a,vi b){return a[0]*(b[0]+b[1])<b[0]*(a[0]+a[1]);};
	priority_queue<vi,vvi,decltype(c)>que(c);
	UnionFind uf(n);
	rep(i,n-1)que.push({v[i+1][0],v[i+1][1],i+1});
	int out=0;
	while(!que.empty()){
		vi t=que.top();
		que.pop();
		int npa=uf.root(t[2]);
		if(t[0]!=v[npa][0]||t[1]!=v[npa][1])continue;
		int pa=uf.root(par[t[2]]);
		out+=v[pa][1]*t[0];
		uf.unionSet(pa,t[2]);
		int ro=uf.root(pa);
		v[ro][0]=v[pa][0]+t[0];
		v[ro][1]=v[pa][1]+t[1];
		if(ro)que.push({v[ro][0],v[ro][1],ro});
	}
	cout<<out<<endl;
}
















Measured memory_bytes: 26668
#include<bits/stdc++.h>
 
using namespace std;
 
#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  f                     first                 
#define  s                     second                
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;
 
const ll   N     =  1e5+8;
const ll   mod   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
 
ll t=1,n,k,a[108],dp[N];
 
void solve(){
    cin>>n>>k;
    for(int i = 0; i < n; i++) cin>>a[i];
    fill_n(dp,k+2,k+2);
    dp[0] = 1;
    for(int i = 1; i <= k; i++){
        for(int j = 0; j < n; j++){
            if(a[j] > i) continue;
            dp[i] = min(dp[i],dp[i-a[j]]^1);
        }
        if(dp[i] == k+2) dp[i] = 1;
    }
    if(dp[k]%2 == 0)
        cout<<"First"<<endl;
    else
        cout<<"Second"<<endl;
}
 
int main(){
    fastio;
    //cin>>t;
    while(t--){
        solve();
    }
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) { cin >> v[i]; }

  vector<int> pos(n + 1);  // それぞれの数字がどこにあるか？
  for (int i = 0; i < n; i++) pos[v[i]] = i;

  ll ans = 0;
  multiset<int> st = {-1, -1, n, n};  // 自分より大きいやつの位置
  for (ll i = n; i > 0; i--) {
    st.insert(pos[i]);

    // for (auto x : st)
    //   cout << x << " ";
    // cout << endl;

    auto now = st.lower_bound(pos[i]);
    // 左側を含むやつ
    // cout << "prev " << *now << " " << *prev(now, 1) << " " << *prev(now, 2) << endl;
    ans += i * (*prev(now, 1) - *prev(now, 2)) * (*next(now, 1) - *now);
    // 右側を含むやつ
    ans += i * (*now - *prev(now, 1)) * (*next(now, 2) - *next(now, 1));
    // cout << i << " " << ans << endl;
  }
  cout << ans << endl;
}


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

int main(){
    using namespace std;
    unsigned long H, N;
    cin >> H >> N;
    vector<unsigned long> dp(H + 10000, numeric_limits<unsigned long>::max() / 5);
    dp[0] = 0;
    for(unsigned long i{0}, A, B; i < N; ++i){
        cin >> A >> B;
        for(unsigned long j{0}; j + A < H + 10000; ++j)dp[j + A] = min(dp[j + A], dp[j] + B);
    }
    cout << *min_element(dp.begin() + H, dp.end()) << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){if((ll)(a)==inf)cout<<"inf"<<'\n';else if((ll)(a)==-inf)cout<<"-inf"<<'\n';else cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';if((ll)(v[i])==inf)cout<<"inf";else if((ll)(v[i])==-inf)cout<<"-inf";else cout<<(ll)(v[i]);}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
int main(){
    string s;cin>>s;
    NoYes(s=="AAA"||s=="BBB");
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a[3];
  for(int  i=0;i<3;i++){
    cin >> a[i];
  }
  if(a[0]+a[1]>=a[2])cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n ,t, a;
  cin >> n >> t >> a;
  t = 1000*t;
  a = 1000*a;
  int ans = 1;
  int min = 1000000000;
  for(int i=1;i<=n; i++){
    int h;
    int pret;

    cin >> h;
    pret = t - 6*h;

    if( pret >= a &&  (pret - a) <= min ){
      min = pret - a;
      ans = i;
    }
    if( pret < a &&  (a - pret ) < min ){
      min =  a - pret;
      ans = i;
    }
  }
  cout << ans << endl;     
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <stack>
#include <array>
#include <fstream>
#include <deque>
#include <bitset>
#include <complex>
using namespace std;
#define REP(i,n) for(int (i) = 0;(i) < (n) ; ++(i))
#define REPS(a,i,n) for(int (i) = (a) ; (i) < (n) ; ++(i))
#define REVERSE(i,n) for(int (i) = n-1;(i) >= 0 ; --i)
#define ALL(c) (c).begin() , (c).end()
#define EACH(it,c) for(auto(it,(c).begin());it != (c).end();)
#define cx real()
#define cy imag()
#define px first
#define py second
#define LL long long
#define int LL
#define inf  (1LL << 60)
#define mod 1000000007
#define QUICK_CIN ios::sync_with_stdio(false); cin.tie(0);
#define lower lower_bound
#define upper upper_bound
#define ZERO(c,n) memset(&c[0],0,sizeof(int)*n)
#define ZERO2(c,n) memset(&c[0][0],0,sizeof(int)*n
#define pl(a) cout << ""#a": " << a << endl;
#ifdef _DEBUG
#define debug_io fstream cin("input.txt");ofstream cout("output.txt");
#else
#define debug_io ;
#endif
#define debug_input debug_io
#define pb(a) push_back(a)
template<class T>void scan(vector<T>& a, int n, istream& cin)
{
	T c; REP(i, n) { cin >> c; a.push_back(c); }
}
using vs = vector<string>; using vi = vector<int>; using pii = pair<int, int>;
using psi = pair<string, int>; using vvi = vector<vi>; using pss = pair<string, string>;
template<class T>bool valid(T x, T w) { return 0 <= x&&x < w; }
int dx[4] = { 1, -1, 0, 0 }; int dy[4] = { 0, 0, 1, -1 };
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------


signed main()
{
	QUICK_CIN;
	debug_input;
	int a, b, c;
	cin >> a >> b >> c;

	bool f = false;
	for (int i = a; i <= a * b; i += a) {
		f |= ((i%b) == c);
	}
	if (f) {
		puts("YES");
	}
	else {
		puts("NO");
	}

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string n;
  char t;
  int j=0;
  cin >> n;
  for(int i=0;i < 3;i++)
  {
    t=n.at(i);
    if(t=='7')
    {
      cout << "Yes";
      j=1;
      break;
    }
  }
  if(j==0)
  {
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 3592
function Main(input) {
  input = input.trim().split("\n");
  const NM = input[0].split(" ");
  const N = parseInt(NM[0], 10);
  const M = parseInt(NM[1], 10);
  const Hs = input[1].split(" ").map(n=>parseInt(n, 10));
  var A = [];
  var B = [];
for(var i=0;i<M;i++){
    var AB = input[i+2].split(" ");
    A[i] = parseInt(AB[0],10)
    B[i] = parseInt(AB[1],10)
}
t = new Array(N).fill(1);
for (var i=0;i<M;i++){
    if(Hs[A[i]-1]>Hs[B[i]-1]){//BよりAのほうが高い
        t[B[i]-1] = 0
    }else if(Hs[A[i]-1]<Hs[B[i]-1]){
        t[A[i]-1] = 0
    }else{
        t[A[i]-1] = 0
        t[B[i]-1] = 0
    }
}
var ans = t.reduce((a,b)=>a+b,0)
  console.log(ans)

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 58460
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n, m;

signed main(){
  
  cin>>n>>m;
  
  priority_queue<int> Q;
  
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    Q.push(a);
  }
  
  while(m){
    
    int num = Q.top(); Q.pop();

    num /= 2;
    m--;

    Q.push(num);
    
  }
  
  int ans = 0;

  while(!Q.empty()) ans += Q.top(), Q.pop(); 
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include<string>
#include<algorithm>
#include<cctype>
#include <vector>
using namespace std;


int main(){
    long long X,K,D;
    cin>>X>>K>>D;
    long long n=abs(X)/abs(D);
    long long ans;
    if(K-n<=0){
        ans=abs(X)-K*abs(D);
      cout<<ans<<endl;
    }else{
        ans=abs(X)-n*abs(D);
        if((K-n)%2==0)cout<<ans<<endl;
        else cout<<abs(ans-D)<<endl;
    }
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
#include <iomanip>
#include <queue>
#include <cmath>
#include <math.h>
#include <string>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;
typedef long long ll;
#define min(a, b) ((a) < (b) ? (a) : (b))
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数
long long gcd(long long a, long long b)
{
	if (a % b == 0) {
		return(b);
	}
	else {
		return(gcd(b, a % b));
	}
}

double calc(int x) {
	double y = 0;
	for (int i = 1; i < x + 1; i++) {
		y += i;
	}
	return y /= x;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	// cout << std::fixed << std::setprecision(15);

	long long N, K;
	cin >> N >> K;
	vector<int> P(N);
	vector<double> sum(N);

	for (long long i = 0; i < N; i++) {
		cin >> P.at(i);
		if (i == 0) {
			sum.at(0) = calc(P.at(i));
		}
		else {
			sum.at(i) = sum.at(i - 1) + calc(P.at(i));
		}
	}
	double tmp = sum.at(K - 1);
	for (long long i = K; i < N; ++i) {
		if (tmp < sum.at(i) - sum.at(i - K)) {
			tmp = sum.at(i) - sum.at(i - K);
		}
	}


	cout << std::fixed << std::setprecision(12) << tmp << endl;;
	return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
        int H,W;
 
        H = sc.nextInt();
        W = sc.nextInt();
 
        int table[][] = new int[H+1][W+1];
 
        for(int row = 0; row < H; row++){
            for(int col = 0; col < W; col++){
                table[row][col] = sc.nextInt();
            }
        }
 
        for(int row = 0; row < H; row++){
            table[row][W] = 0;
            for(int col = 0; col < W; col++){
                table[row][W] += table[row][col];
            }
        }
 
        for(int col = 0; col <= W; col++){
            table[H][col] = 0;
            for(int row = 0; row < H; row++){
                table[H][col] += table[row][col];
            }
        }
 
        for(int row = 0; row <= H; row++){
            System.out.printf("%d", table[row][0]);
            for(int col = 1; col <= W; col++){
                System.out.printf(" %d", table[row][col]);
            }
            System.out.printf("\n");
        }
    }
}


Measured memory_bytes: 52272
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
using ll = long long;
using d = double;

int main(){
  int n;
  string s;
  cin >> n >> s;
  vector<int> m(n);
  rep(i,n){
    if(s[i]=='R')m[i]=0;
    if(s[i]=='B')m[i]=1;
    if(s[i]=='G')m[i]=2;
  }
  vector<ll> c(3);
  rep(i,n)c[m[i]]++;
  ll t=c[0]*c[1]*c[2];
  rep(j,n){
    rep(i,j){
      int k=j+(j-i);
      if(k<n){
      	if(m[i]==m[j])continue;
        if(m[j]==m[k])continue;
        if(m[k]==m[i])continue;
      	--t;
      }
    }
  }
  cout << t << endl;
  return 0;
}

Measured memory_bytes: 3644
package main

import "fmt"

func main() {

	var tenki string
	fmt.Scan(&tenki)

	if tenki == "Sunny" {
		fmt.Println("Cloudy")
	}
	if tenki == "Cloudy" {
		fmt.Println("Rainy")
	}
	if tenki == "Rainy" {
		fmt.Println("Sunny")
	}

}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int n;
double mx;
int x[105], y[105];
double a[105];
const double PI = acos(-1);

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d%d", &x[i], &y[i]);
    }
    for(int i = 0; i < n; i++)
    {
        mx = 0;
//        a[i] = 0;
        int k = 0;
        for(int j = 0; j < n; j++)
        {
            if(i == j) continue;
            a[k++] = atan2(y[j] - y[i], x[j] - x[i]);
        }
        sort(a, a + k);
        for(int j = 1; j < k; j++)
        {
            mx = max(mx, a[j] - a[j - 1]);
        }
        mx = max(mx, a[0] - a[k - 1] + 2 * PI);
        printf("%.10f\n", max(mx - PI, 0.0) / PI / 2);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<ll> a, vector<ll> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll N,M,K;
    cin >> N >> M >> K;
    VLL A(N), B(M);
    rep(i,N){
        cin >> A[i];
    }
    rep(i,M){
        cin >> B[i];
    }
    VLL s(N+1);
    VLL t(M+1);
    cum_sum(N, A, s);
    cum_sum(M, B, t);
    ll ans=0;
    rep(i,N+1){
        ll tmp_ans=0;
        ll tmp_K=K;
        ll sum=s[i];
        ll dif=tmp_K-sum;
        if(dif<0) continue;
        if(dif==0){
            tmp_ans=i;
            ans=max(ans, tmp_ans);
            continue;
        }
        tmp_ans=i;
        auto it=upper_bound(t.begin(), t.end(), dif);
        tmp_ans+=it-t.begin()-1;
        ans=max(ans, tmp_ans);
    }
    cout << ans << endl;
}

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

#define inf 0x3f3f3f3f

using namespace std;

typedef long long ll;

const ll mod = 998244353;

int i, j;
string s;
int a, b;
void solve() {
	cin >> a >> b;
	int sum = a + b;
	if (sum % 2 == 1) {
		cout << "IMPOSSIBLE" << endl;
	} else {
		cout << (sum / 2) << endl;
	}
}

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

Measured memory_bytes: 256
s = input()
n = len(s)
list0 = list()
list2 = list()
ans = 0
for i in range(n-1):
    if s[i:i+2] == '><':
        list0.append(i+1)
    elif s[i:i+2] == '<>':
        list2.append(i+1)

if s[0] == '<':
    list0.insert(0, 0)
else:
    if len(list0):
        p1 = list0[0]
    else:
        p1 = n
    ans += 1/2 * p1 * (p1 + 1)



if s[-1] == '>':
    list0.append(n)
else:
    if len(list0):
        p1 = n - list0[-1]
    else:
        p1 = n
    ans += 1/2 * p1 * (p1 + 1)

for i in range(len(list2)):
    p1 = max(list2[i] - list0[i], list0[i+1] - list2[i])
    p2 = min(list2[i] - list0[i], list0[i+1] - list2[i])
    ans += 1/2 * p1 * (p1 + 1) + 1/2 * p2 * (p2 - 1)

print(int(ans))


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

int main(void) {
  vector<int> num(3);
  rep(i, num.size()) {
    cin >> num[i];
  }

  sort(num.rbegin(), num.rend());

  int ans = num[0] * 10 + num[1] + num[2];

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

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int a=0,b=0;
int money;
cin >> money;
while(money>0){
    if(money>=500){
        money-=500;
        a++;
    }
    else{
        b=money/5;
        money=0;
    }
}
cout << a*1000+b*5 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono; 
#define ll long long
#define fo(i,v,e) for(v=i;v<e;v++)
#define pb(x) push_back(x)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fi first 
#define se second
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define sz(x) (int)x.size()
#define ull unsigned long long
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pii>
#define vpl vector<pll>
ll mod = 1000000007;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x);
#else
#define deb(x...)
#endif
vector<ll> sieveOfErthnosis(ll n)
{
    vector<bool>flag(n+5,false);
    vector<ll>primes;
    for(int i=2;i*i<=n;i++)
    {
        if(!flag[i])
        {
            for(int j=i*i;j<=n;j+=i)
            {flag[j]=true;}
        }
    }
    for (int  i = 2; i < n+1; i++)
    {
        if(!flag[i])primes.pb(i);
    }
    return primes;
}
void init()
{
    
}
void solve()
{
    ll s,w;cin>>s>>w;
    cout<<(s>w?"safe":"unsafe");
}
int main()
{
    init();
    #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    #endif
    auto start = high_resolution_clock::now(); 
    int T = 1;
    // cin>>T;
    while(T--)
    {
        solve();
    }
    auto stop = high_resolution_clock::now(); 
    auto duration = duration_cast<milliseconds>(stop - start); 
    #ifndef ONLINE_JUDGE
    // cout << "time taken : "<<duration.count()<<" ms" << endl;
     #endif
}


Measured memory_bytes: 3628
def main():
    n, m = map(int, input().split())
    a = sorted(list(map(int, input().split())))
    change = []
    change_n = 0
    for _ in range(m):
        b, c = map(int, input().split())
        change.append((b, c))
        change_n += b
    change.sort(key=lambda x: x[1], reverse=True)
    answer = 0
    added = 0
    index = 0
    for i in range(n):
        if i < change_n:
            if added + change[index][0] == i:
                added = i
                index += 1
            answer += max(a[i], change[index][1])
        else:
            answer += a[i]
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 22504
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
N = int(input())
pf = prime_factorize(N)
m = 1
ext = {}
c = 0
l = 1
if len(pf) > 0:
  l = pf[0]
while True:
  if len(pf) == 0:
    break
  i = pf.pop()
  if l != i:
    l = i
    m = 1
  m = m * i
  if not m in ext:
    ext[m] = m
    m = 1
    c += 1
print(c)
  

Measured memory_bytes: 62956
A, B = map(int, input().split())
S = list(input())
a = ''.join(S[0:A])
b = ''.join(S[A+1:A+2+B])
c = S[A]
if str.isdecimal(a) and str.isdecimal(b) and c == '-':
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
import sys
from bisect import bisect_right

N,T = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]
#%%
b0 = []
ab1 = []
for a,b in ab:
    if a==0:
        b0.append(b+1)
    else:
        ab1.append([(b+1)/a, a, b])

N0 = len(b0)
N1 = len(ab1)

b0.sort()
if N0>0:
    b_ruiseki = [0]*N0
    b_ruiseki[0] = b0[0]
    for i in range(1,N0):
        b_ruiseki[i] = b_ruiseki[i-1] + b0[i]
else:
    b_ruiseki = []

ab1.sort()

INF = T + 100

dp = [[INF]*31 for _ in range(N1+1)]
dp[0][0] = 0
ans = 0
for i in range(N1):
    # dp[i+1][j] : 0~i番目までの店を見て，j個選ぶときの最小時間
    
    for j in range(31):
        if j>i+1:break
        if j==0:
            dp[i+1][j] = 0
        else:
            dp[i+1][j] = min(dp[i][j], (dp[i][j-1]+1)*(ab1[i][1]+1)+ab1[i][2])

for j in range(31):
    if dp[N1][j]>T:break    
    # a>0をj店舗めぐった後にa=0を何店舗めぐれるか
    num0 = bisect_right(b_ruiseki, T - dp[N1][j])
    ans = max(ans, j + num0)
        
    
print(ans)


Measured memory_bytes: 149540
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

ll inq(ll x, ll y, ll mod)
{
    if (!y) re 1 % mod;
    ll l = inq(x, y / 2, mod);
    if (y % 2) re l * l % mod * x % mod;
    re l * l % mod;
}

ll inv(ll x, ll mod)
{
    return inq(x, mod - 2, mod);
}

const int N = 405949; // 405949 is my favorite number, but it's less than 5e5
const int P = 1e9 + 97;
const int Q = 1e6 + 3;
const int INV = inv(Q, P);

int n;
int a[N];

signed main()
{
    #ifdef ONLINE_JUDGE
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // ONLINE_JUDGE
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i]--;
    }
    for (int i = 0; i < n; i++)
    {
        if (a[i] != i)
        {
            int mx_meet = a[i];
            vector<pair<int, int> > v;
            int j = i;
            if (j + 2 == n && a[j + 1] != j + 1)
            {
                cout << "No";
                return 0;
            }
            while (1)
            {
                mx_meet = max(mx_meet, a[j]);
                v.push_back({a[j], j});
                if (j + 2 < n)
                {
                    if (mx_meet > j || a[j + 2] != j + 2)
                    {
                        if (a[j + 1] == j + 1)
                        {
                            j += 2;
                        }
                        else
                        {
                            cout << "No";
                            return 0;
                        }
                        continue;
                    }
                    break;
                }
                else
                {
                    if (j + 1 < n && a[j + 1] != j + 1)
                    {
                        cout << "No";
                        return 0;
                    }
                    break;
                }
            }
            vector<int> x, y;
            for (int k = 0; k < v.size(); k++)
            {
                if (v[k].first < v[k].second) x.push_back(v[k].first);
                else y.push_back(v[k].first);
                if (v[k].first < i || v[k].first > j) break;
            }
            for (int j = 0; j + 1 < x.size(); j++) if (x[j + 1] < x[j]) cout << "No", exit(0);
            for (int j = 0; j + 1 < y.size(); j++) if (y[j + 1] < y[j]) cout << "No", exit(0);
            i = j;
        }
    }
    cout << "Yes";
}


Measured memory_bytes: 4208
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                ans += 1
print(ans)

Measured memory_bytes: 66868
$debug = false
flag = ARGV.shift
if flag == "-d"
  $debug = true
end

def dputs str
  p str if $debug
end

def max(n, m)
  if n > m
    return n
  else
    return m
  end
end

def min(n, m)
  if n < m
    return n
  else
    return m
  end
end

def gets_all_int
  return gets.chomp.split.map{|v| v.to_i}
end

## start

N = gets_all_int[0]

#puts (N-1).downto(1).to_a.inject(0, :+)
puts ((N-1) * N)/2

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    int k, q;
    cin >> k >> q;
    Vl d(k);
    for (int i = 0; i < k; i++) {
        cin >> d[i];
    }

    Vl dm(k);
    for (int i = 0; i < q; i++) {
        ll n, x, m;
        cin >> n >> x >> m;
        ll out = 0;
        ll a_last = x % m;
        for (int j = 0; j < k; j++) {
            dm[j] = d[j] % m;
        }
        for (int j = 0; j < k; j++) {
            ll tmp;
            if (j <= (n - 1) % k - 1)
                tmp = (n - 1) / k + 1;
            else
                tmp = (n - 1) / k;
            a_last += dm[j] * tmp;
            if (dm[j] == 0) out += tmp;
        }
        out += a_last / m;
        cout << n - 1 - out << "\n";
    }

    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>

using namespace std;
typedef long long ll;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)

const int MAX_N = (int) 1e5;
ll N, A[MAX_N], diffs[MAX_N + 1], sum = 0;

void solve() {
    REP(i, N) {
        ll temp = i == 0 ? 0 : A[i - 1];
        ll temp2 = i == N - 1 ? 0 : A[i + 1];
        cout << sum - diffs[i] - diffs[i + 1] + abs(temp2 - temp) << endl;
    }
}

int main() {
    cin >> N;
    REP(i, N) {
        cin >> A[i];
        if (i == 0) {
            diffs[0] = abs(A[0]);
        } else {
            diffs[i] = abs(A[i] - A[i - 1]);
        }
        if (i == N - 1) {
            diffs[N] = abs(A[i]);
            sum += diffs[N];
        }
        sum += diffs[i];
    }
    solve();
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  int counter = 0;
  if (s[0] == '1') ++counter;
  if (s[1] == '1') ++counter;
  if (s[2] == '1') ++counter;
  cout << counter << endl;
}

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

int main() {
	int N;
	int min = 200001, ans = 0;
	int P[200000] = { 0 };
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> P[i];
	}
	for (int i = 0; i < N; i++) {
		if (min > P[i]) {
			min = P[i];
			ans++;
		}
	}
	cout << ans;
	
}

Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Array.Sort(A);
		
		//long l = -1 * (long)1e18 - 20;
		long r = (long) 1e18 + 20;
		long l = -r;
		while(r - l > 1){
			var c = (r + l) / 2;
			long cnt = calc(c);
			//Console.WriteLine("{0} {1}",c, cnt);
			if(cnt < K){
				l = c;
			} else {
				r = c;
			}
		}
		Console.WriteLine(r);
		
	}
	
	long calc(long v){
		// v以下の個数
		long cnt = 0;
		
		for(int i=0;i<N-1;i++){
			var n = A[i];
			if(n == 0){
				if(v >= 0) cnt += N - i - 1;
				continue;
			}
			if(n > 0){
				int l = i + 1;
				int r = N;
				if(n * A[l] > v) continue;
				while(r - l > 1){
					int c = (l + r) / 2;
					if(A[c] * n <= v){
						l = c;
					} else{
						r = c;
					}
				}
				cnt += l - i;
				continue;
			}
			if(n < 0){
				int l = i + 1;
				int r = N;
				if(n * A[l] <= v){
					cnt += N - (i + 1);
					continue;
				}
				while(r - l > 1){
					int c = (l + r) / 2;
					if(A[c] * n > v){
						l = c;
					} else{
						r = c;
					}
				}
				//Console.WriteLine("{0} {1} {2} {3}",v,n,l,r);
				cnt += N - r;
				continue;
			}
		}
		return cnt;
	}
	
	int N;
	long[] A;
	long K;
	public Sol(){
		var d = rla();
		N = (int) d[0]; K = d[1];
		A = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 32604
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int MOD=1e9+7;
   
int32_t main()
{
   IOS
   const int MXV=1e5;
   int N,W;cin>>N>>W;
   vector<int>w(N+1);
   vector<int>v(N+1);
   vector<int>dp(MXV+1,1e15);
   dp[0]=0;
   for(int i=1;i<=N;i++)
   cin>>w[i]>>v[i];
   for(int i=1;i<=N;i++)
   {
	   auto dp2=dp;
	   for(int j=0;j<=MXV;j++)
	   if( j + v[i] <= MXV )
	   {
		   dp2[j+v[i]]=min(dp2[j+v[i]],dp[j]+w[i]);
	   }
	   dp=dp2;
   }
   int mxval=0;
   for(int i=0;i<=MXV;i++){
	   if( dp[i] <= W )mxval=i;
   }
   cout<< mxval << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	int arr[n];
	float sum(0);
	for(int i=0;i<n;i++){
			cin>>arr[i];
			sum += arr[i];
		}
	int f = floor(sum / n);
	int c = ceil(sum / n);
	
	int ans1(0),ans2(0);
	for(int i=0;i<n;i++){
	 ans1 += pow(arr[i] - f,2);
	 ans2 += pow(arr[i]-c,2);
	}	
	
	int ans = min(ans1,ans2);
	cout<<ans;
	return 0;
	} 


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

int main() {
  int n, m, o, d, t, l1, l2;
  string str;
  bool a[30][10], x;

  while (cin >> n && n) {
    cin >> m >> o >> d;
    --m; --o;
    for (int i=0; i<d; i++) {
      cin >> str;
      for (int  j=0; j<n-1; j++) {
        a[i][j] = str.at(j)-'0';
      }
    }

    l1 = m;
    l2 = o;
    for (int i=d-1; i>=0; i--) {
      if (l2<n-1 && a[i][l2]) ++l2;
      else if (l2 && a[i][l2-1]) --l2;
    }
    if (l1 == l2) {
      cout << "0" << endl;
      continue;
    }

    x = false;
    for (int i=0; i<d; i++) {
      t = 0;
      if (l1<n-1 && a[i][l1]) ++l1;
      else if (l1 && a[i][l1-1]) --l1;
      else ++t;
      if (l2<n-1 && a[i][l2]) ++l2;
      else if (l2 && a[i][l2-1]) --l2;
      else ++t;
      if (t==2 && (l1==l2+1 || l2==l1+1)) {
        cout << i+1 << " " << ((l1<l2) ? l2 : l1) << endl;
        x = true;
        break;
      }
    }
    if (!x) {
      cout << "1" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1204
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
const int maxn=200000+10,mo=1000000007;
struct dong{
	int x,v,id;
} a[maxn];
struct suan{
	int l,r;
	friend bool operator <(suan a,suan b){
		return a.r<b.r||a.r==b.r&&a.l<b.l;
	}
} b[maxn];
int tree[maxn*4],left[maxn],right[maxn],f[maxn];
int i,j,k,l,t,n,m,mi,mx,ans;
int read(){
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0'||ch>'9'){
		if (ch=='-') f=-1;
		ch=getchar();
	}
	while (ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
bool cmp(dong a,dong b){
	return a.v<b.v;
}
bool cmp2(dong a,dong b){
	return a.x<b.x;
}
void change(int p,int l,int r,int a,int b){
	if (l==r){
		(tree[p]+=b);
		if (tree[p]>=mo) tree[p]-=mo;
		return;
	}
	int mid=(l+r)/2;
	if (a<=mid) change(p*2,l,mid,a,b);else change(p*2+1,mid+1,r,a,b);
	tree[p]=(tree[p*2]+tree[p*2+1]);
	if (tree[p]>=mo) tree[p]-=mo;
}
int query(int p,int l,int r,int a,int b){
	if (l==a&&r==b) return tree[p];
	int mid=(l+r)/2;
	if (b<=mid) return query(p*2,l,mid,a,b);
	else if (a>mid) return query(p*2+1,mid+1,r,a,b);
	else{
		int t=(query(p*2,l,mid,a,mid)+query(p*2+1,mid+1,r,mid+1,b));
		if (t>=mo) t-=mo;
		return t;
	}
}
int main(){
	//freopen("data.in","r",stdin);
	//scanf("%d",&n);
	n=read();
	fo(i,1,n)
		//scanf("%d%d",&a[i].x,&a[i].v);
		a[i].x=read(),a[i].v=read();
	sort(a+1,a+n+1,cmp);
	fo(i,1,n) a[i].id=i;
	sort(a+1,a+n+1,cmp2);
	mi=n+1;
	fd(i,n,1){
		mi=min(mi,a[i].id);
		left[a[i].id]=mi;
	}
	mx=0;
	fo(i,1,n){
		mx=max(mx,a[i].id);
		right[a[i].id]=mx;
	}
	fo(i,1,n) b[i].l=left[i],b[i].r=right[i];
	sort(b+1,b+n+1);
	fo(i,1,n){
		if (b[i].l==1) f[i]++;
		t=max(b[i].l-1,1);
		(f[i]+=query(1,1,n,t,b[i].r));
		if (f[i]>=mo) f[i]-=mo;
		change(1,1,n,b[i].r,f[i]);
		if (b[i].r==n){
			(ans+=f[i]);
			if (ans>=mo) ans-=mo;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 9472
#include <vector>
#include <set>
#include <algorithm>
#include <cstdio>
#define SENTINEL 99999999
using namespace std;
typedef pair<int,int> pii;
class union_find{
	vector<pii>parent;
	pii root(int a){
		if(parent[a].first==a)return parent[a];
		pii ret=root(parent[a].first);
		return parent[a]=make_pair(ret.first,ret.second+parent[a].second);
	}
public:
	union_find(int n): parent(n){for(int i=0;i<n;i++)parent[i]=make_pair(i,0);}
	int dist(int a,int b){
		pii x=root(a),y=root(b);
		if(x.first!=y.first)return SENTINEL;
		return x.second-y.second;
	}
	int unite(int a,int b,int w){
		pii x=root(a),y=root(b);
		if(x.first==y.first)return 0;
		parent[x.first]=make_pair(y.first,y.second-x.second+w);
		return 1;
	}
};
int main(){
	char s[2];
	int N,Q,a,b,w;
	for(;scanf("%d%d",&N,&Q),N;)for(union_find uf(N);Q--;){
		scanf("%s",s);if(*s=='!'){
			scanf("%d%d%d",&a,&b,&w),a--,b--;
			uf.unite(a,b,w);
		}else{
			scanf("%d%d",&a,&b),a--,b--;
			w=uf.dist(a,b);
			printf(w==SENTINEL?"UNKNOWN\n":"%d\n",w);
		}
	}
}

Measured memory_bytes: 2740
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N, K;
  cin >> N >> K;
  vector<int> data(N);
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());
  int ans = data.at(K - 1) -data.at(0);
  for (int i = 0; i < N - K + 1; i++) {
    if (data.at(i + K - 1) -data.at(i) < ans) ans = data.at(i + K - 1) -data.at(i);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N; cin >> N;
  for(ll h = 1; h <= 3500; h++){
    for(ll n = 1; n <= 3500; n++){
      if((4*h*n-N*n-N*h) > 0 && (N*h*n)%(4*h*n-N*n-N*h) == 0 && (N*h*n)/(4*h*n-N*n-N*h) <= 3500){
        cout << h << " " << n << " " << (N*h*n)/(4*h*n-N*n-N*h) << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
int n,t,a[111111],mx,cur,kk[111111],cnt,ans;
map<int,int> mp;
int main()
{
	scanf("%d%d",&n,&t);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	mx=-1e9;
	for (int i=n;i>=1;i--)
	{
		cur=max(cur,mx-a[i]);
		mx=max(mx,a[i]);
		mp[a[i]]=i;
	}
	for (int i=1;i<=n;i++) kk[i]=a[i];
	for (int i=1;i<=n;i++)
	{
		if (mp.find(kk[i]+cur)!=mp.end() && mp[kk[i]+cur]>i) 
		{
			cnt++;
			kk[mp[kk[i]+cur]]--;
			if (mp.find(kk[i]+cur-1)==mp.end()) mp[kk[i]+cur-1]=mp[kk[i]+cur];
			mp[kk[i]+cur]=-1;
		}
		if (mp.find(kk[i]+cur+1)!=mp.end() && mp[kk[i]+cur+1]>i) 
		{
			cnt+=2;
			kk[mp[kk[i]+cur+1]]-=2;
			if (mp.find(kk[i]+cur-1)==mp.end()) mp[kk[i]+cur-1]=mp[kk[i]+cur+1];
			mp[kk[i]+cur+1]=-1;
		}
	}
	ans=cnt;
	for (int i=1;i<=n;i++) kk[i]=a[i];
	for (int i=1;i<=n;i++) mp[a[i]]=i;
	for (int i=n;i>=1;i--)
	{
		if (mp.find(kk[i]-cur)!=mp.end() && mp[kk[i]-cur]<i) 
		{
			cnt++;
			kk[mp[kk[i]-cur]]++;
			if (mp.find(kk[i]-cur+1)==mp.end()) mp[kk[i]-cur+1]=mp[kk[i]-cur];
			mp[kk[i]-cur]=1e9;
		}
		if (mp.find(kk[i]-cur-1)!=mp.end() && mp[kk[i]-cur-1]<i) 
		{
			cnt+=2;
			kk[mp[kk[i]-cur-1]]+=2;
			if (mp.find(kk[i]-cur+1)==mp.end()) mp[kk[i]-cur+1]=mp[kk[i]-cur-1];
			mp[kk[i]-cur-1]=1e9;
		}
	}
	ans=min(ans,cnt);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 10368
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0



n,m=LI()
a=sorted(LI())

if a[-m]<sum(a)/(4*m):
    ans='No'
else:
    ans='Yes'
    
print(ans)


    
    

Measured memory_bytes: 39404
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

int gcd(int a, int b){
    /*
    if(a == b)
        return a;
    else if(a > b)
        gcd(a-b, b);
    else
        gcd(a, b-a);
    */
    if(b > 0)
        gcd(b, a%b);
    else
        return a;
}

int main(){
    int N;
    cin >> N;
    int X;
    cin >> X;
    vector<int> x(N);
    for(int i = 0; i < N; i++){
        cin >> x.at(i);
    }

    int i, j;

    int d[N];
    for(i = 0; i < N; i++){
        if (X > x.at(i)) d[i] = X - x.at(i);
        else d[i] = x.at(i) - X;
    }

    int D = d[0];
    for(i = 0; i < N; i++){
        D = gcd(D, d[i]);
        if(D == 1) break;
    }
    cout << D << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        for(int i = 0; i < n; i++){
            String x = input.next();
            String y = input.next();
            System.out.println(lcs(x,y));
        }
    }

    public static int lcs(String x, String y) {
        int m = x.length();
        int n = y.length();
        int[][] c = new int[m+1][n+1];
        for(int i = 1; i <= m; i++) {
            c[i][0] = 0;
        }
        for(int j = 1; j <= n; j++) {
            c[0][j] = 0;
        }
        for(int i = 1; i <= m; i++) {
            for(int j = 1; j <= n; j++) {
                if(x.charAt(i-1) == y.charAt(j-1)) {
                    c[i][j] = c[i-1][j-1] + 1;
                } else if (c[i-1][j] >= c[i][j-1]) {
                    c[i][j] = c[i-1][j];
                } else {
                    c[i][j] = c[i][j-1];
                };
            }
        }
        return c[m][n];
    }
}



Measured memory_bytes: 65864
#include <bits/stdc++.h> 
using namespace std;
#define int long long int
#define float double
#define pb push_back
#define FF first
#define SS second
#define N 100005
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i++)
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define pii pair<int,int>
#define mp make_pair
#define INF 9223372036854775807
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int n,m;
string s[1001];
int dp[1001][1001];

int recmemo(int i,int j)
{
    if(dp[i][j]!=-1) return dp[i][j];
    if(i==0 && j==0) return 1;
    int a=0;
    if(i>0 && s[i-1][j]=='.') a=recmemo(i-1,j);
    int b=0;
    if(j>0 && s[i][j-1]=='.') b=recmemo(i,j-1);
    dp[i][j]=(a+b)%MOD;
    return dp[i][j];
}


signed main() 
{
    speed;
    //freopen("input.tXt","r",stdin);
    //freopen("output.tXt","w",stdout);

    cin>>n>>m;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++) cin>>s[i];
    cout<<recmemo(n-1,m-1);
}   

Measured memory_bytes: 12544
n = int(input())

taro = 0
hanako = 0
for ni in range(n):
    t, h = input().split()
    
    if t < h:
        hanako += 3
    elif t > h:
        taro += 3
    else:
        hanako += 1
        taro += 1
        
print(taro, hanako)

Measured memory_bytes: 7612
from sys import stdin

def main():

    input = stdin.readline

    X = int(input())

    A = 100

    ans = 0

    while True:
        A = A + int(A * 0.01)
        ans += 1
        if X <= A:
            print(ans)
            return 0

if __name__ == "__main__":
    main()

Measured memory_bytes: 9192