akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 262150
#define inf 2147483647
using namespace std;
struct pos1{int l, r;}pos[N][19];
int n, m, k, w[N], now, dp_l[N], dp_r[N], bin[19], x, ff, sum;
int main(){
	scanf("%d%d", &n, &m);
	bin[0]=1; for(int i=1; i<=18; i++)bin[i]=bin[i-1]<<1;
	for(int i=1; i<=n; i++)scanf("%d", &w[i]); w[0]=w[1]-m-1; w[n+1]=w[n]+m+1;
	k=-1; x=m<<1;
	while(x){
		k++; x>>=1; now=0;
		for(int i=1; i<=n; i++){
			if(w[i]-w[i-1]>x)now=i;
			pos[i][k].l=now;
		}
		pos[n+1][k].r=n;
		now=n+1;
		for(int i=n; i; i--){
			if(w[i+1]-w[i]>x)now=i;
			pos[i][k].r=now;
		}
		pos[0][k].l=1;
	}
	dp_l[0]=0; dp_r[0]=n+1;
	for(int i=1; i<=bin[k]-1; i++){
		dp_l[i]=0; dp_r[i]=n+1;
		for(int j=1; j<=k; j++)if(i&bin[j-1]){
			dp_l[i]=max(dp_l[i], pos[dp_l[i-bin[j-1]]+1][j].r);
			dp_r[i]=min(dp_r[i], pos[dp_r[i-bin[j-1]]-1][j].l);
		}
	}
	sum=0; for(int i=1; i<=n; i++)if(pos[i][0].l==i)sum++;
	if(sum>=k+2){for(int i=1; i<=n; i++)printf("Impossible\n"); return 0;}
	for(int i=1; i<=n; i++)if(pos[i][0].l==i){
		ff=0;
		for(int j=0; j<=bin[k]-1; j++)if(dp_l[j]>=pos[i][0].l-1&&dp_r[bin[k]-1-j]<=pos[i][0].r+1){ff=1; break;}
		for(int j=pos[i][0].l; j<=pos[i][0].r; j++)if(ff)printf("Possible\n"); else printf("Impossible\n");
	}
	return 0;
}

Measured memory_bytes: 35072
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, l;
	scanf("%d%d", &n, &l);
	int total = n * (n-1) / 2 + n * l;
	int best = 1e9, answer = 0;
	for (int i = 0; i < n; i++) {
		int tmp = abs(l + i);
		if (tmp < best) {
			best = tmp;
			answer = total - (l + i);
		}
	}
	printf("%d\n", answer);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
using namespace std;

bool compare(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
    return a.second<b.second;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll tests=1;
    //cin>>tests;
    while(tests--)
    {
        ll n,l,i;
        cin>>n>>l;
        vector<string>a(n);
        for(i=0;i<n;i++)cin>>a[i];
        sort(a.begin(),a.end());
        for (auto x:a)
        cout<<x;
    }
    
    return 0;
}


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

#define FOR(i,s,e) for(int i = (s);i <= (e);i++)

int N;
int M;

vector<int> edges[100010];

int visited[100010];

vector<int> start_v;
vector<int> end_v;

int main()
{
	int a,b;
	cin >> N >> M;
	FOR(i,0,M - 1)
	{
		cin >> a >> b;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	
	start_v.push_back(a);
	end_v.push_back(b);

	visited[a] = 1;
	visited[b] = 1;

	while(true)
	{
		bool suc = true;
		int next;
		int s = start_v[start_v.size() - 1];
		for(int to : edges[s])
		{
			if(visited[to] == 0)
			{
				suc = false;
				next = to;
				break;
			}
		}

		if(suc)
		{
			break;
		}
		else
		{
			start_v.push_back(next);
			visited[next] = 1;
		}
	}
	
	while(true)
	{
		bool suc = true;
		int next;
		int e = end_v[end_v.size() - 1];
		for(int to : edges[e])
		{
			if(visited[to] == 0)
			{
				suc = false;
				next = to;
				break;
			}
		}

		if(suc)
		{
			break;
		}
		else
		{
			end_v.push_back(next);
			visited[next] = 1;
		}
	}
	cout << start_v.size() + end_v.size() << endl;
	for(int i = start_v.size() - 1; i >= 0;i--)
	{
		cout << start_v[i] << " ";
	}
	for(int i : end_v)
	{
		cout << i << " ";
	}

	return 0;
}


Measured memory_bytes: 7160
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
const double eps = 1e-7;
int N, M, K, Q, T;
ll gcd(ll a, ll b) {
	if (b == 0LL) return a;
	return gcd(b, a % b);
}

int main()
{
	int i, j;
	scanf("%d", &N);
	for (i = 1; i <= N; ++i) printf("ACL");
}

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


int main(){
	int label[7];
	cin >> label[1] >> label[2] >> label[3] >> label[4] >> label[5] >> label[6];
	string cmd;
	cin >> cmd;
	
	for(int i = 0;i < 100;i++){
		if(!cmd[i])break;
		if(cmd[i] == 'N'){
			int tmp;
			tmp = label[1];
			label[1] = label[2];
			label[2] = label[6];
			label[6] = label[5];
			label[5] = tmp;
		}
		else if(cmd[i] == 'S'){
			int tmp;
			tmp = label[1];
			label[1] = label[5];
			label[5] = label[6];
			label[6] = label[2];
			label[2] = tmp;
		}
		else if(cmd[i] == 'E'){
			int tmp;
			tmp = label[1];
			label[1] = label[4];
			label[4] = label[6];
			label[6] = label[3];
			label[3] = tmp;
		}
		else if(cmd[i] == 'W'){
			int tmp;
			tmp = label[1];
			label[1] = label[3];
			label[3] = label[6];
			label[6] = label[4];
			label[4] = tmp;
		}
	}
	cout << label[1] << "\n";
	return 0;
}

Measured memory_bytes: 3144
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,ra,re) for((i)=ra;(i)<(re);(i)++)
#define _rep(i,ra,re) for((i)=ra;(i)>(re);(i)--)
#define rep_(i,ra,re) for((i)=ra;(i)<=(re);(i)++)
#define _rep_(i,ra,re) for((i)=ra;(i)>=(re);(i)--)
#define put(n) cout << n << " "; 
#define puts(n) cout << n << endl;
#define pu(n) cout << n;
int i,j,k,l;
static const int MAX_N=10e5;
int a[MAX_N];int ans=0;
int main(void){
	int N;
		cin >> N;
	rep(i,0,N){
		cin >> a[i];
	}
	
	rep(i,1,N-1){
		if(a[i-1]<a[i]&&a[i]<a[i+1])
			ans++;
		else if(a[i-1]>a[i]&&a[i]>a[i+1])
			ans++;
	}
	puts(ans);
	return 0;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
// 自分の得意な言語で
// Let's チャレンジ！！

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
    
  var sum =0;
  var x= parseInt(lines[0],10);
  var y= lines[1];
  for(var i=0;i<=9;i++){
      var xx = y.indexOf(i);
      if(xx !=-1 && xx<=x-3){
          for(var j=0;j<=9;j++){
              var yy = y.indexOf(j,xx+1);
              if(yy !=-1 && yy<=x-2){
                  for(var k=0;k<=9;k++){
                      var zz = y.indexOf(k,yy+1);
                      if(zz != -1){
                          sum++;
                      }
                  }
              }
          }
      }
  }
 console.log(sum);
 
});

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[300005];
//! 引かれる数がN+iの時の最大値
ll S[100005];

int main()
{
    ll N;
    cin >> N;
    REP(i, 3 * N)
    {
        cin >> A[i];
    }
    priority_queue<ll, vector<ll>, function<bool(ll, ll)>> q0([](ll a, ll b) { return a > b; });
    priority_queue<ll, vector<ll>, function<bool(ll, ll)>> q1([](ll a, ll b) { return a < b; });
    ll fs = 0, bs = 0;
    REP(i, N)
    {
        q0.push(A[i]);
        q1.push(A[3 * N - 1 - i]);
        fs += A[i];
        bs += A[3 * N - 1 - i];
        S[i] = 0;
    }
    S[0] = fs;
    S[N] = -bs;

    FOR(i, N + 1, 1)
    {
        {
            ll t = q0.top();
            q0.pop();
            fs -= t;
            t = std::max(t, A[N - 1 + i]);
            fs += t;
            q0.push(t);
            S[i] += fs;
        }
        {
            ll t = q1.top();
            q1.pop();
            bs -= t;
            t = std::min(t, A[2 * N - i]);
            bs += t;
            q1.push(t);
            S[N - i] -= bs;
        }
    }

    ll max = -INF;
    REP(i, N + 1)
    {
        max = std::max(max, S[i]);
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 5100
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define INF 1000000000
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	string s;
	cin>>s;
	int k;
	cin>>k;
	REP(i,k){
		if(s[i]!='1'){
			cout<<s[i]<<endl;
			return 0;
		}
	}
	cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int main()
{
    while(cin>>n)
    {
        int cnt=0;
        for(int i=0;i<n;i++)
        {
            int num;
            cin>>num;
            while(!(num&1))
            {
                cnt++;
                num/=2;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

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


int combination(int n, int r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int main(){
    int L;
    cin >> L;
    long double V;
    V = (long double)(L) / 3.0 * (long double)(L) / 3.0 * (long double)(L) / 3.0;
    cout << fixed;
    cout << setprecision(12) << V << endl;
}



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

int main(){
	int a, b;
	scanf("%d%d", &a, &b);
	if (a <= 0 && 0 <= b){
		puts("Zero");
		return 0;
	}
	if (a > 0){
		puts("Positive");
		return 0;
	}
	puts(b - a & 1 ? "Positive" : "Negative");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<string.h>
using namespace std;

int h,w;

int v[50][50];

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

void calc(int y,int x){
	if(v[y][x]==0) return;
	v[y][x]=0;
	for(int r=0;r<8;r++){
		int nx=x+dx[r],ny=y+dy[r];
		if(nx<0 || ny<0 || nx>=w || ny>=h)
			continue;
		calc(ny,nx);
	}
}


void solve()
{
	memset(v,0,sizeof(v));
	for(int y=0;y<h;y++){
		for(int x=0;x<w;x++){
			int t;cin>>t;v[y][x]=t;
		}
	}
	int res=0;

	for(int y=0;y<h;y++)
		for(int x=0;x<w;x++){
			if(v[y][x]==0) continue;
			res++;
			calc(y,x);
		}
		cout<<res<<endl;
}



int main()
{
	while(cin>>w>>h){
		if(w==0) break;
		solve();
	}
	return 0;
}

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

#define int long long
#define ll long long
#define pb push_back

main(){
    int n;
    cin >> n;
    int ans = n / 500 * 1000;
    n = n % 500;
    ans += n / 5 * 5;
    cout << ans;
}


Measured memory_bytes: 256
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).
*/

f("A", "T").
f("T", "A").
f("G", "C").
f("C", "G").

main :-
    get_string(S),
    f(X, S),
    writeln(X).


Measured memory_bytes: 8040
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

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

    vector<char> t(n, '-');
    cout << 0 << endl;
    string s;
    cin >> s;
    if (s == "Vacant") return 0;
    t[0] = s[0];
    cout << n-1 << endl;
    cin >> s;
    if (s == "Vacant") return 0;
    t[n-1] = s[0];

    int l = 0;
    int r = n-1;

    int cnt = 0;
    while(true) {
        cnt++;
        int m = (l+r)/2;
        debug(m);
        cout << m << endl;
        cin >> s;
        if (s == "Vacant") return 0;
        t[m] = s[0];
        if ((t[l] == t[m] && l%2==m%2) || (t[l] != t[m] && l%2!=m%2)) {
            l = m;
        } else {
            r = m;
        }
        if (cnt>=20) return 1;
    }

}


Measured memory_bytes: 3852
#include<stdio.h>

int r[51];

int main(){
	int N,M;
	scanf("%d%d",&N,&M);
	int a[M],b[M];
	for(int i=0;i<M;i++){
		scanf("%d%d",&a[i],&b[i]);
		r[a[i]]++;
		r[b[i]]++;
	}
	for(int i=1;i<=N;i++)printf("%d\n",r[i]);
	return 0;
}

Measured memory_bytes: 128
[n,m] = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
x = sorted(x)

if n == 1:
    print(max(x) - min(x))
elif n >= m:
    print(0)
else:
    dif = []
    for i in range(m - 1):
        dif.append(x[i+1] - x[i])
    dif = sorted(dif)
    dif = dif[:m-n]
    print(sum(dif))


Measured memory_bytes: 13840
//	-*- mode: C++ -*-
//	Allocation
//		You are given n packages of wi kg from a belt conveyor in order (i=0,1,...n−1). You should load all packages onto k trucks which have the common maximum load P. Each truck can load consecutive packages (more than or equals to zero) from the belt conveyor unless the total weights of the packages in the sequence does not exceed the maximum load P.
//
//		Write a program which reads n, k and wi, and reports the minimum value of the maximum load P to load all packages from the belt conveyor.
//
//	Input
//		In the first line, two integers n and k are given separated by a space character. In the following n lines, wi are given respectively.
//
//	Output
//		Print the minimum value of P in a line.
//
//	Constraints
//		1≤n≤100,000
//		1≤k≤100,000
//		1≤wi≤10,000
//	Sample Input 1
//		5 3
//		8
//		1
//		7
//		3
//		9
//	Sample Output 1
//		10
//		If the first truck loads two packages of {8,1}, the second truck loads two packages of {7,3} and the third truck loads a package of {9}, then the minimum value of the maximum load P shall be 10.
//
//
//	Sample Input 2
//		4 2
//		1
//		2
//		2
//		6
//	Sample Output 2
//		6
//		If the first truck loads three packages of {1,2,2} and the second truck loads a package of {6}, then the minimum value of the maximum load P shall be 6.


#include <iostream>
#include <vector>

const unsigned int	maxN	{100000};
const unsigned int	maxK	{100000};
const unsigned int	maxWi	{10000};

// 最大積載量がpのとき、先頭から順番に積んで何個積むことこができるかを返す
unsigned int	check(unsigned long long		p,
					  unsigned int				n,
					  unsigned int				k,
					  std::vector<unsigned int>	w)
{
	unsigned int	i	{0};

	for(int j = 0; j < k; j++){
		unsigned long long	s	{0};

		while((s + w[i]) <= p){
			s	+= w[i];
			i++;

			if(i == n){		// iがnに達したので全て積めた
				return	n;
			}
		}
	}

	// ここはi個しか積めない場合
	return i;
}

unsigned long long	solve(unsigned int				n,
						  unsigned int				k,
						  std::vector<unsigned int>	w)
{
	unsigned long long	left	{0};
	unsigned long long	right	{maxN * maxWi};		// 最大の個数*重量
	unsigned long long	mid		{0};

	// 二分探索で最大積載量の最小値を求める
	while((right - left) > 1){
		mid	= (left + right) / 2;

		unsigned int	v	= check(mid, n, k, w);
		if(v >= n){
			right	= mid;
		}
		else{
			left	= mid;
		}
	}

	return right;
}

int	main(int	argc,
		 char*	argv[])
{
	unsigned int				n			{0};	// 荷物の個数
	unsigned int				k			{0};	// トラックの台数
	std::vector<unsigned int>	w			{};		// 荷物の重さの配列

	std::cin >> n >> k;

	for(unsigned int i = 0; i < n; i++){
		unsigned int	wi	{0};
		std::cin >> wi;
		w.push_back(wi);
	}

	unsigned long long	ans	= solve(n, k, w);

	std::cout << ans << std::endl;

	return	0;
}



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

int main() {
  int N, copy;
  cin >> N;
  
  int count = 0;
  
  copy = N;
  while (copy) {
    count += copy % 10;
    copy /= 10;
  }
  
  if (N % count == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int main() {
  long long n,m;
  cin >> n >> m;
  if(n > m/2){
    cout << m/2 << endl;
    return 0;
  }
  else{
    cout << n+(m-2*n)/4 << endl;
    return 0;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)

const ll mod = (ll)998244353;
const ll maxn = (ll)2e5+5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};


void solve(){
	
	ll pos = 1;
	string s;
	ll q;
	cin >> s >> q;
	vector < char > st , ed;
	while(q--){
		ll t;
		cin >> t;
		if(t == 1){
			pos *= -1;
			continue;
		}
		ll f;
		char c;
		cin >> f >> c;
		if(f == 2) f = -1;
		f *= pos;
		if(f == 1) st.pb(c);
		else ed.pb(c);
	}
	if(pos == 1){
		reverse(st.begin(),st.end());
		for(auto u : st) cout << u;
		cout << s;
		for(auto u : ed) cout << u;
	}else{
		reverse(s.begin(),s.end());
		reverse(ed.begin(),ed.end());
		for(auto u : ed) cout << u;
		cout << s;
		for(auto u : st) cout << u;
	}
	return;
}


int main() {
   
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
   // cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}
    
    return 0;
}


Measured memory_bytes: 976
p = [map(int, raw_input().split()) for _ in xrange(input())]
ct, cx, cy = 0, 0, 0
flag = True
for dt, dx, dy in p:
    _ = dx - cx + dy - cy
    if dt < _ or (dt - _) % 2:
        flag = False
        break
print 'Yes' if flag else 'No'


Measured memory_bytes: 18308
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
using namespace std;
using ll = long long;

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

int main()
{

  int n; cin >> n;
  string s; cin >> s;

  if (n%2==1){cout << "No" << endl;}
  else {
    int flag=1;
    rep(i,n/2){
      if (s[i]!=s[i+n/2]){flag=0;break;}
    }
    if (flag==1){cout<<"Yes"<<endl;}
    else {cout << "No" << endl;}
  }


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <tuple>
#include <cstring>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

// #define DEBUG
#ifdef DEBUG
#include <iostream>
#include <iomanip>

void dbg_impl() {
  std::cerr << '\n';
}

template <class Head, class... Tail>
void dbg_impl(const Head& head, const Tail&... tail) {
  std::cerr << ' ' << head;
  dbg_impl(tail...);
}

struct dbg_setup {
  dbg_setup() {
   std::cerr << std::boolalpha;
   std::cerr << std::fixed << std::setprecision(5);
  }
} debug_setup;

#define debug(...)\
  do {\
    std::cerr << std::setw(5) << __LINE__ << "  | ";\
    std::cerr << "[" << #__VA_ARGS__ << "]:";\
    dbg_impl(__VA_ARGS__);\
  } while (false)

#else
#define debug(...) 0
#endif

int N, C;
int L[6], order[6];
long long dp[301][32][301];

int main() {
  scanf("%d %d", &N, &C);
  for (int i: range(0, N)) {
    scanf("%d", &L[i]);
  }
  std::sort(L, L + N);
  int longest = L[N - 1];
  std::iota(order, order + N, 0);
  long double ans = 0;
  do {
    std::memset(dp, 0, sizeof(dp));
    dp[0][0][longest * N] = 1;
    for (int pos: range(0, C * N)) {
      for (int S: range(0, 1 << (N - 1))) {
        for (int done: range(0, C * N + 1)) {
          debug(pos, S, done, dp[pos][S][done]);
          if (pos < done) {
            dp[pos + 1][S][done] += dp[pos][S][done];
          }
          int tmp = pos % N;
          if (tmp != 0) {
            int i = order[tmp] - 1;
            if ((S & (1 << i)) == 0) {
              dp[pos + 1][S | (1 << i)][std::min(C * N, std::max(done, pos + L[i] * N))] += dp[pos][S][done];
            }
          }
        }
      }
    }
    ans += dp[C * N][(1 << (N - 1)) - 1][C * N];
  } while (std::next_permutation(order + 1, order + N));
  for (int i: range(1, N)) {
    ans /= i * C;
  }
  printf("%.20Lf\n", ans);
  return 0;
}


Measured memory_bytes: 22912
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  ll n;
  cin >> n;
  int t = sqrt(n);
  for(int i = t + 1; i >= 1; i--){
    if(n % i == 0){
      cout << i + (n / i) - 2 << endl;
      return 0;
    }
  }
}

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int maxn = 1e5+10;
const int mod = 1e9+7;

using namespace std;

void solve(){
	int x,y,z;
	cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y<<endl;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};

class Solver {
  public:
    int H, W;
    bool in_field(int y, int x) {
        return 0 <= y and y < H and 0 <= x and x < W;
    }
    
    bool solve() {
        cin >> H >> W;
        vector<string> G(H); cin >> G;

        int y = 0, x = 0;
        int py = -1, px = -1;
        while(true) {
            int nxts = 0;
            int nx, ny;
            rep(d, 4) {
                int nnx = x + dx[d];
                int nny = y + dy[d];
                if(in_field(nny, nnx) and (nnx != px or nny != py) and G[nny][nnx] == '#') {
                    if(d != 1 and d != 2) goto FAIL;
                    nxts += 1;
                    nx = nnx;
                    ny = nny;
                }
            }
            if(nxts > 1) goto FAIL;
            if(x == W - 1 and y == H - 1) break;
            if(nxts == 0) goto FAIL;
            py = y;
            px = x;
            y = ny;
            x = nx;            
        }
        cout << "Possible" << endl;
        return 0;
  FAIL:
        cout << "Impossible" << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

i64 gcd(i64 n,i64 m){return m?gcd(m,n%m):n;}
int main(){
    int N;
    cin >> N;
    vector<i64> A(N);
    rep(i,N) cin >> A[i];

    vector<i64> gcd_front(N, A[0]), gcd_back(N, A[N-1]);
    for(int i = 1; i < N; i++) gcd_front[i] = gcd(gcd_front[i-1], A[i]);
    for(int i = N-2; i >= 0; i--) gcd_back[i] = gcd(gcd_back[i+1], A[i]);

    i64 ans = max(gcd_front[N-2], gcd_back[1]);
    for(int i = 1; i < N-1; i++){
        ans = max(ans, gcd(gcd_front[i-1], gcd_back[i+1]));
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
from collections import deque
def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def bfs(field,s):
  MOVE=[(0,1),(1,0),(0,-1),(-1,0)]
  q=deque([(0,s)])
  dist=[[-1]*W for _ in range(H)]
  d,i,j=-1,-1,-1
  while q:
    d,(i,j)=q.popleft()
    if dist[i][j]!=-1:
      continue
    dist[i][j]=d
    for di,dj in MOVE:
      ni,nj=i+di,j+dj
      if not 0<=ni<H or not 0<=nj<W:
        continue
      if dist[ni][nj]!=-1:
        continue
      if field[ni][nj]=='#':
        continue
      q.append((d+1,(ni,nj)))
  return d
ans=0
H,W=MI()
field=[input() for _ in range(H)]
for i in range(H):
  for j in range(W):
    if field[i][j]=='.':
      d=bfs(field,(i,j))
      ans=max(ans,d)
print(ans)

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int turn1, turn2;
  turn1 = (c+b-1)/b;
  turn2 = (a+d-1)/d;
  if(turn1 <= turn2) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int a, b, c;

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

    void run() {
        FastReader sc = new FastReader();
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        solve();
    }

    void solve() {
        if (a == b) {
            System.out.println(c);
        } else if (b == c) {
            System.out.println(a);
        } else {
            System.out.println(b);
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a) (a).begin(), (a).end()

const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T &r, T &l)
{
  T tmp = r;
  r = l;
  l = tmp;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}

int main()
{
  ll n;
  cin >> n;
  vector<ll> p(n);
  cin >> p;

  bool ans = false;

  for (ll i = 0; i < n; i++){

    for (ll j = i; j < n; j++){
      vector<ll> q(p.size());
      copy(p.begin(), p.end(), q.begin());

      ll tmp = 0;
      tmp = q[i];
      q[i] = q[j];
      q[j] = tmp;

      bool tmpans = true;
      for (ll k = 1; k < n; k++)
      {
        if (q[k] < q[k - 1])tmpans = false;
        cerr << q[k] << ",";
      }cerr <<" ans :" << tmpans << endl;
      if (tmpans)ans = true;



    }


  }
  

  cout << ((ans == true) ? "YES" : "NO");
}


Measured memory_bytes: 256
from math import gcd


def eratosthenes(n):
    is_prime = [0, 0] + [1] * (n - 1)
    for i in range(int(n**0.5) + 1):
        if is_prime[i] == 0:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = 0
    return [i for i, pi in enumerate(is_prime) if pi == 1]


def factorize(N):  # 素因数分解
    PRIME = set()
    for p in prime_list:
        if p * p > N:
            break
        while N % p == 0:
            N //= p
            PRIME.add(p)
    if N > 1:
        PRIME.add(N)
    return PRIME


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

ans = 0
for ai in a:
    ans = gcd(ans, ai)
if ans != 1:
    print('not coprime')
    exit()

prime_list = eratosthenes(10 ** 6)
num = set()
for ai in a:
    prime = factorize(ai)
    if len(prime & num) > 0:
        print('setwise coprime')
        break
    num |= prime
else:
    print('pairwise coprime')


Measured memory_bytes: 196828
while True:
    n = int(input())
    if n == 0:break
    sumA = sumB = 0
    for i in range(n):
        c = list(map(int,input().split()))
        if c[0]==c[1]:
            sumA = sumA+c[0]
            sumB = sumB+c[1]
        else:
            sumA = sumA + (c[0]+c[1] if c[0]>c[1] else 0)
            sumB = sumB + (c[0]+c[1] if c[1]>c[0] else 0)
    print(sumA, sumB)

Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
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<ll> vll;

int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  int two = 1;
  rep(i,m) two *= 2;
  cout << ((n-m)*100+m*1900)*two << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
ans=1
if N <=104:
  print(0)
elif N==105 or N==106:
  print(1)
else:
  for i in range(107,N+1,2):
    i_div ={div for div in range(1,i+1) if i%div == 0}
    if len(i_div) == 8:
      ans+=1
  print(ans)

Measured memory_bytes: 3064
#include<iostream>

using namespace std;
#define repeat(i,n) for(int i=0;i<(n);i++)

int v[200];

int main(){

  int a, b, c; cin>> a>> b>> c;

  int x=a%b;
  while(not v[x]){
    v[x]=1;
    (x+=a)%=b;
  }

  if(v[c]) cout<< "YES"<< endl;
  else cout<< "NO"<< endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

typedef vector<vector<bool>> Map;
typedef tuple<pair<int, int>, Map, int> T;

const int h = 20, w = 17;
const int dy[16] = { 0,-1, 0, 1, 1,-1, 1,-1, 0,-2, 0, 2};
const int dx[16] = { 1, 0,-1, 0, 1, 1,-1,-1, 2, 0,-2, 0};

int ans;
Map c;

bool impossible(int y, Map& c){
	vector<bool> no(h,0);
	range(i,y + 1,18){
		bool f = false;
		rep(j,w){
			if(c[i][j]) f = true;
		}
		if(not f) no[i] = true;
	}
	rep(i,h - 1){
		if(no[i] and no[i + 1]) return true;
	}
	return false;
}

map<Map, map<pair<int, int>, int>> memo;

void dfs(int y, int x, int cost){
	if(ans <= cost) return;
	if(memo.count(c) and memo[c].count(make_pair(y,x)) and memo[c][make_pair(y,x)] <= cost) return;
	memo[c][make_pair(y,x)] = cost;

	if(y == 18 or y == 19){
		ans = min(ans, cost);
		return;
	}

	if(impossible(y, c)) return;

	rep(i,8){
		int ny = y + dy[i];
		int nx = x + dx[i];
		if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
		if((nx == 0 && ny <= 18) or (nx == w - 1 && ny <= 18)) continue;
		if(c[ny][nx] == 1){
			vector<pair<int, int>> tmp;
			while(true){
				if(ny < 0 || ny >= h || nx < 0 || nx >= w) {
					ny = -1;
					break;
				}
				if((nx == 0 && ny <= 18) or (nx == w - 1 && ny <= 18)){
					ny = -1;
					break;
				}
				if(c[ny][nx] == 0) break;
				tmp.emplace_back(ny,nx);
				//pc[ny][nx] = 0;
				ny = ny + dy[i];
				nx = nx + dx[i];
			}
			if(ny == -1) continue;

			for(auto i : tmp) c[i.first][i.second] = 0;
			dfs(ny, nx, cost + 1);
			for(auto i : tmp) c[i.first][i.second] = 1;
		}
	}
}

int main(){
	pair<int, int> s;
	c = Map(h, vector<bool>(w));
	rep(i,h - 1){
		rep(j,w - 2){
			char a;
			cin >> a;
			if(a == 'X') c[i][j + 1] = 1;
			else c[i][j + 1] = 0;
			if(a == 'O'){
				s = make_pair(i,j + 1);
			}
		}
	}

	ans = 1e9;
	dfs(s.first, s.second, 0);
	cout << (ans == 1e9 ? -1 : ans) << endl;
}



Measured memory_bytes: 3732
#include <cstdio>
#include <vector>
using namespace std;
typedef vector<int> vi;
#define pb push_back
const int maxn = 100000;
int N,S[maxn]; vi ans;
int main() {
    scanf("%d",&N);
    for (int i = 0;i < N;i++) {
        scanf(" %c",&S[i]);
        if (ans.empty() || ans.back() != S[i]) ans.pb(S[i]);
    }
    printf("%d\n",ans.size());
}

Measured memory_bytes: 1148
L = [list(map(int,input().split())) for k in range(3)]

n = 1
v = [1,0,0,0]
for k in range(10):
    for e in L:
        if e[0] == n and v[e[1]-1] == 0:
            n = e[1]
            v[e[1]-1] = 1
        elif e[1] == n and v[e[0]-1] == 0:
            n = e[0]
            v[e[0]-1] = 1

if min(v) == 1:
    print("YES")
else:
    print("NO")


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

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

int main() {
    int h,w;
    char input;
    int map[50][50]={{0}};
    int out[50][50]={{0}};
    cin >> h >> w;
    for(int j=0;j<h;j++){
        for(int i=0;i<w;i++){
            cin >> input;
            if(input=='#'){
                map[i][j]=1;
            }
        }
    }
    for(int j=0;j<h;j++){
        for(int i=0;i<w;i++){
            if(map[i][j]==1){
                out[i][j]=9;
            }else{
                if(i!=0){
                    if(map[i-1][j]==1){
                        out[i][j]++;
                    }
                    if(j!=0){
                        if(map[i-1][j-1]==1){
                            out[i][j]++;
                        }
                    }
                    if(j!=h-1){
                        if(map[i-1][j+1]==1){
                            out[i][j]++;
                        }
                    }
                }
                if(i!=w-1){
                    if(map[i+1][j]==1){
                        out[i][j]++;
                    }
                    if(j!=h-1){
                        if(map[i+1][j+1]==1){
                            out[i][j]++;
                        }
                    }
                    if(j!=0){
                        if(map[i+1][j-1]==1){
                            out[i][j]++;
                        }
                    }
                }
                if(j!=h-1){
                    if(map[i][j+1]==1){
                        out[i][j]++;
                    }
                }
                if(j!=0){
                    if(map[i][j-1]==1){
                        out[i][j]++;
                    }
                }
            }
        }
    }

    for(int j=0;j<h;j++){
        for(int i=0;i<w;i++){
            if(out[i][j]==9){
                cout << '#';
            }else{
                cout << out[i][j];
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			m = scanner.nextInt();
			n = scanner.nextInt();
			if ((m | n) == 0)
				break;
			M = new HashMap<Integer, Integer>();
			h = 1;
			a = new int[n][m];
			Y = new int[24];
			X = new int[24];
			for (int i = 0; i < n; i++)
				for (int j = 0; j < m; j++) {
					int t = scanner.nextInt();
					if (t == 0) {
						a[i][j] = -1;
					} else if (t == 1) {
						Y[h] = i;
						X[h] = j;
						a[i][j] = h++;
					} else {
						Y[0] = i;
						X[0] = j;
						a[i][j] = 0;
					}
				}
			System.out.println(slove(0, 1));
		}
	}

	private int slove(int cur, int bit) {
		if (Integer.bitCount(bit) <= 15) {
			int k = cur << 24 | bit;
			if (M.containsKey(k))
				return M.get(k);
		}
		int res = 0;
		for (int[] mo : move) {
			int y = Y[cur];
			int x = X[cur];
			while (true) {
				y += mo[0];
				x += mo[1];
				if (!isOK(y, x))
					break;
				if (a[y][x] == 0)
					if (bit == (1 << h) - 1)
						res++;
				if (a[y][x] >= 1) {
					if ((bit >> a[y][x] & 1) == 1)
						continue;
					res += slove(a[y][x], bit | 1 << a[y][x]);
					break;
				}
			}
		}
		if (Integer.bitCount(bit) <= 15)
			M.put(cur << 24 | bit, res);
		return res;
	}

	private boolean isOK(int y, int x) {
		if (0 <= y && y < n && 0 <= x && x < m)
			return true;
		return false;
	}

	int m, n, h;
	int[] Y, X;
	int[][] a;
	int[][] move = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };
	Map<Integer, Integer> M;
}

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

int INF = 100000000;
int H, W, Ch, Cw, Dh, Dw;
vector<vector<char>> S;
vector<vector<int>> d;

vector<int> dx0 = {1, 0, -1, 0}, dy0 = {0, 1, 0, -1};
vector<int> dx1 = {-2, -2, -2, -2, -2, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2};
vector<int> dy1 = {-2, -1, 0, 1, 2, -2, -1, 1, 2, -2, 2, -2, -1, 1, 2, -2, -1, 0, 1, 2};

int bfs() {
  queue<pair<int, int>> Q0, Q1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) d.at(i).at(j) = INF;
  }
  pair<int, int> Pc = make_pair(Ch, Cw);
  Q0.push(Pc);
  d.at(Ch).at(Cw) = 0;
  
  while (Q0.size() != 0 || Q1.size() != 0) {
    if (Q0.size() != 0) {
      pair<int, int> P0 = Q0.front();
      Q0.pop();
      for (int i = 0; i < 4; i++) {
        int nx = P0.first + dx0.at(i), ny = P0.second + dy0.at(i);
        if (nx >= 0 && nx < H && ny >= 0 && ny < W && S.at(nx).at(ny) != '#'
            && d.at(nx).at(ny) > d.at(P0.first).at(P0.second)) {
          pair<int, int> N = make_pair(nx, ny);
          Q0.push(N);
          d.at(nx).at(ny) = d.at(P0.first).at(P0.second);
        }
      }
      for (int i = 0; i < 20; i++) {
        int nx = P0.first + dx1.at(i), ny = P0.second + dy1.at(i);
        if (nx >= 0 && nx < H && ny >= 0 && ny < W && S.at(nx).at(ny) != '#'
            && d.at(nx).at(ny) > d.at(P0.first).at(P0.second) + 1) {
          pair<int, int> N = make_pair(nx, ny);
          Q1.push(N);
          d.at(nx).at(ny) = d.at(P0.first).at(P0.second) + 1;
        }
      }
    }
    else {
      pair<int, int> p = Q1.front();
      Q1.pop();
      Q0.push(p);
    }
  }
  return d.at(Dh).at(Dw);
}

int main() {
  cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
  Ch--;
  Cw--;
  Dh--;
  Dw--;
  S.resize(H);
  d.resize(H);
  for (int i = 0; i < H; i++) {
    S.at(i).resize(W);
    d.at(i).resize(W);
    for (int j = 0; j < W; j++) cin >> S.at(i).at(j);
  }
  int ans = bfs();
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 8636
#include <iostream>
using namespace std;
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a<b)?a:b)
int main() {
	int A,B;
	cin>>A>>B;
	for(int i=B-A+1; i<A+B-1; i++)cout<<i<<" ";
	cout<<A+B-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)

constexpr int mod = 998244353;
template<class T>using V = vector<T>;
template<class T>using V2 = V<V<T>>;

int main(){
  int n, s; cin >> n >> s;
  V<int> a(n); V2<ll> dp1(n+1,V<ll>(s+1,0)), dp2(n+1,V<ll>(s+1,0)), dp3(n+1,V<ll>(s+1,0));
  FOR(i,0,n) cin >> a[i];
  dp1[0][0] = 1;
  FOR(i,0,n){
    FOR(j,0,s+1) {
      dp1[i+1][j] = dp1[i][j];
    }
    FOR(j,0,s+1){
      dp2[i+1][j] += (dp1[i][j] + dp2[i][j]) % mod;
      if( (j+a[i]) <=s) (dp2[i+1][j+a[i]] += dp1[i][j]+dp2[i][j]) %= mod;
    }
    FOR(j,0,s+1){
      (dp3[i+1][j] += (dp3[i][j] + dp2[i][j]+dp1[i][j])%mod) %= mod;
      if( (j+a[i])<=s) (dp3[i+1][j+a[i]] += (dp1[i][j]+dp2[i][j]) ) %= mod;
    }
  }/*
  FOR(i,0,n+1){
    FOR(j,0,s+1) cout << dp1[i][j] << " ";
    cout << "\n";
  }cout << "\n";
  FOR(i,0,n+1){
    FOR(j,0,s+1) cout << dp2[i][j] << " ";
    cout << "\n";
  }cout << "\n";
  FOR(i,0,n+1){
    FOR(j,0,s+1) cout << dp3[i][j] << " ";
    cout << "\n";
  }*/
  cout <<  dp3[n][s];
}




Measured memory_bytes: 211584
#include<bits/stdc++.h> 
using namespace std;
typedef long long int ll;
#define MOD 1000000007
#define fo(i,k,n) for(i=k;i<=n;i++)
#define endl '\n'
ll dp[101][100001];
//memoisation
ll knapsnack(ll* w,ll* v,ll n,ll mw){
	if(dp[n][mw]>-1) return dp[n][mw];
	if(n==0) return 0;//no item left
	if(mw==0) return 0;//no more capacity
	ll op1 = knapsnack(w,v,n-1,mw);
	ll op2 = LLONG_MIN;
	if(w[n-1]<=mw) op2 = v[n-1]+knapsnack(w,v,n-1,mw-w[n-1]);
	return dp[n][mw]=max(op1,op2);
}
//tabulation
ll knapsnacki(ll* w,ll* v,ll n,ll mw){
	ll i,j;
	fo(i,0,mw) dp[0][i]=0;
	fo(i,0,n) dp[i][0]=0;
	fo(i,1,n){
		fo(j,1,mw){
			dp[i][j] = dp[i-1][j];
			if(w[i-1]<=j) dp[i][j] = max(dp[i][j],v[i-1]+dp[i-1][j-w[i-1]]);
		}
	}
	return dp[n][mw];
}
//tabulation memory optimised
ll knapsnacki2(ll* w,ll* v,ll n,ll mw){
	ll i,j;
	ll dp2[2][mw+1];
	fo(i,0,mw) dp2[0][i]=0;
	dp2[1][0]=0;
	ll idx=1;
	fo(i,1,n){
		fo(j,1,mw){
			dp2[idx][j] = dp2[idx^1][j];
			if(w[i-1]<=j) dp2[idx][j] = max(dp2[idx][j],v[i-1]+dp2[idx^1][j-w[i-1]]);
		}
		idx^=1;
	}
	return dp2[idx^1][mw];
}
//for large weights
ll dpi3[100001][101];
ll knapsnacki3(ll* w,ll* v,ll n,ll mw){
	ll i,j;
	for(i=0;i<=n;i++) dpi3[0][i]=0;
	for(i=1;i<=100000;i++) dpi3[i][n]=mw+1;
	for(i=1;i<=100000;i++){
		for(j=n-1;j>=0;j--){
			dpi3[i][j] = dpi3[i][j+1];
			if(i-v[j]>=0) dpi3[i][j] = min(dpi3[i][j],w[j]+dpi3[i-v[j]][j+1]);
		}
	}
	ll ans = 0;
	for(i=0;i<=100000;i++) if(dpi3[i][0]>0&&dpi3[i][0]<=mw) ans = max(ans,i);
	return ans;
}
void solve(){
	ll i,j,n,mw;
	cin>>n>>mw;
	ll* w = new ll[n];
	ll* v = new ll[n];
	fo(i,0,n-1){
		cin>>w[i]>>v[i];
	}
	memset(dp,-1,sizeof(dp));
	cout<<knapsnacki3(w,v,n,mw)<<endl;
	//cout<<knapsnacki2(w,v,n,mw)<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll t;
	t=1;//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 161448
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n,a[110000],bt;
struct nod{
	int x,num;
};
long long ans;
nod b[110000];
int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	fo(i,1,n) if (a[i]>b[bt].x){
		if (b[bt].num==1) bt--;//!!!!!!!
		b[++bt].x=a[i];
		b[bt].num=1;
	}else b[bt].num++;
	fd(i,bt,1) if (b[i].num>=4){
		ans=max(ans,b[i].x*(long long)b[i].x);
		break;
	}
	fd(i,bt,2) if (b[i].num>=2&&b[i-1].num>=2){
		ans=max(ans,b[i].x*(long long)b[i-1].x);
		break;
	}
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std ; 

typedef long long ll ; 

char s[1111] ; 

int main()
{
    scanf("%s", s); 
    int len = strlen(s) ; 
    bool N = false ; 
    bool W = false ; 
    bool S = false ; 
    bool E = false ; 
    for(int i = 0 ; i != len ; i++) {
        N |= (s[i] == 'N') ; 
        W |= (s[i] == 'W') ; 
        S |= (s[i] == 'S') ; 
        E |= (s[i] == 'E') ; 
    }
    puts(((N^S) || (W^E)) ? "No" : "Yes") ; 
    return 0 ; 
}



Measured memory_bytes: 128