akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define P pair<int, int>

using namespace std;
using ll = long long;

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

struct edge {int from, to, cost; };

const int MAX_V = 200;
int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u, int v){
    G[u].push_back(v);
    G[v].push_back(u);
}

bool dfs(int v){
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        int u = G[v][i], w = match[u];
        if(w < 0 || (!used[w] && dfs(w))){
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

int bipartite_matching(){
    int res = 0;
    memset(match, -1, sizeof(match));
    for(int v = 0; v < V; v++){
        if(match[v] < 0){
            memset(used, 0, sizeof(used));
            if(dfs(v)){
                res++;
            }
        }
    }
    return res;
}

void solve(){
    cin >> V;
    int a[V], b[V], c[V], d[V];
    rep(i, V) cin >> a[i] >> b[i];
    rep(i, V) cin >> c[i] >> d[i];
    rep(i, V){
        rep(j, V){
            if(a[i] < c[j] && b[i] < d[j]){
                add_edge(i, V+j);
            }
        }
    }
    cout << bipartite_matching() << endl;
}

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


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

#define loop(i, n) for(int i = 0; i < n; i++)
#define sloop(i, s, n) for (int i = s; i < n; i++)
#define rloop(i, n) for (int i = n - 1; i >= 0; i--)

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, temp;
    cin >> n;
    vector<int> v(n+1, 0), pressed(n+1, 1);
    sloop(i, 1, n+1) {
        cin >> v[i];
    }
    temp = 1;
    int ans = 0;
    while(temp != 2 && pressed[temp]) {
        pressed[temp]--;
        temp = v[temp];
        ans++;
    }
    if(temp == 2) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}



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

    string s; cin >> s;

    int i = 0;
    int j = s.size() - 1;

    int ans = 0;
    while (i < j) {
        if (s[i] != s[j]) ans++;
        i++;
        j--;
    }

    cout << ans;


    return 0;
}


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

long long sel(long long a,long long b,long long c){
    return a*b*c;
}

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

    long long M=0,A=0,R=0,C=0,H=0;
    for(int i=0;i<N;i++){
        string S;
        cin >> S;
        if(S[0]=='M') M++;
        if(S[0]=='A') A++;
        if(S[0]=='R') R++;
        if(S[0]=='C') C++;
        if(S[0]=='H') H++;
    }

    long long ans=0;
    ans+=sel(M,A,R);
    ans+=sel(M,A,C);
    ans+=sel(M,A,H);
    ans+=sel(M,R,C);
    ans+=sel(M,R,H);
    ans+=sel(M,C,H);
    ans+=sel(A,R,C);
    ans+=sel(A,R,H);
    ans+=sel(A,C,H);
    ans+=sel(R,C,H);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from itertools import permutations
import numpy as np
N, C = map(int, input().split())
D = np.ndarray((C, C), dtype=int)
c = np.ndarray((N, N), dtype=int)
for i in range(C):
    D[i] = list(map(int,input().split()))
for i in range(N):
    c[i] = list(map(int,input().split()))
c -= 1
acc = np.zeros((3, C), dtype=int)
for i in range(N):
    for j in range(N):
        acc[(i+j) % 3] += D[c[i][j]]
ans = float("inf")
for i,j,k in permutations(range(C), r=3):
    ans = min(ans, acc[0][i]+acc[1][j]+acc[2][k])
print(ans)

Measured memory_bytes: 28720
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int N;
    cin >> N;
    vector<vector<int>> G(N, vector<int>());
    vector<int> c(N);
    int s;
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
        s = a;
    }

    rep(i, N) { cin >> c[i]; }

    sort(all(c), greater<int>());

    ll ans = accumulate(all(c), 0LL) - c[0];
    queue<int> que;
    map<int, int> ma;
    int cur = 0;
    ma[s + 1] = c[cur];
    que.push(s);
    while (!que.empty()) {
        int t = que.front();
        que.pop();

        for (auto n : G[t]) {
            if (ma[n + 1] != 0)
                continue;
            cur++;
            ma[n + 1] = c[cur];
            que.push(n);
        }
    }

    cout << ans << endl;
    for (auto m : ma) {
        cout << m.second << " ";
    }
    cout << endl;
}

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int n; std::cin >> n;
  auto calcTop = [](int val) {
    while (10 <= val)
      val /= 10;
    return val;
  };
  vector<vi> cnt(10, vi(10));
  rrep(val, n) {
    int top = calcTop(val);
    cnt[top][val%10]++;
  }
  int ans = 0;
  rep(top, 10) rep(btm, 10)
    ans += cnt[top][btm] * cnt[btm][top];
  std::cout << ans << "\n";
}


Measured memory_bytes: 256
// Get Many Persimmon Trees
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1125

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

const int NONE = false;
const int TREE = true;

int N;
int W, H, S, T;
vector<vector<bool>> field;

inline int get_persimmon_trees(int x, int y) {
    int total = 0;
    for (int i = y; i < y+T; ++i) {
        for (int j = x; j < x+S; ++j) {
            if (field[i][j] == TREE) total++;
        }
    }
    return total;
}

int main() {
    while (cin >> N) {
        if (N == 0) break;
        cin >> W >> H;
        field.assign(H, vector<bool>(W, NONE));

        for (int i = 0; i < N; ++i) {
            int x, y;
            cin >> x >> y;
            x--; y--;
            field[y][x] = TREE;
        }
        cin >> S >> T; 

        int ans = 0;
        for (int y = 0; y <= H-T; ++y) {
            for (int x = 0; x <= W-S; ++x) {
                ans = max(get_persimmon_trees(x, y), ans);
            }
        }
        cout << ans << endl;
    }
	return 0;
}

Measured memory_bytes: 3080
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
using namespace std;
typedef long long int ll;
ll h, w;
 
ll solve(ll x, ll y){
    ll ans = h * w;
    for(int i = 1; i < x; i++){
        ll s1 = i * y;
        ll s2 = (x - i) / 2 * y;
        ll s3 = x * y - s1 - s2;
        ll smax = max(s1, max(s2, s3));
        ll smin = min(s1, min(s2, s3));
        ans = min(ans, smax - smin);
 
        s2 = (x - i) * (y / 2);
        s3 = x * y - s1 - s2;
        smax = max(s1, max(s2, s3));
        smin = min(s1, min(s2, s3));
        ans = min(ans, smax - smin);
    }
    return ans;
}
 
int main(){
    cin >> h >> w;
    cout << min(solve(h, w), solve(w, h)) << endl;
    return 0 ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int pallindrom(string s)
{
    string ss;
    ss=s;
    reverse(s.begin(),s.end());
    if(ss==s)
    {
        return 1;
    }
    else
        return -1;
}
int main()
{
    string ss;
    cin>>ss;
    int n=ss.size();
    int r=  pallindrom(ss);
    if(r==1)
    {
        int a=(n-1)/2;
        int b=(n+3)/2;
        string s1= ss.substr(0, a);

        string s2= ss.substr(b-1, n);
        // cout<<s1<<" " <<s2;
        int p1=  pallindrom(s1);
        int p2=  pallindrom(s2);
        if(p1==p2 && p1==1)
        {
            cout<<"Yes";
        }
        else
            cout<<"No";
    }
    else
        cout<<"No";





}


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

int main() {
	int n;
	long long a[50], k;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	while(1) {
		long long mm = 0;
		int j = -1;
		for(int i = 0; i < n; i++) {
			if(a[i] > mm) {
				j = i;
				mm = a[i];
			}
		}
		
		if(mm < n) break;
		
		long long dk = a[j] / n;
		k += dk;
		a[j] %= n;
		for(int i = 0; i < n; i++) {
			if(i == j) continue;
			a[i] += dk;
		}
	}
	
	cout << k << '\n';
	
	
	
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/

#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int r, D, x;
  cin >> r >> D >> x;

  REP(i, 10)
  {
    x = r * x - D;
    cout << x << '\n';
  }

  return 0;
}


Measured memory_bytes: 384
n,m,x = map(int,input().split())
B = [list(map(int,input().split())) for _ in range(n)]
ans = 10**9

for i in range(2**n):
    R = [0 for _ in range(m)]
    tmp = 0
    for j in range(n):
        if i & (1 << j):
            tmp += B[j][0]
            for k,b in enumerate(B[j][1:]):
                R[k] += b
    flag = True
    for r in R:
        if r < x:
            flag = False
            break
    if flag:
        ans = min(ans,tmp)
if ans == 10**9:
    ans = -1
print(ans)

Measured memory_bytes: 69080
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define si set <ll>
#define vi vector <ll>
#define popcount(x) __builtin_popcountll(x)
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,n) for(ll i=a ; i<n ; i++)
#define ld long double
#define rall(a) (a).rbegin(),(a).rend()
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")



ll power(ll b,ll e,ll m)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b%m,e/2,m)%m;
  return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b,e/2);
  return power(b*b,e/2);
}  
bool isPowerOfTwo(ll x)
{
    // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
    return (x && !(x & (x - 1)));
}

void solve()
{
  ll n,x,t;
  cin>>n>>x>>t;
  ll y=n/x;
  if(n%x) y++;
  cout<<y*t;
}

int main()
{
  fastio
  ll tt=1;
  // cin>>tt;
  while(tt--)
  {
    solve();
    cout<<"\n";
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
#define mem0(x) memset(x, 0, sizeof(x))
#define mem1(x) memset(x, -1, sizeof(x))
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define de(x) cout << #x << " = " << x << endl;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = a; i > b; i--)
#define setI freopen("input.txt", "r", stdin);
#define setIO freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout);
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
//---------------------------------------------------------//
const int N = 2e5 + 5;
const LL MOD = 1e9 + 7;

int n;
LL dp[55];
char s[2][55];

int main()
{
	#ifdef M1saki
		setI;
	#endif
//	ios::sync_with_stdio(false);
	scanf("%d%s%s", &n, s[0] + 1, s[1] + 1);
	dp[0] = 1;
	rep(i, 1, n + 1)
	{
		dp[i] = dp[i - 1];
		if (s[0][i] == s[1][i])
		{
			if (i == 1)  dp[i] = dp[i - 1] * 3;
			else if (i - 1 >= 1 && s[0][i - 1] == s[1][i - 1])  dp[i] = dp[i - 1] * 2 % MOD;
		}
		else if (i - 1 >= 1 && s[0][i - 1] == s[0][i])
		{
			if (i == 2)  dp[i] = dp[i - 2] * 6 % MOD;
			else if (i - 2 >= 1 && s[0][i - 2] == s[1][i - 2])  dp[i] = dp[i - 2] * 2 % MOD;
			else if (i - 3 >= 1 && s[0][i - 3] == s[0][i - 2])  dp[i] = dp[i - 2] * 3 % MOD;
		}
	}
	printf("%lld\n", dp[n]);
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> int size(const T &x) { return x.size(); }
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = 2147483647;

int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll n;
    cin >> n;

    ll rest = n/2*d;
    if (n % 2 == 1) {
        rest += min(4*a, min(2*b,c));
    }

    cout << min(4*a*n,
            min(2*b*n,min(c*n,rest))) << endl;
    return 0;
}



Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
  long long int a,b,c,d,u,x,tmp,r;
  cin >> a >> b >> c >> d;
  u=b-a+1;
  u -=b/c - (a+(c-1))/c +1;
  u -=b/d - (a+(d-1))/d +1;
    x = c*d;
   if(c<d){
    tmp = c;
    c= d;
    c = tmp;
   }
   r =c%d;
  while(r!=0){
    c=d;
    d=r;
  r=c%d;
  }
  u +=b/(x/d) - (a+(x/d-1))/(x/d) +1;
  cout << u << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef string::const_iterator State;
class ParseError {};

struct Parser {
    int number(State &begin) {
	    int ret = 0;
	    while(isdigit(*begin)) {
	    	ret *= 10;
	    	ret += *begin - '0';
	    	begin++;
	    }
	    return ret;
    }

    int factor(State &begin) {
	    if(*begin == '(') {
		    begin++;
		    int ret = expression(begin);
		    begin++;
            return ret;
	    } else {
		    return number(begin);
	    }
    }

    int term(State &begin) {
	    int ret = factor(begin);
	    while(1) {
	    	if(*begin == '*') {
	    		begin++;
	    		ret *= factor(begin);
	    	} else if(*begin == '/') {
                begin++;
	    		ret /= factor(begin);
	    	} else {
	    		break;
	    	}
    	}
    	return ret;
    }

    int expression(State &begin) {
	    int ret = term(begin);
	    while(1) {
	    	if(*begin == '+') {
		    	begin++;
		    	ret += term(begin);
	    	} else if(*begin == '-') {
	    		begin++;
		    	ret -= term(begin);
	    	} else {
	    		break;
	    	}
    	}
    	return ret;
    }
};

int main() {
    int N;
    cin >> N;
    for(int i = 0; i < N; i++) {
        Parser ps;
        string s;
        cin >> s;
        State begin = s.begin();
        int ans = ps.expression(begin);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
using System;
using System.Collections.Generic;
using System.Linq;

namespace id_0586cs
{
    public class Symmetry
    {
        int _n, _c;
        public Symmetry(int n,int c)
        {
            _n = n;
            _c = c;
        }
        public List<int> Sequences()
        {
            List<int> vs = new List<int>();
            for(int i = (int)(Math.Pow(10,_n-1));i<=(int)Math.Pow(10,_n) - 1; i++)
            {
                string pre = i.ToString();
                string post = string.Join("", pre.Reverse());
                int cand = 0;
                if(_c < 0)
                {
                    cand = int.Parse(pre + post);
                }
                else
                {
                    cand = int.Parse(pre + _c.ToString() + post);
                }
                if (Symmetry.IsPrime(cand))
                {
                    vs.Add(cand);
                }
            }
            return vs;
        }
        public string WinningNumber()
        {
            if(_c <0 && _n >= 2)
            {
                return new string('9', _n * 2);
            }
            List<int> vs = Sequences();
            if (vs.Any()){
                return (vs.Max()).ToString();
            }
            string nine = ((int)Math.Pow(10, _n) - 1).ToString();
            if (_c <0 )
            {
                return nine + nine;
            }
            else
            {
                return nine + _c.ToString() + nine;
            }
        }
        public static bool IsPrime(int givenVal)
        {
            if (givenVal < 2) return false;
            if (givenVal == 2) return true;
            if (givenVal % 2 == 0) return false;
            int sqrtnum = (int)Math.Sqrt(givenVal);
            for (int i = 3; i <= sqrtnum; i += 2)
            {
                if (givenVal % i == 0) return false;
            }
            return true;
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            var vs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var sym = new Symmetry(vs[0], vs[1]);
            Console.WriteLine(sym.WinningNumber());
        }
    }
}



Measured memory_bytes: 18552
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
	int n;
	char s[101];
	scanf("%d %s",&n,s);
	int length=strlen(s),x=0;
	int max = 0;
	int i;
	
	for(i=0;i<length;i++){
		if(s[i]=='I'){
			x++;
		}else if(s[i]=='D'){
			x--;
		}
		
		if(x>max){
			max=x;
		}
	}
	
	printf("%d\n",max);
	
	return 0;
}

Measured memory_bytes: 128
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

#[allow(dead_code)]
pub const M: u64 = 1_000_000_007;

fn main() {
    input! {
        n: usize, k: u64,
        a: [[u64; n]; n]
    }

    let a_k = matrix_pow(&a, k);
    let mut sum = 0;
    for i in 0..n {
        for j in 0..n {
            sum += a_k[i][j];
            sum %= M;
        }
    }

    println!("{}", sum);
}

#[allow(dead_code)]
fn matrix_mul(a: &[Vec<u64>], b: &[Vec<u64>]) -> Vec<Vec<u64>> {
    let mut c = vec![vec![0; b[0].len()]; a.len()];
    for i in 0..a.len() {
        for k in 0..b.len() {
            for j in 0..b[0].len() {
                let tmp =  a[i][k] * b[k][j] % M;
                c[i][j] = c[i][j] + tmp;
                c[i][j] %= M;
            }
        }
    }
    c
}
#[allow(dead_code)]
fn matrix_pow(a_: &[Vec<u64>], mut n: u64) -> Vec<Vec<u64>> {
    let mut a: Vec<Vec<u64>> = a_.to_vec();
    let mut b = vec![vec![0; a.len()]; a.len()];
    for i in 0..a.len() {
        b[i][i] = 1;
    }
    while n > 0 {
        if n & 1 == 1 {
            b = matrix_mul(&b, &a);
        }
        a = matrix_mul(&a, &a);
        n >>= 1;
    }
    b
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
//deque/functional/iterator/list/map/memory/numeric/queue/set/stack/utility/vector
#define ll long long
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int n,k;
	int a[100005];
	int b[100005];
	int min=1000000000;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=k-1;i<n;i++)
	{
		
		b[i]=a[i]-a[i-k+1];
		if(b[i]<=min) min=b[i];
	}
	cout<<min<<endl;
	
	
return 0;
}


Measured memory_bytes: 640
n,m=map(int,input().split())
lst=[list(map(int,input().split())) for _ in range(m)]
left=lst[0][0]
right=lst[0][1]
for l,r in lst:
    left=max(left,l)
    right=min(right,r)
    if left > right:
        left=0
        right=-1
        break
print(int(right-left+1))

Measured memory_bytes: 27332
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a,b;
		String op;
		while(true){
			a = scan.nextInt();
			op = scan.next();
			b = scan.nextInt();

			if(op.indexOf("+") ==0) System.out.println(a+b);
			if(op.indexOf("-") ==0) System.out.println(a-b);
			if(op.indexOf("*") ==0) System.out.println(a*b);
			if(op.indexOf("/") ==0) System.out.println(a/b);
			if(op.indexOf("?") ==0) break;
		}
		
	}

}

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

int main() {
  int w, h ,n;
  cin >> w >> h >> n;
  int x[n], y[n], a[n];
  int i;
  for (i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> a[i];
  }
  int x_min, x_max, y_min, y_max;
  x_min = 0;
  x_max = w;
  y_min = 0;
  y_max = h;
  for (i = 0; i < n; i++) {
    if (a[i] == 1) {
      x_min = max(x_min, x[i]);
    } else if (a[i] == 2) {
      x_max = min(x_max, x[i]);
    } else if (a[i] == 3) {
      y_min = max(y_min, y[i]);
    } else {
      y_max = min(y_max, y[i]);
    }
  }
  cout << max(0, max((x_max - x_min), 0) * max((y_max - y_min), 0)) << endl;
  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split( ))
line=[]
for i in range(m):
    line.append(list(map(int,input().split( ))))
p_line=list(map(int,input().split( )))

C=0

for i in range(2**n):
    bin_i=format(i,'b')
    l=len(bin_i)
    for j in range(n-l):
        bin_i='0'+bin_i
    bin_i=list(bin_i)
    # print(bin_i)

    count=0

    for j in range(m):
        check=line[j]
        # print(check)
        s=0
        for k in range(check[0]):
            s+=int(bin_i[check[k+1]-1])
        s+=p_line[j]
        if s%2==0:
            count+=1
    
    # print(count)
    if count==m:
        C+=1
        # print('OK')

print(C)
    



Measured memory_bytes: 43508
N = int(input())
h = [int(h) for h in input().split()]

def jump(i, j):
    return abs(h[j] - h[i])

a, b = 0, jump(0, 1)
for i in range(2, N):
    a, b = b, min(b + jump(i - 1, i), a + jump(i - 2, i))
print(b)


Measured memory_bytes: 13924
#include <iostream>

using namespace std;

int main()
{
    int m,n;
    int a[60][3];
    cin >> m >> n;
    for(int i=0;i<n;i++)
        for(int j=0;j<2;j++)
            cin >> a[i][j];
    for(int i=1;i<=m;i++){
        int sum = 0;
        for(int j=0;j<n;j++){
            if(a[j][1] == i || a[j][0] == i){
                sum++;
            }
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, m;
  cin >> n >> m;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}

Measured memory_bytes: 764
s = list(input())
t = set(s)
if(len(t) == 1):
    if(len(s) == 1):
        print('YES')
    else:
        print('NO')
elif(len(t) == 2):
    if(len(s) == 2):
        print('YES')
    else:
        print('NO')
else:
    n = [0,0,0]
    for i in s:
        if(i == 'a'):n[0] +=1
        if(i == 'b'):n[1] +=1
        if(i == 'c'):n[2] +=1
    n.sort()
    n[1] -= n[0]
    n[2] -= n[0]
    n[0] -= n[0]
    if(n[1] <= 1 and n[2] <= 1):
        print('YES')
    else:
        print('NO')




Measured memory_bytes: 3956
def main():
    N, Ma, Mb = map(int, input().split())
    yakuhin = []
    for i in range(N):
        yakuhin.append(list(map(int, input().split())))
    
    INF = 10**15
    DP = [[[INF for _ in range(401)] for _ in range(401)] for _ in range(N+1)]
    DP[0][0][0] = 0
    
    for i in range(N):
        for j in range(401):
            for k in range(401):
                if(DP[i][j][k] != INF):
                    DP[i+1][j][k] = min(DP[i+1][j][k], DP[i][j][k])
                    DP[i+1][j+yakuhin[i][0]][k+yakuhin[i][1]] = min(DP[i+1][j+yakuhin[i][0]][k+yakuhin[i][1]], DP[i][j][k]+yakuhin[i][2])
    
    ans = INF
    for i in range(1, N+1):
        for j in range(1, 401):
            for k in range(1, 401):
                if(j*Mb == k*Ma):
                    ans = min(ans, DP[i][j][k])    
        
    print(ans if ans != INF else -1)
    
main()

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

#define int long long

int n,sz;
int a[100001], b[100001], p[100001];
int BIT[200001];

void update(int x)
{
	if (x == 0) x = 1;
	for(;x<=200000;x+=x&(-x))	
		BIT[x]++;
	return;
}

int query(int x)
{
	int ans = 0;
	for(;x>0;x-=x&(-x))
		ans += BIT[x];
	return ans;
}

bool check(int x)
{
	for (int i=1;i<=n;i++)
	{
		if (a[i] >= x)
			b[i] = 1;
		else
			b[i] = 0;
		p[i] = p[i-1] + b[i];
	}
	for (int i=0;i<=200000;i++)
		BIT[i] = 0;
	update(100000);
	int cur = 0;
	for (int i=1;i<=n;i++)
	{
		cur += query(2*p[i] - i + 100000);
		update(2*p[i] - i + 100000);
	}
	return (cur >= sz);
}

int32_t main() 
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> n;
	for (int i=1;i<=n;i++)
		cin >> a[i];
	sz = n*(n+1)/2;
	sz = (sz+1)/2;
	int l = 1, r = 1e9;
	int res;
	while(l <= r)
	{
		int mi = (l+r)/2;
		if (check(mi))
		{
			res = mi;
			l = mi + 1;
		}
		else
			r = mi - 1;
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (long long i = (a); i <= (b); i++)
#define FORD(i,a,b) for (long long i = (a); i >= (b); i--)
#define REP(i,a) FOR(i,0,(long long)(a)-1)
#define reset(a,b) memset(a,b,sizeof(a))
#define all(x) x.begin(), x.end()
#define uni(x) x.erase(unique(all(x)), x.end());
#define BUG(x) cout << #x << " = " << x << endl
#define BUGP(x) cout << #x << " = " << x._1 << ", " << x._2 << endl
#define PR(x,a,b) {cout << #x << " = "; FOR (_,a,b) cout << x[_] << ' '; cout << endl;}
#define CON(x) {cout << #x << " = "; for(auto _i:x) cout << _i << ' '; cout << endl;}
#define mod 1000000007
#define pi acos(-1)
#define eps 1e-8
#define pb push_back
#define sqr(x) (x) * (x)
#define _1 first
#define _2 second

int n, val, ans;

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  while (n--) {
    cin >> val;
    while (val % 2 == 0) val /= 2, ans++;
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
int ans = 0;
int main(){
    cin >> N;
    int A[100002] = {0};
    for(int i = 1; i <= N; i++)
        cin >> A[i];
    for(int i = 1; i <= N; i++)
        ans += abs(A[i] - A[i - 1]);
    ans += abs(A[N]);
    for(int i = 1; i <= N; i++)
        cout << ans - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) + abs(A[i + 1] - A[i - 1]) << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <set>
#include <list>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std; 

uint64_t
gcd(uint64_t a, uint64_t b) {
    if (b > a) {
	auto tmp = a;
	a = b;
	b = tmp;
    }

    uint64_t r = a % b;
    while (r != 0) {
	a = b;
	b = r;
	r = a % b;
    }
    return b;
}

int
main(int argc, char const *argv[])
{
    uint64_t a, b, c, d;
    cin >> a >> b >> c >> d;;
    uint64_t ans;
    uint64_t e = (c * d);
    auto f = gcd(c, d);
    if (f > 0) {
	e = e / f;
    }

    ans = ((b / c) - ((a-1) / c)) + ((b / d) - ((a-1) / d)) - ((b / e) - ((a-1) / e));
    ans = (b - a + 1) - ans;
    cout << ans << endl;
    return 0;
}
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int K, A, B;
  int AA, BB;
  cin >> K >> A >> B;

  if (A % K == 0){
    cout << "OK" << endl;
    return 0;
  }

  if (B % K == 0){
    cout << "OK" << endl;
    return 0;
  }

  AA = A / K;
  BB = B / K;
 
  if (AA == BB){
    cout << "NG" << endl;
  } else {
    cout << "OK" << endl;
  }
}

Measured memory_bytes: 3632
import itertools

count = 0
x = int(input())
line = list(map(int, input().split()))
for i in itertools.combinations(line,3):
  if i[0] != i[1] and i[1] != i[2] and i[2] != i[0] and i[0] + i[1] > i[2] and i[1] + i[2] > i[0] and i[0] + i[2] > i[1]:
    count += 1
print(count)

Measured memory_bytes: 9188
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

static const long long MOD = 1000000007;
static const long long MAX = 100005;


long long fac[MAX], finv[MAX], inv[MAX]; 

void init_comb() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

long long combination(long long n, long long k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}


int main(void) {
    ll n;
    cin >> n;
    vector<ll> memo(n+5, -1);
    int s = -1, t = -1;
    rep(i, 0, n+1) {
      ll a;
      cin >> a;
      if (memo[a]!=-1) {
        s = memo[a];
        t = i;
        break;
      }
      memo[a] = i;
    }
    
    ll x = t-s+1;
    init_comb();
    
    rep(k, 1, n+2) {
      ll ans = combination(n+1, k) - combination(n+1-x, k-1);
      ans %= MOD;
      if (ans<0) ans += MOD;
      cout << ans << endl;
    
    }

    return 0;
}


Measured memory_bytes: 6256
N, Ma, Mb = map(int, input().split(' '))
med = []
for _ in range(N):
    med.append(tuple(map(int, input().split(' '))))
inf = 10 ** 9 + 7

dp = [[inf for _ in range(401)] for _ in range(401)]
dp[0][0] = 0

for k in range(N):
    (a, b, c) = med[k]
    for i in range(400, -1, -1):
        for j in range(400, -1, -1):
            if dp[i][j] != inf:
                dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c)

ans = inf
for i in range(401):
    for j in range(401):
        if i == 0 or j == 0:
            continue
        if i * Mb == j * Ma:
            ans = min(ans, dp[i][j])
print(ans if ans != inf else -1)

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

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

  ll D; cin >> D;
  vector<ll> C(26); for (ll i = 0; i < 26; i++) cin >> C[i];
  vector<vector<ll>> S(D, vector<ll>(26, 0));
  for (ll i = 0; i < D; i++) {
    for (ll j = 0; j < 26; j++) {
      cin >> S[i][j];
    }
  }
  vector<ll> T(D, 0);
  for (ll i = 0; i < D; i++) {
    cin >> T[i];
    T[i]--;
  }

  ll ans = 0;
  vector<ll> last(26, 0);
  for (ll i = 0; i < D; i++) {
    ans += S[i][T[i]];
    last[T[i]] = i + 1;
    ll temp = 0;
    for (ll j = 0; j < 26; j++) {
      temp += C[j] * (i + 1 - last[j]);
    }
    ans -= temp;
    cout << ans << '\n';
  }

  return 0;
}

Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <deque>
#include <map>
#include <cmath>

int main(void) {
    int n;
    std::vector<int> a;

    std::cin >> n;

    int odd_cnt = 0;
    for (int i = 0; i < n; i++) {
        int val;
        std::cin >> val;
        odd_cnt ^= val & 1;
    }

    if (odd_cnt == 0) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

const int MAX_V = 10000;

class UnionFind{
public:
    UnionFind(){}
    UnionFind(int n){init(n);}
    void init(int n){
        REP(i, n){
            parent[i] = i;
            rank[i] = 0;
        }
    }
    int find(int v){
        if(parent[v] == v){return v;}
        return parent[v] = find(parent[v]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y){return;}
        if(rank[x] > rank[y]){
            parent[y] = x;
        }else{
            parent[x] = y;
            if(rank[x] == rank[y]){rank[y]++;}
        }
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
private:
    int parent[MAX_V], rank[MAX_V];
};

struct Edge{
    int from, to, cost;
};

bool compareEdge(const Edge &le, const Edge &re){
    return le.cost < re.cost;
}

UnionFind uf;
int main(){
    int V, E;
    std::cin >> V >> E;

    std::vector<Edge> G;
    REP(i, E){
        int from, to, cost;
        std::cin >> from >> to >> cost;
        G.push_back({from, to, cost});
    }

    std::sort(G.begin(), G.end(), compareEdge);

    uf.init(V);
    ull sum = 0;
    REP(i, E){
        Edge &e = G[i];
        if(!uf.same(e.from, e.to)){
            sum += e.cost;
            uf.unite(e.from, e.to);
        }
    }

    std::cout << sum << std::endl;
}

Measured memory_bytes: 2724
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F         first
#define S          second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define hell        1000000007
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 1e9
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e12+1;


using namespace std;
void solve();

void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);


/*class CompareDist
{
public:
    bool operator()(pair<ll,int> a,pair<ll,int> b) {
        if(a.F!=b.F)
        return a.F<b.F;
        else
        return a.S>b.S;
    }
};*/

void solve(){

  ll n;
  cin>>n;

  vector<pair<ll,ll>> vec;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      vec.pb(mp(i,n/i));
    }
  }

  int x=vec.size();
  ll ans=INF;

  for(int i=0;i<x;i++){
    ans=min(ans,vec[i].F-1ll+vec[i].S-1ll);
  }
  cout<<ans;
}


///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll x,ll y){
  if(x==0)
  return y;
  else
  return gcd(y%x,x);
}


ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1)%hell)*k%hell)%hell;
  else
  return ((pw(k,x/2)%hell)*(pw(k,x/2)%hell))%hell;
}

/*void sieve(){

  for(int i=2;i<=1000000;i++){
    if(prime[i]==true){
      for(int j=i*i;j<=1000000;j+=i)
      prime[j]=false;
    }
  }

}*/


Measured memory_bytes: 384
N = int(input())

def sort_alpabetical(s):
	
	s_list = list(s)
	s_list.sort()
	return ''.join(s_list)

list_s = []
for n in range(N):
	list_s.append(input())

list_s = [sort_alpabetical(s) for s in list_s]

dict_s = {s : 0 for s in set(list_s)}

n_of_pairs = 0


for s in list_s:
	
	n_of_pairs += dict_s[s]
	dict_s[s] +=1
	
print(n_of_pairs)



Measured memory_bytes: 26948
#include<iostream>
using namespace std;
string s[105],t[105];
int main()
{
	int n,m,i,j,maxv=-105,k;
	bool f=0;
	cin>>n;
	for(i=1;i<=n;i++) cin>>s[i];
	cin>>m;
	for(i=1;i<=m;i++) cin>>t[i];
	for(i=1;i<=n;i++){
		k=0;
		for(j=1;j<=n;j++)
			if(s[i]==s[j]) k++;
		for(j=1;j<=m;j++)
			if(s[i]==t[j]) k--;
		if(k>maxv && k>=0){
			f=1;
			maxv=k;
		}
	}
	if(f==1) 
		cout<<maxv<<endl;
	else 
		cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
import math
import sys
from collections import deque


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N, D, A = map(int, input().split())
    monster = [list(map(int, input().split())) for _ in range(N)]

    monster.sort(key=lambda x: x[0])

    attack = []
    for i in range(N):
        attack.append(math.ceil(monster[i][1] / A))

    acc_damage = 0
    attacked = deque([])
    answer = 0

    for i in range(N):
        x = monster[i][0]
        h = attack[i]

        while attacked and x > attacked[0][0]:
            limit, damage = attacked.popleft()
            acc_damage -= damage

        need = max(0, h - acc_damage)
        answer += need

        acc_damage += need

        if need:
            attacked.append((x + 2 * D, need))

    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 68676
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

using namespace std;
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; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

	ll N;
	cin >> N;

	ll q = N;
	ll ans = 1;

	while (q != 0)
	{
		q += N;
		q %= 360;
		ans++;
	}


	cout << ans << endl;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

ll n,m,T,k,q;
const ll big = 1000000007;
const ll big2 = 998244353;
ll F[139] = {0};
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,e;

   for(int c1 = 0; c1 < 4; c1++){
    cin >> a;
    F[a] = 1;
   }

    if(F[1]+F[9]+F[7]+F[4] == 4){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }

    return 0;
}


Measured memory_bytes: 768
#include<stdio.h>
#include<string.h>
int main()
{
    char s[20],s1[20];
    int i,count=0,len;
    scanf("%s",s);
    len=strlen(s);
    for(i=0;i<len;i++)
    {
       if(s[i]==',')
       {
          s1[i]=' ';
          count++;
       }
       else
       {
           s1[i]=s[i];
       }

    }
   for(i=0;i<strlen(s);i++)
   {
       printf("%c",s1[i]);
   }
   return 0;

}


Measured memory_bytes: 128
#include <stdio.h>

int getgcd(int a, int b) {
	if(b == 0)
		return a;
	return getgcd(b, a%b);
}

int main(void) {
	int n, m, a, i;
	scanf("%d%d", &n, &m);
	scanf("%d", &a);
	long lcm = a/2;
	for(i = 0; i < n - 1; i++) {
		scanf("%d", &a);
		int gcd = getgcd((int)lcm, a/2);
		if((lcm/gcd)%2 == 0 || (a/gcd)%4 == 0) {
			printf("0\n");
			return 0;
		}
		lcm = lcm*a/(2*gcd);
		if(m < lcm) {
			printf("0\n");
			return 0;
		}
	}
	printf("%d\n", (int)((m + lcm)/(2*lcm)));
	return 0;
}

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

namespace E
{
    class Program
    {
        static int[,] commonLength;
        static char[] charS;
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            Program.commonLength = new int[N, N];
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    Program.commonLength[i, j] = -1;
                }
            }
            Program.charS = S.ToCharArray();

            for (int i = 0; i < N - 1; i++)
            {
                for (int j = i + 1; j < N; j++)
                {
                    int tmpLength = Program.GetCommonLength(i, j);
                }
            }

            int maxCommonLength = 0;
            for (int i = 0; i < N - 1; i++)
            {
                for (int j = i + 1; j < N; j++)
                {
                    Program.commonLength[i, j] = Math.Min(Program.commonLength[i, j], j - i);
                    maxCommonLength = Math.Max(maxCommonLength, Program.commonLength[i, j]);
                }
            }
            Console.WriteLine(maxCommonLength);
        }
        public static int GetCommonLength(int i, int j)
        {
            if (Math.Max(i, j) >= Program.charS.Length)
            {
                return 0;
            }
            if (Program.commonLength[i, j] > 0)
            {
                return Program.commonLength[i, j];
            }
            else if (Program.charS[i] != Program.charS[j])
            {
                Program.commonLength[i, j] = 0;
                return 0;
            }
            else
            {
                Program.commonLength[i, j] = 1 + Program.GetCommonLength(i + 1, j + 1);
                return Program.commonLength[i, j];
            }
        }
        // public static int GetCommonLength(int i, int j)
        // {
        //     if (Math.Max(i, j) >= Program.charS.Length)
        //     {
        //         return 0;
        //     }
        //     if (Program.commonLength[i, j] > 0)
        //     {
        //         return Program.commonLength[i, j];
        //     }
        //     else if (Program.charS[i] != Program.charS[j])
        //     {
        //         Program.commonLength[i, j] = 0;
        //         return 0;
        //     }
        //     else
        //     {
        //         Program.commonLength[i, j] = 1 + Program.GetCommonLength(i + 1, j + 1);
        //         return Program.commonLength[i, j];
        //     }
        // }
        
    }
}


Measured memory_bytes: 109516
import java.util.Scanner;

/**
 * Deque
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            long[] A = new long[N];
            for (int i = 0; i < N; i++) {
                A[i] = sc.nextLong();
            }

            long[][] dp = new long[N][N];
            for (int i = 0; i < N; i++) {
                dp[i][i] = A[i] * (N % 2 == 1 ? 1 : -1);
            }

            for (int k = 1; k < N; k++) {
                for (int i = 0; i < N; i++) {
                    if (i + k >= N) {
                        break;
                    }

                    if ((N - k) % 2 == 1) {
                        dp[i][i + k] = Math.max(dp[i][i + k - 1] + A[i + k], dp[i + 1][i + k] + A[i]);
                    } else {
                        dp[i][i + k] = Math.min(dp[i][i + k - 1] - A[i + k], dp[i + 1][i + k] - A[i]);
                    }
                }
            }

            System.out.println(dp[0][N - 1]);
        }
    }

}


Measured memory_bytes: 128504
#include <iostream>
#include <vector>
#include <string>

using namespace std;

class NODE {
public:
	int k, p=0, r=0, l=0;
	NODE(int key) {
		this->k = key;
	}
};

vector<NODE> A;

void maxHeapify(int H, int i) {
	int largest, l = 2*i, r = 2*i+1;

	if (l <= H && A[l].k > A[i].k) largest = l;
	else largest = i;
	if (r <= H && A[r].k > A[largest].k) largest = r;

	if (largest != i) {
		NODE B = A[i]; A[i] = A[largest]; A[largest] = B;
		maxHeapify(H, largest);
	}
}

void buildMaxHeap(int H) {
	for (int i = H / 2; i > 0; i--) {
		maxHeapify(H, i);
	}
}

int main() {
	int H, key;
	cin >> H;
	NODE z(0); A.push_back(z);
	for (int i = 1; i <= H; i++) {
		cin >> key;
		NODE z(key); A.push_back(z);
	}

	buildMaxHeap(H);

	for (int i = 1; i <= H; i++) {
		cout << " " << A[i].k;
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 11088