akhauriyash/Code-Regression huggingface dataset:
n = int(input())
machi = []
li_x = []
li_y = []
for i in range(n):
    x, y = map(int, input().split())
    li_x.append((x, i))
    li_y.append((y, i))
    machi.append((x, y, i))
li_x.sort()
li_y.sort()
edge = [[] for _ in range(n)]
for i in range(n-1):
    edge[li_x[i][1]].append((li_x[i+1][0]-li_x[i][0], li_x[i+1][1]))
    edge[li_x[i+1][1]].append((li_x[i+1][0]-li_x[i][0], li_x[i][1]))
    edge[li_y[i][1]].append((li_y[i+1][0]-li_y[i][0], li_y[i+1][1]))
    edge[li_y[i+1][1]].append((li_y[i+1][0]-li_y[i][0], li_y[i][1]))

import heapq
def prim_heap(edge, n):
    used = [True] * n # True ：　不使用husiyou
    edgelist = []
    for e in edge[0]:
        heapq.heappush(edgelist, e)
    used[0] = False
    res = 0
    while len(edgelist) != 0:
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist, e)
        res += minedge[0]
    return res
print(prim_heap(edge, n))

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

class Program
{
    static void Main(string[] args)
    {
        int[] input = Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray();
        if (input[1] - input[0] == input[2] - input[1])
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 13268
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<int,int>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

/* --------------------------------------- */
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<ll> a(n);
	REP(i,n) cin >> a[i];
	ll ans = 0;
	REP(i,n) {
		ans += a[i] - 1;
	}
	cout << ans << endl;
	return 0;
}
/* --------------------------------------- */


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


int main(int argc, const char * argv[]) {
    
    int leftArray[4] = {0},rightArray[4] = {0};
    
    double left,right;
    while (cin >> left >> right) {
        if(left >= 1.1) leftArray[0]++;
        else if(left >= 0.6) leftArray[1]++;
        else if(left >= 0.2) leftArray[2]++;
        else leftArray[3]++;
        
        if(right >= 1.1) rightArray[0]++;
        else if(right >= 0.6) rightArray[1]++;
        else if(right >= 0.2) rightArray[2]++;
        else rightArray[3]++;
            
    }
    
    for(int i=0;i<4;i++){
        cout << leftArray[i] << " " << rightArray[i] << endl;
    }
    
    return 0;
}

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

"""
# このアプローチはメモリーエラー
s=[[1]]

#長さNまで
import copy
while True:
    n = []
    for s1 in s:
        for append in range(s1[-1], M+1):
            n1 = copy.copy(s1)
            n1.append(append)
            n.append(n1)
    if len(n[0]) > M:
        break
    s = n
#for s1 in s:
#    print(s1)
iidp = [list(map(int,input().split())) for q in range(Q)]

al = 0
for s1 in s:
    a = 0
    for i1, i2, d, p in iidp:
        if s1[i2-1] - s1[i1-1] == d:
            a += p
    al = max(a,al)

print(al)
"""

iidp = [list(map(int,input().split())) for q in range(Q)]
import itertools
al = 0
for s1 in itertools.combinations_with_replacement(list(range(1,M+1)), N):
    a = 0
    for i1, i2, d, p in iidp:
        if s1[i2-1] - s1[i1-1] == d:
            a += p
    al = max(a,al)

print(al)

Measured memory_bytes: 9208
import math

pi = math.pi
a, b, h, m = map(int, input().split())
m_theta = m*2*pi/60
h_theta = h*2*pi/12 + m*2*pi/720
theta = abs(h_theta-m_theta)
# print(math.cos(theta))
c2 = a**2 + b**2 - 2*a*b*math.cos(theta)
print(math.sqrt(c2))


Measured memory_bytes: 9496
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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 int MAX_N = 110;
const int MAX_V = 10010;
int N;
ll W, v[MAX_N], w[MAX_N];
// dp[i][j] := i番目までの品物を選んだとき
//             価値の総和がjになる重さの最小値
ll dp[MAX_N][MAX_V];

int main() {
    cin >> N >> W;
    rep(i, N) cin >> v[i] >> w[i];

    rep(i, MAX_N) rep(j, MAX_V) dp[i][j] = LLINF;
    dp[0][0] = 0;
    for (int i = 0; i < N; i++) {
        for (int sum_v = 0; sum_v < MAX_V; sum_v++) {
            if (sum_v - v[i] >= 0) {
                chmin(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i]);
            }
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    int ans = 0;
    rep(sum_v, MAX_V) {
        if (dp[N][sum_v] <= W) ans = sum_v;
    }
    cout << ans << endl;
}



Measured memory_bytes: 11728
#include<bits/stdc++.h>
using namespace std;
const int N=15;
int n,m,x,y,z,g[1<<N],a[N][N],f[1<<N][N],ans;
int main(){
	scanf("%d%d",&n,&m);
	int sum=0;
	while (m--){
		scanf("%d%d%d",&x,&y,&z);
		sum+=z;
		x--;y--;
		a[x][y]=a[y][x]=z;
	}
	for (int s=1;s<1<<n;s++)
		for (int i=0;i<n;i++)
			if (s&(1<<i)){
				g[s]=g[s^(1<<i)];
				for (int j=0;j<n;j++)
					if ((s&(1<<j)))g[s]+=a[i][j];
				break;
			}
	memset(f,172,sizeof f);
	f[1][0]=0;
	for (int s=1;s<1<<n;s++)
		for (int j=0;j<n;j++)
			if (f[s][j]>=0){
				for (int i=0;i<n;i++)
					if (!(s&(1<<i))&&a[j][i])
						f[s|(1<<i)][i]=max(f[s|(1<<i)][i],f[s][j]+a[j][i]);
				int sy=((1<<n)-1)^s;
				for (int i=sy;i;i=(i-1)&sy)f[s|i][j]=max(f[s|i][j],f[s][j]+g[i|(1<<j)]);
			}
	int ans=0;
	for (int i=1;i<1<<n;i++)ans=max(ans,f[i][n-1]);
	printf("%d",sum-ans);
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, l;
	string s = "";
	cin >> n >> l;
	vector<string> v(n);
	for (int i = 0; i < n; i++){
		cin >> v.at(i);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n; i++){
		s += v.at(i);
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;


int main()
{
	string S, ans;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'B' && !ans.empty()) ans.pop_back();
		else if (S[i] != 'B')ans.push_back(S[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

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

    ll N, Q;
    cin >> N >> Q;

    typedef vector<ll> Edge;
    struct Node{
        Edge edge;
        ll value;
        bool flag;
    };
    typedef vector<Node> Graph;

    Graph tree(N, {{},0, false});
    rep(i, N - 1){
        ll a, b;
        cin >> a >> b;
        --a, --b;
        tree[a].edge.pb(b);
        tree[b].edge.pb(a);
    }    

    rep(_, Q){
        ll p, x;
        cin >> p >> x;
        --p;
        tree[p].value += x;
    }

    stack<Node> sk;
    sk.push(tree[0]);
    tree[0].flag = true;

    while(!sk.empty()){
        Node now = sk.top();
        sk.pop();
        ll s = now.value;

        for(auto e : now.edge){
            if(tree[e].flag) continue;
            tree[e].value += s;
            tree[e].flag = true;
            sk.push(tree[e]);
        }
    }

    rep(i,N) cout << tree[i].value << " ";

    return 0;
}

Measured memory_bytes: 32312
#include<stdio.h>
int main(){
    int m,f,r,t;
        for(;;)
            {        scanf("%d%d%d",&m,&f,&r);
                    t=m+f;       
                     if(m+f+r==-3)return 0;       
                      if(m==-1||f==-1)puts("F");       
                       else if(t>=80)puts("A");       
                        else if(t>=65)puts("B");       
                         else if(t>=50||r>=50)puts("C");       
                          else if(t>=30)puts("D");       
                           else puts("F");    }    
                           return 0;} 

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> l(n);
    
    for (int i=0; i<n; i++) cin >> l.at(i);
    
    sort(l.begin(), l.end(), greater<int>());
    
   int ans = 0;
   for (int i=0; i<k; i++) ans += l.at(i);
   
   cout << ans << endl;
    
}

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

S = input()
T = input()


arr1 = [0]*(max(N, M) + 1)
arr2 = [0]*(max(N, M) + 1)


def factoring(arr, tmp):
    i = 1
    while i < tmp:
        i += 1
        if tmp % i == 0:
            tmp = tmp // i
            arr[i] += 1
            i = 1
    
factoring(arr1, tmp=N)
factoring(arr2, tmp=M)

U = 1
for i in range(2, max(N, M)+1):
    tmp = max(arr1[i], arr2[i])
    if tmp != 0:
        U *= i**tmp
V = 1
for i in range(2, max(N, M)+1):
    tmp = min(arr1[i], arr2[i])
    if tmp != 0:
        V *= i**tmp


def good_str(N, M, S, T):
    n = 0
    m = 0
    while n < N and m < M:
        if M*n == N*m:
            if S[n] != T[m]:
                return False
        if M*n > N*m:
            m += 1
        else:
            n += 1
    return True


if good_str(N, M, S, T):
    print(U)
else:
    print(-1)

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

using namespace std;
#define sz(a) int(a.size())
#define ll  long long int
#define mod (long long)(1e9+7)
#define endl '\n'
#define ENGZ ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);cin.tie(0) , cout.tie(0) ;
#define pi (acos(-1))
#define F first
#define S second

ll fp(ll n , ll p )
{
    if(p==0)
        return 1;
    if(p==1)
        return n ;
    ll res = fp(n,p/2);
    res=((res)*(res)) ;
    if(p%2)
        res=(res*n) ;
    return res ;
}

ll n , m , a,  b , c , cnt = 0 , cost = 0;
map<ll,ll> mp;
int main()
{
    ENGZ;
    cin>>n >>m ;
    mp[0] = 0 ;
    for(int i=0 ; i<m ; i++)
    {
        cin>>a >>b ;
        cnt = 0 ;
        for(int i=0 ; i<b ; i++)
        {
            cin>>c ;
            cnt+= fp(2,c-1); // to change digit of mask ..
        }
        for(auto i:mp)
        {
            ll mask = i.F | cnt;
            if(mp.count(mask))mp[mask] = min(mp[mask],i.S + a);
            else mp[mask] = i.S + a;
        }
    }
    ll a5er_box = fp(2,n) -1;
    for(auto i:mp)cerr<<i.F <<" " <<i.S <<endl ;
    cerr<<"---------------------------" <<endl ;
    if(mp.count(a5er_box))cout<<mp[a5er_box] <<endl;
    else cout<<-1 <<endl ;
    return 0;
}


Measured memory_bytes: 3820
#include "bits/stdc++.h"
using namespace std;

int main() {
	string S;
	cin >>S;
	int ans = 0;
	for (int n = 0;n<S.size()/2;++n) {
		if (S[n] != S[S.size()-1-n]) {
			ans++;
		}
	}
	cout << ans <<endl;
	return 0;
}

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

using namespace std;
using P = pair<int,int>;
const int INF = 1e9;

vector<P> dir = {P(1,0), P(-1,0), P(0,1), P(0,-1)};
vector<int> area = {-2,-1,0,1,2};

int H,W;
int sh,sw,gh,gw;
vector<vector<char>> field;
vector<vector<int>> depth;

queue<P> que;
queue<P> magicQue;

int magicNum=0;

void walkAround(){
    // cout << "call walkAround" << endl;
    while(!que.empty()){
        P q = que.front(); que.pop();
        int nh,nw;
        int dep = depth.at(q.first).at(q.second);
        for(P d : dir){
            nh = q.first + d.first;
            nw = q.second + d.second;
            // cout << "\th: " << nh << "\tw: " << nw << endl;

            if(0<=nh && nh<H && 0<=nw && nw<W && field.at(nh).at(nw) == '.' &&
            depth.at(nh).at(nw) > dep){
                que.push(P(nh,nw));
                magicQue.push(P(nh,nw));
                depth.at(nh).at(nw) = dep; 

                // cout << "\th: " << nh << "\tw: " << nw << "\tadd que" << endl; 
            }
        }
    }
}

void useMagic(){
    // cout << "call useMagic" << endl;
    queue<P> tmpQue;
    while(!magicQue.empty()){
        P q = magicQue.front(); magicQue.pop();
        int h=q.first;
        int w=q.second;
        int dep = depth.at(h).at(w);
        for(int dh : area){
            for(int dw : area){
                if(0<=h+dh && h+dh<H && 0<=w+dw && w+dw<W && field.at(h+dh).at(w+dw) == '.' 
                && depth.at(h+dh).at(w+dw) > dep){
                    tmpQue.push(P(h+dh,w+dw));

                    depth.at(h+dh).at(w+dw) = dep+1;
                    // cout << "h: " << h+dh << "\tw: " << w+dw << "\tadd magicQue" << endl;
                }
            }
        }
    }

    while(!tmpQue.empty()){
        P q = tmpQue.front(); tmpQue.pop();
        que.push(q);
        magicQue.push(q);
    }
}

void showDepth(){
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            string s;
            if(depth.at(i).at(j) == INF)s = "INF";
            else s = to_string(depth.at(i).at(j));
            cout << setw(4) << s << " ";
        }
        cout << endl;
    }
}

int main(){
    // cout << "start init" << endl;
    cin >> H >> W;
    cin >> sh >> sw >> gh >> gw;
    sh--; sw--; gh--; gw--;
    
    field = vector<vector<char>>(H,vector<char>(W));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++)cin >> field.at(i).at(j);
    }
    depth = vector<vector<int>>(H, vector<int>(W, INF));

    que.push(P(sh,sw));
    magicQue.push(P(sh,sw));
    depth.at(sh).at(sw) = 0;

    // cout << "end init" << endl;

    while(!que.empty() || !magicQue.empty()){
        walkAround();
        if(depth.at(gh).at(gw) != INF){
            cout << depth.at(gh).at(gw) << endl;
            return 0;
        }

        useMagic();
        // cout << endl;
        // showDepth();
    }
    
    cout << -1 << endl;
}

Measured memory_bytes: 8864
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

std::string ab("AB");

int count_ab(const std::string& st) {
    int ret{0};
    std::size_t pos = st.find(ab);
    while (pos != std::string::npos) {
        ++ret;
        pos = st.find(ab, pos + ab.length());
    }
    return ret;
}

int main(int argc, char** argv) {
    int64_t n, ans{0};
    cin >> n;
    for (int64_t i = 1; i < floor(sqrt(n))+1; ++i) {
        if (n % i == 0) {
            if ((n/i-1) > i)
                ans += (n/i -1);
            else
                break;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int a[101];

float avg(int * a, int n)	{
	float mean = 0;
  	for (int i = 0; i < n; i++)	{
    	mean += a[i];
    }
  	mean /= n;
  	return mean;
}

int main()	{
  	int n;
  	cin >> n;
  	int int_mean = 0;
  	for (int i = 0; i < n; i++)	{
    	cin >> a[i];
    }
  	float mean = avg(a, n);
  	if (mean < 0)	{
    	int_mean = mean - 0.5;
    }
  	else	{
    	int_mean = mean + 0.5;
    }
  	long long result = 0;
  	for (int i = 0; i < n; i++)	{
    	result += (a[i] - int_mean) * (a[i] - int_mean);
    }
  	cout << result << endl;
  	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sq(a) ((a)*(a))
using namespace std;
typedef long long int ll;
typedef long double llf;

int main()
{
    ll x;cin>>x;
    if(x%2==0) {cout<<"-1"<<endl; return 0;}
    ll mm=0,c=0,ans=0;
    while(1)
    {
        mm=mm*10+7;
        c++;
        if(c>10000000) break;
        if(mm%x==0)
        {
            break;
        }
        mm=mm%x;
    }
    if(c<=10000000) cout<<c<<endl;
    else cout<<"-1"<<endl;
    return 0;
}



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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    string S;
    cin >> S;
    if(S=="AAA"||S=="BBB"){
    	cout << "No" << endl;
    }else{
    	cout << "Yes" << endl;	
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



int n, res;
vector<ll> d;

// 約数全列挙 O(√N)
void divs(ll n) {
    for (ll i = 1; i*i <= n; ++i) {
        if (n%i==0) {
            d.push_back(i);
            if (i!=n/i) d.push_back(n/i);
        }
    }
}

signed main() {
    cin >> n;
    divs(n);
    each(i,d) {
        int m = i-1;
        if (m==0) continue;
        if ((n/m) == (n%m)) res += m;
    }
    cout << res << endl;
}


Measured memory_bytes: 384
#include <stdio.h>

int main() {
    int N;
    scanf("%d", &N);

    int n, i, j, tmp, count=1, max_count=0;
    n = N/1000;
    // printf("%d\n", N);
    N -= n*1000;
    // printf("%d\n", N);
    for(i=2; i>=0; i--) {
        tmp = 1;
        for(j=0; j<i; j++) {
            tmp *= 10;
        }
        if(n == N/tmp) {
            count += 1;
            if(max_count<count) max_count = count;
        } else {
            n = N/tmp;
            count = 1;
            if(max_count<count) max_count = count;
        }
        N -= n*tmp;
        // printf("%d %d\n", N, max_count);
    }

    if(max_count>=3) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
    
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}



int main() {
	int n,flag;
	while(1){
		cin >> n;
		if (n == 0) break;
		int ans = 0;
		string str,str2;
		vector<string> v(n);
		cin >> str;
		v[0]=str;
		for (int i = 1; i < n;i++) {
			cin >> v[i];
			str = v[i];
			str2 = v[i - 1];
			if (str[0] != str2[0] && str[1] == str2[1]) {
				ans++;
			}
		}
		cout << ans << endl;
	}
}



Measured memory_bytes: 3168
#include <iostream>
#include <cmath>
#include <string>
#include <string.h>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>

using namespace std;

int main(){
  char w[11],t[1001],*p;
  int count=0;

  scanf("%s\n",w);

  while(1){
      scanf("%s\n",t);
      if(strcmp(t,"END_OF_TEXT")==0){
        printf("%d\n",count);
        return 0;
      }

      p = t;
      if(strcasecmp(p,w)==0) {
        count++;
      }
  }


}


Measured memory_bytes: 3224
PROGRAM stringsWith
      IMPLICIT NONE
      character(100) :: s,t
      character(200) :: ans
      integer :: n
      integer :: i,c1=1,c2=1
      
      read*,n
      read*,s,t
      
      do i = 1,2*n
        if( mod(i,2)==1 )then
          ans(i:i) = s(c1:c1)
          c1 = c1 + 1
        else
          ans(i:i) = t(c2:c2)
          c2 = c2 + 1
        end if
      end do
      
      print*,ans(1:2*n)
      
      
      
      
      END PROGRAM

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

using namespace std;

#define DIM 100007
#define DIMM 2007
#define INF 10000000000007.0
#define X 2000000007
#define epc 0.0000001
#define PI 3.14159265358979323846
#define MAX 25
#define MODULO 10009
const long double gr=(1+sqrt(5))/2;

typedef int I;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<I,I> pII;
typedef pair<ll,ll> pllll;
typedef pair<ld,ld> pldld;
typedef pair<ll,pllll> pllpllll;

typedef vector<I> vI;
typedef vector<ll> vll;
typedef vector<pllll> vpllll;

typedef char cr;
typedef string str;

ll a,b,res;
ll f(ll z){
   if(z%4==0)return z;
   if(z%4==1)return 1;
   if(z%4==2)return (z+1);
   return 0;
}

int main()
{
    //freopen("events.in", "r", stdin);
    //freopen("events.out", "w", stdout);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //cout<<"ops"<<endl;

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    //ll x1,y1,xs,ys,x2,y2,x3,x4,y3,y4;

    cin>>a>>b;
    res=f(a-1)^f(b);
    cout<<res<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    int ans = 0;
    for(int a = 1; a <= n; a++){
        for(int b = 1; a*b <= n; b++){
            if(n - a*b > 0) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
int max(int x, int y) {
	return x > y ? x : y;
}
int cmpint(const void *x, const void *y) {
	return *(int *)y - *(int *)x;
}
int main() {
	int n, v, EvenNumCnt[100000] = {0}, OddNumCnt[100000] = {0};
	int OddMax = 0, EvenMax = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &v);
		if (i % 2 == 1) {
			OddNumCnt[v - 1]++;
		} else {
			EvenNumCnt[v - 1]++;
		}
	}
	int OddMaxNum, EvenMaxNum;
	for (int i = 0; i < 1e5; i++) {
		if (OddMax < OddNumCnt[i]) {
			OddMax = OddNumCnt[i];
			OddMaxNum = i + 1;
		}
	}
	for (int i = 0; i < 1e5; i++) {
		if (EvenMax < EvenNumCnt[i]) {
			EvenMax = EvenNumCnt[i];
			EvenMaxNum = i + 1;
		}
	}
	if (OddMaxNum == EvenMaxNum) {
		qsort(OddNumCnt, n, sizeof(int), cmpint);
		qsort(EvenNumCnt, n, sizeof(int), cmpint);
		OddMax = max(OddNumCnt[1], EvenNumCnt[1]);
	}
	printf("%d\n", n / 2 - OddMax + n / 2 - EvenMax);
	return 0;
}

Measured memory_bytes: 1276
s = gets.chomp

a=s[0..1].to_i

b=s[2..3].to_i



if([a,b].include?(0)) then
  if( (a==0&&b==0)|| (a==0&&b>12) || (b==0&&a>12) ) then
    puts "NA"
  else
    if(b==0) then 
      puts "MMYY"
    elsif(a==0) then
      puts "YYMM"
    end
  end
elsif (a>12||b>12) then 
  if(a>12&&b>12)then
    puts "NA"
  else 
    if(a<=12) then 
      puts "MMYY"
    elsif(b<=12)then
      puts "YYMM"
    end
  end
else
  puts "AMBIGUOUS"
end




Measured memory_bytes: 1788
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(void){
    int num;
    cin>>num;
    int X[num];
    int Y[num];
    double sum=0;
    double max=0;
    for(int i=0;i<num;i++){
        cin>>X[i];
    }
    for(int i=0;i<num;i++){
        cin>>Y[i];
    }
    
    for(int i=0;i<num;i++){
        if(0>X[i]-Y[i])sum-=(X[i]-Y[i]);
        else sum+=(X[i]-Y[i]);
    }
    cout<<fixed<<setprecision(6)<<sum<<endl;
    sum=0;
    
    for(int i=0;i<num;i++){
        sum+=pow((X[i]-Y[i]),2);
    }
    cout<<fixed<<setprecision(6)<<pow(sum,1.0/2.0)<<endl;
    sum=0;
    
    for(int i=0;i<num;i++){
        if(0>X[i]-Y[i])sum-=pow((X[i]-Y[i]),3.0);
        else sum+=pow((X[i]-Y[i]),3.0);
    }
    cout<<fixed<<setprecision(6)<<pow(sum,(1.0/3.0))<<endl;
    sum=0;
    max=0;
    for(int i=0;i<num;i++){
        if(0>X[i]-Y[i])sum=-(X[i]-Y[i]);
        else sum=X[i]-Y[i];
        if(max<sum)max=sum;
    }
    cout<<fixed<<setprecision(6)<<max<<endl;
    
    return 0;
}



Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define sd(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define pl(n) printf("%lld",n)
#define sf(n) scanf("%f",&n)
#define pf(n) printf("%.12f",n)
#define psp printf(" ")
#define endc printf("\n")

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

const int maxn = 5e5 + 7; 
//const int md = 1e9 + 7;

int dp[maxn];
int last[maxn];

int solve(string s) {
	if (s.size() < 3) return 0;
	int j = -1;
	for (int i = 0; i < s.size(); i++) {
		last[i] = j;
		if (s[i] == '0') j = i;
	}
	dp[0] = 0; dp[1] = 0;
	for (int i = 2; i < s.size(); i++) {
		dp[i] = dp[i-1];
		if (s[i] == '0') continue;
		if (s[i-1] == '0') {
			int p = last[i-1];
			dp[i] = max(dp[i], dp[p+1] + i - p - 3);
			dp[i] = max(dp[i], ((p >= 0) ? dp[p] : 0) + i-p-2);
		}
		if (s[i-1] == '1' && last[i] > 0) {
			int p = last[i];
			dp[i] = max(dp[i], ( ((p-2)>=0) ? dp[p-2] : 0 ) + i - p);
		}
		//cout<<i<<" : "<<dp[i]<<endl;
	}
	//cout<<s<<" : "<<dp[s.size()-1]<<endl;
	return dp[s.size()-1];
}

int main() {
	IOS;;
	int n; cin>>n; int ans = 0;
	string s;cin>>s;
	string a = ""; int i = 0; while (s[i] == '0') i++;
	while (i < s.size()) {
		if (s[i] == '0' && i + 1 < s.size() && s[i+1] == '0') {
			ans += solve(a);
			while (s[i] == '0') i++;
			a = "";
		}
		a += s[i];
		i++;
	}
	if (a.size() > 0) {
		if (a[a.size()-1] == '0') a = a.substr(0, a.size()-1);
		ans += solve(a);
	}
	cout<<ans<<endl;
}

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

#define INF 1<<29

int main(){

  int n,m;
  int d[1111];
  int c[1111];
  int memo[1111][1111]={{0}};
  int mi=INF;
  //memo[n][m]

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

  for(int i=0;i<n;i++){
    scanf("%d",&d[i+1]);
  }

  for(int i=0;i<m;i++){
    scanf("%d",&c[i+1]);
  }

  for(int i=0;i<=n;i++){
    mi=INF;
    for(int j=0;j<=m;j++){
      
      if(i>0 && j>=i) mi=min(mi,memo[i-1][j-1]);
      
      if(i==0) memo[i][j]=0;
      else if(j<i) memo[i][j]=INF;
      else{
	memo[i][j]=mi+(d[i]*c[j]);
      }


      // printf("%d ",memo[i][j]);
    }
    //printf("\n");
  }

  mi=INF;
  for(int i=1;i<=m;i++){
    mi=min(mi,memo[n][i]);
  }

  printf("%d\n",mi);

  return 0;
}

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

int main(){
	int n, l; cin >> n >> l;
	int a, b; cin >> a;
	for(int i = 1; i < n; ++i){
		cin >> b;
		if(a + b >= l){
			cout << "Possible\n";
			for(int j = 1; j < i; ++j) cout << j << endl;
			for(int j = n - 1; j > i; --j) cout << j << endl;
			cout << i << endl;
			return 0;
		}
		a = b;
	}
	cout << "Impossible\n";
	return 0;
}

Measured memory_bytes: 896
X = int(input())

if 400<=X<=599:
  print(8)
elif 600<=X<=799:
  print(7)
elif 800<=X<=999:
  print(6)
elif 1000<=X<=1199:
  print(5)
elif 1200<=X<=1399:
  print(4)
elif 1400<=X<=1599:
  print(3)
elif 1600<=X<=1799:
  print(2)
elif 1800<=X<=1999:
  print(1)



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

int main() {
  int a,b,k;
  cin >> a >> b;
  if((a+b)%2==0){
    k = (a+b)/2;
    cout << k;
  }
  else{
    cout << "IMPOSSIBLE";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9+7LL;
 
int main() {
    ll N, X, M; cin >> N >> X >> M;
    ll f = X;
    ll ans = 0;
    map<ll, ll> m;
    vector<ll> sum(2*M+1);
    sum.at(0) = X;
    m[X] = 0;
    bool flag = false;
 
    rep(i, N){
        if(i==0) continue;
        f = f*f % M;
        sum.at(i) = sum.at(i-1) + f;
 
        if(m.count(f)){
            flag = true;
            ll x = i - m[f];
            ll tmp = sum.at(i) - sum.at(m[f]);

            ll a = 0;
            if(m[f]!=0) a = sum.at(m[f]-1);
            ll b = tmp * ((N-m[f])/x);
            ll c = 0;
            if((N-m[f])%x!=0){
                c = sum.at((N-m[f])%x + m[f]-1);
                if(m[f]!=0) c -= sum.at(m[f]-1);
            }
            ans = a + b + c;
            break;
        }
        else m[f] = i;
    }
    if(!flag) ans = sum.at(N-1);
    cout << ans << endl;
}

Measured memory_bytes: 7872
#BFS
from collections import deque
def bfs(i,j):
    q=deque()
    q.append((i,j))
    log=[[-1]*w for i in range(h)]
    log[i][j]=0
    dx=[0,1,0,-1]
    dy=[1,0,-1,0]
    long=0
    while q:
        #qの先頭を取り出す
        p=q.popleft()
        for i in range(4):
            nx=p[0]+dx[i]
            ny=p[1]+dy[i]

            if not(0<=nx<h and 0<=ny<w):continue
            if maze[nx][ny]=='#':continue
            if log[nx][ny]!=-1:continue
            log[nx][ny]=log[p[0]][p[1]]+1
            q.append((nx,ny))
            if long<=log[nx][ny]:long=log[nx][ny]
    return long

h,w=map(int,input().split())
maze=[list(input()) for i in range(h)]

ans=0
for i in range(h):
    for j in range(w):
        if maze[i][j]=='.':
            temp=bfs(i,j)
            if ans<temp:ans=temp
print(ans)

Measured memory_bytes: 3316
h, w = map(int, input().split())
a=[input() for i in range(h)]
ver=[False]*w
hor=[False]*h

for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            ver[j]=True
            hor[i]=True

for i in range(h):
    if hor[i]:
        for j in range(w):
            if ver[j]==True:
                print(a[i][j],end="")
        print()

Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using P = pair<int, int>;

signed main() {

    string s, t;
    cin >> s >> t;

    if(s == t.substr(0, s.length())){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3572
#include<iostream>
#include<complex>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define repn(i, m, n) for (int i = m; i < int(n); ++i)

#define X real()
#define Y imag()

typedef complex<double> P;
typedef pair<P, P> L;
typedef vector<P> Pol;

const double INF = 1e40;
const double EPS = 1e-8;
const double PI = acos(-1);

int sig(double r) {return (r < -EPS) ? -1 : (r > EPS) ? 1: 0;}
bool eq(double a, double b) {return abs(a - b) < EPS;}

// ツ外ツ静?
double cross(P a, P b) {return a.X * b.Y - a.Y * b.X;}
// ツ静シツ閉ェツづ個ベツクツトツδ?
P vec(L a) {return a.second - a.first;}
// ツ角ツ度
double ang(P p) {double theta = arg(p); return sig(theta - 2 * PI) < 0 ? theta : 0;}
P dv(double theta) {return polar(1., theta);}
// ツ古ーツ債キツ板サツ津ィ ツ端ツ点ツづーツ甘慊づ?
bool iLS(L a, L b) {return sig(cross(vec(a), b.first - a.first)) * sig(cross(vec(a), b.second - a.first)) < 0;}
// ツ古ーツ点
P pLL(L a, L b) {return a.first + vec(a) * (cross(vec(b), b.first - a.first) / cross(vec(b), vec(a)));}

int main() {
  int w, h ,n;
  for (;;) {
    cin >> w >> h >> n;
    if (w == 0 && h == 0 && n == 0) break;
    vector<P> vp;
    rep (i, 2 * n) {
      double x, y;
      cin >> x >> y;
      vp.push_back(P(x, y));
    }
    vector<double> yy;
    yy.push_back(0);
    yy.push_back(h);
    L base = L(0, P(0, h));
    rep (i, 2 * n) repn (j, i + 1, 2 * n) {
      if (iLS(L(vp[i], vp[j]), base)) yy.push_back(pLL(L(vp[i], vp[j]), base).Y);
    }
    rep (i, 2 * n) {
      if (iLS(L(vp[i], P(w, 0)), base)) yy.push_back(pLL(L(vp[i], P(w, 0)), base).Y);
      if (iLS(L(vp[i], P(w, h)), base)) yy.push_back(pLL(L(vp[i], P(w, h)), base).Y);
    }
    sort(yy.begin(), yy.end());
    double res = 0;
    rep (i, yy.size() - 1) {
      P mp = P(0, (yy[i] + yy[i + 1]) / 2);
      vector<double> vpp;
      rep (j, 2 * n) vpp.push_back(ang(vp[j] - mp));
      sort(vpp.begin(), vpp.end());
      P p1, p2;
      double ang1, ang2, ang3, ang4;
      ang1 = vpp[n - 1];
      ang2 = vpp[n];
      ang3 = ang(P(w, 0) - mp);
      ang4 = ang(P(w, h) - mp);
      if (ang1 < ang3) {
	p1 = P(w, 0);
      } else if (ang1 > ang4) {
	p1 = P(w, h);
      } else {
	p1 = pLL(L(P(w, 0), P(w, h)), L(mp, dv(vpp[n - 1]) + mp));
      }
      if (ang2 < ang3) {
	p2 = P(w, 0);
      } else if (ang2 > ang4) {
	p2 = P(w, h);
      } else {
	p2 = pLL(L(P(w, 0), P(w, h)), L(mp, dv(vpp[n]) + mp));
      }
      res += (yy[i + 1] - yy[i]) * (p2.Y - p1.Y);
    }
    res /= h * h;
    printf("%.12lf\n", res);
  }
}

Measured memory_bytes: 1212
#include <stdio.h>
int main(void){
    int card[4][14] ;
    int n , no , i , j ;
    char e , d ;
    
    for(i = 0 ; i < 4 ; i++){
        for(j = 0 ; j < 14 ; j++){
            card[i][j] = 0;
        }
    }
    
    scanf("%d" , &n);
    for(i = 0 ; i < n ; i++){
        scanf("%c" , &d);
        scanf("%c %d" , &e , &no);
        if(e == 'S'){
            card[0][no] = 1;
        }
        else if(e == 'H'){
            card[1][no] = 1;
        }
        else if(e == 'C'){
            card[2][no] = 1;
        }
        else if(e == 'D'){
            card[3][no] = 1;
        }
    }
    
    for(j = 1 ; j < 14 ; j++){
        if(card[0][j] != 1){
            printf("S %d\n" , j);
        }
    }
    
    for(j = 1 ; j < 14 ; j++){
        if(card[1][j] != 1){
            printf("H %d\n" , j);
        }
    }
    for(j = 1 ; j < 14 ; j++){
        if(card[2][j] != 1){
            printf("C %d\n" , j);
        }
    }
    for(j = 1 ; j < 14 ; j++){
        if(card[3][j] != 1){
            printf("D %d\n" , j);
        }
    }
    return 0;
}


Measured memory_bytes: 2088
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Rect {
    int x, y;

    Rect() {}
    Rect(int x, int y) : x(x), y(y) {}
};

int main() {
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        vector<Rect> v;
        v.push_back(Rect(0, 0));
        
        int dt[][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
        while(--N) {
            int n, d;
            cin >> n >> d;
            Rect r = v[n];
            r.x += dt[d][0];
            r.y += dt[d][1];
            v.push_back(r);
        }
        int l, r, t, b;
        l = t = N;
        r = b = 0;
        for(int i = 0; i < v.size(); ++i) {
            const Rect &rc = v[i];
            l = min(l, rc.x); r = max(r, rc.x);
            t = min(t, rc.y); b = max(b, rc.y);
        }
        cout << (r-l+1) << ' ' << (b-t+1) << endl;
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int e;
    vector<int> ans;
    while(true){
        int res = mod;
        cin >> e;
        if(e == 0) break;
        int z_loop = 0;
        int y_loop = sqrt(e) + 1;
        int temp;
        while(z_loop*z_loop*z_loop <= e) z_loop++;
        for(int z = 0; z <= z_loop; z++){
            temp = z*z*z;
            for(int y = 0; y <= y_loop; y++){
                int x = e - temp - y*y;
                if(x >= 0) res = min(res, x+y+z);
            }
        }
        ans.push_back(res);
    }
    rep(i, ans.size()) cout << ans[i] << endl;
    return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

int main(void) {
    int a, b;
    bool flg = false;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b;
    FOR(c, 1, 3 + 1) {
        if ((a * b * c) % 2) {
            flg = true;
        }
    }

    cout << (flg? "Yes" : "No") << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#define MAXN 100500
using namespace std;
int n, m;
int dist[MAXN];
vector <int> g[MAXN];
bool was[MAXN];
int ans;


void dfs(int v){
     //cout << v << ' ';
     was[v] = true;
     for (int w:g[v]){
         if (!was[w]) dfs(w);
         if (dist[v] < dist[w]+1) dist[v] = dist[w] + 1;
         if (ans < dist[v]) ans = dist[v];
     }

}

int x, y;
int main(){
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        cin >> x >> y;
        g[x].push_back(y);
    }
    for (int i = 1; i <= n; i++){
        if (!was[i]){
           dfs(i);
           //cout << endl;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  for (int i = n - 1; i >= 0; i -= 2) {
    if (i != n - 1) cout << " ";
    cout << a[i];
  }
  if (n & 1) {
    for (int i = 1; i < n; i += 2) {
      cout << " " << a[i];
    }
  }
  else {
    for (int i = 0; i < n; i += 2) {
      cout << " " << a[i];
    }
  }
  cout << endl;



  
  return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#define PRE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
const int Mod = 1e9 + 7;
int lst[Max], f[Max];
int ls[Max];

int main()
{
	PRE;
	string str, st;
	cin >> str >> st;
	int n = st.size(), k = -1;
	for (int i = str.size() - n;i >= 0;i--)
	{
		int f = 1;int g = -1;
		for (int j = i;j < i + n;j++)
		{
			++g;
			if (!(str[j] == '?' || str[j] == st[g])) f = 0;
		}
		if (f)
		{
			k = i;break;
		}
	}
	if (k == -1)cout << "UNRESTORABLE";
	else
	{
		for (int i = 0;i <= k - 1;i++)
		{
			if (str[i] == '?')cout << 'a';
			else cout << str[i];
		}
		cout << st;
		for(int i=k+n;i<str.size();i++)
		{
			if (str[i] == '?')cout << 'a';
			else cout << str[i];
		}
	}
}

Measured memory_bytes: 3040
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <set>
#include <set>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <ctime>
#include <cmath>
#include <sstream>
#include <cstdlib>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
ll qpow(ll a, ll b){
	ll res = 1;
	while (b) {
		if(b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}
ll inv[maxn];
int main() {
	inv[1] = 1;
	for (int i = 2; i < maxn; i++) inv[i] = qpow(i, mod - 2);
	int n, a, b;
	cin >> n >> a >> b;
	ll ans = qpow(2, n) - 1;
	ll c1 = 1, c2 = 1;
	for (int i = n; i > n - a; i--) {
		c1 = c1 * i % mod;
	}
	for (int i = 1; i <= a; i++) {
		c1 = c1 * inv[i] % mod;
	}
	for (int i = n; i > n - b; i--) {
		c2 = c2 * i % mod;
	}
	for (int i = 1; i <= b; i++) {
		c2 = c2 * inv[i] % mod;
	}
	ans = ((ans - c1 - c2) % mod + mod) % mod;
	cout << ans << endl;
}


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

main()
{
	int n;
	string s;
	
	cin>>n>>s;
	
	vector<vector<ll>> dp(n+1,vector<ll> (n+1));
	dp[1][1]=1;
	
	for(int len=2;len<=n;len++)
	{
		vector<ll> pre(len);
		for(int i=1;i<len;i++)
		pre[i]=(pre[i-1]+dp[len-1][i])%MOD;
		
		/*for(int i=1;i<=len;i++)
		{
			for(int j=1;j<=len;j++)
			{
				if(i!=j)
				{
					if((i<j)==(s[len-2]=='<'))
					{
						if(i>j)
						dp[len][i]=(dp[len][i]+dp[len-1][j])%MOD;
						else
						dp[len][i]=(dp[len][i]+dp[len-1][j-1])%MOD;
					}
				}
			}
		}*/
		
		if(s[len-2]=='<')
		{
			for(int i=1;i<=len;i++)
			dp[len][i]=(dp[len][i]+pre[len-1]-pre[i-1]+MOD)%MOD;
		}
		else
		{
			for(int i=1;i<=len;i++)
			dp[len][i]=(dp[len][i]+pre[i-1])%MOD;
		}
	}
	
	ll ans=0;
	
	for(int i=1;i<=n;i++)
	{
		ans=(ans+dp[n][i])%MOD;
	}
	
	cout<<ans;
}

Measured memory_bytes: 70784
// ABC168D
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i, c) for(long long i=0; i<(long long)c; i++)
const int INF=1001001001;
vector<int> to[100005];
int main() {
	int n,m;

	cin>>n>>m;
	rep(i,m){
		int a,b;
		cin >>a>>b;
		--a;--b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	queue<int>q;
	vector<int>dist(n,INF);
	vector<int>pre(n,-1);
	dist[0]=0;
	q.push(0);
	while (!q.empty()){
		int v=q.front();q.pop();
		for (int u:to[v]){
			if (dist[u] !=INF) continue;
			dist[u]=dist[v]+1;
			pre[u]=v;
			q.push(u);
		}
	}
	cout << "Yes" << endl;
	rep(i,n){
		if (i==0) continue;
		int ans=pre[i];
		++ans;
		cout <<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 10732
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <map>
#define mp make_pair
#define N 200005
using namespace std;
typedef long long ll;
const int inf=1e9+1e6;
const int mod=1e9+7;
map<pair<int,int>,int> m; 
struct P{
	int c,w,id;
	P(){}
	P(int a,int b,int q){c=a;w=b;id=q;}
}a[N];
bool operator <(P a,P b){
	if(a.w!=b.w) return a.w>b.w;
	return a.id>b.id;
}
bool cmp(P a,P b){
	return a.id<b.id;
}
int n,x,y,fa[N],sum[N],s[N],top;
ll f[N],inv[N];
priority_queue<P> q[N]; 
int find(int k){
	if(fa[k]!=k) fa[k]=find(fa[k]);
	return fa[k];
}
ll quick_pow(ll a,ll b){
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1) ans=ans*a%mod;
	return ans;
}
ll C(ll n,ll m){
	return f[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
	//freopen("test.in","r",stdin);
	scanf("%d%d%d",&n,&x,&y);
	f[0]=inv[0]=1;
	for(int i=1;i<=n;i++){
		f[i]=f[i-1]*i%mod;
		inv[i]=quick_pow(f[i],mod-2);
		scanf("%d%d",&a[i].c,&a[i].w);
		a[i].id=i;
		fa[i]=i;
	}
	for(int i=1;i<=n;i++) q[i].push(P(i,inf,n+1)),q[0].push(P(i,inf,n+1));
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		P now=q[0].top(),pre,mn=P(0,inf,0);int f1,f2;
		int bug=0;
		top=0;
		while(now.w+a[i].w<=y){
			if(now.id!=q[now.c].top().id){
				q[0].pop();now=q[0].top();continue;
			}
			int S=y;bug++;
			if(now.c==a[i].c) S=-inf;
			while(q[now.c].top().w+a[i].w<=S){
				pre=q[now.c].top();q[now.c].pop();
				f1=find(pre.id);f2=find(a[i].id);
				fa[f1]=f2;
				if(pre.w<mn.w&&pre.c!=a[i].c) mn=pre;
			}
			s[++top]=now.c;
			q[0].pop();now=q[0].top();
		}
		now=q[a[i].c].top();
		while(now.w+a[i].w<=x){
			f1=find(now.id);f2=find(a[i].id);
			fa[f1]=f2;
			q[a[i].c].pop();
			now=q[a[i].c].top();
		} 
		q[a[i].c].push(a[i]);
		if(mn.c) q[mn.c].push(mn);
		bool T=0;
		for(int p=1;p<=top;p++){
			q[0].push(q[s[p]].top());
			if(s[p]==a[i].c) T=1;
		}
		if(!T) q[0].push(q[a[i].c].top());
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++){
		sum[find(i)]++;
		if(m.find(mp(fa[i],a[i].c))==m.end()) m[mp(fa[i],a[i].c)]=0;
		m[mp(fa[i],a[i].c)]++;
	}
	ll ans=1;
	for(int i=1;i<=n;i++){
		int g=m[mp(fa[i],a[i].c)];m[mp(fa[i],a[i].c)]=0;
		ans=ans*C(sum[fa[i]],g)%mod;
		sum[fa[i]]-=g;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 41516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n;

struct TREE {
	int ys[200010], yn;
	int t[200010];
	void clear(){ yn = 0; for(int i=1; i<=n; ++i) t[i]=0; }
	void put(int x){ ys[yn++] = x; }
	void init(){ sort(ys, ys+yn); }
	void add(int x){
		int p=lower_bound(ys, ys+yn, x)-ys+1;
		while(p<=yn) ++t[p], p+=(p&-p);
	}
	int S(int x){ int ret=0; while(x>0) ret+=t[x], x&=(x-1); return ret; }
	int range(int l, int r){
		if(l>r) return 0;
		r=upper_bound(ys, ys+yn, r)-ys;
		l=lower_bound(ys, ys+yn, l)-ys;
		return S(r)-S(l);
	}
} tr[2];

int a[200010];
int b[200010];

int main()
{
	read(n);
	for(int i=1; i<=n; ++i) read(a[i]);
	for(int i=1; i<=n; ++i) read(b[i]);
	int ans = 0;
	for(int bt=0; bt<=28; ++bt){
		int bv = (1<<bt);
		for(int i=0; i<2; ++i) tr[i].clear();
		for(int i=1; i<=n; ++i) tr[1&(a[i]>>bt)].put(a[i]&(bv-1));
		for(int i=0; i<2; ++i) tr[i].init();
		for(int i=1; i<=n; ++i) tr[1&(a[i]>>bt)].add(a[i]&(bv-1));
		int cp=0;
		for(int i=1; i<=n; ++i){
			if(1&(b[i]>>bt)){
				cp += tr[0].range(0, bv-(b[i]&(bv-1))-1);
				cp += tr[1].range(bv-(b[i]&(bv-1)), bv-1);
			} else {
				cp += tr[1].range(0, bv-(b[i]&(bv-1))-1);
				cp += tr[0].range(bv-(b[i]&(bv-1)), bv-1);
			}
		}
		if(cp&1) ans |= bv;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 4992