akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int a;
string s;

signed main()
{
	cin >> a;
	cin >> s;

	if (a >= 3200) cout << s << endl;
	else cout << "red" << endl;
}




Measured memory_bytes: 256
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
#include<cmath>
#include<set>
#include<utility>

using namespace std;


int main()
{
	vector<int> a(4);
	for(int i=0;i<3;i++)
		{
		int x, y;
		cin >> x >> y;
		
		a[x-1]++;
		a[y - 1]++;
	}
	int t = 0;
	int h = 0;
	for (int i = 0; i < 4; i++)
	{
		if (a[i] == 3)
		{
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

const int mod = 1e9+7;
struct mint {
    ll x;
    mint (ll x = 0) : x((x%mod+mod)%mod) {}
    mint operator -() const {return mint(-x);}
    mint& operator +=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator -=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator *=(const mint a) {(x *= a.x) %= mod; return *this;}
    mint operator +(const mint a) const {return mint(*this) += a;}
    mint operator -(const mint a) const {return mint(*this) -= a;}
    mint operator *(const mint a) const {return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {return pow(mod-2);}
    mint operator /=(const mint a) {return *this *= a.inv();}
    mint operator /(const mint a) {return mint(*this) /= a;}
};
istream& operator >>(istream &is, const mint &a) {return is >> a.x;}
ostream& operator <<(ostream &os, const mint &a) {return os << a.x;}

mint dp[10005][2][105];

int main() {
    string s; cin >> s;
    int n = s.size();
    int d; cin >> d;
    dp[0][0][0] = 1;
    rep(i,n)rep(j,2)rep(k,d)rep(l,10) {
        int n_j = j; int n_k = (k+l)%d; int n_i = i+1;
        if (j == 0) {
            if (l > s[i]-'0') continue;
            if (l < s[i]-'0') n_j = 1;
        }
        dp[n_i][n_j][n_k] += dp[i][j][k];
    }
    cout << dp[n][0][0] + dp[n][1][0] - 1 << endl;
}

Measured memory_bytes: 16640
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean[] f = new boolean[1000000];
		Arrays.fill(f, true);//???????????¨????´????true????????????

		/*
			for?????¨??????????????????????????§false???????´?
		*/

		for(int i=2;i<1000000;i++){
			//if(f[i]){
				for(int j=i*2;j<1000000;j+=i){//j 
					f[j]=false;
				}
			//}
		}//false?????????
		while(sc.hasNext()){
			int n = sc.nextInt();
			int c = 0;
			for(int i=2;i<=n;i++)c+=f[i]?1:0;//true??????1?¶???????false??????0?¶????
			System.out.println(c);
		}
	}
}

Measured memory_bytes: 27724
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

    ll i, j, n;
    cin>>n;
    ll a[n];
    double m=1, k=0;
    for(i=0; i<n; i++){
        cin>>a[i];
        k=k+(1/(double)(a[i]));
    }
    cout<<fixed<<setprecision(10);
    cout<<1/k<<endl;
    return 0;
}




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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using pinin=pair<int ,int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

string yes="Yes",no="No";



int main() {
    int n;
    cin>>n;
    vin a(n);
    int s=0;
    rep(i,n){
        cin>>a[i];
        s=(s^a[i]);
    }
    bitset<32> t(s);
    rep(i,n){
        bitset<32> u(a[i]);
        rep(j,32){
            if(t[j]) u.flip(j);
        }
        cout<<u.to_ullong()<<" ";
    }
    cout<<endl;
    
  

}


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

using namespace std;
using ll = long long;

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

  const ll mod = 1e9 + 7;

  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  // bits[i][j][0or1] := i番目以降の数にj桁目が0or1になる数がいくつあるか
  vector<vector<vector<ll>>> bits(n, vector<vector<ll>>(60, vector<ll>(2)));

  for (ll i = n - 1; i >= 0; i--) {
    for (ll j = 0; j < 60; j++) {
      if (i < n - 1) {
        bits[i][j][0] = bits[i + 1][j][0];
        bits[i][j][1] = bits[i + 1][j][1];
      }
      if (a[i] & (1ll << j)) {
        bits[i][j][1]++;
      } else {
        bits[i][j][0]++;
      }
    }
  }

  ll ans = 0;
  // for (ll i = 0; i < n - 1; i++) {
  //   for (ll j = 0; j < 60; j++) {
  //     if (a[i] & (1ll << j)) {
  //       ans += ((1ll << j) % mod) * bits[i + 1][j][0];
  //       ans %= mod;
  //     } else {
  //       ans += ((1ll << j) % mod) * bits[i + 1][j][1];
  //       ans %= mod;
  //     }
  //   }
  // }
  for (ll j = 0; j < 60; j++) {
    ans += (1ll << j) % mod * bits[0][j][0] % mod * bits[0][j][1] % mod;
    ans %= mod;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1001584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, L = 0, x;
  cin >> N >> K;
 
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (x > K - x) L += 2 * (K - x);
    else L += 2 * x;
  }
  cout << L << endl;
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto&& e : a) cin >> e;
  valarray<int64_t> x(n), y(n);
  for (int i = 0; i < n; i++) {
    x[clamp(i + a[i], 0, n - 1)]++;
    y[clamp(i - a[i], 0, n - 1)]++;
  }
  cout << (x * y).sum() << endl;
}


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

int main() {
  int a, b, c, d; cin >> a >> b >> c >> d;
  if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main()
{
    int N,M;
    cin >> N >> M;
    int num,a[N]={};
    for(int i=0;i<M*2;i++){
        cin >> num;
        for(int j=0;j<N;j++){
            if(num==j+1){
                a[j]+=1;
            }
        }
    }
    for(int i=0;i<N;i++){
        cout << a[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

vector<int> m[1000000];
int main(){
    CIN(N);CIN(M);
    V<P> vec;
    REP(a,M){
        CIN(b);CIN(c);
        vec.pb(make_pair(b,c));
        m[b-1].pb(a+1);
        m[c-1].pb(a+1);
    }
    set<int> se;
    LL ans = 0;
    REP(a,N){
        REP(b,m[a].size()){

            if(se.find(m[a].at(b)) != se.end()){
                ans++;
                se.clear();
            }
        }
        REP(b,m[a].size()){

            if(se.find(m[a].at(b)) == se.end()){
                se.insert(m[a].at(b));
            }


        }
    }
    COUT(ans);
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repf(i, f, l) for(int i = f; i < (int)l; ++i)
#define repit(it, t) for(__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++)
#define endl "\n"
#define pb emplace_back
#define lb lower_bound
#define int long long
#define ul unsigned long
#define ull unsigned long long
#define ll long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second
#define DBG0(x) { cout << #x << ": " << x << "\t"; }
#define DBG(x) {DBG0(x); cout << endl;}
#define DBG2(x, y) {DBG0(x); DBG(y);}
#define DBG3(x, y, z) {DBG0(x); DBG2(y, z);}
#define DBG4(w, x, y, z) {DBG0(w); DBG3(x, y, z);}

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef vector<bool> vbl;
typedef pair<int, int> pii;


signed main(void){
    ios::sync_with_stdio(false);
    vint xs = vint(4);
    rep(i, 4) cin >> xs[i];
    sort(xs.begin(), xs.end());
    bool ans = true;
    ans &= xs[0] == 1;
    ans &= xs[1] == 4;
    ans &= xs[2] == 7;
    ans &= xs[3] == 9;

    cout << (ans ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
int main()
{
	map<int,int> m;
	int N;
	int num;
	cin >> N;
	for(int i = 1; i <= N; i++)
	{
		scanf("%d", &num);
		m[num] = i;
	}
	map<int,int>::iterator it = m.begin();
	for(; it != m.end(); it++)
		printf("%d ", it->second);
	return 0;
} 

Measured memory_bytes: 5504
#include<stdio.h>
int main(void){
    int E,Y;
    scanf("%d %d",&E,&Y);
    if(E==0){
        if(Y>=1868 && Y<=1911){
            printf("M%d\n",Y-1868+1);
        }else if(Y>=1912 && Y<=1925){
            printf("T%d\n",Y-1912+1);
        }else if(Y>=1926 && Y<=1988){
            printf("S%d\n",Y-1926+1);
        }else if(Y>=1989 && Y<=2016){
            printf("H%d\n",Y-1989+1);
        }
    }else if(E==1){
        printf("%d\n",Y+1868-1);
    }else if(E==2){
        printf("%d\n",Y+1912-1);
    }else if(E==3){
        printf("%d\n",Y+1926-1);
    }else if(E==4){
        printf("%d\n",Y+1989-1);
    }
    return 0;
}


Measured memory_bytes: 2148
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    int64_t R;

    std::cin >> R;

    std::cout << (double)(2*M_PI*R) << std::endl;

    return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <vector>
#include <string>
#define FIN freopen("inputs.txt", "r", stdin)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
long long H;
int ans = 0;
ll solve(long long arg){
//    cout<<"arg = "<<arg<<endl;
    if(arg == 1)
        return 1;
  	else if(arg == 0) return 0;
    else 
       return 1 + 2 * solve(arg/2);
}
int main(){
//FIN;
    cin>>H;
    cout<<solve(H)<<endl;
    // cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

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

const int MOD=1000000007;
int INF=100100100100100;

int sa[200010];
int ko_1=0;
int ko_m1=0;
int kosuu[200010];

int add(int a,int b){
  return (a+b)%MOD;
}
int prod(int a,int b){
  return (a*b)%MOD;
}
int kaijo(int x){
  if(x==0)return 1;
  return prod(x,kaijo(x-1));
}
signed main(){
  int n;
  int ans=1;
  string s;
  cin>>n>>s;
  if(s[0]=='W' || s[2*n-1]=='W'){
    cout<<0<<endl;
    return 0;
  }
  rep(i,2*n){
    if(i==0)sa[0]=1;
    else{
      if(s[i-1]!=s[i])sa[i]=sa[i-1];
      else sa[i]=-sa[i-1];
    }
    //cout<<sa[i]<<endl;
    if(sa[i]==1)ko_1++;
    if(sa[i]==-1){
      ans=prod(ans,ko_1-ko_m1);
      ko_m1++;
    }
  }
  if(ko_1!=n)ans=0;
  ans=prod(ans,kaijo(n)); 
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <algorithm>

int main(){
    int n;

    while(true){
        std::cin >> n;
        if(n == 0) break;

        int* x = new int[n];

        for(int i=0; i<n; i++){
            std::cin >> x[i];
        }

        std::sort(x, x+n);
        int sum = 0;
        for(int i=1; i<(n-1); i++){
            sum += x[i];
        }

        std::cout << sum/(n-2) << std::endl;

        delete[] x;
    }

    return 0;
}



Measured memory_bytes: 3116
n, m = map(int, input().split())
d1 = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a in d1:
    d1[a].append(b)
  else:
    d1[a] = [b]
result = 0
d2 = {}
maxb = -1
for i in range(1, m + 1):
  if i in d1:
    for j in d1[i]:
      if j not in d2:
        d2[j] = 0
      d2[j] += 1
      if j > maxb:
        maxb = j
  else:
    if len(d2) == 0:
      continue
  result += maxb
  if d2[maxb] == 1:
    del d2[maxb]
    if len(d2) == 0:
      maxb = 0
    else:
      maxb = max(d2.keys())
  else:
    d2[maxb] -= 1
print(result)


Measured memory_bytes: 63576
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    vector<string> a;
    vector<string> b;
    rep(i,n) {
        string ta;
        cin >> ta;
        a.push_back(ta);
    }
    rep(i,m) {
        string tb;
        cin >> tb;
        b.push_back(tb);
    }
    for(int i=0;i<(n-m+1);i++){
        for (int j=0;j<(n-m+1);j++){
            if (b[0][0]==a[i][j]){
                bool ok = true;
                for (int sm_l=0;sm_l<m;sm_l++){
                    for (int sm_j=0;sm_j<m;sm_j++){
                        if (a[i+sm_l][j+sm_j] != b[sm_l][sm_j]) ok = false;
                    }
                }
                if (ok) {
                    cout << "Yes" << endl;
                     return 0;
                }
               
            } 
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()

    stack = deque([])
    right = 0
    for i in range(N):
        if S[i] == "(":
            stack.append(S[i])
        else:
            if stack:
                stack.pop()
            else:
                right += 1

    ans = "(" * right + S + ")" * len(stack)
    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl


int main(){
    int n;
    cin>>n;
    vi a(n);
    REP(i,n){
        cin>>a[i];
    }
    for(int i=n-1;i>0;i-=2){
        cout<<a[i]<<" ";
    }
    cout<<a[0]<<" ";
    for(int i=2-(n%2);i<n;i+=2){
        cout<<a[i]<<" ";
    }cout<<endl;

    return 0;
}


Measured memory_bytes: 2944
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
// bool operator<(const pair<int, int> &a, const pair<int, int> &b)
// {
//     if (a.first == b.first)
//         return a.second < b.second;
//     return a.first < b.first;
// };

/*unsigned int xor128(void)
{
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
unsigned int xor128rnd(unsigned int m)
{
    return xor128() % m;
}*/

/*bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return a.second < b.second;
    }
    return a.first < b.first;
}*/

int N, H, W;
double arr[3000];
double dp[3000][3000];
vector<int> v1, v2;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(12);
    vector<int> v;
    int a;
    cin >> a;
    v.push_back(a);
    cin >> a;
    v.push_back(a);
    cin >> a;
    v.push_back(a);
    cin >> a;
    v.push_back(a);
    sort(v.begin(), v.end());
    if (v[0] == 1 && v[1] == 4 && v[2] == 7 && v[3] == 9)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

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

const int H=3,W=3;
const int SIZE=H*W;

class State
{
 public:
    string str;
    int space,distFromS,distToG;
    State(string str,int space,int dist):str(str),space(space),distFromS(dist),distToG(0){
        for(int i=0;i<SIZE;i++) if(i!=space){
            int y=i/W,x=i%W;
            int gy=(str[i]-'a')/W,gx=(str[i]-'a')%W;
            distToG+=abs(y-gy)+abs(x-gx);
        }
    }
    bool operator<(const State& s) const{
        return distFromS+distToG>s.distFromS+s.distToG;
    }
};

int d[4]={-W,-1,1,W};

int main()
{  
    string s(SIZE,' '),goal(SIZE,' ');
    for(int i=0;i<SIZE;i++) goal[i]=(char)('a'+i);
    for(int i=0;i<SIZE;i++){
        int t; cin>>t;
        if(t==0) s[i]=goal[SIZE-1];
        else s[i]=goal[t-1];
    }

    State start(s,s.find(goal[SIZE-1]),0);
    priority_queue<State> Q; Q.push(start);
    set<string> visited; visited.insert(s);
    while(!Q.empty()){
        auto cur=Q.top(); Q.pop();
        if(cur.str==goal){
            cout<<cur.distFromS<<endl;
            return 0;
        }
        for(int i=0;i<4;i++){
            int nxtspace=cur.space+d[i];
            if(nxtspace<0 or nxtspace>=SIZE) continue;
            if(d[i]==1 and nxtspace%W==0) continue;
            if(d[i]==-1 and nxtspace%W==W-1) continue;
            string nxtstr=cur.str;
            swap(nxtstr[cur.space],nxtstr[nxtspace]);
            if(!visited.count(nxtstr)){
                visited.insert(nxtstr);
                State nxt(nxtstr,nxtspace,cur.distFromS+1);
                Q.push(nxt);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4216
#include <iostream>
#include <string.h>

using namespace std;

int main()
{
    char s[100000];
    int n, a=-10;
    cin>>s;
    n=strlen(s);
    for(int i=0; i<n; i++)
        if(s[i]==s[i+1])
            a=i;
    if(a!=-10)
        cout<<a+1<<" "<<a+2;
    else{
        for(int i=0; i<n; i++)
            if(s[i]==s[i+2])
                a=i;
    if(a!=-10)
        cout<<a+1<<" "<<a+3;
    else
        cout<<"-1 -1";
    }


    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int i,n;
  while(cin>>n,n){
   long long a[n],s=0,p=0;
    for(i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(i=0;i<n-1;i++){
      s=s+a[i];
      p+=s;
    }
    cout<<p<<endl;
  }
}

Measured memory_bytes: 3104
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define PER(a,b,c) for(int a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
using namespace std;
const double Pi=acos(-1.0);
const int MAXN=1e6+5;
int n,m,t;
int a[20][20];
int now[20];
int cost[20];
int ans=1e9;
void dfs(int x,int sum){
    if(x==n+1){
        int flag=1;
        REP(i,1,m){
            if(now[i]<t)flag=0;
        }
        if(flag)ans=min(ans,sum);
    }
    REP(i,x+1,n+1){
        REP(j,1,m)now[j]+=a[i][j];
        dfs(i,sum+cost[i]);
        REP(j,1,m)now[j]-=a[i][j];
    }
}

int main(){
    cin>>n>>m>>t;
    REP(i,1,n){
        cin>>cost[i];
        REP(j,1,m)cin>>a[i][j];
    }
    dfs(0,0);
    if(ans==1e9)cout<<-1;
    else cout<<ans;
}

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

from collections import defaultdict

dp = defaultdict(int)

dp[0] = 0

for _ in range(N):
    w, v = map(int, input().split())
    for k, val in list(dp.items()):
        if k+w <= W:
            dp[k+w] = max(dp[k+w], val+v)



print(max(dp.values()))

Measured memory_bytes: 136304
#include <iostream>
#include <vector>
static constexpr int NUM = 7368792;
bool number[NUM];
 
int main()
{
    int m, n;
    while(std::cin >> m >> n && n && m) {
        for (int i = 0; i < NUM; i++) number[i] = true;
        for (int i = 0; i < n + 1; i++) {
            while (!number[m++]) {}
            number[--m] = 0;
            int year = m;
            while ((year += m) < NUM) number[year] = 0;
        }
        std::cout << m << std::endl;
    }
    return 0;
}

Measured memory_bytes: 10176
h = int(input())
w = int(input())
n = int(input())

big = 0
temp = 0

if h >= w:
  temp = h
  big = h
else:
  temp = w
  big = w

c = 1

for i in range(1000000):
  if big >= n:
    break
  big += temp
  c += 1

print(c)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define ll long long
#define maxn 16505 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
vi eg[maxn];
int f[maxn];
int dfn[maxn], low[maxn], dfcnt, inq[maxn];
int top = 0;
int bl[maxn];
int s[maxn];
vector<vi> tr;
void dfs(int a) {
	s[top++] = a; inq[a] = 1;
	dfn[a] = low[a] = ++dfcnt;
	for (auto v : eg[a]) {
		if (!dfn[v]) dfs(v), low[a] = min(low[a], low[v]);
		else {
			if (inq[v]) low[a] = min(low[a], dfn[v]);
		} 
	} 
	if (low[a] == dfn[a]) {
		vi cur;
		while (1) {
			int g = s[top - 1];
			cur.pb(g);
			inq[g] = 0;
			bl[g] = tr.size();
			top--;
			if (g == a) break; 
		} 
		tr.pb(cur);
	}
}
int fn[maxn], fl[maxn];
int tt[maxn];
int tp[maxn];
int n, x, a, o;
int main() {
	cin >> n >> x >> a >> o;
	if (x == 0) {
		cout << "No" << endl;
		return 0;
	}
	int s = (1 << (n + 1));
	for (int i = 0; i < s; i++) {
		int nc = 0;
		for (int j = 0; j < s; j++)
			if ((i ^ j) == x || ((i & j) == a) || ((i | j) == o)) tt[nc++] = j ^ x;
		eg[i].resize(nc);
		for (int j = 0; j < nc; j++)
			eg[i][j] = tt[j];//, cout << "ADE" << i << ' ' << tt[j] << endl;
	}
	for (int i = 0; i < s; i++)
		if (!dfn[i]) dfs(i); // fl : 每个数能不能选 
	for (int i = 0; i < s; i++) {
		fl[i] = 1;
		if (bl[i] == bl[i ^ x]) {
			cout << "No" << endl;
			return 0;
		}
	}
	vi fn;
	for (int i = 0; i < tr.size(); i++) {
		bool nfl = 1;
		for (auto v : tr[i]) {
		//	cout << i << ' ' << v << endl;
			for (auto q : eg[v]) {
				if (!fl[q]) fl[v] = 0;
			}
			if (!fl[v]) nfl = 0;
		}
		if (nfl) {
			for (auto v : tr[i]) 
				fn.pb(v), 
				fl[v ^ x] = 0;
		}
	}
	cout << "Yes" << endl;
	for (int i = 0; i < fn.size(); i++) {
		printf("%d", fn[i]);
		if (i == fn.size() - 1) printf("\n");
		else printf(" ");
	}
	return 0;
}
/*
13 1231 21 37
*/



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

class Graph{
    unordered_map<int,list<int>> adjlist;
    unordered_map<int,bool>visited;
    int dp[100001];
    int N;
    public:
        
        Graph(int n){
            for(int i = 1; i<=n; i++){
                dp[i] = -1;
            }
            N = n;
        }
        
        void addEdge(int x, int y){
            adjlist[x].push_back(y);
        }
        int maxDfs(int root){
            int max_path = 0;
            visited[root] = true;
            if(dp[root]!=-1){
                return dp[root];
            }
            for(auto child: adjlist[root]){
                max_path = max(max_path,maxDfs(child)+1);
            }
            dp[root] = max_path;
            return dp[root];
        }

        int checkBPT(){
            int max_ans = 0;
            for(int i = 1; i<=N; i++){
                if(!visited[i]){
                    max_ans = max(maxDfs(i),max_ans);
                }
            }
            return max_ans;
        }

};

int main() {
    int n,m,x,y;
    cin>>n>>m;
    Graph G(n);
    for(int i = 0; i<m; i++){
        cin>>x>>y;
        G.addEdge(x,y);
    }
    cout<<G.checkBPT()<<endl;
}


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

int main() {
  long long N;
  cin >>N;
  vector<long>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  long long M=1000;
  long long K=1;
  for(int i=0;i<N;i++){
    if(K==1){
      if(A[i]<A[i+1]){
        K=M/A[i];
        M-=K*A[i];
      }
    }
    else if(i==N-1){
      if(A[i]>A[i-1]){
        M+=K*A[i];
      }
    }
    else if(K>0){
      M+=K*A[i];
      K*=0;
      if(A[i]<A[i+1]){
        K=M/A[i];
        M-=K*A[i];
      }
    }
    else if(A[i]<A[i+1]){
      K=M/A[i];
      M-=K*A[i];
    }
  }
  cout<<M<<endl;
}

Measured memory_bytes: 3572
unittest
{
	assert( [ "6" ].solve == 3 );
	assert( [ "3141" ].solve == 13 );
	assert( [ "314159265358" ].solve == 9 );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	
	// 最初に割れるだけ割って、割れなくなったら引けるところまで引くことになる。
	// 引き算では割り算の余りが変わることはないので、引き算を繰り返した結果は割り算の余りに等しくなる。途中で割り算が挟まることもない。
	
	// 割り算→引き算の順でやって結果が1になるkをカウント
	auto ans = 0L;
	foreach( k; n.divisors )
	{
		if( k == 1 ) continue;
		auto m = n;
		while( m % k == 0 ) m /= k;
		if( m % k == 1 ) ans++;
	}
	
	// 引き算して結果が1になるkをカウント
	foreach( k; ( n - 1 ).divisors )
	{
		if( k == 1 ) continue;
		ans++;
	}
	return ans;
}

// 約数列挙
auto divisors( long n )
{
	bool[ long ] ds;
	auto s = cast( long ) n ^^ 0.5L;
	for( auto i = 1L; i <= s; i++ )
	{
		if( n % i != 0 ) continue;
		ds[ i     ] = true;
		ds[ n / i ] = true;
	}
	return ds.keys;
}


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

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

//constexpr long long int MOD=1000000007;
//constexpr  int MOD=1000000007;
constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;

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

	vector<int>h(4);
	vector<int>w(4);
	vector<vector<string>>s(4);
	for(int i=0;i<4;i++){
		cin>>h[i]>>w[i];
		s[i].resize(h[i]);
		for(auto &j:s[i])cin>>j;
	}
	vector<bitset<40>>t(4);
	for(int i=0;i<4;i++){
		for(int j=0;j<h[i];j++){
			for(int k=0;k<w[i];k++){
				if(s[i][j][k]=='#')t[i].flip(j*10+k);
			}
		}
	}
	unordered_set<bitset<40>>bs;
	for(int i=0;i<4;i++){
		for(int j=i+1;j<4;j++){
			for(int k=j+1;k<4;k++){
				for(int l=0;l<40;l++){
					for(int m=0;m<40;m++){
						for(int n=0;n<40;n++){
							bitset<40>box;
							box|=(t[i]<<l)|(t[j]<<m)|(t[k]<<n);
							bs.insert(box);
						}
					}
				}
			}
		}
	}
	cin>>N;
	bitset<40>ma;
	for(int i=0;i<40;i++)ma.flip(i);
	for(int i=0;i<N;i++){
		vector<string>field(4);
		for(auto &j:field)cin>>j;
		bitset<40>cf;
		for(int j=0;j<4;j++){
			for(int k=0;k<10;k++){
				if(field[j][k]=='.')cf.flip(j*10+k);
			}
		}
		auto it=bs.find(cf);
		if(it==bs.end())cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 10748
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll N;
  cin >> N;
  vll A(N), B(N), C(N);
  vector<Pll> D(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i) >> B.at(i);
    C.at(i) = A.at(i) + B.at(i);
    D.at(i) = Pll(C.at(i), i);
  }
  sort(ALL(D), greater<Pll>());
  ll sum = 0;
  for(int i = 0; i < N; i++){
    int num = D.at(i).second;
    if(i%2==0){
      sum += A.at(num);
    }
    else sum -= B.at(num);
  }
  cout << sum << endl;
}

Measured memory_bytes: 4224
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
namespace io
{
	const int N=1<<20;
	char buf[N],*t1=buf,*t2=buf;
	#ifdef cjy
	#define getc() getchar()
	#else
	#define getc() t1==t2&&(t2=(t1=buf)+fread(buf,1,N,stdin),t1==t2)?EOF:*t1++
	#endif
	inline int read()
	{
		static int an,f;an=0,f=1;
		static char ch;ch=getc();
		while(ch<48||ch>57)ch=='-'?f=-1:0,ch=getc();
		while(ch>=48&&ch<=57)an=(an<<3)+(an<<1)+(ch^48),ch=getc();
		return an*f;
	}
	char buff[N],*T=buff;
	void flush(){fwrite(buff,1,T-buff,stdout);T=buff;}
	inline void putc(char ch){if(T==buff+N)flush();*T++=ch;}
	template<typename o>
	inline void print(o x)
	{
		if(x<0)putc('-'),x=-x;
		if(!x)return putc('0'),void();
		static int st[20],tp;
		while(x)st[++tp]=x%10,x/=10;
		while(tp)putc(st[tp]^48),--tp;
	}
}
using io::read;
using io::putc;
using io::flush;
using io::print;
struct edge
{
	int nxt,to;
}e[100010];
int n,h,head[500],num,dg[500];
inline void add(int from,int to){e[++num]=edge{head[from],to};head[from]=num;++dg[from],--dg[to];}
bool vis[500];
int main()
{
	n=read(),h=read();
	for(int i=1,a,b,c,d,x,y;i<=n;++i)
	{
		a=read(),b=read(),c=read(),d=read();
		if(c==0)x=a;
		else x=c+h;
		if(d==0)y=b+h;
		else y=d;
		add(x,y);
	}
	for(int i=1;i<=h;++i)if(dg[i]<0)return printf("NO"),0;
	for(int i=h+1;i<=2*h;++i)if(dg[i]>0)return printf("NO"),0;
	queue<int>q;
	for(int i=1;i<=h;++i)if(dg[i]>0)q.push(i);
	int cnt=0;
	while(!q.empty())
	{
		int x=q.front();q.pop();
	//	printf("%d\n",x);
		if(vis[x])continue;
		vis[x]=1;
		for(int i=head[x],y;i;i=e[i].nxt)y=e[i].to,++cnt,q.push(y);
	}
	if(cnt==n)printf("YES");
	else printf("NO");
	flush();
	return 0;
}

Measured memory_bytes: 5260
import heapq,sys
input=sys.stdin.readline
INF=float('inf')
heappush=heapq.heappush
heappop=heapq.heappop

n,m=map(int,input().split())
graph=[[] for _ in range(n)]
minway=[]
bridges=[]
ans=0
for _ in range(m):
    a,b,c=map(int,input().split())
    graph[a-1].append((b-1,c))
    graph[b-1].append((a-1,c))
    bridges.append((a-1,b-1,c))

def dijkstra(graph,n,start):
    Q=[]
    distance=[]
    dappend=distance.append
    for i in range(n):
        dappend([INF,i])
    distance[start][0]=0
    for j in distance:
        heappush(Q,j)
    while Q!=[]:
        q=heappop(Q)
        for v,vl in graph[q[1]]:
            alt=vl+q[0]
            if alt<distance[v][0]:
                distance[v][0]=alt
                heappush(Q,[alt,v])
    return distance

for k in range(n):
    minway.append(dijkstra(graph,n,k))

for l in bridges:
    x,y,z=l[0],l[1],l[2]
    flag=True
    for p in range(n):
        if minway[x][p][0]+z==minway[y][p][0] or minway[y][p][0]+z==minway[x][p][0]:
            flag=False
            break
    if flag:
        ans+=1

print(ans)

Measured memory_bytes: 73180
import sys

stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


M, K = na()
if 2 ** M <= K:
    print(-1)
    exit()
if M == 1:
    if K == 0:
        print("0 0 1 1")
        exit()
    else:
        print(-1)
        exit()
ans_array = [0] * (2 ** (M+1))

for i in range(2**M-1):
    ans_array[i] = i if i < K else i + 1

ans_array[2**M-1] = K

for i in range(2**M-1, 0, -1):
    ans_array[-(i+1)] = i if i > K else i - 1

ans_array[-1] = K
print(" ".join(map(str, ans_array)))


Measured memory_bytes: 101312
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 666666
int arr[N];
int n,m;
map<int,int> mp;
signed main(){
	mp.clear();
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>arr[i];
	for(int i=1;i<=n;i++) mp[-1*(arr[i]-i)]++;
	int ans=0;
	for(int i=1;i<=n;i++){
		
		ans+=mp[(arr[i]+i)];
		mp[-1*abs(arr[i]-i)]--;
	}
	cout<<ans;
	return 0;
}

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

#define pb push_back
#define mp make_pair

#define mod 1000000007LL
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG printf("Hi\n")
#define INF 2000000000000000000LL
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2
#define SZ(z) ((int)z.size())
#define sq(x) ((x)*(x))

#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL)

#define EPS 1e-7

// using namespace __gnu_pbds;
using namespace std ;

// typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

typedef long double T ;

const T PI = ( acosl(-1.0) ) ;

#define maxn 200005

i64 a[maxn] , b[maxn] ;

int main()
{
    int n ;

    scanf("%d",&n) ;

    for(int i=0 ; i<n ; i++) scanf("%lld",&a[i]) ;
    for(int i=0 ; i<n ; i++) scanf("%lld",&b[i]) ;

    for(int i=0 ; i<n ; i++)
    {
        if( b[i] < a[i] )
        {
            printf("-1\n") ;
            return 0 ;
        }
    }

    priority_queue < pair<i64,int> > pq ;

    for(int i=0 ; i<n ; i++)
    {
        if( a[i]!=b[i] )
        {
            pq.push( mp(b[i],i) ) ;
        }
    }

    i64 ans = 0 ;

    while( !pq.empty() )
    {
        pair<i64,int> p = pq.top() ;
        pq.pop() ;
        int k = p.yy , j = (k-1+n)%n , l = (k+1)%n ;

        i64 r = 0 ;

        if( b[k]!=a[k] && b[k] > b[j] && b[k] > b[l] )
        {
            r = (b[k]-a[k])/(b[j]+b[l]) ;
            b[k] -= r*(b[j]+b[l]) ;
        }
        ans += r ;
        if( a[k] != b[k] && r==0 )
        {
            printf("-1\n") ;
            return 0 ;
        }
        if(a[k]!=b[k]) pq.push( mp(b[k],k) ) ;
    }

    for(int i=0 ; i<n ; i++)
    {
        if(a[i]!=b[i])
        {
            printf("-1\n") ;
            return 0 ;
        }
    }

    printf("%lld\n",ans) ;

    return 0 ;
}


Measured memory_bytes: 9328
# -*- coding: utf-8 -*-

def count(val1, val2):
    digit = 1
    while digit*val2 <= val1:
        digit *= val2

    res = 0
    while digit!=1:
        cnt = int(val1 // digit)
        val1 -= digit*cnt
        res += cnt
        digit /= val2

    return res,val1


N = int(input())
ans = N

for i in range(0,N+1):
    n = i
    m = N - i
    res = 0

    cnt, nn = count(n, 9)
    n = nn
    res += cnt

    cnt, mm = count(m, 6)
    m = mm
    res += cnt

    res += n + m
    ans = min(ans, int(res))

print(ans)


Measured memory_bytes: 9280
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<queue>

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

int main() {
	int n, i, j, k;
	lli ans, s;
	vi c;

	s = pow(10, 9) + 7;

	cin >> n;

	c.resize(n);

	rep(i, n) {
		cin >> j;
		if (j >= n) {
			cout << 0;
			return 0;
		}
		if (n % 2 == 0) {
			if (j % 2 == 0) {
				cout << 0;
				return 0;
			}
		}
		else {
			if (j % 2 == 1) {
				cout << 0;
				return 0;
			}
		}
		c[j]++;
		if (j == 0 && c[0] >= 2) {
			cout << 0;
			return 0;
		}
		if (c[j] >= 3) {
			cout << 0;
			return 0;
		}
	}
	ans = 1;

	for (i = n % 2 == 0 ? 1 : 0; i <= n; i += 2) {
		if (c[i] == 1 && i != 0) {
			cout << 0;
			return 0;
		}
		ans *= c[i];
		ans %= s;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;

int n;
int a;
int tot;
int m=0;

int main()
{
    cin>>n;
    for (int i=0; i<n; ++i)
    {
        cin>>a;
        tot+=a;
        if (a>m) m=a;
    }
    tot-=(m/2);
    cout<<tot<<endl;

    return 0;
}


Measured memory_bytes: 256
import bisect
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
    ans = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            ab = L[i] + L[j]
            idx = bisect.bisect_left(L, ab)
            ans += max(idx - j - 1, 0)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;cin>>n;
    vector<ll>a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    int ans=1;
    vector<ll>tmp;
    tmp.pb(a[0]);
    for(int i=1;i<n;i++){
        if(a[i]<=tmp[0]){
            tmp.insert(tmp.begin(),a[i]);
            ans++;
            continue;
        }
        auto m=lower_bound(all(tmp),a[i]);
        ll nna=a[i];
        tmp.erase(m-1);
        auto mm=lower_bound(all(tmp), nna);
        tmp.insert(mm, nna);
        
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


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

  int h,n,a[1111000];
  int ans = 0;
  
  cin >> h >> n;
  rep(i,n){
    cin >> a[i];
    ans+= a[i];
  }
  
  if(ans >= h){
    puts("Yes");
  }else{
    puts("No");
  }
}

    
    
    

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

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

    long long acc = 0;
    for (auto f : flames){
        acc += f;
    }
    double ave = acc / (double)n;

    vector<double> diff;
    double min_diff = 100000000000000000000.0;
    for (auto f: flames){
        double val = abs(f - ave);
        diff.push_back(val);
        if (val < min_diff){
            min_diff = val;
        }
    }
    int min_index = 0;
    for (int i=0;i<diff.size();i++){
        if (diff[i] == min_diff){
            min_index = i;
            break;
        }
    }
    cout << min_index << endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define N 4
#define LIM 46


int ans[N][N]={
    {1,2,3,4},
    {5,6,7,8},
    {9,10,11,12},
    {13,14,15,0}};

int x[N*N]={3,0,1,2,
            3,0,1,2,
            3,0,1,2,
            3,0,1,2},
    y[N*N]={3,0,0,0,
            0,1,1,1,
            1,2,2,2,
            2,3,3,3};

int min = LIM;



void dfs(int A[N][N], int B[N][N], int n)
{
    int i, j, i0, j0, d = 0;
    int f = 0;
    int tmp[N][N];

    for( i = 0 ; i < N ; i++)
    {
        for( j = 0 ; j < N ; j++)
        {
            if( ans[i][j] != A[i][j]) f++;
            if( A[i][j] == 0)
            {
                i0 = i;
                j0 = j;
            }
            else
                d += abs( j - x[A[i][j]] ) + abs( i-y[A[i][j]] );

        }
    }

    if( f == 0 )
    {
        if( min > n )
        {
            min = n;
        }
        return;
    }
    if( d + n > min ) return;


    if( i0 > 0 && i0 < N )
    {
        memcpy( tmp, A, sizeof(int) * N * N );
        f = tmp[i0][j0];
        tmp[i0][j0] = tmp[i0-1][j0];
        tmp[i0-1][j0] = f;
        if(memcmp( tmp, B, sizeof(int)*N*N) != 0 )
            dfs(tmp, A, n+1);
    }
    if(j0 > 0 && j0 < N)
    {
        memcpy(tmp, A, sizeof(int) * N * N );
        f = tmp[i0][j0];
        tmp[i0][j0] = tmp[i0][j0-1];
        tmp[i0][j0-1] = f;
        if(memcmp(tmp, B, sizeof(int) * N * N ) != 0)
            dfs(tmp, A, n+1);
    }

    if( i0 >= 0 && i0 < N-1)
    {
        memcpy( tmp, A, sizeof(int) * N * N);
        f = tmp[i0][j0];
        tmp[i0][j0] = tmp[i0+1][j0];
        tmp[i0+1][j0] = f;
        if(memcmp(tmp, B, sizeof(int) * N * N ) != 0 )
            dfs(tmp, A, n+1);
    }
    if( j0 >= 0 && j0 < N-1)
    {
        memcpy( tmp, A, sizeof(int) * N * N );
        f = tmp[i0][j0];
        tmp[i0][j0] = tmp[i0][j0+1];
        tmp[i0][j0+1] = f;
        if(memcmp( tmp, B, sizeof(int) * N * N ) != 0)
            dfs( tmp, A, n+1 );
    }

}

int main()
{
    int i,j;
    int A[N][N];

    for( i = 0 ; i < N ; i++)
    {
        for( j = 0 ; j < N ; j++)
        {
            scanf("%d", &A[i][j]);
        }
    }
    dfs(A,A,0);

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

    return 0;
}



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

int main(){
  int n;
  cin >> n;
  long double t[n], a[n];
  for ( int i = 0; i < n; i++){
    cin >> t[i] >> a[i];
    if ( i == 0)continue;
    if ( t[i] >= t[i-1] && a[i] >= a[i-1])continue;

    long double mul = max(ceil(t[i-1]/t[i]), ceil(a[i-1]/a[i]));
    t[i] = t[i] * mul;
    a[i] = a[i] * mul;
  }
  long long ans = t[n-1] + a[n-1];

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define debug(x) cout<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define cast static_cast
#define vi vector<int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
typedef long long int ll;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;
 
void solve(){
	string s;
	string t;
	cin>>s>>t;
	int l1=s.length();
	int l2=t.length();
	v<v<p<int,p<int,int>>>> dp(l1,v<p<int,p<int,int>>>(l2));
	for(int i=0;i<l1;i++){
		for(int j=0;j<l2;j++){
			if(s[i]==t[j]){
				if(i==0 || j==0){
					dp[i][j]=mk(1,mk(-1,-1));
				}
				else{
					dp[i][j]=mk(dp[i-1][j-1].first+1,mk(i-1,j-1));
				}
			}
			else{
				if(i==0 && j==0){
					dp[i][j]=mk(0,mk(-1,-1));
				}
				else if(i==0){
					dp[i][j]=mk(dp[i][j-1].first,mk(i,j-1));
				}
				else if(j==0){
					dp[i][j]=mk(dp[i-1][j].first,mk(i-1,j));
				}
				else{
					if(dp[i][j-1].first>=dp[i-1][j].first){
						dp[i][j]=mk(dp[i][j-1].first,mk(i,j-1));
					}
					else{
						dp[i][j]=mk(dp[i-1][j].first,mk(i-1,j));
					}
				}
			}
		}
	}
	int i=l1-1;
	int j=l2-1;
	v<char> a(dp[l1-1][l2-1].first);
	int h=0;
	while(i!=-1 && j!=-1){
		if(s[i]==t[j]){
			a[h]=s[i];
			h++;
		}
		int h1=i;
		int h2=j;
		i=dp[h1][h2].second.first;
		j=dp[h1][h2].second.second;
	}
	for(int k=dp[l1-1][l2-1].first-1;k>=0;k--){
		cout<<a[k];
	}
	cout<<"\n";
}	
 
int main(){
	boost_io;
	solve();
	return 0;
}


Measured memory_bytes: 108804
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>

using namespace std ; 

typedef long long ll ; 

int a[222222] ; 
int rev[222222] ; 
int conn[222222] ; 

int main()
{
    int N ; 
    scanf("%d", &N) ; 
    for(int i = 1 ; i <= N ; i++) {
        scanf("%d", a+i) ;
        rev[a[i]] = i ; 
    }
    ll ans = 0 ; 
    for(int i = N ; i >= 1 ; i--) {
        int loc = rev[i] ; 
        ll l, r ; 
        if(loc-1 >= 1) {
            l = conn[loc-1]+1 ; 
        }
        else
            l = 1 ; 
        if(loc+1 <= N) {
            r = conn[loc+1]+1 ; 
        }
        else
            r = 1 ; 
        ans += l*r*i ; 
//        printf("ans += %lld * %lld * %d\n", l, r, rev[i]) ; 
        conn[loc-l+1] = l+r-1 ; 
        conn[loc+r-1] = l+r-1 ; 
  //      printf("conn: ") ; 
    //    for(int i = 1 ; i <= N ; i++)
      //      printf("%d ", conn[i]) ; 
        //    puts("") ;
    }
    printf("%lld\n", ans) ; 
    return 0 ; 
}



Measured memory_bytes: 2560
#include<stdio.h>
#include<string.h>
int n;
int k;
char s[105];
int main(){
	scanf("%d %d %s", &n, &k, s);
	for(int i = 0; i < n; i++)
		if(i == k - 1)
			s[i] += 32;
	for(int j = 0; j < n; j++)
		printf("%c", s[j]);
	printf("\n");
}



Measured memory_bytes: 128