akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<stack>
using namespace std;

enum Status {WHITE, GRAY, BLACK};

stack<int> stc;
Status *status;
int *discovered, *finished;
bool *visited;
vector<vector<int> > a;
int n, timer;

void dfs(int i){
        if(status[i]==BLACK) return;
        if(status[i]==WHITE){
                discovered[i] = ++timer;
                status[i] = GRAY;
        }

        if(visited[i]) return;
        visited[i] = true;
        stc.push(i);

        for(int j=0;j<a[i].size();j++) dfs(a[i][j]);

        if(status[i]==GRAY){
                finished[i] = ++timer;
                status[i] = BLACK;
        }
        stc.pop();
}

int main(){

        cin>>n;
        a = vector<vector<int> >(n, vector<int>());
        status = new Status[n];
        discovered = new int[n];
        finished = new int[n];
        visited = new bool[n];

        int m, k, r;
        for(int i=0;i<n;i++){
                cin>>r;
                cin>>m;
                for(int j=0;j<m;j++){
                        cin>>k;
                        a[r-1].emplace_back(k-1);
                }
        }
        for(int i=0;i<n;i++) status[i] = WHITE;
        for(int i=0;i<n;i++) visited[i] = false;

        timer = 0;
        for(int i=0;i<n;i++)
                dfs(i);

        for(int i=0;i<n;i++){
                cout<<i+1<<" "<<discovered[i]<<" "<<finished[i]<<endl;
        }
        return 0;
}




Measured memory_bytes: 3164
#include <iostream>

using namespace std;

typedef long long ll;

#define all(x) (x).begin(), (x).end()
#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(str) printf(#str "\n")

//関数定義
//最大公約数
ll gcd(ll a, ll b);

//最小公倍数
ll lcm(ll a, ll b);

int main() {
  // ========================================================
  int a;
  cin >> a;
  cout << (a % 2 ? (a / 2 + 1) : a / 2) << endl;
}

//最大公約数
ll gcd(ll a, ll b) {
  if (!b) return a;
  return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

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

int main()

{
    int a;
    cin >> a;
    if(a/100<=12&&a/100>=1&&a%100<=12&&a%100>=1) cout << "AMBIGUOUS" << endl ;
    else if(a/100<=12&&a/100>=1)cout << "MMYY" << endl;
    else if(a%100<=12&&a%100>=1)cout << "YYMM" << endl;
    else cout << "NA"<< endl;
    return 0;
}


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

class UnionFind {
public:
    vector<int> par, rank;
    UnionFind(int n) : par(n), rank(n) { for(int i = 0; i < n; ++i) par[i] = i; }
    int root(int a) { return (par[a] == a) ? a : par[a] = root(par[a]); }
    bool isConnect(int a, int b) { return root(a) == root(b); }
    void connect(int a, int b) {
        a = root(a); b = root(b);
        if(a == b) return;
        if(rank[a] < rank[b]) par[a] = b;
        else if(rank[a] == rank[b]) par[b] = a, rank[a]++;
        else par[b] = a;
    };
};

int main() {
    int N, K, L;
    cin >> N >> K >> L;
    vector<vector<int>> G(N);
    for(int i = 0; i < K; ++i) {
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    UnionFind uf(N);
    for(int i = 0; i < L; ++i) {
        int a, b; cin >> a >> b;
        a--, b--;
        uf.connect(a, b);
    }
    vector<int> ans(N);
    vector<bool> visited(N);
    for(int i = 0; i < N; ++i) {
        map<int, vector<int>> ma;
        auto dfs = [&](auto &&dfs, int cur) -> void {
            visited[cur] = true;
            ma[uf.root(cur)].push_back(cur);
            for(auto &to : G[cur]) {
                if(visited[to]) continue;
                dfs(dfs, to);
            }
        };
        if(!visited[i]) dfs(dfs, i);
        for(auto &v : ma) for(auto &e : v.second) ans[e] = v.second.size();
    }
    for(auto &e : ans) cout << e << " ";
    cout << '\n';
    return 0;
}


Measured memory_bytes: 16008
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
   string s;    cin >> s;
   string left, right;
   int n;
   s.pop_back();
   int first_size = s.size();
   for (int i = first_size; i >= 2; i--){
       n = s.size();
       if (n % 2 != 0){
           s.pop_back();
           continue;
       }

       left = s.substr(0, n / 2);
       right = s.substr(n / 2, n - 1);
       if (left == right){
           cout << i << endl;
           return 0;
       }
       s.pop_back();
   }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define INF 1e18
#define pll pair<ll, ll> 
#define vll vector<ll>
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=1e5+11,mod=1e9+7;
inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
int getnode(int x,int y)
{
    return x*m+y;
}
vector<pll> v[1111111];
ll dis[1111111];
void bfs(int s)
{
    deque<int> q;
    q.push_back(s);
    while(!q.empty())
    {
        int f=q.front();
        q.pop_front();
        for (auto edge : v[f]) 
        {
        ll u = edge.first;
        ll w = edge.second;
        if (dis[f] + w < dis[u]) 
        {
            dis[u] = dis[f] + w;
            if (w == 1)
                q.push_back(u);
            else
                q.push_front(u);
        }
        }
    }
    return ;
}
void sol()
{
cin>>n>>m;
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
x1--,y1--,x2--,y2--;
string s[n];
for(int i=0;i<n;i++) cin>>s[i];
for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
    {
     dis[getnode(i,j)]=INF;
     if(s[i][j]=='#')
     continue;
     if(i!=0)
     {
         if(s[i-1][j]=='.')
         {
         v[getnode(i-1,j)].pb({getnode(i,j),0});
         v[getnode(i,j)].pb({getnode(i-1,j),0});
         }
     }
     if(j!=0)
     {
         if(s[i][j-1]=='.')
         {
         v[getnode(i,j-1)].pb({getnode(i,j),0});
         v[getnode(i,j)].pb({getnode(i,j-1),0});
         }
     }
     if(i!=n-1)
     {
         if(s[i+1][j]=='.')
         {
         v[getnode(i+1,j)].pb({getnode(i,j),0});
         v[getnode(i,j)].pb({getnode(i+1,j),0});
         }
     }
     if(j!=m-1)
     {
         if(s[i][j+1]=='.')
         {
         v[getnode(i,j+1)].pb({getnode(i,j),0});
         v[getnode(i,j)].pb({getnode(i,j+1),0});
         }
     }
     for(int ii=max(0,i-2);ii<=min(n-1,i+2);ii++)
     {
        for(int jj=max(0,j-2);jj<=min(m-1,j+2);jj++)
        {
         if(s[ii][jj]=='#')
         continue;
         v[getnode(i,j)].pb({getnode(ii,jj),1});
         v[getnode(ii,jj)].pb({getnode(i,j),1});
        } 
     }
    }
}
dis[getnode(x1,y1)]=0;
bfs(getnode(x1,y1));
if(dis[getnode(x2,y2)]>10000000)
cout<<-1;
else
cout<<dis[getnode(x2,y2)];
return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    for(int i=1;i<=test;i++)
    sol();
}


Measured memory_bytes: 371032
#define _USE_MATH_DEFINES
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
typedef long long int LL;
typedef pair<int,int> P;

int main() {
	double ans = 0;
	int n;
	cin >> n;
	double x;
	string u;
	for(int i = 0;i < n;i++) {
		cin >> x >> u;
		if(u=="BTC") x *= 380000.0;
		ans += x;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge{
    int to, cost;
};


// dijikstra
/* int V;
vector<edge> G[10];
int d[10];

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + V + 1, INF);
    d[s] = 0;
    que.push(P(0, s));

    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        REP(i, G[v].size()){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}
*/

int main(){
    ll n, T;
    vector<ll> t;
    cin >> n >> T;
    REP(i, n){
        ll tmp;
        cin >> tmp;
        t.pb(tmp);
    }
    SORT(t);
    ll ans = 0, before;
    REP(i, n){
        if(i == 0){
            before = t[0];
            ans += T;
        }else{
            if(before + T > t[i]){
                ans += T - (before + T - t[i]);
                before = t[i];
            }else{
                ans += T;
                before = t[i];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define endl '\n'
typedef pair <int, int> ii;
typedef vector <int> vi;

const int N = 1e5 + 1, inf = 1e7;
vi g[N];
int n, k, h[N], ans[N];
ii  L[N];
 
void dfs(int u, int p){
	for (int v : g[u]){
		if (v != p){
			h[v] = h[u] + 1;
			dfs(v, u);
		}
	}
}
 
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++){
		L[i] = ii(-inf,inf);
	}
	for (int i = 1; i < n; i++){
		int x, y;
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1, 0);
	queue <int> q;
	cin >> k;
	int m = -1;
	while (k--){
		int u, p;
		cin >> u >> p;
		L[u] = ii(p, p);
		q.push(u);
		int c = (p + h[u]) % 2;
		if (m == -1){
			m = c;
		}
		if (m != c){
			cout << "No";
			exit(0);
		}
	}
	while(q.size()){
		int u = q.front();
		q.pop();
		for (int v : g[u]){
			ii tmp = L[v];
			tmp.fi = max(tmp.fi, L[u].fi - 1);
			tmp.se = min(tmp.se, L[u].se + 1);
			if (tmp.fi > tmp.se){
				cout << "No";
				exit(0);
			}
			if (tmp != L[v]){
				L[v] = tmp;
				q.push(v);
			}
		}
	}
	cout << "Yes" << endl;
	for(int i = 1; i <= n; i++){
		cout << L[i].fi << endl;
		for (int u : g[i]){
			L[u] = ii(max(L[u].fi, L[i].fi - 1), min(L[u].se, L[i].fi + 1));
		}
	}
}

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

namespace
{
const int MAX_N	= 100;
const int MAX_T	= 20000;
int t[ MAX_N + 5 ];
int v[ MAX_N + 5 ];
int A[ MAX_T * 2 + 10 ];
int B[ MAX_T * 2 + 10 ];

}

int main( int argc, char *argv[] )
{
int i;
int j;
int N;
int T;
int iSumT;
int iLen;

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

	cin >> N;

	iSumT = 0;
	for( i = 0; i < N; i++ )
	{
		cin >> t[ i ];
		t[ i ] *= 2;
		iSumT += t[ i ];
	}

	for( i = 0; i < N; i++ )
	{
		cin >> v[ i ];
		v[ i ] *= 2;
	}

	j = 0;
	T = t[ j ];
	A[ 0 ] = 0;
	for( i = 1; i <= iSumT; i++ )
	{
		T--;
		A[ i ] = A[ i - 1 ] + 1;
		if( A[ i ] > v[ j ] ) A[ i ] = v[ j ];

		if( T <= 0 )
		{
			j++;
			T = t[ j ];
			if( A[ i ] > v[ j ] ) A[ i ] = v[ j ];
		}
	}

	j = N - 1;
	T = t[ j ];
	B[ iSumT ] = 0;
	for( i = iSumT - 1; i >= 0; i-- )
	{
		T--;
		B[ i ] = B[ i + 1 ] + 1;
		if( B[ i ] > v[ j ] ) B[ i ] = v[ j ];

		if( T <= 0 )
		{
			j--;
			T = t[ j ];
			if( B[ i ] > v[ j ] ) B[ i ] = v[ j ];
		}
	}

	iLen = 0;
	for( i = 1; i <= iSumT; i++ )
	{
		if( A[ i ] > B[ i ] ) A[ i ] = B[ i ];

		iLen += A[ i ];
	}

	i = iLen % 4;
	if( i == 0 )
		cout << iLen / 4 << endl;
	else if( i == 1 )
		cout << iLen / 4 << ".25" << endl;
	else if( i == 2 )
		cout << iLen / 4 << ".5" << endl;
	else if( i == 3 )
		cout << iLen / 4 << ".75" << endl;

	return 0;
}



Measured memory_bytes: 512
#include "bits/stdc++.h"

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define int ll
 int INF = 1e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
typedef pair<int, int> Vec2;
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int d[500][500];

const int MAX_N = 8;
bool used[MAX_N];
int perm[MAX_N];
bool G[MAX_N][MAX_N];
int ans = 0;

void permutation1(int pos, int n) {
	if (pos == n) {
		if (perm[0] != 0) return;
		rep(i, n-1) {
			int a = perm[i];
			int b = perm[i + 1];
			if (!G[a][b]) return;
		}
		ans++;
		return;
	}
	rep(i, n) {
		if (!used[i]) {
			perm[pos] = i;
			used[i] = true;
			permutation1(pos + 1, n);
			used[i] = false;
		}
	}
	return;
}

signed main() {
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >>  m;
	rep(i, MAX_N) {
		rep(j, MAX_N) G[i][j] = false;
	}
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		G[a][b] = true;
		G[b][a] = true;
	}
	rep(i,MAX_N) used[i] = false;
	permutation1(0,n);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __Mammamia__                ios_base :: sync_with_stdio(false);
#define ll                          long long
#define MAXN                        200007

int main ()
{
    __Mammamia__

    int n; cin >> n;
    map <string, int> Map;
    for (int i = 0; i < n; ++i)
    {
        string str; cin >> str;
        Map[str]++;
    }
    int Max = 0;
    for (auto it = Map.begin(); it != Map.end(); ++it)
    {
        Max = max(Max, it->second);
    }
    for (auto it = Map.begin(); it != Map.end(); ++it)
    {
        if (it->second == Max) cout << it->first << endl;
    }


    return 0;
}





Measured memory_bytes: 23808
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()

from collections import defaultdict
edges = defaultdict(set)
for i in range(M):
    u, v = nl()
    edges[u].add(v+N)
    edges[u+N].add(v+2*N)
    edges[u+2*N].add(v)

S, T = nl()

import queue
q = queue.Queue()
q.put((S, 0))

done = defaultdict(bool)
done[S] = True

while not q.empty():
    src, cost = q.get()
    for dst in edges[src]:
        if dst == T:
            print((cost+1) // 3)
            import sys
            sys.exit()

        if not done[dst]:
            done[dst] = True
            q.put((dst, cost+1))

print(-1)




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

using namespace std;

typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;

typedef pair<int, int> ii;

typedef vector<bool> vb;

int main( int argc, char *argv[] ) {
	int T;

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> T;
	int max, n, tmp;
	max = 0;
	n = 0;
	for ( int i = 0 ; i < T ; i++ ) {
		cin >> tmp;
		if ( tmp >= max ){
			max = tmp;
			n++;
		}
	}
	std::cout << n << std::endl;
}


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

int main() {
	string n;
	cin >> n;
	string a = n, b = n;
	while (true) {
		bool c = true;
		for (int i = 0; i < a.size() / 2; i++) {
			if (a[i] != a[a.size() - i - 1]) {
				c = false;
				break;
			}
		}
		if (c) {
			cout << a << endl;
			break;
		}
		c = true;
		for (int i = 0; i < b.size() / 2; i++) {
			if (b[i] != b[b.size() - i - 1]) {
				c = false;
				break;
			}
		}
		if (c) {
			cout << b << endl;
			break;
		}
		a = to_string(stoi(a) - 1);
		b = to_string(stoi(b) + 1);
	}
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long

const int MOD =  1000000007;
const int IINF = INT_MAX;
const ll INF = 1LL << 60;


int main() {
    string s; cin >> s;
    int q; cin >> q;
    deque<char> deq;
    for(int i = 0; i < (int)s.size(); i++){
        deq.push_back(s[i]);
    }
    bool flip = false;
    for(int i = 0; i < q; i++){
        int t; cin >> t;
        if(t == 2){
            int f; cin >> f;
            char c; cin >> c;
            if(f == 1){
                if(f == 1 && flip) deq.push_back(c);
                else deq.push_front(c);
            }else{
                if(flip) deq.push_front(c);
                else deq.push_back(c);
            }
        }else{
            flip = !flip;
        }
    }

    if(flip) reverse(ALL(deq));
    while(!deq.empty()){
        char c = deq.front();
        deq.pop_front();
        cout << c;
    }
    cout << "\n";

    return 0;
}


Measured memory_bytes: 4080
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> v(62, 0);
  REP(i, N){
    int A;
    cin >> A;

    REP(j, 62){
      if(A%2) v[j]++;
      A /= 2;
    }
  }

  int ans = 0;
  int a = 1;
  REP(i, 62){
    (ans += (a*v[i])%MOD*(N-v[i])) %= MOD;
    (a *= 2) %= MOD;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, x, n) for (ll i = x; i < (ll)(n); i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
//cin.tie(0);ios::sync_with_stdio(false);


signed main()
{
   ll n,m;cin>>n>>m;
   vector<ll> v(n,0);
   rep(i,m){
       ll a,b;cin>>a>>b;
       a--;b--;
       v[a]++;
       v[b]++;
   }

   rep(i,n){
       if(v[i]%2==1){
           cout<<"NO"<<endl;
           return 0;
       }
   }

   cout<<"YES"<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

void Main();

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
	return 0;
}

int dis(string s, string t, int start){
	int ret = 0;
	rep(i,t.size()){
		if(s[i+start] != t[i]) ret++;
	}
	return ret;
}

void Main(){
	string s,t;
	cin >> s >> t;
	int ans = t.size();
	rep(start, s.size()-t.size()+1){
		ans = min(ans, dis(s,t,start));
	}
	cout << ans << endl;
}


Measured memory_bytes: 3660
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int a[3];
int main(){
    scanf("%d%d%d",a,a+1,a+2);
    if((a[0]&1)&&(a[1]&1)&&(a[2]&1)){
        sort(a,a+3);
        printf("%lld\n",a[0]*1ll*a[1]);
    }
    else printf("0\n");
    //system("pause");
    return 0;
}


Measured memory_bytes: 256
import math

N = int(input())

for n in range(1, N + 1):
    cnt = 0
    for x in range(1, n + 1):
        for y in range(1, n + 1):
            xy = n - (x ** 2 + y ** 2 + x * y)
            if xy < 0:
                break
            p = x + y
            q = p ** 2 + 4 * xy
            if int(math.sqrt(q)) ** 2 == q:
                d = -p + int(math.sqrt(q))
                if d % 2 == 0 and d > 0:
                    cnt += 1

        else:
            break

    print(cnt)


Measured memory_bytes: 69356
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
#include<stack>
using namespace std;
using ll = __int64_t;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
constexpr int inf=(1<<30)-1;
constexpr ll mod=1e9+7;



int main(){
      ll n;
      cin>>n;
      ll a[n][n];
      rep0(i,n)rep0(j,n-1){
            cin>>a[i][j];
            --a[i][j];
      }
      vector<int> nextnode[n*n];
      int degree[n*n];
      fill(degree,degree+n*n,0);
      rep0(i,n)rep0(j,n-2){
            int bk=i;
            int bl=a[i][j];
            int nk=i;
            int nl=a[i][j+1];
            if(bk>bl){
                  swap(bk,bl);
            }
            if(nk>nl){
                  swap(nk,nl);
            }
            int bn=bk*n+bl;
            int nn=nk*n+nl;
            nextnode[bn].push_back(nn);
            degree[nn]++;
      }
      queue<int> qu;
      int ansday=1;
      int day[n*n];
      fill(day,day+n*n,1);
      rep0(i,n){
            rep0(j,n){
                  if(i>=j) continue;
                  int k=min(i,j);
                  int l=max(i,j);
                  int t=i*n+j;
                  if(degree[t]==0) qu.push(t);
            }
      }
      int cnt=0;
      while(qu.size()){
            int bn=qu.front();
            qu.pop();
            //cout<<bn/n<<" "<<bn%n<<" "<<day[bn]<<endl;
            cnt++;
            for(auto nn:nextnode[bn]){
                  degree[nn]--;
                  if(degree[nn]==0){
                        qu.push(nn);
                        day[nn]=max(day[bn]+1,day[nn]);
                        ansday=max(day[nn],ansday);
                  }
            }
      }
      if(cnt==(n*(n-1))/2) cout<<ansday<<endl;
      else cout<<-1<<endl;
      return 0;
}


Measured memory_bytes: 54912
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) (v).begin(), (v).end()
const char newl = '\n';

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

  ll D;
  cin >> D;
  vl c(26);
  rep(i, 26) cin >> c[i];

  vpl C(26);
  rep(i,26) C[i] = pl (c[i], i);
  sort(all(C), greater<pl>());

  ll b=1;
  rep(i, D) {
    ll day=i;
    day%=17;
    if(day>=8 and b%3==0) day+=9;
    if(day==16) b++;
    if(day==25) b++;
    cout << C[day].second+1 << newl;
  }

  return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int h,w;
	string s[50];
	cin >> h >> w;
	int c[50][50] = {0};
	for(int i= 0; i < h; i++){
		cin >> s[i];
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '#'){
				if(i > 0){
					c[i - 1][j]++;
					if(j > 0)
						c[i - 1][j - 1]++;
					if(j < w - 1)
						c[i - 1][j + 1]++;
				}
				if(i < h - 1){
					c[i + 1][j]++;
					if(j > 0)
						c[i + 1][j - 1]++;
					if(j < w - 1)
						c[i + 1][j + 1]++;
				}
				if(j > 0)
					c[i][j - 1]++;
				if(j < w - 1)
					c[i][j + 1]++;
			}
		}
	}
	
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '#')
				cout << '#';
			else
				cout << c[i][j];
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int g = sc.nextInt();
    int b = sc.nextInt();
    
    int n = r*100+g*10+b;
    
    if(n%4==0){
    System.out.println("YES");
    }else{
    System.out.println("NO");
    }
    }
}

Measured memory_bytes: 35524
const val P = 1000000007L

class FiniteField(xRaw: Long) {
  val x = if (xRaw >= 0) xRaw % P else (P - ((-xRaw) % P)) % P
  constructor(xi: Int): this(xi.toLong())
  operator fun plus(o: Long) = FiniteField((x + o) % P)
  operator fun plus(o: FiniteField) = this + o.x
  operator fun minus(o: Long) = FiniteField((x + P - o) % P)
  operator fun minus(o: FiniteField) = this - o.x
  operator fun times(o: Long) = FiniteField((x * o) % P)
  operator fun times(o: FiniteField) = this * o.x
  override fun toString() = x.toString()
}

fun powerOfTwo(p: Int): FiniteField {
  if (p == 0) return FiniteField(1)
  val a = powerOfTwo(p / 2)
  return a * a * if (p % 2 == 1) FiniteField(2) else FiniteField(1)
}

fun solve(hs: List<Int>): Pair<FiniteField, FiniteField> {
  // println(hs)
  val hMin = hs.min()!!
  if (hs.all { it == hMin }) {
    val w = hs.size
    val v1 = powerOfTwo(w) + powerOfTwo(hMin) - 2
    val v2 = powerOfTwo(hMin)
    return Pair(v1, v2)
  } else {
    // Fill this.
    val r = hs.count { it == hMin }

    var p1 = FiniteField(1)
    var p2 = FiniteField(1)
    val childHs = mutableListOf<Int>()
    for (h in hs) {
      if (h == hMin) {
        if (childHs.size > 0) {
          val (c1, c2) = solve(childHs)
          p1 *= c1 + c2
          p2 *= c2
          childHs.clear()
        }
      } else {
        childHs.add(h - hMin)
      }
    }
    if (childHs.size > 0) {
      val (c1, c2) = solve(childHs)
      p1 *= c1 + c2
      p2 *= c2
      childHs.clear()
    }

    val v1 = p1 * powerOfTwo(r) + (powerOfTwo(hMin) - 2) * p2
    val v2 = powerOfTwo(hMin) * p2
    return Pair(v1, v2)
  }
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val hs = readLine()!!.split(" ").map { it.toInt() }
  println(solve(hs).first)
}


Measured memory_bytes: 37704
n,k = map(int,input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
a.sort()
b.sort(reverse=True)


def ok(mid,a,b,k,n):
    tmp = 0
    for i in range(n):
        if a[i] * b[i] > mid:
            tmp += a[i] - mid//b[i]
    if tmp > k:
        return 1
    else:
        return -1


def bin_search(a,b,k,n):
    l = 0
    r = 10**12
    while l <= r:
        mid = l + (r - l)//2
        res = ok(mid,a,b,k,n)
        if res < 0:
            r = mid - 1
        else:
            l = mid + 1
    return l


print(bin_search(a,b,k,n))

Measured memory_bytes: 119628
//dont try to understand my code i really dont understand it 
#include<iostream>
#include<fstream>
#include<cmath>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<vector>
#include <queue>
#include <stack>
#include<algorithm>
#include<memory.h>
using namespace std;
typedef long long ll;
#define f( i , x , n ) for(int i = x; i < (int)(n); ++i)
#define pb push_back
#define mp make_pair
#define mt make_tuple
typedef pair<int, int> ii;
const double PI = acos(-1.0);
//const int oo = 10e9;
//const ll F = LLONG_MIN;	
const int A = 300002;
typedef long long ll;
// write what you need here : ...
int arr[26];
int main() {
	string s;
	cin >> s;
	ll ans = 1;
	for (int i = 0; i < s.length();i++)
	{
		ans += i - arr[s[i] - 'a'];
		arr[s[i] - 'a']++;
	}

	cout << ans;

	return 0;
}	

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
	int n,i;
	int a[100];
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	int sum=0;
	for(i=0;i<n;i++){
		sum=sum+a[i];
	}
	int all=0,all1=0;
	int b,c;
	if(sum%n==0){
		b=sum/n;
		for(i=0;i<n;i++){
			all=(b-a[i])*(b-a[i])+all;
		}
	}
	else{
		b=sum/n;
		c=b+1;
		for(i=0;i<n;i++){
			all=(b-a[i])*(b-a[i])+all;
		}
		for(i=0;i<n;i++){
			all1=(c-a[i])*(c-a[i])+all1;
		}
		if(all>all1)
		all=all1;
		else
		all=all;
	}	
	cout<<all;
	return 0;
} 

Measured memory_bytes: 256
def foo():
    N = input()
    data = [map(int, raw_input().split()) for _ in range(N)]
    data.sort(key=lambda x: (x[1], x[0]))

    total = 0
    for a, b in data:
        total += a
        if total > b:
            return "No"
    return "Yes"

print foo()


Measured memory_bytes: 59368
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        out.println(Math.min(n*a,b));
        
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 23252
n=int(input())
s=[int(c) for c in input()]
count=0
for p in range(10):
    for q in range(10):
        for r in range(10):
            if p in s[:n-2]:
                inp=s.index(p)
                if q in s[inp+1:n-1]:
                    inq=s[inp+1:n-1].index(q)+inp+1
                    if r in s[inq+1:]:
                        count+=1
print(count)

Measured memory_bytes: 132516
h,w=gets.split.map &:to_i
arr=h.times.map{gets.chomp.chars}

# マス目を'.'で囲う
arr.map do |i|
  i.push('.')
  i.unshift('.')
end
arr.push(Array.new(w+2,'.'))
arr.unshift(Array.new(w+2,'.'))

# マスを置き換えて出力
1.upto(h) do |i|
  1.upto(w) do |j|
    cnt=0
    cnt+=1 if arr[i-1][j-1] === '#'
    cnt+=1 if arr[i-1][j] === '#'
    cnt+=1 if arr[i-1][j+1] === '#'        
    cnt+=1 if arr[i][j-1] === '#'
    cnt+=1 if arr[i][j+1] === '#'
    cnt+=1 if arr[i+1][j-1] === '#'
    cnt+=1 if arr[i+1][j] === '#'
    cnt+=1 if arr[i+1][j+1] === '#'
    print arr[i][j] === '#' ? '#' : cnt
  end
  print "\n"
end

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

using namespace std;

#define oo (1L<<62)
#define ll long long int

int h[100005];
ll memo[100005];
char visitado[100005];
int N;

ll memoiter[3];

ll costo(int  n){
    if(!n) return n;
    if(n == 1) return abs(h[0]-h[1]);
    if(visitado[n]) return memo[n];
    visitado[n] = 1;
    return memo[n]= min(costo(n-1)+abs(h[n]-h[n-1]), 
                    costo(n-2)+abs(h[n]-h[n-2])); 
}

ll iterativo(){
    memoiter[0] = 0;
    memoiter[1] = abs(h[0]-h[1]);
    for(int i = 2; i<N; i++)
        memoiter[i%3] = min(memoiter[(i-1)%3]+abs(h[i]-h[i-1]),
                      memoiter[(i-2)%3]+abs(h[i]-h[i-2]));
    return memoiter[(N-1)%3];
}
    

int main()
{
    cin>>N;
    for(int i = 0; i<N;i++)
        cin>>h[i];
    cout<<costo(N-1)<<"\n";
}


Measured memory_bytes: 7216
#include<stdio.h>
#include<stdlib.h>
#define N 1000

int top=0,S[N];

void push(int x){
  if(top==N){
    printf("Stack overflow!\n");
    exit(2);
    }
   S[++top]=x;
}
int pop(void){
   if(top==0){
    printf("Stack is empty!\n");
    exit(3);
    }
   top--;
    return S[top+1];
}

int main(){
  int a,b;
  top=0;
  char s[100];

  while( scanf("%s", s) != EOF){
    if(s[0]=='+'){
      push(pop()+pop());
    }
    else if(s[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }
    else if(s[0]=='*'){
      push(pop()*pop());
    }
    else{
      push(atoi(s));
    }
  }

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

  return 0;
}


Measured memory_bytes: 2048
l, r = gets.chomp.split(' ').map(&:to_i)
min = 2019
(l..[r, l + 2019].min).each do |i|
  ((i + 1)..[r, l + 2019].min).each do |j|
    min = [(i * j) % 2019, min].min
  end
end
puts min

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

using namespace std;

long long int n, a, c, ans;

int main()
{
    cin >> n;
    ans = n;
    while (ans != 0) 
    {
        ans /= 10;
        a++;
    }
    ans = 0;
    c = 1;
    for (int i = 0; i < a; i++) 
    {
        ans += c * 9;
        c *=  10;
    }
    for(int i = 0; i < 10; i++) 
    {
        if(ans <= n)
        {
            cout << 9 * a - i << endl;
            break;
        }
        ans -= pow(10, a - 1);
    }
    return 0;
}



Measured memory_bytes: 256
dd = input().strip().split(' ')
N, Q = tuple(map(int, dd))
S = input().strip()

ac_indicies = []
cp = S.find('AC')
while cp != -1:
    ac_indicies.append(cp)
    cp = S.find('AC', cp + 1)

min_i = 0
ac = ac_indicies + [N]
l_index = []
for i in range(N):
    if i > ac[min_i]:
        min_i += 1
    l_index.append(min_i)

total = len(ac_indicies)
for i in range(int(Q)):
    l, r = tuple(map(int, input().strip().split(' ')))
    print(l_index[r-1] - l_index[l-1])


Measured memory_bytes: 8684
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while (sc.hasNext()) {
			String str = sc.nextLine();
			tictactoe(str);
		}

	}

	private static void tictactoe(String str) {
		char[][] t = new char[3][3];
		char winner = 'd';

			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					t[i][j] = str.charAt( i * 3 + j );
				}
			}

			for (int i = 0; i < 3; i++) {
					if ( t[i][0] == t[i][1] && t[i][0] == t[i][2] &&
						 t[i][1] == t[i][2] && t[i][0] != 's'		)
					{
						winner = t[i][0];
						break;
					} else if (t[0][i] == t[1][i] && t[0][i] == t[2][i] &&
							 t[1][i] == t[2][i] && t[0][i] != 's'		)
					{
						winner = t[0][i];
						break;
					}
			}

			if ( winner == 'd' ) {
				if ( t[0][0] == t[1][1] && t[1][1] == t[2][2] &&
					 t[0][0] == t[2][2] && t[0][0] != 's'	)
				{
					winner = t[0][0];
				} else if ( t[0][2] == t[1][1] && t[1][1] == t[2][0] &&
						 	t[0][2] == t[2][0] && t[0][2] != 's'	)
				{
					winner = t[0][2];
				}

			}

			System.out.println(winner);
	}

}


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

const vector<long long> prime{ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 };
const long long mod = (long long)1e9 + 7LL;

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

	long long ans = 1;
	for (auto p : prime) {
		long long cnt = 0;
		for (int i = p; i <= n; i *= p) {
			cnt += n / i;
		}
		ans = ans * (cnt + 1) % mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int H,W,K; cin>>H>>W>>K;
	vector<vector<char>> nap(H, vector<char> (W));
	rep(i,H)rep(j,W)cin>>nap[i][j];
	int ans = 0;
	for(int bith = 0; bith < (1<<H); ++bith){
		for(int bitw = 0; bitw < (1<<W); ++bitw){
			vector<vector<char>> t_nap = nap;
			rep(i,H){
				if(bith & (1<<i)){
					rep(j,W)t_nap[i][j] = 'R';
				}
			}
			rep(j,W){
				if(bitw & (1<<j)){
					rep(i,H)t_nap[i][j] = 'R';
				}
			}
			int e_ans = 0;
			rep(i,H){
				rep(j,W){
					if(t_nap[i][j] == '#')++e_ans;
				}
			}
			if(e_ans == K)++ans;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n,M,s,d;
	while(cin >> n && n){
		cin >> M >> s >> d;
		M--,s--;
		string data[30];
		rep(i,d){
			cin >> data[i];
		}
		
		int m = M;
		rep(i,d){
			if(m > 0 && data[i][m-1]=='1'){m = m-1;}
			else if(m < n-1 && data[i][m]=='1'){m = m+1;}
		}
		if(m == s){
			cout << 0 << endl;
			continue;	
		}
		rep(y,d){
			rep(x,n-1){
				if(data[y][x] == '0'){
					m = M;
					data[y][x] = '1';
					bool f = false;
					rep(i,n-2)if(data[y][i] == '1' && data[y][i+1] == '1')f = true;
					if(!f){
						rep(i,d){
							if(m > 0 && data[i][m-1]=='1'){m = m-1;}
							else if(m < n-1 && data[i][m]=='1'){m = m+1;}
						}
						if(m == s){
							cout << y+1 << " " << x+1 << endl;
							goto end;
						}
					}
					data[y][x] = '0';
				}
			}
		}
		cout << 1 << endl;
		end:;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define PB push_back
#define ar2 array<int, 2>
typedef long long LL;
const int P = 998244353;
const int N = 130;
const double PI = acos(-1);
mt19937 rng(time(0));

bool isauto = 0;

int n, x, sz[70], L = 128;
char ch[70];
char s[150];
string ans[70], ansstr;

int dp[N][N];

int ask(string s){
	cout<<"? "<<s<<endl<<flush;
	if(!isauto)
		cin>>x;
	else{
		int n = s.size(), m = ansstr.size();
		memset(dp,0,sizeof dp);
		rep(i,1,n) rep(j,1,m){
			dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			dp[i][j] = max(dp[i][j], dp[i-1][j-1] + (s[i-1] == ansstr[j-1]) );
		}
		x = max(n,m) - dp[n][m];
	}
	return x;
}

int main(){
	#ifndef ONLINE_JUDGE
	if (isauto)
		freopen("test.in","r",stdin);
	#endif
	
	if(isauto) cin>>ansstr;
	
	n = 62;
	rep(i,1,26) ch[i] = i+'A'-1;
	rep(i,27,52) ch[i] = i+'a'-27;
	rep(i,53,62) ch[i] = i+'0'-53;
	
	rep(i,1,n){
		memset(s,0,sizeof s);
		rep(j,1,L) s[j] = ch[i];
		sz[i] = L - ask(string(s+1));
		rep(j,1,sz[i]) ans[i] += ch[i];
	}
	
	L = 0;
	rep(i,1,n) L += sz[i];
	
	priority_queue<ar2,vector<ar2>,greater<ar2>> heap;
	rep(i,1,n) if(sz[i]) heap.push({sz[i],i});
	
	while(heap.size()>=2){
		ar2 e1 = heap.top(); heap.pop();
		ar2 e2 = heap.top(); heap.pop();
		
		int a = e1[1], b = e2[1];
		string tmp = "", s1 = ans[a], s2 = ans[b];
		int m1 = e1[0], m2 = e2[0];
		
		while(m1 && m2){
			char y = s2[m2-1];
			if(ask(s1+y+tmp) == L - tmp.size() - (m1+1)){
				tmp = y + tmp;
				s2 = s2.substr(0, m2-1);
				m2--;
			}else{
				tmp = s1[m1-1] + tmp;
				s1 = s1.substr(0, m1-1);
				m1--;
			}
		}
		if(m1==0) tmp = s2 + tmp;
		else tmp = s1 + tmp;
		
		sz[a] += sz[b], sz[b] = 0, ans[a] = tmp;
		heap.push({sz[a], a}); 
	}
	
	int a = heap.top()[1];
	cout<<"! "<<ans[a]<<endl;
	return 0;
}

Measured memory_bytes: 3808
import scala.io.StdIn.readInt

object Main {
  val c = Math.cos(Math.PI/3)
  val s = Math.sin(Math.PI/3)

  def getPoints(list:IndexedSeq[(Double,Double)],i:Int):IndexedSeq[(Double,Double)]  =
    if(i==0) list
    else
      getPoints( for{
        k<-0 until list.length-1; i = list(k); j = list(k+1)
        p1 = ((i._1*2+j._1)/3,(i._2*2+j._2)/3)
        p2 = ((i._1+j._1*2)/3,(i._2+j._2*2)/3)
        x = (p2._1-p1._1)*c-(p2._2-p1._2)*s+p1._1
        y = (p2._1-p1._1)*s+(p2._2-p1._2)*c+p1._2
        list2 = if(k==0) Iterator(i,p1,(x,y),p2,j) else Iterator(p1,(x,y),p2,j)
        q<-list2
      } yield q , i-1)

  def main(args:Array[String]) = {
    val n = readInt
    val list = getPoints(IndexedSeq((0D,0D),(100D,0D)),n)
    for((i,j)<-list) printf("%.8f %.8f\n",i,j)
  }
}

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

int main(){
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  c *= 2;
  int ans = 0;
  int d = min(x,y);
  if (a+b>=c){
    ans += c*d;
  }else{
    ans += (a+b)*d;
  }
  x -=d,y-=d;
  if(x==0){
    if(b>=c) ans += c*y;
    else ans += b*y;
  }else{
    if(a>=c) ans += c*x;
    else ans += a*x;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair
using namespace std;
int MOD = 1e9+7;
int inf = 1e18;
const int N = 5e5+999;
//int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
      int n;
      cin>>n;
      int arr[n];
      int sum  = 0;
      rep(i,0,n){
      cin>>arr[i];
      }
      sum =0 ;
      int minn = inf;
      int ans = 0;
      for(int j=0;j<1000;++j){
            sum = j;
      rep(i,0,n)
      {
          ans+= ((sum-arr[i])*(sum-arr[i]));
      }

         minn = min(minn,ans);
          ans = 0;
      }
      cout<<minn<<el;
    }
   return 0;
}


Measured memory_bytes: 256
import numpy as np
n = int(input())
timezones = np.array([[int(i) for i in input().split()] for _ in range(n)])
points = np.array([[int(i) for i in input().split()] for _ in range(n)])
max_scores = - float('inf')
for i in range(1, 2 ** 10):
    indices = []
    for j in range(10):
        if i & (1 << j):
            indices.append(j)
    nums = timezones[:, indices].sum(axis=1)
    scores = points[range(n), nums].sum()
    max_scores = max(max_scores, scores)
print(max_scores)

Measured memory_bytes: 13640
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	string S=in<string>(),T=in<string>();
	string U(2*N,'0');
	REP(i,N){
		U[2*i] = S[i];
		U[2*i+1] = T[i];
	}
	out(U);
	return 0;
}

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

int main()
{
  int n; cin >> n;
  bool flag = true;
  rep(i, n)
  {
    int a; cin >> a;
    if (a % 2 == 0 && a % 3 != 0 && a % 5 != 0)
    {
      flag = false;
      break ;
    }
  }
  if (flag)
    cout << "APPROVED" << endl;
  else
    cout << "DENIED" << endl;
}


Measured memory_bytes: 256