akhauriyash/Code-Regression huggingface dataset:
import sys


class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x


N = int(input())
Px = []
Py = []
for k, s in enumerate(sys.stdin.readlines()):
    x, y = map(int, s.split())
    Px.append((x, k))
    Py.append((y, k))

edge = []

Px.sort()
Py.sort()
for i in range(N - 1):
    x0, k0 = Px[i]
    x1, k1 = Px[i + 1]
    d = abs(x0 - x1)
    edge.append((d, k0, k1))

    y0, k0 = Py[i]
    y1, k1 = Py[i + 1]
    d = abs(y0 - y1)
    edge.append((d, k0, k1))

edge.sort()
uf = UnionFind(N)
cnt = 0
for d, k0, k1 in edge:
    if uf.find(k0) != uf.find(k1):
        uf.union(k0, k1)
        cnt += d

print(cnt)


Measured memory_bytes: 132048
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e,n;
  string s,ss,sss;
  cin>>n;
  if(n%2){
    double num=(double)(n/2+1)/(double)(n);
    printf("%.10f\n",num);
  }else printf("0.500000000\n");
  return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;

int digit(long int num)
{

    int cnt = 0;

    while (num != 0) {
        num /= 10;
        cnt++;
    }

    return cnt;
}

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

    int ans = digit(N);
    int num;

    for (long int i = 1; i*i <= N; ++i) {
        if (N % i == 0) {
            long int A = i;
            long int B = N / i;
            
            num = max(digit(A), digit(B));

            if (ans > num) 
                ans = num;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
x, k, d = map(int, input().split())
r = x % d
q = (x - r) // d
if abs(x) >= k*d:
  if x>0:
    ans = x-k*d
  else:
    ans = abs(x+k*d)
elif k%2 == q%2:
  ans = r
else:
  ans = d - r
print(ans)

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

int main() {
    unsigned int n = 0;
    unsigned int d = 0;

    unsigned int ok = 0;

    scanf("%d %d", &n, &d);

    long* x = new long[n];
    long* y = new long[n];
    long double* r = new long double[n];

    for(int i = 0; i < n; i++) {
        scanf("%lu %lu", &(x[i]), &(y[i]));
        r[i] = sqrt(x[i] * x[i] + y[i] * y[i]);

        if(r[i] <= d) ok++;
    }
    printf("%d\n", ok);

    return 0;
}

Measured memory_bytes: 9448
while (1):
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if (op == '?'):
        break
    elif (op == '+'):
        print(a + b)
    elif (op == '-'):
        print(a - b)
    elif (op == '*'):
        print(a * b)
    elif (op == '/'):
        print(a // b)



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


int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    int n;
    cin>>n;
    ll ans = 0;
    int a[n];
    for(int i = 0;i < n;i++) cin>>a[i];
    for(int i = 0;i < n;i++) {
        for(int j = i+1;j < n;j++) ans += a[i]*a[j];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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;

//input
ll h[100010];

//DP Table
ll dp[100010];

int main() {

    int N,K; cin >> N >> K;
    for (int i = 0; i < N; ++i) {
        cin >> h[i];
    }

    //initialize
    for (int i = 0; i < 100010; ++i) {
        dp[i] = INF;
    }

    //First Condition
    dp[0] = 0;

    //loop
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)


int main() {
	int r;
	cin>>r;
	if(r<1200)cout<<"ABC";
	else if(r<2800)cout<<"ARC";
	else cout<<"AGC";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1000000000000000000
#define MOD 1000000007 

void func()
{
    ll h,w,k;
    cin>>h>>w>>k;
    vector<vector<ll> > row,col;
    for(ll b=0;b<(1<<h);b++){
        vector<ll> subset;
        for(ll i=0;i<h;i++){
            if(b&(1<<i))
                subset.pb(i);
        }
        row.pb(subset);
    }
    for(ll b=0;b<(1<<w);b++){
        vector<ll> subset;
        for(ll i=0;i<w;i++){
            if(b&(1<<i))
                subset.pb(i);
        }
        col.pb(subset);
    }
    char a[h][w];
    loop(i,0,h){
        loop(j,0,w){
            cin>>a[i][j];
        }
    }
    ll ans=0;
    loop(i,0,row.size()){
        vector<ll> x,y;
        x=row[i];
        loop(j,0,col.size()){
            y=col[j];
            ll b[h][w];
            loop(i,0,h){
                loop(j,0,w){
                    b[i][j]=a[i][j];
                }
            }
            loop(l,0,x.size()){
                loop(r,0,w){
                    b[x[l]][r]='.';
                }
            }
            loop(l,0,y.size()){
                loop(r,0,h){
                    b[r][y[l]]='.';
                }
            }
            ll cnt=0;
            loop(l,0,h){
                loop(r,0,w){
                    if(b[l][r]=='#')
                        ++cnt;
                }
            }
            if(cnt==k){
                ans++;
            }
        }
    }
    cout<<ans<<"\n";
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }
}

Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  unordered_map<long, long> mp;
  long N;
  cin >> N;
  rep (i, N) {
    long a;
    cin >> a;
    mp[a-1]++;
    mp[a]++;
    mp[a+1]++;
  }
  long maxnum = 0;
  for (auto it: mp) {
    if (it.second > maxnum) {
      maxnum = it.second;
    }
  }
  cout << maxnum << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 4260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e2+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

char ans[MAXn][MAXn];
int main(){
  IOS();
  ll a,b;
  cin >> a >> b;
  ll n = 100, m = 100;
  a--,b--;
  REP (i,51) REP (j,m) ans[i][j] = '.';
  for (int i=51;i<n;i++) REP (j,m) ans[i][j] = '#';
  REP (i,51) REP (j,m) {
    if (!b) break;
    if (i%2 == 0 && j%2 == 0) {
      if (b) ans[i][j] = '#',b--;
    }
  }
  for (int i=51;i<n;i++) REP (j,m) {
    if (!a) break;
    if (i%2 == 0 && j%2 == 0) {
      if (a) ans[i][j] = '.',a--;
    }
  }

  cout << n << ' ' << m << endl;
  REP (i,n) REP (j,m) {
    cout << ans[i][j];
    if (j == m-1) cout << endl;
  }
}


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

typedef long long ll;
typedef unsigned long long ull;
#define fr first
#define sc second
#define pii pair<int, int>
#define all(v) v.begin(), v.end()

using namespace std;

const ll MOD = 1000000007;

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

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

    reverse(all(v));

    ll ans = v[0];

    for (int i = 2; i < n; i++) {
        ans += v[i / 2];
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 3964
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



int main(){
    int n;
    cin >> n;
    switch(n%10){
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
	P("hon");
	break;
    case 0:
    case 1:
    case 6:
    case 8:
	P("pon");
	break;
    case 3:
	P("bon");
	break;
    }
    return  0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,s=0;cin>>n;int ar[n];for(int i=0;i<n;i++){cin>>ar[i];s+=ar[i];}
    int m;cin>>m;
    while(m--)
    {
        int pos,a;cin>>pos>>a;
        cout<<s+(a-ar[pos-1])<<endl;
    }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define r(i,a,n) for(i=a;i<n;i++)
#define R(i,a,n) for(int i=a;i>=n;i--)
using namespace std;
int main(){
	int n,a,b;
	double s1,s2,s3,aa;
	while(cin>>n,n){
		aa=99999999.9;
		while(n--){
			cin>>b>>s1>>s2;
			s3=abs(22.0-s2/((s1/100.0)*(s1/100.0)));
			if(aa>s3){
				a=b;
				aa=s3;
			}
		}
		cout<<a<<endl;
	}
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n+1];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 1; i < n - 1; ++i)
    {
        if((a[i]>a[i-1]&&a[i]<a[i+1])||(a[i]<a[i-1]&&a[i]>a[i+1]))
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
color = [ [] for i in range(N)]

def updateColor( color, i, from_i, c):
    if len(color[i]) == 1 and color[i][0][0] == from_i:
        color[i] = c
    else:
        for l in color[i]:
            if l[0] != from_i:
                if l[1] == 'Same':
                    updateColor( color, l[0], i, c)
                else:
                    updateColor( color, l[0], i, 1-c)
        color[i] = c
                    

for i in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    if i == 0:
        if w%2 == 0:
            color[u] = color[v] = 0
        else:
            color[u] = 0
            color[v] = 1
    else:
        if color[u] in (0,1):
            if w%2 == 0:
                temp = color[u]
            else:
                temp = 1-color[u]

            for l in color[v]:
                if l[1] == "Same":
                    updateColor( color, l[0], v, temp )
                else:
                    updateColor( color, l[0], v, 1-temp )
            color[v] = temp

        elif color[v] in (0,1):
            if w%2 == 0:
                temp = color[v]
            else:
                temp = 1-color[v]
                
            for l in color[u]:
                if l[1] == "Same":
                    updateColor( color, l[0], u, temp )
                else:
                    updateColor( color, l[0], u, 1-temp )
            color[u] = temp

        else:
            if w%2 == 0:
                color[u].append([v, "Same"])
                color[v].append([u, "Same"])
            else:
                color[u].append([v, "Diff"])
                color[v].append([u, "Diff"])
                    
for c in color:
    print(c)

Measured memory_bytes: 31944
H, W = map(int, input().split())


HW=[ [-1 for w in range(W)] for h in range(H) ]

#print(HW)
from collections import deque
Q = deque()

for h in range(H):
  S = input()
  for w in range(W):
    if S[w]=="#":
      Q.append([h,w])
      HW[h][w]=0

X = [0,0,-1,1]
Y = [-1,1,0,0]
ans=0

while Q:
  h,w = Q.popleft()

  for i in range(len(X)):
    ih,iw = h + Y[i], w + X[i]

    if not ((0 <= ih < H) and (0 <= iw < W)): continue
    if HW[ih][iw] >= 0: continue

    HW[ih][iw] = HW[h][w]+1
    ans = max(ans, HW[ih][iw])
    Q.append([ih,iw])

print(ans)








Measured memory_bytes: 139612
N = int(input())
list1 = list(map(int,input().split()))

list1.sort(reverse=True)

alice = 0
bob = 0
for i in range(len(list1)):
    if i % 2 == 0:
        alice += list1[i]
    else:
        bob += list1[i]

print(alice - bob)


Measured memory_bytes: 9108
#include<iostream>   //AA06( 31/ 05/ 20) If u see my code, Have a Good Day! (^_^)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)

using namespace std;

int main()
{
    fastio;

    int A, B;

    cin >> A >> B;

    cout << A * B << endl;

    return 0;
}


Measured memory_bytes: 3652
s = input()
q = int(input())
qs = [input().split() for i in range(q)]
n = False
left= right = ""
for operation in qs:
    if operation[0] == '1':
        n = not n
    if operation[0] == '2':
        t , f, c = operation
        f = int(f)
        if n:
            f = 1 if f != 1 else 2
        if f == 1:
            left=c+left
        elif f == 2:
            right+=c
s = left+s+right
print(s[::-1] if n else s)

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
   int n,x,y; 
  cin >> n >> x >>y ;
  VI ans(n+1);
  rep(i,n+1) ans.at(i)=0;
  for(int i=1;i<n;i++){
     for(int j=i+1;j<=n;j++){
       int k=j-i;
       if(i<=x){
         if(j>=x && j<=y){
            k=min(k,x-i+y-j+1);
         }
         else if(y<j){
           k=min(k,j-y+x-i+1);
         }
       }
       if(x<i &&i<=y){
         if(j>=x,j<=y){
           k=min(k,i-x+y-j+1);
         }
         else if(y<j){
           k=min(k,j-y+i-x+1);
         }
       }
       ans.at(k)++;
     }
  }
  for(int i=1;i<n;i++){
    cout << ans.at(i) << endl;
  }
}
                 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,sum = 0,all = 0;
    cin >> n;
    vector<int> a(n);
    for(int i  = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    for(int i = 0; i < n; i++){
        all += a[i];
    }
    for(int i = 0; i < n; i += 2){
        sum += a[i];
    }
    cout << sum - (all - sum) << endl;
}

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

main() {
    string s,t; cin >> s >> t;
    int x = stol(s+t);
    double c=(double)sqrt(x);
    if(ceil(c)==floor(c)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
h, w = map(int, input().split())
pict =[]
for i in range(h):
    pict.append(input().rstrip())
    pict[i] = '#'+ pict[i] + '#'
pict.insert(0,'#'*(w+2))
pict.append('#'*(w+2))
for i in range(len(pict)):
    print(pict[i])

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

int main(){
        int n;
        long long int a[100010];
        long long int first=0,second=0;

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

        sort(a,a+n);

        for(int i=n-1; i>0; i--){
                if(a[i]==a[i-1]){
                        if(first==0){
                                first=a[i];
                                i--;
                        }
                        else{
                                second=a[i];
                                break;
                        }
                }
        }

        cout<<first*second<<endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN (-2147483647 - 1)
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;

struct node {
	bool done;
	vi to;
	int id, from;
	int pre, low;
};

class Lowlink {
	int ord;
public:
	vector<node> nodes;
	set<P> bridges;
	set<int> arts; //articulation point
	Lowlink(vector<node> A) {
		nodes = A;
		ord = 0;
		Loop(i, nodes.size()) {
			if (!nodes[i].done) dfs(i, i);
		}
	}
	void dfs(int a, int root) {
		nodes[a].done = 1;
		nodes[a].pre = nodes[a].low = ord;
		ord++;
		int cnt = 0;
		Loop(i, nodes[a].to.size()) {
			int b = nodes[a].to[i];
			if (b == nodes[a].from) continue;
			if (!nodes[b].done) {
				nodes[b].from = a;
				dfs(b, root);
				nodes[a].low = min(nodes[a].low, nodes[b].low);
				if (nodes[a].pre <= nodes[b].low) cnt++;
				if (nodes[a].pre < nodes[b].low) {
					int s = min(a, b), t = max(a, b);
					bridges.insert({ s,t });
				}
			}
			else {
				nodes[a].low = min(nodes[a].low, nodes[b].pre);
			}
		}
		if (cnt > (a == root ? 1 : 0)) arts.insert(a);
		return;
	}
	void put_arts() {
		auto itr = arts.begin();
		Loop(i, arts.size()) {
			cout << *itr << endl;
			itr++;
		}
	}
	void put_bridges() {
		auto itr = bridges.begin();
		Loop(i, bridges.size()) {
			cout << (*itr).first << " " << (*itr).second << endl;
			itr++;
		}
	}
};

int main() {
	int v, e; cin >> v >> e;
	vector<node> nodes(v);
	Loop(i, v) nodes[i] = { 0,{}, i,-1,-1,-1 };
	Loop(i, e) {
		int s, t;
		cin >> s >> t;
		nodes[s].to.push_back(t);
		nodes[t].to.push_back(s);
	}
	Lowlink lk(nodes);
	lk.put_arts();
	return 0;
}

Measured memory_bytes: 6136
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	int b=a%10;
	if(b==2 || b==4 || b==5 || b==7 || b==9)
	cout<<"hon";
	if(b==3)
	cout<<"bon";
	else if(b==0 || b==1 || b==6 || b==8)
	cout<<"pon";
	return 0;
 } 

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

int main(){
    int A,B,m;
    cin >> A >> B >> m;
    int a[A],b[B];
    for(int i=0; i<A; i++){
        cin >> a[i];
    }
    for(int i=0; i<B; i++){
        cin >> b[i];
    }
    int *p = min_element(a,a+A);
    int *q = min_element(b,b+B);
    int ans = *p + *q;
    for(int i=0; i<m; i++){
        int x,y,c;
        cin >> x >> y >> c;
        x--;y--;
        ans = min(a[x]+b[y]-c,ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
	int S, h, m, s;
	scanf("%d",&S);
	h = S / 3600;
	m = S % 3600 / 60;
	s = S % 60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}


Measured memory_bytes: 2104
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

ll dp[110][110];

int main(){
  int h,w; cin >> h >> w;
  vector<string> g(h);
  rep(i,h) cin >> g[i];
  rep(i,h)rep(j,w) dp[i][j]=inf;
  dp[0][0]=0;
  if(g[0][0]=='#') dp[0][0]++;
  rep(i,h)rep(j,w){
    if(g[i][j]=='#'){
      if(i-1>=0&&g[i-1][j]=='.') chmin(dp[i][j],dp[i-1][j]+1);
      else if(i-1>=0) chmin(dp[i][j],dp[i-1][j]);
      if(j-1>=0&&g[i][j-1]=='.') chmin(dp[i][j],dp[i][j-1]+1);
      else if(j-1>=0) chmin(dp[i][j],dp[i][j-1]);
    }
    else{
      if(i-1>=0) chmin(dp[i][j],dp[i-1][j]);
      if(j-1>=0) chmin(dp[i][j],dp[i][j-1]);
    }
  }
  cout << dp[h-1][w-1] << endl;
}

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

using namespace std;

typedef long long ll;

int main() {
	ll A, B = 0;
	string b;
	cin >> A >> b;
	B = (b[0] - '0') * 100 + (b[2] - '0') * 10 + (b[3] - '0');
	A *= B;
	A /= 100;
	cout << A << endl;
 	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int mod = 1000000007;
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
        sum %= mod;
    }
 
    long ans = 0;
 
    //Search for all i
    for (int i = 0; i < N; i++)
    {
        //Update the values of A[i+1] ... A[N]
        sum -= A[i];
        if (sum < 0) sum += mod;
 
        ans += A[i] * sum;
        ans %= mod;
    }
 
    cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 4068
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
#include<numeric>
#include<chrono>
#include <fstream>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
#define mkp(a,b) make_pair(a,b)
using namespace std;
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	// This is code taken from geeksforgeek
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
/*ll power(ll x, ll y)
{
	// This is code taken from geeksforgeek
	ll res = 1;

	x = x % N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % N;
		y = y >> 1;
		x = (x * x) % N;
	}
	return res;
}*/
ll power(ll x, ll y)
{
	ll res = 1;

	x = x;

	while (y > 0)
	{

		if (y & 1)
			res = (res * x);

		y = y >> 1;
		x = (x * x);
	}
	return res;
}


/*ll modInverse(ll n, ll p)
{
	return power(n, p - 2, p);
}*/

ll sum(ll n)
{
	return (n * (n + 1)) / 2;
}
ll sum_digit(ll n)
{
	ll ans = 0;
	while (n)
	{
		ans += n % 10;
		n /= 10;
	}
	return ans;
}
ll gp(ll r, ll n)
{
	return (pow(r,n)-1)/(r-1);
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n;
	cin>>n;
	vector<ll> arr(n,0);
	ll sum=0;
	f(i,0,n)
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	ll ans=0;
	f(i,0,n-1)
	{
		sum-=arr[i];
		ans+=(arr[i])*(sum%N);
		ans%=N;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4772
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;

namespace zyt
{
	const int N = 1e5 + 10, P = 1000000007;
	int n, arr[N], num[N];
	int work()
	{
		int ans = 1;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++)
			scanf("%d", arr + i), ++arr[i];
		num[0] = 3;
		for (int j = 1; j <= n; j++)
		{
			++num[arr[j]];
			if (!num[arr[j] - 1])
			{
				puts("0");
				return 0;
			}
			ans = (ll)ans * (num[arr[j] - 1]--) % P;
		}
		printf("%d", ans);
		return 0;
	}
}
int main()
{
	return zyt::work();
}

Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner reader = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int MAX = 1000000002;
		ArrayList<Integer> monster = new ArrayList<Integer>();
		ArrayList<Integer> heroes = new ArrayList<Integer>();
		int n;
		long maximo = 0;
		n = reader.nextInt();
		for(int i=0; i<n+1; i++)
			monster.add(reader.nextInt());
		for(int i=0; i<n; i++)
			heroes.add(reader.nextInt());
		
		for(int i=0; i<n;i++) {
			if(heroes.get(i) <= monster.get(i)) {
				maximo += heroes.get(i);
			}else {
				//heroes[i]-=monster[i];
				
				heroes.set(i, heroes.get(i) - monster.get(i));
				maximo+=monster.get(i);
				if(heroes.get(i)>=monster.get(i+1)) {
					maximo+=monster.get(i+1);
					monster.set(i+1, 0);
				}else {
					maximo+=heroes.get(i);
					monster.set(i+1, monster.get(i+1)-heroes.get(i));
					//monster[i+1]-=heroes[i];
				}
			}
		}
		System.out.println(maximo);
	}

}


Measured memory_bytes: 91680
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int a,b,k;
  cin>>a>>b>>k;
  if(a>=k){
    cout<<a-k<<' '<<b<<endl;
  }
  else{
    cout<<0<<' '<<max(0LL,b-(k-a))<<endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el cout << "\n"
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);
ll n , m ,k;
ll nbr;

int main()
{
	IOS;


        ll n;
        cin >> n;
        ll k;
        cin >> k;
    vector<ll> L;
    for(int i=0;i<n;i++)
    {
        ll x;
        cin >> x;
        L.push_back(x);
    }
vector<ll> dp(k+1,2);
for(int i=0;i<=k;i++)
    for(int j=0;j<n;j++)
    {
        if((i-L[j])>=0 && dp[i-L[j]]==2)
            dp[i]=1;
    }
    if(dp[k]==2)
        cout << "Second";
    else
        cout << "First";



    return 0;
}


Measured memory_bytes: 1024
/**
*	created: 21.09.2020 19:15:48
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
// #define endl '\n'
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rrep(i,n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define len(x) ll(x.size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
using ll = long long;
using P = pair<int,int>;
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;
template<typename T> inline bool chmax(T &a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T> inline bool chmin(T &a, T b) {if (b < a) {a = b; return 1;} return 0;}
inline void print(P a) {cout << a.first << " " << a.second << endl;}
template<typename T> T pow(T a, ll n) {T r(1); while(n) {if (n & 1) r *= a; a *= a; n >>= 1;} return r;}
struct faster_io {faster_io() {cin.tie(0); ios_base::sync_with_stdio(false);}} faster_io_;

// Dijkstra's Algorithm（単一始点最短経路問題）
struct graph {
    struct edge {
        int to, cost;
        edge(int t, int c) : to(t), cost(c) {}
    };
    int n;
    vector<vector<edge>> G;
    vector<int> d, pre;
    graph(int i) : n(i), G(i), d(i,INF), pre(i) {}
    void add_edge(int s, int to, int cost) {
        G[s].push_back(edge(to,cost));
    }
    void dijkstra(int s) {
        rep(i,n) {d[i] = INF; pre[i] = 0;}
        d[s] = 0;
        priority_queue<P, vector<P>, greater<P>> que;
        que.push(P(0,s));
        while(!que.empty()){
            P p = que.top(); que.pop(); int v = p.second;
            if(d[v] < p.first) continue;
            for(auto e : G[v]) if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost; pre[e.to] = v;
                que.push(P(d[e.to],e.to));
            }
        }
    }
};

signed main() {
    int n; cin >> n;
    graph g(n);
    rep(i,n-1) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        g.add_edge(a,b,c);
        g.add_edge(b,a,c);
    }
    g.dijkstra(0);
    rep(i,n) cout << g.d[i] % 2 << endl;
    return 0;
}

Measured memory_bytes: 12424
#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
using namespace std;

string s;

inline void work(){
	cin >> s;													//输入一个字符串 
	if (s.size() % 2){											//如果字符串的长度为奇数 
		puts("No");												//输出No
		exit(0);												//等同于return 0 
	}
	REP(i, 0, s.size() - 1)										//依次枚举字符串的每个字符 
		if (i % 2 && s[i] != 'i' || i % 2 == 0 && s[i] != 'h'){	//如果i是奇数并且s[i]不等于'i'或者i是偶数并且s[i]不等于'h' 
			puts("No");											//输出No 
			exit(0);											//等同于return 0
		}
	puts("Yes");												//这个字符串合法 
}

int main(){
	work();
	return 0;
}

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

typedef unsigned long long ull;

ull dig[20]={};
ull sum3[20]={};
ull sum5[20]={};
ull sum15[20]={};
ull s;

ull getsum(ull m){
  if(m==0)return 0;
  int a=(int)log10(m);
  ull b,c,d,res;
  
  b=m/3-sum3[a];
  c=m/5-sum5[a];
  d=m/15-sum15[a];
  res=dig[a];
  m-=(ull)pow(10,a);
  res+=(m-b-c+d+1)*(a+1);
  res+=(b+c)*4;

  return res;
}

bool ok(ull m){
  ull res=getsum(m);
  if(res<s)return true;
  return false;
}

int main()
{
  ull tmp1=0,tmp2=1,tmp3=0;

  for(int i=1;i<18;i++){
    ull sum=((ull)pow(10,i));
    sum3[i]=sum/3-tmp1;
    tmp1+=sum3[i];
    sum5[i]=sum/5-tmp2;
    tmp2+=sum5[i];
    sum15[i]=sum/15-tmp3;
    tmp3+=sum15[i];
  }

  for(int i=1;i<18;i++){
    ull sum=(pow(10,i)-pow(10,i-1));
    dig[i]=(sum-sum3[i]-sum5[i]+sum15[i])*i;
    dig[i]+=(sum3[i]+sum5[i])*4;
  }
  for(int i=1;i<18;i++){
    sum3[i]+=sum3[i-1];
    sum5[i]+=sum5[i-1];
    sum15[i]+=sum15[i-1];
    dig[i]+=dig[i-1];
  }

  cin>>s;

  ull l=1,r=1e18,m;
  while(l<r){
    m=(l+r)/2;
    if(ok(m))l=m+1;
    else r=m;
  }

  ull start=s-getsum(m-1)-1;

  string ans="";
  while(1){
    if(ans.length()>100)break;
    if(m%3==0 && m%5==0)ans+="FizzBuzz";
    else if(m%3==0)ans+="Fizz";
    else if(m%5==0)ans+="Buzz";
    else {
      ostringstream os;
      os<<m;
      ans+=os.str();
    }
    m++;
  }

  for(ull i=start;i<20+start;i++)cout<<ans[i];
  cout<<endl;
  
  return 0;
}

Measured memory_bytes: 1284
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) throws Exception {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();

        int[] A = new int[N];
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();

        for (int i = 0; i < N; i++) {
            int tmp = sc.nextInt();
            if (map.get(tmp) == null) {
                map.put(tmp, 1);
            } else {
                map.put(tmp, map.get(tmp) + 1);
            }
        }

        int count = 0;
        for (Entry<Integer, Integer> entry : map.entrySet()) {
            if(entry.getValue() % 2 != 0) {
                count++;
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 63896
N,M = map(int,input().split())

ki = [list() for i in range(N)]
for _ in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    ki[a].append(b)

K = [-1] * N
def dfs(now,time):
    K[now] = time
    for i in ki[now]:
        time += 1
        dfs(i,time)
        time -= 1

dfs(0,0)
print('POSSIBLE' if K[N-1] == 2 else 'IMPOSSIBLE')

Measured memory_bytes: 34936
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,v.size())
#define all(v)(v).begin(),(v).end()
#define bit(n)(1ll<<(n))
#define uniq(v)sort(all(v));v.erase(unique(all(v)),v.end())
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,T&&t,U&&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(T&&...t){_print(cout,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#else
template<class...T>void dprint(T&&...t){_print(cerr,t...);}
#endif
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<<(ostream&o,const multiset<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n,q;
    cin>>n>>q;
    vvi ki(n);
    REP(i,n-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        ki[a]<<b;
        ki[b]<<a;
    }
    vi c(n);
    REP(i,q){
        int p,x;
        cin>>p>>x;
        c[p-1]+=x;
    }
    vi ans(n, -1);
    queue<P> que;
    que.emplace(0,0);
    while(que.size()){
        P top=que.front();
        que.pop();
        ans[top.F]=top.S+c[top.F];
        for(int a:ki[top.F]){
            if(ans[a]<0){
                que.emplace(a, ans[top.F]);
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 17140
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define int long long
#define str string
#define vint vector<signed>
#define pint pair<signed,signed>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define isEven(t) t%2==0
#define debg(a) cout<<#a<<":"<<a<<endl;
signed main(){
  int n,k;
  cin>>n>>k;
  int a[n+1];
  rep(i,n)cin>>a[i];
  a[n]=0;
  sort(a,a+n+1);
  int cent,left,right;
  rep(i,n+1)if(a[i]==0)cent=i;
  vint ans;
  rep(i,k+1){
    if(k-i>cent){
      left=0;
    }
    else left=cent-(k-i);
    right=cent+k-(cent-left);
    if(right>n)break;
    int Lres=abs(a[left]-a[cent]);
    int Rres=abs(a[right]-a[cent]);
    int res=min((Lres*2+Rres),(Lres+Rres*2));
    ans.pb(res);
  }
  sort(all(ans));
  cout<<ans[0]<<endl;
  
  return 0;
}


Measured memory_bytes: 1660
a,b,c = [int(i) for i in input().split()]
d = []
for i in range(1,int(c**0.5)+1):
    if i **2 == c:
        d.append(i)
        continue
    if c%i == 0:
        d.extend([i,c//i])
d.sort()
e = [i for i in d if a<=i<=b]
print(len(e))



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

list = [500000,300000,200000,100000,0]

if(A>3):
    A = 4
if(B>3):
    B = 4
elif(A==1 and B==1):
    A=B=0
money = list[A]+list[B]
print(money)


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

typedef long long ll;
const ll INF = 1LL<<60, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(v) (v).begin(), (v).end()
#define first fi
#define second se

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n,l,sum=0,ans=INF,ret=0,num;
  cin >> n >> l;
  REP(i,1,n+1) sum += (l+i-1);
  REP(i,1,n+1){
    if(ans > abs(sum-(sum-(l+i-1)))){
      ans = abs(sum-(sum-(l+i-1)));
      num = i;
    }
  }
  cout << sum-(l+num-1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#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> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  int n;
  cin >> n;
  vi x(n);
  rep(i, n) cin >> x[i];

  int ans = 1001001001;
  for(int i=1;i<=100;i++){
    int cost = 0;
    rep(j, n){
      cost += pow(x[j] - i, 2);
    }
    ans = min(ans, cost);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n,k; cin >> n >> k;
  vector<int> h(n);
  for(auto &e: h) cin >> e;
  vector<int> cost(n);
  cost[0] = 0;
  for(int i=1;i<cost.size();i++) {
    int res = INT_MAX;
    for(int j=max(0,i-k);j<i;j++) {
      res = min(res,cost[j] + abs(h[j]-h[i]));
    }
    cost[i] = res;
  }
  cout << cost[n-1];
  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X = Integer.parseInt(sc.next());
    int N = Integer.parseInt(sc.next());
    if(N == 0){
      System.out.println(X);
      return;
    }
    int p[] = new int[N];
    for(int i = 0; i<N;i++){
      p[i] = Integer.parseInt(sc.next());
    }
    boolean f = true;
    for(int j = 0;j<100;j++){
      int before = X - j;
      int after = X + j;
      for(int k =0;k<N;k++){
        if(before == p[k]){
          f = false;
        } 
      }
      if(f==true){
        System.out.println(X-j);
        return;
      }
      f = true;
      for(int k =0;k<N;k++){
        if(after == p[k]){
          f = false;
        } 
      }
      if(f==true){
        System.out.println(X+j);
        return;
      }
      f = true;
    }
  }
}

Measured memory_bytes: 35752
from decimal import *
import math

def main():
    a, b, x = map(int, input().split())
    if a * a * b == x:
        print(0)
        exit()
    if Decimal(a) * Decimal(b) / Decimal(2) >= Decimal(x) / Decimal(a):
        tmp = Decimal(2) * Decimal(x) / (Decimal(a) * Decimal(b))
        c = math.atan(Decimal(tmp) / Decimal(b))
        d_deg = math.degrees(Decimal(c))
        print(Decimal(90) - Decimal(d_deg))
    else:
        d = (Decimal(2) * Decimal(x) / (Decimal(a) * Decimal(a))) - Decimal(b)
        c = math.atan(Decimal(a) / (Decimal(b) - Decimal(d)))
        d_deg = math.degrees(Decimal(c))
        print(Decimal(90) - Decimal(d_deg))


if __name__ == "__main__":
    main()

Measured memory_bytes: 61420
import java.util.*;

public class Main {
    private final static long MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // int n = sc.nextInt();
        // int k = sc.nextInt();
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        Long ans = 1L;

        // int[] a = new int[n];
        Integer[] a = new Integer[n];
        ArrayList<Integer> s = new ArrayList<>();
        ArrayList<Integer> t = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (a[i] < 0)
                t.add(a[i]);
            else
                s.add(a[i]);
        }

        int S = s.size(), T = t.size();
        boolean ok = false;

        if (S > 0) {
            if (n == k)
                ok = (T % 2 == 0);
            else
                ok = true;
        } else {
            ok = (k % 2 == 0);
        }

        if (!ok) {
            Arrays.sort(a, (x, y) -> (Math.abs(x) - Math.abs(y)));
            for (int i = 0; i < k; i++) {
                ans = mul(ans, a[i]);
            }
        } else {
            Collections.sort(s);
            Collections.sort(t, (x, y) -> (y - x));
            if (k % 2 == 1) {
                int last = s.size() - 1;
                ans = mul(ans, s.get(last));
                s.remove(last);
            }
            ArrayList<Long> p = new ArrayList<>();
            while (s.size() >= 2) {
                int last = s.size() - 1;
                long x = s.get(last);
                s.remove(last--);
                x *= s.get(last);
                s.remove(last);
                p.add(x);
            }
            while (t.size() >= 2) {
                int last = t.size() - 1;
                long x = t.get(last);
                t.remove(last--);
                x *= t.get(last);
                t.remove(last);
                p.add(x);
            }
            Collections.sort(p, (o1, o2) -> Long.compare(o2, o1));
            for (int i = 0; i < k / 2; i++) {
                ans = mul(ans, p.get(i));
            }
        }
        ans = Math.floorMod(ans, MOD);
        System.out.println(ans);

    }

    private static long mul(long a, long b) {
        return (((a + MOD) % MOD) * ((b + MOD) % MOD)) % MOD;
    }
}

Measured memory_bytes: 65996