akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
typedef long long ll;
vector<P> ans1;
vector<P> ans2;
const int dx[2] = {1, 0};
const int dy[2] = {0, 1};


//void dfs(int y, int x, vector<vector<bool>> &visited,  vector<vector<int>> &grid){
//  visited[y][x] = true;
//  if(grid[y][x] % 2 == 0){
//    dfs()
//  }
//  vector<int> cond;
//  for (int i = 0; i < 5; i++){
//    int ny = y + dy[i], nx = x + dx[i];
//    if(ny < 0 || h <= ny || nx < 0 || w <= nx){
//      continue;
//    }
//  }
//}

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> grid(h, vector<int>(w));
  vector<P> ans1;
  vector<P> ans2;
  rep(i, h){
    rep(j, w){
      cin >> grid[i][j];
    }
  }
  rep(i, h){
    rep(j, w){
      if(grid[i][j] % 2 == 0)continue;
      vector<bool> cond; 
      rep(k, 2){
        int ny = i + dy[k];
        int nx = j + dx[k];
        if(ny < 0 || h <= ny || nx < 0 || w <= nx)continue;
        if(grid[ny][nx] % 2 == 1){
          ans1.push_back({i + 1, j + 1});
          ans2.push_back({ny + 1, nx + 1});
          grid[i][j]--;
          grid[ny][nx]++;
          cond.push_back(false);
          break;
        }
      }
      if(cond.size() == 0){
        if(j == w-1 & i != h-1){
          grid[i][j]--;
          grid[i + 1][j]++;
          ans1.push_back({i + 1, j + 1});
          ans2.push_back({i + 2, j + 1});
        }else if (j != w-1){
          grid[i][j]--;
          grid[i][j+1]++;
          ans1.push_back({i + 1, j + 1});
          ans2.push_back({i + 1, j + 2});
        }
      }
    }
  }
  cout << ans1.size() << endl;
  rep(i, ans1.size()){
    cout << ans1[i].first << " " << ans1[i].second << " " << ans2[i].first << " " << ans2[i].second << endl;
  }
}

Measured memory_bytes: 6252
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
string conv(string s){
  string v = "kstnhmyrw";
  map<char, string> m;
  m['T'] = "a";
  m['L'] = "i";
  m['U'] = "u";
  m['R'] = "e";
  m['D'] = "o";
  if(s == "0U") return "nn";
  string res = "";
  if(s[0] != '1' && s[0] != '0') res += v[s[0] - '0'  - 2];
  if(s[0] == '0') res += "w";
  res +=  m[s[1]];
  return res;
}


int main(){
  string s;
  while(cin>>s){
    REP(i, s.size()){
      string t = s.substr(i, 2);
      i += 1;
      cout<<conv(t);
    }
    cout<<endl;
  }
  return 0;
}

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

int main() {
  int n;
  cin>>n;
  int A[n];
  int m=1000000000,M=0;
  for (int i = 0; i < n; i++) {
    cin>>A[i];
    if(m>A[i])m=A[i];
    if(M<A[i])M=A[i];
  }
  cout<<M-m<<endl;

}


Measured memory_bytes: 256
function prime(max){
   var arr=[];
   for(var i=0;i<=max;i++)arr[i]=i;
   arr[0]=false;
   arr[1]=false;
   var sqrt=Math.floor(Math.sqrt(max));
   for(var i=2;i<=sqrt;i++){
      if(arr[i]==false)continue;
         for(var j=i+i;j<=max;j+=i){
            arr[j]=false;
         }
   }
   var result=[];
   for(var i=0;i<=max;i++){
      if(arr[i]!==false)result.push(arr[i]);
   }
   return result;
}
var pr=prime(1000000);

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
for(var I=0;I<Arr.length;I++){
   var np=Arr[I].split(" ").map(Number);
   var n=np[0];
   var p=np[1];
   if(n==-1 && p==-1)break;
   var arr=[];
   for(var i=0;i<pr.length;i++){
      if(pr[i]>n){
         arr.push(pr[i]);
         if(arr.length>=50)break;
      }
   }
   var s=[];
   var obj={};
   for(var i=0;i<arr.length;i++){
      for(var j=0;j<arr.length;j++){
         if(obj.hasOwnProperty(j+" "+i))continue;
         obj[i+" "+j]=true;
         s.push(arr[i]+arr[j]);
      }
   }
   s.sort(function(a,b){return a-b;});
   console.log(s[p-1]);
}

Measured memory_bytes: 29584
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const ll inf = 1e16 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
string s;

string solve() {
    int st = 0;
    int a = 0;

    for (int i = 0; i < n; i++) {
        if (s[i] == '(') st++;
        else if (st > 0) st--;
        else a++;
    }

    string res = "";
    for (int i = 0; i < a; i++) res += '(';
    res += s;
    for (int i = 0; i < st; i++) res += ')';
    return res;
}

void input() {
    cin >> n >> s;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;;
}


Measured memory_bytes: 256
#define scanf_s scanf

#include <string>
#include <stdio.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <iostream>
using namespace std;
#define PI 3.14159265358
#define _rag(x) (x) * (PI / 180)
void fractale(int n, double p1x, double p1y, double p2x, double p2y)
{
	if (n > 0) {
		double sx = 0, sy = 0, ux = 0, uy = 0, tx = 0, ty = 0;
		sx = (2 * p1x + p2x) / 3; sy = (2 * p1y + p2y) / 3;
		tx = (p1x + 2 * p2x) / 3; ty = (p1y + 2 * p2y) / 3;
		ux = (tx - sx) * cos(_rag(60.0)) - (ty - sy) * sin(_rag(60.0)) + sx;
		uy = (tx - sx) * sin(_rag(60.0)) + (ty - sy) * cos(_rag(60.0)) + sy;

		fractale(n - 1, p1x, p1y, sx, sy);//1
		printf("%f %f\n", sx, sy);

		fractale(n - 1, sx, sy, ux, uy);//2
		printf("%f %f\n", ux, uy);

		fractale(n - 1, ux, uy, tx, ty);//3
		printf("%f %f\n", tx, ty);
		fractale(n - 1, tx, ty, p2x, p2y);//4	
	}
}
int main(void)
{
	int n;
	scanf_s("%d", &n);
	printf("%f %f\n", 0.0, 0.0);
	fractale(n, 0.0, 0.0, 100.0, 0.0);
	printf("%f %f\n", 100.0, 0.0);

}

Measured memory_bytes: 1220
#include <iostream>
#include <algorithm>
#include <vector>
#include <assert.h>

using namespace std;

#define MAXN 21
long long MM =(1e9+7);


int A[MAXN+1][MAXN+1];


int number_1_bit(int set) {
  int count = 0;
  while (set != 0) {
    count += (set & 1);
    set = set >> 1;
  }

  return count;
}

int main() {
  // task O
  assert( (1 << 1) == 2);

  assert( number_1_bit(7) == 3 );
  assert( number_1_bit(8) == 1 );
  assert( number_1_bit(0) == 0 );
  assert( number_1_bit(0b101010100) == 4 );
  assert( number_1_bit(0b001010100) == 3 );

  int N;
  cin >> N;
  assert(N > 0 && N <= 21);
  // count from 0 -> N-1
  for(auto i=0;i<N; i++) {
    for(auto j=0;j<N; j++) cin >> A[i][j];
  }

  vector<int> F( (1<<N) + 1, 0);

  F[0] = 1; // there is a way to match two empty sets

  for (int subset = 1; subset < (1 << N); subset++) {
    auto size = number_1_bit(subset);
    // matching subset (women) with the set {0 .. |subset|-1} (men)

    for (auto i=0; i<N; i++) { // consider matching (size-1)-th man <-> i-th bit woman
      if(  subset & (1<<i) ) { // in the subset
        if ( A[size-1][ i ] == 1) {  // a match, consider a sub problem, disable i-th bit
          auto sub = subset - (1<<i);
          F[subset] = (F[subset] + F[sub]) % MM;
        }
      }
    }
  }

  cout << F[ (1<<N) - 1] << endl;
  return 0;
}


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

void solve(long long a, long long b, long long c, long long d)
{

    ll ans = a * c;
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);
    cout << ans << endl;
}

signed main()
{
    long long a;
    scanf("%lld", &a);
    long long b;
    scanf("%lld", &b);
    long long c;
    scanf("%lld", &c);
    long long d;
    scanf("%lld", &d);
    solve(a, b, c, d);
    return 0;
}


Measured memory_bytes: 3756
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n, k = _ia()
    ans = set()
    for _ in range(k):
        _ = _i()
        ans |= set(_ia())
    return n - len(ans)


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 67464
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

template <class T>
void cout_vec2(const vector<vector<T>> &vec){
  rep(i,vec.size()){
    rep(j,vec[i].size()){
      cout<<vec[i][j]<<' ';
    }
    cout<<endl;
  }
}

typedef pair<ll,ll> P;
const ll mod=998244353;
const ll inf=1e15;

template <class T>
T mult(T n,T m){
	if(m==0) return 1;
	if(m==1){
		return n%mod;
	}else if(m%2==0){
		T t=mult(n,m/2);
		return (t*t)%mod;
	}else{
		T t=mult(n,m-1);
		return (t*n)%mod;
	}
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin>>n;
  vector<ll> d(n);
  map<ll,ll> cnt;
  rep(i,n){
    cin>>d[i];
    cnt[d[i]]++;
  }
  if(d[0]!=0){
    cout<<0<<endl;
    return 0;
  }
  ll ans=1;
  ll now=0;
  ll pre=1;
  for(auto itr:cnt){
    if(itr.fi!=now){
      cout<<0<<endl;
      return 0;
    }
    if(itr.fi==0 && itr.se>1){
      cout<<0<<endl;
      return 0;
    }else{
      ans*=mult(pre,itr.se);
      ans%=mod;
      pre=itr.se;
    }
    now++;
  }
  cout<<ans<<endl;
}

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

#define all(x) (x).begin(),(x).end()
#define isz(x) (int)(x).size()

template<class C, class X>
int lowpos(const C& c, X x) {
    return int(std::lower_bound(all(c), x) - c.begin());
}

template<class C, class X>
int uppos(const C& c, X x) {
    return int(std::upper_bound(all(c), x) - c.begin());
}

using pii = std::pair<int,int>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;

struct Edge { int u, v; };

const int MAX = (int)1e9;

const bool debug = 0;

std::ostream& operator<<(std::ostream& os, Edge e) {
    return os << "{" << e.u << ", " << e.v << "}";
}

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    os << "{";
    for (int i = 0; i < isz(v); i++) {
        if (i > 0) os << ", ";
        os << v[i];
    }
    return os << "}";
}

#define watch(x) std::cerr << #x << " = " << x
#define watchln(x) watch(x) << std::endl
#define watchsp(x) watch(x) << " "
#define cerr cerr && debug && std::cerr
int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    std::vector<pii> arr(n);
    for (auto &it : arr) {
        scanf("%d %d", &it.first, &it.second);
    }
    arr.push_back(pii{0,0});
    arr.push_back(pii{MAX+1,0});
    std::sort(all(arr));
    // transform to xor:
    vi d;
    for (int i = 1; i < isz(arr); i++) {
        d.push_back(arr[i].second ^ arr[i-1].second);
    }
    watchln(d);
    // building graph:
    std::vector<Edge> edges(m);
    vvi adj(isz(d));
    for (int i = 0; i < m; i++) {
        int l, r;
        scanf("%d %d", &l, &r);
        int u = lowpos(arr, pii(l, 0))-1;
        int v = uppos(arr, pii(r,1))-1;
        assert(0 <= u && u <= v && v < isz(d));
        watchsp(l); watchln(r);
        watchsp(u); watchln(v);
        edges[i] = Edge{u,v};
        if (u < v) {
            adj[u].push_back(i);
            adj[v].push_back(i);
        }
    }
    vi take(m), color(isz(d));
    std::function<void(int,int,int)> dfs = [&](int u, int p, int id) {
        std::cerr << "dfs(" << u << "," << p << "," << id << ")" << std::endl;
        if (color[u] != 0) return;
        color[u] = 1;
        watchln(adj[u]);
        for (int eid : adj[u]) {
            const auto & e = edges[eid];
            int v = e.u + e.v - u;
            if (v == p) continue;
            if (color[v] == 0) {
                dfs(v,u,eid);
            }
        }
        if (d[u] == 1 && p >= 0) {
            std::cerr << "switch state for u = " << u << ", p = " << p << "with "; watchln(edges[id]);
            take[id] = 1;
            d[u] ^= 1;
            d[p] ^= 1;
            watchln(d);
        }
        color[u] = 2;
    };
    bool answ = true;
    for (int u = 0; u < isz(d); u++) {
        if (color[u] == 0) {
            dfs(u,-1,-1);
        }
        answ = answ && (d[u] == 0);
    }
    if (!answ) {
        printf("-1\n");
    } else {
        vi k;
        for (int i = 0; i < m; i++) {
            if (take[i]) {
                k.push_back(i+1);
            }
        }
        printf("%d\n", isz(k));
        for (int it : k) printf("%d ", it);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 18032
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
typedef pair<ll,ll> l_l;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back


ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll n;cin>>n;
    ll s[n+1],l[n+1],p[n+1];
    rep(i,1,n){
        cin>>s[i]>>l[i]>>p[i];
    }
    ll m;cin>>m;
    ll w[m];
    rep(i,0,m-1){
        cin>>w[i];
    }
    
    ll dp[n+1][410];
    rep(i,0,n){
        rep(j,0,400){
            dp[i][j]=-1;
        }
        dp[i][0]=0;
    }
    ll maxi;
    rep(i,1,n){
        rep(j,1,400){
            if(j-s[i]<0){
                dp[i][j]=dp[i-1][j];
            }else{
                maxi=-1;
                rep(k,max(0,j-l[i]),j-s[i]){
                    maxi=max(maxi,dp[i][k]);
                }
                if(maxi==-1){
                    dp[i][j]=dp[i-1][j];
                }else{
                    dp[i][j]=max(maxi+p[i],dp[i-1][j]);
                }
            }
        }
    }
    /*
    rep(i,0,n){
        rep(j,0,15){
            cout<<dp[i][j]<<' ';
        }
        cout<<endl;
    }
     */
    bool b=false;
    ll ans[m];
    rep(i,0,m-1){
        if(dp[n][w[i]]==-1){
            b=true;
            break;
        }else{
            ans[i]=dp[n][w[i]];
        }
    }
    if(b){
        cout<<-1<<endl;
    }else{
        rep(i,0,m-1){
            cout<<ans[i]<<endl;
        }
    }
    
    return 0;
}




Measured memory_bytes: 4312
/*******************************************c#
*********************************************/
using System; //Console, IComparable
using System.IO; //StreamWriter 
using System.Linq; //Select(), Where(), OrderBy(), Count()
using System.Collections.Generic; //List<T>
using System.Reflection; //PropertyInfo[], GetProperties[]
using static System.Console; 
using static NNN.CInput;

namespace NNN {
    public class CRun{
        private static class gv{
            public static double L = 0.0;
        }
    
        public void build(){            
            gv.L = _double;
        }
    
        public void solve(){ StreamWriter so = new StreamWriter(Console.OpenStandardOutput());
            var side = gv.L/3;
            var ans = Math.Pow(side,3);
            WriteLine(ans.ToString("F12"));
            
        }
    }

    class Program { 
        static void Main() { 
            var run = new CRun();
            run.build();
            run.solve();
        } 
    }

    public static class CInput{
        public static string _string{get{return Console.ReadLine();}}
        public static string[] _stringa{get{return (Console.ReadLine().Split());}}
        public static int _int{get{return int.Parse(Console.ReadLine());}}
        public static int[] _inta{get{return Console.ReadLine().Split().Select(x=>int.Parse(x)).ToArray();}}
        public static double _double{get{return double.Parse(Console.ReadLine());}}
        public static double[] _doublea{get{return Console.ReadLine().Split().Select(x=>double.Parse(x)).ToArray();}}
        public static long _long{get{return long.Parse(Console.ReadLine());}}
        public static long[] _longa{get{return Console.ReadLine().Split().Select(x=>long.Parse(x)).ToArray();}}    
    }
}


Measured memory_bytes: 11220
a,b,c,d = map(int,input().split())
res1 = a*c
res2 = a*d
res3 = b*c
res4 = b*d

x =[]
y =[]
z =[]
l =[]

x.append(res1)
y.append(res2)
z.append(res3)
l.append(res4)

res0 = x+y+z+l

m = max(res0)

print(m)



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


public class Main {

    public static void main(String[] args) {
        new Main().run();
    }

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));;
    PrintWriter out = new PrintWriter(System.out);
    StringTokenizer tok = new StringTokenizer("");

    void run() {
        try {
            long timeStart = System.currentTimeMillis();
            solve();

            out.close();

            long timeEnd = System.currentTimeMillis();
            System.err.println("Time = " + (timeEnd - timeStart));
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    String readLine() throws IOException {
        return in.readLine();
    }

    String delimiter = " ";

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine) return null;

            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken(delimiter);
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }


    void solve() throws IOException {
        int n = readInt(), m = readInt(), from, to, s;
        int[] h = new int[n];
        for (int i = 0; i < n; i++)
            h[i] = readInt();
        List<Integer>[] g;
        g = new List[n];
        for (int v = 0; v < n; ++v)
            g[v] = new ArrayList<>();
        for (int e = 0; e < m; ++e){
            from = readInt() - 1;
            to = readInt() - 1;
            g[from].add(to);
            g[to].add(from);
        }
        s = 0;
        boolean f;
        for (int i = 0; i < n; i++){
            f = true;
            for (int j:g[i]){
                if (h[j] >= h[i]){
                    f = false;
                    break;
                }
            }
            if (f)
                s++;
        }
        out.println(s);

    }
}

Measured memory_bytes: 72436
#include <bits/stdc++.h> 
#include <time.h>
#define F(i,a,b) for(long long i=a;i<=(b);++i)
#define dF(i,a,b) for(long long i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 1e5+10;
const int N = 1e5+10;
const int E = 1e5+10;  
ll n,m,k,x;
bool vis[maxn];
int a[maxn];
struct node{
	int id,hig;
}h[maxn];
bool cmp(node A,node B){
	return A.hig<B.hig;
}
vector<int> g[maxn];

bool check(int x){
	for(int i=0;i<g[x].size();i++){
		if(a[x]<=a[g[x][i]]){
			return false;
		}
	}
	for(int i=0;i<g[x].size();i++){
		vis[g[x][i]] = 1;
	}
	return true;
}

int main(){
	cin>>n>>m;
	F(i,1,n){
		cin>>h[i].hig;
		a[i] = h[i].hig;
		h[i].id = i;
	}
	int u,v;
	F(i,1,m){
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	sort(h+1,h+1+n,cmp);
	int ans = 0;
	F(i,1,n){
		if(!vis[h[i].id]&&check(h[i].id)){
			vis[h[i].id] = 1;
			ans++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 10032
fn getline() -> String{
    let mut __ret = String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}

fn main() {
    let s = getline();
    let a:Vec<_> = s.trim().split(' ').collect();
    let (h,w):(i32,i32) = (a[0].parse().unwrap(), a[1].parse().unwrap());
    for i in 0..w+2 {
        print!("#");
    }
    println!("");
    for i in 0..h {
        let s = getline().to_string();
        // s = s.slice_chars(0,s.count()-1);
        println!("{}{}{}","#",s.trim(),"#");
    }
    for i in 0..w+2 {
        print!("#");
    }
    println!("");
}


Measured memory_bytes: 4352
# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    MOD = 10**9 + 7

    # もしN = K なら全部選択しないといけないので、
    # 全部掛け算して返す
    if N == K:
        ans = 1
        for a in A:
            ans = (ans * a) % MOD
        print(ans)
        return

    Ap = [] # 正の数だけ入っている
    Am = [] # 負の数だけ入っている.値は絶対値で入れる
    has0 = False # 0がAの中にあるか
    for a in A:
        if a == 0:
            has0 = True
        elif a > 0:
            Ap.append(a)
        else:
            Am.append(-a)

    # それぞれを絶対値の大きい順に並べる
    Ap.sort(reverse=True)
    Am.sort(reverse=True)

    ip = 0
    im = 0
    lp = len(Ap)
    lm = len(Am)

    # もし0でない数がK個未満しかない場合、0を必ず選ばないといけないので
    # 答えは0になる
    if lp + lm < K:
        print(0)
        return

    # # 正の数+負の数=K かつ負の数が奇数のとき、0を選んだほうがマシなので、
    # # 答えは0になる
    # if lp + lm == K and lm % 2 == 1:
    #     print(0)
    #     return
    # もしKが奇数のときで、かつ正の数が1個もない時
    if K % 2 == 1 and lp == 0:
        # 0があるなら0にする
        if has0:
            print(0)
            return
        # 0がない場合は、負の数の中から絶対値の小さいものを選ぶ
        else:
            ans = 1
            for a in Am[-K:]:
                ans = (ans * a) % MOD
            print(MOD - ans)
            return

    # 戦略: Aの中から絶対値の大きい順に選んでいく
    ans = 1
    for i in range(K):
        x = None
        if ip == lp: # 正の数をこれ以上選べないのであれば負の数を選ぶ
            x = Am[im]
            im += 1
        elif im == lm: # 負の数をこれ以上選べないのであれば正の数を選ぶ
            x = Ap[ip]
            ip += 1
        # 正の数、負の数どちらも選べるのであれば、絶対値の大きいほうを選ぶ
        elif Am[im] < Ap[ip]:
            x = Ap[ip]
            ip += 1
        else:
            x = Am[im]
            im += 1
        # print(x)
        ans = ans * x % MOD

    # もし絶対値の大きい順で選んで、負の数を奇数個選んでいたとき
    if im % 2 == 1:
        # 選んだ中で一番小さい負の数を外して、まだ選んでない中で最も大きい正の数を入れるか、
        # 選んだ中で一番小さい正の数を外して、まだ選んでない中で最も（絶対値が）大きい負の数を入れるか選ぶ

        # これ以上0でない数がない場合は、0を選択して答えを0にするのが最大値になる
        if ip == lp and im == lm:
            print(0)
            return
        # 正の数をこれ以上選べない場合は負の数から選ぶ
        elif ip == lp:
            ans = ans * modinv(Ap[ip-1]) % MOD
            ans = ans * Am[im] % MOD
        # 負の数をこれ以上選べない場合は正の数から選ぶ
        # 正の数を1つも選んでないときも正の数から選ぶ
        elif im == lm or ip == 0:
            ans = ans * modinv(Am[im-1]) % MOD
            ans = ans * Ap[ip] % MOD
        # 正、負ともまだ選ぶ余裕がある場合
        else:
            # 一旦、選んだ中で一番小さい負の数と、選んだ中で一番小さい正の数を戻す（再度選べるようにする）
            ip -= 1
            ans = ans * modinv(Ap[ip]) % MOD
            im -= 1
            ans = ans * modinv(Am[im]) % MOD
            
            # 正、負のリストから、まだ選んでない中で絶対値が大きいもの2つを選び、その積の大きいほうを選ぶ
            a = Ap[ip] * Ap[ip+1]
            b = Am[im] * Am[im+1]
            # print(a, b)

            ans = ans * max(a, b) % MOD

    print(ans)

if __name__ == '__main__':
    main()

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000001)
#define MOD (1000000007)
#define PI (acos(-1))

int N,M,x[100010],y[100010];
int main(){
  cin >> N >> M;
  rep(i,M){
    cin >> x[i] >> y[i];
    x[i]--;y[i]--;
  }
  int num[100010];
  bool red[100010];
  rep(i,N){
    num[i]=1;
  }
  red[0]=1;

  rep(i,M){
    num[x[i]]--;
    num[y[i]]++;
    if(red[x[i]]==1)red[y[i]]=1;
    if(num[x[i]]==0)red[x[i]]=0;
  }
  int ans=0;
  rep(i,N){
    if(red[i])ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include <iomanip>
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long ll;
//#define INF 1000000000000 //10^12:極めて大きい値,∞
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    
    long n,sum;
    cin >> n;
    vector<long> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    sum = accumulate(a.begin(),a.end(),0l);
    sort(a.begin(),a.end());
    
    cout << a[0] << ' ' << a[n-1] << ' ' << sum << endl;
    return 0;
}


Measured memory_bytes: 3184
#include <iostream>
#include <algorithm>
#include <string>
#include <functional> 
#include <vector>
#include <numeric>
#include <stack>
#include <queue>
#include <utility>


using namespace std;

int main(){

    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];

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

    if(a[0]%2 == 0 && a[1]%2 == 0 && a[2]%2 == 0){
        cout << (a[2]-a[0])/2 + (a[2]-a[1])/2;
        return 0;
    }

    if(a[0]%2 == 1 && a[1]%2 == 1 && a[2]%2 == 1){
        cout << (a[2]-a[0])/2 + (a[2]-a[1])/2;
        return 0;
    }

    if((a[0]%2 == 1 && a[1]%2 == 0 && a[2]%2 == 1) || (a[0]%2 == 0 && a[1]%2 == 1 && a[2]%2 == 0)){
        a[0] += 1;
        a[2] += 1;
        sort(a.begin(),a.end());
        cout << (a[2]-a[0])/2 + (a[2]-a[1])/2 + 1;
        return 0;
    }


    if((a[0]%2 == 1 && a[1]%2 == 0 && a[2]%2 == 0) || (a[0]%2 == 0 && a[1]%2 == 1 && a[2]%2 == 1)){
        a[1] += 1;
        a[2] += 1;
        sort(a.begin(),a.end());
        cout << (a[2]-a[0])/2 + (a[2]-a[1])/2 + 1;
        return 0;
    }

    if((a[0]%2 == 0 && a[1]%2 == 0 && a[2]%2 == 1) || (a[0]%2 == 1 && a[1]%2 == 1 && a[2]%2 == 0)){
        cout << a[2] - a[1] + (a[1] - a[0])/2;
    }

    return 0;
}

Measured memory_bytes: 256
/*
sonu_verma1
*/
#include <bits/stdc++.h>
// For policy based data structure
/*#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> */
using namespace std;
/*using namespace __gnu_pbds; 
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set;*/
 
#define MD 1000000007
#define X first
#define Y second
#define pb push_back
#define debug(val, ch) cout <<val <<ch
#define FOR(i, st, en, ch) for(register int i = (st); i <= (en) ; i += (ch))
#define RFOR(i, st, en, ch) for(register int i = (st); i >= (en) ; i -= (ch))
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
 
typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<int, bool> pib;
typedef pair<bool, int> pbi;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
/*********************************************************************/
double fun(vector<double>&p,vector<vector<double>>&dp,int i,
	int n,int m)
{
	if(m==0)
		return 1;
	if(i==n)
	return 0;
	if(dp[i][m]!=-1)
		return dp[i][m];
	double ans=fun(p,dp,i+1,n,m)*(1-p[i])+fun(p,dp,i+1,n,m-1)*p[i];
	dp[i][m]=ans;
	return ans;
}
void test(int r)
{
	int n;
	cin>>n;
	vector<double>p(n);
	int i,j;
	for(i=0;i<n;i++)
		cin>>p[i];
	vector<vector<double>>dp(n,vector<double>(n/2+2,-1));
	cout<<setprecision(10)<<fun(p,dp,0,n,n/2+1)<<endl;
	

}
/***********************************************************************/
int main()
{
	fast();
    int t=1,r;
    // cin>>t;
    for(r=1;r<=t;r++)
        test(r);
    return 0;
}

Measured memory_bytes: 38912
#include<bits/stdc++.h>
#define ll long long
#define loop(n) for(ll i = 0; i<n; i++)
#define sort(a) sort(a.begin(), a.end())
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll n, count = 0, x; cin>>n;
    ll m = n+2;
    loop(n){
        cin>>x;
        if(m >= x) count++;
        m = min(x, m);
    }
    cout<<count<<"\n";
    return 0;
}

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

int main()
{
    int n;
    // N
    scanf("%d",&n);
    // a1..aN (=a[0]..a[n-1])
    std::array<unsigned int, 200000> arr;
    for (int i = 0; i < n; ++i) {
        scanf("%d",&arr[i]);
    }
    
    decltype(arr)::iterator itr = arr.begin();
    std::advance(itr, n);
    std::sort(arr.begin(), itr);
    
    bool result = true;
    for (int i = 0; i < n - 1; ++i) {
        if (arr[i] == arr[i+1]) {
            result = false;
            break;
        }
    }
    
    // 出力
    if (result) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
		#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
		#define endl "\n"

		using namespace std;
	
	int main() {	
		int a, b; cin >> a >> b;
		if (a == 1 && b != 1 || a > b && b != 1)
			cout << "Alice";
		else if (a == b)
			cout << "Draw";
		//else if (b == 1 && a != 1 || b > a)
		else
			cout << "Bob";
		return 0;
		}
	


Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c,d;
	int i,j,k;
	while(cin>>a>>b){
		c=a;
		d=b;
		while(d!=0){
			c%=d;
			swap(c,d);
		}
		a/=c;
		b/=c;
		d=a*b*c;
		cout<<c<<" "<<d<<endl;
	}
	return 0;
}
			

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define ll long long 
#define inf 1e17
#define f(i,a,b) for(i=a;i<b;i++)
ll m = 1e9+7;
using namespace std;
//cout<<setprecision(9)<<m/(1<<q);
//__builtin_popcount();
//next_permutation(abc.begin(), abc.end());
//(string(n, abc[0]);
//str.find(s);
//ll a[1000001];
ll umin(ll a,ll b)
{
  if(a<b)
    return a;return b;
}
/*string toBinary(ll n)
{
    string r;
    while(n!=0) {r=(n%2==0 ?"0":"1")+r; n/=2;}
    return r;
}*/
ll dp[10][1000001];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;cin >> n;double d;
	if(n&1)
		d = ((double)(n/2+1))/n;
	else
		d=(double)1/2;
	cout<< setprecision(9) << d;

	return 0;
}


Measured memory_bytes: 256
"""
n=1の時、山札とＹの初期手札が答え
n>=2の時、
・Ｘは得点の最大化を狙う
・Ｙは得点の最小化を狙う＝Ｘの邪魔をする
山札内の得点の最大化をできるカードをＸが選んでも、Ｙはそれを邪魔する動きをとるので、真に最大化すること(Xの狙いを達成すること)はできない
→選べるのはＹの初期値＆山札最後（Ｘがすべて取る）か、最後とその一つ手前の比較（Ｘが一枚残してすべて取る）のどちらかにするのがましな選択



"""


n,x,y = map(int, input().split())

a = list(map(int, input().split()))

if n == 1:
        print(abs(a[-1] - y))
else:
        print(max(abs(y-a[-1]), abs(a[-1] - a[-2])))

Measured memory_bytes: 3188
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans = 0
j = M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47332
object Main extends App {
  val Seq(n,q): Seq[Int] = io.StdIn.readLine().split(" ").map(_.toInt)
  val ds = new DisjointSets(n)

  (0 until q) foreach {_ =>
    io.StdIn.readLine().split(" ").map(_.toInt) match {
      case Array(0, x, y) => ds.union(x, y)
      case Array(1, x, y) => println(if (ds.same(x,y)) 1 else 0)
    }
  }
}

class DisjointSets(size: Int) {
  val sets: Array[Tree] = Array.tabulate(size)(make)
  def make(x: Int): Node = Node(x, 0)

  def union(x: Int, y: Int): Unit = {
    val i = find(x)
    val j = find(y)
    val rootX = sets(i)
    val rootY = sets(j)

    if (rootX.rank > rootY.rank) sets(j) = Node(i, rootY.rank)
    else sets(i) = Node(j, rootX.rank + (if (rootX.rank == rootY.rank) 1 else 0))
  }

  def find(x: Int): Int = sets(x) match {
    case Node(p, _) if x == p => x
    case Node(p, _) => {
      val i = find(p)
      sets(x) = Node(i, 0)
      i
    }
  }

  def same(x: Int, y: Int):Boolean = find(x) == find(y)

  sealed trait Tree {val rank: Int}
  case class Node(parent: Int, rank: Int) extends Tree
}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

unsigned long n,m;
string s;
//Write From this Line
unsigned GetDigit(unsigned num){
	unsigned digit=0;
	while(num!=0){
		num /= 10;
		digit++;
	}
	return digit;
}
const int mod = 1e9+7;
int main()
{
	cin >> n ;
	unsigned long ans = 0 ;
	if(n %2 == 1 ){
		cout << 0 << endl; 
		return 0;
	}
	else {
		for(unsigned long i = 10 ; i <= 1000000000000000000 ; i*=10){
			ans +=  (n / i ); 
		}
		for(unsigned long i = 5 ; i <= 1000000000000000000 ; i*= 5){
			for(unsigned long j = 10 ; i*j<= 1000000000000000000 ;j*=10){
				ans += ((n / (i * j) )+1 ) / 2;
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll N = 0,M;
  cin >> N >> M;
  rep(i,N+N-1){
    cout << M-N+1+i << " ";
  }
}


Measured memory_bytes: 3636
#include<iostream>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <algorithm>
using namespace std;
#include <cmath>
#include <string>
#define elif else if
int main(void) {
  int N;
  cin>>N;
  int tmp = N/3;
  cout<<tmp<<endl;
  return 0;
}

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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

std::string l;
ll dp1[100005];
ll dp2[100005];
int main() {
	std::cin >> l;

	dp1[1] = 1;
	dp2[1] = 2;
	int n = l.size();
	for (int i = 1; i < n; ++i) {
		if (l[i] == '1') {
			dp1[i + 1] = (dp1[i] * 3 + dp2[i]) % mod;
			dp2[i + 1] = dp2[i] * 2 % mod;
		}
		else {
			dp1[i + 1] = dp1[i] * 3 % mod;
			dp2[i + 1] = dp2[i];
		}
	}

	std::cout << (dp1[n] + dp2[n]) % mod << std::endl;
	return 0;
}


Measured memory_bytes: 2048
import itertools
N = int(input())
l = [i+1 for i in range(N)]
cnt = 0
l = list(itertools.permutations(l))
li = []
for i in l:
  li.append(list(i))
p_l = list(map(int,input().split()))
q_l = list(map(int,input().split()))

print(abs(li.index(q_l) -li.index(p_l)))

Measured memory_bytes: 50544
import java.util.*;


public class Main{
  
  public static void main(String[] args){
    ArrayList<String> array = new ArrayList<String>();
      
    Scanner scan = new Scanner(System.in);
    //int val = scan.nextInt();
    //System.out.print(val);
    //int val2 = scan.nextInt();
    //System.out.print(val2);
    while(scan.hasNext()){
      array.add(scan.next());
    }
    
    Collections.sort(array);
    
    String val=""; 
    for(int i=2; i<array.size(); i++){
      val = val + array.get(i);
    }
    
    System.out.print(val);
  }
   
}

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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)
typedef long long ll;
typedef pair <int, int> P;
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;

using namespace std;

char c[52][2];

int main() {
	int n;
	cin >> n;
	REP(i, n)cin >> c[i][0];
	REP(i, n)cin >> c[i][1];

	VI v;
	REP(i, n) {
		if (c[i][0] == c[i][1])v.push_back(1);
		else v.push_back(2),i++;
	}
	if (v.size() == 0) {
		cout << 3 << endl;
		return 0;
	}

	ll ans = 1;
	if (v[0] == 2)ans = 6;
	else ans = 3;
	REP(i, v.size() - 1) {
		if (v[i + 1] == 2 && v[i] == 2)ans *= 3;
		else if (v[i + 1] == 2 && v[i] == 1)ans *= 2;
		else if (v[i + 1] == 1 && v[i] == 1)ans *= 2;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  ll a, b, m; cin >> a >> b >> m;
  map<ll, ll> ma, mb;
  ll min_a = 1e5, min_b = 1e5;
  rep(i, a){
    ll k; cin >> k;
    ma[i+1] = k;
    min_a = min(min_a, k);
  }
  rep(i,b){
    ll k; cin >> k;
    mb[i+1] = k;
    min_b = min(min_b, k);
  }
  ll ans = min_a + min_b;
  for(int i = 0; i < m; i++){
    ll x, y, z; cin >> x >> y >> z;
    ll t;
    t = ma[x]+mb[y]-z;
    ans = min(ans, t);
  }
  cout << ans << endl;
  system("pause");
}

Measured memory_bytes: 14848
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
using namespace std;

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

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

    vector<double> p1;
    vector<double> p2;

    double ans = (v[0] + v[1]) / 2.0;
    double q1 = v[0];
    double q2 = v[1];
    for(int i = 2; i < n; i++){
        double tmp = 0;
        tmp = (ans + v[i]) / 2.0;
        ans = tmp;
        //q1 = q2;
        //q2 = v[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {

	int N, T, A, H[1005];

	cin >> N >> T >> A;

	for (int i = 1; i <= N; i++) {
		cin >> H[i];
	}

	 double tmp;

	int ans = 0;
	double save;
	save = 1.0*T - 0.006*H[1] - 1.0*A;
	if (save < 0.0) { save = -save; }

	for (int i = 1; i <= N; i++) {
		tmp = 1.0*T - 0.006*H[i]-1.0*A;
		if (tmp < 0.0) { tmp = -tmp; }
		if (tmp <= save) { ans = i; save = tmp; }
	}
	cout << ans << endl;

	//system("pause");
	return 0;
}

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

template <typename T>
class DynamicFenwickTree {
	const ll n;
	unordered_map<ll, T> data;
public:
	DynamicFenwickTree(ll n_, int pmax = 1e5) : n(n_), data(pmax) {}
	T find(ll p) {
		T res = 0;
		while (p >= 0) {
			res += data[p];
			p = (p & (p + 1)) - 1;
		}
		return res;
	}
	void add(ll p, T val) {
		while (p < n) {
			data[p] += val;
			p |= p + 1;
		}
	}
};

template <typename T>
class DynamicRARS {
	const ll n;
	DynamicFenwickTree<T> bit0, bit1;
public:
	DynamicRARS(ll n_) : n(n_), bit0(n), bit1(n) {}
	T find(ll p) {
		return bit1.find(p) * (p + 1) + bit0.find(p);
	}
	T find(ll l, ll r) {
		return find(r) - find(l - 1);
	}
	void add(ll l, ll r, T val) {
		bit0.add(l, -val * l);
		bit1.add(l, val);
		bit0.add(r + 1, val * (r + 1));
		bit1.add(r + 1, -val);
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	DynamicRARS<ll> rars(n);
	for (int i = 0, type, s, t, x; i < q; i++) {
		cin >> type >> s >> t; s--; t--;
		if (type) {
			printf("%lld\n", rars.find(s, t));
		}
		else {
			cin >> x;
			rars.add(s, t, x);
		}
	}
	return 0;
}



Measured memory_bytes: 10184
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		List<Integer> d = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			d.add(sc.nextInt());
		}
		Collections.sort(d);
		System.out.println(d.get(N/2) - d.get(N/2 -1));
	}
}

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

#define gc( ) std::getchar( )
#define pc( i ) std::putchar( i )
#define RE cout << "Passing [" << __FUNCTION__ << "] on " << __LINE__ << '\n'
#define DEBUG(...) for( auto &i: __VA_ARGS__ ) cout << i << " "; cout << '\n'
#define space ' '
#define enter '\n'
using std::make_pair;

template < typename T >
inline T read( )
{
 T x = 0;
 char ch = gc( );
 bool f = 0;
 while( !std::isdigit( ch ) )
 {
  f = ( ch == '-' );
  ch = gc( );
 }
 while( std::isdigit( ch ) )
 {
  x = x * 10 + ( ch - '0' );
  ch = gc( );
 }
 return f ? -x : x;
}

template < typename T >
void print( T x )
{
 if( x < 0 )
 {
  x = -x;
  pc( '-' );
 }
 if( x < 10 )
 {
  pc( x + 48 );
  return;
 }
 print < T > ( x / 10 );
 pc( x % 10 + 48 );
 return ;
}

namespace Solution
{
#define IOS std::ios::sync_with_stdio( false ), std::cin.tie( 0 ), std::cout.tie( 0 )
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
#define rdi( ) read < int > ( )
#define rdl( ) read < long long > ( )
#define pti( i ) print < int > ( i ), putchar( space )
#define ptl( i ) print < long long > ( i ), putchar( space )
#define For( i, j, k ) for( int i = j; i <= k; ++i )
 using std::cin;
 using std::cout;
 using std::endl;
 using std::vector;
 using std::map;
 using std::queue;
 using std::deque;
 using std::set;
 using std::pair;
 const int N = 204001, mod = 1e9 + 7;
 long long n, k;
 void Fakemain( )
 {
  IOS;
  cin >> k;
  if( k % 2 == 0 || k % 5 == 0 )
  {
   cout << -1;
   return;
  }
  int cnt = 1;
  long long a = 7;
  while( 1 )
  {
   if( !a )
    break;
   else
   while( a < k )
    a = a * 10 + 7,
    cnt++;
   a %= k;
  }
  cout << cnt;
  return;
 }

} // namespace Solution

int main( int argc, char* argv[] )
{
 Solution::Fakemain( );
 return 0;
}

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

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

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k,t;
	cin>>k>>t;
	priority_queue<Pi> que;
	rep(i,t){
		int x;
		cin>>x;
		que.push(Pi(x,i));
	}
	int ans=0;
	int prev=-1;
	while(que.size()!=1){
		Pi now=que.top();
		if(now.se==prev){
			Pi x=now;
			que.pop();
			now=que.top();
			que.pop();
			que.push(x);
		}else{
			que.pop();
		}
		prev=now.se;
		now.fi--;
		if(now.fi){
			que.push(Pi(now.fi,now.se));
		}
	}
	cout<<que.top().fi-1<<endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
ai = [int(input()) for i in range(m)]

mod = 10**9+7

dp = [0] * (n+1)
dp[0] = 1
num = 0

for i in range(1,n+1):
    #print(i)
    if m == 0:
        if i == 1:
            dp[i] = dp[i-1] % mod
        else:
            dp[i] = (dp[i-1] + dp[i-2])%mod
    else:
        if i == ai[num]:
            dp[i] = 0
            num += 1
            num = min(num,m-1)
        else:
            if i == 1:
                dp[i] = dp[i-1] % mod
            else:
                dp[i] = (dp[i-1] + dp[i-2])%mod
    #    dp[i+1] = dp[i-1] + dp[i]
            
print(dp[n]%mod)

Measured memory_bytes: 7848
N = int(input())
A = list(map(int,input().split()))
res = [0]* N

for i in range(N-1):
    res[i+1] = A[i+1] - res[i]
res[0]  = (A[0] - res[0] - res[-1])//2
for i in range(N-1):
    res[i+1] = A[i+1] - res[i]
ans = [2*res[i-1] for i in range(N)]
print(*ans)

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    rep(i, N + 2) {
        if (1LL * i * i > N) {
            cout << (i - 1) * (i - 1) << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <iomanip>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
 
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=2e2 + 5;
const int M=1e5 + 5;

vector <int> v[N]; 
char s[N][N];
int clr[N];
bool vis[N];
bool ok = true;
int ans = -1,n;

void dfs(int s, int c)
{
    vis[s]=true;
    clr[s]=c;
    for(int x: v[s]){
        if(!vis[x]){
            dfs(x,(1+c)%2);
        }
        else{
            if(clr[s]==clr[x]) ok = false;
        }
    }
}

void bfs(int s)
{
    int i,j;
    int d[N];
    for(i=1;i<=n;i++){
        vis[i]=false;
    }
    queue <int> qu;
    d[s]=1;
    qu.push(s);
    vis[s]=true;
    while(!qu.empty()){
        int x = qu.front();
        qu.pop();
        for(int y: v[x]){
            if(!vis[y]){
                vis[y]=true;
                d[y]=1+d[x];
                qu.push(y);
            }
        }
    }
    for(i=1;i<=n;i++) ans = max(ans,d[i]);
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    int i,j,k;
    cin>>n;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            cin>>s[i][j];
            if(s[i][j]=='1'){
                v[i+1].pb(j+1);
                v[j+1].pb(i+1);
            }
        }
    }
    for(i=1;i<=n;i++){
        vis[i]=false;
    }
    dfs(1,0);
    if(!ok){
        cout << -1 << endl;
        return 0;
    }
    for(i=1;i<=n;i++){
        bfs(i);
    }
    cout << ans << endl;

 
    return 0;
}

Measured memory_bytes: 768