akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int n,m,np;
char rule[1024][3][10];
char pa[1024][3][51],in[3][51];

int main()
{
	while(scanf("%d%d",&n,&m),n||m)
	{
		rep(i,n)rep(j,3)scanf("%s",rule[i][j]);
		
		np=0;
		rep(i,m)
		{
			rep(j,3)scanf("%s",in[j]);
			bool ok=0;
			rep(j,n)
			{
				rep(k,2)rep(l,8)if(rule[j][k+1][l]!='?'&&rule[j][k+1][l]!=in[k][l])goto NEXT;
				if(rule[j][0][0]=='p')ok=1; else ok=0;
				NEXT:;
			}
			if(ok)
			{
				rep(j,3)strcpy(pa[np][j],in[j]);
				np++;
			}
		}
		printf("%d\n",np);
		rep(i,np)rep(j,3)printf("%s%c",pa[i][j],j==2?'\n':' ');
	}
	
	return 0;
}

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

int d[2222][2222][4];
int main() {
	int h, w, m = 0;
	cin >> h >> w;
	string s[2222];
	for (int i = 0; i < h; i++)
		cin >> s[i];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') continue;
			if (i) d[i][j][0] = d[i - 1][j][0] + 1;
			else d[i][j][0] = 1;
			if (j) d[i][j][1] = d[i][j - 1][1] + 1;
			else d[i][j][1] = 1;
		}
	}
	for (int i = h; i--;) {
		for (int j = w; j--;) {
			if (s[i][j] == '#') continue;
			if (i + 1 < h) d[i][j][2] = d[i + 1][j][2] + 1;
			else d[i][j][2] = 1;
			if (j + 1 < w) d[i][j][3] = d[i][j + 1][3] + 1;
			else d[i][j][3] = 1;
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int a = 0;
			for (int k = 0; k < 4; k++)
				a += d[i][j][k];
			m = max(m, a - 3);
		}
	}
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 73984
use std::io::BufRead;
fn main() {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let mut lines = stdin.lines().flat_map(|x|x);
    let line = lines.next().unwrap();
    drop(line);
    let mut line:Vec<_> = lines.collect();
    line.sort();
    for line in line {
        print!("{}", line);
    }
}

Measured memory_bytes: 4352
import java.util.*;

class Main{

	static int mod=1000000007;

	static long[] fact=new long[2001];

	public static void main(String[] $){
		fact[0]=1;
		for(int i=1;i<=2000;++i)
			fact[i]=fact[i-1]*i%mod;
		System.err.println();
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),k=s.nextInt();
		int b=k,r=n-k;
		for(int i=1;i<=k;++i){
			long pos=nCr(r+1,i);
			long count=nCr(b-1,i-1);
			System.out.println(pos*count%mod);
			//System.err.println(pos+" "+count+" "+pos*count%mod);
		}
	}

	static long modpow(long n,long a){
		if(a==0)
			return 1;
		if(a%2==0){
			long t=modpow(n,a/2);
			return t*t%mod;
		}
		return n*modpow(n,a-1)%mod;
	}

	static long nCr(int n,int r){
		if(n<r) return 0;
		if(n<0||r<0) return 0;
		return fact[n]*modpow(fact[r],mod-2)%mod*modpow(fact[n-r],mod-2)%mod;
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    string s;
    cin >> s;
    vector<string> word = {"dream","dreamer","erase","eraser"};
    reverse(s.begin(),s.end());
    for (auto &i:word){
        reverse(i.begin(),i.end());
    }
    
    for (int i=0; i<(int)s.size();){
        bool flg=false;
        for (auto j:word){
            if(s.substr(i,j.size())==j){
                i+=j.size();
                flg=true;
                break;
            }
        }
        if(!flg){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<fstream>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<sstream>

using namespace std;

#define forn(i,n) for(int i=0;i<(int)(n); i++)
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
#define esta(x,v) (find((v).begin(),(v).end(),(x)) !=  (v).end())
#define index(x,v) (find((v).begin(),(v).end(),(x)) - (v).begin())
#define debug(x) cout << #x << " = "  << x << endl
#define pb push_back
#define mp make_pair

typedef long long tint;
typedef unsigned long long utint;
typedef long double ldouble;

typedef vector<int> vint;

int main (){
	string s;
	cin>>s;
	int arr=0, cg=0;
	forn(i, s.size()){
		if (s[i]=='g'){
			arr++;
			cg++;
		}else{
			arr--;
		}
	}
	cout<<min(cg, arr/2)<<endl;
}

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

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	string s;
	int sum; int ans = 0;
	for (int i = 1; i <= n; i++) {
		sum = 0;
		s = to_string(i);
		for (int j = 0; j < s.length(); j++) {
			sum += s[j] - '0';
		}
		if (sum >= a && b >= sum) {
			ans+=i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/abc126/tasks/abc126_b
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
// clang-format on
bool check(string T)
{
    int N = stoi(T);
    if (N <= 12 && N != 0)
    {
        return 1;
    }
    return 0;
}
int main()
{
    string S;
    cin >> S;
    cout << (check(S.substr(0, 2)) == true && check(S.substr(2, 2)) == true ? "AMBIGUOUS" : check(S.substr(0, 2)) == true ? "MMYY" : check(S.substr(2, 2)) == true ? "YYMM" : "NA") << endl;
    return 0;
}

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

using namespace std;

int main()
{
//    ios_base::sync_with_stdio(false);
//    cin.tie(0);
	string s;
	cin >> s;
	ll n;
	n=s.size();
	bool ch=true;
	ll i,j,t,k;
	for(i=0;i<n/2;i++){
		if(s[i]!=s[n-1-i]){
			ch=false;
			break;
		}
	}
	if(ch){
		for(i=0;i<=(n-1)/2-1;i++){
			if(s[i]!=s[(n-1)/2-1-i]){
				ch=false;
				break;
			}
		}
	}
	if(ch){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

int INF = 100000000;
int dp[20001][256];

void slove(int n, int m){
	vint c(m);
	rep(i, m) scanf("%d", &c[i]);
	vint x(n);
	rep(i, n) scanf("%d", &x[i]);

	rep(i, 20001) rep(j, 256) dp[i][j] = INF;

	dp[0][128] = 0;
	rep(i, n){
		rep(j, 256){
			if(dp[i][j] == INF) continue;
			rep(k, m){
				int now = j + c[k];
				if(now < 0) now = 0;
				if(now > 255) now = 255;
				//dp[?????????????????????????????? 20000][????£°???????????? ??? 255] = ????????????????°????
				dp[i + 1][now] = min(dp[i + 1][now], dp[i][j] + (x[i] - now) * (x[i] - now));
			}
		}
	}
	int ans = 100000000;
	//?????????dp[n][]
	rep(i, 256){
		ans = min(ans, dp[n][i]);
	}
	printf("%d\n", ans);
	return;
}

int main(void){
	int n, m;
	while(1){
		scanf("%d %d", &n, &m);
		if(n == 0) break;
		slove(n, m);
	}
	return 0;
}

Measured memory_bytes: 23264
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << c << " " << a << " " << b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
using PII = pair<int,int>;

void vprn(vector<int> &v){ for(int i=0;i<v.size();i++) cout<<v[i]<<(i<v.size()-1?",\t":"\n"); }

ll solve(int N, vi &A){
	sort(allr(A));
	// vprn(A);//
	ll a = 0, b = 0;
	int i = 0, c = 0;
	while(i<N && c<2){
		if(A[i-1] == A[i]){
			if(c==0){
				a = A[i];
				i++;
			}
			else if(c==1){
				b = A[i];
			}
			c++;
		}
		i++;
	}

	ll ans = a*b;

	return ans;
}

int main(){
	int N; cin>>N;
	vi A(N);
	rp(i, 0, N) cin>>A[i];
	ote(solve(N, A));
}


Measured memory_bytes: 768
#include<stdio.h>
int main(void){
    int H,W,x,y,z;
    
    while(1){
        scanf("%d %d",&H,&W);
        if(H == 0 && W ==0)
            break;
        for(y=0; y<H;y++){
            for(x=0; x<W; x++){
                z = x+y;
                if( z%2 == 1){
                    printf(".");
                }else if(z%2 == 0){
                    printf("#");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int[] rooms = new int[121];
		scan.nextLine();
		
		for (int i=1; i<=n; i++) {
			int b = scan.nextInt();
			int f = scan.nextInt();
			int r = scan.nextInt();
			int v = scan.nextInt();
			
			rooms[((b-1)*30) + ((f-1)*10) +r] += v;
		}
		
		for(int i=1; i<=120; i++) {
			System.out.print(" " + rooms[i]);
			if(i%10 == 0) {
				System.out.println();
			}
			if(i%10 == 0 && i%3 == 0 && i < 120) {
				System.out.println("####################");
			}
		}
		
	}
}


Measured memory_bytes: 29684
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    vector<ll> s(n);
    s[0] = a[0];
    for (int i = 1; i < n; i++) {
        s[i] = s[i - 1] + a[i];
        s[i] %= MOD;
    }
    
    ll ans = 0;
    for (int i = 0; i < n - 1; i++) {
        ans += s[i] * a[i + 1];
        ans %= MOD;
    }
    cout << ans << endl;
    
    return 0;
}


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

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int64_t N, K;
	cin >> N >> K;
	vector<int64_t> A(N), B(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i) >> B.at(i);
	}
	
	int64_t ans = 0;
	for (int i = 30; i >= 0; i--) {
		int64_t tmpK = K;
		if ((K & (1 << i)) != 0) {
			tmpK = 0;
			for (int j = 30; j > i; j--) {
				tmpK = tmpK*2 + !!(K & (1 << j));
			}
			tmpK = tmpK*2;
			for (int j = i-1; j >= 0; j--) {
				tmpK = tmpK*2 + 1;
			}
		}
		int64_t sum = 0;
		for (int i = 0; i < N; i++) {
			if ((A.at(i) | tmpK) == tmpK) {
				sum = sum + B.at(i);
			}
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;

}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
vector<int> G[100005];

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		if(m-a>=0)G[m-a].push_back(b);
	}
	ll ans=0;
	priority_queue<int> que;
	for(int i=m-1;i>=0;i--){
		for(int j=0;j<G[i].size();j++){
			que.push(G[i][j]);
		}
		if(que.size()==0)continue;
		ans+=que.top();
		que.pop();
	}
	printf("%lld\n",ans);
	return 0;
}


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

using namespace std;
 
#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair
 
#define debug(_x)		cerr << #_x << '=' << (_x) << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << (_x) << ' ' << #_y << '=' << (_y) << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << (_x) << ' '; cerr << endl;

#define HERE debug(__LINE__);

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;

vi a;

const int N = 3009;
ii dp[N][N][2];

pair<int, int> solve(int l, int r, bool turn) {
	if (dp[l][r][turn] != ii{INF, INF}) return dp[l][r][turn];
	
	if (l > r) return dp[l][r][turn] = ii{0, 0};
	
	if (turn) {
		ii p = solve(l+1, r, !turn);
		ii q = solve(l, r-1, !turn);
		p.first += a[l];
		q.first += a[r];
		if (p.first - p.second > q.first - q.second) {
			return dp[l][r][turn] = p;
		} else return dp[l][r][turn] = q;
	} else {
		ii p = solve(l+1, r, !turn);
		ii q = solve(l, r-1, !turn);
		p.second += a[l];
		q.second += a[r];
		if (p.first - p.second < q.first - q.second) {
			return dp[l][r][turn] = p;
		} else return dp[l][r][turn] = q;
	}
}

int32_t main() {
	FAST_IO;
	
	int n;
	cin >> n;
	
	a.resize(n+1);
	for (int i = 1; i <= n; i++) cin >> a[i];
	
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			for (int k = 0; k < 2; k++) dp[i][j][k] = {INF, INF};
	ii ans = solve(1, n, true);
	
	cout << ans.first - ans.second << endl;
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined


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

template<class T> struct DualSegmentTree {
    using F = function<T(T, T)>;
private : 
    int n, dep;
    const F f;
    T id;
    vector<T> node;

public : 
    DualSegmentTree (const F &f, const T &id) : f(f), id(id) { }

    void init (int sz) {
        n = 1; dep = 0;
        while (n < sz) { n <<= 1; dep++; }
        node.resize(2 * n, id);
    }

    void build (const vector<T> v) {
        const int sz = (int)v.size();
        init(sz);
        for (int i = 0; i < sz; i++) node[i] = v[i];
    }

    inline void eval (int k) {
        if (node[k] == id) return;
        node[k<<1|0] = f(node[k<<1|0], node[k]);
        node[k<<1|1] = f(node[k<<1|1], node[k]);
        node[k] = id;
    }

    inline void thrust (int k) {
        for (int i = dep; i; i--) eval(k>>i);
    }

    void update (int a, int b, T x) {
        thrust(a += n);
        thrust(b += n - 1);
        for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
            if (l&1) { node[l] = f(node[l], x); l++; }
            if (r&1) { r--; node[r] = f(node[r], x); }
        }
    }

    const T &operator[] (int i) {
        thrust(i += n);
        return node[i];
    }

};

int main() {
    int n, q, op, s, t, x, i;
    cin >> n >> q;
    
    auto f = [] (int a, int b) { return a + b; };
    DualSegmentTree<int> seg(f, 0);
    seg.init(n);
    
    while (q--) {
        cin >> op;
        if (op) {
            cin >> i;
            cout << seg[--i] << endl;
        } else {
            cin >> s >> t >> x;
            seg.update(s-1, t, x);
        }
    }
    return 0;
}


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

int main(){
    int n,m, g[2];
    cin >> n >> g[0] >> g[1] >> m;
    
    vector<vector<pair<int,int> > > sheet(2, vector<pair<int,int> >((int)1e6+1, make_pair(-1,-1)));
    for(int k=0; k<2; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                int num;
                cin >> num;
                sheet[k][num] = make_pair(i,j);
            }
        }
    }
    
    vector<vector<int> > bingo1(2, vector<int>(n+1, 0)), bingo2(2, vector<int>(n+1, 0));
    int winner=-1;
    for(int i=0; i<m; i++){
        int num;
        cin >> num;
        if(winner!=-1) continue;
        
        for(int j=0; j<2; j++){
            if(sheet[j][num].first!=-1){
                if(n==1){
                    g[j]--;
                    continue;
                }
                int x=sheet[j][num].first;
                int y=sheet[j][num].second;
                bingo1[j][x]++;
                bingo2[j][y]++;
                if(bingo1[j][x]==n) g[j]--;
                if(bingo2[j][y]==n) g[j]--;
                if(x==y){
                    bingo1[j][n]++;
                    if(bingo1[j][n]==n) g[j]--;
                }
                if(x+y==n-1){
                    bingo2[j][n]++;
                    if(bingo2[j][n]==n) g[j]--;
                }
            }
        }
        if(g[0]<=0){
            if(g[1]<=0){
                winner=2;
            }else{
                winner=0;
            }
        }else{
            if(g[1]<=0){
                winner=1;
            }
        }
    }
    
    if(winner==0){
        cout << "USAGI" << endl;
    }else if(winner==1){
        cout << "NEKO" << endl;
    }else{
        cout << "DRAW" << endl;
    }
    return 0;
}

Measured memory_bytes: 26336
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	//	"strings"
	"sort"
)

func main() {
	sc := NewScanner()

	_ = sc.NextInt()
	m := sc.NextInt()

	mp := map[int][]int{}

	plist := []int{}
	ylist := []int{}

	for i := 0; i < m; i++ {
		p := sc.NextInt()
		y := sc.NextInt()
		plist = append(plist, p)
		ylist = append(ylist, y)
	}
	for i := 0; i < m; i++ {
		mp[plist[i]] = append(mp[plist[i]], ylist[i])
	}

	for _, v := range mp {
		sort.Ints(v)
	}

	amp := map[string]string{}

	for k, v := range mp {
		for i := 0; i < len(v); i++ {
			amp[fmt.Sprintf("%s%s", k, v[i])] = fmt.Sprintf("%06d%06d", k, i+1)

		}
	}
	for i := 0; i < m; i++ {
		fmt.Printf("%+v\n", amp[fmt.Sprintf("%s%s", plist[i], ylist[i])])
	}

	// fmt.Printf("%06d%06d\n", plist[i], j+1)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

int main(){
    int n,mod=1000000007;
    long long ans=1;
    bool p[1100];
    int  l[1100];
    for (int i=0;i<1100;i++) {
        p[i]=0;
        l[i]=0;
    }
    p[2]=1;
    for (int i=3;i<1100;i++) {
        int f=1;
        int t=2;
        while (t*t<=i) {
            if (i%t==0){
                f=0;
                break;
            }
            t++;
        }
        p[i]=f;
     }

     scanf("%d",&n);
     for (int i=2;i<=n;i++) {
        int tmp=i;
        int cnt=0;
        for (int j=2;j<=n;j++) {
            if (p[j]==1) {
                for (;;) {
                    if (tmp%j==0) {
                        l[j]++;
                        tmp/=j;
                    } else {
                        break;
                    }
                }
            }
        }
    }

    for (int i=0;i<1100;i++) {
        ans*=l[i]+1;
        ans%=mod;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  int N, D;
  cin >> N >> D;
  int X[N][D];
  REP(i, N) {
    REP(j, D) { cin >> X[i][j]; }
  }
  int cnt = 0;
  REP(i, N) {
    FOR(j, i + 1, N) {
      double tmp = 0;
      REP(k, D) { tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]); }
      double d = sqrt(tmp);
      if (ceil(d) == floor(d)) {
        cnt++;
      }
    }
  }
  cout << cnt;

  return 0;
}

Measured memory_bytes: 256
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sat Jan 18 17:16:49 2020
//
package main

import "fmt"

var H, W int
var S []string

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func in(l, x, r int) bool {
	return l <= x && x < r
}

type point struct {
	x int
	y int
}

func bfs(dists [][]int, x, y int) {
	dists[x][y] = 0
	q := []point{point{x, y}}
	for len(q) > 0 {
		cur := q[0]
		q = q[1:]
		for _, p := range []point{point{-1, 0}, point{1, 0}, point{0, -1}, point{0, 1}} {
			s := p.x + cur.x
			t := p.y + cur.y
			if in(0, s, H) && in(0, t, W) && dists[s][t] == -1 && S[s][t] != '#' {
				dists[s][t] = dists[cur.x][cur.y] + 1
				q = append(q, point{s, t})
			}
		}
	}
}

func main() {
	fmt.Scan(&H, &W)
	S = make([]string, H)
	for i := range S {
		fmt.Scan(&S[i])
	}

	ans := 0
	for x := 0; x < H; x++ {
		for y := 0; y < W; y++ {
			dists := make([][]int, H)
			for i := range dists {
				dists[i] = make([]int, W)
				for j := range dists[i] {
					dists[i][j] = -1
				}
			}
			if S[x][y] == '.' {
				bfs(dists, x, y)
			}
			for i := range dists {
				for j := range dists[i] {
					ans = max(ans, dists[i][j])
				}
			}
		}
	}
	fmt.Println(ans)
}


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

using namespace std;

int main(void){
	int a, b, x;
	cin >> a >> b >> x;

	if(a <= x && x <= a+b){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<string>
#include<stack>
#include<queue>
#include<iterator>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int inf=0x3f3f3f3f;
typedef long long ll;

string s;

int main()
{
    cin>>s;
    if(s[s.size()-1]=='s')
    {
        s+="es";
    }
    else
        s+="s";
    cout<<s<<endl;
}


Measured memory_bytes: 3640
#include<stdio.h>
typedef long long ll;
template<class T>T gcd(T x,T y){return y?gcd(y,x%y):x;}
int T;ll a,b,c,d,g;
int main(){
	for(scanf("%d",&T);T;--T){
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		if(a<b||d<b)puts("No");
		else if(b-c<=1)puts("Yes");
		else if(b-c-1>=(g=gcd(b,d)))puts("No");
		else if(((c-a)%g+g)%g>((b-2-a)%g+g)%g)puts("No");
		else puts("Yes");
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N, K;
  std::cin >> N >> K;
  std::vector< ll > vd(K, 0LL);

  std::map<ll, bool> mc;
  for (char c = '0'; c <= '9'; c++) {
    mc[c] = true;
  }
  for (ll i = 0; i < K; i++) {
    char c;
    std::cin >> c;
    mc[c] = false;
  }

  ll ans = INF;
  for (ll i = N; ; i++) {
    bool judge = true;
    ll x = i;
    while (x > 0) {
      if (!mc[x % 10 + '0']) {
	judge = false;
	break;
      }
      x /= 10;
    }
    if (judge) {
      ans = i;
      break;
    }
  }

  print(ans);
  return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int sum = 0;
	for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) sum += a[i] * a[j];
	cout << sum;
}
	

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int q1, b, c1, c2, q2;
int main() {
	while (cin >> q1, q1) {
		cin >> b >> c1 >> c2 >> q2;
		int ret1 = -1, ret2 = -1;
		for (int x = 1; x <= q2; x++) {
			for (int y = max(q1 - x, 0); c1 * x + c2 * y <= b; y++) {
				ret1 = x;
				ret2 = y;
			}
		}
		if(ret1 != -1) cout << ret1 << ' ' << ret2 << endl;
		else cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 3012
#!/usr/bin/env python3
from bisect import bisect

def solve(s):
    def processArr(arr):
        r_count = arr.count("R")
        r = sum((r_count - i) % 2 for i in range(len(arr)))
        l = len(arr) - r
        return [0] * (r_count - 1) + [r] + [l] + [0] * (len(arr) - r_count - 1)
    ans = []
    lst = []
    prev = ""
    n = len(s)
    for i in range(n):
        if s[i] == "R" and prev == "L":
            ans.extend(processArr(lst))
            lst.clear()
        lst.append(s[i])
        prev = s[i]
    if lst != []:
        ans.extend(processArr(lst))
    return ans

def main():
    S = input()
    print(*solve(S))
    return

if __name__ == '__main__':
    main()


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

int main(void){
    int n, sum;
    
    cin >> n;
    
    vector<int> b(n);
    
    rep(i, n-1){
        cin >> b.at(i);
    }
    
    sum = b.at(0);
    b.at(n-1) = 100001;
    
    rep(i,n-1){
        if(b.at(i) > b.at(i+1)){
            sum += b.at(i+1);
        } else {
            sum += b.at(i);
        }
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
N,K = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]

ctr = Counter()
for a,b in src:
    ctr[a] += b

now = 0
for k,v in sorted(ctr.items()):
    if now + v < K:
        now += v
    else:
        print(k)
        break

Measured memory_bytes: 26412
N, M = map(int, input().split())
d = {}
for i in range(M):
	for i in [int(i) for i in input().split()]:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
for i in d.values():
	if i%2:
		print("NO")
		break
else:
	print("YES")

Measured memory_bytes: 9144
fun main(args: Array<String>) {
    val (N, A, B) = readLine()!!.split(" ").map(String::toInt)
    var total = 0
    for (n in 1..N) {
        var digit = n
        var sum = 0
        while (digit > 0) {
            sum += digit%10
            digit /= 10
        }
        if (sum in A..B) {
            total += n
        }
    }
    println(total)
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

struct Doubling {
  const int LOG;
  vector< vector< int > > table;

  Doubling(int sz, int64_t lim_t) : LOG(64 - __builtin_clzll(lim_t)) {
    table.assign(LOG, vector< int >(sz, -1));
  }

  void set_next(int k, int x) {
    table[0][k] = x;
  }

  void build() {
    for(int k = 0; k + 1 < LOG; k++) {
      for(int i = 0; i < table[k].size(); i++) {
        if(table[k][i] == -1) table[k + 1][i] = -1;
        else table[k + 1][i] = table[k][table[k][i]];
      }
    }
  }

  int query(int k, int64_t t) {
    for(int i = LOG - 1; i >= 0; i--) {
      if((t >> i) & 1) k = table[i][k];
    }
    return k;
  }
};


int main() {
  int N;
  int64 K;
  cin >> N >> K;
  Doubling beet(N, infll);
  for(int i = 0; i < N; i++) {
    int x;
    cin >> x;
    --x;
    beet.set_next(i, x);
  }
  beet.build();
  cout << beet.query(0, K) + 1 << "\n";
}

Measured memory_bytes: 52568
import java.util.*;

public class Main {
    public static void main(String[] args) {  
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.indexOf("RRR") != -1){
          System.out.println(3);
        } else if (s.indexOf("RR") != -1){
          System.out.println(2);
        } else if (s.indexOf("R") != -1){
          System.out.println(1);
        } else {
          System.out.println(0);
        }
    }
}

Measured memory_bytes: 35532
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
ll mod = 998244353;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

int main(){
    ll n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++)  cin >> v[i];
    vector<int> cnt(100001, 0);
    int to = 0;
    for(int i = 0; i < n; i++){
        if(i == 0 && v[i] != 0){
            cout << 0 << endl;
            return 0;
        }
        if(i != 0 && v[i] == 0){
            cout << 0 << endl;
            return 0;
        }
        cnt[v[i]]++;
        to = max(v[i], to);
    }
    ll ans = 1;
    for(int i = 1; i <= to; i++){
        for(int j = 0; j < cnt[i]; j++) ans = ans*cnt[i-1]%mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include <fstream>
#include<unordered_set>
#include<stack>
#include <map>
#include<time.h>
#include <chrono>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define all(x) x.begin(),x.end()
using namespace std;
#define MAX 1000001 
#define M 998244353
ll inverse(ll n)
{
	ll modu = M;
	ll m = modu;
	ll a = 0, b = 1;
	if (modu == 1)
		return 0;
	while (n > 1)
	{
		ll quo = n / modu;
		ll temp = modu;
		modu = n % modu, n = temp;
		temp = a; 
		a = b - (quo * a);
		b = temp;
	}
	if (b < 0)
		b += m;
	return b;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n;
	cin >> n;
	vector<ll> arr(n, 0);
	vector<ll> mini(n, INF);
	f(i, 0, n)
	{
		cin >> arr[i];
		if (i == 0)
			mini[i] = arr[i];
		else
		{
			if (arr[i] < mini[i - 1])
				mini[i] = arr[i];
			else
				mini[i] = mini[i - 1];
		}
	}
	ll count = 1;
	f(i, 1, n)
	{
		if (mini[i - 1] >= arr[i])
		{
			count += 1;
		}
	}
	cout << count;
	return 0;
}


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

int main(){
  int a[3];
  REP(i,3) cin>>a[i];
  sort(a,a+3);
  cout<<(a[2]-a[0])<<endl;
}

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

typedef unsigned long long ll;

const ll MOD = 1e9+7;

ll ModPow(ll base,ll exp,ll mod){
  ll ret = 1;
  base %= mod;
  while(exp>0){
    if(exp&1) ret = (ret*base)%mod;
    base = (base*base)%mod;
    exp >>= 1;
  }
  return ret;
}

ll ModInv(ll base,ll mod){
  return ModPow(base,mod-2,mod);
}

ll Comb(ll n, ll r,ll fct[][4001]){
  assert(n<=2000);
  return fct[0][n]*(fct[1][r]*fct[1][n-r]%MOD)%MOD;
}

int main(){
  ll n,k; cin >> n >> k;

  ll fct[2][4001];
  fct[0][0] = fct[0][1] = 1;
  for(ll i=2; i<=n; fct[0][i]%=MOD,i++)
    fct[0][i] = fct[0][i-1]*(i%MOD);

  for(ll i=0; i<=n; i++)
    fct[1][i] = ModPow(fct[0][i],MOD-2,MOD);

  for(ll i=0; i<k; i++)
    cout << (Comb(k-1,i,fct)*Comb(n-k+1,i+1,fct))%MOD << endl;
  return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
h_list=list(map(int,input().split()))
h_list_new=[]
for k in range(n):
    h_list_new.append(1)
for k in range(m):
    a,b=map(int,input().split())
    if h_list[a-1]>=h_list[b-1]:
        h_list_new[b-1]=0
    else:
        pass
    if h_list[a-1]<=h_list[b-1]:
        h_list_new[a-1]=0
    else:
        pass
print(h_list_new.count(1))

Measured memory_bytes: 84776
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val total = f(n)
    println(if ((n % total) == 0) "Yes" else "No")
}

private fun f(n: Int): Int {
    var sum = 0
    var value = n
    while (value >= 1) {
        sum += (value % 10)
        value /= 10
    }
    return sum
}

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	long long int x, k, d;
	cin >> x >> k >> d;

	x = abs(x);

	long long int c = x / d;

	if(c <= k){
		x -= c * d;
		k -= c;
		k %= 2;

		rep(i, k){
			if(0 < x) x -= d;
			else x += d;
		}
	}
	else{
		x -= k * d;
	}

	cout << abs(x);
	
	return 0;
}

Measured memory_bytes: 3568
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int k = sc.nextInt();

        char c = s.charAt(k-1);
        StringBuilder sb = new StringBuilder();
        for(int i = 0;i < n;i++){
            if(s.charAt(i) == c){
                sb.append(c);
            } else {
                sb.append("*");
            }
        }
        System.out.println(sb.toString());

    }

}


Measured memory_bytes: 21588
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>

using  namespace std;
#define ll long long 
struct node{
	int t,x,y;
}a[100005];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d%d",&a[i].t,&a[i].x,&a[i].y);
	}
	int pret = a[1].t,pre = a[1].x + a[1].y;
	int prex = a[1].x;
	int prey = a[1].y;
	if(pret < pre){
		cout<<"No\n";
		return 0;
	}
	if(pret > pre && (pret - pre)%2 != 0){
		cout<<"No\n";
		return 0;
	}
	for(int i=2;i<=n;i++)
	{
		int nowt = a[i].t - a[i-1].t;
		int now = abs(a[i].x - a[i-1].x) + abs(a[i].y - a[i-1].y);
		if(nowt < now){
			cout<<"No\n";
			return 0;
		}
		if(nowt > now && (nowt - now)%2 != 0){
			cout<<"No\n";
			return 0;
		} 
	}
	cout<<"Yes\n";
	return 0;
} 

Measured memory_bytes: 1408
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 1000000001
#define EPS 1.0e-6

using namespace std;

typedef long long ll;

int n, W;
int v[105];
int w[105];

//dp[i+1][j]:i???????????§???????????§???????????\????????????????????§???
int dp[105][10500];

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

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

	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= W; j++) {
			if (j < w[i])dp[i + 1][j] = dp[i][j];
			else {
				dp[i + 1][j] = max( dp[i][j],dp[i][j - w[i]] + v[i] );
			}
		}
	}

	cout << dp[n][W] << endl;

	return 0;
}

Measured memory_bytes: 7200
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;

signed main() {
	int n, k;
	while (cin >> n >> k, n || k) {
		vector<int>v(n + 1, 0);
		rep(i, 1, n + 1)cin >> v[i];
		rep(i, 1, n + 1)v[i] += v[i - 1];
		int ans(-INF);
		for (int i = k; i < v.size(); i++) {
			ans = max(ans, v[i] - v[i - k]);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2996
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class ARoundOne {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int A, B;
        in>>A>>B;
        RREP(i, 3){
            if(i!=A and i!=B){
                out<<i<<'\n';
                return;
            }
        }
    }
};


int main() {
	ARoundOne solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

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

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 main():
    n,k = LI()
    a = sorted(LI(),reverse=True)

    return sum(a[:k])


print(main())





Measured memory_bytes: 5584
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int w, h, n, x, y, a;
    cin >> w >> h >> n;
    int x0 = 0, x1 = w, y0 = 0, y1 = h;
    for (int i = 0; i < n; i++) {
        cin >> x >> y >> a;
        if (a == 1 && x > x0) x0 = x;
        if (a == 2 && x < x1) x1 = x;
        if (a == 3 && y > y0) y0 = y;
        if (a == 4 && y < y1) y1 = y;
    }
    cout << max(x1 - x0, 0) * max(y1 - y0, 0) << endl;
    
}

Measured memory_bytes: 256
function main(input) {
  input = input.trim();
  const [n, d] = input.split(" ").map(n => Number(n));
  const range = 2*d + 1;
  const result = Math.ceil(n/range);
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9420
<?php
$A = 0;
define('MAX', 2000);
 
fscanf(STDIN, "%d", $N);
$L = array_map('intval', explode(" ", trim(fgets(STDIN))));
$max = max($L);
$S = array_pad(array(), MAX + 1, 0);
foreach ($L as $v) {
    $S[$v]++;
}
for ($i = 1; $i <= MAX; $i++) {
    $S[$i] = $S[$i - 1] + $S[$i];
}
sort($L);
for ($i = 0; $i < $N - 2; $i++) {
    for ($j = $i + 1; $j < $N - 1; $j++) {
        $x = $L[$i] + $L[$j] - 1;
        $A += $S[$x] - $j - 1;
    }
}
echo $A;

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

int main() {
    int h,w;
    cin >> h >> w;
    
    vector<vector<char>> grid(h+2,vector<char>(w+2, '.'));
    for (int i = 1; i <= h; i++){
      for (int j = 1; j <= w; j++){
        cin >> grid.at(i).at(j);
      }
    }

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

    bool can=true;
    
    for (int i = 1; i <= h; i++){
        for (int j = 1; j <= w; j++){
            if(grid.at(i).at(j)=='#' && grid.at(i+1).at(j)=='.' && grid.at(i).at(j+1)=='.' && grid.at(i-1).at(j)=='.' && grid.at(i).at(j-1)=='.'){
                can=false;
                break;
            }
        }
        if(!can){
            break;
        }
    }
    if(can){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 3592
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        double r=scan.nextDouble();
        double area=Math.PI*r*r;
        double lap=2*Math.PI*r;
        System.out.printf("%f %f",area,lap);
    }
}


Measured memory_bytes: 28140
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
vector<int> inv(vector<int> a) {
	int n = a.size();
	vector<int> b(n);
	for (int i = 0; i < n; ++i) b[a[i]] = i;
	return b;
}
// c = a o b
vector<int> compose(vector<int> a, vector<int> b) {
	int n = a.size();
	vector<int> c(n);
	for (int i = 0; i < n; ++i) c[i] = a[b[i]];
	return c;
}
vector<int> power(vector<int> a, int b) {
  int n = a.size();
  vector<int> x(n);
  iota(x.begin(), x.end(), 0);
  while (b) {
    if (b & 1) x = compose(x, a);
    a = compose(a, a);
    b >>= 1;
  }
  return x;
}
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	vector<int> p(n), q(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &p[i]);
		--p[i];
	}
	for (int i = 0; i < n; ++i) {
		scanf("%d", &q[i]);
		--q[i];
	}
	vector<vector<int>> mid(6);
	mid[0] = p;
	mid[1] = q;
	for (int i = 2; i < 6; ++i) {
		mid[i] = compose(mid[i - 1], inv(mid[i - 2]));
	}
	auto rep = compose(q, compose(inv(p), compose(inv(q), p)));
	auto v = power(rep, (k - 1) / 6);
	auto ans = compose(v, compose(mid[(k - 1) % 6], inv(v)));
	for (int i = 0; i < n; ++i) printf("%d ", ans[i] + 1);
}


Measured memory_bytes: 7528
#include<iostream>
using namespace std;
int main(){
    
    int a[1000];
    int n;
    
    cin>>n;
    int i;
    for(i=0;i<=n-1;i=i+1)
    {cin>>a[i];}
    
    int j;
    for(j=n-1;j>-1;j=j-1)
    {cout<<a[j];
    if(j>0){cout<<" ";}
    if(j==0){cout<<endl;}
    }


}


Measured memory_bytes: 3088