akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,m; cin >> n >> m;
    int ans = 0;
    VI x(m); VIin(x);
    VI y(m,0);
    SORT(x);
    rep(i,m-1) y[i] = x[i+1] - x[i];
    SORT(y);
    REVERSE(y);
    FOR(i,n-1,m-1)ans += y[i];
    ANS;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

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

    int a = 1;
    for (int i = 0; i < N; i++)
    {
        if(a*2<(a+K)){
            a = a*2;
        }else{
            a = a+K;
        }
    }
    cout << a << endl;    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <deque>
#include <tuple>
#include <unordered_set>
#include <array>
#include <string>

using namespace std;
#define ll long long
#define ar array


struct query {
    int l;
    int r;
    int i;
    int ans;
};
 
int main() {
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<query> q(t);
    for (int i = 0; i < t; ++i) {
        cin >> q[i].l >> q[i].r;
        q[i].i = i;
        q[i].l--;
        q[i].r--;
    }
 
    int sqrtn = sqrt(n) + 1;
    sort(q.begin(), q.end(), [&sqrtn](query &a, query &b) {
        if (a.l / sqrtn != b.l / sqrtn) {
            return a.l / sqrtn < b.l / sqrtn;
        }
        return a.r < b.r;
    });
 
    vector<int> m(n+1);
    int l = 0;
    int r = -1;
    int cnt = 0;
 
    for (auto &q : q) {
        if (r < q.l || q.r < l) {
            m.assign(n+1, 0);
            cnt = 0;
            l = q.l;
            r = q.l - 1;
        }
        while (r < q.r) {
            r++;
            if (m[a[r]] == 0) cnt++;
            m[a[r]]++;
        }
        while (r > q.r) {
            m[a[r]]--;
            if (m[a[r]] == 0) cnt--;
            r--;
        }
        while (l < q.l) {
            m[a[l]]--;
            if (m[a[l]] == 0) cnt--;
            l++;
        }
        while (l > q.l) {
            l--;
            if (m[a[l]] == 0) cnt++;
            m[a[l]]++;
        }
        q.ans = cnt;
    }
    sort(q.begin(), q.end(), [](query &a, query &b) {return a.i < b.i;});
 
    for (auto &q : q) {
        cout << q.ans << '\n';
    }
	return 0;
}

Measured memory_bytes: 15452
from operator import itemgetter
n, m = list(map(int, input().split()))
pyl = [tuple(map(int, input().split())) for _ in range(m)]

pyd = {pyl[i]:i for i in range(m)}
pyl.sort(key=itemgetter(1))
pref = {i+1:1 for i in range(n)}

ids = [["", 0] for _ in range(m)]
for i in range(m) :
    py = pyl[i]
    ids[i] = ["{:0=6}".format(py[0])+"{:0=6}".format(pref[py[0]]),
              pyd[py]]
    pref[py[0]] += 1

ids.sort(key=itemgetter(1))
for anid in ids :
    print(anid[0])

Measured memory_bytes: 55020
package main

import (
        "bufio"
        "fmt"
        "os"
        "strconv"
        "strings"
)

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
        line := nextLine()
        spl := intSprit(line)

        fmt.Println(spl[0] - spl[1] + 1)
}



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

int main(){
  int x, a, b;
  cin >> x >> a >> b;
  if (a - b >= 0) cout << "delicious" << endl;
  else if (b - a - x > 0) cout << "dangerous" << endl;
  else cout << "safe" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a.begin(),a.end());
  cout<<a[n/2]-a[n/2-1]<<endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>

using namespace std;

struct DATA{
  int x;
  int y;
};

DATA MakeData(int, int);

int main(){
  int i, n, m, d;
  int top, bottom, left, right, height, width;
  DATA onedata;
  vector<DATA> data;

  while(1){
    cin >> n;
    if(n == 0) break;

    data.push_back(MakeData(0, 0));

    for(i=1; i<n; ++i){
      cin >> m >> d;

      if(d == 0) onedata = MakeData(data[m].x-1, data[m].y);
      else if(d == 1) onedata = MakeData(data[m].x, data[m].y-1);
      else if(d == 2) onedata = MakeData(data[m].x+1, data[m].y);
      else if(d == 3) onedata = MakeData(data[m].x, data[m].y+1);

      data.push_back(onedata);
    }

    left = 0;
    right = 0;
    top = 0;
    bottom = 0;

    for(i=1; i<data.size(); ++i){
      if(left > data[i].x) left = data[i].x;
      if(right < data[i].x) right = data[i].x;
      if(top < data[i].y) top = data[i].y;
      if(bottom > data[i].y) bottom = data[i].y;
    }

    width = 1 + right - left;
    height = 1 + top - bottom;

    cout << width << " " << height << endl;
    data.clear();
  }

  return 0;
}

DATA MakeData(int x, int y){
  DATA data;
  data.x = x;
  data.y = y;
  return data;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<int>moji(3);
  for(int i=0;i<3;i++){
  cin>>moji.at(i);
  }
  sort(moji.begin(),moji.end());
  cout<<moji.at(0)+moji.at(1)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define N_MAX 100
#define K_MAX 100

int blood[K_MAX];
int family[K_MAX];
int n,k;

void solve(){
	int tmp;
	for(int i=0;i<k;i++){
		cin>>blood[i];
		family[i]=0;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<k;j++){
			cin>>tmp;
			family[j]+=tmp;
		}
	}
	for(int i=0;i<k;i++){
		if(family[i]>blood[i]){
			cout<<"No"<<endl;
			return ;
		}
	}
	cout<<"Yes"<<endl;
	return ;
}
int main(){
	while(cin>>n>>k&&(n||k)){
		solve();
	}
	return 0;
}

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

    vector <long long int> a(3*N);

    for(int i=0;i<3*N;i++){
        cin >> a.at(i);
    }

    long long int ans=0;

    sort(a.begin(),a.end());

    for(int i=0;i<N;i++){
        ans += a.at(3*N-2*i-2);
    }

    cout << ans << endl;
}

Measured memory_bytes: 5632
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
const int inf=1e9+7;
const int mod=1e9+7;
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
int main(){
	int N,T;
	int mi=inf;
	cin>>N>>T;
	for(int i=0;i<N;i++){
		int x,t;
		cin>>x>>t;
		if(T>=t){
			mi=min(mi,x);
		}
	}
	if(mi==inf){
		cout<<"TLE"<<endl;
	}else{
		cout<<mi<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc080/tasks/abc080_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a)  (a).begin(),(a).end()
#define elif else if
int low(V<int> a,int b){
  decltype(a)::iterator c=lower_bound(a.begin(),a.end(),b);
  int d=c-a.bgn;
  return d;
}
int upp(V<int> a,int b){
  decltype(a)::iterator c=upper_bound(a.begin(),a.end(),b);
  int d=c-a.bgn;
  return d;
}
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
int wari(int a,int b) {
  if(a%b==0)
    return a/b;
  else
    return a/b+1;
}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int souwa(int a){
  return a*(a+1)/2;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
int INF=1000000007;
int kaijou(int a){
  int b=1;
  fo(i,a)
    b*=i+1;
  return b;
}
int nPr(int a,int b){
  if(a<b)
    return 0;
  if(b==0)
    return 1;
  int c=1;
  for(int i=a;i>a-b;i--){
    c*=i;
    c%=INF;
  }
  return c;
}
int MOD=INF;



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

V<P<int,int>> factorize(int n){
  V<P<int,int>> res;
  for(int i=2; i*i<=n; i++){
    if(n%i)
      continue;
    res.emplace_back(i,0);
    while(n%i==0){
      n/=i;
      res.back().second++;
    }
  }
  if(n!=1)
    res.emplace_back(n,1);
  return res;
}

signed main(){
  int a,b;
  cin>>a>>b;
  int g=gcd(a,b);
  auto f=factorize(g);
  int ans=f.size()+1;
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

#define endl '\n'
#define int long long int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define revrep(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))

int INF = 1e18;
int MOD = 998244353;
int segtree[800008], lazy[800008], marked[800008], ones[200001];

int multiply(int a, int b){
    return (a*b)%MOD;
}
int power(int a, int b) {
    if (b == 0)
        return 1;
    int res = power(a, b / 2);
    if (b % 2)
        return (res * res * a)%MOD;
    else
        return (res * res)%MOD;
}

int merge(int fre, int digit) {
    return multiply(ones[fre], digit);
}

void update(int v, int bl, int br, int l, int r, int val) {
    if(l>r)
        return;
    if(bl == l && br == r){
        lazy[v] = val;
        marked[v] = true;
        segtree[v] = merge(r-l+1, val);
        return;
    }
    int mid = (bl+br)>>1;
    if(marked[v]){
        // If any segment has all values identical that is marked = true
        // then mark function propagates the mark to children and unmarks parent
        marked[v] = false;
        marked[2*v] = marked[2*v+1] = true;
        lazy[v*2] = lazy[v*2+1] = lazy[v];
        segtree[2*v] = merge(mid-bl+1, lazy[v]);
        segtree[2*v+1] = merge(br-mid, lazy[v]);
    }
    update(2*v, bl, mid, l, min(r, mid), val);
    update(2*v+1, mid+1, br, max(l, mid+1), r, val);
    segtree[v] = (multiply(segtree[2*v], power(10, br-mid)) + segtree[2*v+1])%MOD;
    return;
}

void solve()
{
    int n, q;cin>>n>>q;
    update(1, 1, n, 1, n, 1);
    rep(i, 1, 200001){
        ones[i] = (multiply(ones[i-1], 10) + 1)%MOD;
    }
    rep(i, 0, q) {
        int l, r, val;
        cin>>l>>r>>val;
        update(1, 1, n, l, r, val);
        cout<<segtree[1]<<endl;
    }
    
    
}

signed main()
{

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


Measured memory_bytes: 17476
#include <bits/stdc++.h>
using namespace std;
template <class T> void vector_print(vector<T> vec) {
  for (unsigned int i = 0; i < vec.size(); i++) {
    cout << vec.at(i);
    if (i < vec.size()-1) {
      cout << " ";
    } else if (i == vec.size()-1) {
      cout << endl;
    }
  }
}

int main() {
  int n, m, sum = 0, A;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> A;
    sum += A;
  }
  if (n-sum >= 0) {
    cout << n-sum << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

string hissan(string a, string b) {
    if (a.size() < b.size()) a.swap(b);
    int bi = b.size() - 1;
    int c = 0;
    string ans;

    for (int i = a.size() - 1 ; i >= 0; i--) {
        int _a = a[i] - '0';
        int _b = (bi >= 0) ? b[bi--] - '0' : 0;
        int x = _a + _b + c;

        if (x < 10) {
            c = 0;
        } else {
            x -= 10;
            c = 1;
        }
        ans.insert(0, to_string(x));
    }
    if (c) ans.insert(0, "1");

    return ans;
}

string replaceX(string s, int x) {
    replace(s.begin(), s.end(), 'X', (char)(x + '0'));
    return s;
}

bool c(string s) { return s[0] == 'X' && s.size() > 1; }

int main () {
    string s, x, y, ans;

    while(cin >> s) {
        int pos  = -1;
        int eq   = s.find("=");
        int plus = s.find("+");

        x   = s.substr(0, plus);
        y   = s.substr(plus + 1, eq - plus - 1);
        ans = s.substr(eq + 1);

        for (int i = c(x) || c(y) || c(ans); i <= 9; i++) {
            string _x   = replaceX(x, i);
            string _y   = replaceX(y, i);
            string _ans = replaceX(ans, i);
            // cout << _x << " + " << _y << " = " << _ans << endl;
            if (hissan(_x, _y) == _ans) {
                pos = i;
                break;
            }
        }
        cout << ((pos < 0) ? "NA" : to_string(pos)) << endl;
    }

    return 0;
}



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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    int h,w;cin>>h>>w;
    int sh,sw;cin >>sh>>sw;
    int gh,gw;cin >>gh>>gw;
    sh--;sw--;gh--;gw--;
    vector<string>s(h);
    for (int i = 0; i < h; ++i) {
        cin >>s[i];
    }
    deque<pair<int,int>>que;
    que.emplace_back(sh,sw);
    int dx[4]={1,-1,0,0};
    int dy[4]={0,0,1,-1};
    vector<vector<int>>d(h,vector<int>(w,INF));
    d[sh][sw]=0;
    while(!que.empty()){
        auto [i,j]=que.front();
        que.pop_front();//h w;
        for (int k = 0; k < 4; ++k) {
            int nh=i+dx[k],nw=j+dy[k];
            if(nh<0||nh>=h||nw<0||nw>=w)continue;
            if(s[nh][nw]=='#')continue;
            if(d[nh][nw]>d[i][j]){
                d[nh][nw]=d[i][j];
                que.emplace_front(nh,nw);
            }
        }
        for (int l =max(i-2,0); l <=min(h-1,i+2); ++l) {
            for (int k =max(j-2,0); k <=min(w-1,j+2); ++k) {
                if(s[l][k]=='#')continue;
                if(l==i&&k==j)continue;
                if(d[l][k]>d[i][j]+1){
                    d[l][k]=d[i][j]+1;
                    que.emplace_back(l,k);
                }
            }
        }
    }
    if(d[gh][gw]==INF)cout <<-1<<endl;
    else cout <<d[gh][gw]<<endl;
}


Measured memory_bytes: 9424
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>



typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)



ll fast_pow(ll x,ll n,ll mod){
    if (n==0) return 1;
    ll res=fast_pow(x*x %mod,n/2,mod);
    if (n&1) res=res*x%mod;
    return res;
}

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;




int main(){
    int n;
    cin>>n;
    vector<vector<int>> vec(n);
    
    int a,b;
    rep(i,n-1){
        cin>>a>>b;
        a--;b--;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    vector<int> idx(n);
    rep(i,n) idx[i]=i;
    int l[n];
    rep(i,n) {
        cin>>l[i];
        
    }
    sort(l,l+n);
    sort(idx.begin(),idx.end(),
    [&](int x,int y){
        return vec[x].size()<vec[y].size();
    });
    ll cnt=0;
    rep(i,n-1) cnt+=l[i];
    cout<<cnt<<endl;;
    int ans[n];
    deque<int> dq(n);
    rep(i,n) {
        dq[i]=idx[i];
        //cout<<dq[i];
    }    
    int size[n];
    rep(i,n){
        size[i]=vec[i].size();
        //cout<<size[i]<<endl;
    }
    int idxcnt=0;
    while(!dq.empty()){
        a=dq[0];
        //cout<<size[a]<<" "<<a<<endl;
        if (size[a]==1 || size[a]==0) {
            for (int i:vec[a]){
                size[i]--;
                
            }
            ans[a]=l[idxcnt++];
        }
        dq.pop_front();
        if (size[a]!=1 && size[a]!=0) dq.push_back(a);
    }
    rep (i,n) cout<<ans[i]<<" ";
    cout<<endl;
    return 0;
    
    //rep(i,n) cout<<l[i];
    //cout<<vec;
    ////cout<<idx;
    
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
  string s;
  int q;
  cin >> s >> q;
  string front = "", end = "";
  int cnt = 0;
  rep(i,q){
    int a;
    cin >> a;
    if(a == 1) cnt ++;
    else{
      int f;
      cin >> f;
      string t;
      cin >> t;
      if(f == 1){
        if(cnt%2 == 0) front = t+front;
        else end += t;
      }
      else{
        if(cnt%2 == 0) end += t;
        else front = t + front;
      }
    }
  }
  if(cnt%2 == 0) cout << front + s + end << endl;
  else{
    reverse(s.begin(),s.end());
    reverse(end.begin(),end.end());
    reverse(front.begin(),front.end());
    cout << end + s + front << endl;
  }
}


Measured memory_bytes: 4376
# ABC156C

import numpy as np
def f(n, x):
    mean =  np.mean(x)
    s1 = sum((x-np.floor(mean))**2)
    s2 = sum((x-np.ceil(mean))**2)
    print(int(min(s1, s2)))

n = int(input())
x = list(map(int, input().split()))
f(n, x)


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

int A,B,C;

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

    if(C<A&&C>B)cout<<"Yes"<<endl;
    else if(C<B&&C>A)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main() {
  int length;
  char input_str[101];
  scanf("%s", input_str);
  length = strlen(input_str);
  printf("%c%d%c\n", input_str[0], length - 2, input_str[length-1]);
  return 0;
}


Measured memory_bytes: 128
N = int(input())

A = [0] * N
for i in range(N):
    a = int(input())
    A[i] = a

tmp = A[:]
tmp.sort(reverse=True)
for i in range(N):
    
    if tmp[0] == A[i]:
        print(tmp[1])
    else:
        print(tmp[0]) 

Measured memory_bytes: 14076
import java.util.*;
public class Main {
static int A= 0;


	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		A=sc.nextInt();
		int T= 52;
		int S=0;
		int count=0;
		int B =0;
		int C= 0;
		int data []=new int[A];
		
		for(int i=0;i<A;i++) {
		data[i] =sc.nextInt();	
		C = data[i];
		if(B > C) {
			
			if(T==52) {
				
				T=i-1;
				
			}else {
				
				S=i;
				
			}

			count++;
			if(count>2) break;
		}
		B= data[i];
		
		}
		if(count>2) {
			System.out.println("NO");
		}else {
		   if(T!=52 && S!=0) {
			int temp=data[T];
			data[T]=data[S];
			data[S]=temp;
		   }
			for(int i=0;i<A;i++) {
				if(i==A-1) {
					System.out.println("YES");

				}else if( data[i]>data[i+1]) {
					System.out.println("NO");
					break;
				}
		}
		
		

	}
}
}


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

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int n,m;cin>>n>>m;
  string s;cin>>s;
  reverse(s.begin(),s.end());
  vector<int> ans;
  int now=0;
  while(now<n){
    int a=0;
    for(int i=1;i<=m;i++){
      if(now+i>n)continue;
      if(s[now+i]=='0')a=i;
    }
    if(a==0)fin(-1);
    now+=a;
    ans.push_back(a);
  }
  reverse(ans.begin(),ans.end());
  for(int p:ans)cout<<p<<" ";cout<<endl;
}


Measured memory_bytes: 1528
//! 尺卂乃卂.卂ﾌ乇乇ㄒ
#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
//Using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> Ordered_set;

#define ll              long long
#define int             long long
#define ld             long double
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define vii             vector<vi>
#define vip            vector<pii>
#define mii             map<int,int>
#define mip             map<pair<int,int>,int>
#define mic             map<char,int> 
#define all(v)          v.begin(),v.end()  
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define lb(x)           (x&(-x))
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define itr(it,v)          for(auto it:v)
#define show(arr,n)     for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n";
#define fi(i,n)         for(int i=0;i<n;i++)
#define fir(i,k,n)       for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ff               first 
#define ss               second
#define deb(x) cout << #x << "=" << x << endl
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define check(x) (x && cout<<"Yes\n")||(cout<<"No\n");
#define fin(s)          freopen(s,"r",stdin);  
#define fout(s)         freopen(s,"w",stdout);

const ld pi = 3.141592653589793238462643383279502884;
const int xd[]={-1,0,1,0};
const int yd[]={0,-1,0,1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0,  1, -1, 1, -1, 0, 1 };

int expo(int a,int b,int m);
int mmi(int a,int m);
void ipgraph(int m);

const int N=5*(1e5)+10;
vii adj(N);
int a[N];

void  solve(){

}
int32_t main()
{
    FIO
    fi(i,5) cin>>a[i];
    fi(i,5){
        if(a[i]==0){
            cout<<i+1<<"\n";
            return 0;
        }
    }
    return 0;

}

void ipgraph(int m){
    int i, u, v;
    while(m--){
          cin>>u>>v;
         u--, v--;
    adj[u].pb(v);
    adj[v].pb(u);
    }
}
int expo(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return a;
    int val=(expo(a,b/2,m)*expo(a,b/2,m))%m;
    if(b & 1) return (val*a)%m;
    else return val;
}
int mmi(int a,int m){
    return expo(a,m-2,m);
}

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

int main() {
  int h, w;
  cin >> h >> w;
  string s = "";
  rep(i, h) {
    string j;
    cin >> j;
    s += j;
  }
  rep(i, h*w) {
    int x = 0;
    if (s.at(i) == '#') {
      cout << '#';
    } else {
      int hi = i / w, wi = i % w;
      if (hi > 0 && wi > 0 && s.at(i-w-1) == '#') x++;
      if (hi > 0 && s.at(i-w) == '#') x++;
      if (hi > 0 && wi < (w-1) && s.at(i-w+1) == '#') x++;
      if (wi > 0 && s.at(i-1) == '#') x++;
      //if (s.at(i) == '#') x++;
      if (wi < (w-1) && s.at(i+1) == '#') x++;
      if (hi < (h-1) && wi > 0 && s.at(i+w-1) == '#') x++;
      if (hi < (h-1) && s.at(i+w) == '#') x++;
      if (hi < (h-1) && wi < (w-1) && s.at(i+w+1) == '#') x++;
      cout << x;
    }
    if (i % w == (w - 1)) {
      cout << endl;
    }
  }
}

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

int r, c, k;
int grid[3005][3005];

long long memo[3005][3005][5];
long long dp(int i, int j, int rem) {
	if (memo[i][j][rem] != -1) return memo[i][j][rem];
	long long cur = 0;
	if (rem == 0) {
        if (i <= r) return memo[i][j][rem] = dp(i + 1, j, 3);
        else return 0;
	}
	if (j <= c) cur = max(dp(i, j + 1, rem), dp(i, j + 1, rem - 1) + grid[i][j]);
	if (i <= r) cur = max(cur, dp(i + 1, j, 3) + grid[i][j]);
	return memo[i][j][rem] = cur;
}

int main() {
	scanf("%d%d%d", &r, &c, &k);
	for (int i = 0; i < k; i++) {
		int r1, c1, v1; scanf("%d%d%d", &r1, &c1, &v1);
		grid[r1][c1] = v1;
	}
	memset(memo, -1, sizeof memo);
	printf("%lld\n", dp(1, 1, 3));
	return 0;
}


Measured memory_bytes: 392124
#include<iostream>
using namespace std;
typedef long long ll;

struct Stack{
  ll table[1000];
  ll top;
  void init(){
    top=0;
  }
  bool empty(){
    return top==0;
  }
  void push(ll x){
    table[top]=x;
    top++;
  }
  ll pop(){
    if(empty())return 0;
    top--;
    return table[top];
  }
};

ll calc(ll x,string op,ll y){
  if(op=="+")return x+y;
  if(op=="-")return x-y;
  if(op=="*")return x*y;
}


int main(){
  string str;
  ll numA,numB;
  Stack stack;
  stack.init();

  while(cin>>str){
    if(str=="+"||str=="-"||str=="*"){
      numA=stack.pop();
      numB=stack.pop();
      stack.push(calc(numB,str,numA));
    }else{
      numA=0;
      for(int i=0;i<(int)str.size();i++){
	numA*=10;
	numA+=str[i]-'0';
      }
      stack.push(numA);
    }
  }
  cout<<stack.pop()<<endl;
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    reverse(a.begin(), a.end());       // 順序反転
    // for (auto x : a ) {cout << x; if (x!=a[n]) cout << " ";}
    for (int j=0; j<n; j++) {cout << a[j]; if (j!=n-1) cout << " ";}
    cout << endl;
    return 0;
}


Measured memory_bytes: 3092
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
typedef pair<int,int> pii;
#define mp make_pair
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=200010;
int n,a[4],ans[N];
char s[N][4];
int main()
{
	n=gi();a[0]=gi();a[1]=gi();a[2]=gi();
	int flag=0;
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
	{
		int x=s[i][1]-'A',y=s[i][2]-'A';
		if(a[x]<a[y])a[x]++,a[y]--,ans[i]=x;
		else if(a[y]<a[x])a[x]--,a[y]++,ans[i]=y;
		else
		{
			if(a[x]==1&&!a[3-x-y])
			{
				if(i==n||(s[i+1][1]!=3-x-y+'A'&&s[i+1][2]!=3-x-y+'A')){a[x]--;a[y]++;ans[i]=y;}
				else
				{
					int x1=s[i+1][1]-'A',x2=s[i+1][2]-'A';
					if(x1==x||x2==x)
					{
						ans[i]=x;
						a[x]++;a[y]--;
					}
					else
					{
						ans[i]=y;a[x]--;a[y]++;
					}
				}
			}
			else
			{
				a[x]--;a[y]++;ans[i]=y;
			}
		}
		if(a[x]<0||a[y]<0){flag=1;break;}
	}
	if(flag)puts("No");
	else
	{
		puts("Yes");
		for(int i=1;i<=n;i++)printf("%c\n",ans[i]+'A');
	}
	return 0;
}


Measured memory_bytes: 4624
#include<iostream>
#include<string>
#include<map>
#include<utility>
using namespace std;
int main() {
	string word;
	map<string, int>m;
	int a;
	for (int j = 0; j < 2; j++) {
		cin >> a;
		for (int i = 0; i < a; i++) {
			cin >> word;
			if (m.find(word) != m.end()) {
				if(j==0)m[word]++;
				else m[word]--;
			}
			else {
				m[word] = 1;
			}
		}
	}
	int ans = 0;
	for(pair<string,int>mp:m)
	{
		if (mp.second > ans) {
			ans = mp.second;
		}
	}
	cout << ans;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  int64_t A[M];
  for(int i=0;i<M;i++) cin >> A[i];
  sort(A,A+M);
  int64_t ans = A[M-1] - A[0];
  if(N < M){
    priority_queue<int> que;
    for(int i=1;i<M;i++){
      que.push(A[i]-A[i-1]);
    }
    for(int i=0;i<(N-1);i++){
      ans -= que.top();
      que.pop();
    }
    cout << ans << endl;
  }
  else cout << 0 << endl;
}

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

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

   if (n % 2 == 0) cout << (double)1 / 2 << endl;
   else if(n % 2 != 0) cout << (double)(n / 2 + 1) / n << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
class Main{
	static int mod = 998244353;
public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();
		int total =0 ;
		for(int i=0;i<=2;i++)
			total += sc.nextInt();
		if(total<22)
			System.out.println("win");
		else System.out.println("bust");
	}
	
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;


		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}

}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,a,cnt;
map<int,int> m;

signed main() {
    cin >> n;
    rep(i,n) cin >> a,m[a]++;
    for(auto i : m) cnt += i.se-1;
    cout << n-cnt-cnt%2 << endl;
}

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

int main() {
  int N, K, a, i;
  cin >> N >> K;
  a=1, i=0;
  
  for (int i=0; i<N; i++){
    
    if (a<K) {
      a *=2;
    }
    else {
      a +=K;
    }
    
  }
  
    cout << a << endl;
  }


    


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

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

int main(void) {
  int n,x;
  cin >> n >> x;

  vector<int> v;
  for (int i = 0; i < n; i++) {
    int xx;
    cin >> xx;
    v.push_back(xx);
  }
  sort(v.begin(), v.end());

  int ans=abs(x-v[0]);
  for (int i = 1; i < n; i++) {
    ans =gcd(ans, v[i]-v[i-1]);
  }

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


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

int main() {
    int N; cin >> N;
    vector<ll> beki3(10); beki3[0] = 1;
    for (int i = 1; i < 10; i++) beki3[i] = beki3[i-1] * 3;
    vector<ll> beki10(10); beki10[0] = 1;
    for (int i = 1; i < 10; i++) beki10[i] = beki10[i-1] * 10;
    int tfs[3] = {3, 5, 7};
    int ans = 0;
    for (int k = 3; k <= 9; k++) {
        for (int x = 1; x < beki3[k]; x++) {
            int t = 0;
            bool flag[3] = {false, false, false};
            for (int l = 0; l < k; l++) {
                t += beki10[l] * tfs[(x / beki3[l]) % 3];
                flag[(x / beki3[l]) % 3] = true;
            }
            if (flag[0] && flag[1] && flag[2] && t <= N) ans++;
        }
    }
    cout << ans << endl;
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

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

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

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

  vi h(n);
  rep(i, 0, n){
    cin >> h[i];
  }

  int ans = 0, m = 0;
  rep(i, 0, n){
    if(m <= h[i]){
      ans++;
      m = h[i];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define emb emplace_back
#define fcout cout << fixed << setprecision(15)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

ll dp[3][100005];
int main() {
  int n;
  cin >> n;
  vi a(n),b(n),c(n);
  rep(i,n) {
    cin >> a.at(i) >> b.at(i) >> c.at(i);
  }

  rep(i,n) {
    dp[0][i+1] = max(dp[1][i],dp[2][i]) + a.at(i);
    dp[1][i+1] = max(dp[0][i],dp[2][i]) + b.at(i);
    dp[2][i+1] = max(dp[0][i],dp[1][i]) + c.at(i);
  }

  ll res = 0;
  res = max(res,dp[0][n]);
  res = max(res,dp[1][n]);
  res = max(res,dp[2][n]);
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3712
n = gets.to_i
result = ''
i = 1
while true do
    x = i
    if x%3 == 0 then
        result += " #{i}"
    else
        loop do
            if x%10 == 3 then
                result += " #{i}"
                break
            end
            x /= 10;
            break if x == 0
        end
    end
    i += 1
    break if i > n
end
puts result


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

struct info
{
    int a,b,c;
};

bool s[101][101][101];

int val(info x)
{
    int ans=x.a*x.a+x.b*x.b+x.c*x.c+x.a*x.b+x.b*x.c+x.c*x.a;
    return ans;
}

int main()
{
    int n;
    cin>>n;
    int cnt[n+1]={0};
    queue<pair<int,info>> p;
    p.push({6,{1,1,1}});
    s[1][1][1]=1;
    while(!p.empty())
    {
        pair<int,info> x=p.front(); p.pop();
        if(x.first<=n)
            cnt[x.first]++;
        info z=x.second;
        z.a++; int k=val(z);
        if(k<=n && !s[z.a][z.b][z.c]) 
        {
            p.push({k,z});
            s[z.a][z.b][z.c]=1;
        }
        z.a--; z.b++; k=val(z);
        if(k<=n && !s[z.a][z.b][z.c]) 
        {
            p.push({k,z});
            s[z.a][z.b][z.c]=1;
        }
        z.b--; z.c++; k=val(z);
        if(k<=n && !s[z.a][z.b][z.c]) 
        {
            p.push({k,z});
            s[z.a][z.b][z.c]=1;
        }
    }
    for(int i=1; i<=n; i++)
        cout<<cnt[i]<<endl;
    return 0;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
        #define ll long long
        #define f   first
        #define s   second
        #define pb          push_back
        #define mod        1000000007
        #define mod1       1000000009
        #define hell        998244353
        #define inf         1000000000000000000LL
        #define pi          3.14159265358979323
        #define N           9
        using namespace std;
        ll n,k,sum,q,res,m,val;
        ll x,y;
        void solve()    
        {   
            ll a,b,v,w;
            double T;
            cin>>a>>v;
            cin>>b>>w;
            cin>>T;
            ll dis=abs(b-a);
            ll speed=v-w;
            if(dis==0)
            {
                cout<<"YES";return;
            }
            else if(speed<=0) {cout<<"NO";return;}
            else
            {
                double t=(double)(dis)/(speed);
                //cout<<t;
                if(T>=t) {cout<<"YES";return;}
                else {cout<<"NO";}

            }



        }
        int main()
        {   ios_base::sync_with_stdio(false);
            cin.tie(0);cout.tie(0);
            ll t=1;
            //cin>>t;
            for(int i=1;i<=t;i++)
                solve();
            

        }            

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int X;
    cin >> X;
    cout << 10-X/200 << endl;
}


Measured memory_bytes: 3604
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, p[209], q[209];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> p[i], q[i] = p[i];
	vector<int> v;
	int cyclic = 0;
	while (true) {
		bool flag = false;
		for (int i = 1; i < n; i++) {
			if (p[i - 1] > p[i]) {
				flag = true;
				int tp = i - cyclic;
				if (tp < 0) tp += n;
				for (int j = 0; j < tp; j++) v.push_back(1);
				cyclic = (cyclic + tp) % n;
				v.push_back(n - 1);
				swap(p[i], p[i - 1]);
			}
		}
		if (!flag) break;
	}
	while (cyclic % n != 0) cyclic++, v.push_back(1);
	cout << v.size() << endl;
	for (int i : v) {
		cout << i << endl;
		for (int j = i; j < n; j++) {
			swap(q[j - i], q[j]);
		}
	}
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppp;
typedef complex<double> xy_t;

const lint mod = 1e9 + 7;

int main(){
    int h, w, K;
    scanf("%d%d%d", &h, &w, &K);
    char a[h][w];
    int sx ,sy;
    rep(i, h)rep(j, w){
        scanf(" %c", &a[i][j]);
        if(a[i][j] == 'S') sx = i, sy = j;
    }
    
    const int INF = 1000000;
    pii d[h][w];
    rep(i, h)rep(j, w) d[i][j] = pii(INF, INF);
    queue<ppp> que;
    d[sx][sy] = pii(1, 0);
    que.push(ppp(pii(sx, sy), pii(1, 0)));
    int dx[4] = {0, 1, 0, -1};
    int dy[4] = {1, 0, -1, 0};
    
    while(!que.empty()){
        ppp p = que.front(); que.pop();
        int x = p.fi.fi;
        int y = p.fi.se;
        int td = p.se.fi;
        int tk = p.se.se;
        if(d[x][y] < p.se || tk == K) continue;
        
        rep(i, 4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(0<=nx && nx<h && 0<=ny && ny<w && a[nx][ny] == '.'){
                pii nd = pii(td, tk+1);
                
                if(d[nx][ny] > nd){
                    d[nx][ny] = nd;
                    que.push(ppp(pii(nx, ny), nd));
                }
            }
        }
    }
    
    rep(i, h)rep(j, w)if(d[i][j].fi == 1) que.push(ppp(pii(i, j), d[i][j]));
    
    while(!que.empty()){
        ppp p = que.front(); que.pop();
        int x = p.fi.fi;
        int y = p.fi.se;
        int td = p.se.fi;
        int tk = p.se.se;
        if(d[x][y] < p.se) continue;
        
        rep(i, 4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(0<=nx && nx<h && 0<=ny && ny<w){
                pii nd;
                if(tk == K || td == 1) nd = pii(td+1, 1);
                else nd = pii(td, tk+1);
                
                if(d[nx][ny] > nd){
                    d[nx][ny] = nd;
                    que.push(ppp(pii(nx, ny), nd));
                }
            }
        }
    }
    
    int ans = INF;
    rep(i, w) ans = min({ans, d[0][i].fi, d[h-1][i].fi});
    rep(i, h) ans = min({ans, d[i][0].fi, d[i][w-1].fi});
    
    printf("%d\n", ans);
    /*rep(i, h){
        rep(j, w) printf("(%d, %d) ", d[i][j].fi, d[i][j].se);
        printf("\n");
    }*/
}

Measured memory_bytes: 16144
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        int M = cin.nextint;
        int Q = cin.nextint;
        var dp = new int[N, N];
        for (int i = 0; i < M; i++)
        {
            int L = cin.nextint - 1;
            int R = cin.nextint - 1;
            dp[L, R]++;
        }
        for (int i = 1; i < N; i++)
        {
            for (int j = 0; j + i < N; j++)
            {
                if (i == 1) dp[j, j + 1] += dp[j, j] + dp[j + 1, j + 1];
                else dp[j, j + i] += dp[j, j + i - 1] + dp[j + 1, j + i] - dp[j + 1, j + i - 1];
            }
        }

        for (int i = 0; i < Q; i++)
        {
            WriteLine(dp[cin.nextint - 1, cin.nextint - 1]);
        }

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 16548
from sys import stdin, stdout

def solve(a,M):
    total = sum(a)
    a.sort(reverse = True)
    #print(total)
    if a[M - 1]*4*M >= total: return 'Yes'
    return 'No'



N, M = map(int,stdin.readline().rstrip().split())
a = [int(x) for x in stdin.readline().rstrip().split()]

stdout.write(solve(a,M))


Measured memory_bytes: 9100
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;



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

int N; cin >> N;
vector<int> v(N, 0); rep(i,0,N) cin >> v[i];
sort(ALL(v));

double ans = v[0];
rep(i, 1, N){
    ans = (ans + v[i]) / 2.0;
}

cout << ans << "\n";

return 0;
}

// 境界，出力文字列 チェック



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, x, MIN = INF;
    cin >> n >> x;
    rep(i, n)
    {
        int a;
        cin >> a;
        MIN = min(MIN, a);
        x -= a;
    }
    cout << n + x / MIN << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int v=in.nextInt();
		int[] val=new int[n+5];
		int[] wei=new int[n+5];
		int[] dp=new int[v+5];
		Arrays.fill(dp,0);
		for(int i=1;i<=n;i++){
			val[i]=in.nextInt();
			wei[i]=in.nextInt();
		}
		in.close();
		for(int i=1;i<=n;i++)
			for(int j=wei[i];j<=v;j++)
				dp[j]=Math.max(dp[j],dp[j-wei[i]]+val[i]);
		System.out.println(dp[v]);
	}
}

Measured memory_bytes: 27056
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<numeric>
#include<stdio.h>

using std::cout;
using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

#define INF 999999999;
#define MOD 1000000007

using ulli = unsigned long long int;

#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

ulli N, x;
ulli a[100001];
ulli ans = 0;

int main(){
	cin.tie(0);
	std::ios::sync_with_stdio(false);
    
    cin >> N >> x;
    for(ulli i = 0; i < N; i++){
        cin >> a[i];
    }
    for(ulli i = 1; i < N; i++){
        dbug(i)dbug(a[i-1])dbug(a[i])dbugln;
        if(a[i-1]+a[i] > x){
            if(a[i-1] < x){
                ans += a[i] - (x - a[i-1]);
                a[i] = x-a[i-1];
            }else{
                ans += a[i] + a[i-1] - x;
                a[i] = 0;
                a[i-1] = x;
            }
            
        }
        dbug(a[i-1])dbug(a[i])dbugln;
    }
    
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024