akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator<< (ostream &out, const vector<int> &b) {
    for (auto k : b) out << k << " ";
    return out;
}

istream& operator>> (istream& in, pii& b) {
    in >> b.first >> b.second;
    return in;
}

ostream& operator<< (ostream& out, const pii& b) {
    out << "{" << b.first << ", " << b.second << "}";
    return out;
}

template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 10;
#else
    #define dbg(x) 57
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 179;
#endif

const ld PI = acos(-1);

#define time clock() / (double) CLOCKS_PER_SEC

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")  
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int w, h;
    cin >> w >> h;
    vector<int> a(w), b(h);
    for (int i = 0; i < w; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < h; i++) {
        cin >> b[i];
    }
    vector<pii> c;
    for (int i = 0; i < w; i++) {
        c.pb({a[i], 0});
    }
    for (int i = 0; i < h; i++) {
        c.pb({b[i], 1});
    }
    vector<int> lft = {w, h};
    sort(all(c));
    int ans = 0;
    for (int i = 0; i < w + h; i++) {
        ans += c[i].first * (1 + lft[!c[i].second]);
        lft[c[i].second]--;
    }
    cout << ans << "\n";
}
/*

*/

Measured memory_bytes: 9040
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
constexpr ll TEN(ll n){return n==0?1:10ll*TEN(n-1);}

constexpr ll inf = TEN(9)+5;
constexpr ll linf = 3*TEN(18);

signed main()
{
    int N; cin >> N;
    vector<pii> D(N);
    rep(i, N) {
        cin >> D[i].first >> D[i].second;
    }

    bool f = false;

    rep(i, N - 2) {
        int cnt = 0;
        rep(j, 3) {
            if (D[i+j].first == D[i+j].scd) cnt++;
        }
        if (cnt==3)f=true;
    }
    puts(f?"Yes":"No");
}


Measured memory_bytes: 3616
def main():
    import sys
    input = lambda:sys.stdin.readline().strip()
    
    N = int(input())
    A = list(map(int,input().split()))

    #大きいほうから数える
    #調和級数なので計算量はOlogN
    ans = [0]*N
    for i in range(N,0,-1):
        tmp = 0
        if N//i == 1:
            ans[i-1] = A[i-1]
        else:
            max_n = N//i
            for j in range(1,max_n):
                tmp += ans[i*(j+1)-1]
            tmp%=2

            ans[i-1] = tmp^A[i-1]

    ans_n = 0
    ans_li = []
    for i in range(N):
        if ans[i]==1:
            ans_n+=1
            ans_li.append(i+1)

    print(ans_n)
    print(*ans_li)

if __name__=='__main__':
    main()

Measured memory_bytes: 98344
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   

int main(){
    std::ios::sync_with_stdio(false);
    ll a,b,c,mini=inf,sum;
    mini*=mini;
    cin>>a>>b>>c;
    ll x,y,i,aa;
    cin>>x>>y;
    rep(i,y+10){
    	sum=2*i*c;
    	aa=x-i;
    	if(aa>0){
    		sum+=aa*a;
    	}
    	aa=y-i;
    	if(aa>0){
    		sum+=aa*b;
    	}
    	mini=min(mini,sum);

    }
    cout<<mini<<endl;
    return 0;  
    
}



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

int main(void){
  int n, input, ice[10];
  int i, j;

  memset(ice,0,sizeof(ice));

  while(1){
    scanf("%d",&n);
    
    if(n==0){
	break;
    }
    
    for(i=0;i<n;i++){
      scanf("%d",&input);
      ice[input] += 1;
    }

    for(i=0;i<10;i++){
      for(j=0;j<=ice[i];j++){
	if(ice[i]==0){
	  printf("-");
	}else if(ice[i]==j){
	  break;
	}else{
	  printf("*");
	}
      }
      printf("\n");
    }

    memset(ice,0,sizeof(ice));
    
    n--;
  }

  return 0;

}

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

int main() {
  int n, d;
  cin >> n >> d;
  int ans = (n+2*d)/(2*d+1);
  cout << ans << endl;
  return 0;
}

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

int main()
{
	int n, q;
	string s;
	cin >> n >> s >> q;
	for (int t = 0; t < q; t++)
	{
		int k;
		cin >> k;
		//output k-DMC
		int64_t d = 0, m = 0, dm = 0, dmc = 0;
		for (int i = 0, j = 0; j < n;)
		{
			while (k <= j - i)
			{
				if (s[i] == 'D')
				{
					d--;
					dm -= m;
				}
				if (s[i] == 'M')
				{
					m--;
				}
				i++;
			}
			while (j < n && j - i < k)
			{
				if (s[j] == 'D')
				{
					d++;
				}
				if (s[j] == 'M')
				{
					m++;
					dm += d;
				}
				if (s[j] == 'C')
				{
					dmc += dm;
				}
				j++;
			}
		}
		cout << dmc << endl;
	}
	return 0;
}

Measured memory_bytes: 1412
//ABC156B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	long long int n, k;
	cin >> n >> k;
	int ans = 0;
	while(n > 0){
		ans++;
		n /= k;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def sqrt(x):
    epsilon = 10**(-15)
    guess = x / 2.0
    while abs(guess**2-x)>=epsilon:
        guess = guess - ((guess**2-x)/(2*guess))
    return guess


def main():
    a, b, c = LI()
    if 4 * a * b < (c - a - b) ** 2 and c - a - b >= 0:
        print('Yes')
    else:
        print('No')

main()



Measured memory_bytes: 5460
from collections import deque
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
t = dict()
for i in range(1, n+1):
    t[i] = set()
for a, b in ab:
    t[a].add(b)
    t[b].add(a)

q = deque()
s = set()
ans = 0
for i in range(1, n+1):
    if i not in s:
        q.append(i)
        s.add(i)
        tmp = [i]
        while q:
            v = q.popleft()
            for ti in t[v]:
                if ti not in s:
                    tmp.append(ti)
                    q.append(ti)
                    s.add(ti)
    ans = max(ans, len(tmp))
print(ans)


Measured memory_bytes: 124336
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
//ll MOD = 1000000007;
ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
ll A,B;
int bitA[65],bitB[65];
int main(){
	cin>>A>>B;
	ll tempA=A;
	ll tempB=B;
	rep(i,65){
		bitA[i]=tempA%2;
		tempA/=2;
		bitB[i]=tempB%2;
		tempB/=2;
	}
	int memo=-1;
	rep(i,65){
		if(bitA[i]!=bitB[i])memo=i;
	}
	ll base=1;
	if(memo==-1){
		cout<<1<<endl;
		return 0;
	}
	rep(i,memo)base*=2;
	ll x=B%base;
	ll y=A%base;
	int memo2=-1;
	rep(i,memo){
		if(bitB[i]==1)memo2=i;
	}
	ll xdash=0;
	rep(i,memo2+1)xdash=xdash*2+1;
	//cout<<x<<" "<<xdash<<" "<<y<<endl;
	ll ans;
	if(xdash<y){
		ans=xdash+base-y+1+base-1-y+1;
	}else{
		ans=base*2-1-y+1;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <queue>
#include <iomanip>
#include <iterator>

#define MOD 1000000007
#define INF 1000000001

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const queue<T>&obj) {
    queue<T> obj_cp = obj;
    bool first = true;
    o << "{";
    while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; }
    o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}


int main(int argc, char const *argv[]) {
    int S, W;
    cin >> S >> W;
    if (W >= S) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
import sys

def main():
    K = int(sys.stdin.readline())
    
    if K%2==0:
        print(-1)
        return
    
    if K % 7:
        L = 9*K
    else:
        L = 9*K//7
    a = 1
    for i in range(1,L+1):
        a = (a * 10) % L
        if a == 1:
            print(i)
            return
    print(-1)
main()

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, a;
	cin >>n >>a;
	VI p(n);
	rep(i, n) cin >>p[i];
	int sm = accumulate(all(p), 0);
	
	vector<VL> dp(n+2, VL(sm +10));
	dp[0][0] =1;
	rep(i, n) repr(j, n, 0) rep(k, sm) if(dp[j][k]>0){
		if(k + p[i] <= sm){
			dp[j+1][k+p[i]] += dp[j][k];
		}
	}
	
	ll ans =0;
	rep2(i, 1, n+1) if(i*a <= sm){
		ans += dp[i][i*a];
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 1280
from bisect import bisect_right
def solve(n, a):
    ans = 1
    L = [-a[0]]
    for i in range(1, n):
        x = -a[i]
        if x >= L[-1]:
            ans += 1
            L.append(x)
        else:
            L[bisect_right(L, x)] = x
    return ans

n = int(input())
a = [int(input()) for i in range(n)]
print(solve(n, a))

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

int main()
{
    int a[5];
    for(int i = 0; i< 5; i++)cin >> a[i];
    int k;
    cin >> k;
    sort(a, a+5);
    for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < 5; j++)
        {
            if(abs(a[i]-a[j])>k)
            {
                cout << ":(";
                return 0;
            }
        }
    }
    cout << "Yay!";
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <limits.h>

#ifndef KOTAISUU
#define KOTAISUU 40
#endif
#ifndef SEDAISUU
#define SEDAISUU 5000
#endif
#ifndef KAKURITU
#define KAKURITU 10
#endif

static unsigned int x=123456789;
static unsigned int y=362436069;
static unsigned int z=521288629;
static unsigned int w=88675123;

void seed(unsigned int a,unsigned int b,unsigned int c,unsigned int d) {
	if((a|b|c|d)==0)return;
	x=a;y=b;z=c;w=d;
}

unsigned int randint(void) {
	unsigned int t;
	t=(x^(x<<11));
	x=y;y=z;z=w;
	w=(w^(w>>19))^(t^(t>>8));
	return w;
}

unsigned int randint2(unsigned int max) {
	unsigned int amari = ((UINT_MAX % max) + 1) % max;
	unsigned int ret;
	do {
		ret = randint();
	} while (ret < amari);
	return ret % max;
}

#define KIND 26
#define MAX 400

struct horieyui {
	int mamegu[MAX];
};

int D;
int c[KIND];
int s[MAX][KIND];

int mizuhasu(const struct horieyui* kitaeri) {
	int sumipe = 0;
	int i, j;
	int last[KIND] = {0};
	for (i = 0; i < D; i++) {
		sumipe += s[i][kitaeri->mamegu[i]];
		last[kitaeri->mamegu[i]] = i + 1;
		for (j = 0; j < KIND; j++) {
			sumipe -= c[j] * ((i + 1) - last[j]);
		}
	}
	return sumipe;
}

int main(void) {
	int i, j;
	struct horieyui otehon;
	struct horieyui saikyou;
	int saikyou_score;
	if (scanf("%d", &D) != 1) return 1;
	for (i = 0; i < KIND; i++) {
		if (scanf("%d", &c[i]) != 1) return 1;
	}
	for (i = 0; i < D; i++) {
		for (j = 0; j < KIND; j++) {
			if (scanf("%d", &s[i][j]) != 1) return 1;
		}
	}

	for (i = 0; i < D; i++) otehon.mamegu[i] = randint2(KIND);
	saikyou = otehon;
	saikyou_score = mizuhasu(&saikyou);

	for (i = 0; i < SEDAISUU; i++) {
		struct horieyui saituyo;
		int saituyo_score = 0;
		for (j = 0; j < KOTAISUU; j++) {
			struct horieyui kore = otehon;
			int k;
			int score;
			for(k = 0; k < D; k++) {
				if (randint2(100) < KAKURITU) {
					kore.mamegu[k] = randint2(KIND - 1);
					if (kore.mamegu[k] >= otehon.mamegu[k]) kore.mamegu[k]++;
				}
			}
			score = mizuhasu(&kore);
			if (j == 0 || score > saituyo_score) {
				saituyo = kore;
				saituyo_score = score;
			}
		}
		otehon = saituyo;
		if (saituyo_score > saikyou_score) {
			saikyou = saituyo;
			saikyou_score = saituyo_score;
		}
	}
	for (i = 0; i < D; i++) {
		printf("%d\n", saikyou.mamegu[i] + 1);
	}
#ifdef PRINT_SCORE
	printf("score = %d\n", saikyou_score < -1000000 ? 0 : 1000000 + saikyou_score);
#endif
	return 0;
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep_ll(i,n) for(ll i = 0; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<char>> s(h,vector<char>(w));
    rep(i, h){
        rep(j, w) cin >> s[i][j];
    }
    int ans=0;
    rep(i, h){
        rep(j, w){
            if(s[i][j]=='#') continue;
            queue<pair_> list;
            vector<vector<int>> dist(h, vector<int>(w, INF));
            list.emplace(i, j);
            //list.push(pair_(i, j));
            dist[i][j]=0;
            while(!list.empty()){
                int i_=list.front().first;
                int j_=list.front().second;
                list.pop();
                rep(dir, 4){
                    int nx=i_+dx[dir];  int ny=j_+dy[dir];
                    if(nx<0||nx>=h) continue;
                    if(ny<0||ny>=w) continue;
                    if(s[nx][ny]=='#') continue;
                    if(dist[nx][ny]!=INF) continue;
                    list.emplace(nx, ny);
                    //list.push(pair_(i, j));
                    dist[nx][ny]=dist[i_][j_]+1;
                }
            }
            rep(_i, h){
                rep(_j, w){
                    if(dist[_i][_j]==INF) continue;
                    ans = max(ans, dist[_i][_j]);
                }
            }
        }
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
import numpy as np
from numba import njit
  
# @njit('(i4[::1],)', cache=True)
# @njit
@njit(cache = True)
def solve(A):
    count = np.zeros(10**6 + 10, np.int32)
    for x in A:
        if count[x] > 1:
            continue
        count[::x] += 1
    ret = 0
    for x in A:
        ret += count[x] == 1
    return ret

N = int(input())
A = np.array(list(map(int,input().split())), np.int32)
 
print(solve(A))


Measured memory_bytes: 123320
# import sys
# input = sys.stdin.readline
import numpy as np


def main():
    N, K = map(int, input().split())
    ps = np.array(list(input().split()), dtype=int)
    ps = (ps + 1) / 2

    s_list = [0 for _ in range(N)]

    left = 0
    right = K
    s_list[0] = sum(ps[left:right])

    maximum = s_list[0]

    for i in range(1, N):
        left = ps[i-1]

        p_right = K + i - 1
        if p_right >= N:
            right = 0
        else:
            right = ps[p_right]

        s_list[i] = s_list[i-1] - left + right
        maximum = max(maximum, s_list[i])

    return maximum


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


Measured memory_bytes: 31004
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        in.nextLine();
        final int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        Arrays.sort(arr);
        final int max = arr[n - 1];
        final boolean[] sieve = new boolean[max + 1];
        Arrays.fill(sieve, true);
        for (int num : arr) {
            for (int p = 2 * num; p <= max; p += num) {
                sieve[p] = false;
            }
        }
        final Set<Integer> res = new HashSet<>();
        final Set<Integer> remove = new HashSet<>();
        for (int num : arr) {
            if (sieve[num]) {
                if (!res.add(num)) {
                    remove.add(num);
                }
            }
        }
        System.out.println(res.size() - remove.size());
    }
}


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

typedef long long ll;
typedef pair<int,int> P;

int main(){
        char s[300];
        while(true){
                fgets(s,300,stdin);
                if(s[0]=='.'&&s[1]=='\n')return 0;
                stack<char> t;
                bool ok=false;
                for(int i=0;s[i]!='\0'&&s[i]!='\n';i++){
                        if(s[i]=='(')t.push(s[i]);
                        else if(s[i]==')'){
                                if(t.empty()||t.top()!='('){
                                        cout<<"no"<<endl;
                                        ok=true;
                                        break;
                                }
                                t.pop();
                        }
                        if(s[i]=='[')t.push(s[i]);
                        else if(s[i]==']'){
                                if(t.empty()||t.top()!='['){
                                        cout<<"no"<<endl;
                                        ok=true;
                                        break;
                                }
                                t.pop();
                        }
                }
                if(!ok){
                        if(t.empty())cout<<"yes"<<endl;
                        else cout<<"no"<<endl;
                }
        }
        return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int i, j;
    long dp[100005][3] = {};
    long a, b, c;
    for(i = 1; i <= N; i++){
        cin >> a >> b >> c;
        dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a;
        dp[i][1] = max(dp[i-1][2],dp[i-1][0])+b;
        dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c;
    }
    cout << max(max(dp[N][0],dp[N][1]),dp[N][2]) << endl;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
using namespace std ;
using ll = long long ;

int main(){
	string s ; cin >> s ;
	ll ans = 0 ;
	for(int i=1;i<s.size();i++){
		if(s.at(i)==s.at(i-1)){
			ans++ ;
			if(s.at(i)=='1') s.at(i) = '0' ;
			else s.at(i) = '1' ;
		}
	}
	cout << ans << endl ;
}


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

public class Main {
	public static boolean safetyJudge(String[] oldarray, String[] newarray) {
		for (int i = 1; i < newarray.length; i++) {
			if (newarray[i].charAt(1) != newarray[i-1].charAt(1)) continue;
			if (Arrays.asList(oldarray).indexOf(newarray[i]) < Arrays.asList(oldarray).indexOf(newarray[i-1]))
				return false;
		}
		return true;
	}
	
	public static String[] bubbleSort(String[] oldarray, int n) {
		String[] newarray = oldarray.clone();
		boolean flag = true;
		String tmp;
		while (flag) {
			flag = false;
			for (int j = n - 1; j > 0; j--) {
				if (newarray[j].charAt(1) - '0' < newarray[j-1].charAt(1) - '0') {
					tmp = newarray[j]; newarray[j] = newarray[j-1]; newarray[j-1] = tmp;
					flag = true;
				}
			}
		}
		return newarray;
	}
	
	public static String[] selectionSort(String[] oldarray, int n) {
		String[] newarray = oldarray.clone();
		int minj;
		String tmp;
		for (int i = 0; i < n; i++) {
			minj = i;
			for (int j = i; j < n; j++) {
				if (newarray[j].charAt(1) - '0'< newarray[minj].charAt(1) - '0') minj = j;
			}
			if (minj != i) {
				tmp = newarray[i]; newarray[i] = newarray[minj]; newarray[minj] = tmp;
			}
		}
		return newarray;
	}
	
	public static void print(String[] oldarray, String[] newarray) {
		for (int i = 0; i < newarray.length; i++) {
			System.out.print(newarray[i]);
			if (i < newarray.length - 1) System.out.print(" ");
		}
		System.out.println();
		if (safetyJudge(oldarray, newarray))
			System.out.println("Stable");
		else
			System.out.println("Not stable");
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		String str = sc.nextLine();
		String[] array = new String[n];
		array = str.split(" ", 0);
		String[] bsortarray = bubbleSort(array, n);
		String[] ssortarray = selectionSort(array, n);
		print(array, bsortarray); print(array, ssortarray);
	}
}



Measured memory_bytes: 26332
#include<iostream>
using namespace std;
string s;
int cnt,a,b;
main(){
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='S')a++;
        else if(a!=0 and s[i]=='T')b++;
        if(a+b>=2 and b>=1)cnt++,a--,b--;
    }
    cout<<s.size()-2*cnt<<endl;
}

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

const int MOD = 1e9 + 7;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w;
    cin >> h >> w;
    vector<int> paths(w+1);
    paths[1] = 1;
    for (int i = 0; i < h; i++) {
        string row;
        cin >> row;
        for (int j = 1; j <= w; j++) {
            if (row[j-1] == '#') {
                paths[j] = 0;
            }
            else {
                paths[j] += paths[j-1];
            }
            if (paths[j] >= MOD) paths[j] -= MOD;
        }
    }
    
    cout << paths[w] % MOD << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n+10);
  rep(i,n) cin >> a[i];
  int count = 0;
  rep(i,n-1){
    if(a[i] == a[i+1]){
      ++count;
      a[i+1] = 101;
    }
  }
  cout << count << endl;
  return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll a,b,c;
    cin>>a>>b>>c;
    ll k;
    cin>>k;
    while(b<=a&&k>0)
    {
        b=b*2;
        k--;
    }
    while(c<=b&&k>0)
    {
        c=c*2;
        k--;
    }
    if(c>b&&b>a)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<":\n";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3648
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

// 頂点数V, 辺の数E
const ll MAX_E = 100 * 100;
ll V, E;
ll d[100][100];
ll a[MAX_E], b[MAX_E], c[MAX_E];
ll raw[100][100];

// v: 頂点数, d: 頂点間距離
void warshall_floyd() {
    rep(k, V)rep(i, V)rep(j, V) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

void solve() {
    rep(i, V) d[i][i] = 0;

    warshall_floyd();
    ll ans = 0;
    rep(i, E) {
        if (d[a[i]][b[i]] != c[i]) ans++;
    }
    cout << ans << endl;
}


int main() {
    fill(d[0], d[100], inf);
    cin >> V >> E;
    rep(i, E) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
        d[a[i]][b[i]] = c[i];
        d[b[i]][a[i]] = c[i];
//        raw[a][b] = c;
//        raw[b][a] = c;
    }
    solve();
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

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

    string S;
    cin >> S;

    // int output = 0;
    // int before = 1;
    // while (before != output) {
    // int index = 0;
    // before = output;

    // while (index < N) {
    // int b = 0, w = 0;
    // while (S[index] == '#') {
    // b++;
    // index++;
    // }
    // while (S[index] == '.') {
    // w++;
    // index++;
    // }
    // output += min(b, w);
    // }
    // }

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

    int b = 0, w = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == '#') {
            b++;
        } else {
            w++;
        }
        b_acc[i + 1] = b;
        w_acc[N - i - 1] = w;
    }
    vector<int> w_tmp = w_acc;
    for (int i = 0; i < N; i++) {
        w_acc[N - i] = w - w_tmp[i];
    }

    int output = N;
    for (int i = 0; i < N + 1; i++) {
        output = min(output, b_acc[i] + w_acc[i]);
    }

    cout << output << endl;

    return 0;
}


Measured memory_bytes: 6028
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);

		ArrayList<String> list = new ArrayList<String>();

		for (int i = 0; i < 10001; i++) {
			list.add(br.readLine());
			if ("0".equals(list.get(i))) {
				for (int j = 1; j < list.size(); j++) {
					System.out.println("Case "+j+": "+list.get(j-1));
				}
				break;
			}
		}
	}
}

Measured memory_bytes: 32060
N = int(input())
table = [[0] * 10 for _ in range(10)]
for i in range(1,N+1):
    start = int(str(i)[0])
    end = int(str(i)[-1])
    table[start][end] += 1
ret = 0
for i in range(1, N+1):
    start = int(str(i)[0])
    end = int(str(i)[-1])
    ret += table[end][start]
print(ret)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    cout<<(N-1)/2<<endl;
}

Measured memory_bytes: 256
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { N: number, A: number[], B: number[], C: number[] } => {
  const N = +lines[0]
  const A = lines[1].split(' ').map(line => +line)
  const B = lines[2].split(' ').map(line => +line)
  const C = lines[3].split(' ').map(line => +line)
  const obj = { N, A, B, C }
  debug(obj)
  return obj
}
// solver
export const solve = (lines: string[]): string => {
  const { N, A, B, C } = parseLines(lines)
  let lastOrder = null
  let satisfiedCounter = 0
  for (let i = 0; i < N; i++) {
    const order = A[i] - 1
    satisfiedCounter += B[order]

    if (lastOrder !== null && lastOrder + 1 === order) {
      satisfiedCounter += C[order - 1]
    }

    lastOrder = order
  }

  return `${satisfiedCounter}`
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


Measured memory_bytes: 7500
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

struct edge { int to, cost; };
struct state {
  int cur, card, cost;
  bool operator<(const state& lhs) const {
    return cost > lhs.cost;
  }
};

typedef pair<int,int> P;

const int kInf = 1 << 28;
int C, N, M, S, D;
vector<edge> es[102];
int d[102][12];

int solve() {
  // init
  for (int i = 0; i < 102; ++i)
    for (int j = 0; j < 12; ++j)
      d[i][j] = kInf;
  // dijkstra
  priority_queue<state> Q;
  d[S][C] = 0;
  Q.push((state){S, C, 0});
  while (!Q.empty()) {
    state s = Q.top(); Q.pop();
    if (d[s.cur][s.card] < s.cost)
      continue;
    rep(i,es[s.cur].size()) {
      const edge& e = es[s.cur][i];
      // without ticket
      if (d[e.to][s.card] > s.cost + e.cost) {
        d[e.to][s.card] = s.cost + e.cost;
        Q.push((state){e.to, s.card, s.cost + e.cost});
      }
      // use ticket
      if (s.card > 0 &&
          d[e.to][s.card - 1] > s.cost + (e.cost / 2)) {
        d[e.to][s.card - 1] = s.cost + (e.cost / 2);
        Q.push((state){e.to, s.card - 1, s.cost + (e.cost / 2)});
      }
    }
  }
  return *min_element(d[D], d[D] + 12);
}

int main() {
  while (scanf("%d%d%d%d%d", &C, &N, &M, &S, &D), C) {
    --S; --D;
    rep(i,N) {
      es[i].clear();
    }
    rep(i,M) {
      int a, b, f;
      scanf("%d%d%d", &a, &b, &f);
      --a; --b;
      es[a].push_back((edge){b, f});
      es[b].push_back((edge){a, f});
    }
    printf("%d\n", solve());
  }
  return 0;
}

Measured memory_bytes: 1252
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


@njit('(i4,i4[:])', cache=True)
def solve(N, yaku):

    for i in range(1, N + 1):
        for j in range(i, N + 1, i):
            yaku[j] += 1

    ans = 0
    for i in range(1, N + 1):
        ans += i * yaku[i]

    return ans


def main():

    N = in_n()
    yaku = np.zeros(N + 1, np.int32)
    print(solve(N, yaku))


if __name__ == '__main__':
    main()


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

// #define multitest 1
// #define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

template <typename T>
void add(T &a, T b)
{
	a = (ll(a) + b) % mod;
}

void solve()
{
	int h, w;
	cin >> h >> w;
	vector<string> grid(h);
	for (auto &a : grid)
		cin >> a;
	vector<vector<int>> Dp(h, vector<int>(w));
	Dp[0][0] = 1;
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j)
			for (int x : {i, i + 1})
			{
				int y = j;
				if (x == i)
					y++;
				if (x < h && y < w && grid[x][y] == '.')
					add(Dp[x][y], Dp[i][j]);
				db(i, j, Dp[i][j]);
				db(x, y, Dp[x][y],grid[x][y]);
			}
	cout << Dp[h - 1][w - 1] << '\n';
}

int main()
{
#ifndef Debug
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define int long long
//#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  vector<int> A(N);
  rep(i, N) {
    int a; cin >> a;
    if(i == 0) A[i] = a;
    else A[i] = A[i-1]+a;
  }
  
  int ans = 0;
  
  unordered_map<int,int> map;
  map[0]++;
  rep(i, N) map[A[i]]++;
  for(auto p : map) {
    if(p.second > 1) ans += (p.second*(p.second-1))/2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 10056
# D - I hate Factorization

import numpy
# Z = int(input())

def abc166(X):
    B = 0


    while True:
        # minus
        B = -B
        A5 = X + B ** 5
        A = int(numpy.sign(A5) * numpy.power(numpy.abs(1.0 * A5), 1/5))

        if A5 == A ** 5:
            break

        # plus
        B = -B
        A5 = X + B ** 5
        A5 = X + B ** 5
        A = int(numpy.sign(A5) * numpy.power(numpy.abs(1.0 * A5), 1/5))

        if A5 == A ** 5:
            break

        B += 1

    # print('\t({0}) ^ 5 - ({1}) ^ 5 = {2}'.format(int(A), int(B), A ** 5 - B ** 5))
    print(A, B)

if __name__ == '__main__':
    # for x in range(10 ** 9 - 100, 10 ** 9):
    #     print('-----')
    #     print('x = {0}'.format(x))
    #     abc166(x)
    X = int(input())
    abc166(X)

Measured memory_bytes: 27164
#include<stdio.h>
int main(void){
	int n,temp;
	scanf("%d",&n);
	int a[n];
	for(int i=0;i<n;i++){
		a[i]=0;
	}
	for(int i=0;i<n-1;i++){
		scanf("%d",&temp);
		a[temp-1]++;
	}
	for(int i=0;i<n;i++){
		printf("%d\n",a[i]);
	}
}

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

using namespace std;

int main(void) {
	long long N, M;
	cin >> N >> M;
	long long Lmax = 1, Rmin = N;
	for(int i = 0; i < M; ++i) {
		long long L, R;
		cin >> L >> R;
		if(Lmax < L) Lmax = L;
		if(R < Rmin) Rmin = R;
	}
	cout << max(Rmin - Lmax + 1, 0LL) << '\n';
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long ans=0,a,b,c,n,h,w;
int main(){
  cin >> h >> w;
  char c[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> c[i][j];
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      int cnt=0;
      if(i!=0){
        if(c[i-1][j]=='#'){
          cnt++;
        }
      }
      if(i!=h-1){
        if(c[i+1][j]=='#'){
          cnt++;
        }
      }
      if(j!=0){
        if(c[i][j-1]=='#'){
          cnt++;
        }
      }
      if(j!=w-1){
        if(c[i][j+1]=='#'){
          cnt++;
        }
      }
      if(cnt==0&&c[i][j]=='#'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;
using ll =long long;
const int MOD = 1000000007;

//////検証する数,超えられない数////
long long cine(long long a, long long b) {
	if (a <= b) {
		return a;
	}
	else {
		return b;
	}
};
//vector型の初期化
void vec_initialize(vector<ll>& a, const ll N) {
	ll c;

	for (int i = 0; i < N; i++) {

		cin >> c;
		a.push_back(c);

	}

};

void vec2_initialize(vector<ll>& a, vector <ll>&b, const ll N) {
	ll c,d;

	for (int i = 0; i < N; i++) {

		cin >> c>>d;
		a.push_back(c);
		b.push_back(d);
	}

};

void vec_pair_initialize(vector<pair<ll, ll>>& a, const ll N) {
	ll c, d;
	for (int i = 0; i < N; i++) {
		cin >> c >> d;
		a.push_back(make_pair(c, d));
	}
};

int main() {

	ll N, M;
	vector<pair<ll,ll>>a,c;
	
	cin >> N>> M;
	vec_pair_initialize(a, N);
	vec_pair_initialize(c, M);
	ll mintmp;
	ll tmp;
	ll check;
	for (ll i = 0; i < N; i++) {
		mintmp = pow(10,10);
		check = 0;
		for (ll j = 0; j < M; j++) {
			tmp = labs(a[i].first-c[j].first);
			tmp += labs(a[i].second-c[j].second);
			if (mintmp > tmp) {

				check = j + 1;

			}
			mintmp = min(tmp, mintmp);
			
		}
		
		cout << check<<endl;
	}


}

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

int main(){
    int n;
    cin>>n;
    int cnt=0;
    bool ans=false;
    vector <int> vt(n);

    for (int i=0;i<n;i++){
        cin>>vt.at(i);
        // cout<<vt.at(i)<<endl;
    }
    while(1){
        for (int j=0;j<n;j++){
            if (vt.at(j) % 2 ==1){
                ans=true;
            }
        }
        if(ans) break;
        cnt++;
        // cout<<cnt<<endl;
        
        for(int j=0;j<n;j++) {
                vt.at(j)/=2;
                //cout<<vt.at(j)<<endl;
        
        }
    }
    cout<<cnt<<endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define mod 998244353
typedef long long ll;
#define NMAX 10000000001
int main()
{
    ll n, x, m;
    cin >> n >> x >> m;
    vector<int> id(m,-1);
    vector<int> a;
    int len = 0;
    ll tot = 0;
    while(id[x] == -1){
        a.push_back(x);
        id[x] = len;
        len++;
        tot += x;
        x = x*x % m;
    }

    int c = len - id[x];
    ll s = 0;
    for(int i=id[x]; i<len; i++) s += a[i];

    ll ans = 0;
    if(n<=len){
        rep(i,n) ans += a[i];
    }
    else{
        ans += tot;
        n -= len;
        ans += s*(n/c);
        n %= c;
        rep(i, n) ans += a[id[x]+i];
    }

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

Measured memory_bytes: 3912
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int d,n;
    cin>>d>>n;
    if(d==0){
        if(n==100){
            cout<<101<<endl;
        }else{
            cout<<n<<endl;
        }
    }else if(d==1){
        if(n==100){
            cout<<10100<<endl;
        }else{
            cout<<100*n<<endl;
        }
    }else if(d==2){
        if(n==100){
            cout<<1010000<<endl;
        }else{
            cout<<10000*n<<endl;
        }
    }
    
    
}



Measured memory_bytes: 256
#include <stdio.h>

int main(){
	long long int W,H,x,y;
	scanf("%lld%lld%lld%lld",&W,&H,&x,&y);
	printf("%lf %d",(double)W*(double)(H)/2,x*2==W&&y*2==H);
	return 0;	
}

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

long long int MOD = 998244353;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(K), R(K);
  for (int i = 0; i < K; i++) cin >> L.at(i) >> R.at(i);
  vector<long long int> F(N), A(N);
  for (int i = 0; i < N; i++) {
    if (i == 0) F.at(i) = 1;
    else if (i == 1) F.at(i) = A.at(i);
    else F.at(i) = (F.at(i - 1) + A.at(i)) % MOD;
    for (int j = 0; j < K; j++) {
      if (i + L.at(j) < N) A.at(i + L.at(j)) = (A.at(i + L.at(j)) + F.at(i)) % MOD;
      if (i + R.at(j) + 1 < N) A.at(i + R.at(j) + 1) = (A.at(i + R.at(j) + 1) - F.at(i)) % MOD;
    }
  }
  if (F.at(N - 1) < 0) F.at(N - 1) += MOD;
  cout << F.at(N - 1) << endl;
}

Measured memory_bytes: 6440
from heapq import heappush, heappop

N, Q = map(int, input().split())
l = []
used = set()
q = []

for i in range(N):
    S, T, X = map(int, input().split())
    l.append((S-X, 1, X))
    l.append((T-X, 0, X))

for i in range(Q):
    l.append((int(input()), 2, i))

l.sort()

for pos, m, x in l:
    if m==0:
        used.remove(x)
    elif m==1:
        heappush(q, x)
        used.add(x)
    else:
        while q:
            if q[0] not in used:
                heappop(q)
            else:
                break
        print(q[0] if q else -1)


Measured memory_bytes: 96980