akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>

long long PRIME = 1e9 + 7;
using namespace std;


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

    vector<int> A(N*N, 0);
    vector<int> B(M*M, 0);

    string buf;

    for(int i = 0; i < N; ++i){
        cin >> buf;
        for(int j = 0; j < N; ++j){
            if(buf[j] == '#'){
                A[N * i + j] = 1;
            }
        }
    }


    for(int i = 0; i < M; ++i){
        cin >> buf;
        for(int j = 0; j < M; ++j){
            if(buf[j] == '#'){
                B[M * i + j] = 1;
            }
        }
    }


    for(int i = 0; i <= N-M; ++i){
        for(int j = 0; j <= N-M; ++j){
            bool check = true;
            for(int k = 0; k < M; ++k){
                for(int l = 0; l < M; ++l){
                    if(A[(i+k)*N+j+l] != B[k*M+l]){
                        check = false;
                        break;
                    }
                }
                if(!check){
                    break;
                }
            }
            if(check){
                cout << "Yes";
                return 0;
            }
        }
    }

    cout << "No";
}



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

const int mod = 1e9 + 7;

void add_self (int & a, int b) {
	a += b;
	if (a >= mod) a -= mod;
}

int mul (int a, int b) {
	return (int) (((ll) a * b) % mod);
}

int power (int a, int k) {
	int ans = 1;
	while (k >= 1) {
		if (k & 1) ans = mul (ans, a);
		a = mul (a, a);
		k >>= 1;
	}
	return ans;
}

int inverse (int a) {
	return power (a, mod - 2);
}

int main() {
	//cout << INT_MAX << endl;
	//cout << 2e9 << endl;
	int n, x, l;
	cin >> n;
	vector < pii > a (n);
	for (int i = 0; i < n; i++) {
		cin >> x >> l;
		a[i].first = (long) x - l;
		a[i].second = (long) x + l;
	}
	sort (a.begin(), a.end(), [&] (const pii & p1, const pii & p2) {
		if (p1.second == p2.second) {
			return p1.first < p2.first;
		}
		return p1.second < p2.second;
	});
	int cnt = 0;
	pii current = a[0];
	for (int i = 1; i < n; i++) {
		if (a[i].first >= current.second) {
			current = a[i];
		} else {
			cnt++;
		}
	}
	cout << (n - cnt) << endl;
	return 0;
}



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

int	main(void)
{
	int n;
	cin >> n;
	vector<long long> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	bool is_zero = false;
	for (int i = 0; i < n; i++)
	{
		if (a[i] == 0) is_zero = true;
	}
	if (is_zero)
	{
		cout << 0 << endl;
		return (0);
	}
	long long ans = 1;
	for (int i = 0; i < n; i++)
	{
		if (a[i] * ans > (long long)1e18 || (double)a[i] * ans > (double)(2e18))
		{
			cout << -1  << endl;
			return (0);
		}
		ans *= a[i];
	}
	cout << ans << endl;
	return (0);
}


Measured memory_bytes: 3944
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
	int n,n_temp[52];
	char c_temp[53],s[14],h[14],c[14],d[14];
	cin >> n;
	
	for(int i = 0;i < n;i++){
		cin >> c_temp[i] >> n_temp[i];
		if(c_temp[i] == 'S'){
			s[n_temp[i] - 1] = 'S';
		}
		
		if(c_temp[i] == 'H'){
			h[n_temp[i] - 1] = 'H';
		}
		
		if(c_temp[i] == 'C'){
			c[n_temp[i] - 1] = 'C';
			}
		
		if(c_temp[i] == 'D'){
			d[n_temp[i] - 1] = 'D';
			}
	}
	
	for(int i = 0;i < 13;i++){
		if(s[i] != 'S') cout << "S "<< i + 1 << endl;
	}
	
	for(int i = 0;i < 13;i++){
		if(h[i] != 'H') cout << "H " << i + 1 << endl;
	}
	
	for(int i = 0;i < 13;i++){
		if(c[i] != 'C') cout << "C " << i + 1 << endl;
		}
	
	for(int i = 0;i < 13;i++){
		if(d[i] != 'D') cout << "D " << i + 1 << endl;
		}
		
		return 0;			
}

Measured memory_bytes: 3068
//q011.cpp
//Wed Sep 23 22:26:44 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int b[m][n];
	rep(i,m)rep(j,n)b[i][j]=0;

	rep(i,m){
		int k;
		cin >> k;
		rep(j,k){
			int s;
			cin >> s;
			s--;
			b[i][s] = 1;
		}
	}

	int p[m];
	rep(i,m)cin>>p[i];

	int ans = 0;
	rep(i,1<<n){
		int s[m];
		fill(s,s+m,0);
		rep(j,n){
			if(i>>j & 1){
				rep(k,m){
					if(b[k][j]==1){
						s[k]++;
					}
				}
			}
		}
		int flag = 1;
		rep(j,m){
			if (s[j]%2!=p[j]){
				flag = 0;
			}
		}
		if(flag){
			ans++;
		}
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vi adj[222222];
ll a[222222];

void dfs(int u, int p, ll cur=0)
{
	cur+=a[u];
	for(int v:adj[u])
	{
		if(v==p) continue;
		dfs(v,u,cur);
	}
	a[u]=cur;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,q; cin>>n>>q;
	for(int i=0;i<n-1;i++)
	{
		int u,v; cin>>u>>v; u--; v--;
		adj[u].pb(v); adj[v].pb(u);
	}
	for(int i=0;i<q;i++)
	{
		int p,x; cin>>p>>x;
		p--;
		a[p]+=x;
	}
	dfs(0,-1);
	for(int i=0;i<n;i++)
	{
		cout<<a[i];
		if(i+1<n) cout<<' ';
	}
	cout<<'\n';
}


Measured memory_bytes: 27904
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int value = Integer.parseInt(std.nextLine());
        int result = IntStream.range(0, 3)
                .map(it -> value)
                .reduce((acc, b) -> acc * b).getAsInt();
        System.out.println(result);
    }
}


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

typedef long long ll;

struct Card{
    int num,id;
    string str;
};

ll partition(Card c[],ll p,ll r){
    ll x=c[r].num;
    ll i=p-1;
    for(ll j=p;j<r;j++){
        if(c[j].num<=x){
            i++;
            swap(c[i],c[j]);
        }
    }
    swap(c[i+1],c[r]);
    return i+1;
}

void qsort(Card c[],ll p,ll r){
    if(p<r){
        ll q = partition(c,p,r);
        qsort(c,p,q-1);
        qsort(c,q+1,r);
    }
}

//ll bs(ll num,const vector<pair<string,ll> > &v, ll n){
//    ll l=-1,r=n-1;
//    for(;r-l>1;){
//        ll mid=(l+r)/2;
//        if(v[mid].second < num){
//            l = mid;
//        }else{
//            r = mid;
//        }
//    }
//    return l+1;
//}

void check(Card c[],int n){

    for(int i=0;i<n-1;i++){
        if(c[i].num<c[i+1].num)continue;
        if(c[i].id<c[i+1].id)continue;
        cout << "Not stable\n";
        return;
    }
    cout << "Stable\n";

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    Card card[100000];
    for(ll i=0;i<n;i++){
        cin >> card[i].str >> card[i].num;
        card[i].id=i;
    }
//    auto res=unique(tab.begin(),tab.end());
//    tab.erase(res,tab.end());
//    vector<pair<string, ll> > sub(card);
    qsort(card,0,n-1);

    check(card,n);
    for(int i=0;i<n;i++){
        cout << card[i].str << " " << card[i].num << endl;
    }
}



Measured memory_bytes: 9380
#include <iostream>
#include <algorithm>
#include <string>
#define int long long
using namespace std;
int n, k = 0, p, ans;
int _3 = -1, _5 = -1, _7 = -1;
void f(int s) {
	if (s == p) {
		if (_3 >= 0 && _5 >= 0 && _7 >= 0) {
			if (k <= n)ans++;
		}
		return;
	}
	k *= 10;
	k += 3; if (_3 < 0)_3 = s;
	f(s + 1);
	k -= 3; if (_3 == s)_3 = -1;
	k += 5; if (_5 < 0)_5 = s;
	f(s + 1);
	k -= 5; if (_5 == s)_5 = -1;
	k += 7; if (_7 < 0)_7 = s;
	f(s + 1);
	k -= 7; if (_7 == s)_7 = -1;
	k /= 10;
	return;
}
signed main() {
	k = 0;
	cin >> n;
	for (p = 3; p < 10; p++)f(0);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    bool can=true;
    for(int i=0;i<s.size();i++){
        if(i%2==0&&s[i]=='L')can=false;
        else if(i%2==1&&s[i]=='R')can=false;
    }
    if(can)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    A = []
    for _ in range(int(input())):
        x, l = map(int, input().split())
        A.append((x - l, x + l))

    A.sort(key = lambda x : x[1])
    ans = 0
    now = -INF
    for l, r in A:
        if now <= l:
            now = r
            ans += 1
    print(ans)
resolve()

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

int main() {
  int n, a;
  string s, t;
  cin >> n >> s >> t;
  a = 2 * n;
  rep(i, n){
    bool b = 1;
    rep(j, n-i){
      if(s[i+j] != t[j]){
        b = 0;
        break;
      }
    }
    if(b){
      a = n + i;
      break;
    }
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 3000 + 5
#define Mod 1000000007
#define rep(i, l, r) for(int i = l; i <= r; ++i)
char s[N];
int n, m, tot, L, R, r[N], sum[N], dp[N][N];
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int Inc(int a, int b){
    return (a += b) >= Mod ? a - Mod : a;
}
int main(){
    n = read(), m = read(), scanf("%s", s + 1);
    rep(i, 1, n) sum[i] = sum[i - 1] + s[i] - '0';
    rep(i, 1, m) L = read(), R = read(), r[L] = max(r[L], R);
    dp[0][0] = 1, R = 0;
    rep(i, 1, n){
        int D = 0; if(r[i] > R) D = sum[r[i]] - sum[R];
        R = max(R, max(r[i], i));
        rep(j, max(D - 1, 0), R - i){
            if(j >= D) dp[i][j] = Inc(dp[i][j], dp[i - 1][j - D]);
            dp[i][j] = Inc(dp[i][j], dp[i - 1][j - D + 1]);
        }   
    } 
    printf("%d", dp[n][0]);
    return 0;
}

Measured memory_bytes: 16056
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, M;
    cin >> N >> M;
    vint A(M);
    rep(i, M) cin >> A[i];
    ll S = 0;
    rep(i, M) S += ll(A[i]);
    
    ll ans = ll(N - S);
    if (ans < 0) ans = -1;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long LL;
#define N 300000

const LL mod=998244353;
LL n,f[N][3][3],g[3][3],d[N],m,mx,rt,fa[N];
vector<LL> e[N];

void dfs(LL u,LL dist){
	if (dist>mx){mx=dist; rt=u;}
	for (LL v:e[u])
		if (v!=fa[u]){
			fa[v]=u;
			dfs(v,dist+1);
		}
}

LL inv(LL x){return x==1?1:(mod-mod/x)*inv(mod%x)%mod;}

void upd(LL &x,LL y){x=(x+y)%mod;}

void dp(LL u,LL dist){
	if (dist==m/2) f[u][1][1]=1;
	else f[u][0][0]=1;
	for (LL v:e[u])
		if (v!=fa[u]){
			fa[v]=u;
			dp(v,dist+1);
			memset(g,0,sizeof g);
			for (LL i1:{0,1,2}) for (LL i2:{0,1,2}) for (LL j1:{0,1,2}) for (LL j2:{0,1,2})
				for (LL k:{0,1,2}){
					LL t1=j1*(k==1),t2=j2*(k==2);
					t1=min(2LL,i1+t1); t2=min(2LL,i2+t2);
					upd(g[t1][t2],f[u][i1][i2]*f[v][j1][j2]);
				}
			memcpy(f[u],g,sizeof f[u]);
		}
}

int main(){
	scanf("%lld",&n);
	for (LL i=1;i<n;++i){
		LL x,y; scanf("%lld%lld",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	dfs(1,1);
	memset(fa,0,sizeof fa); mx=0;
	dfs(rt,1);
	for (LL i=rt;i;i=fa[i]) d[++m]=i;
	memset(fa,0,sizeof fa);
	if (m&1){
		LL p=d[m/2+1];
		dp(p,0);
		printf("%lld\n",f[p][1][1]*inv(2)%mod);
	}
	else{
		LL p1=d[m/2],p2=d[m/2+1];
		fa[p1]=p2; fa[p2]=p1;
		dp(p1,1); dp(p2,1);
		printf("%lld\n",(f[p1][1][0]+f[p1][1][1]+f[p1][1][2])*(f[p2][1][0]+f[p2][1][1]+f[p2][1][2])%mod);
	}
	
	return 0;
}
			

Measured memory_bytes: 42240
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <iterator>
#include <queue>
#include <set>
#include <map>

using namespace std;

void solve(){
    int N,K;
    cin >> N >> K;

    long long ans = 0, t;
    t = N/K;
    ans = t*t*t;

    if(K%2==0){
        if(N%K >= K/2)t++;
        ans += t*t*t;
    }
    cout << ans << endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

ans = 0

for i in range(2**n):
    i = format(i, "b").zfill(n)
    for j in range(len(s)):
        tmp = 0
        for k in s[j][1:]:
            tmp += int(i[k - 1])

        if p[j] != tmp % 2:
            break
        if j == len(s) - 1:
            ans += 1

print(ans)


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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, ans = 0;
  string s;
  cin >> n >> s;

  for (int i = 2; i < n; i++) {
    if (s[i - 2] == 'A' && s[i - 1] == 'B' && s[i] == 'C') {
      ans++;
    }
  }

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

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a[3], m;
	scanf("%d%d%d", &a[0], &a[1], &a[2]);
	for(int i=0;i<3;i++){
		if(a[i]==5 || a[i]==7){
		
		}else{
			break;
		}
		m+=a[i];
	}
	if(m==17){
		printf("YES");
	}else{
		printf("NO");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

int main(){
    int a[3], k;
    cin >> a[0] >> a[1] >> a[2] >> k;

    sort(a, a+3);

    for(int i=0; i<k; i++){
        a[2] = a[2] * 2;
    }

    cout << a[1]+a[2]+a[0] << endl;
}

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

int main(int argc, char* argv[]){
  std::string s;
  std::cin >> s;
  int c = 0;
  for (auto i = 0; i < 4; i++){
    if (s [i] == '+'){
      c++;
    } else {
      c--;
    }
  }
  std::cout << c << std::endl;
  return 0;  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);
const ll MAX_N = 2000010;

// 素因数分解。計算量はO(√n)
map<ll, ll> primefactor(ll n) {  // (nのi番目の素因数, その素因数の個数)のmapを返す(n = 720 = (2^4)*(3^2)*(5^1)なら{(2, 4), (3, 2), (5, 1)}のように)
    map<ll, ll> res;
    for(ll i = 2; i*i <= n; i++) {
        while(n%i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) {
        res[n] = 1;
    }
    return res;
}

// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

ll inverse(ll a) {
    return modpow(a, mod-2);
}

ll inv[MAX_N];  // inv[i] : iの逆数のmod

void init() {
    inv[0] = inv[1] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        if(i >= 2) {
            inv[i] = mod - inv[mod%i]*(mod/i)%mod;
        }
    }
}

//--- main関数でinit()を呼び出すのを忘れるな ---//
int main() {
    ll n;
    cin >> n;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    map<ll, ll> mp1;
    rep(i, n) {
        map<ll, ll> mp2 = primefactor(a[i]);
        for(auto p : mp2) {
            chmax(mp1[p.first], p.second);
        }
    }

    ll lcm = 1;
    for(auto p : mp1) {
        rep(i, p.second) {
            lcm *= p.first;
            lcm %= mod;
        }
    }

    init();

    ll ans = 0;
    rep(i, n) {
        ans += lcm*inv[a[i]];
        ans %= mod;
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 16512
import numpy as np
N, M  = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(M)]
ab.sort(key=lambda student: student[1])
temp = [0,0]
count = 0
for x in ab:
    if  x[0] <= temp[0] and temp[1] <= x[1] :
        continue
    else:
        temp[0] = x[1]-1
        temp[1] = x[1]
        count += 1
print(count)                                        

Measured memory_bytes: 38060
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main{

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

	private Scanner scan;

	private boolean[] state;
	private long[] sum;
	private List<Integer> onstate;

	private int N;
	private boolean flag;

	private void mainrun() {

		scan = new Scanner(System.in);

		state = new boolean[4001];
		sum = new long[4001];
		onstate = new ArrayList<Integer>();

		while(true){
			N = scan.nextInt();

			if(N == 0) {
				break;
			}
			Arrays.fill(sum,0);
			Arrays.fill(state,false);
			
			onstate.clear();
			
			flag = false;
			
			for(int i = 0;i < N;i++){
				looprun();
			}

			onstate.sort((e1,e2)->(e1 > e2 ? 1 : 0));

			for(Integer num : onstate) {
				if(sum[num] >= 1000000) {
					flag = true;
					System.out.println(num);
				}
			}
			if(!flag) {
				System.out.println("NA");
			}

			

		}


	}


	private void looprun() {
		int e = scan.nextInt();
		long p = scan.nextInt();
		long q = scan.nextInt();

		if(!state[e]) {
			state[e] = true;
			onstate.add(e);
		}

		sum[e] += p * q;
	}

}


Measured memory_bytes: 37312
#include <bits/stdc++.h>
using namespace std;
struct times
{
    int x,y,t;
    times(){}
    times(int x,int y,int t)
    {
        this -> x = x;
        this -> y = y;
        this -> t = t;
    }
}temp;
int dir[4][2] = {0,1,1,0,0,-1,-1,0};
int h,w,c,flag = 0;
char mp[51][51];
int vis[51][51];
int main()
{
    cin>>h>>w;
    for(int i = 0;i < h;i ++)
    {
        cin.get();
        for(int j = 0;j < w;j ++)
        {
            cin>>mp[i][j];
            if(mp[i][j] == '.')c ++;
        }
    }
    if(mp[0][0] == '.' && mp[h - 1][w - 1] == '.')
    {
        queue<times> q;
        q.push(times(0,0,1));
        vis[0][0] = 1;
        while(!q.empty())
        {
            if(flag)break;
            temp = q.front();
            q.pop();
            for(int i = 0;i < 4;i ++)
            {
                int tx = temp.x + dir[i][0];
                int ty = temp.y + dir[i][1];
                if(tx < 0 || ty < 0 || tx >= h || ty >= w || vis[tx][ty] || mp[tx][ty] == '#')continue;
                vis[tx][ty] = 1;
                if(tx == h - 1 && ty == w - 1)flag = temp.t + 1;
                q.push(times(tx,ty,temp.t + 1));
            }
        }
    }
    if(flag)cout<<c - flag;
    else cout<<-1;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 2e5+1;
const ll bits = 20;
const ld pi = 3.14159265358979323846;
const ll mod = 1e9+7;
const ll p = 29;

ll dp[51][5001]; // reaching node with these many coins

vector<array<ll,3>>adj[51];
ll c[51],d[51];

int main(){

    // FASTIO;
    PRECISION; 

    ll n,m,s;
    cin>>n>>m>>s;
    ll ma = -inf;

    for(int i=0;i<m;i++){
        ll a,b,u,v;
        cin>>u>>v>>a>>b;
        adj[u].push_back({v,a,b});
        adj[v].push_back({u,a,b});
        ma = max(ma,a);
    }
    ma = ma*n;

    for(int i=1;i<=n;i++){
        cin>>c[i]>>d[i];
    }

    for(int i=1;i<=n;i++){
        for(int j=0;j<=ma;j++){
            dp[i][j] = inf;
        }
    }
    s = min(s,ma);
    dp[1][s] = 0;
    queue<array<ll,2>>q;
    q.push({1,s});
    int cntr = 0;

    while(q.size()){
        auto tp = q.front();
        q.pop();
        int u = tp[0];
        ll coins = tp[1];
        // cout<<u<<" "<<coins<<" "<<dp[u][coins]<<"\n";
        for(ll j=0;coins+j*c[u]<=ma;j++){
            ll nc = coins + j*c[u];
            ll extra_time = j*d[u];

            for(auto temp: adj[u]){
                int nxt = temp[0];
                ll a = temp[1];
                ll b = temp[2];
                // i will go from u to v
                if(nc-a>=0){
                    if(dp[nxt][nc-a]>dp[u][coins]+extra_time+b){
                        dp[nxt][nc-a] = dp[u][coins]+extra_time+b;
                        q.push({nxt,nc-a});
                    }
                }
            }
        }
    }

    for(int i=2;i<=n;i++){
        ll ans = inf;
        for(int j=0;j<=ma;j++){
            ans = min(ans,dp[i][j]);
        }
        cout<<ans<<"\n";
    }

}

Measured memory_bytes: 29204
#include <stdio.h>
#include <math.h>

int main(){
  int N;
  scanf("%d", &N);
  int A[N], B[N];
  int i, sum = 0;
  A[N] = 0;
  for (i = 0; i < N; i++) {
    B[i] = 0;
  }
  
  for (i = 1; i < N; i++) {
    A[i] = 0;
    scanf("%d", &A[i]);
    B[A[i] - 1] += 1;
  }
  
  for (i = 0; i < N; i++) {
    printf("%d\n", B[i]);
  }
  return 0;
}

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

int main(){
    int a,b; cin >> a >> b;
    string s(b,'0'+a);
    string t(a,'0'+b);
    cout << min(s,t) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N;
  cin>>N;
  ll X[N+1],P,Q;
  vector<ll> L;
  for(int i=1; i<=N; ++i){
    cin>>X[i];
    L.push_back(X[i]);
  }
  SORT(L);
  P=L.at(N/2-1);
  Q=L.at(N/2);
  RREP(i,N){
    if(X[i]<=P) cout<<Q<<endl;
    else cout<<P<<endl;
  }
}


Measured memory_bytes: 5488
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    vi vec(n+1);
    FOR(i,1,n+1){
        cin>>vec[i];
    }
    vi ans;
    for(int i=n;i>0;i--){
        int cnt=0;
        for(int j=1;i*j<=n;j++){
            if(vec[i*j]==-1){
                cnt++;
            }
        }
        if(cnt%2!=vec[i]){
            ans.pb(i);
            vec[i]=-1;
        }
    }
    reverse(all(ans));
    cout<<ans.size()<<endl;
    REP(i,ans.size()){
        if(i)cout<<" ";cout<<ans[i];
    }cout<<endl;
    return 0;
}

Measured memory_bytes: 2424
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <cmath>
#include <iomanip>
#include <iterator>

using namespace std;

clock_t timeStart, timeFinish;

void timeBegin() {
    timeStart = clock();
}

void timeEnd() {
    timeFinish = clock();
}

void timeDuration() {
    double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC);
    cout << "Time taken by program is : " << fixed << time_taken << setprecision(5);
    cout << " sec " << endl;
}

class InputReader {
public:
    InputReader() {
        input_file = stdin;
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    InputReader(const char *file_name) {
        input_file = fopen(file_name, "r");
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    inline InputReader &operator >>(int &n) {
        while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
            advance();
        }
        int sign = 1;
        if (buffer[cursor] == '-') {
            sign = -1;
            advance();
        }
        n = 0;
        while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
            n = n * 10 + buffer[cursor] - '0';
            advance();
        }
        n *= sign;
        return *this;
    }
private:
    FILE *input_file;
    static const int SIZE = 1 << 17;
    int cursor;
    char buffer[SIZE];
    inline void advance() {
        ++ cursor;
        if(cursor == SIZE) {
            cursor = 0;
            fread(buffer, SIZE, 1, input_file);
        }
    }
};

int main() {
    timeBegin();
    //ifstream cin("input.in");
    //ofstream cout("output.txt");
    long long a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;
    if (v <= w || (v - w) * t < abs(a - b)) {
        cout << "NO\n";
    } else {
        cout << "YES\n";
    }
    //timeDuration();
    return 0;
}




Measured memory_bytes: 3624
while True:
    try:
        n = int(raw_input())
    except EOFError:
        break
    count = 0
    for a in range(10):
        for b in range(10):
            for c in range(10):
                for d in range(10):
                    if a + b + c + d == n:
                        count += 1
    print count

Measured memory_bytes: 4996
#include<bits/stdc++.h>
#define N 600005
using namespace std;
int n,m,b[N];
struct T
{
	int x,y,l;
}a[N];
bool cmp(T x,T y)
{
	return x.l<y.l;
}

void mdy(int k,int l,int r,int x,int y)
{
	if (x<=l&&r<=y)
	{
		b[k]++;
		return;
	}
	int mid=l+r>>1;
	if (x<=mid) mdy(k<<1,l,mid,x,y);
	if (y>mid) mdy(k<<1|1,mid+1,r,x,y);
}
int qry(int k,int l,int r,int x)
{
	if (l==r) return b[k];
	int mid=l+r>>1;
	if (x<=mid) return b[k]+qry(k<<1,l,mid,x);
	return b[k]+qry(k<<1|1,mid+1,r,x);
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i].x,&a[i].y);
		a[i].l=a[i].y-a[i].x+1;
	}
	sort(a+1,a+n+1,cmp);
	
	for (int i=1,j=1;i<=m;i++)
	{
		while(j<=n&&a[j].l<i)
		{
			mdy(1,1,m,a[j].x,a[j].y);
			j++;
		}
		int Ans=n-j+1;
		for (int j=1;i*j<=m;j++)
			Ans+=qry(1,1,m,j*i);
		printf("%d\n",Ans);
	}
}

Measured memory_bytes: 7040
#include <stdio.h>
#define heap_size 500001

int Parent(int);
int Left(int);
int Right(int);
void MaxHeapify(int);
void BuildMaxHeap();
int A[heap_size],n;

main(){
  
  int i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  BuildMaxHeap();
  for(i=1;i<=n;i++){
    printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}

int Parent(int i){
  return i/2;
}

int Left(int i){
  return 2*i;
}

int Right(int i){
  return 2*i+1;
}
 
void MaxHeapify(int i){
  int left,right,tmp;
  int largest;
  left = Left(i);
  right = Right(i);
  if(left <= n && A[left] > A[i]){
    largest = left;
  } else {
    largest = i;
  }
  if(right <= n && A[right] > A[largest]){
    largest = right;
  }
  if(largest !=i){
    tmp = A[i];
    A[i]=A[largest];
    A[largest]= tmp;
    MaxHeapify(largest);
  }
}

void BuildMaxHeap(){
  int i;
  for(i=n/2;i>0;i--){
    MaxHeapify(i);
  }
}

Measured memory_bytes: 2548
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main()
{
    ll n,k;
    cin >> n >> k;
    ll ans = 0;
    for(ll i = k;i <= n + 1;i++)
    {
        ll Max = i * (2 * n + (i - 1) * -1) / 2;
        ll Min = i * (i - 1) / 2;
        ans = (ans + ((Max - Min + 1) % MOD)) % MOD;
    }
    cout << ans << "\n";

    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> sieve(N + 1, 1);
  sieve[0] = sieve[1] = 1;
  for (int i = 2; i < N + 1; i++) {
    if (sieve[i] == 1) {
      sieve[i] = i;
      for (int k = 2; i * k < N + 1; k++) {
        sieve[i * k] = i;
      }
    }
  }
  int64_t res = 0;
  for (int i = 1; i < N + 1; i++) {
    int64_t k = i;
    vector<int> primes;
    while (k != 1) {
      primes.emplace_back(sieve[k]);
      k /= sieve[k];
    }
    map<int, int> mp;
    for (auto p : primes) {
      mp[p]++;
    }
    int64_t x = i;
    for (const auto& [key, value] : mp) {
      x *= (value + 1);
    }
    res += x;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 42268
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {
	string s;
	cin >> s;
	for(int i=0; i<s.length(); i++){
		if(i%2==0){
			cout << s[i];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 512
import collections
n = int(input())
v = list(map(int,input().split()))
odd = collections.Counter(v[0::2]).most_common()
even = collections.Counter(v[1::2]).most_common()
odd.append((0, 0))
even.append((0, 0))
if odd[0][0] != even[0][0]:
    print(n - odd[0][1] - even[0][1])
else:
    print(n - max(odd[0][1] + even[1][1], odd[1][1] + even[0][1]))

Measured memory_bytes: 20572
import numpy as np
import scipy.misc as scm

N, P = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(A)

evens = A[A%2==0]
le = len(evens)
odds = A[A%2==1]
lo = len(odds)
ans = 0

for i in range(N+1) :
    for j in range(P,i+1,2) :
        ans += scm.comb(lo, j, 1)*scm.comb(le, i-j, 1)

print(ans)

Measured memory_bytes: 24568
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if(A == B && B == C) {
        if(A%2 == 1) {
            cout << 0;
        }
        else {
            cout << -1;
        }
    }
    else {
        int ans = 0;
        int a[110], b[110], c[110];
        a[0] = A;  b[0] = B;  c[0] = C;

        int i = 0;
        while(a[i]%2 == 0 && b[i]%2 == 0 && c[i]%2 == 0) {
            ans++;
            a[i+1] = (b[i] + c[i])/2;
            b[i+1] = (c[i] + a[i])/2;
            c[i+1] = (a[i] + b[i])/2;
            i++;
        }

        cout << ans;
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int a,b,k;cin >>  a >> b >> k;
    int eatT = min(k,a);
    a -= eatT;
    k -= eatT;
    int eatA = min(k,b);
    b -= eatA;
    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 3584
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		System.out.println(a * b >= c * d ? a * b : c * d);
	}
}


Measured memory_bytes: 35608
W,H,N=gets.split.map(&:to_i)

l,r,t,b = 0,W,H,0
$<.read.split.map(&:to_i).each_slice(3) do |x,y,a|
    case a
    when 1
        l = x if l < x
    when 2
        r = x if x < r
    when 3
        b = y if b < y
    when 4
        t = y if y < t
    end
end

if 0 < r-l && 0 < t-b
    puts (r-l)*(t-b)
else
    puts 0
end

Measured memory_bytes: 3836
#include <iostream> //以下のコードは、とても無駄が多いです。
using namespace std;

int main(){

int tokuten;
int goukei;
goukei = 0;
int i;

for ( i =0 ; i <5 ; i = i+1 ){
	cin>>tokuten;
		if(tokuten<40){ tokuten =40; }
		goukei = goukei + tokuten;
}

cout <<goukei / 5 <<endl ;

return 0;
}


Measured memory_bytes: 3092
<?php

while (true) {
    $stdin = preg_split('/ /', trim(fgets(STDIN)));
    $n = intval(array_shift($stdin));
    $x = intval(array_shift($stdin));
    $count = 0;
    
    if ($n == 0 && $x == 0) return;
    
    for ($i = 1; $i <= $n; $i++) {
        for ($j = $i + 1; $j <= $n; $j++) {
            for ($k = $j + 1; $k <= $n; $k++) {
                if ($i + $j + $k == $x) {
                    $count++;
                }
            }
        }
    }
    
    print($count . "\n");
}

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

int main() {
	int n,ans = 0;
	cin >> n;
	for (int i = 0;i < n;i++) {
		int a;
		cin >> a;
		ans += a;
	}
	cout << ans-n << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    int ma = 0, mi = INF;
    rep(i, N) {
        int x;
        cin >> x;
        ma = max(x, ma);
        mi = min(x, mi);
    }
    cout << (ma - mi + 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 3100
#!/usr/bin/env python
# -*- coding: utf-8 -*-

if __name__ == "__main__":
    N,T = map(int,input().split(" "))
    cost = []
    for i in range(N):
        c,t = map(int,input().split(" "))
        if t > T:
            continue
        else:
            cost.append(c)
    if not cost:
        print("TLE")
    else:
        print(min(cost))


Measured memory_bytes: 2940
from sys import stdin


def main() -> None:
    n = int(next_str())
    lucas = [2, 1]

    for i in range(2, n + 1):
        lucas[i % 2] = sum(lucas)

    print(lucas[n % 2])


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

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

int H, W;

int stp[21][21];
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};


int main(){
  cin >> H >> W;
  vector<vector<bool> > maze(H, vector<bool>(W, 1));
  
  for(int h = 0; h < H; h++){
    for(int w = 0; w < W; w++){
      char c; cin >> c;
      maze[h][w] = (c == '.');
    }
  }
  
  int ans = 0;
  
  for(int h = 0; h < H; h++){
    for(int w = 0; w < W; w++){
      if(!maze[h][w]) continue;
      
      for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
          stp[i][j] = -1;
        }
      }
      
      stp[h][w] = 0;
      queue<int> que;
      que.push(h);
      que.push(w);
      
      while(!que.empty()){
        int h1 = que.front(); que.pop();
        int w1 = que.front(); que.pop();
        
        for(int i = 0; i < 4; i++){
          int h2 = h1 + dh[i];
          int w2 = w1 + dw[i];
          if(h2 < 0 || h2 >= H || w2 < 0 || w2 >= W)
            continue;
          if(maze[h2][w2] && stp[h2][w2] == -1){
            stp[h2][w2] = stp[h1][w1] + 1;
            que.push(h2);
            que.push(w2);
          }
        }
      }
      
      int tmp_ans = 0;
      for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
          if(maze[i][j])
            tmp_ans = max(tmp_ans, stp[i][j]);
        }
      }
      
      ans = max(ans, tmp_ans);
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int vs[1000];
int main(void) {
  int n;
  cin >> n;
  REP(i, n) {
    cin >> vs[i];
  }
  int res = 0;
  REP(i, n) {
    if(i-1 >= 0 && i+1 < n) {
      if(vs[i-1] < vs[i] && vs[i] < vs[i+1]) {
        ++res;
      } else if(vs[i+1] < vs[i] && vs[i] < vs[i-1]) {
        ++res;
      }
    }
  }
  cout << res << endl;
  
  return 0;
}


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

int main()
{
  int a,b;
  string s;
  cin >>a>>b;
  if(a>b){
    for(int i=0;i<a;i++){
      s+=to_string(b);
    }
  }
  else{
    for(int i=0;i<b;i++){
    s+=to_string(a);
    }
  }
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class P {
  static void Main() {
    var str = Console.ReadLine().Split().Select(int.Parse).ToArray();
    Console.WriteLine(str.Sum() - str.Max());
    /*
    foreach (int i in str) {
      Console.WriteLine(i);
    }*/
  }
}

Measured memory_bytes: 13396
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
int main(){
  Dice d;
  for(int i=0;i<6;i++) cin >> d.s[i];
  int n;cin >> n;
  while(n--){
    int a,b;cin >> a >> b;
    if(d.left()==a) d.roll('E');
    if(d.right()==a) d.roll('W');
    while(d.top()!=a) d.roll('N');
    while(d.front()!=b) d.roll('R');
    cout << d.right() << endl;
  }
  return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i,n) for(int i=0;i<n;i++)
#define unsigned long ul
using namespace std;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int a[100001];
    /*if(s[0]=='A'||s[0]=='T'||s[0]=='G'||s[0]=='C'){
        a[0] = 1;
    }else{
        a[0] = 0;
    }*/
    a[0] = 0;
    REP(i, n){
        if(i==0)continue;
        if(s[i]=='C'&&s[i-1]=='A'){
            a[i] = a[i-1] + 1;
        }else{
            a[i] = a[i-1];
        }
    }
    
    REP(i, q){
        int l, r;
        cin >> l >> r;
        if(l==1){
            cout << a[r-1] << "\n";
        }else{
            cout << a[r-1] - a[l-1] << "\n";
        }
    }
    //REP(i, n){cout << a[i] << endl;}
	return 0;
}


Measured memory_bytes: 1488
#include<stdio.h>
int main(void)
{
      int a,b,c,d;
      
      scanf("%d",&a);
      scanf("%d",&b);
      scanf("%d",&c);
    
if(a>=b)
{
d=a;
a=b;
b=d;
}
if(b>=c)
{
d=b;
b=c;
c=d;
}
if(a>=b)
{d=a;
a=b;
b=d; }

printf("%d %d %d\n",a,b,c);
return(0);
    
}


Measured memory_bytes: 2112
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
pii a[MAXN];
int dp[MAXN];

int main() {
	int x1, y1, x2, y2, n, m = 0;
	scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
	if (x1 > x2) {
		swap(x1, x2);
		swap(y1, y2);
	}
	ll ans = abs(x1 - x2) + abs(y1 - y2);
	ans *= 100ll;
	ni(n);
	for (int i = 0; i < n; i++) {
		pii tmp;
		scanf("%d %d", &tmp.fi, &tmp.se);
		if (tmp.fi < x1 || tmp.fi > x2) continue;
		if (tmp.se < min(y1, y2) || tmp.se > max(y1, y2)) continue;
		a[m++] = tmp;
	}
	sort(a, a+m);
	if (x1 == x2 || y1 == y2) return !printf("%.20f\n", (double)ans + (pi * 10. - 20.) * (double)m);
	if (y1 > y2) reverse(a, a+m);
	dp[1] = 0;
	int mx = min(m,1);
	for (int i = 1; i < m; i++) {
		int lo = 1, hi = mx;
		while (lo <= hi) {
			int mi = (lo+hi) / 2;
			if (a[dp[mi]].se < a[i].se)
				lo = mi+1;
			else
				hi = mi-1;
		}	
		if (lo > mx || a[dp[lo]].se > a[i].se)
			dp[lo] = i;
		if (lo > mx)
			mx = lo;
	}
	if (mx == min(abs(x1-x2),abs(y1-y2))+1)
		printf("%.20f\n", (double)ans + (double)(mx-1) * (5. * pi - 20.) + 10. * pi - 20.);
	else
		printf("%.20f\n", (double)ans + (double)mx * (5. * pi - 20.));
    return 0;
}


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

int		main(void)
{
	priority_queue<int, vector<int>, greater<int>> train;
	priority_queue<int, vector<int>, greater<int>> bus;
	vector<int> tmp(4);
	for (int i = 0; i < 4; i++)
		cin >> tmp.at(i);
	for (int i = 0; i < 4; i++)
	{
		if (i < 2)
			train.push(tmp.at(i));
		else
			bus.push(tmp.at(i));
	}
	cout << train.top() + bus.top() << endl;

}

Measured memory_bytes: 256
fn main() {
    let (a, b, c): (u32, u32, u32) = {
        let vec: Vec<u32> = read_vec();

        (vec[0], vec[1], vec[2])
    };

    if (a < c && c < b) || (b < c && c < a) {
        println!("Yes");
    }
    else {
        println!("No");
    }

}

#[warn(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[warn(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

#[warn(dead_code)]
fn read_mat<T: std::str::FromStr>(row: u32) -> Vec<Vec<T>> {
    let mut vec = Vec::new();

    for _i in 0..row {
        vec.push(read_vec::<T>());
    }

    vec
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
        int A,B,AB,X,Y;
        cin >> A >> B >> AB >> X >> Y;
        int AaB,ABaA,ABaB;

        if(X > Y) {
                swap(A,B);
                swap(X,Y);
        }
        // X < Y
        AaB = A*X + B*Y;
        ABaA = 2*AB*Y;
        ABaB = 2*AB*X + (Y-X)* B;

        cout << min(min(AaB,ABaA),ABaB) << endl;

        return 0;
}

Measured memory_bytes: 256