akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)


int calc(int a,int b){
	int tmp = 1;
	for(int ccc=0;ccc<4*a;ccc++){
		tmp*=2;
	}
	for(int j=0;j<b;j++){
		tmp*=2;
	}
	return tmp;
}

int main(){
	int n;
	cin >> n;
	vector<pair<int,int> > p;
	for(int i=0;i<n;i++){
		int h,w;
		cin >> h >> w;
		p.PB(MP(h,w));
	}
	set<vector<pair<int,int> > >sp;
	for(int qq=0;qq<n;qq++){
		for(int i=-3;i<=3;i++){
			for(int j=-3;j<=3;j++){
				vector<pair<int,int> > z;
				for(int x = 0;x<p[qq].first;x++){
					for(int y=0;y<p[qq].second;y++){
						if(i+x>=0&&i+x<=3&&j+y>=0&&j+y<=3){
							z.PB(MP(i+x,j+y));
						}
					}
				}
				if(z.size()!=0)sp.insert(z);
			}
		}
	}
	//cout << sp.size() << endl;
	string s[4];
	for(int i=0;i<4;i++){
		cin >> s[i];
	}
	int a[4][4];
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			if(s[i][j]=='R'){
				a[i][j] = 1;
			}else if(s[i][j]=='G'){
				a[i][j] = 2;
			}else{
				a[i][j] = 3;
			}
		}
	}
	int ans=0;
	queue<pair<int,int > >q;
	bool used[100010];
	used[0] = 1;
	q.push(MP(0,0));
	set<int> st;
	bool breakflag=0;
	while(!q.empty()){
		auto x = q.front();
		q.pop();
		int f = x.first;
		int g = x.second;
		if(f==65535){
			ans = g;
			break;
		}
			for(auto w:sp){
				for(int c=1;c<4;c++){
					int s = f;
					for(int i=0;i<w.size();i++){
						if(a[w[i].first][w[i].second]==c){
							s |= calc(w[i].first,w[i].second);
						}else{
							if((s&calc(w[i].first,w[i].second))==calc(w[i].first,w[i].second)){
								s -= calc(w[i].first,w[i].second);
							}	
						}
					}
					if(s==65535){
						ans = g+1;
						breakflag = 1;
						break;
					}
					if(used[s]!=1){
						//cout << static_cast<bitset<16> > (f) << " " << static_cast<bitset<16> > (s) << endl;
						used[s]=1;
						q.push(MP(s,g+1));
					}
				}
				if(breakflag)break;	
			}
			if(breakflag)break;
		
		if(breakflag)break;
	}
	cout << ans << endl;
	return 0;
}





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

#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef long double ld;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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





int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int x,n;
    cin>>x>>n;

    int a[110]={};

    rep(i,n){
        int pi;
        cin>>pi;
        a[pi] = -1;
    }


    int d = INF;
    rep(i,110){
        if(a[i] != -1){
            if(chmin(d,abs(x-i)))ans=i;
            //db2(i,x-i);ln;
        }
    }

    cout<<ans<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 3564
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<ll,ll> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef tuple<ll,ll,ll,ll> tp;
typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cap,rev;};//ikisaki youryou gyakuhen
class MF{//max flow
	public:
	int n;
	vector<vector<edge> >G;//[MAX];
	vi level,iter;//[MAX];
	MF(int size){
		n=size;
		G=vector<vector<edge> >(n);
	}
	void add_edge(int from, int to, int cap){
		edge q={to,cap,int(G[to].size())};
		G[from].push_back(q);
		q={from,0,int(G[from].size()-1)};
		G[to].push_back(q);
	}
	void bfs(int s){
		level=vi(n,-1);
		queue<int>q;
		level[s]=0;
		q.push(s);
		while(!q.empty()){
			int v=q.front();q.pop();
			for(int i=0;i<G[v].size();i++){
				edge &e=G[v][i];
				if(e.cap>0&&level[e.to]<0){
					level[e.to]=level[v]+1;
					q.push(e.to);
				}
			}
		}
	}
	int dfs(int v,int t, int f) {
		if(v==t)return f;
		for(int &i=iter[v];i<G[v].size();i++){
			edge &e=G[v][i];
			if(level[v]>=level[e.to]||e.cap<=0) continue;
			int d =dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
		return 0;
	}
	int mf(int s,int t) {//from s to t,ford_fulkerson
		int flow=0;
		while(1){
			bfs(s);
			if(level[t]<0)return flow;
			iter=vi(n);
			int f;
			while((f=dfs(s,t,inf))>0)flow+=f;
		}
	}
};
int main(){
	int n,m;
	cin>>n>>m;
	vs in(n);
	rep(i,n)cin>>in[i];
	MF mf(n+m+2);
	int s=n+m,t=s+1;
	int sx,sy,gx,gy;
	rep(i,n)rep(j,m)if(in[i][j]=='o'){
		mf.add_edge(i,n+j,1);
		mf.add_edge(n+j,i,1);
	}else if(in[i][j]=='S'){
		sx=i;sy=j;
		mf.add_edge(s,i,inf);
		mf.add_edge(s,n+j,inf);
	}else if(in[i][j]=='T'){
		gx=i,gy=j;
		mf.add_edge(i,t,inf);
		mf.add_edge(n+j,t,inf);
	}
	if(sx==gx||sy==gy)cout<<-1<<endl;
	else cout<<mf.mf(s,t)<<endl;
}










Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);
ll n,k;
ll cnt[40];
ll fu(ll bit){
	if(bit<0) return 0;
	ll tmp1=0;
	ll tmp2=0;
	if(!((ll)k&((ll)1<<bit))) {
		tmp1+=((ll)1<<bit)*cnt[bit];
		tmp1+=fu(bit-1);
	}
	else{

		FOR(i,0,bit-1){
			tmp1+=((ll)1<<i)*max(cnt[i],n-cnt[i]);
		}
		tmp1+=((ll)1<<bit)*(cnt[bit]);
		tmp2+=((ll)1<<bit)*(n-cnt[bit]);
		tmp2+=fu(bit-1);
	}
	//dbg3(bit,tmp1,tmp2);
	return max(tmp1,tmp2);

}


int main(){

cin>>n>>k;
std::vector<ll> a(n);
fo(i,n) cin>>a[i];

fo(i,40) cnt[i]=0;
fo(i,n){
	fo(j,40){
		if(((ll)1<<j&a[i])) cnt[j]++;


	}
}

ll ans=fu(39);
//dbg(cnt[0]);
cout<<ans<<endl;


}




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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(b / a, c) << endl;
    return 0;
}

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

using namespace std;

int main() {
    int x = 0;
    int len;
    string s;
    cin >> len >> s;
    int ans = 0;
    for(int i = 0; i < len; i++) {
        if(s[i] == 'I') x++;
        else x--;
        ans = max(ans,x);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int mod = 1e9 + 7;

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> s(n);
  for (auto &e : s) {
    cin >> e;
  }
  sort(begin(s), end(s));

  vector<int> ub(x + 1);
  for (int i = 0; i <= x; i++) {
    ub[i] = upper_bound(begin(s), end(s), i) - begin(s);
  }

  vector<vector<ll>> dp(n + 1, vector<ll>(x + 1));
  dp[0][x] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= x; j++) {
      if (!dp[i][j]) continue;
      int b = ub[j];
      for (int k = 0; k < b; k++) {
        int t = j % s[k];
        dp[i + 1][t] += dp[i][j];
        dp[i + 1][t] %= mod;
      }
      dp[i + 1][j] += (n - b - i) * dp[i][j];
      dp[i + 1][j] %= mod;
    }
  }

  ll r = 0;
  for (int j = 1; j <= x; j++) {
    r += j * dp[n][j];
    r %= mod;
  }
  cout << r << endl;
}


Measured memory_bytes: 158976
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

ll const M = 1e9+7;

void solve(int tc) {
	ll n, k;
	cin>>n>>k;
	ll ans = 0;
	for(ll i=k; i<=n+1; ++i) {
		ll mn = i*(i-1)/2;
		ll mx = n*(n+1)/2 - (n-i)*(n-i+1)/2;
		ans += (mx-mn+1+M)%M;
		ans %= M;
	}
	cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    for(int tc=1; tc<=t; ++tc) {
        solve(tc);
    }    
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	long A[10] = {};
	for(int i = 0; i < n; ++i ) cin >> A[i];
	
	int a = A[0],
		b = A[1],
		i = 1, c, r;
	while( true )
	{
		if( a < b ) swap( a, b );
		c = a * b;
		while( a % b != 0 ) {
			r = b;
			b = a % b;
			a = r;
		}
		c /= b;
		if( i == n - 1 ) break;
		a = c;
		b = A[++i];
	}
	cout << c << "\n";	

	return 0;
}

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

using namespace std;

int n,np[1000000];
bool isp[1000000];

int main()
{
    memset(isp,1,sizeof isp);
    isp[0]=isp[1]=0;
    for(int i=2;i<1000;i++)
        if (isp[i]) for(int j=i*i;j<1000000;j+=i) isp[j]=false;
    for(int i=1;i<1000000;i++) np[i]+=np[i-1]+isp[i];
    while (~scanf("%d",&n)) printf("%d\n",np[n]);
    return 0;
}



Measured memory_bytes: 7992
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>

using namespace std;

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

	int n;
	cin >> n;

	map<int,int> a;
	int tmp, ans=0;
	for(int i=0;i<n;i++){
		cin >> tmp;
		if(tmp > 100000) ans++;
		else if(a.find(tmp) == a.end()){
			a[tmp] = 1;
		}
		else a[tmp]++;
	}
	for(auto i=a.begin(); i!=a.end(); i++) 
		ans += (i->first - i->second > 0? i->second : i->second - i->first);
		
	cout << ans << "\n";
	
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: chars,
    }
    let mut res = 0;
    for bit in 0..(1 << (s.len() - 1)) {
        let mut tmp: std::vec::Vec<char> = std::vec::Vec::with_capacity(s.len() * 2);
        tmp.push(s.get(0).unwrap().clone());
        for i in 0..(s.len() - 1) {
            if bit & 1 << i != 0 {
                tmp.push('+');
            }
            tmp.push(s.get(i + 1).unwrap().clone());
        }

        // print!("{:?}: ( ", bit);
        let mut r: u64 = 0;
        let mut tmp_1 = std::vec::Vec::with_capacity(tmp.len());
        for i in 0..tmp.len() {
            // print!("{:?} ", tmp[i]);
            if tmp[i] == '+' {
                r += tmp_1
                    .into_iter()
                    .cloned()
                    .collect::<String>()
                    .parse::<u64>()
                    .unwrap();
                tmp_1 = std::vec::Vec::with_capacity(tmp.len())
            } else {
                tmp_1.push(tmp.get(i).unwrap());
            }
        }
        // println!("{:?}", tmp_1);
        r += tmp_1
            .into_iter()
            .cloned()
            .collect::<String>()
            .parse::<u64>()
            .unwrap();
        // println!(") {:?}", r);
        res += r;
    }
    println!("{:?}", res);
}

Measured memory_bytes: 4352
N = int(input())
A = list(map(int, input().split()))
MOD = 10**18
if 0 in A:
    print(0)
else:
    ans = 1
    flag = True
    for a in A:
        ans *= a
        if ans > MOD:
            print(-1)
            flag = False
            break
    
    if flag:
        print(ans)

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

int n, m;
vector<vector<int>> dp;
vector<int> s, d;

int solve();

int main() {
  while(1) {
    cin >> n >> m;
    if(n + m == 0) break;
    s.resize(n);
    d.resize(m);
    for(int i = 0; i < n; ++i) cin >> s[i];
    for(int i = 0; i < m; ++i) cin >> d[i];
    cout << solve() << endl;
  }
  return 0;
}

int solve() {
  dp.assign(1 << n, vector<int>(m + 1, 1000000000));
  dp[0][m] = 0;
  for(int i = 0; i < m; ++i) {
    dp[0][i] = d[i];
    dp[0][m] += d[i];
  }
  for(int i = 1; i < (1 << n); ++i)
    for(int j = 0; j < n; ++j)
      if(i >> j & 1) {
        int bit = i - (1 << j), sum = 0;
        for(int k = 0; k < n; ++k)
          if(i >> k & 1) sum += s[k];
        vector<int> v(m + 1, 0);
        for(int k = 0; k < m; ++k) {
          v[k] = min(dp[bit][k], abs(d[k] - sum));
          v[m] += v[k];
        }
        if(dp[i][m] > v[m]) dp[i] = v;
      }
  return dp[(1 << n) - 1][m];
}


Measured memory_bytes: 17536
import sys
input = sys.stdin.readline

# B - Battle
def win_takahashi(A, B, C, D):

	for i in range(200):
		if i % 2 == 0:
			if B >= C:
				return True
			else:
				C -= B
		else:
			if D >= A:
				return False
			else:
				A -= D
			

A, B, C, D = map(int, input().split())

if win_takahashi(A, B, C, D):
	print('Yes')
else:
	print('No')


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

void Main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    sort(a.begin(), a.end());
    vector<int> b(1000000);
    int num = 0;
    int c = 1;
    for (int i = 0; i < n; i++)
    {
        if(i < n-1 && a[i] == a[i+1]){
            c++;
            continue;
        }
        for (int j = a[i]; j <= 1000000; j += a[i])
        {
            b[j] += c;
        }
        c = 1;
    }
    for (int i = 0; i < n; i++)
    {
        if(b[a[i]] > 1){
            num++;
        }
    }

    cout << n - num << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 8008
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define K 10005
#define LEN 2000005
int numbers[LEN];
int sortedNums[LEN];

void countingSort(int n){
  int C[K];
  for(int i = 0; i <= K; ++i){
    C[i] = 0;
  }
  for(int i = 0; i < n; ++i){
    ++C[numbers[i]];
  }
  for(int i = 1; i <= K; ++i){
    C[i] = C[i] + C[i - 1];
  }
  for(int i = 0; i < n; ++i){
    sortedNums[C[numbers[i]] - 1] = numbers[i];
    --C[numbers[i]];
  }
}
void printArray(int *array, int n){
  for(int i = 0; i < n; ++i){
    printf("%d", array[i]);
    if(i != n - 1)
      printf(" ");
  }
  printf("\n");
}
int main(){
  int n;
  scanf("%d", &n);
  for(int i = 0; i < n; ++i){
    scanf("%d", &numbers[i]);
  } 
  countingSort(n);
  printArray(sortedNums, n);
  return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
// pll pp; (pp.first,pp.second)

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl

int main() {
  ll n,m;
  cin >> n >> m;
  pll pp[100000];
  REP(i,n){
    ll a,b;
    cin >> a >> b;
    pp[i] = make_pair(a,b);
  }
  sort(pp,pp+n);
  ll ans = 0;
  REP(i,n){
    ll tm = min(m,pp[i].second);
    ans += tm * pp[i].first;
    m -= tm;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef int64_t Int;
using namespace std;
 
int main(){
    string S; int Q;
    cin >> S >> Q;

    deque<char> DQ;
    rep(i, S.length()) DQ.push_back(S[i]);
 
    bool head = true;
    rep(q, Q){
        int T; cin >> T;
 
        if(T == 1) head = !head;
        if(T == 2){
            int F; char C; cin >> F >> C;
            if((F == 1 && head) || (F == 2 && !head)) DQ.push_front(C);
            if((F == 2 && head) || (F == 1 && !head)) DQ.push_back(C);  
        }
    }

    string ans;
    while(!DQ.empty()) {ans.push_back(DQ.front()); DQ.pop_front();}
 
    if(!head) reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 1416
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        new Thread(null, () -> {
            int n;
            int k;
            List<Integer> as = new ArrayList<>();
            try (Scanner sc = new Scanner(System.in)) {
                n = sc.nextInt();
                k = sc.nextInt();
                for (int i = 0; i < n; i++) {
                    as.add(sc.nextInt() - 1);
                }
            }
            System.out.println(new Calculator(n, k, as).calculate());
        }, "", 1 << 24).start();
    }
}

/**
 * 計算クラス
 */
class Calculator {
    /**
     * 整数K
     */
    private int k;

    /**
     * 転送先を変えなければならないテレポータの数
     */
    private int answer = 0;

    /**
     * 計算済みかどうか
     */
    private boolean isCalculate = false;

    /**
     * ある町へ転送するテレポータが設置されている町のリスト
     */
    private List<List<Integer>> lists = new ArrayList<>();

    /**
     * コンストラクタ
     *
     * @param n  町の数
     * @param k  整数K
     * @param as 各町のテレポータの転送先リスト
     */
    Calculator(int n, int k, List<Integer> as) {
        this.k = k;
        for (int i = 0; i < n; i++) {
            this.lists.add(new ArrayList<>());
        }
        for (int i = 0; i < n; i++) {
            int j = as.get(i);
            if (0 < i) {
                this.lists.get(j).add(i);
            } else if (0 < j) {
                this.answer++;
            }
        }
    }

    /**
     * 転送先を変えなければならないテレポータの数を求める
     *
     * @return 転送先を変えなければならないテレポータの数
     */
    int calculate() {
        if (!this.isCalculate) {
            this.dfs(0, 0);
            this.isCalculate = true;
        }
        return this.answer;
    }

    /**
     * 転送回数を算出する
     *
     * @param a   着目する町
     * @param pre 1つ前の町
     * @return 転送回数
     */
    private int dfs(int a, int pre) {
        int h = 0;
        for (int i : this.lists.get(a)) {
            h = Math.max(h, this.dfs(i, a));
        }
        if (0 < pre && h == this.k - 1) {
            h = 0;
            this.answer++;
        } else {
            h++;
        }
        return h;
    }
}

Measured memory_bytes: 47068
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let N = get!(u64);
    let mut abs: Vec<(u64, u64)> = get!(u64, u64; N);
    abs.sort_by(|x, y| x.1.cmp(&y.1));
    let mut a_sum = 0;
    for &(A, B) in abs.iter() {
        a_sum += A;
        if a_sum > B {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


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

int main() {
  int n; cin >>n;
  vector<int> a(n);
  rep(i,n) cin >>a[i];
  sort(a.rbegin(), a.rend());
  int t = n-1;
  ll ans = 0;
  rep(i,n){
    int lim = 2;
    if(i==0) lim = 1;
    rep(j,lim){
      if(t>0){
        ans += a[i];
        t--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4032
n = int(input())
a = list(map(int, input().split()))

mapa = {4:0, 2:0, 1:0}

for i in a:
    if i % 4 == 0:
        mapa[4] += 1
    elif i % 2 == 0:
        mapa[2] += 1
    else:
        mapa[1] += 1
if mapa[2] > 0:
    mapa.pop(2)
    mapa[1] += 1
if mapa[1] > mapa[4] + 1:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 14228
#include<bits/stdc++.h>
using namespace std;
//万合以致，向阳而生——背叛时代，忠于时间//
#pragma GCC optimize(3,"Ofast","inline")
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef unsigned long long ull;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(register int i=0; i<n; i++)
#define Forn(i, n) for(register int i=1; i<=n; i++)
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define Foreach(it, a) for(__typeof((a).rbegin()) it=(a).rbegin(); it!=(a).rend(); it++)
#define mid l+r>>1
#define lid id<<1|1
#define rid (id<<1)+2
#define lson lid, l, mid
#define rson rid, mid, r

inline int in()
{
    char c=getchar();
    int neg=1, x=0;
    while(!isdigit(c)) (c=='-')?neg=-1, c=getchar():c=getchar();
    while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48), c=getchar();
    return neg*x;
}
inline int lcm(int a, int b){return a*b/__gcd(a, b);}

const int MAX=20e5+5;

int N, M, ret, ptr, mark[MAX], v[MAX];
char tt[MAX];
set<int> tmp;
string s, t;

struct Hash
{
        int val, mod, seed;
        Hash(int _m=1e9+7, int _s=61):val(0), mod(_m), seed(_s){}
        inline int update(int x)
        { 
            val=(1LL*val*seed+x)%mod; 
            return val;
        }
        inline int v(){ return val; }
}h;

struct Hash_suff// const int MAX=???
{
        Hash a;
        int ptr, mod, hash[MAX], base[MAX];
        Hash_suff() {}
        inline void init(int _m, int _p)
        {
            ptr=0;
            mod=a.mod=_m, a.seed=_p, a.val=0;
            base[0]=1;
            Forn(i, MAX-1)
                base[i]=1LL*base[i-1]*_p%_m;
        }
        inline void update(int x)
        { hash[++ptr]=a.update(x); }
        inline int get(int l, int r)// (l,r]
        { return (hash[r]-1LL*hash[l]*base[r-l]%mod+mod)%mod; }
        inline int getl(int l1, int r1, int l2, int r2)
        {
            int t1=get(l1, r1), t2=get(l2, r2);
            return (1LL*t1*base[r2-l2]+t2)%mod;
        }
}H;

int main()
{
    memset(mark, -1, sizeof(mark));
    H.init(1e9+7, 61);
    scanf("%s", tt); s=tt;
    scanf("%s", tt); t=tt;
    while(s.size()<t.size()) s+=s;
    N=s.size(), M=t.size();
    s+=s;
    forn(i, N*2) H.update(s[i]-'a'+1);
    forn(i, M) h.update(t[i]-'a'+1);
//    forn(i, N-M+1) cout<<H.get(i, i+M)<<" "<<h.v()<<endl;
    forn(i, N) if(mark[i]==-1)
    {
        int p=i, c=0;
        tmp.clear();
//        cout<<" "<<i<<endl;
        while(H.get(p, p+M)==h.v())
        {
//            cout<<p<<endl;
            if(tmp.count(p))
            {
                puts("-1");
                return 0;
            }
            if(~mark[p])
            {
                c=mark[p];
                break;
            }
            v[ptr++]=p, tmp.insert(p);
            p=(p+M)%N;
        }
        if(!ptr) mark[i]=0;
        else
        {
            c++;
            while(ptr>0)
                mark[v[ptr-1]]=c,
                c++, ptr--;
            ret=max(ret, c-1);
        }
    }
    printf("%d\n", ret); 
    return 0;
}
// baaab
//abaaba


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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    rep(i,0,n) cin >> a[i];
    sort(all(a));
    int num=0;
    int cnt=0;
    int ans = 0;
    rep(i,0,n){
        if(num!=a[i]){
            if(num > cnt) ans += cnt;
            else ans += cnt-num;
            cnt=1;
            num = a[i];
        }else{ 
            cnt++;
        }
    }
    if(num > cnt) ans += cnt;
    else ans += cnt-num;

    cout << ans << endl;
}

Measured memory_bytes: 640
from math import sqrt
N,D = map(int,input().split())
X = [[int(i) for i in input().split()] for j in range(N)]
count = 0

for i in range(N-1):
  for j in range(i+1,N):
    tmp = sqrt(sum([(a-b)**2 for a,b in zip(X[i],X[j])]))
    if tmp == int(tmp):
      count += 1
      
print(count)

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

#define rep(i, n) for (ll i=0;i<(n); i++)
# define ALL(v) (v).begin(), (v).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

//vector<vector<ll> > comb(ll n, ll b){





int main(){
  ll n,q,a,b,p,x,cnt;
  cnt = 0;
  cin >> n;
  vector<ll> v(n);

  rep(i,n) {
    cin >> x;
    v.at(i) = x;
  }

  for(ll i=n-1;i>=0;i--) {
    a = 0;
    b= n/(i+1);
    // cout<< b<< endl;
    for(ll j=1;j<=b;j++){
      a += v.at(j*(i+1)-1);
    }
    // cout << "i: " << i << " a: " << a << "v[i]: " <<v[i] << endl;
    if (a%2!=v.at(i)){
      if(v[i]==0) v[i] = 1;
      else v[i]=0;
    }
    // cout << "i: " << i << " a: " << a << "v[i]: " <<v[i] << endl;
  }
  cout << accumulate(ALL(v), 0) << endl;

  rep(i,n){
    if(v[i]==1) cout << (i+1) << " ";
  }
  
}


Measured memory_bytes: 2432
N = input()
S = input()

current_num_max=0
current_num=0
text = list(S)
for c in text:
    if c == 'I':
        current_num+=1
    else:
        current_num-=1

    if current_num > current_num_max:
        current_num_max = current_num

print(current_num_max)


Measured memory_bytes: 2940
#include <stdio.h>
#define N 505
int n,m;
char x[N][N];
char t[N];
inline void gen(char *s,char a,int w) {
	s[w]=0;
	while(w--) s[w]=a;
}
int main() {
	int i;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;++i) scanf("%s",x[i]);
	puts(x[0]);
	gen(t,'#',m);t[m-1]='.';
	for(i=1;i<n-1;++i) puts((i&1)?t:(x[i][0]='#',x[i]));
	puts(x[0]);puts("");puts(x[0]);
	gen(t,'#',m);t[0]='.';
	for(i=1;i<n-1;++i) puts((i&1)?(x[i][m-1]='#',x[i]):t);
	puts(x[0]);
	return 0;
}

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

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
using namespace std;
typedef long long ll;
ll M = 32;

ll L1(pair<ll, ll> x){
    return abs(x.first) + abs(x.second);
}

pair<ll, ll> sub(pair<ll, ll> x, pair<ll, ll> y){
    return make_pair(x.first - y.first, x.second - y.second);
}

void operation(ll* dist, pair<ll, ll> y) {
    char op[M+1];
    op[M] = 0;
    pair<ll, ll> now = y;
    for (ll i = M-1; i >=0; i--) {
        pair<ll, ll> u = make_pair(0, dist[i]);
        pair<ll, ll> d = make_pair(0, -dist[i]);
        pair<ll, ll> l = make_pair(-dist[i], 0);
        pair<ll, ll> r = make_pair(dist[i], 0);

        if (L1(sub(now, u)) < dist[i]) {
            op[i] = 'U';
            now = sub(now, u);
        }
        else if(L1(sub(now, d)) < dist[i]) {
            op[i] = 'D';
            now = sub(now, d);
        }
        else if(L1(sub(now, l)) < dist[i]) {
            op[i] = 'L';
            now = sub(now, l);
        }
        else {
            op[i] = 'R';
            now = sub(now, r);
        }
    }
    cout << op << "\n";
}

int main(){
	ll N;
	ll dist[M];
	cin >> N;
	vector<pair<ll, ll> >coor;
	ll parity = -1;
    REP(i, N){
        ll tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        coor.push_back(make_pair(tmp1,tmp2));
        if (parity == -1){
            parity = abs((tmp1 + tmp2) % 2);
        }
        else {
            if (parity != abs((tmp1 + tmp2) % 2)){
                cout << -1 << "\n";
                return 0;
            }
        }
    }

    REP(i, M) dist[i] = pow(2, i);
    if (parity == 1){
        cout << M << "\n";
        REP(i, M) cout << dist[i] << " ";
        cout << "\n";
        REP(i, N) {
            operation(dist, coor[i]);
        }
    }
    else {
        cout << M+1 << "\n";
        cout << 1 << " ";
        REP(i, M) cout << dist[i] << " ";
        cout << "\n";
        pair<ll, ll> offset = make_pair(0, 1);
        REP(i, N) {
            cout << "U";
            operation(dist, sub(coor[i], offset));
        }
    }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int A,B,M;cin >> A >> B >> M;
    int a[A],b[B],x[M],y[M],c[M];
    for(int i = 0;i < A;i++)cin >> a[i];
    for(int i = 0;i < B;i++)cin >> b[i];
    for(int i = 0;i < M;i++)cin >> x[i] >> y[i] >> c[i];
    int miniprice,index,initialmin,initialmin2;
    for(int i = 0;i < A;i++)
    {
        if(i == 0)initialmin = a[i];
        else initialmin = min(initialmin,a[i]);
    }
    for(int i = 0;i < A;i++)
    {
        if(i == 0)initialmin2 = a[i];
        else initialmin2 = min(initialmin2,a[i]);
    }
    initialmin += initialmin2;
    for(int i = 0;i < M;i++)
    {
        if(i == 0)miniprice = a[x[i] - 1] + b[y[i] - 1] - c[i];
        else miniprice = min(miniprice,(a[x[i] - 1] + b[y[i] - 1] - c[i]));
    }
    cout << min(initialmin,miniprice) << endl;
    return 0;

}


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

class Main{

    static class DP{
        int l,r, cost, useCost;
        DP(int l,int r){this.l=l;this.r=r;}
    }
    static DP[] dp;
    static int[] sum;
    static class RMQ{
        int data1[];
        int data2[];
        int N;
        RMQ(int n){
            N=1;
            while(N<n)N*=2;
            data1 = new int[2*N];
            data2 = new int[2*N];
            Arrays.fill(data1, Integer.MAX_VALUE/10);
            Arrays.fill(data2, Integer.MAX_VALUE/10);
        }
        void set1(int i, int x){
            i+=N;
            data1[i]=Math.min(data1[i], x);
            for(i=i/2;i>0;i/=2)data1[i]=Math.min(data1[2*i], data1[2*i+1]);
        }
        void set2(int i, int x){
            i+=N;
            data2[i]=Math.min(data2[i], x);
            for(i=i/2;i>0;i/=2)data2[i]=Math.min(data2[2*i], data2[2*i+1]);
        }
        //[l, r)
        int getMin1(int l, int r){return getMin(l, r, 1, 0, N, data1);}
        int getMin2(int l, int r){return getMin(l, r, 1, 0, N, data2);}
        int getMin(int l, int r, int k, int a,int b, int[] data){
            if(b<=l || r<=a)return Integer.MAX_VALUE/10;
            if(l<=a && b<=r)return data[k];
            return Math.min(getMin(l, r, 2*k, a, (a+b)/2, data), getMin(l, r, 2*k+1, (a+b)/2, b, data));
        }
    }
    
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        sum = new int[N+1];
        for(int i=0;i<N;++i)sum[i+1]=sum[i]+scan.nextInt();
        int Q = scan.nextInt();
        dp = new DP[Q+1];
        dp[0] = new DP(0, 0);
        // [l, r]　1-index
        for(int i=0;i<Q;++i)dp[i+1] = new DP(scan.nextInt(), scan.nextInt());
        Arrays.sort(dp, (a,b)->a.l==b.l ? b.r-a.r : a.l-b.l);
        RMQ rmq = new RMQ(N+2);
        dp[0].useCost =0;
        rmq.set1(dp[0].r, 0);
        rmq.set2(dp[0].r, 0);
        for(int i=1;i<=Q;++i){
            // li<rk<ri
            dp[i].useCost = Math.min(dp[i].r-sum[dp[i].r] + rmq.getMin1(dp[i].l, dp[i].r), 2*sum[dp[i].l-1] + dp[i].r -(dp[i].l-1) -sum[dp[i].r] + rmq.getMin2(0, dp[i].l));
            rmq.set1(dp[i].r, dp[i].useCost -dp[i].r + sum[dp[i].r]);
            rmq.set2(dp[i].r, dp[i].useCost - sum[dp[i].r]);
        }
        // for(int i=0;i<=Q;++i)System.out.println("("+dp[i].l+", "+dp[i].r+") : "+dp[i].useCost);
        // System.out.println();
        // for(int i=0;i<=N;++i)System.out.println(i+" "+rmq.getMin1(i, i+1) + " "+rmq.getMin2(i, i+1));
        int ans = Integer.MAX_VALUE;
        for(int i=0;i<=Q;++i)ans=Math.min(ans, dp[i].useCost + sum[N]-sum[dp[i].r]);
        System.out.println(ans);
    }
}

Measured memory_bytes: 159200
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    cin.tie(0);cout.tie(0);
    ios::sync_with_stdio(false);
    ll A,B,K;cin>>A>>B>>K;
    ll p=min(A,K);
    A-=p,K-=p;
    ll q=min(B,K);
    B-=q,K-=q;
    cout<<A<<" "<<B<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
ll k (ll a){
    a--;
    ll ans =0;
    while(a != 0){
        ans += a;
        a--;
        
    }
    return ans;
}


int main(){
    int size;
    string s;
    cin >> size >> s;

    int ans = 1;
    REP(i,size-1){
        if(s[i] == s[i+1]){
            continue;
        }else{
            ans++;
        }
    }

    

    cout << ans <<endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define sz(a) (int)a.size()
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(){

	int n,m;cin>>n>>m;
	vi a(n);
	inputarr(a,n);
	int ans=0;
	for(auto i:a) if(i%2) return cout<<0,0;
	int cur=1;
	// for(int i=0;i<n;i+)
	for(auto i:a){
		cur=LCM(i/2,cur);
		if(cur>m) return cout<<0,0;
	}
	// trace
	// if(cur%2==0) return cout<<0,0;
	for(auto i:a){
		// if((cur%2==0) return cout<<0,0;
		// trace(cur,)
		// trace()
		if((2*cur/i)%2==0) return cout<<0,0;
 	}
	// trace(cur);
	ans=(m+cur)/(2*cur);
	cout<<ans<<endl;




    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 1024
A, B = list(map(int, input().split()))

begin = int(min(A // 0.08, B // 0.10))
end = int(max((A + 1) // 0.08, (B + 1) // 0.10))

for n in range(begin, end+1):
    if int(n * 0.08) == A and int(n * 0.1) == B:
        print(n)
        break
else:
    print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <list>

using namespace std;

int main(){
    int N,T;
    list<int> lst;
    scanf("%d %d", &N, &T);

    for(int i = 0; i < N; i++){
        int ci,ti;
        scanf("%d %d",&ci,&ti);
        if(ti <= T){
            lst.push_front(ci);
        }
    }
    list<int>::iterator itr;
    lst.sort();
    if(lst.size() == 0)
        cout << "TLE" << endl;
    else
        cout << *lst.begin() << endl;
}

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

int main() {
	int a[4], b[4];
	while (cin>> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]){
		int ht = 0, bl = 0;
		for (int i = 0; i < 4; i++) {
			if (a[i] == b[i])
				ht++;
		}
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				if (i != j && a[i] == b[j])
					bl++;
			}
		}
		printf("%d %d\n", ht, bl);
	}
	return 0;
}




Measured memory_bytes: 3008
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
using namespace std;
int main() {
  int N,T,A;
  int h[1100];
  cin >>N>>T>>A;
  for(int i=1; i<=N;i++)
    cin >>h[i];
  int min=500000000;
  int index;
  int t;
  for(int i=1; i<=N; i++){
    t=T*1000-h[i]*6;
    if(min>abs(t-A*1000) ){min=abs(t-A*1000); index=i;}
  }
  cout << index;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 998244353;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, S;
int A[MAX_N];

ll dp[3010][3010];

void solve() {
	cin >> N >> S;
	rep(i, 0, N) cin >> A[i];

	ll res = 0;
	rep(i, 0, N) {
		rep(j, 0, S + 1) {
			ADD(dp[i + 1][j], dp[i][j]);
			if(j + A[i] <= S) ADD(dp[i + 1][j + A[i]], dp[i][j]);
		}
		ADD(dp[i + 1][A[i]], i + 1);
		ADD(res, dp[i + 1][S]);
	}
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 71936
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MAX=1000000007;



signed main() {
int n;
cin>>n;
long double x,y;
char d;
long double maxx=-1*MAX,minx=MAX,maxy=-1*MAX,miny=MAX,lmaxx=-1*MAX,lminx=MAX,rmaxx=-1*MAX,rminx=MAX,umaxy=-1*MAX,uminy=MAX,dmaxy=-1*MAX,dminy=MAX;
for(int i=0;i<n;i++){
    cin>>x>>y>>d;
    if(d=='R'){
        maxy=max(maxy,y);
        miny=min(miny,y);
        rmaxx=max(rmaxx,x);
        rminx=min(rminx,x);
    }
    if(d=='L'){
        maxy=max(maxy,y);
        miny=min(miny,y);
        lmaxx=max(lmaxx,x);
        lminx=min(lminx,x);
    }
    if(d=='U'){
        umaxy=max(umaxy,y);
        uminy=min(uminy,y);
        maxx=max(maxx,x);
        minx=min(minx,x);
    }
    if(d=='D'){
        dmaxy=max(dmaxy,y);
        dminy=min(dminy,y);
        maxx=max(maxx,x);
        minx=min(minx,x);
    }
}
long double ans=(max(maxx,max(rmaxx,lmaxx))-min(minx,min(lminx,rminx)))*(max(maxy,max(umaxy,dmaxy))-min(miny,min(uminy,dminy)));
long double a=max(maxx,max(rmaxx,lmaxx))-min(minx,min(lminx,rminx)),b=max(maxy,max(umaxy,dmaxy))-min(miny,min(uminy,dminy));
rmaxx+=0.5;lmaxx-=0.5;rminx+=0.5;lminx-=0.5;umaxy+=0.5;uminy+=0.5;dmaxy-=0.5;dminy-=0.5;
while(a>max(maxx,max(rmaxx,lmaxx))-min(minx,min(lminx,rminx))||b>max(maxy,max(umaxy,dmaxy))-min(miny,min(uminy,dminy))){
    ans=min(ans,(max(maxx,max(rmaxx,lmaxx))-min(minx,min(lminx,rminx)))*(max(maxy,max(umaxy,dmaxy))-min(miny,min(uminy,dminy))));
  a=max(maxx,max(rmaxx,lmaxx))-min(minx,min(lminx,rminx));b=max(maxy,max(umaxy,dmaxy))-min(miny,min(uminy,dminy));
rmaxx+=0.5;lmaxx-=0.5;rminx+=0.5;lminx-=0.5;umaxy+=0.5;uminy+=0.5;dmaxy-=0.5;dminy-=0.5;
}
cout<<setprecision(12)<<ans;

 
   

      return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a, b;
  while(true)
  {
    cin >> a >> b;
    if(a==0&&b==0) return 0;
    int k = a;
    while(a--)
    {
      int r = b;
      while(r--)
      {
        if(r==b-1 || r==0 || a==0 || a == k-1) cout << "#";
        else cout << ".";
      }
      cout << "\n";
    }
    cout << "\n";
  }
}


Measured memory_bytes: 3020
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,x;
cin >> n >> x;
vector<int>vec(n);
for(int i =0;i<n;i++){
    cin >> vec[i];
}    
int count=0;
for(int i = 0;i<n;i++){
    count +=vec[i];
}
int us = x - count;
int min = vec[0];
for(int i = 0;i<n;i++){
    if(vec[i]<min){
        min =vec[i];
    }
}
cout << us/min + n << endl;



}


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


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

    map<string, int> words;
    int max = 0;

    rep(i,n){
        string s;
        cin >> s;
        words[s]++;
        if (words[s] > max) max = words[s];
    }

    for(auto i = words.begin(); i != words.end(); ++i){
        if(i->second == max) cout << i->first << endl;
    }

    return 0;
    
}

Measured memory_bytes: 25216
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static int process(TestCase testCase) {
        final int N = testCase.N;
        List<Integer> h = testCase.h;

        // TODO: optimize sum count
//        int sum = h.stream().mapToInt(i -> i).sum();

        int total = 0;

        while (sum(h) > 0) {
            total += computeAndUpdateHeight(h, N);
        }

        return total;
    }

    private static int computeAndUpdateHeight(List<Integer> h, int N) {
        int totalInOneIteration = 0;
        int start = 0;
        PriorityQueue<Integer> minHeap = new PriorityQueue<>();
        for (int i = 0; i < N; ++i) {
            final Integer hi = h.get(i);
            if (hi == 0) {
                totalInOneIteration += computeAndUpdateSection(h, start, minHeap, i);
                minHeap = new PriorityQueue<>();
                start = i + 1;
            } else {
                minHeap.add(hi);
            }
        }

        return totalInOneIteration + computeAndUpdateSection(h, start, minHeap, N);
    }

    private static int computeAndUpdateSection(List<Integer> h, int start, PriorityQueue<Integer> minHeap, int i) {
        final Integer minValue = minHeap.poll();
        if (null != minValue && minValue > 0) {
            updateForSection(h, start, i, minValue);
            return minValue;
        } else {
            return 0;
        }
    }

    private static void updateForSection(List<Integer> h, int startInclusive, int endExclusive, int minValue) {
        for (int i = startInclusive; i < endExclusive; ++i) {
            h.set(i, h.get(i) - minValue);
        }

    }

    private static int sum(List<Integer> h) {
        return h.stream().mapToInt(i -> i).sum();
    }

    // Util func

    public static void main(String[] args) {
        TestCase testCase = readFromInput();

        final int result = process(testCase);

        output(result);
    }

    private static TestCase readFromInput() {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        List<Integer> h = new ArrayList<>();
        for (int i = 0; i < N; ++i) {
            h.add(sc.nextInt());
        }

        sc.close();
        return new TestCase(N, h);
    }

    private static void output(int result) {
        System.out.println(result);
    }

    public static class TestCase {
        final int N;
        final List<Integer> h;

        public TestCase(int N, List<Integer> h) {
            this.N = N;
            this.h = h;
        }
    }
}


Measured memory_bytes: 28628