akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);

ll const mod = 1e9 + 7;

ll add(ll x, ll y)
{
	return (x + y) % mod;
}

ll sub(ll x, ll y)
{
	return (x - y + mod) % mod;
}

ll mul(ll x, ll y)
{
	return (x * y) % mod;
}

int const N = 2e5 + 7;
ll ar[N];
ll pfx[N] = {};

ll range(ll a, ll b)
{
	return sub(pfx[b], pfx[a-1]);
}

int main()
{
	fastio;

	int n;
	cin >> n;

	for (int i = 1; i <= n; ++i)
		cin >> ar[i], pfx[i] = add(ar[i], pfx[i-1]);

	ll res = 0;
	for (int i = 1; i < n; ++i)
	{
		res = add(res, mul(ar[i], range(i+1, n)));
	}
	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 6732
/**
        Bismilla- hir rahma-nir rahi-m
    @uthor Md Hasibur Rahman (Evan)
                JKKNIU
*/


#include<bits/stdc++.h>
#define         ll              long long
#define         FI              freopen("input.txt","r",stdin)
#define         FO              freopen("output.txt","w",stdout)
#define         PrintCase(i)    printf("Case %d: ",i)
#define         sc(a)           scanf("%d",&a)
#define         scl(a)          scanf("%lld",&a)
#define         rep(i,n)        for(int i=0;i<n;i++)
#define         pb              push_back
#define         MAX             1000000
#define         fast            ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define         endl            "\n"


using namespace std;

bool isPrime(ll a)
{
    for(ll i=2;i*i<=a;i++)
        if(a%i==0)
            return false;
    return true;
}






bool isPowerOfTwo(ll a)
{
    if(a==1)
        return true;
    if(a&1)
        return false;
    while(a)
    {
        a/=2;
        if(a!=1 && a&1)
            return false;
        if(a==1)
            return true;
    }
    return true;
}



void Swap(ll &a, ll &b)
{

    a^=b;
    b^=a;
    a^=b;
}



ll gcd(ll a, ll b)
{
    if(a<0 || b<0)
    {
        a = abs(a);
        b = abs(b);
    }
    if(a<b)
        Swap(a,b);
    if(b==0)
        return a;
    if(a%b==0)
        return b;
    else
        return gcd(b,a%b);
}



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



ll power(ll base, ll exponent)
{
    ll ans = 1;
    for(ll i=1;i<=exponent;i++)
        ans*=base;
    return ans;
}




bool isPowerOfX(ll x, ll value)
{
    if(value==1)
        return true;
    while(value)
    {
        value/=x;
        if(value%x && value!=1)
            return false;
    }
    return true;
}


vector<ll>graph[333333];
bool Visit[333333];

void bfs(ll src)
{
    queue<ll>q;
    q.push(src);
    while(!q.empty())
    {
        ll tmp = q.front();
        q.pop();
        Visit[tmp] = true;
        for(int i=0;i<graph[tmp].size();i++)
        {
            ll tmp2 = graph[tmp][i];
            if(!Visit[tmp2])
                q.push(tmp2);
        }
    }
}



int main()
{
    ll n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        graph[x].pb(y);
        graph[y].pb(x);
    }
    ll cnt = -1;
    for(ll i=1;i<=n;i++)
    {
        if(!Visit[i])
        {
            bfs(i);
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}




Measured memory_bytes: 15304
S=gets.chomp.split("")
if (S[0]==S[1])&&S[0]==S[2]&&S[0]==S[3]
  puts "No"
elsif (S[0]==S[1]&&S[2]==S[3])||(S[0]==S[2]&&S[1]==S[3])||(S[0]==S[3]&&S[1]==S[2])
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int>P;
const int N=1e3+5,o[8]={6,7,4,5,2,3,0,1};
set<P>s[8],ss[8][8];
int n,i,j,k,l,x,y,c,tot,fl1[2][N][4],fl2[2][N];
ll f[8][8],w[2][N][4],ww[2][N][4][4],ans,d[8],mmx;
inline void calcf(){
	for(j=0;j<8;++j)for(k=0;k<8;++k)
		f[j][k]=j!=k && !ss[j][k].empty()?ss[j][k].rbegin()->first:-(1ll<<60);
}
vector<int>v1,v2;
int q[999],pre[8],t,www,u,ff[8];
bool inq[8];
inline void relax(int u,int v,ll ww){if(ww>d[v]){d[v]=ww;pre[v]=u;if(!inq[v])inq[v]=1,q[++www]=v;}}
inline void spfa(int S){
	if(s[S].empty())return;
	q[t=0,www=1]=S;memset(d,250,64);memset(inq,0,8);d[S]=0;
	for(;t<www;){
		u=q[++t];inq[u]=0;
		relax(u,o[u],d[u]);x=u>>2<<2;y=u&3;
		for(j=0;j<4;++j)if(j!=y)relax(u,x+j,(x?f[x+j][u]:f[u][x+j])+d[u]);
	}
	int mxid;ll mx=-(1ll<<60);
	for(j=4;j<8;++j)if(!s[j].empty() && s[j].rbegin()->first+s[S].rbegin()->first+d[j]>mx)
		mx=s[j].rbegin()->first+s[S].rbegin()->first+d[j],mxid=j;
	if(mx>mmx){
		mmx=mx;
		v2.clear();for(j=mxid;j!=S;j=pre[j])v2.push_back(j);v2.push_back(S);v1=v2;
	}
}
inline void del(int x){
	int o=x>>2,y=s[x].rbegin()->second;
	if(!--fl2[o][y])for(i=0;i<4;++i)s[o<<2|i].erase(P(w[o][y][i],y));
	if(1==++fl1[o][y][x&3])for(j=0;j<4;++j)
		if(j!=(x&3))ss[x][o<<2|j].insert(P(ww[o][y][x&3][j],y));
}
inline void mdy(int o,int x,int y){
	if(o)swap(x,y);
	int z=ss[x][y].rbegin()->second;
	if(0==--fl1[o][z][x&3])for(j=0;j<4;++j)if(j!=(x&3))ss[x][o<<2|j].erase(P(ww[o][z][x&3][j],z));
	if(1==++fl1[o][z][y&3])for(j=0;j<4;++j)if(j!=(y&3))ss[y][o<<2|j].insert(P(ww[o][z][y&3][j],z));
}
int main(){
	scanf("%d",&n);
	for(j=0;j<2;++j)for(i=1;i<=n;++i){
		scanf("%d%d%d",&x,&y,&c);tot+=c*j;
		w[j][i][0]=x+y;w[j][i][1]=-x+y;w[j][i][2]=-x-y;w[j][i][3]=x-y;
		s[0+j*4].insert(P(w[j][i][0],i));s[1+j*4].insert(P(w[j][i][1],i));
		s[2+j*4].insert(P(w[j][i][2],i));s[3+j*4].insert(P(w[j][i][3],i));
		for(k=0;k<4;++k)for(l=0;l<4;++l)ww[j][i][k][l]=w[j][i][l]-w[j][i][k];
		fl2[j][i]=c;
	}
	for(;tot--;){
		mmx=-(1ll<<60);calcf();
		for(i=0;i<4;++i)spfa(i);
		ans+=mmx;reverse(v2.begin(),v2.end());
		del(v2[0]);del(v2.back());
		for(i=0;i+1<v2.size();++i)if((v2[i]&4)==(v2[i+1]&4))mdy(v2[i]>>2,v2[i],v2[i+1]);
			else ff[max(v2[i],v2[i+1])&3]+=v2[i]<v2[i+1]?1:-1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1152
import sys
import math

N = int(input())
if N % 2 == 1:
    print(0)
    sys.exit()

count_2 = 0
count_5 = 0
deno = 2
while deno <= N:
    count_2 += N // deno
    deno *= 2

deno = 10
while deno <= N:
    count_5 += N // deno
    deno *= 5

print(min(count_2, count_5))


Measured memory_bytes: 62136
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int A, B;
  cin >> A >> B;

  map<int,int> m;
  m[1] = 1;
  m[2] = 1;
  m[3] = 1;
  m[A]--;
  m[B]--;

  FOR(it,m){
    if(it->second == 1) cout << it->first << endl;
  }

  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 1000005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    
    if(a==b&&a==c&&a%2==0)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    int ans=0;
    while(a%2==0&&b%2==0&&c%2==0)
    {

        int p=b/2+c/2;
        int d=a/2+c/2;
        int l=a/2+b/2;
        a=p;b=d;c=l;
        ans++;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cctype>
#include <cmath>
using namespace std;

int main() {
    string number;
    cin >> number;
    long total = 0;
    char cToStr[2];
    cToStr[1] = '\0';
    for (int i = 0; i < number.length(); i++) {
        cToStr[0] = number[i];
        total += atoi(cToStr);
    }
    if (total % 9 == 0) {
        cout << "Yes";
    } else {
        cout << "No";
    }
	return 0;
}



Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

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

#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;
const int MOD = 1000000007;


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

    string s, head="", tail="";
    int q;

    cin >> s >> q;

    bool straight = true;
    int cnt = 0;

    rep(i,q){
        int t; cin >> t;

        if(t==1){
            straight = !straight;
            cnt++;
        }else{
            int f; cin >> f;
            string c; cin >> c;

            if((f==1 && cnt%2==0) ||(f==2 && cnt%2==1)){
                head += c;
            } else{
                tail += c;
            }
        }
    }

    if(cnt%2==0){
        reverse(head.begin(), head.end());
        cout << head << s << tail << endl;
    } else {
        reverse(tail.begin(), tail.end());
        reverse(s.begin(), s.end());
        cout << tail << s << head << endl;
    }

    return 0;
}

Measured memory_bytes: 1040
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;

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

	vector<int> a(n), b(n);
	long long ans_a = 0, ans_b = 0;
	vector<bool> fa(n, true), fb(n, true);
	int count = 0;
	int tmp = 1;
	for (int i = 0; i < n; i++) {
		cin >> a[i];

		count = 0;
		tmp = 1;
		for (int j = 1; j <= n; j++) {
			if (j == a[i]) {
				fa[j - 1] = false;
				
				for (int k = 2; k <= n - 1 - i; k++) {
					tmp *= k;
				}
				ans_a += tmp * count;
				break;
			}
			else if (fa[j - 1]) {
				count++;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];

		count = 0;
		tmp = 1;
		for (int j = 1; j <= n; j++) {
			if (j == b[i]) {
				fb[j - 1] = false;

				for (int k = 2; k <= n - 1 - i; k++) {
					tmp *= k;
				}
				ans_b += tmp * count;
				break;
			}
			else if (fb[j - 1]) {
				count++;
			}
		}
	}

	cout << labs(ans_a - ans_b) << endl;

	return 0;
}

Measured memory_bytes: 256
M=998244353
class Factorial:
    def __init__(self,n):
        self.f=f=[0]*(n+1)
        f[0]=b=1
        for i in range(1,n+1):f[i]=b=b*i%M
        self.inv=inv=[0]*(n+1)
        inv[n]=b=pow(self.f[n],M-2,M)
        for i in range(n,0,-1):inv[i-1]=b=b*i%M
    def factorial(self,i):
        return self.f[i]
    def ifactorial(self,i):
        return self.inv[i]
    def comb(self,n,k):
        if n>=k:return self.f[n]*self.inv[n-k]*self.inv[k]%M
        else:return 0
comb=Factorial(10**5*5).comb
n,m,k=map(int,input().split())
print(sum(m*comb(n-1,i)*pow(m-1,~i+n,M)for i in range(k+1))%M)

Measured memory_bytes: 79344
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>

int n, m, l;

std::vector<std::pair<int, int> > edges[300];
int D[300][300];


int dist[300];
void dfs(int root, int x, int d){
  if(d >= dist[x]) return;
  dist[x] = d;
  if(x != root) D[root][x] = D[x][root] = 1;
  for(auto b: edges[x]){
    dfs(root, b.first, b.second + d);
  }
}

int main(){
  scanf("%d%d%d",&n,&m,&l);
  for(int i = 0; i < 300; i++){
    for(int j = 0; j < 300; j++){
      D[i][j] = l+1;
    }
  }
  for(int i = 0; i < m; i++){
    int a, b, c;
    scanf("%d%d%d",&a,&b,&c);
    if(c > l) continue;
    edges[a-1].push_back(std::pair<int, int>(b-1, c));
    edges[b-1].push_back(std::pair<int, int>(a-1, c));
    D[a-1][b-1] = c;
    D[b-1][a-1] = c;
  }

/*
  for(int i=0;i<n;i++){
    for(int j = 0; j < 300; j++) dist[j] = l+1;
    dfs(i, i, 0);
  }
*/
  for(int i=0;i<n;i++) D[i][i] = 0;

  for(int k = 0; k < n; k++){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if(D[i][j] > D[i][k] + D[k][j]) D[i][j] = D[i][k] + D[k][j];
        if(D[i][j] > l) D[i][j] = l+1;
      }
    }
  }

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      D[i][j] = D[i][j] <= l;
    }
  }

/*
puts("");
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
printf("%d ", D[i][j]);
      }
puts("");
    }
puts("");
*/

  for(int k = 0; k < n; k++){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if(D[i][k] && D[k][j] && (!D[i][j] || D[i][j] > D[i][k] + D[k][j])) D[i][j] = D[i][k] + D[k][j];
      }
    }
  }
/*
puts("");
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
printf("%d ", D[i][j]);
      }
puts("");
    }
puts("");
*/

  int q;
  scanf("%d",&q);
  for(int i = 0; i < q; i++){
    int s, t;
    scanf("%d%d",&s,&t);
    printf("%d\n", D[s-1][t-1] - 1);
  }

  return 0;
}


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


int main() {
    const int MAX_N = 1e5;
    int N, h[MAX_N], dp[MAX_N];
	cin >> N;
    for (int i = 0; i < N; ++i){
        cin >> h[i];
    }

    dp[0] = 0, dp[1] = abs(h[1]-h[0]);
    for (int i = 2; i < N; ++i){
        dp[i] = min( 
            dp[i-2] + abs(h[i]-h[i-2]),
            dp[i-1] + abs(h[i]-h[i-1])
        );
    }

    cout << dp[N-1] << endl;

}

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

using namespace std;

int H, pzl[10][5];

int delStone()
{
  int ret = 0;
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < 5 - 2; j++){
      int *a = &pzl[i][j], *b = &pzl[i][j+1], *c = &pzl[i][j+2];
      if(abs(*a) == abs(*b) && abs(*a) == abs(*c)){
	*a = *b = *c = -abs(*a);
      }
    }
  }/*
    cout << "-------------------" << endl;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < 5; j++) cout << pzl[i][j] << " ";
    cout << endl;
  }
   */
  for(int i = 0; i < H; i++){
    for(int j = 0; j < 5; j++){
      if(pzl[i][j] < 0){
	ret -= pzl[i][j];
	pzl[i][j] = 0;
      }
    }
  }/*
  cout << "-------------------" << endl;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < 5; j++) cout << pzl[i][j] << " ";
    cout << endl;
  }
   */
  for(int i = H-1; i > 0; i--){
    for(int j = 0; j < 5; j++){
      if(pzl[i][j] == 0){
	for(int k = i-1; k >= 0 && pzl[i][j] == 0; k--){
	  swap(pzl[i][j], pzl[k][j]);
	}
      }
    }
  }/*
  cout << "-------------------" << endl;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < 5; j++) cout << pzl[i][j] << " ";
    cout << endl;
  }
   */
  return ret;
}

int getScore()
{
  int ret = 0, rec = 0;
  while((rec = delStone()) > 0){
    ret += rec;
  }
  return ret;
}

int main()
{
  while(cin >> H, H){
    for(int i = 0; i < H; i++){
      for(int j = 0; j < 5; j++) cin >> pzl[i][j];
    }
    cout << getScore() << endl;
  }
  return 0;
}

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

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

n = int (raw_input ())
a = [int (i) for i in raw_input ().split ()]
x = [0] * (1 + len (a))
y = [0] * (1 + len (a))
for i in range (1, len (a) + 1): x [i] = x [i - 1] + a [i - 1]
a = a [::-1]
for i in range (1, len (a) + 1): y [i] = y [i - 1] + a [i - 1]
y = y [::-1]
ret = 10 ** 10
for i in range (1, len (x) - 1): ret = min (ret, abs (x [i] - y [i]))
print ret


Measured memory_bytes: 28660
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
const int mod = 998244353;
int n, m, fact[N], ifact[N], inv[N];
inline int C(int x, int y) {
	if (x < 0 || y < 0 || x < y) return 0;
	return 1ll * fact[x] * ifact[y] % mod * ifact[x - y] % mod;
}
int main() {
	scanf("%d%d", &n, &m);
	inv[1] = 1;
	for (int i = 2; i < N; i++) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
	fact[0] = ifact[0] = 1;
	for (int i = 1; i < N; i++) fact[i] = 1ll * fact[i - 1] * i % mod, ifact[i] = 1ll * ifact[i - 1] * inv[i] % mod;
	int ans = 0;
	for (int r = m; r >= n && r >= m - r; r--) {
		int f = (r == m - r);
		ans = (ans + (C(m - f, r) - C(m - f, 2 * r - n + 1) + mod) % mod) % mod;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 9692
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    double a, b, C;
    double area, length, height, opposite_side;
    cin >> a >> b >> C;
    C = C / 180 * M_PI;
    area = a * b * sin(C) / 2.0;
    opposite_side = sqrt(a * a + b * b - 2 * a * b * cos(C));
    length = a + b + opposite_side;
    height = area / a * 2.0;

    printf("%10.8f\n", area);
    printf("%10.8f\n", length);
    printf("%10.8f\n", height);

    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
using namespace std;

const int maxn = int(2e5)+5, maxc = 27, inf = int(1e9)+5;

int n, memo[maxn], memoi[maxn];
set<int> S[maxc];

int DP(int idx)
{
	if(idx >= n) return 0;
	if(memo[idx] != -1) return memo[idx];
	int res = inf, resi = -1;
	for(int i = 0;i < 26;i++)
	{
		int c = DP(*S[i].upper_bound(idx));
		if(res > c)
		{
			res = c, resi = i;
		}
	}
	memoi[idx] = resi;
	return memo[idx] = res+1;
}

int main(void)
{
	string A;
	cin >> A;
	n = int(A.size());
	for(int i = 0;i < n;i++) S[int(A[i]-'a')].insert(i), memo[i] = -1;
	for(int i = 0;i < 27;i++) S[i].insert(n+1);

	int res = inf, resi = -1;
	for(int i = 0;i < 26;i++)
	{
		int c = DP(*S[i].begin());
		if(res > c)
		{
			res = c, resi = i;
		}
	}
	int cur = *S[resi].begin();
	while(cur < n)
	{
		cout << char(resi+'a');
		resi = memoi[cur];
		cur = *S[resi].upper_bound(cur);
	}
	cout << char(resi+'a');
	cout << "\n";
}

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

using namespace std;

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

  if (n % 10 == 9 || n > 89) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int arr[101] = {0};

int main()
{
	long long int n, total=0;
	cin >> n;
	total += n/500*1000;
	n -= n/500*500;
	total += n/5*5;
	cout << total;
}



Measured memory_bytes: 3644
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

bool canGoal(bool[][] checked, ref char[][] c, int x, int y) {
    if(checked[x][y]) {
        return false;
    }
    checked[x][y] = true;
    if(x == 0 || y == 0 || x == c.length-1 || y == c[0].length-1) {
        return true;
    }

    auto dx = [1, 0, -1, 0];
    auto dy = [0, 1, 0, -1];
    foreach(i; iota(4)) {
        auto nx = x + dx[i];
        auto ny = y + dy[i];
        if(c[nx][ny] == '#') {
            continue;
        }
        if(canGoal(checked, c, nx, ny)) {
            return true;
        }
    }
    return false;
}

void goOver(ref char[][] c, int x, int y) {
    auto dx = [1, 0, -1, 0];
    auto dy = [0, 1, 0, -1];

    c[x][y] = 'g';

    void fill(int x, int y) {
        if(c[x][y] != '#') {
            return;
        }

        c[x][y] = 'g';

        foreach(i; iota(4)) {
            auto nx = x + dx[i];
            auto ny = y + dy[i];
            if(nx < 0 || ny < 0 || nx >= c.length || ny >= c[0].length) {
                continue;
            }
            fill(nx, ny);
        }
    }

    foreach(i; iota(4)) {
        auto nx = x + dx[i];
        auto ny = y + dy[i];
        if(nx < 0 || ny < 0 || nx >= c.length || ny >= c[0].length) {
            continue;
        }
        if(c[nx][ny] == '#') {
            fill(nx, ny);
        }
        if(c[nx][ny] == '.') {
            goOver(c, nx, ny);
        }
    }
}

void recover(ref char[][] c) {
    foreach(ref ci; c) {
        foreach(ref cii; ci) {
            if(cii == 'g') {
                cii = '.';
            }
        }
    }
}

void main(){
    while(true) {
        int n, m;
        readlnTo(n, m);
        if(n == 0) {
            return;
        }
        char[][] c;
        foreach(i; iota(m)) {
            c ~= readln().chomp().to!(char[]);
        }
        int sx, sy;
        foreach(i; iota(m)) {
            foreach(j; iota(n)) {
                if(c[i][j] == '&') {
                    sx = i;
                    sy = j;
                }
            }
        }
        int ans;
        while(!canGoal(new bool[][](m, n), c, sx, sy)){
            ++ans;
            goOver(c, sx, sy);
            recover(c);
        }
        writeln(ans);
    }
}

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

using namespace std ;
typedef long long ll;
typedef string str;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<ll,ll> pll ;
typedef vector<pii> vpii ;
typedef vector<pll> vpll ;

#define REP(i, n) for (ll (i) = 0; (i) < (ll)(n); i++) 
#define FOR(i, a, b) for(ll (i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define CHI 1000000000000000003
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define NP next_permutation
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}
//-----------------------------------------




















//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s ;
  cin >> s ;
  int ans = INF ;
  REP(i,26){
    str t ;
    char c = (char)('a'+i) ;
    t = c + s + c ;
    int n = SZ(t) ;
    int tmp = 0 ;
    int tmp2 = 0 ;
    REP(i,n){
      if(t[i]==c){
        tmp = max(tmp,tmp2) ;
        tmp2 = 0 ;
      }
      else{
        tmp2++ ;
      }
    }
    ans = min(ans,tmp) ;
  }
  
  cout << ans <<endl;
      
      
    
  
  
  
  return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N, A;
  cin >> N >> A;

  if (N % 500 <= A)
    cout << "Yes" << endl;
  else
    cout << "No" << 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(void)
{
  int A, B, H, M;
  cin >> A >> B >> H >> M;

  double longhand = M * 6.0;
  double hourhand = H * 30.0 + M * 0.5;

  double big = max(longhand, hourhand);
  double small = min(longhand, hourhand);

  double r = big - small;

  double answer = A * A + B * B - 2 * A * B * cos(M_PI * r / 180);

  answer = sqrt(answer);

  cout << fixed << setprecision(20);
  cout << answer << endl;

  return 0;
}

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

int main(){
  int n,l;
  string s[100];
  cin >> n >> l;
  for(int i=0;i<n;i++) cin >> s[i];
  sort(s, s+n);
  for(int i=0;i<n;i++) cout << s[i];
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

#define INF 1e9+7;

int main() {
    int N;
    long max_ = 0, min_ = INF;
    cin >> N;
    for (int i = 0; i < N; i++) {
        long a;
        cin >> a;
        max_ = max(max_, a);
        min_ = min(min_, a);
    }

    cout << max_ - min_ << endl;

    return 0;
}

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

int main() {
    int q; cin >> q;
    while (q--) {
        long long a, b; cin >> a >> b;
        auto check = [&](long long k) {
            return (k+1)/2 * (k+1 - (k+1)/2) < a * b;
        };
        auto binary_search = [&](long long ok, long long ng) {
            assert(check(ok) == true);
            assert(check(ng) == false);
            while (abs(ng - ok) > 1) {
                long long mid = (ng + ok) / 2;
                (check(mid) ? ok : ng) = mid;
            }
            return ok;
        };
        cout << binary_search(0, 2e9) - (a != b) << endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
    vector<string>a;
    for(int i = 0;i < 3;i++)
    {
        string x;cin>>x;
        a.push_back(x);
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    cout<<stoi(a[0]+a[1])+stoi(a[2]);
}


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

int main(){
	int n;
	cin >> n;
	int h[30];
	for(int i = 0; i < n; ++i) cin >> h[i];
	int maxv = 0;
	int cnt = 0;
	for(int i = 0; i < n; ++i){
		if(h[i] >= maxv){
			cnt++;
			maxv = h[i];
		}
	}
	cout << cnt << endl;
}


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

int main() {
    while(1){
        int a, b;
        char op;

        cin >> a >> op >> b;

        switch(op){
        case '+':
            cout << a + b << endl;
            break;
        case '-':
            cout << a - b << endl;
            break;
        case '*':
            cout << a * b << endl;
            break;
        case '/':
            cout << a / b << endl;
            break;
        case '?':
            return 0;
        }
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
// const ll MOD=998244353;

int main(){
  int N; cin>>N;
  int S=0;
  rep(i,N){
    int A; cin>>A;
    S^=A;
  }
  if(S==0) cout<<"Yes\n";
  else cout<<"No\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())
#define SORTDESC(c) sort((c).begin(), (c).end(), greater<short>());
#define DEBUG

using namespace std;
typedef vector<long> VI;
typedef vector<VI> VVI;
typedef pair<long,long> pr;
typedef map<double,pr> mp;
typedef vector<short> vs;

short c[3][3];
short a[3], b[3];

int main(void){
    REP(i,3){
        REP(j,3){
            cin >> c[i][j];
        }
    }

    REP(x, 100){
        a[0] = x;
        
        REP(i,3){
            b[i] = c[0][i]  - a[0];
        }
        REP(i,3){
            a[i] =  c[i][0] - b[0];
        }

        REP(i,3){
            REP(j,3){
                if (a[i] + b[j] != c[i][j]){
                    cout << "No";
                    return 0;
                }
            }
        }
    }

    cout << "Yes";
    
	return 0;
}

Measured memory_bytes: 384
// D - 井井井

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
const ll MOD = 1e9 + 7;

ll x[100000];
ll y[100000];

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

	for (int i=0; i<n; i++) {
		cin >> x[i];
		x[i] = (x[i] + MOD) % MOD;
	}

	for (int i=0; i<m; i++) {
		cin >> y[i];
		y[i] = (y[i] + MOD) % MOD;
	}

	ll xi = 0;
	ll xj = 0;
	ll yk = 0;
	ll yl = 0;

	for (ll j=n-1; j>0; j--) {
		xj = (xj + (x[j] * j) % MOD) % MOD;
	}

	for (ll i=0; i<n-1; i++) {
		xi = (xi + (x[i] * (n-1-i)) % MOD) % MOD;
	}

	for (ll l=m-1; l>0; l--) {
		yl = (yl + (y[l] * l) % MOD) % MOD;
	}

	for (ll k=0; k<m-1; k++) {
		yk = (yk + (y[k] * (m-1-k)) % MOD) % MOD;
	}

	ll ans = (((xj - xi + MOD) % MOD) * ((yl - yk + MOD) % MOD)) % MOD;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
n = gets.to_i

all = 0
ans = 0
sa = 0
aover = 0
aovermin = 10**9

n.times{
  a,b = gets.split.map(&:to_i)
  all += a
  sa += (a-b).abs
  if a<=b
    ans += a
  else
    ans += a-b
    aover += 1
    aovermin = b if aovermin > b
  end
}


if sa==0
  p 0
else
  p all - aovermin
end

Measured memory_bytes: 3836
#include <iostream>
#define NORTH 10
#define EAST 11
#define SOUTH 12
#define WEST 13
using namespace std;


int sizex,sizey,arrow;
int turn();
int go(int dist,int &x,int &y);
int main(){
  int x,y;
  string mei;
  int dist;
 while(1){
    cin >>sizex>>sizey;
    if(sizex==0&&sizey==0) return 0; 
    arrow=NORTH;
    x=y=1;
    while(1){
      cin >>mei;
      if(mei=="STOP")
	break;
      switch(mei[0]){
      case 'B':
	cin>>dist;
	dist=-1*dist;
	go(dist,x,y);
	break;
      case 'F':
	cin>>dist;
	go(dist,x,y);
	break;
      case 'R':
	arrow++;
	if(arrow==WEST+1)
	  arrow=NORTH;
	break;
      case 'L':
	arrow--;
	if(arrow==NORTH-1)
	  arrow=WEST;
	break;
      }

   }
    cout <<x<<" "<<y<<endl;   
  }
  return 0;
}

int go(int dist,int &x,int &y){
  switch(arrow){
  case NORTH:
    y+=dist;
    break;
  case SOUTH:
    y-=dist;
    break;
  case EAST:
    x+=dist;
    break;
  case WEST:
    x-=dist;
    break;
  }
  if(x>sizex)
    x=sizex;
  if(y>sizey)
    y=sizey;
  if(x<1)
    x=1;
  if(y<1)
    y=1;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int result = 1;
  for (int i = 0; i < N; ++i) {
    int add = result + K;
    int multi = result * 2;
    result = min(add, multi);
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int N = 0, K = 0;
    scanf("%d%d", &N, &K);
    int i;
    int resultCountOfFriends = 0;
    for (i = 0; i < N; ++i) {
        int heightOfFriend = 0;
        scanf("%d", &heightOfFriend);
        if (heightOfFriend >= K) {
            resultCountOfFriends++;
        }
    }

    printf("%d", resultCountOfFriends);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//UnionFindで1のもの
//だめか。1ときはとらざるをえない

int main(){
  ll N,M; cin>>N>>M;
  vector<ll> G(N+1,1);
  vector<bool> is_red(N+1, false);
  is_red[1]=true;
  for(int i=0; i<M; i++){
    ll a,b; cin>>a>>b;
    if(G[a]==1 && is_red[a]){
      is_red[a]=false;
      is_red[b]=true;
    }
    else if(G[a]>1 && is_red[a])
      is_red[b]=true;
    G[a]--;
    G[b]++;
  }
  ll ans=0;
  for(int i=1; i<=N; i++){
    if(is_red[i]) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define i64 long long
#define all(x) x.begin(), x.end()
#define LB(x,v) lower_bound(all(x),v) - x.begin()
#define maxn (int)(1e5)
using namespace std;
int freq[maxn+2] = {0}, freqUpto[maxn+2];
int main() {
	// your code goes here
	
	int n,val,maxVal = 0, minVal = INT_MAX; 
	scanf("%d",&n);

	//vector<int>d(n);
	for(int i=0;i<n;i++) {
		scanf("%d",&val);
		freq[val]++;
		//d.push_back(val);
		maxVal = max(maxVal,val);
		minVal = min(minVal,val);
	}
	
	//sort(all(d));
	//for(int i=0;i<n;i++) printf("%d ",d[i]);
	//printf("%d\n",(int)(sum/(i64)n));
	
	for(val=minVal; val<=maxVal; val++) {
		freqUpto[val] = freq[val];
		if(val > minVal) freqUpto[val] += freqUpto[val-1];
	}
	
	int ans = 0;
	for(val=maxVal; val>=minVal; val--){
		int cnt = freqUpto[val];
		//printf("%d %d %d\n", val, cnt, n-cnt);
		if(cnt == n-cnt) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
string s;
int x,y;
vector<int> a,b;
bool dp1[8010][16020],dp2[8010][16020];
signed main(){
	cin>>s>>x>>y;
	bool f=false;
	int cnt=0;
	rep(i,s.size()){
		if(s[i]=='T'){
			if(!f)a.push_back(cnt);
			else b.push_back(cnt);
			f^=1;
			cnt=0;
		}
		else cnt++;
	}
	if(cnt){
		if(!f)a.push_back(cnt);
		else b.push_back(cnt);
	}
	dp1[0][8010]=1;
	bool c=true;
	if(s[0]=='T')c=false;
	rep(i,a.size()){
		for(int j=8010-s.size();j<=8010+s.size();j++){
			if(dp1[i][j]){
				if(j-i>=0&&dp1[i][j]&&!c)dp1[i+1][j-a[i]]=1;
				dp1[i+1][j+a[i]]=1;
			}
		}
		c=false;
	}
	dp2[0][8010]=1;
	rep(i,b.size()){
		for(int j=8010-s.size();j<=8010+s.size();j++){
			if(dp2[i][j]){
				if(j-i>=0&&dp2[i][j])dp2[i+1][j-b[i]]=1;
				dp2[i+1][j+b[i]]=1;
			}
		}
	}
	if(dp1[a.size()][8010+x]&&dp2[b.size()][8010+y])puts("Yes");
	else puts("No");
    return 0;
}

Measured memory_bytes: 125824
/*
 ***
 Question Name:
 ***
 Question Link:
 
 ***
 Idea:
 */

#include <memory.h>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef unordered_set<int> ui;
typedef pair<LL,LL> pLL;

int main(){
    int n, x, cnt1 = 0, cnt4 = 0;
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>x;
        if(x%2) cnt1++;
        else if(x%4==0) cnt4++;
    }
    if(cnt1<=cnt4 || (cnt4==cnt1-1 && cnt4+cnt1==n)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

int main(int argc, const char * argv[]) {
    // insert code here...
    int A, B;
    cin >> A >> B;
    
    int C = max(A + B, A - B);
    
    cout << max(C, A * B) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
int a[100];
vector<int> b;
int main()
{
	int i,j,k,n,m,x,y,l,sum,ans=0;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<=min(n,k);i++)
	{
		for(j=0;j<=min(n,k);j++)
		{
			if(i+j>n||i+j>k)
			{
				continue;//break;
			}
			b.clear();
			for(l=0;l<i;l++)
			{
				b.push_back(a[l]);
			}
			for(l=0;l<j;l++)
			{
				b.push_back(a[n-1-l]);
			}
			sort(b.rbegin(),b.rend());
			sum=0;
			for(l=0;l<i+j;l++)
			{
				sum+=b[l];
			}
			ans=max(ans,sum);
			x=k-i-j;
			y=i+j-1;
			while(x>0&&b.size()>0&&b[y]<0)
			{
				sum-=b[y];
				y--;
				x--;
			}
			ans=max(ans,sum);
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] h = new int[N];
        int max = 0;
        for(int i= 0; i<N; i++) {
            h[i] = Integer.parseInt(sc.next());
            if(max < h[i]) {
                max = h[i];
            }
        }
        int count = 0;
        while(max > 0) {
            if(N == 1) {
                count = h[0];
                break;
            }
            for(int i=1; i<N; i++) {
                if(i<N-1) {
                    if(h[i-1] == max) {
                        h[i-1]--;
                        if(h[i] != max) {
                            count++;
                        }
                    }
                }else {
                    if(h[i-1] == max) {
                        h[i-1]--;
                        count++;
                        if(h[i] == max) {
                            h[i]--;
                        }
                    }else {
                        if(h[i] == max) {
                            count++;
                            h[i]--;
                        }
                    }
                }
            }
            max--;
        }
        System.out.println(count);
        
    }
}

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

int main() {
  int N,K; cin >>N >>K;

  int ans=K*pow(K-1,N-1);

  cout <<ans <<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
using R = double;
using P = complex<R>;
#define x real()
#define y imag()
const R eps = 1e-9,PI = acos(-1);

bool equal(R a,R b){return abs(b-a)<eps;}
bool equal0(R a){return equal(a,0.0);}

P operator*(const P& p,const R& d){
    return P(p.x*d,p.y*d);
}

istream &operator>>(istream& is,P& p){
    R a,b;
    is >> a >> b;
    p = P(a,b);
    return is;
}

ostream &operator<<(ostream& os,P& p){
    os << fixed << setprecision(10) << p.real() << " " << p.imag();
}
//内積
double dot(P a,P b) {return (conj(a)*b).real();}
//外積
double cross(P a,P b) {return (conj(a)*b).imag();}

struct L{
    P a,b;
    L(P a,P b):a(a),b(b){}
    L(R A,R B,R C){
        if(equal(A,0)) a = P(0,C/B),b = P(1,C/B);
        else if(equal(B,0)) b = P(C/A,0),b = P(C/A,1);
        else a = P(0,C/B),b = P(C/A,0);
    }
};

//pをbに射影
P projection(P p,P b) {return b*dot(p,b)/norm(b);}

//pとp1 to p2 に射影
P projection(L l,P p){
    p -= l.a; l.b -= l.a;
    P proj = projection(p,l.b);
    return l.a+proj;
}

struct S:L{
    S(P a,P b):L(a,b){}
};

//点の回転方向を判定
int ccw(P& p0,P p1,P p2){
    p1 -= p0,p2 -= p0;
    if(cross(p1,p2)>eps) return 1; //"COUNTER_CLOCKWISE"
    if(cross(p1,p2)<-eps) return -1; //"CLOCKWISE"
    if(dot(p1,p2)<0) return 2; //"ONLINE_BACK"
    if(norm(p1)<norm(p2)) return -2; //"ONLINE_FRONT"
    return 0; //"ON_SEGMENT"
}

bool is_parallel(L& l1,L& l2){
    return equal0(cross(l1.b-l1.a,l2.b-l2.a));
}

bool is_orthogonal(L& l1,L& l2){
    return equal0(dot(l1.a-l1.a,l2.b-l2.a));
}

//pをlに関して対称移動
P reflection(L& l,P& p){
    return p+(projection(l,p)-p);
}

//pがl上にあるか
bool is_online(L& l,P& p){
    return abs(ccw(l.a,l.b,p))!=1;
}

bool is_onsegment(S& s,P& p){
    return ccw(s.a,s.b,p)==0;
}

int main(){
    P p1,p2;
    cin >> p1;
    cin >> p2;
    int Q;
    cin >> Q;
    for(int i=0;i<Q;i++){
        P p;
        cin >> p;
        P res = projection(L(p1,p2),p);
        cout << res << endl;
    }
}


Measured memory_bytes: 3356
Module Module1

    Sub Main()

        Dim N As Integer = Console.ReadLine()
        Dim tmp() As String = Split(Console.ReadLine())

        Dim a(N) As Integer

        Dim c As Integer

        For c = 0 To N - 1
            a(CInt(tmp(c)) - 1) = c + 1
        Next

        For c = 0 To N - 1
            Console.Write(a(c) & " ")
        Next

        'Console.Read()

    End Sub

End Module


Measured memory_bytes: 26712
dice_init = input().split()
dicry = {'search':"152304",'hittop':'024135', 'hitfront':'310542'}
num = int(input())

def dicing(x):
    global dice
    dice = [dice[int(c)] for c in dicry[x]]

for _ in range(num):
    dice = dice_init
    top, front = map(int, input().split())
    while True:
        if int(dice[0]) == top and int(dice[1]) == front:
            break
        elif int(dice[0]) == top:
            dicing('hittop')
        elif int(dice[1]) == front:
            dicing('hitfront')
        else:
            dicing('search')
    print(dice[2])


Measured memory_bytes: 5604
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define IO std::ios::sync_with_stdio(false)
#define ll long long
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define INF 0x3f3f3f3f

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

int a,b,c,d;
signed main() {
  IO;
  cin >> a >> b >> c >> d;
  while(a > 0 && c > 0){
     c -= b;
     if(c <= 0) break;
     a -= d;
     if(a <= 0) break;
  }
  if(a <= 0) cout << "No" << '\n';
  else cout << "Yes" << '\n';
  return 0;
}

Measured memory_bytes: 3640
import Control.Applicative

main :: IO ()
main = do
  ns <- (map read . words) <$> getLine :: IO [Int]
  putStrLn $ show $ solve ns

solve :: [Int] -> Int
solve (s:e:_) = length [x | x <- [s..e], isPalindrome x]
  where
    isPalindrome n = show n == (reverse $ show n)


Measured memory_bytes: 892
N,M=map(int,input().split())
Hlist=list(map(int,input().split()))
ABlist=[]
for _ in range(M):
    ABlist.append(list(map(int,input().split())))
flaglist=[1]*N
for row in ABlist:
    one=row[0]-1 #indexと番号の調整
    two=row[1]-1
    if Hlist[one]<=Hlist[two]:
        flaglist[one]=0
    if Hlist[one]>=Hlist[two]:
        flaglist[two]=0
print(sum(flaglist))

Measured memory_bytes: 31900
#include<iostream>

using namespace std;


main(){
  int a,b,c,d,n,count=0;
  int cAndD[2001];
  
  for(int j = 0; j<2001;j++){
    cAndD[j] = 0;
  }
  
  for(c = 0; c <= 1000; c++){
    for(d = 0; d <= 1000; d++){
      cAndD[c+d]++;
    }
  }
  
  
  while(cin >> n){

      if(n > 2000){
	n = n - 2000;
	n = 2000 - n;
      }
      
      for(a = 0; a <= 1000; a++){
	if(a > n)break;
	for(b = 0; b <= 1000; b++){
	  if(a + b >n) break;
	  if((n-a-b) > 2000 || (n-a-b) < 0)break;
	  count += cAndD[n-(a+b)];
	}
      }
      cout << count << endl;
      count = 0;
  }

}

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

typedef long long ll;

int main(void)
{
    //freopen("input.txt", "r", stdin);

    ll a,b,h,m;
    cin>>a>>b>>h>>m;
    
    double pi = 3.14159265358979323846;
    double ans2 = (double)m/60;
    double ans1 = ((double)h+ans2)/12;
    
    double ans3 = abs(ans1*2*pi - ans2*2*pi);
    
    double ans4 = (a*a)+(b*b);
    double ans5 = ans4 - 2*a*b*cos(ans3);
    double ans6 = sqrt(ans5);
    
    cout<<setprecision(21)<<fixed;
    cout<<ans6<<"\n";

    return 0;
}


Measured memory_bytes: 4292
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a+ n);
    for(int i = 0; i < n - 1; i++) {
        if(a[i] == a[i + 1]) {
            cout << "NO" << "\n";
            return 0;
        }
    }
    cout << "YES" << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL a, b;

int main()
{
	in >> a >> b;
	for (LL i = 1; i < 499500; ++i)
	{
		LL aa = a + i, bb = b + i;
		if (bb == (bb - aa)*(bb - aa + 1) / 2)
		{
			out << i << std::endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
n=int(input())
a=[0]*n
b=list(map(int, input().split()))
a[0]=b[0]
a[1]=b[0]
for i in range(1,n-1):
    if a[i]>b[i]:
        a[i]=b[i]
    a[i+1]=b[i]
print(sum(a))


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N){
    cin >>  A.at(i);
  }
 vector<int> count(1000);
  rep(i,N) {
    while(A.at(i) % 2 == 0) {
      count.at(i)++;
      A.at(i) /= 2;
    }
 }
  int  mini = 1e10;
  rep(i,N) {
    mini = min(mini,count.at(i));
  }
cout << mini << endl;
  return 0;
}


Measured memory_bytes: 256
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
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);
}
struct edge {
    int to, cost;
};
int n, b, c;
int a[10000];
vector<vector<int> > v(100000);
vector<bool> used(100000,false);
int center;
int dfsc(int a,int count){
    if(a==n-1) return count;
    used[a]=true;
    int res=0;
    for(int i=0;i<v[a].size();i++){
        if(used[v[a][i]]) continue;
        res=max(res,dfsc(v[a][i],count+1));
    }
    if(res/2==count) center=a;
    return res;
}
int dfs(int a){
    used[a]=true;
    int res=1;
    for(int i=0;i<v[a].size();i++){
        if(used[v[a][i]]) continue;
        res+=dfs(v[a][i]);
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;

    for (int i = 0; i < n-1; i++)
    {
        int tempa, tempb;
        cin >> tempa>>tempb;
        tempa--;
        tempb--;
        v[tempa].push_back(tempb);
        v[tempb].push_back(tempa);
    }
    center=0;
    int c=dfsc(0,0);
    used=vector<bool> (100000,false);
    //cout<<center<<"\n";
    used[center]=true;
    int ans=dfs(n-1);
    //cout<<ans<<"\n";
    if(ans*2>=n)
    return cout <<"Snuke"<< "\n",0;
    else{
        return cout <<"Fennec"<< "\n",0;
    }
}



Measured memory_bytes: 12032
#include<stdio.h>


int main()
{
	int N, X;
	int m[100];
	int saisyou=1000;
	int count = 0;
	scanf("%d %d", &N, &X);
	

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &m[i]);
		X -= m[i];
		if (m[i] < saisyou) saisyou = m[i];
		
	}
	
	
	count = X / saisyou+N;
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 128