akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    from itertools import product
    n,k=map(int,input().split())
    X=[0]*n
    Y=[0]*n
    XY=[0]*n
    for i in range(n):
        x,y=map(int,input().split())
        X[i]=x
        Y[i]=y
        XY[i]=(x,y)
    # 2-dim cumsum (pivot=(-inf,-inf))
    S=[[0]*n for _ in range(n)]
    X.sort(); Y.sort()
    for i,j in product(range(n),repeat=2):
        for x,y in XY:
            if x<=X[i] and y<=Y[j]: S[i][j]+=1
    # calculate
    ans=INF
    for i0,j0 in product(range(n),repeat=2):
        for i1,j1 in product(range(i0+1,n),range(j0+1,n)):
            count=S[i1][j1]
            if i0>0: count-=S[i0-1][j1]
            if j0>0: count-=S[i1][j0-1]
            if i0>0 and j0>0: count+=S[i0-1][j0-1]
            if count>=k:
                ans=min(ans,(X[i1]-X[i0])*(Y[j1]-Y[j0]))
    print(ans)
resolve()

Measured memory_bytes: 46428
/**
     *    author:  shashank_hire
    **/
#include <bits/stdc++.h>
using namespace std;
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define ll long long
#define ld long double
#define MOD 1000000007

// A C++ program for Dijkstra's single source shortest path algorithm. 
// The program is for adjacency matrix representation of the graph 
 
// #include <limits.h> 
// #include <stdio.h>

// Number of vertices in the graph 
ll V;

// A utility function to find the vertex with minimum distance value, from 
// the set of vertices not yet included in shortest path tree 
int minDistance(int dist[], bool sptSet[]) 
{ 
	// Initialize min value 
	int min = INT_MAX, min_index; 

	for (int v = 0; v < V; v++) 
		if (sptSet[v] == false && dist[v] <= min) 
			min = dist[v], min_index = v; 

	return min_index; 
} 

// A utility function to print the constructed distance array 
int printSolution(int dist[]) 
{ 
	// printf("Vertex \t\t Distance from Source\n"); 
	// for (int i = 0; i < V; i++) 
	// 	printf("%d \t\t %d\n", i, dist[i]); 
    if(dist[V-1]==2147483647)
        cout<<"-1\n";
    else
    cout<<dist[V-1]<<"\n";
} 

// Function that implements Dijkstra's single source shortest path algorithm 
// for a graph represented using adjacency matrix representation 
void dijkstra(int graph[1001][1001], int src) 
{ 
	int dist[V]; // The output array. dist[i] will hold the shortest 
	// distance from src to i 

	bool sptSet[V]; // sptSet[i] will be true if vertex i is included in shortest 
	// path tree or shortest distance from src to i is finalized 

	// Initialize all distances as INFINITE and stpSet[] as false 
	for (int i = 0; i < V; i++) 
		dist[i] = INT_MAX, sptSet[i] = false; 

	// Distance of source vertex from itself is always 0 
	dist[src] = 0; 

	// Find shortest path for all vertices 
	for (int count = 0; count < V - 1; count++) { 
		// Pick the minimum distance vertex from the set of vertices not 
		// yet processed. u is always equal to src in the first iteration. 
		int u = minDistance(dist, sptSet); 

		// Mark the picked vertex as processed 
		sptSet[u] = true; 

		// Update dist value of the adjacent vertices of the picked vertex. 
		for (int v = 0; v < V; v++) 

			// Update dist[v] only if is not in sptSet, there is an edge from 
			// u to v, and total weight of path from src to v through u is 
			// smaller than current value of dist[v] 
			if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX 
				&& dist[u] + graph[u][v] < dist[v]) 
				dist[v] = dist[u] + graph[u][v]; 
	} 

	// print the constructed distance array 
	printSolution(dist); 
}

int main()
{
	ll h, n, i;
	cin>>h>>n;
	vector<ll> a(n);
	for(i=0;i<n;i++)
		cin>>a[i];
	accumulate(a.begin(), a.end(), 0)<h ? cout<<"No\n":cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 1024
def main():
    S = input()
    if len(S)%2:
        sl,sr = S[:len(S)//2],S[:len(S)//2:-1]
    else:
        sl,sr = S[:len(S)//2],S[:len(S)//2-1:-1]
    count=0
    for _, (l,r) in enumerate( zip(sl,sr)):
        if l!=r:
            count+=1
    print(count)

if __name__=='__main__':
    main()


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

typedef long long ll;
#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;


int main() {
  ll N, W;
  cin >> N >> W;

  vector<ll> v(N), w(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i] >> w[i];
  }

  vector<ll> dp(W + 1, -1);
  dp[0] = 0;
  for (int i = 0; i < N; i++) {
    for (int k = W; k >= 0; k--) {
      ll temp = k - w[i];
      if (temp < 0) break;

      if ( dp[temp] >= 0 ) {
        dp[k] = max(dp[k], dp[temp] + v[i]);
      }
    }
  }

  ll ans = 0;
  for (int i = 0; i < W + 1; i++) {
    ans = max(ans, dp[i]);
  }

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<ll>
using namespace std;
using ll = long long;

int main(){
    ll n,k;
    cin>>n>>k;
    V x(n);
    ll ans=0;
    rep(i,0,n) cin>>x[i];
    rep(i,0,n){
        ans+=min(x[i]*2,(k-x[i])*2);
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,a,x=0,y=0;
    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>a;
        if(a!=1+y){
            x++;
        }
        else{
            y++;
        }
    }
    if(x==n){
        cout<< "-1" <<endl;
    }
    else{
    cout<< x <<endl;
    }
}


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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void we_r_done(){cout<<"NO"; exit(0);}

void debug(string mssg){cout<<mssg; exit(0);}

using minHeap = priority_queue< int, vector< int >, greater< int > >;

string K;
int D;
int dp[10001][101][2][2];

int add(int x , int y){
    return (x%mod + y%mod)%mod;
}

int fun(int pos, int md , int isSmall , int isStart){

    if(pos == K.size()) return (!md && !isStart);

    int &ret = dp[pos][md][isSmall][isStart];

    if(ret != -1) return ret;

    ret = 0;

    if(isStart){
        ret = add(ret , fun(pos+1,0,1,1));

        int h = (isSmall?9: K[pos]-'0');

        for(int i=1; i<=h ; i++){
            int d = K[pos]-'0';
            ret = add(ret , fun(pos+1 , (md + i)%D , isSmall || (i<d) , 0) ) ;
        }
    }
    else{
        int h = (isSmall?9: K[pos]-'0');

        for(int i=0; i<=h ; i++){
            int d = K[pos]-'0';

            ret = add(ret , fun(pos+1 , (md + i)%D , isSmall || (i<d) , 0) ) ;
            //cout<<md<<" "<<ret<<endl;
        }
    }
    return ret;
}


int main()
{
    ///freopen("output.txt","w",stdout);
    ///freopen("input.txt","r",stdin);

    ///FastIO;
    cin>>K>>D;

    Fill(dp,-1);
    cout<<fun(0,0,0,1);
    return 0;

}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?


Measured memory_bytes: 17024
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()

if m == 1:
    print(1, 2)
    exit()

if m % 2 == 0:
    l = (m + 1) // 2
    r = (m + 1) // 2 + 2
    cnt = 0
    while cnt < m and l >= 1 and r <= (m + 1):
        print(l, r)
        l -= 1
        r += 1
        cnt += 1
    l = (n - m - 1) // 2
    r = (n - m - 1) // 2 + 1
    while cnt < m and l >= 1 and r <= (n - m - 1):
        print(m + 1 + l, m + 1 + r)
        l -= 1
        r += 1
        cnt += 1
else:
    l = m // 2
    r = m // 2 + 2
    cnt = 0
    while cnt < m and l >= 1 and r <= m:
        print(l, r)
        l -= 1
        r += 1
        cnt += 1
    l = (n - m) // 2
    r = (n - m) // 2 + 1
    while cnt < m and l >= 1 and r <= (n - m):
        print(m + l, m + r)
        l -= 1
        r += 1
        cnt += 1

Measured memory_bytes: 9336
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-05-19 20:12:22
---------------------------------*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;

int main(int argc, char const *argv[])
{

	long double n, k;
	cin >> n >> k;
	
	long double p = 0;
	for(long double i = 1; i <= n; ++i){
		if(i >= k)	p += 1.0 / n;
		else{
			int m = ceil(log2(1.0*k/i));
			p += pow(0.5, m)*1.0/n;
		}
	}
	// cout << p << endl;
	printf("%.10Lf", p);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch OddsOfOddness | diff OddsOfOddness.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address OddsOfOddness.cpp && ./a.out

/*
 
 9/28/2019
 
 5:02-
 
 */

int N;

void solve() {
  int a=(N+1)/2;
  double res=(double)a/N;
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  solve();
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int i;
    int n,h,lh=0,flg=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&h);
        if(h > lh){
            lh = h - 1;
        }else if(h < lh){
            flg = 1;
        }
    }
    if(flg == 0){
        printf("Yes\n");
    }else{
        printf("No\n");}
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using static Scanner;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Solve();
        Console.Out.Flush();
    }
    static void Solve() {
        int N = ScanInt(), K = ScanInt();
        Span<int> nums = stackalloc int [N + 1];
        for (int i = 0; i < N; i++) {
            var A = ScanInt();
            nums[A]++;
        }
        var list = new List<int>();
        foreach (var v in nums) {
            if (v > 0) list.Add(v);
        }
        var answer = 0;
        if (list.Count > K) {
            list.Sort();
            for (int i = 0; i < list.Count - K; i++) answer += list[i];
        }
        Console.WriteLine(answer);
    }
}

public static class Scanner
{
    static readonly Stream stream = Console.OpenStandardInput();
    static readonly byte[] buffer = new byte[1024];
    static int length, p;
    static bool isEof;
    private static byte ConsoleIn() {
        if (isEof) return 0;
        if (p < length) return buffer[p++];
        p = 0;
        if ((length = stream.Read(buffer, 0, 1024)) > 0) return buffer[p++];
        isEof = true;
        return 0;
    }
    public static char GetChar() {
        var by = ConsoleIn();
        while ((by < '!' || '~' < by) && !isEof) by = ConsoleIn();
        return (char) by;
    }
    public static int ScanInt() {
        var temp = 0;
        for (var ch = GetChar(); '0' <= ch && ch <= '9'; ch = (char) ConsoleIn()) {
            temp = temp * 10 + ch - '0';
        }
        return temp;
    }
}

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

int mid(int a,int b,int c){
  return a+b+c-max(max(a,b),c)-min(min(a,b),c);
}

int main(){
  int a,b,c;
  cin >>a>>b>>c;
  cout << max(max(a,b),c)-mid(a,b,c) + mid(a,b,c)-min(min(a,b),c) << endl;
}

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

#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define ALL(v) begin(v), end(v)

/* REPmacro */
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (s); i >= (n); i--)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define rrep(i, n) RFOR(i, n - 1, 0)
#define rrepi(i, n) RFOR(i, n, 1)

/* debug */
#define pp(v) cerr << #v "=" << (v) << endl;

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using vs = vector<string>;
using Graph = vvi;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* iostream */
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define TIME system("date +%M:%S.%N")
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }
template<class T> T div_ceil(const T &a, const T &b) { return (a + b - 1) / b; }

signed main() {
  int x;cin>>x;
  int ans = x/11*2;
  int b = x%11;
  ans += b == 0 ? 0 : b <= 6 ? 1 : 2;
  cout << ans << endl;
}

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

using namespace std;


const int BITS = 64;
long long N, K;
vector<vector<bool>> v;
vector<bool> k(BITS);
vector<long long> pw(BITS);

void solve()
{
    bool match = true;
    long long ans = 0;
    for (int i = 0; i < BITS; ++i) {
        long long cnt = 0;
        for (int j = 0; j < N; ++j) if (v[j][i]) ++cnt;
        if ((N-cnt) <= cnt) {
            // put 0
            ans += pw[i] * cnt;
            if (k[i]) match = false;
        } else {
            // put 1
            if (!match || k[i])
                ans += pw[i] * (N-cnt);
            else
                ans += pw[i] * cnt;
        }
    }
    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> K;
    pw[BITS-1] = 1;
    for (int i = BITS-2; i; --i) {
        pw[i] = 2ll * pw[i+1];
    }
    for (int i = 0; i < BITS && K; ++i) {
        if (K & 1) k[i] = 1;
        K /= 2;
    }
    reverse(k.begin(), k.end());

    long long a;
    for(int i = 0 ; i < N ; i++){
        cin >> a;
        vector<bool> b(BITS);
        int j = 0;
        for (int j = 0; j < BITS && a; ++j) {
            if (a & 1) b[j] = 1;
            a /= 2;
        }
        reverse(b.begin(), b.end());
        v.push_back(b);
    }
    solve();
    return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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

const int INF = 1e9;

int main(void){

	int S, W; cin >> S >> W;

	if(W >= S) cout << "unsafe" << endl;
	else cout << "safe" << endl;


	return 0;

}


Measured memory_bytes: 3620
def main():
	inf=10**9
	h,w=map(int,input().split())
	a,b=map(int,input().split())
	c,d=map(int,input().split())
	s=[input() for _ in range(h)]
	cnt=[[inf]*w for _ in range(h)]
	LIS=((-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -2), (-1, -1), (-1, 1), (-1, 2), (0, -2), (0, 2), (1, -2), (1, -1), (1, 1), (1, 2), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2))
	cnt[a-1][b-1]=0
	new_stack=[(a-1,b-1)]
	for i in range(inf):
		if len(new_stack)==0:
			break
		lis=[]
		stack=new_stack.copy()
		new_stack=[]
		while stack:
			r=stack.pop()
			lis.append(r)
			x,y=r[0],r[1]
			for dx,dy in ((-1,0),(0,1),(1,0),(0,-1)):
				if 0<=x+dx<h and 0<=y+dy<w:
					if s[x+dx][y+dy]=="." and cnt[x+dx][y+dy]==inf:
						cnt[x+dx][y+dy]=i
						stack.append((x+dx,y+dy))
		for x,y in lis:
			for dx,dy in LIS:
				if 0<=x+dx<h and 0<=y+dy<w:
					if s[x+dx][y+dy]=="." and cnt[x+dx][y+dy]==inf:
						cnt[x+dx][y+dy]=i+1
						new_stack.append((x+dx,y+dy))		
	print(cnt[c-1][d-1] if cnt[c-1][d-1]!=inf else -1)
if __name__ == '__main__':
	main()

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

int main() {
  string s;
  int k;
  cin >> s >> k;
  int sz = s.size();
  vector<char> vec(sz);
  
  int b=0;
  for(int i=0; i<sz; i++){
    if(b==0){
      vec.at(i)=s.at(i);
      if(s.at(i)!='1') b=1;
    }
    else{
      vec.at(i)=vec.at(i-1);
    }
  }
  if(k>sz) cout << vec.at(sz-1) << endl;
  else cout << vec.at(k-1) << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	long long t1, t2, a1, a2, b1, b2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

	long long dif = (t1 * a1 + t2 * a2) - (t1 * b1 + t2 * b2);
	if (dif == 0) {
		cout << "infinity" << endl;
		return 0;
	}
	if (dif < 0) {
		swap(a1, b1);
		swap(a2, b2);
		dif = -dif;
	}
	if (a1 > b1) {
		cout << 0 << endl;
		return 0;
	}

	long long dt1 = t1 * (a1 - b1);

	long long ans = (-dt1 / dif) * 2;
	if (-dt1 % dif != 0)ans++;
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000



int main(){
	
	long long H,W,h,w;
	cin>>H>>W>>h>>w;
	
	vector<vector<long long>> ans(H,vector<long long>(W,0));
	
	long long m = -1000000000;
	
	for(long long i=0;i<H;i+=h){
		for(long long j=0;j<W;j+=w){
			ans[i][j] = (-m)-1;
		}
	}
	
	for(long long i=h-1;i<H;i+=h){
		for(long long j=w-1;j<W;j+=w){
			ans[i][j] = m;
		}
	}
	
	
	
	long long sum = 0;
	for(long long i=0;i<H;i++){
		for(long long j=0;j<W;j++){
			sum += ans[i][j];
		}
	}
	
	if(sum<=0){
		cout<<"No"<<endl;
		return 0;
	}
	else{
		cout<<"Yes"<<endl;
	}
	
	for(long long i=0;i<H;i++){
		for(long long j=0;j<W;j++){
			if(j!=0)cout<<' ';
			cout<<ans[i][j];
		}
		cout<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main(int argc, char** argv){
	int n,k;
	cin >> n >> k;
	int m = (n-1)*(n-2)/2;
	if(k > m){
		cout << -1 << endl;
		return 0;
	}
	int u[2*m-k],v[2*m-k];
	for(int i = 0; i < n-1; i++){
		u[i] = 1;
		v[i] = i+2;
	}
	int j = 2;
	int l = 3;
	for(int i = n-1; i < n-1+m-k; i++){
		u[i] = j;
		v[i] = l;
		l++;
		if(l>n){
			l = ++j + 1;
		}
	}
	cout << n-1+m-k << endl;
	for(int i = 0; i < n-1+m-k; i++){
		cout << u[i] << " " << v[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7,MAX = 1e5;

int main()
{
	ll n;
	cin >> n;
	string s,t;
	cin >> s >>t;
	ll ans;
	ll i;
	ll mae;
	if(s[0]==t[0])
	{
		ans = 3;
		i=1;
		mae = 0;
	}
	else
	{
		ans = 6;
		mae = 1;
		i = 2;
	}
	int cnt[4] = {};
	for(i;i<n;i++)
	{
		if(s[i]==t[i])
		{
			if(mae==0)
			{
				ans*=2;
				ans%=MOD;
				cnt[0]++;
			}
			else
			{
				cnt[1]++;
			}			
			mae = 0;
		}
		else
		{
			if(mae==0)
			{
				ans *= 2;
				ans %= MOD;
				cnt[2]++;
			}
			else
			{
				ans*=3;
				ans %= MOD;
				cnt[3]++;
			}
			
			mae = 1;
			i++;
		}
		
		
	}
	 cout<<ans<<endl;
	 for(int i =0;i<4;i++)
	 {
		 //cout<<cnt[i]<<endl;
	 }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef long double LD;

const int MOD = 1e9 + 7;
const int MAXN = 3*1e5;
const int MAXM = 1e5+1;

// BIT (Binary indexed tree)
int bit[MAXM];

int sum(int i) {
	int s = 0;
	while (i > 0) {
		s += bit[i];
		i -= i&-i; // i&-i => last bit which is 1.  0110&1010=0010
	}
	return s;
}

void add(int i, int x) {
	while(i <= MAXM) {
		bit[i] += x;
		i += i&-i; // i&-i => last bit which is 1.
	}
}
// BIT : end

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

	int N, M, L, R;
	vector<pair<int, int>> a[MAXM];
//	cin >> N >> M;
	scanf("%d %d", &N, &M);
	for (int i = 0; i < N; i++) {
//		cin >> L >> R;
		scanf("%d %d", &L, &R);
		a[R-L+1].push_back(make_pair(L, R));
	}
	for (int i = 1; i <= M; i++) {
		int ans = N;
		for (int j = i; j <= M; j += i) {
			ans += sum(j);
		}
		for (auto p : a[i]) {
			// 001100
			//   LR
			add(p.first, 1);
			add(p.second+1, -1);
			N--;
		}
//		cout << ans << endl;
		printf("%d\n", ans);
	}
	return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vll a(N), b(N);
  ll asum = 0, bsum = 0;
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
    asum += a.at(i);
  }
  for(int i = 0; i < N; i++){
    cin >> b.at(i);
    bsum += b.at(i);
  }
  ll num = bsum - asum;
  if(num < 0 || (num == 0 && a != b)){
    cout << "No" << endl;
    return 0;
  }
  ll acount = 0, bcount = 0;

  for(int i = 0; i < N; i++){
    if(a.at(i) == b.at(i)) continue;

    if(a.at(i) > b.at(i)){
      bcount += a.at(i) - b.at(i);
    }
    else{
      ll d = b.at(i) - a.at(i);
      if(d % 2 == 0) acount += d/2;
      else{
        acount += (d+1)/2;
        bcount += 1;
      }
    }
    if(acount > num || bcount > num){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 384
n = list(raw_input())
operators = ["+", "-"]
total = None
for op1 in operators:
    for op2 in operators:
        for op3 in operators:
            total = n[0] + op1 + n[1] + op2 + n[2] + op3 + n[3]
            if eval(total) == 7:
                total = total + "=7"
                print(total)
                exit(0)


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

int main () {
  string S;
  ll K;

  cin >> S >> K;

  for(char c: S) {
    if(c != '1') {
      cout << c << endl;
      return 0;
    } else {
      K--;
      if(K == 0) break;
    }
  }

  cout << '1' << endl;

  return 0;
}


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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i] >> B[i];
    }
    ll ans = 0;
    for ( int i = N-1; i >= 0; i-- ) {
        ans += (B[i] - (A[i] + ans) % B[i]) % B[i];
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

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

	int min, maxDiff;
	int num;

	for(int i=0; i<n; i++){
		cin >> num;
		if(i==0){ min = num; continue; }
		if(i==1){ maxDiff = num - min; }
		if(num < min){ min = num; continue; }
		if(num - min > maxDiff) maxDiff = num - min;
	}

	cout << maxDiff << endl;
}


Measured memory_bytes: 3116
use std::io::stdin;
fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let s:Vec<char> = st.trim().chars().collect();
    let mut ten = 1;
    let mut c:usize = 0;
    let mut r:[i64;2020] = [0;2020];
    let m = s.len() as usize;
    for i in 1..m+1 {
        let mut x = s[m-i] as usize;
        x -= 48;
        c = (c+(x*ten)%2019)%2019;
        r[c] += 1;
        ten = (ten*10)%2019;
    };
    let mut result:i64 = 0;
    for i in 0..2019 {
        if &1 < &r[i] {
            result += (r[i]-1)*r[i]/2
        };
    };
    result += r[0];
    println!("{}", result);
}

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

int findSum(int n){
    int sum=0;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
    return sum;
}

int main(void){
   int N,A,B;
   cin>>N>>A>>B;
   int total=0;
   for(int i=1;i<=N;i++){
       int sum=findSum(i);
       if(sum>=A && sum <=B) total+=i;
   }
   cout<<total<<endl;
   return 0;
}


Measured memory_bytes: 256
// g++ -I ~/Documents/programming/cppLib -std=gnu++14 -o test ~/Documents/programming/cppLib/test.cpp && ./test && rm test
#include <bits/stdc++.h>
using namespace std;
template <typename T> using vector2 = vector <vector  <T>>;
template <typename T> using vector3 = vector <vector2 <T>>;
template <typename T> using vector4 = vector <vector3 <T>>;
using lint = long long;
#define FOR( i, a, b ) for( lint i=(a) ; i <= (b) ; ++i )
#define REP( i, n )    for( lint i= 0  ; i <  (n) ; ++i )
#define ALL( v )       (v).begin(), (v).end()
#define MOD            1000000007

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

    vector<bool> A(N, false);
    REP( i, M ) {
        int a;
        cin >> a;
        A[a] = true;
    }

    vector<int> dp(N);
    dp[0] = 1;
    dp[1] = A[1] ? 0 : 1;

    for( int i=2; i<N; i++ ) {
        dp[i] = A[i] ? 0 : (dp[i-1] + dp[i-2]) % MOD;
    }

    cout << (dp[N-1] + dp[N-2]) % MOD << endl;

}


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

using namespace std;

vector<pair<long long, int> > v;
long long ans;

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		v.push_back({a, 1});
	}
	for (int i = 0; i < m; i++)
	{
		int b, c;
		cin >> b >> c;
		v.push_back({c, b});
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	for (int i = 0; i < v.size(); i++)
	{
		long long c = min(v[i].second, n);
		n -= c;
		ans += c * v[i].first;
	}
	cout << ans;
}


Measured memory_bytes: 6512
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int A, B;

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

  int ans = max(A + B, A - B);
  ans = max(ans, A * B);

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

Measured memory_bytes: 256
def common_raccoon_vs_monster():
    # 入力
    H, N = map(int, input().split())
    A = list(map(int, input().split()))
    # 必殺技の合計攻撃力
    sum_A = 0 # 必殺技の攻撃力の合計
    for i in range(len(A)):
        sum_A += A[i]
    # 比較
    if H > sum_A:
        return 'No'
    else:
        return 'Yes'

result = common_raccoon_vs_monster()
print(result)

Measured memory_bytes: 20536
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int H = sc.nextInt();
    int W = sc.nextInt();
    
    long ans = Long.MAX_VALUE;
    ans = Math.min(ans, solve1(H, W));
    ans = Math.min(ans, solve1(W, H));
    ans = Math.min(ans, solve2(H, W));
    ans = Math.min(ans, solve2(W, H));
    
    System.out.println(ans);
  }
  
  private static long solve2(int x, int y) {
    return x%3 != 0 ? y : 0;
  }
    
  private static long solve1(int x, int y) {
    
    long ret = Long.MAX_VALUE;
    for (int i = 1; i <= x-1; i++) {
      long b = (long)y * i; // 10 5*2
      long a = (long)(x-i) * (y/2); // 6 3*2
      long c = (long)(x-i) * ((y+1)/2); // 9 3*3
      long max = Math.max(Math.max(a,b),c);
      long min = Math.min(Math.min(a,b),c);
      long diff = Math.abs(max-min);
      ret = Math.min(ret, diff);
    }

    return ret;
  }
}

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

int main() {
  int a;
  string s;
  cin >>a >>s;
  int k =0;
  for(int i=0; i<a-2; i++){
    if(s.at(i)=='A'&&s.at(i+1)=='B'&&s.at(i+2)=='C'){
      k++;
    }
  }
  cout <<k <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repm(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll a, b, c, i, j, k, l, m, n, ans, tmp, hoge;

int calc(ll _n)
{
    int count = 0;
    while (_n % 2 == 0 && _n > 1)
    {
        //cout << "n : " << _n << endl;
        count++;
        _n /= 2;
    }
    return count;
}

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

    cin >> n;

    ll sum = 0, num = 1;
    repm(i, 1, n + 1)
    {
        int _sum = calc(i);
        if (_sum > sum)
        {
            num = i;
            sum = _sum;
        }
    }

    cout << num << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int a1, a2, a3;
	while (cin >> a1 >> a2 >> a3)
	{
		int sum = 0;
		int x1 = abs(a2 - a1);
		int x2 = abs(a3 - a1);
		int x3= abs(a3 - a2);
		int max = x1 > x2 ? x1 : x2;
		max = max > x3 ? max : x3;
		sum = x1 + x2 + x3 - max;
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a.sort()
nums = n
nin = a[0]
next_nin = a[0]
while nums != 1:
    for i in range(n - nums + 1,n):
        a[i] %= nin
        if a[i] != 0:
            next_nin = min(next_nin, a[i])
        else:
            nums -= 1
    a.sort()
    nin = next_nin
print(nin)







Measured memory_bytes: 14252
#include<iostream>
using namespace std;
int main(){
	int c1, c5, c10, c50, c100, c500;
	cin >> c1 >> c5 >> c10 >> c50 >> c100 >> c500;
	if (c1 * 1 + c5 * 5 + c10 * 10 + c50 * 50 + c100 * 100 + c500 * 500 >= 1000){
		cout << "1" << endl;
	}
	else cout << "0" << endl;










	return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;

// const
// 円周率
const double pi = M_PI;
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)

int main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(ALL(a));
  ll res = 0;
  rep(i, n) {
    repz(j, i + 1, n) {
      ll li = a[i];
      ll lj = a[j];
      res += n - 1 - j -
             (a.end() - lower_bound(a.begin() + j, a.end(), li + lj));
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int MAXN=2*1e5+10;
long long a[MAXN];
int n,k;
int check(long long x){
    long long sum=0;
    for(int i=1;i<=n;i++){
        if(a[i]%x==0) sum+=a[i]/x-1;
        else sum+=a[i]/x;
    }
    if(sum<=k) return true;
    else return false;
}
int main(){
    int i;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    long long l=1,r=1999999999;
    while(r-l>1)
    {
        long long mid=(l+r)/2;
        if(check(mid)==1) r=mid;
        else l=mid;
    }
    if(check(l))
        printf("%lld",l);
    else
        printf("%lld",r);
}


Measured memory_bytes: 5324
#include <iostream>
using namespace std;
int main(){
    int t,n;
    for(int i=0;i<4;i++){
        cin>>t>>n;
        if(t==1)cout<<6000*n<<endl;
        else if(t==2)cout<<4000*n<<endl;
        else if(t==3)cout<<3000*n<<endl;
        else cout<<2000*n<<endl;
    }
}



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

int main() {
    int A, B, res = 0;
    int Z[5] = {{ }};
    cin >> A >> B;

    for (int i = A; i <= B; i++) {
        int tmp = i;
        for (int j = 0; j < 5; j++) {
            Z[j] = tmp % 10;
            tmp /= 10;
        }
        if (Z[0] == Z[4] && Z[1] == Z[3]) res++;
    }

    cout << res << endl;
}

Measured memory_bytes: 3604
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
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 = Integer.parseInt(sc.next());
        List<List<Pair>> graph = new ArrayList<>();
        for(int i = 0; i < n; i++){
            graph.add(new ArrayList<>());
        }
        for(int i = 0; i < n-1; i++){
            int s = Integer.parseInt(sc.next());
            int t = Integer.parseInt(sc.next());
            int w = Integer.parseInt(sc.next());
            graph.get(s).add(new Pair(t, w));
            graph.get(t).add(new Pair(s, w));
        }
        
        ArrayDeque<Integer> queue = new ArrayDeque<>();
        int[] dist = new int[n];
        Arrays.fill(dist, -1);
        dist[0] = 0;
        queue.add(0);
        int x = 0;
        
        while(!queue.isEmpty()){
            int u = queue.poll();
            for (Pair v : graph.get(u)) {
                if(dist[v.id] == -1){
                    dist[v.id] = dist[u] + v.w;
                    if(dist[v.id] > dist[x]) x = v.id;
                    queue.add(v.id);
                }
            }
        }
        
        Arrays.fill(dist, -1);
        dist[x] = 0;
        queue.add(x);
        int y = 0;
        
        while(!queue.isEmpty()){
            int u = queue.poll();
            for (Pair v : graph.get(u)) {
                if(dist[v.id] == -1){
                    dist[v.id] = dist[u] + v.w;
                    if(dist[v.id] > dist[y]) y = v.id;
                    queue.add(v.id);
                }
            }
        }
        
        System.out.println(dist[y]);
    }
    
    static class Pair {
        int id;
        int w;

        public Pair(int id, int w) {
            this.id = id;
            this.w = w;
        }
    }
}


Measured memory_bytes: 97436
/**
 *    author:  abhishekvtangod
 *    created: 
**/

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

#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define debug(x) cerr<<#x<<": "<<x<<" "<< endl;

typedef long long int ll;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// oset<pair<ll,ll>> indexed_set;

// struct HASH{
//   size_t operator()(const pair<int,int>&x)const{
//     return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
//   }
// };

void solve(){
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n);
	int dp[n][3];
	for(int i =0; i < n;i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	for(int i =0;i<n;i++){
		for(int j =0;j<3;j++){
			dp[i][j] = 0;
 		}
	}
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];

	for(int i =1;i<n;i++){
		dp[i][0] = max({dp[i-1][1],dp[i-1][2]}) + a[i];
		dp[i][1] = max({dp[i-1][0],dp[i-1][2]}) + b[i];
		dp[i][2] = max({dp[i-1][1],dp[i-1][0]}) + c[i];
	
		// cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << " " << endl;
	}

	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;


}


int main()
{   
	IOS;

	#ifndef ONLINE_JUDGE
		freopen("C:\\Users\\Thangod\\Desktop\\zAbhi\\input.txt", "r", stdin);
		freopen("C:\\Users\\Thangod\\Desktop\\zAbhi\\output.txt", "w", stdout);
	#endif


	// ll t;cin>>t;
	// while(t--){
		solve();
	// }
	

    return 0;
}

Measured memory_bytes: 5580
from itertools import accumulate
N,M = map(int,input().split())
A = list(map(int,input().split()))
As = [0]
for i in accumulate(A):
    As.append(i%M)
count = {}
ans = 0
for i in As:
    if i not in count:
        count[i] = 1
    else:
        ans += count[i]
        count[i] += 1
print(ans)

Measured memory_bytes: 17236
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int suu(char n) {
	return n-'0';
}

int main() {
	int n,a,b;
	cin >> n >> a >> b;
	if(abs(a-b)%2==0) {
		cout << "Alice" << endl;
	}
	else cout << "Borys" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <type_traits>
#include <vector>


template<uint32_t mod> class Residue_Field {
public:
    uint32_t num = 0;
    Residue_Field() { }
    Residue_Field(const Residue_Field &x) : num(x.num) { }
    template<class T> Residue_Field(T x) {
        using Int = std::conditional_t<sizeof(T) >= 4, T, int32_t>;
        Int y = x;
        y %= static_cast<Int>(mod);
        if(y < 0) y += mod;
        num = static_cast<uint32_t>(y);
    }
    Residue_Field& operator+=(Residue_Field x) {
        num += x.num;
        if(num >= mod) num -= mod;
        return *this;
    }
    Residue_Field& operator-=(Residue_Field x) {
        if(num < x.num) num += mod;
        num -= x.num;
        return *this;
    }
    Residue_Field& operator*=(Residue_Field x) {
        num = static_cast<uint64_t>(num) * x.num % mod;
        return *this;
    }
    Residue_Field& operator/=(Residue_Field x) {
        return *this *= x.inv();
    }
    Residue_Field operator+(Residue_Field x) const { return Residue_Field(*this) += x; }
    Residue_Field operator-(Residue_Field x) const { return Residue_Field(*this) -= x; }
    Residue_Field operator*(Residue_Field x) const { return Residue_Field(*this) *= x; }
    Residue_Field operator/(Residue_Field x) const { return Residue_Field(*this) /= x; }
    Residue_Field pow(uint64_t x) const {
        Residue_Field ans = 1, cnt = *this;
        while(x){
            if(x & 1) ans *= cnt;
            cnt *= cnt;
            x >>= 1;
        }
        return ans;
    }
    Residue_Field inv() const { return pow(mod - 2); }
};

int main(){
    using Mint = Residue_Field<998244353>;
    
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;
    
    std::vector dp(c + 1, std::vector<Mint>(d + 1));
    dp[a][b] = 1;
    
    for(int i = a; i <= c; i++) for(int j = b; j <= d; j++){
        dp[i][j] += dp[i - 1][j] * j + dp[i][j - 1] * i -  dp[i - 1][j - 1] * (i - 1) * (j - 1);
    }
    
    std::cout << dp[c][d].num << std::endl;
}

Measured memory_bytes: 38500
#include <stdio.h>
 
int main(){
  int n, min=1000000000, max=0, tmp;
  scanf ("%d", &n);
  
  for (int i=0;i<n;i++) {
    scanf ("%d ", &tmp);
    if (tmp > max)
      max = tmp;
    if (tmp < min)
      min = tmp;
  }
  printf ("%d\n", max - min);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
int a,b,c;
cin>>a>>b>>c;
int k;
cin>>k;
int ans=0;
int d=max({a,b,c});
int e=d*pow(2,k);
ans=a+b+c-d+e;
cout<<ans<<endl;
}

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

int main(void) {
    int A,B,C,D;cin>>A>>B>>C>>D;
    int AB = A + B;
    int CD = C + D;
    if (AB > CD) cout << "Left" << endl;
    else if (AB < CD) cout << "Right" << endl;
    else cout << "Balanced" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
int main(){
	int n;
	cin>>n;
	vector<pi>arr(n);
	for(int i=0; i<n; i++) cin>>arr[i].second>>arr[i].first;
	sort(arr.begin(),arr.end());
	ll curr = 0;
	for(int i=0; i<n; i++){
		curr+=arr[i].second;
		if(curr>arr[i].first){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
}

Measured memory_bytes: 6384
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,K = map(int, input().split())

    ans = 0
    for i in range(1,N+1):
        j=0
        while i<<j < K:
            j += 1
        ans += 1/((2**j)*N)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3952