akhauriyash/Code-Regression huggingface dataset:
/*-------------------------------"ANJAN AGARWALA"-----------------------------

         _/_/_/_/    _/_/    _/   _/_/_/_/   _/_/_/_/    _/_/    _/   
        _/    _/    _/ _/   _/         _/   _/    _/    _/ _/   _/        
       _/_/_/_/    _/   _/ _/         _/   _/_/_/_/    _/  _/  _/         
      _/    _/    _/    _/_/   _/    _/   _/    _/    _/    _/_/  
     _/    _/    _/      _/   _/_/_/_/   _/    _/    _/      _/   

-------------------------------------@anjn98---------------------------------*/

//#define opti
#ifdef opti
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long long int LL;
typedef unsigned long long int ull;
ll power(ll x,ll y,ll p){ll r=1; x=x%p; while(y){ if(y&1) r= r*x%p; y=y>>1; x=x*x%p; } return r; }
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;*/

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int csrand(int l=0, int r=1e9){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

#define IO              ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FILEIO          freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define all(v)          v.begin(),v.end()
#define PR(a)           cout<<"("<<a<<")";
#define ED              cout<<'\n';
#define endl            '\n'
#define loop(j,a,n)     for(int j=a;j<=n;j++)
#define loop1(j,a,n)    for(int j=a;j>=n;j--)
#define fr1(j,n)        for(int j=0;j<n;j++)
#define fr(n)           for(int i=0;i<n;i++)
#define trav(x,s)       for(auto x:s)
#define SC(n)           scanf("%d",&n)
#define PB              push_back
#define MP              make_pair
#define pii             pair<int,int>
#define pll             pair<long long int,long long int>
#define F               first
#define S               second 
#define binf            2000000000000000001
#define mod             1000000007

const int N=1e5+99;

int n,k;
int dp[N][2],a[N];


int solve(int k,int t)
{
    if(k<0) return 1;
    if(k==0) return 0;

    if(dp[k][t]!=-1) return dp[k][t];
    
    for(int i=1;i<=n;i++) if(solve(k-a[i],t^1)==0) {return dp[k][t]=1;}

    return dp[k][t]=0;
}


int main() 
{
    IO
    memset(dp,-1,sizeof(dp));

    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];

    int ans=solve(k,0);


    if(ans) cout<<"First"<<endl;
    else    cout<<"Second"<<endl;

}




 

Measured memory_bytes: 5760
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var (tt, aa) = readLine()!!.split(" ").map(String::toLong)
    for (i in 2..n) {
        val (t, a) = readLine()!!.split(" ").map(String::toInt)
        val x = Math.max((tt + t - 1) / t, (aa + a - 1) / a)
        tt = t * x
        aa = a * x
    }
    println(tt + aa)
}


Measured memory_bytes: 36160
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 1e5+10;
int n;
ll a[N];

int main(){
	n=read();
	For(i,1,n) a[i]=read();
	sort(a+1,a+1+n);
	if (a[1]<0&&a[n]>=0){
		ll ans=0;
		For(i,1,n) ans+=abs(a[i]);
		printf("%lld\n",ans);
		int l=1;
		while (a[l]<0) ++l;
		For(i,l,n-1) printf("%lld %lld\n",a[1],a[i]),a[1]-=a[i];
		FOR(i,1,l) printf("%lld %lld\n",a[n],a[i]),a[n]-=a[i];
		return 0;
	}
	if (a[1]<0){
		ll ans=a[n]-a[n-1];
		For(i,1,n-2) ans+=abs(a[i]);
		printf("%lld\n",ans);
		printf("%lld %lld\n",a[n],a[n-1]),a[n]-=a[n-1];
		For(i,1,n-2) printf("%lld %lld\n",a[n],a[i]),a[n]-=a[i];
	} else {
		ll ans=-a[1];
		For(i,2,n) ans+=a[i];
		printf("%lld\n",ans);
		FOR(i,2,n) printf("%lld %lld\n",a[1],a[i]),a[1]-=a[i];
		printf("%lld %lld\n",a[n],a[1]);
	}
}

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

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

int W, H, sx, sy, gx, gy;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
vector <vector <int>> maze;

bool inrange(int x, int y) {
	return 0 <= x && x < W && 0 <= y && y < H;
}

int dfs(int x, int y, int cnt) {
	if (x == gx && y == gy) return cnt;
	if (cnt == 10) return INF;
	int res = INF;
	rep(4, i) {
		int nx = x + dx[i], ny = y + dy[i];
		if (inrange(nx, ny) && maze[ny][nx] == 3) {
			res = min(cnt+1, res);
			continue;
		}
		if (inrange(nx, ny) && maze[ny][nx] != 1) {
			while (inrange(nx+dx[i], ny+dy[i]) && maze[ny+dy[i]][nx+dx[i]] != 1 && maze[ny+dy[i]][nx+dx[i]] != 3) {
				nx += dx[i];
				ny += dy[i];
			}
			if (inrange(nx+dx[i], ny+dy[i]) && maze[ny+dy[i]][nx+dx[i]] == 3) {
				res = min(cnt+1, res);
				continue;
			}
			if (!inrange(nx+dx[i], ny+dy[i])) continue;
			if (maze[ny+dy[i]][nx+dx[i]] == 1) maze[ny+dy[i]][nx+dx[i]] = 0;
			res = min(res, dfs(nx, ny, cnt+1));
			if (maze[ny+dy[i]][nx+dx[i]] == 0) maze[ny+dy[i]][nx+dx[i]] = 1;
			//cout << cnt << ' ' << nx << ' ' << ny << endl;
		}
	}
	return res;
}

void solve(void){
	while (1) {
		cin >> W >> H;
		if (W == 0 && H == 0) break;
		vector <vector <int>> m(H, vector <int> (W, -1));
		maze = m;
		rep(H, i) rep(W, j) {
			cin >> maze[i][j];
			if (maze[i][j] == 2) {
				sx = j, sy = i;
			}
			if (maze[i][j] == 3) {
				gx = j, gy = i;
			}
		}
		int ans = dfs(sx, sy, 0);
		//cout << sx << ' ' << sy << ' ' << gx << ' ' << gy << endl;
		cout << (ans == INF ? -1 : ans) << endl;
	}
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



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



int main() {

//変数の宣言

	int a,b,sum,i=0;



/////メイン処理/////


	while(cin>>a>>b){ 
//入力
		sum = a + b;
//桁数の計算
	
		while(1){
			if (pow(10,i)<=sum && pow(10,i+1) > sum){
				cout << i+1 <<endl;
				break;
			}
			i++;
		}
		
		i = 0;
	}
	
	
	return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+2;
bool mark[N],flag[N];

int main()
{
    int n,i,j,a,ans=0;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a);
        if(mark[a])flag[a]=true;
        mark[a]=true;
    }
    for(i=1; i<N; i++)
    {
        if(mark[i])
        {
            for(j=i+i; j<N; j+=i)mark[j]=false;
            ans+=(flag[i]^1);
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 5788
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int H, W, i, j;
    
    while(true) {
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
        }
        
        for(i = 0; i < H; i++) {
            for(j = 0; j < W; j++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    
    return 0;
    
}


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

int main() {
  int K, N;
  cin >> K;
  cin >> N;
  vector<int> distanceFromNorth(N);
  vector<int> distanceBetweenHouses(N);
  
  for (int i=0; i<N; i++) {
    cin >> distanceFromNorth.at(i);
  }
  
  for (int i=0; i<N; i++) {
    if (i == 0) {
      distanceBetweenHouses.at(i) = distanceFromNorth.at(i) - distanceFromNorth.at(N - 1) + K;
    } else {
      distanceBetweenHouses.at(i) = distanceFromNorth.at(i) - distanceFromNorth.at(i - 1);
    }
  }
  
  sort(distanceBetweenHouses.begin(), distanceBetweenHouses.end());
  cout << K - distanceBetweenHouses.at(N - 1) << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    int suma=0;
    int sumb=0;
    rep(i,n){
      int a,b;
      cin>>a>>b;
      if(a<b)
        sumb+=a+b;
      else if(a>b)
        suma+=a+b;
      else{
        suma+=a;
        sumb+=b;
      }
    }
    cout<<suma<<" "<<sumb<<endl;
  }
}

Measured memory_bytes: 3028
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
template<class T>inline bool chmax(T& a, T b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T& a, T b){if(a > b){a = b; return 1;}return 0;}
const ll INF = 1LL<<60;
//const int dy[4] = {0, 1, 0, -1};
//const int dx[4] = {1, 0, -1, 0};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};

void solve(){
    ll n; cin >> n;
    string s = to_string(n);
    ll res = 0;
    if(n%2 == 0){
        ll dev = 5*2;
        while(n >= dev){
            res += n/dev;
            dev *= 5;
        }
        cout << res << endl;
    }
    else cout << 0 << endl;
}

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

Measured memory_bytes: 3708
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	int n=s.size();
	cout<<s.substr(0,n-8)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
int main() {
 int ramen = 700;
	int count = 0;

	char a[3] = {};
	std::cin >> a[0] >> a[1] >> a[2];
	if (a[0] == 'o') {
		count++;
	}
	if (a[1] == 'o') {
		count++;
	}
	if (a[2] == 'o') {
		count++;
	}
	std::cout << ramen + (100 * count) << std::endl;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,d;
  cin >> n >> d;
  vvi x(n, vi(d));
  rep(i, n){
    rep(j, d) cin >> x[i][j];
  }
  int ans = 0;
  rep(i, n - 1){
    for(int j = i + 1; j < n; j++){
      int num = 0;
      rep(k, d) num += pow(x[i][k] - x[j][k], 2);
      double val = sqrt(num);
      if(val - (int)val == 0) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
x = 0
for i in range(n):
    x += b[a[i]-1]
    if i!=0 and a[i-1]==a[i]-1:
        x += c[a[i]-2]
print(x)

Measured memory_bytes: 3060
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
  string s;
  cin>>s;
  if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes"<<"\n";
  else cout<<"No"<<"\n";
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
string s;
int side1,side2,dia;
int rect=0,hisi=0;
while (scanf("%d,%d,%d", &side1, &side2, &dia)!=EOF){
	if (side1*side1+side2*side2==dia*dia)
	rect++;
	if (side1==side2)
	hisi++;
	}
	cout<<rect<<endl;
	cout << hisi << endl;
	return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  int a,b,c;
  cin>>a>>b>>c;
  set<int> s;
  s.insert(a);
  s.insert(b);
  s.insert(c);
  out(s.size());
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let h: usize = read();
    let w: usize = read();
    let mut field = vec![vec!['\0'; w]; h];
    let mut black_cnt = 0;
    for y in 0..h {
        let s: String = read();
        field[y] = s.chars().collect::<Vec<char>>();
        for x in 0..w {
            if field[y][x] == '#' { black_cnt += 1; }
        }
    }
    let mut dists = vec![vec![h * w; w]; h];
    let mut visits = vec![vec![false; w]; h];
    let mut que = VecDeque::<(usize, usize)>::new();
    que.push_back((0, 0));
    dists[0][0] = 0;
    while !que.is_empty() {
        let y = que.front().unwrap().0;
        let x = que.front().unwrap().1;
        que.pop_front();
        if visits[y][x] { continue; }
        visits[y][x] = true;
        let dx = vec![1, 0, -1, 0];
        let dy = vec![0, 1, 0, -1];
        for i in 0..4 {
            let ny: i32 = y as i32 + dy[i];
            let nx: i32 = x as i32 + dx[i];
            let nd = dists[y][x] + 1;
            if nx < 0 || nx >= w as i32 || ny < 0 || ny >= h as i32 { continue; }
            let ny = ny as usize;
            let nx = nx as usize;
            if field[ny][nx] == '#' || visits[ny][nx] || dists[ny][nx] <= nd { continue; }
            dists[ny][nx] = nd;
            que.push_back((ny, nx));
        }
    }
    if dists[h - 1][w - 1] == h * w {
        println!("-1");
    } else {
        println!("{}", h * w - black_cnt - dists[h - 1][w - 1] - 1);
    }
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int ans = s.size();
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != s[i - 1]) {
      ans = min(ans, max(i, (int)s.size() - i));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

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

    long long ans = 0;
    for (int d = 1; d < n; d++) {
        long long cur = 0;
        for (int a = n - 1; a > d; a -= d) {
            cur += s[a] + s[n-1-a];
            if (!((n - 1) % d == 0 && (n - 1 - a) / d * 2 * d >= n - 1)) {
                ans = max(ans, cur);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void){
int a,b,c,x;
scanf("%d %d %d",&a,&b,&c);
if(a>b){
x=a;
a=b;
b=x;
}
if(b>c){
x=b;
b=c;
c=x;
}
if(a>b){ 
x=a;
a=b;
b=x;
}
printf("%d %d %d\n",a,b,c);
return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long co[1000100] = { 0 };
long long a[100010];
int main() {
	long long n;
	cin >> n;
	for (long long i = 0; i < n; i++) {
		cin >> a[i];
		long long a1 = a[i];
		for (long long j = 2; j * j <= a[i]; j++) {
			if (a[i] % j == 0){
				long long co1 = 0;
				while (a[i] % j == 0) {
					a[i] /= j;
					co1++;
				}
				if (co[j] < co1) {
					co[j] = co1;
				}
			}
		}
		if (a[i] != 1 && co[a[i]] < 1) {
			co[a[i]] = 1;
		}
		a[i] = a1;
	}
	long long ans = 1;
	for (long long i = 2; i < 1000100; i++) {
		for (long long j = 0; j < co[i]; j++) {
			ans = ans * i % 1000000007;
		}
	}
	long long ans2 = 0;
	for (int i = 0; i < n; i++) {
		long long x = 1000000005;
		long long ans1 = 1;
		while (x > 0) {
			if ((x & 1) == 1) {
				ans1 = ans1 * a[i] % 1000000007;
			}
			a[i] = a[i] * a[i] % 1000000007;
			x >>= 1;
		}
		ans2 = (ans2 + (ans * ans1 % 1000000007)) % 1000000007;
	}
	cout << ans2 % 1000000007 << endl;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod=MOD){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)3e2+11;
ll const LG=(ll)log2(N)+1;


void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        cin>>n;
        vll a(n);
        for(i=0;i<n;i++){
                cin>>a[i];
        }
        
        ll ans=0;
        for(i=1;i<n-1;i++){
                vll v={a[i-1],a[i],a[i+1]};
                sort(all(v));
                if(v[1]==a[i])ans++;
        }
        cout<<ans<<endl;
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}

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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

const int N = 100005;
int n , ara[N], pos[N];
int main()
{
    cin >> n;
    for(int i = 1;i <= n;i++)cin >> ara[i] , pos[ara[i]] = i;

    set<int>st;
    st.insert(0);
    st.insert(n + 1);
    LL ans = 0;
    for(int i = n;i >= 1;i--){
        auto rt = st.lower_bound(pos[i]);
        auto lt = rt;lt--;
        if(rt != --st.end()){
            int r1 = *rt;
            int r2 = *(++rt);
            LL R = abs(r2 - r1) ;
            LL L = abs(pos[i] - *lt) ;
            ans = ans + (L * R * i);
            --rt;
        }
        if(lt != st.begin()){
            int l2 = *lt;
            int l1 = *(--lt);
            LL L = abs(l1 - l2) ;
            LL R = abs(pos[i] - *rt);
            ans = ans + (L * R * i);
        }
        st.insert(pos[i]);
    }
    cout << ans << "\n";

}




Measured memory_bytes: 5760
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


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

	double h1[100001],h2[100001], ans = 0, ans_num = INF, t, a;
	cin >> t >> a;
	for (int i = 0; i < n; i++) {
		cin >> h1[i];
		h2[i] = t - (h1[i] * 0.006);

			if (abs(a - h2[i]) < ans_num) { ans_num = abs(a - h2[i]); ans = i + 1; }
		
	
	}
	cout << ans << endl;

	return 0;
}

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

ll MOD = 1000000000 + 7;
vector<vi> to;
vector<vll> ans;

void dfs(int n, int p){
  for (int i: to[n]){
    if (i != p){
      dfs(i, n);
      ans[n][0] *= ans[i][0] + ans[i][1];
      ans[n][1] *= ans[i][0];
      ans[n][0] %= MOD;
      ans[n][1] %= MOD;
    }
  }
}

int main(){
  int N; cin >> N;
  to.resize(N);
  ans.resize(N);
  rep(i,N){
    ans[i].resize(2);
    ans[i][0] = 1;
    ans[i][1] = 1;
  }

  rep(i,N-1){
    int x, y; cin >> x >> y;
    to[x-1].push_back(y-1);
    to[y-1].push_back(x-1);
  }

  dfs(0, -1);

  cout << (ans[0][0] + ans[0][1]) % MOD << endl;

  return 0;
}

Measured memory_bytes: 16768
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct _stddev_st
{
    double value;
    struct _stddev_st *next;
} stddev_st;

int main(int argc, char *argv[])
{
    stddev_st *head = NULL, *tail = NULL;
    for (int n; scanf("%d", &n) && n;)
    {
        int scores[1000];
        int sum = 0;
        for (int *elm = scores, *const end = elm + n; elm != end; ++elm)
        {
            scanf("%d", elm);
            sum += *elm;
        }
        const double average = (double)sum / n;
        double sqdiffsum = 0.0;
        for (int *elm = scores, *const end = elm + n; elm != end; ++elm)
        {
            sqdiffsum += pow(*elm - average, 2);
        }
        stddev_st *node = (stddev_st *)malloc(sizeof(stddev_st));
        *node = (stddev_st){.value = sqrt(sqdiffsum / n), .next = NULL};
        head = head ?: node;
        if (tail)
        {
            tail->next = node;
        }
        tail = node;
    }
    while (head)
    {
        stddev_st *node = head;
        head = head->next;
        printf("%.8lf\n", node->value);
        free(node);
    }
    tail = NULL;
    return 0;
}



Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int n,t;
int ans = 0;


int main(){
  cin >> n >> t;
  P a[n];
  rep(i,n){ cin >> a[i].F >> a[i].S;}
  sort(a,a+n);
  
  int dp[n+1][6020];
  rep(i,6020){dp[0][i]=0;}
    
  rep(i,n){ rep(j, 6020){
      if(j>=a[i].F && j-a[i].F<t){
        dp[i+1][j] = max(dp[i][j], dp[i][j-a[i].F]+a[i].S);
      } else {
        dp[i+1][j] = dp[i][j];
      }
  
    ans = max(ans,dp[i+1][j]);
  } }
  
  cout << ans << endl; 
  return 0;
}

Measured memory_bytes: 70784
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, k = rm()
li = sorted(rl(), reverse=True)
print(sum(li[:k]))











Measured memory_bytes: 27124
#include<bits/stdc++.h>
using namespace std;
int main(){
    string st;
    cin>>st;
    int a=-1,z=-1;
    for(int i=0;i<st.length();i++){
        if(st[i]=='A'&&a==-1){
            a=i;
        }
        if(st[i]=='Z'){
            z=i;
        }
    }
    cout<<z-a+1<<endl;
    return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;

ll dist[2005];

int main() {
  ll N, X, Y;
  scanf("%lld %lld %lld", &N, &X, &Y);

  map<ll, ll> counts;

  for (ll i = 1; i <= N - 1; i++) {
    for (ll j = i + 1; j <= N; j++) {
      ll normal_dist = (j - i);
      ll special_dist1 = abs(X - j) + abs(Y - i) + 1;
      ll special_dist2 = abs(Y - j) + abs(X - i) + 1;

      ll dist = min(normal_dist, special_dist1);
      dist = min(dist, special_dist2);

      // cout << i << "," << j << endl;
      // cout << "normal_dist:" << normal_dist << endl;
      // cout << "special_dist1:" << special_dist1 << endl;
      // cout << "special_dist2:" << special_dist2 << endl;
      // cout << dist << endl;
      // cout << "" << endl;

      counts[dist] += 1;
    }
  }

  for (ll i = 1; i <= N - 1; i++) {
    cout << counts[i] << endl;
  }
}


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

int main() {
  int N, K, d=0;
  cin >> N  >> K;
  for (int i=0; i<N; i++) {
    int x;
    cin >> x;
    if (x >= K-x) {
      d += 2*(K-x);
    }
    else {
      d += 2*x;
    }    
  }
  cout << d << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include <cmath>
using namespace std;
int main()
{
	int a,b,c,d,x[3];
	cin>>a>>b>>c>>d;

	x[0]=abs(a-b);
		x[1]=abs(b-c);
	x[3]=abs(c-a);
	if(x[0]<=d&&x[1]<=d||x[3]<=d)
		printf("Yes");
			   else
	printf("No");
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, D;
    cin >> N >> D;
    int max = 1 + 2 * D;
    int r = N % max;
    if(r != 0) {
        cout << N / max + 1 << endl;
    }else {
        cout << N / max << endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}


int memo[100100];
bool done[100100];
vector<int> g[100100];

int solve(int i){
	int j;
	if(done[i]){
		return memo[i];
	}
	done[i] = true;
	memo[i] = 0;
	for(j=(g[i].l_ength()-1); j>=0; --j){
		memo[i] = max(memo[i],solve(g[i][j])+1);
	}
	return memo[i];
}

int main(void){
	int n,m,x,y,i,ans=0ll;
	fill(done,done+100100,false);
	cin >> n >> m;
	for(i=0; i<m; ++i){
		cin >> x >> y;
		--x; --y;
		g[x].push_back(y);
	}
	for(i=0; i<n; ++i){
		ans = max(ans,solve(i));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8192
N=int(input())
H=tuple(map(int,input().split()))
A=tuple(map(int,input().split()))
class SegTreeMax:
    def __init__(self,N):
        self.N0=2**(N-1).bit_length()
        self.INF=2**63-1
        self.data=[-self.INF]*(2*self.N0)
        self.d=[0]*N
    def update(self,i,x):
        self.d[i]=x
        i+=self.N0-1
        self.data[i]=x
        while i>0:
            i=(i-1)//2
            self.data[i]=max(self.data[i*2+1],self.data[i*2+2])
    def max(self,l,r):
        L = self.N0 + l; R = self.N0 + r
        s = -self.INF
        while L < R:
            if R & 1:
                R -= 1
                s = max(s, self.data[R-1])
            if L & 1:
                s = max(s, self.data[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s
s=SegTreeMax(N+1)
s.update(0,0)
for i,h in enumerate(H):
    m=s.max(0,h)
    s.update(h,m+A[i])
print(s.max(0,N+1))

Measured memory_bytes: 128720
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
	for(i = 0; i < VMAX; i++){
		C[i] = 0;
	}
	for(i=0;i < n;i++){
		scanf("%hd",&A[i+1]);
		C[A[i + 1]]++;
	}
	for(i = 1 ; i < VMAX;i++){
		C[i] = C[i] + C[i-1];
	}
	for(j = n; j >=1; j--){
		 B[C[A[j]]] = A[j];
		 C[A[j]]--;
	}
	for(i=1;i < n;i++){
		printf("%d ",B[i]);
	} printf("%d\n",B[n]);
  return 0;
}


Measured memory_bytes: 9712
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define nl '\n'

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int , int> pi;

void solve()
{
	
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	set<string> a;
	for(int i=0; i<n; i++)
	{
		string t;
		cin>>t;
		a.insert(t);
	}
	cout<<a.size()<<nl;
	return 0;
}


Measured memory_bytes: 19196
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		String Sdash = sc.nextLine();
		String T = sc.nextLine();

		String ans = "zzzzzzz";
		for(int i=0;i<=Sdash.length() - T.length();i++) {
			String temp = Sdash;
			int k = i;
			boolean flag = true;
			for(int j=0;j<T.length();j++) {
				if(Sdash.charAt(k) != '?' && T.charAt(j) != Sdash.charAt(k)) {
					flag = false;
					break;
				}else{
					temp = temp.substring(0,k) + T.substring(j, j+1) + temp.substring(k+1, Sdash.length());
					k++;
				}
			}

			if(flag) {
				for(int j=0;j<Sdash.length();j++) {
					if(temp.charAt(j) == '?') {
						temp = temp.substring(0,j) + "a" + temp.substring(j+1,Sdash.length());
					}
				}

				if(ans.compareTo(temp) >= 0) {
					ans = temp;
				}
			}
		}

		if(ans.equals("zzzzzzz")) {
			System.out.println("UNRESTORABLE");
		}else {
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 23892
n = gets.chomp.to_i
ar = gets.chomp.split.map(&:to_i)

ans = ar.inject do |result, val|
  if val.zero?
    puts 0
    exit
  end

  result = -1 if result > 10**18

  if result != -1
    result * val
  else
    -1
  end
end
if ans > 10**18 || ans == -1
  puts -1
else
  puts ans
end


Measured memory_bytes: 23656
//Knapsack 0-1 standard problem

#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define ll long long
  #define int long long 
  #define double long double
  #define max(a,b) (a>b?a:b)
  #define min(a,b) (a<b?a:b)
  #define mkp make_pair
  #define pb push_back
  #define inf INT_MAX

 const int N =  200005;
 
    int dp[N];
    int wt[105];
    int val[105];
  int32_t main()
  {
  	  IOS
      int n,W;
      cin>>n>>W;
      //int dp[n+1],wt[n+1],val[n+1];
      dp[0]=0;
      wt[0]=0;
      val[0]=0;
      for(int i=1;i<=n;i++)
      {
          cin>>wt[i]>>val[i];
      }
      //for(int i=1;i<=n;i++)
      //{ cout<<wt[i]<<"   "<<val[i]<<endl;}
      for(int i=1;i<=n;i++)
      {
          for(int j=W;j>=0;j--)
          {
              if(j+wt[i]<=W)
              dp[j+wt[i]]=max(dp[j+wt[i]],dp[j]+val[i]);
          }
      }
      cout<<dp[W]<<endl;
      //for(int i=0;i<=W;i++)
     //cout<<dp[i]<<" ";
      return 0;
  }

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

int main() {
    char c;
    std::cin >> c;
    if(c=='a'){
        std::cout << "vowel" << std::endl;
    }
        else if(c=='e'){
            std::cout << "vowel" << std::endl;
        }
        else if(c=='i'){
            std::cout << "vowel" << std::endl;
        }
        else if(c=='o'){
            std::cout << "vowel" << std::endl;
        }
        else if(c=='u'){
            std::cout << "vowel" << std::endl;
        }
        else{
            std::cout << "consonant" << std::endl;
        }
    return 0;    
}


Measured memory_bytes: 256
from operator import itemgetter
n,m=map(int,input().split())
l=[]
for i in range(m):
  g=list(map(int,input().split()))
  l.append(g)
  l[i].append(i)
l.sort()
l[0][1]=1
for i in range(1,m):
  if l[i][0]==l[i-1][0]:
    l[i][1]=int(l[i-1][1])+1
  else:
    l[i][1]=1
newl=sorted(l,key=itemgetter(2))
for i in range(m):  
  print((6-len(str(newl[i][0])))*'0'+str(newl[i][0])+(6-len(str(newl[i][1])))*'0'+str(newl[i][1]))


Measured memory_bytes: 33220
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
using namespace std;

int main(){
    int n;
    cin >> n;
    int w[n+1];
    w[0] = 0;
    for(int i = 1; i <= n; i++){
        int w1;
        cin >> w1;
        w[i] = w[i-1] + w1;
    }
    
    int r = 1<<30;
    for(int i = 1; i < n; i++){
        int sub = abs(w[i]-(w[n]-w[i]));
        r = min(r, sub);
    }
    cout << r << endl;
    
    return 0;
}


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


typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#define pb push_back
#define popb pop_back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define forz(i,n) for( int i=0;i<n;i++)
#define forl(i, n) for(int i = 0; i<= n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
// #define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)

using namespace std;

void cpc()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w" , stdout);
#endif
}
lli power(lli x, lli y)
{
	lli res = 1;     // Initialize result
	// lli p = mod;
	x = x ; // Update x if it is more than or
	// equal to p

	if (x == 0) return 0; // In case x is divisible by p;

	while (y > 0)
	{
		// If y is odd, multiply x with result
		if (y & 1)
			res = (res * x);

		// y must be even now
		y = y >> 1; // y = y/2
		x = (x * x);
	}
	return res;
}

// lli mod(lli x)
// {
// 	if (x < 0)
// 		x = -x;
// 	return x;
// }



int main()
{
	// cpc();
	// kira;
	lli n;
	cin >> n;
	forz(i, 2000)
	{
		forz(j, i)
		{
			if (power(i, 5) + power(j, 5) == n)
			{
				cout << i << " " << -1 * j << endl;
				return 0;
			}
			else if (power(i, 5) - power(j, 5) == n)
			{
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 10;
const int maxm = 200 + 10;
int n;
bool flag[maxn];
int prime[maxn], cnt;
int a[maxm], vis[maxm], match[maxm], cur;
vector<int> odd, even, E[maxm];
void ins(int x)
{
	if(x & 1) odd.push_back(x);
	else even.push_back(x);
}
void sieve()
{
	flag[1] = 1;
	for(int i = 2; i < maxn; ++i)
	{
		if(!flag[i]) prime[++cnt] = i;
		for(int j = 1; j <= cnt && i * prime[j] < maxn; ++j)
		{
			flag[i * prime[j]] = 1;
			if(i % prime[j] == 0)
				break;
		}
	}
}
bool dfs(int now)
{
	for(auto v : E[now])
		if(vis[v] != cur)
		{
			vis[v] = cur;
			if(match[v] == -1 || dfs(match[v]))
			{
				match[v] = now;
				return true;
			}
		}
	return false;
}
void add(int u, int v)
{
	++u, ++v;
	v += odd.size();
	E[u].push_back(v);
}
int h()
{
	int ret = 0;
	memset(match, -1, sizeof match);
	for(int i = 1; i <= odd.size(); ++i)
	{
		cur = i;
		ret += dfs(i);
	}
	return ret;
}	
int main()
{
	sieve();
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	ins(a[1]);
	for(int i = 2; i <= n; ++i)
	{
		if(a[i] == a[i - 1] + 1)
			continue;
		ins(a[i - 1] + 1);
		ins(a[i]);
	}
	ins(a[n] + 1);
	for(int i = 0; i < odd.size(); ++i)
		for(int j = 0; j < even.size(); ++j)
			if(!flag[abs(odd[i] - even[j])])
				add(i, j);
	int ret = h();
	if((odd.size() - ret) & 1) --ret;
	int ans = odd.size() + even.size() - ret;
	printf("%d\n", ans);
	return 0;
}
	
	

Measured memory_bytes: 16236
#include <stdio.h>
int main(){
int a,b,c,d,x,y=0;
while(scanf ("%d\n",&x)!=EOF){
for (a=0;a<10;a++){
for (b=0;b<10;b++){
for (c=0;c<10;c++){
for (d=0;d<10;d++){
if (a+b+c+d==x){
y+=1;
}
}
}
}
}
printf ("%d\n",y);
y=0;
}
return 0;
}


Measured memory_bytes: 2028
while True:
    try:
        num = int(input())
        for i in range(num):
            lengths = (int(x) for x in input().split())
            sortLengths = sorted(lengths)
            
            if(sortLengths[2] * sortLengths[2] == (sortLengths[1] * sortLengths[1]) + (sortLengths[0] * sortLengths[0])):
                print("YES")
            else:
                print("NO")
    except EOFError:
        break


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


int main() {
  int X,Y;
  cin >> X >> Y;
  
  if(Y%2==1){
    cout << "No" <<endl;
  }
  else if(Y<2*X){
    cout << "No" <<endl;
  }
  else if(Y>4*X){
    cout << "No" <<endl;
  }
  else{
    cout << "Yes" <<endl;
  }
  
}


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

int main(){
	int S[32]={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
	int K;
	cin >> K;
	cout << S[K-1] << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
ll ans[200005];
vector<int> g[200005];
ll ad[200005];

void dfs(int v, int prev, ll d) {
  ans[v] = d;
  for(int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    if(u == prev) continue;
    dfs(u,v,d+ad[u]);
  }
}

  
int main() {
  int n,q;
  cin >> n >> q;
  for(int i = 0; i < n - 1; i++) {
    int a,b;
    cin >> a >> b;
    a--,b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  for(int i = 0; i < q; i++) {
    int p,x;
    cin >> p >> x;
    p--;
    ad[p] += x;
  }

  dfs(0,-1,ad[0]);

  for(int i = 0; i < n - 1; i++) {
    cout << ans[i] <<' ';
  }
  cout << ans[n-1] << endl;
}

  


Measured memory_bytes: 28672
using System;
using System.Linq;

namespace hitochi2020_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] read = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            int A = read[0];
            int B = read[1];
            int M = read[2];
            int[] a = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            int[] b = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            int[] x = new int[M];
            int[] y = new int[M];
            int[] c = new int[M];
            int minCost = a.Min() + b.Min();
            for(int i = 0; i < M;i++){
                int[] tmp = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
                x[i] = tmp[0];
                y[i] = tmp[1];
                c[i] = tmp[2];
                minCost = Math.Min(minCost,a[x[i]-1]+b[y[i]-1]-c[i]);
            }
            Console.WriteLine(minCost);
        }
    }
}

Measured memory_bytes: 34524
import Control.Monad                                                                                                       
main :: IO ()                                                                                                              
main = do                                                                                                                  
  n <- read <$> getLine                                                                                                    
  lrs <- map (\x -> (,) (x!!0) (x!!1)) <$> replicateM n (map read . words <$> getLine) :: IO [(Int,Int)]                   
  print $ sum . map (\x -> snd x - fst x + 1) $ lrs

Measured memory_bytes: 1788
#include<iostream>
#include <algorithm>
#include <string>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
typedef long long ll;
const int INF = numeric_limits<int>::max();
const int MOD = (1e9 + 7);


int main(){
  int N, M, cnt=0;
  cin >> N >> M;
  int C[N];
  rep(i, N){
    cin >> C[i];
  }
  rep(i, N){
    if(C[i] >= M)
      cnt ++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR0(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define FOR(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define FORD(i,l,r) for(int i=(r), _##i=(l); --i>=_##i; )
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(), _##i=(a).end(); i!=_##i; ++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(), _##i=(a).rend(); i!=_##i; ++i)
#define printCase() "Case #" << caseNum << ": "
#define pb push_back
#define mp make_pair
#define INF (int)1e9
#define EPS 1e-9
#define SYNC std::ios::sync_with_stdio(false)
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
	SYNC;
	int n, m, cnt[55], a, b;
	cin >> n >> m;
	memset(cnt, 0, sizeof cnt);
	while(m--) {
		cin >> a >> b;
		cnt[a]++;
		if(a!=b) cnt[b]++;
	} 
	FOR0(i,n) cout << cnt[i+1] << endl;
}

Measured memory_bytes: 256
n=int(input())
weights=[int(i)  for  i  in  input().split()]
ans=10000000

for  i  in  range(1,n+1):
    weights1=sum(weights[0:i+1])
    weights2=sum(weights)-weights1
    dif=abs(weights1-weights2)
    if  dif<ans:
        ans=dif
    
print(ans)
        

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

int main()
{
  int N;
  cin >> N;
  vector<pair<ll, int>> A(N);
  rep(i, N)
  {
    ll a;
    cin >> a;
    A.at(i) = make_pair(a, i);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, 0));
  rep(i, N)
  {
    rep(l, i + 1)
    {
      dp.at(i + 1).at(l + 1) = max(dp.at(i + 1).at(l + 1), dp.at(i).at(l) + A.at(i).first * (A.at(i).second - l));
      dp.at(i + 1).at(l) = max(dp.at(i + 1).at(l), dp.at(i).at(l) + A.at(i).first * (N - i + l - 1 - A.at(i).second));
    }
  }
  ll ans = 0;
  rep(l, N + 1)
  {
    ans = max(ans, dp.at(N).at(l));
  }
  cout << ans << endl;
}

Measured memory_bytes: 34688