akhauriyash/Code-Regression huggingface dataset:
/*
   Username : moondancer
   Name : Moon Dancer
*/


#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s,t;
    cin>>t>>s;
    int ans=1e9;
    for(int i=0; i<=t.size()-s.size(); ++i){
        int ss=0;
        int k=i;
        for(int j=0; j<s.size(); ++j){
            if(s[j]!=t[k])
                ss++;
            k++;
        }
        ans=min(ans,ss);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string w;
    cin >> w;
    int a = 0;
    for(char i = 'a'; i <= 'z'; i++){
        for(int j = 0; j < w.size(); j++){
            if(w[j] == i) a++;
        }
        if(a%2 != 0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

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

#define dump(x) cerr << #x << " = " <<(x)<<endl;
#define debug(x) cerr << #x << " = " <<(x) << "(L" << __LINE__ << ")" << __FILE__ << endl;

#define BIT_ON(x,b) ((x)|=(b))
#define BIT_OFF(x,b) ((x)&=~(b))
#define BIT_IS_ON(x,b) (((x)&(b))==(b))


using namespace std;

int main(void){
  string s;
  cin >> s;
  REP(i,12){
    if(i==4){
      cout << " ";
    }
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 888
//Gaurav Singh (saintpopo)
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(x) x.begin(),x.end()
#define pb push_back
 
void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
 
int main(){
    //io_set();
    ll i,n=5,k,f=0,j;
    ll a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    ll ans=0,m=INT_MIN;
    for(i=0;i<n;i++){
        //cout<<a[i]<<endl;
        if(a[i]%10 == 0){
            f++;
            ans+=a[i];
        }
        else{
            //cout<<"b ";
            ll r=a[i]/10;
            ll pk=(r+1)*10;
            m=max(m,abs(pk-a[i]));
            //cout<<r<<endl;
            ans+=pk;
        }
        //cout<<ans<<endl;
    }
    if(f==n){
        cout<<ans<<endl;
    }
    else{
        cout<<ans-m<<endl;
    }
    return 0;
}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>void add(T &a, const T &b){a += b; a %= mod;}

signed main(){
  long double n, k; cin >> n >> k;
  long double ans = 0;
  FOR(i,1,n+1){
    long double l;
    if(i >= k) l = 1;
    else l = pow(2,-1*ceil(log(k/i)/log((long double)2)));
    ans += l;
  }
  dump(ans);
  printf("%.10Lf\n",ans/n);
}


Measured memory_bytes: 512
#include <cmath>
#include <iostream>
#include <iomanip>

/*
ax + by = c
dx + ey = f

x = (c-by)/a
d(c-by)/a + ey = f
dc/a - dby/a + ey = f
ey - dby/a = f - dc/a
y(e-db/a) = f - dc/a
y = (f-dc/a)/(e-db/a)

aex + bey = ce
bdx + bey = bf
aex - bdx = ce - bf
x(ae - bd) = ce - bf
x = (ce - bf)/(ae - bd)
by = c - ax
y = (c - ax)/b
*/
int main()
{
    while(true){
        double a, b, c, d, e, f;
        std::cin >> a >> b >> c >> d >> e >> f;
        if(std::cin.eof()) break;
        double x, y;
        if(b == 0) return 0;
        // if(b){
            // x = (c*e - b*f) / (a*e - b*d);
            // y = (c - a*x) / b;
        // }else{
            y = (f-d*c/a)/(e-d*b/a);
            x = (c-b*y)/a;
        // }
        if(x == -0) x = 0;
        if(y == -0) y = 0;
        std::cout << std::fixed << std::setprecision(3);
        std::cout << x << " " << y << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3272
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int A,B,K;
  cin >> A >> B >> K;
  for(int i=100;i>=0;i--){
    if(A%i==0 && B%i==0){
      K--;
    }
    if(K==0){
      cout << i << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
from collections import deque
s = input()
q = int(input())
Q = [list(input().split()) for _ in range(q)]

ans = deque(s)
ok = True
for v in Q:
    if v[0] == "1":
        if ok: ok = False
        else: ok = True
    else:
        if v[1] == "1":
            if ok: ans.appendleft(v[2])
            else: ans.append(v[2])
        else:
            if ok: ans.append(v[2])
            else: ans.appendleft(v[2])
ans = list(ans)
if not ok: ans = ans[::-1]
print("".join(ans))

Measured memory_bytes: 34672
#include <algorithm>
#include <cctype>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

typedef long long ll;
const ll INF = 1e9 + 314;

// no need to have a[mid] ?
bool solve(ll n, ll k, const vector<ll>& a, ll mid) {
    const ll w = a[mid];
    vector<ll> b(a);
    b[mid] = INF;

    vector<ll> dp(k + 1);
    vector<ll> dp_next(k + 1);

    // no card, no sum
    fill(dp.begin(), dp.end(), 0);

    for (ll i = 0; i < n; i++) {
        for (ll j = 1; j <= k; j++) {
            dp_next[j] = dp[j];
            if (j - b[i] > 0) {
                dp_next[j] = max(dp_next[j], b[i] + dp[j - b[i]]);
            }
        }
        dp = dp_next;
    }

    return dp[k] + w < k;
}

signed main(void) {
    ll n, k;
    cin >> n >> k;

    vector<ll> a;
    for (ll i = 0; i < n; i++) {
        ll x;
        cin >> x;
        if (x < k) {
            a.push_back(x);
        }
    }

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

    // [lb, ub)
    ll ub = a.size();
    ll lb = -1;
    while (ub - lb > 1) {
        ll mid = lb + (ub - lb) / 2;
        if (solve(a.size(), k, a, mid)) {
            lb = mid;
        } else {
            ub = mid;
        }
    }

    cout << (lb + 1) << endl;

    return 0;
}


Measured memory_bytes: 384
#include <cstdint>
#include <iostream>
#include <queue>

using namespace std;

priority_queue<uint64_t> q;

int32_t main()
{
  uint32_t N;
  cin >> N;

  for (uint32_t i = 0; i < N; i++) {
    uint32_t len;
    cin >> len;
    q.push(len);
  }

  uint64_t len1 = 0;
  uint64_t len_old = 0;
  while (!q.empty()) {
    uint64_t len = q.top();
    q.pop();

    if (len_old == len) {
      if (len1 != 0) {
        cout << len * len1 << endl;
        return 0;
      } else {
        len1 = len;
        len_old = 0;
      }
    } else {
      len_old = len;
    }
  }

  cout << "0" << endl;

  return 0;
}


Measured memory_bytes: 1908
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //e
  int h, w, m;
  cin >> h >> w >> m;
  vector<int> a(h), b(w);
  vector<vector<int>> aa(h);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    a[x]++;
    b[y]++;
    aa[x].push_back(y);
  }
  set<pair<int, int>> st;
  for (int i = 0; i < w; i++) st.emplace(b[i], i);
  int ans = 0;
  for (int i = 0; i < h; i++) {
    set<pair<int, int>> here;
    for (auto& x : aa[i]) {
      here.emplace(b[x], x);
      st.erase(make_pair(b[x], x));
    }
    if (!st.empty()) ans = max(ans, a[i] + st.rbegin()->first);
    if (!here.empty()) ans = max(ans, a[i] + here.rbegin()->first - 1);
    for (auto& x : aa[i]) {
      st.emplace(b[x], x);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 41784
// Header {{{
#include <bits/stdc++.h>

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}
// {{{ MaxFlow
class MaxFlow{
    private:
        // destination, capacity, reverse edge index
        const ll inf=1e18;
        struct edge { ll to, cap, rev; };
        ll _n;
        vector<vector<edge>> G;
        vector<bool> used;

        ll dfs (ll src, ll dst, ll flow){
            if (src==dst)
                return flow;
            used[src]=true;
            rep(i,0,G[src].size()){
                edge &e = G[src][i];
                if (!used[e.to] && e.cap > 0) {
                    ll d = dfs(e.to, dst, min(flow, e.cap));
                    if (d>0){
                        e.cap -= d;
                        G[e.to][e.rev].cap += d;
                        return d;
                    }
                }
            }
            return 0;
        }

    public:
        MaxFlow (ll numOfVertex){
            _n = numOfVertex;
            G = vector<vector<edge>>(_n);
        }

        // 0<=src,dst<numOfVertex
        void addEdge(ll src, ll dst, ll cap) {
            G[src].push_back(edge{dst, cap, (ll)G[dst].size()});
            G[dst].push_back(edge{src, 0, (ll)G[src].size()-1});
        }

        ll maxFlow(ll src, ll dst){
            ll flow = 0;
            while(true){
                used = vector<bool>(_n, false);
                ll f = dfs(src, dst, inf);
                if (f==0){
                    return flow;
                }
                flow += f;
            }
        }
};
// }}}
const ll M = 1e9 + 7;
signed main() {
    vector<bool> isprime(2000, true);
    isprime[0] = isprime[1] = false;
    rep(i,0,2000){
        if (!isprime[i])
            continue;
        for (ll k=2; i*k<2000; k++){
            isprime[i*k]=false;
        }
    }

    ll n;
    map<ll, ll> mp;
    cin>>n;
    rep(i,1,n+1){
        for (ll k=1; k<=n; k++){
            if (isprime[k] && i%k == 0){
                ll p = i;
                while (p % k == 0){
                    mp[k]++;
                    p /= k;
                }
                // cout<<"i="<<i<<" k="<<k<<" p="<<p<<endl;
            }
        }
    }

    ll ans=1;
    for (auto e: mp){
        // cout<<e.first<<" "<<e.second<<endl;
        ans *= e.second+1;
        ans %= M;
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i=0;i<N;i++){
    cin >> H.at(i);
  }
  int S=1;
  for (int j=1;j<N;j++){
    int s=1;
    for (int i=0;i<j;i++){
      if (H.at(j)>=H.at(i)){
        s*=1;
      }
      else {
        s*=0;
      }
    }
    if (s==1){
      S+=1;
    }
    else {
      S=S;
    }
  }
  cout << S << endl;
}


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

void input(long &n, vector<long> &a) {
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
}

long div(long n) { // 整数が2で割り切れる回数
    long count = 0;
    while (n % 2 == 0) {
        n /= 2;
        count++;
    }
    return count;
}

int main() {
    long n; vector<long> a;
    input(n, a);

    long sum = 0;
    for (long i = 0; i < n; i++) { //各要素の2で割り切れる回数の総和
        sum += div(a[i]);
    }
    cout << sum << endl;
}

Measured memory_bytes: 3644
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		scan.close();

		if (0 < a - 2 * b)
			System.out.print(a - 2 * b);
		else
			System.out.print(0);

	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    ll a, b;
    cin >> a >> b;
    ll diff = abs(a-b) + 1;
    if ( a > 0 && b <= 0 || a <= 0 && b > 0 ) {
        cout << "Zero" << endl;
    }
    else if ( a > 0 && b > 0 ) {
        cout << "Positive" << endl;
    }
    else if ( a < 0 && b < 0 ) {
        if ( diff % 2 == 1 ) {
            cout << "Negative" << endl;
        }
        else {
            cout << "Positive" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int N;
long long T[20][1<<18];
int main(){
	cin>>N;
	long long a=1;
	REP(i,N){
	   a=a*2;
	}
	REP(i,a){
	    cin>>T[0][i];
	}
	REP(i,N+1){
	    if(i==0)continue;
	    a=a/2;
	    REP(j,a){
	        if(abs(T[i-1][2*j]-T[i-1][2*j+1])==0){
	           T[i][j]=abs(T[i-1][2*j]);
	        }else{
	           T[i][j]=abs(T[i-1][2*j]-T[i-1][2*j+1]);
	        }
	    }
	}
        cout<<T[N][0]<<endl;
	return(0);
}

Measured memory_bytes: 4480
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    ll x;cin>>x;
    ll ans=2*(x/11);
    ll tmp=x-(ans/2)*11;
    if(0<tmp&&tmp<7)ans++;
    else if(6<tmp)ans+=2;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        for (int i = 1; i <= n; i++) {
            if (String.valueOf(i).length() % 2 == 0) {
                continue;
            }
            count++;
        }
        System.out.println(count);
    }

}



Measured memory_bytes: 28244
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int a=0,b=0;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='o')
			a++;
		else b++;
	}
	if(a>=8)
		puts("YES");
	else if(8-a<=15-a-b)
		puts("YES");
	else puts("NO");
}

Measured memory_bytes: 256
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>

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

using namespace std;

int n;
int a[10][10];
int ta[10][10];

int kiten_cnt;
int kiten_y[70];
int kiten_x[70];

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

bool ans;

//ta??????????????????????????\??????????????????

void dfs(int kiten_num, int syohi, int y, int x) {
    if (kiten_num == kiten_cnt) {
        bool exist_not_zero = false;
        rep(i,n) {
            rep(j,n) {
                if (ta[i][j] != 0) exist_not_zero = true;
            }
        }
        if (exist_not_zero) {
            return;
        } else {
            ans = true;
            return;
        }
    }

    if (ta[y][x] > 0) {
        syohi += ta[y][x];
        ta[y][x] = 0;
    } else {
        syohi = 0;
        ta[y][x] = 0;
    }

    if (syohi == abs(a[kiten_y[kiten_num]][kiten_x[kiten_num]])) {
        kiten_num++;
        dfs(kiten_num, 0, kiten_y[kiten_num], kiten_x[kiten_num]);
    } else {
        rep(i,4) {
            int ny = y + dy[i];
            int nx = x + dx[i];

            if (ny < 0 || n <= ny || nx < 0 || n <= nx) continue;
            if (ta[ny][nx] == 0 || ta[ny][nx] < 0) continue;
            if (syohi + ta[ny][nx] > abs(a[kiten_y[kiten_num]][kiten_x[kiten_num]])) continue;

            dfs(kiten_num, syohi, ny, nx);
        }
    }

    ta[y][x] = a[y][x];
}

int main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

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

        kiten_cnt = 0;

        rep(i,n) {
            rep(j,n) {
                cin >> a[i][j];
                ta[i][j] = a[i][j];
                if (a[i][j] < 0) {
                    kiten_y[kiten_cnt] = i;
                    kiten_x[kiten_cnt] = j;
                    kiten_cnt++;
                }
            }
        }

        ans = false;
        dfs(0, 0, kiten_y[0], kiten_x[0]);

        if (ans) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

Measured memory_bytes: 2984
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

// 重み無し
struct UnWeightedEdge {
    int src, to;
    UnWeightedEdge(int src, int to) : src(src), to(to) {}
};
using UnWeightedEdges = vector<UnWeightedEdge>;
using UnWeightedGraph = vector<UnWeightedEdges>;

void Main() {
	int N, M; cin >> N >> M;
	UnWeightedGraph uwg(N, vector<UnWeightedEdge>());
	REP(i,M) {
		int x, y; cin >> x >> y;
		--x, --y;
		uwg[x].emplace_back(x, y);
	}
	vi memo(N);
	vector<bool> done(N);
	auto dp = [&](auto dp, int v) {
		if (done[v]) return memo[v];
		int ans = 0;
		for (auto e : uwg[v]) {
			chmax(ans, dp(dp, e.to) + 1);
		}
		done[v] = true;
		memo[v] = ans;
		return ans;
	};
	int ans = 0;
	REP(i,N) {
		chmax(ans, dp(dp, i));
	}
	cout << ans << endl;
}

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


Measured memory_bytes: 8704
#include <iostream>
#include <vector>
#include <utility>

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

int highestWorth(vector<Pii> item, int weight)
{
    int item_num = item.size();
    int dp[item_num][weight + 1];

    for (int i = 0; i < item_num; i++)
    {
        for (int j = 0; j <= weight; j++)
        {
            if (i == 0 || j == 0)
            {
                dp[i][j] = 0;
                continue;
            }

            int before = j - item[i].second;
            if (before >= 0)
            {
                dp[i][j] = max(
                    dp[i - 1][j],
                    max(dp[i - 1][before] + item[i].first,
                        dp[i][before] + item[i].first));
            }
            else
            {
                dp[i][j] = max(dp[i - 1][j], before);
            }
        }
    }

    return dp[item_num - 1][weight];
}

int main()
{
    int N, W;
    cin >> N >> W;
    vector<Pii> item;

    // 0 番目の品物は空にする
    item.push_back(make_pair(0, 0));

    for (int i = 0; i < N; i++)
    {
        int v_i, w_i;
        cin >> v_i >> w_i;
        item.push_back(make_pair(v_i, w_i));
    }

    cout << highestWorth(item, W) << endl;
}


Measured memory_bytes: 7084
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    if n % 2 == 0:
        print(1 / 2)
    else:
        print((n // 2 + 1) / n)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38384
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################
n = int(input())
arr = list(map(int , input().split()))
psum = [0]*n
psum[0] = arr[0]
m = 10**9 + 7
for i in range(1,n):
	psum[i] = (psum[i-1] + arr[i])%(m)
ans = 0
for i in range(n-1):
	#print(arr[i],(psum[n-1] - psum[i]))
	ans += arr[i]*(psum[n-1] - psum[i])
	ans = ans % m
print(ans)










Measured memory_bytes: 95868
using System;
using System.Linq;

namespace codefestival_2016_qualC_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(a.Max() * 2 > x[0] + 1 ? a.Max() * 2 - 1 - x[0] : 0);
        }
    }
}

Measured memory_bytes: 13396
import sys
from heapq import heappush, heappop


N, H = map(int, input().split())
S = [tuple(map(int, s.split())) for s in sys.stdin.readlines()]
q = []
a, b = 0, 0
for na, nb in S:
    if na <= a:
        heappush(q, (-nb, na))
    else:
        heappush(q, (-b, a))
        a, b = na, nb


cnt = 0
while H > 0:
    if H <= b:
        cnt += 1
        break

    if a < -1 * q[0][0]:
        nb, na = heappop(q)
        H -= -nb
        cnt += 1
    else:
        hit = (H - b) // a + ((H - b) % a != 0)
        cnt += hit
        H -= a * hit

print(cnt)


Measured memory_bytes: 82268
#include <bits/stdc++.h>
#define rep(i,n); for(long long i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
int main(){
  ll a,b; cin >> a >> b;
  ll ans = -1;
  if(a<=9&&b<=9)ans = a*b;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>

#include <cmath>

using namespace std;

const int INF = 4;

double my_distance(int *z,int z_size,int op){
    double ans=0;
    int temp=0;
    switch (op){
        case INF:
            for(int i=0;i<z_size;i++){
                temp = max(temp,z[i]);
            }
            ans = double(temp);
            break;
        default:
            for(int i=0;i<z_size;i++){
                ans += pow(z[i],op);
            }
            ans = pow(ans,1./op);
            break;
    }
    return ans;
}
int main(){

    int n, z[100],tempY;

    cin >> n;
    for(int i=0;i<n;i++) cin >> z[i];
    for(int i=0;i<n;i++) {
        cin >> tempY;
        z[i] = (z[i] > tempY) ? z[i]-tempY : tempY-z[i];
    }

    for(int i=1;i<=4;i++){
        printf("%.5f\n",my_distance(z,n,i));
    }




    return 0;
}


Measured memory_bytes: 3352
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    let (n, a, b) = (io.read::<usize>(), io.read::<usize>(), io.read::<usize>());
    let f = |x: usize| -> usize {
        let mut y = x;
        let mut ret = 0;
        while y > 0 {
            ret += y % 10;
            y /= 10;
        }
        ret
    };
    let mut ans = 0;
    for i in 1..n + 1 {
        let x = f(i);
        if x >= a && x <= b {
            ans += i;
        }
    }
    io.writeln(ans);
}

static MX: usize = 1010101;
static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 2132
#include <iostream>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  bool t = false;
  if (a == 5 && b == 5 && c == 7)
    t = true;
  else if (a == 5 && b == 7 && c == 5)
    t = true;
  else if (a == 7 && b == 5 && c == 5)
    t = true;
  if (t)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] p = new int[n];
		for(int i=0; i<n; i++) {
			p[i] = sc.nextInt();
		}
		
		int count = 0;
		for(int i=0;i<n-2;i++) {
			if(judge(p,i)) count++;
		}
		System.out.println(count);
		
		sc.close();	
	}
	
	private static boolean judge(int[] p,int first) {
		int i1 = p[first];
		int i2 = p[first + 1];
		int i3 = p[first + 2];
		
		if(i1 < i2 && i2 < i3 || i1 > i2 && i2 > i3) {
			return true;
		}else {
			return false;
		}
	}
}

Measured memory_bytes: 21844
N,*A=`dd`.split.map(&:to_i)
M = [A.max.bit_length, 1].max
$bx = [0]
$bs = [0]
(0...N).each{ |i|
  $bx << ($bx[-1] ^ A[i])
  $bs << ($bs[-1] + A[i])
}
$bx << (1 << M) - 1
$bs << ($bs[-1] + 1e9.to_i)
#p $bs
#$stderr.puts A.map.with_index{ |a,i| sprintf("%0#{M}b %d", a,i+1) }
f = ->(x,y){ ($bx[y] ^ $bx[x-1]) == $bs[y] - $bs[x-1] }
i = 1; j = 1
ans = 0
while j <= N+1
  if f.call(i,j)
    j += 1; next
  end
  
  #p [i,j]
  while true
    ans += (j-i)
    i += 1
    break if f.call(i,j) || i >= j
  end
  #p [i,j,ans]
end
p ans

Measured memory_bytes: 20264
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int n = sc.nextInt();
			
			HashMap<Integer, Integer> map = new HashMap<>();
			long sum = 0;
			for(int i = 0 ; i < n ; i++ ) {
				int a = sc.nextInt();
				
				int count = 0;
				if ( map.containsKey(a)) {
					count = map.get(a);
				}
				count++;
				
				map.put(a, count);
				
				sum += a;
			}
			
			showMap(map);
			
			int q = sc.nextInt();
			
			for(int i = 0 ; i < q ; i++ ) {
				int b = sc.nextInt();
				int c = sc.nextInt();
				
				if ( map.containsKey(b)) {
					
					int count = map.remove(b);
					int diff = c - b;
					
					sum += diff * count;
					
					int cCount = 0;
					if ( map.containsKey(c)) {
						cCount = map.get(c);
					}
					cCount += count;
					map.put(c, cCount);
//					map.remove(b);
					
					showMap(map);
				}

				System.out.println(sum);

			}
			
				
		}
	}
	
	public static void showMap(Map<Integer, Integer> map) {
		
//		for(int i : map.keySet()) {
//			System.out.println("## " + i + ":" + map.get(i));
//		}
	}

}

Measured memory_bytes: 65224
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  //
  ll n;
  cin >> n;
  REP(x, 1, n + 1) {
    if (floor(x * 1.08) == n) {
      cout << x << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define ALL(n) begin(n),end(n)

#define SENTINEL 2000000000
#define NIL -1
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
static const int MAX = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int INFTY = (1<<21);

int n,M[MAX][MAX];

//primのアルゴリズム
int prim(){
    int color[MAX],d[MAX],p[MAX];
    int minv;
    for (int u = 0; u < n; u++)
    {
        color[u] = WHITE;
        d[u] = INFTY;
        p[u] = -1;
    }
    d[0]=0; 
    while(1){
        minv = INFTY;
        int u= -1;
        for (int i = 0; i < n; i++)
        {
            if(color[i]!=BLACK&&d[i]<minv){
                minv = d[i];
                u = i;
            }
        }
        if (u == -1)break;
        color[u] = BLACK;
        for (int v = 0; v < n; v++)
        {
            if(color[v]!=BLACK&&M[u][v]!=INFTY){
                if(M[u][v]<d[v]){
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
            
        }  
    }
    int sum = 0;
    for (int  i = 0; i < n; i++)
    {
        if(p[i]!=-1){
            sum += M[i][p[i]];
        }
    }
    return sum;
}

int main(){
    cin >> n;
    REP(i,n){REP(j,n){
        int e;
        cin >> e;
        M[i][j] = (e ==-1)?INFTY:e;    
        }
    }
    cout << prim() << endl;

    return 0;
}


Measured memory_bytes: 3232
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		final int N = 9;
		Scanner in = new Scanner(System.in);

		while(in.hasNext()) {
			int n = in.nextInt();
			int ans = 0;
			for(int a=0;a<=N;a++) {
				for(int b=0;b<=N;b++) {
					for(int c=0;c<=N;c++) {
						for(int d=0;d<=N;d++) {
							if(a+b+c+d == n) ans++;
						}
					}
				}
			}
			System.out.printf("%d\n", ans);
		}
	}
}

Measured memory_bytes: 26824
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; ll k;
	cin >> n >> k;
	vector<ll> a(n);
	for( auto &temp : a ) cin >> temp;
	ll ans = 0;
	for( int d = 40; d >= -1; --d ){
		// d: 分岐点
		if( d >= 0 && !(k & (1LL<<d)) ) continue;
		ll sum = 0;
		for( int e = 40; e >= 0; --e ){
			// e: どの場所を見ているか
			// f: その場所のフラグ
			ll f = (1LL<<e);
			ll cnt = 0;
			for( auto &b : a ) if( b & f) ++cnt;
			if( e > d ){
				if( k & f ) sum += (n-cnt) * f;
				else sum += cnt * f;
			} else if( e == d ){
				sum += cnt * f;
			} else {
				sum += max(cnt, n-cnt) * f;
			}
		}
		ans = max(sum, ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define int long long
#define fill(x, v) memset(x, v, sizeof(x))
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define ios std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
/*
std::cout << std::setprecision(9) << f << '\n';//3.141590000;
map<char,int>::reverse_iterator rit;
for(rit = mp.rbegin(); rit!=mp.rend(); rit++)
*/
int n, k;
int dp[100000 + 10];
int arr[120];
bool winner(int s)
{
    if (dp[s] != -1)
        return dp[s];
    for (int i = 0; i < n; i++)
    {
        if (s >= arr[i] && !winner(s - arr[i]))
            return dp[s] = 1;
    }
    return dp[s] = 0;
}
int32_t main()
{
    ios;
    fill(dp, -1);
    dp[0] = 0;
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    if (winner(k))
        cout << "First" << endl;
    else
        cout << "Second" << endl;
}


Measured memory_bytes: 4224
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops"
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define MOD 998244353
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll n , a[maxN];
void solve(){
	cin>> n ;
	for(ll i=0;i<n ;i++)cin>>a[i];

	ll ans =0 ; 
	for(ll i=1;i<n ;i++){
		ans += max(0LL , a[i-1]-a[i]);
		a[i] += max(0LL , a[i-1]-a[i]);
	}
	cout<<ans<<endl;
}

int main(){
	//mahakal();
	fast;
	ll t =1 ;
	//cin>> t ; 
	while(t--)solve();
	//cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
	return 0;
}

Measured memory_bytes: 5200
#include <iostream>
#include <numeric>

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

int main() {
  int n, m;
  std::cin >> n >> m;
  int a[m];
  rep(i, m) std::cin >> a[i];

  int sum = std::accumulate(a, a + m, 0);
  int ans = n - sum;

  if (ans < 0) {
    std::cout << -1 << '\n';
  } else {
    std::cout << ans << '\n';
  }

  return 0;
}


Measured memory_bytes: 3676
#include <stdio.h>
int main(void){
	int a,b,c;
	int div,num;
	scanf("%d %d %d",&a,&b,&c);
	div=a;
	num=0;
	while(div<=b){
		if(c % div == 0){
			num++;
		}
		div++;
	}
	printf("%d\n",num);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define f(I, a, b) for (int I = a; I <= b; I++) 
using namespace std;

int main() {
	int N;
    cin >> N;
  	int a[N], b[N], c[N];
  	f(i, 0, N-1) cin >> a[i] >> b[i]>>c[i];
  	int dp[N+1][3] = {};
  	
  	f(i, 0, N-1){
      f(j, 0, 2) {
        if (j == 0){ 
          dp[i+1][1] = max(dp[i+1][1], dp[i][j] + b[i]);
          dp[i+1][2] = max(dp[i+1][2], dp[i][j] + c[i]);
        } else if (j == 1){
          dp[i+1][0] = max(dp[i+1][0], dp[i][j] + a[i]);
          dp[i+1][2] = max(dp[i+1][2], dp[i][j] + c[i]);
        } else if (j == 2) {
          dp[i+1][0] = max(dp[i+1][0], dp[i][j] + a[i]);
          dp[i+1][1] = max(dp[i+1][1], dp[i][j] + b[i]);
        }
      }
    }
  	int ans;
    ans = max(dp[N][0], max(dp[N][1], dp[N][2]));
      cout << ans <<endl;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    int counter[N];
    fill(counter, counter + N, 0);
    for(int i = 0; i < M; i++){
        int start, goal;
        cin >> start >> goal;
        counter[start - 1]++;
        counter[goal - 1]++;
    }
    for(int i = 0; i < N; i++){
        cout << counter[i] << endl;
    }
}


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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll n,y;
    cin >> n >> y;
    for(int i=0;i<=y/10000;i++){
        for(int j=0;j<=(y-i*10000)/5000;j++){
            ll x=(y-(i*10000+j*5000))/1000;
            if(i+j+x==n){
                cout << i << " " << j << " " << x << endl;
                return 0;
            }
        }
    }
    
    printf("-1 -1 -1\n");
    
    return 0;
}











Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int N = S.length();
        String A = S.substring(0, N/2);
        String B = S.substring(((N+3)/2)-1, N);
        if(A.equals(B)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
    }
}


Measured memory_bytes: 35612
#include <iostream>
using namespace std;
int binary_search(int ilow,int ihigh,int *s,int t);
int main(){
  int n;
  int q;
  int s[100000];
  int t;
  int cnt = 0;
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> s[i];
  }
  cin >> q;
  for(int i = 0;i < q;i++){
    cin >> t;
    cnt += binary_search(0,n - 1,s,t);
  }
  cout << cnt << endl;
  return (0);
}
int binary_search(int ilow,int ihigh,int *s,int t){
  int imid = (ilow + ihigh) / 2;
  int cnt = 0;
  if(ilow > ihigh)return(0);
  if(s[imid] < t){
    cnt = binary_search(imid + 1,ihigh,s,t);
  }else if(s[imid] == t){
    return 1;
  }else{
    cnt = binary_search(ilow,imid - 1,s,t);
  }
  return cnt;
}

Measured memory_bytes: 1548
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final String S = sc.next();
			
			System.out.println(S.substring(0, N / 2).equals(S.substring(N / 2)) ? "Yes" : "No");
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 22740
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        int k,n; cin >>  k >> n;
        vll a(n);
        ll sum = 0;
        for(int i = 0; i<n; i++){
            cin >> a[i];
            sum+=a[i];
        }
        ll mx = 0;
        ll prev = 0;
        for(int i =0; i<n; i++){
            mx = max(mx, abs(prev-a[i]));
            prev = a[i];
        }
        mx = max(mx, k - a.back()+a[0]);
        cout<<k-mx<<endl;


return 0;
}



Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

public class Main{
	
	static long mod=(long)1e9+7;
	
	public static void main(String[] args) throws IOException {
		Writer out=new Writer(System.out);
		Reader in=new Reader(System.in);
		int ts=1;
		
		outer: while(ts-->0) {	
			int n=in.nextInt();
			int m=in.nextInt();
			int a[]=in.readArray(n);
			sort(a);
			long total_votes=0;
			for(int i: a) total_votes+=i;
			for(int i=n-1; i>=n-m; i--) {
				if(4*m*a[i]<total_votes) {
					out.println("No");
					continue outer;
				}
			}
			out.println("Yes");
		}
		out.close();		
		
	}

	static boolean tri(int a, int b, int c) {
		if(c<a+b && c>abs(a-b)) return true;
		return false;
	}
	
	
/*********************************** UTILITY CODE BELOW **************************************/	
		
	static int abs(int a) {
		return a>0 ? a : -a;
	}
	
	static int max(int a, int b) {
		return a>b ? a : b;
	}
	
	static int pow(int n, int m) {
		if(m==0) return 1;
		int temp=pow(n,m/2);
		long res=(((long)temp*temp)%mod);
		if(m%2==0) return (int)res;
		return (int)((res*n)%mod);
	}
	
	static class Pair{
		int u, v;
		
		Pair(int u, int v){this.u=u; this.v=v;}
		
		static void sort(Pair [] coll) {		
			List<Pair> al=new ArrayList<>(Arrays.asList(coll));
			Collections.sort(al,new Comparator<Pair>() {
				public int compare(Pair p1, Pair p2) {
					return p1.u-p2.u;
				}	
			});
			for(int i=0; i<al.size(); i++) {
				coll[i]=al.get(i);
			}
		}
		
	}
	
	static void sort(int[] a) {
		ArrayList<Integer> list=new ArrayList<>();
		for (int i:a) list.add(i);
		Collections.sort(list);
		for (int i=0; i<a.length; i++) a[i]=list.get(i);
	}
	
	static void sort(long a[]) {
		ArrayList<Long> list=new ArrayList<>();
		for(long i: a) list.add(i);
		Collections.sort(list);
		for(int i=0; i<a.length; i++) a[i]=list.get(i);
	}
	
	static int [] array(int n, int value) {	
		int a[]=new int[n];
		for(int i=0; i<n; i++) a[i]=value;
		return a;
	}
	
	static class Reader{
		
		BufferedReader br;
		StringTokenizer to;
		
		Reader(InputStream stream){
			br=new BufferedReader(new InputStreamReader(stream));
			to=new StringTokenizer("");
		}
		
		String next() {
			while(!to.hasMoreTokens()) {
				try {
					to=new StringTokenizer(br.readLine());	
				}catch(IOException e) {}
				
			}
			return to.nextToken();
			
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0; i<n ;i++) a[i]=nextInt();
			return a;
		}
		long [] readLongArray(int n) {
			long a[]=new long[n];
			for(int i=0; i<n ;i++) a[i]=nextLong();
			return a;
		}
		
	}
	
	static class Writer extends PrintWriter{
		Writer(OutputStream stream){
			super(stream);
		}
		void println(int [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
		void println(long [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
	}
	
}

Measured memory_bytes: 32956
#include <bits/stdc++.h>
using namespace std;
struct point{double x;double y;};
int i,j,k,count1=0,count2=0;

int main(void){
    int n,ans;
    string s,t;
    cin>>n>>s>>t;
    ans=0;
    for(i=1;i<=n;i++){
        if(s.substr(n-i,i)==t.substr(0,i)){
            ans=i;
        }
    }
    cout<<2*n-ans<<endl;
}

Measured memory_bytes: 256
s = str(input())
n = int(input())
k = ord("z")
a = [0]*len(s)
for i in range(len(s)):
    a[i] = ord(s[i])
for i in range(len(s)):
    if a[i] == ord("a"):
        continue
    if n>=k+1-a[i]:
        n = n-k-1+a[i]
        a[i] = ord("a")
    
    if n<=0:
        break
if n>0:
    a[-1] += n%26
ans = ""
for i in range(len(s)):
    ans += chr(a[i])
print(ans)


Measured memory_bytes: 4212
#077-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
a=IL()
b=IL()
c=IL()
a.sort()
b.sort()
c.sort()
bc=[0]*(n+1)
j=0
for i in range(n):
    while j<n:
        if c[j]>b[i]:
            break
        else:
            j+=1
    bc[i]=n-j

ans=0
for i in range(2,n+1):
    bc[-i-1]+=bc[-i]

j=0
for i in range(n):
    while j<n:
        if b[j]>a[i]:
            break
        else:   
            j+=1
    ans+=bc[j]

print(ans)

Measured memory_bytes: 24052
//Pranet Verma
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000000 + 7;
long long pwr[404][404];
int a[404], b[404];
int DP[404][404];
int dp(int n, int c) {
    if (n == 0) {
        return c == 0;
    }
    if (DP[n][c] != -1) {
        return DP[n][c];
    }
    long long ans = 0;
    for (int k = 0; k <= c; ++k) {
        ans += dp(n - 1, c - k) * (pwr[b[n]][k] - pwr[a[n] - 1][k]) % MOD;
        ans %= MOD;
    }
    if (ans < 0) {
        ans += MOD;
    }
    return DP[n][c] = ans;
}
int main() {
    memset(DP, -1, sizeof DP);
    for (int p = 1; p <= 400; ++p) {
        pwr[p][0] = 1;
        for (int i = 1; i <= 400; ++i) {
            pwr[p][i] = pwr[p][i - 1] * p;
            pwr[p][i] %= MOD;
        }   
    }
    for (int i = 0; i <= 400; ++i) {
        for (int p = 1; p <= 400; ++p) {
            pwr[p][i] += pwr[p - 1][i];
            pwr[p][i] %= MOD;
        }
    }
    int n, c;
    cin >> n >> c;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    } 
    for (int i = 1; i <= n; ++i) {
        cin >> b[i];
    } 
    cout << dp(n, c);
}

Measured memory_bytes: 2176
#include <stdio.h>
#define N 100000
int main(void){
    int n;
    int i=0,cnt=0;
    int a[N];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    i=0;
    while(a[i]!=2){
        if(cnt==n)break;
        i=a[i]-1;
        cnt++;
    }
        if(a[i]==2)printf("%d\n",cnt+1);
    else printf("-1\n");
    return 0;
}


Measured memory_bytes: 512