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

using namespace std;

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

	long long n;
	cin >> n;
	map<long long, int> mp;
	for(long long i =2; i*i<=n; ++i) {
		if (n % i == 0) {
			int cnt = 0;
			while(n % i == 0) cnt++, n /= i;
			mp[i] = cnt;
		}
	}
	if (n > 1) mp[n] = 1;
	int ans = 0;
	for(auto [f, s] : mp) {
		for(int i =1; s >= i; ++i) {
			s -= i;
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define all(a)  (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  int H,W; cin >> H >> W;
  vector<string> s(H);
  rep(i, H) cin >> s[i];

  //int L[H][W] = {},R[H][W] = {},U[H][W] = {},D[H][W] = {};
  vvi L(H,vi(W,0)), R(H,vi(W,0)), D(H,vi(W,0)), U(H,vi(W,0));
  rep(h, H) rep(w, W){
    if(s[h][w] != '#'){
      if(w == 0) L[h][w] = 1;
      else L[h][w] = L[h][w-1] + 1;

      if(h == 0) U[h][w] = 1;
      else U[h][w] = U[h-1][w] + 1;
    }
  }

  for (int h = H-1; h >= 0; h--) for(int w = W-1; w >= 0; w--){
    if(s[h][w] != '#'){
      if(w == W-1) R[h][w] = 1;
      else R[h][w] = R[h][w+1] + 1;

      if(h == H-1) D[h][w] = 1;
      else D[h][w] = D[h+1][w] + 1;
    }
  }

  int ans = 0;
  rep(h, H) rep(w, W){
    chmax(ans,L[h][w] + R[h][w] + U[h][w] + D[h][w] - 3);
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 67200
/*
	不同颜色出现次数
	并不需要记录一个区间的颜色状态压位,转移不了
	只需要记录最后一个颜色出现在哪里就好了
*/
#include <iostream>
#include <cstdio>
#include <vector>
#define N 305

using namespace std;

const int mod = 1e9 + 7;

int n, m, cur;
int f[N][N][N], ans;
bool iscalc[N][N][N];

vector <pair<int, int> > q[N];

inline void inc(int &x, int y) { if((x += y) >= mod) x -= mod; }

void modify(int a, int b, int c) {
	if(iscalc[a][b][c] || !f[a][b][c]) return;
	iscalc[a][b][c] = true;
//	printf("%d %d %d : %d\n", a, b, c, f[a][b][c]);
	if(cur == n + 1) return inc(ans, f[a][b][c]);
	inc(f[cur][b][c], f[a][b][c]);
	inc(f[a][cur][c], f[a][b][c]);
	inc(f[a][b][cur], f[a][b][c]);
	return;
}

int main() {
	cin >> n >> m;
	for(int i = 1, l, r, x; i <= m; ++i) {
		cin >> l >> r >> x;
		q[r].push_back(make_pair(l, x));
	}
	
	f[0][0][0] = 1;
	for(int o = 0; o <= n; ++o) {
		cur = o + 1;
		for(int i = q[o].size() - 1; ~i; --i) {
			int l = q[o][i].first, x = q[o][i].second;
			for(int j = 0; j <= o; ++j)
				for(int k = 0; k <= o; ++k) {
					if( (j >= l) + (k >= l) + 1 != x ) {
						f[o][j][k] = 0;
						f[j][o][k] = 0;
						f[j][k][o] = 0;
					}
				}
		}
		for(int j = 0; j <= o; ++j) {
			for(int k = 0; k <= o; ++k) {
				modify(o, j, k);
				modify(j, o, k);
				modify(j, k, o);
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 137472
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n; cin >> n;
	vector<int>l;
	int sum = 0;
	for (int i = 0; i < n; i++){
		int s; cin >> s;
		l.push_back(s);
		sum += s;
	}
	if (sum % 10 == 0) {
		sort(l.begin(), l.end());
		for (int i = 0; i < n; i++){
			if (l[i] % 10 != 0) {
				cout << sum - l[i] << endl;
				return 0;
			}
		}
		cout << 0 << endl;
	}
	else cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

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

Measured memory_bytes: 256
import math
 
n,k = map(int, input().split())
 
def main(i):
  blue = math.factorial(k-1) // (math.factorial(i-1) * math.factorial(k-i))
  red = math.factorial(n-k+1) // (math.factorial(n-k+1-i) * math.factorial(i))
  print((blue*red) % (10**9 + 7))
 
for i in range(1, k+1):
  if i > n-k+1:
    print('0')
  else:
   main(i)

Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
int main() {
	string S;
	cin >> S;
	if (S.length() < 26) {
		string t = S;
		for (char c = 'a'; c <= 'z'; ++ c) {
			if (S.find(c) == string::npos) {
				t += c;
				break;
			}
		}
		cout << t << endl;
	} else {
		string t = "-1";
		for (int i = 24; i >= 0; -- i) {
			char c = 127;
			for (int j = i+1; j < 26; ++ j) {
				if (S[j] > S[i]) c = min(c, S[j]);
			}
			if (c != 127) {
				t = S.substr(0, i);
				t += c;
				break;
			}
		}
		cout << t << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort(all(vec));
#define rever(vec) reverse(all(vec));
#define bisea binary_search
#define unsort(vec) sort(vec); rever(vec)
#define cend cout<<endl;
#define gcd __gcd
using namespace std;
int aa[50][50]={0};
signed main(){
	int a,b,c,d,e=0;
	cin>>a>>b>>c>>d;
	rep(i,a+1){
		rep(j,b+1){
			rep(k,c+1){
				if(i*500+j*100+k*50==d){
					e++;
				}
			}
		}
	}
	cout<<e<<endl;
}
// anmichi & mutuhuhihusenonu かわいい
//sanadayukimura73はエロい
//駒場東邦の理科準備室でsex

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
//#define Local
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;

int n, k;

void run() {
    int p;
    for(int i = 1; i <= n; i++) {
        int x; cin >> x;
        if(x == 1) p = i;
    }
    int ans = N;
    for(int i = 1; i <= n; i++) {
        int l = i, r = min(n, i + k - 1);
        if(l <= p && p <= r)
            ans = min(ans, 1 + (l - 1 + k - 2) / (k - 1) + (n - r + k - 2) / (k - 1));
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
#ifdef Local
    freopen("../input.in", "r", stdin);
    freopen("../output.out", "w", stdout);
#endif
    while(cin >> n >> k) run();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    vector<vector<int>> dis(110,vector<int>(110,inf));
    map<pair<int,int>,int> mpi;
    int n,m; 
    cin >> n >> m;
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        dis[a][b]=c;
        dis[b][a]=c;
        mpi[{a,b}] = c;
        mpi[{b,a}] = c;
    }
    rep(k,n){
        rep(i,n){
            rep(j,n){
                dis[i][j] = min(dis[i][k]+dis[k][j],dis[i][j]);
                if(i==j) dis[i][j]=0;
            }
        }
    }
    set<pair<int,int>> spi;
    rep(i,n){
        rep(j,n){
            //cout << i+1 << " and " << j+1 << endl;
            //cout << dis[i][j] << endl << endl;

            for(auto u : mpi){

                //if(i==j) continue; 
                //cout << dis[i][u.first.first]<<" "<<dis[u.first.second][j]<<" "<<u.second << endl;
                if(dis[i][j] == dis[i][u.first.first]+dis[u.first.second][j] + u.second){
                   // cout << dis[i][u.first.first]+dis[u.first.second][j] + u.second << endl;
                    //cout << u.first.first+1 << " " << u.first.second+1 << endl << endl;
                    if(u.second!=0) spi.insert({u.first.first,u.first.second});
                    //spi.insert({u.first.second,u.first.first});
                }
            }
        }
    }
    //cout << spi.size() << endl;
    cout << m - (int)spi.size()/2 << endl;
    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

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

int main(void){
    int N; cin >> N;
    VI d(N); REP(i,N) cin >> d[i];
    VI S(100001,0); REP(i,N) S[d[i]]++;
    REP(i,100000) S[i+1] += S[i];

    int ans = 0;
    REP(i,100001) if(S[i] == N-S[i]) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define REP(i,n)  for(int i=0;i<(n);i++)

int main() {
    int n,a,b,now=0,kai=1;
    cin>>n >>a >>b;
    string s; cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='c')cout<<"No"<<endl;
        else if(s[i]=='a'){
            if(now<a+b){
                cout<<"Yes"<<endl;
                now++;
            }else{
                cout<<"No"<<endl;
            }
        }else if(s[i]=='b'){
            if(now<a+b&&kai<=b){
                cout<<"Yes"<<endl;
                now++;
                kai++;
            }else{
                cout<<"No"<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 896
# coding: utf-8
 
N  = int(input())
sum = 0
 
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
for i in range (N):
    for j in range(N):
        for k in range(N):
            sum += gcd(*[i+1, j+1, k+1])
 
print(sum)

Measured memory_bytes: 69548
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define repe(i,x) for (edge *i=fst[x]; i; i=i->nxt)
using namespace std;

typedef long long LL;
int n,m,u,v,dep[100100],w[100100],a[100100],tot;
LL ans;
struct edge
{
    int v;
    edge *nxt;
} pool[200100],*tp=pool,*fst[100100];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

void dfs1(int x,int fa)
{
    dep[x]=dep[fa]+1,w[x]=-w[fa];
    repe(i,x)
        if (i->v!=fa)
            if (dep[i->v])
                u=x,v=i->v;
            else
                dfs1(i->v,x);
}

bool dfs2(int x,int fa)
{
    bool flag=x==u || x==v;
    dep[x]=1;
    repe(i,x)
        if (!dep[i->v])
            flag^=dfs2(i->v,x),w[x]+=w[i->v];
    if (flag)
        a[++tot]=w[x];
    else
        ans+=abs(w[x]);
    return flag;
}

int main()
{
    scanf("%d%d",&n,&m);
    repu(i,1,m)
    {
        u=getint(),v=getint();
        *tp=(edge){v,fst[u]},fst[u]=tp++;
        *tp=(edge){u,fst[v]},fst[v]=tp++;
    }
    if (n&1)
    {
        puts("-1");
        return 0;
    }
    w[0]=1,dfs1(1,0);
    int sum=0;
    repu(i,1,n)
        sum+=w[i];
    if (sum && (m<n || ((dep[u]-dep[v])&1)))
    {
        puts("-1");
        return 0;
    }
    if (m<n)
        u=v=0;
    if (m==n && !((dep[u]-dep[v])&1))
        w[u]-=sum/2,w[v]-=sum/2,ans=abs(sum/2),u=v=0;
    memset(dep,0,sizeof(dep));
    tot=1,dfs2(u?u:1,0),nth_element(a+1,a+tot/2,a+1+tot);
    repu(i,1,tot)
        ans+=abs(a[i]-a[tot/2]);
    printf("%lld\n",ans);
    return 0;
}

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

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}

};

int main() {
	int n, in, ans =INF;
	cin >> n;
	rep(i, n) {
		int count = 0;
		cin >> in;
		while (in % 2 == 0) {
			count++;
			in /= 2;
		}
		ans = min(ans, count);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

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

    string S;

    cin >> S;

    int count = 1;

    char last = S[0];

    for(int i = 1; i < S.length(); i++) {
        if(last == S[i]) {
            if(i == S.length() - 2) {
                count++;
                break;
            }
            if(i == S.length() - 1) {
                break;
            }
            i += 2;
            count += 2;
            last = S[i];
        } else {
            count++;
            last = S[i];
        }    
    }

    cout << count << endl;
}

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


int main()
{


     ios_base::sync_with_stdio(false);
     cin.tie(NULL);

    int t=1;
    while(t--)
    {
      
      int count;
      cin>>count;
      int flag=0;
      while(count>0)
      {
        int temp=count%10;
        if(temp==7)
          flag=1;
        count/=10;
      }
      if(flag)cout<<"Yes"<<endl;
      else
        cout<<"No"<<endl;

    }

return 0;

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;
#define fori(i,a,b) for(ll i=(a);i<=(b);i++)
#define repi(i,n) fori(i,0,(n)-1)
#define forr(i,a,b) for(ll i=(b);i>=(a);i--)
#define repr(i,n) forr(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
#define fill(a,x) memset(a,x,sizeof(a))
#define vec vector<ll>
#define pb push_back
#define mp make_pair
#define pcnt __builtin_popcount
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

#define N 105
#define M 100005
ll a[N];
bool win[M];
void solve(){
    ll n,k;cin>>n>>k;
    repi(i,n)cin>>a[i];
    fori(i,1,k){
        repi(j,n){
            if(i-a[j]>=0&&!win[i-a[j]]){
                win[i]=true;
                break;
            }
        }
    }
    cout<<(win[k]?"First":"Second")<<endl;
}

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


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

#define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
typedef long long ll ;
typedef long double ldb ;
 
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define nl "\n"
 
#define all( x ) x.begin(),x.end()
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

bool isPalin(string s) {
	string t(s.rbegin(), s.rend());
	return s == t;
}

int main( ) {
	timesaver ;
	string s;
	cin >> s;
	int l = s.length();
	if(isPalin(s) && isPalin(s.substr(0, (l - 1) / 2)) && isPalin(s.substr((l + 1)/2)))
		cout << "Yes";
	else 
		cout << "No";
	return 0;
}

Measured memory_bytes: 256
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 105
#define fi(a, b, c, d) for(int a = b; i < c; i += d)
#define fl(a, b, c, d) for(ll a = b; i < c; i += d)
#define quit exit(0)

ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
map<ll, ll> cache[5];
vector<ll> V;
set<ll> S;

int main() {
	scanf("%lld %lld", &N, &M);
	for(int i = 1; i <= N; i++) {
		scanf("%lld %lld", &arr[i], &arr1[i]);
	}
	ll X = 0;
	cache[0][0] = 0;
	for(int i = 1; i <= N; i++) {
		ll Y = X;
		X ^= 1;
		cache[X].clear();
		for(auto x: cache[Y]) {
			cache[X][x.ff] = max(cache[X][x.ff], x.ss);
			if(x.ff + arr[i] <= M) {
				cache[X][x.ff + arr[i]] = max(cache[X][x.ff + arr[i]], x.ss + arr1[i]);
			}
		}
	}
	ll ans = 0;
	for(auto x: cache[X]) {
		ans = max(ans, x.ss);
	}
	printf("%lld\n", ans);

	return 0;
}
/*
	Powered by Buggy Plugin
*/




Measured memory_bytes: 512
/**
*    created: 09.07.2020 00:52:04
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

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

    int n;
    cin >> n;
    vector<string> v(n);
    rep(i,n) cin >> v[i];
    string m = v[0];
    rep(i,n) if (v[i].size() < m.size()) m = v[i];
    map<char,int> mp;
    rep(i,m.size()) mp[m[i]]++;
    for (auto p : mp) {
        bool ok = true;
        int num = p.second;
        rep(i,n) {
            string t = v[i];
            int cnt = 0;
            rep(j,t.size()) if (t[j] == p.first) cnt++;
            if (cnt == 0) ok = false;
            else  chmin(num,cnt);
        }
        if (!ok) continue;
        else rep(i,num) cout << p.first; 
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3648
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n;
    cin>>n;
    rep(i,0,n-1){
        rep(j,i+1,n-1){
            ll x=i^j;
            ll k=0;
            while((x&(1<<k))==0) k++;
            cout<<k+1<<" ";
        }
        cout<<endl;
    }   
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int a,b,c,d,e,f;
  while(cin>>a>>b>>c>>d>>e>>f,a||b||c||d||e||f){
    int sum=100;
    sum+=a*15+b*15+c*7+d*2;
    int kai=f-e;
    sum-=3*kai;
    int bau=5*a+3*b;
    sum+=bau*16;
    cout<<sum<<endl;
  }
}

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

#define MAX_N 100000

int n;
int t;

void solve(){
    int *a;
    int *diff;
    int *mins;
    a = new int[n];
    diff = new int[n];
    mins = new int[n];

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

    for(int i = 0; i < n - 1; i++){
        mins[i] = min(tmp_min, a[i]);
        tmp_min = mins[i];
    }

    diff[0] = 0;
    int max_diff = 0;

    for(int i = 1; i < n; i++){
        diff[i] = a[i] - mins[i - 1];
        max_diff = max(max_diff, diff[i]);
    }

    int count = 0;
    for(int i = 1; i < n; i++){
        if (diff[i] == max_diff) count++; 
    }
    cout << count << endl;
    return ;
}


int main(){
    cin >> n >> t;
    solve();
    return 0;
}


Measured memory_bytes: 1408
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

n, start = map(int, input().split())
x = list(map(int, input().split()))
x.append(start)
x.sort()
# print(x)
gaps = []
for i in range(n):
    gaps.append(x[i + 1] - x[i])
# print(gaps)
if len(gaps) == 1:
    print(gaps[0])
else:
    ans = reduce(gcd, gaps)
    print(ans)


Measured memory_bytes: 16260
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

int e[100005];
int o[100005];

int main(){
  int n;
  cin>>n;
  for(int t=0;t<n;t++){
    int temp;
    cin>>temp;
    if(t%2==0){
      o[temp]++;
    }else{
      e[temp]++;
    }
  }
  int om=0,em=0;
  for(int t=0;t<100001;t++){
    if(o[t]>o[om])om=t;
    if(e[t]>e[em])em=t;
  }

  sort(o,o+100005,greater<int>());
  sort(e,e+100005,greater<int>());
  if(om==em){
    if(o[0]+e[1]>o[1]+e[0]){
      cout<<n-o[0]-e[1]<<"\n";
    }else{
      cout<<n-o[1]-e[0]<<"\n";
    }
  }else{
    cout<<n-o[0]-e[0]<<"\n";
  }
  return 0;
}


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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define llrp(i,n) for(long long i=0;i<n;i++)
#define llrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define vcin(a); rp(i,a.size()){cin>>a[i];}
#define vcout(a); rp(i,a.size()){cout<<a[i]<<endl;}
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;

bool isOK(int index, int key,vi a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key,vi a) {
    int left = -1;
    int right = (int)a.size();
    while (right - left > 1) {
        int mid = left + (right - left) / 2;
        
        if (isOK(mid, key,a)) right = mid;
        else left = mid;
    }
    return right;
}

int modpow(int a,int b,int p){
    if(b==0){
        return 1;
    }elif(b%2==0){
        return modpow((a*a)%p,b/2,p);
    }else{
        return (a*modpow(a,b-1,p))%p;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    S s;
    cin >> s;
    stack<char> ans;
    ans.push(s.at(0));
    rep(i,1,s.size()-1){
        if(s.at(i)=='S'){
            ans.push('S');
        }else{
            if(ans.size()==0){
                ans.push('T');
            }elif(ans.top()=='S'){
                ans.pop();
            }else{
                ans.push('T');
            }
        }
    }
    cout << ans.size() << endl;
    return 0;
}


Measured memory_bytes: 720
def main():
    s = input()
    t = input()
    s_len, t_len = len(s), len(t)

    def gen():
        for left in range(0, s_len - t_len + 1):
            edit = sum((c_s != c_t) for c_s, c_t in zip(s[left:], t))
            yield edit
    return min(gen())


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 9100
#include "stdio.h"

int main(){
    int a[5];
    int i,j,k;
    int ret = 0;
    scanf("%d",&a[0]);
    scanf("%d",&a[1]);
    scanf("%d",&a[2]);
    scanf("%d",&a[3]);
    scanf("%d",&a[4]);
    scanf("%d",&k);
    for(i=0;i<4;i++){
        for(j=i;j<5;j++){
            if((a[j]-a[i])>k){
                ret++;
            }
        }
    }
    if( ret == 0 ){
        printf("Yay!\n");
    }else{
        printf(":(\n");
    }

    return 0;
}


Measured memory_bytes: 128
def solve():
    for Cx in range(101):
        for Cy in range(101):
            div = 0
            for i in range(N):

                xi, yi, hi = xyh[i]

                if 0 < hi:
                    h = abs(xi - Cx) + abs(yi - Cy) + hi
                    if div in [0, 2]:
                        H = h
                        div = 1
                    else:
                        if (H != h):
                            div = 2
                            break

            if div == 2:
                continue

            for i in range(N):
                xi, yi, hi = xyh[i]

                if 0 == hi:
                    h = abs(xi - Cx) + abs(yi - Cy)
                    if h < H:
                        div = 2
                        break

            if div == 2:
                continue

            return Cx, Cy, H


N = int(input())

xn = [0] * N
yn = [0] * N
hn = [0] * N

xyh = [[int(j) for j in input().split()] for i in range(N)]

Cx, Cy, H = solve()

print(Cx, Cy, H)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int i=0;
	while (1)
	{
		if (i % 2 == 0)
		{
			c -=b;
			if (c<= 0)
			{
				cout << "Yes";
				break;
			}
		}
		else
		{
			a -= d;
			if (a<= 0)
			{
				cout <<"No";
				break;
			}
		}
		i++;
	}
	return 0;
};

Measured memory_bytes: 3604
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    a.sort()
    c.sort()
    ans = 0
    for i in range(n):
        bi = b[i]
        j = bisect.bisect_left(a,bi)
        k = bisect.bisect_right(c,bi)
        ans += j*(n-k)
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 93156
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

int N;
int a[101010];
bool visit[101010];

signed main()
{
    cin >> N;
    REP(i,N) cin >> a[i+1];

    int ans = 0;
    int now = 1;
    while (now != 2) {
        visit[now] = true;

        now = a[now];
        if (visit[now]) {
            cout << -1 << endl;
            return 0;
        }

        ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>

using namespace std;

int main() {
	int h, w;
	cin >> h >> w;

	char a[110][110];
	char yl[110] = { 0 };
	char xl[110] = { 0 };

	for (int y = 0; y < h; y++) {
		cin >> a[y];
		for (int x = 0; x < w; x++) {
			char c = a[y][x];
			if (yl[y] == 0) {
				yl[y] = c;
			}
			if (xl[x] == 0) {
				xl[x] = c;
			}
			if (yl[y] != c) {
				yl[y] = 'Z';
			}
			if (xl[x] != c) {
				xl[x] = 'Z';
			}
		}
	}
	bool ff = false;
	for (int y = 0; y < h; y++) {
		ff = false;
		if (yl[y] == '.') continue;
		for (int x = 0; x < w; x++) {
			if (xl[x] == '.') continue;
			cout << a[y][x];
		}
		ff = true;
		cout << endl;
	}
	if(!ff)
		cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		System.out.println(res(n));
	}

	public static int res(int n) {
		if(n==1) {
			return 1;
		}

		return n+res(n-1);
	}
}




Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
template<typename T1, typename T2> using P = pair<T1,T2>;
template<typename T> using V = vector<T>;
struct edge { int from, to; int cost; };
bool operator< (const edge &edge1, const edge &edge2) { return edge1.cost < edge2.cost; };
const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const V<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}

bool check(int A, int B, int i) {
   if (i == 0) {
      return false;
   } else {
      return (A*B-1)/i - i > 0;
   }
}

int solve(int A, int B)
{
   int m, l = 0, r = A*B;
   while (r - l > 1) {
      m = (l + r) / 2;
      if (check(A, B, m)) {
         l = m;
      } else {
         r = m;
      }
   }

   int ans = 2*l;
   if (min(A, B) <= l) ans--;
   if ((A*B-1)/(l+1) == l+1 && min(A, B) != l+1) ans++;
   return ans;
}

signed main()
{
   int Q; cin >> Q;
   V<int> A(Q), B(Q);
   REP(i, Q) {
      cin >> A[i] >> B[i];
   }

   REP(i, Q) {
      cout << solve(A[i], B[i]) << endl;
   }

   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    vector<pair<ll,ll> > ans;
    ll ma=a[n-1];
    ll mi=a[0];
    for(int i=1;i<n-1;i++){
        if(a[i]<0){
            ans.pb(make_pair(ma,a[i]));
            ma-=a[i];
        }
        else if(a[i]==0){
            ans.pb(make_pair(ma,0));
        }
        else{
            ans.pb(make_pair(mi,a[i]));
            mi-=a[i];
        }
    }
    ans.pb(make_pair(ma,mi));
    cout << ma-mi <<endl;
    for(int i=0;i<n-1;i++){
        cout <<ans[i].first<<" "<<ans[i].second<<endl;
    }
    return 0;

}



Measured memory_bytes: 4336
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    ll N; cin>>N;
    string S; cin>>S;
    vector<set<int>> ns(N+1, set<int>());
    vector<set<P>> ps(N+1, set<P>());
    for(int i=N-1; i>0; i--){
        ns[i-1] = ns[i];
        ns[i-1].insert(S[i]-'0');
        ps[i-1] = ps[i];
        for(auto &x: ns[i]){
            ps[i-1].insert(P(S[i]-'0', x));
        }
    }
    //for(auto x: ns[0]){
        //cout << x << " ";
    //}
    //cout << endl;
    //for(auto x: ps[0]){
        //cout << x << endl;
    //}
    vector<int> pos(10, -1);
    for(int i=0; i<N; i++){
        int x = S[i] -'0';
        if(pos[x]<0) pos[x] = i;
    }
    ll res = 0;
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            for(int k=0; k<10; k++){
                if(pos[i]<0) continue;
                int x = pos[i];
                if(ps[x].count(P(j, k))) res++;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 204544
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

using Graph = vector<set<int>>;

set<int> bfs(int v, Graph &G){
    int n = G.size();
    vector<int> f(n, 0);
    f[v] = 1;
    queue<int> que;
    vector<int> prev(n, -1);
    que.push(v);
    while(!que.empty()){
        int u = que.front(); que.pop();
        f[u] = 1;
        bool cyc = 0;
        repe(i, G[u]){
            if(i == v){
                cyc = 1;
                break;
            }
        }
        if(cyc){
            set<int> ans;
            for(int j=u; j!=v; ){
                ans.insert(j);
                j = prev[j];
            }
            ans.insert(v);
            return ans;
        }
        repe(i, G[u])if(!f[i]){
            que.push(i);
            prev[i] = u;
        }
    }
    return set<int>();
}


int main(){
    fastcin();

    int n, m;
    cin >> n >> m;
    Graph G(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].insert(b);
    }
    set<int> ans;
    int sz = INF;
    rep(i, n){
        auto tmp = bfs(i, G);
        if(!tmp.empty() && tmp.size() < sz){
            sz = tmp.size();
            ans = tmp;
        }
    }
    if(sz == INF) cout << -1 << endl;
    else{
        cout << sz << endl;
        repe(i, ans) cout << i+1 << endl;
    }
}

Measured memory_bytes: 512
# coding: utf-8
# Your code here!
#import numpy as np
N = int(input())
A = list(map(int,input().split()))
table = []
 
for i, a in enumerate(A):
    table.append([a,i])
table.sort()
dp = [[0for i in range(N+1)]for j in range(N+1)]
for i in range(1,N+1):
    baby,pos = table.pop()
    dp[i][0]=dp[i-1][0]+baby*abs(pos-i+1)
    dp[0][i] = dp[0][i-1] + baby * abs(pos-(N-i))
    for x in range(1,i):
        y = i-x
        dp[x][y]= max(dp[x-1][y] + baby * abs(pos-x+1),dp[x][y-1] + baby * abs(pos-(N-y)))
print(int(max(dp[k][N-k] for k in range(N+1))))

Measured memory_bytes: 137152
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  double W,H,x,y;cin >> W >> H >> x >> y;
  int ans = 0;
  if(x==W/2.0 && y==H/2.0)ans = 1;
  cout << H*W/2.0 SP ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int X;
    cin >> X;

    int x = X;
    int cnt = 1;
    while (X % 360 != 0) {
        cnt++;
        X += x;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    sort(rALL(a));
    ll ans = 0;
    priority_queue<ll> pq;
    for(ll x:a){
        if(pq.empty()){
            pq.push(x);
        }else{
            ans += pq.top();pq.pop();
            rep(i,2)pq.push(x);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6872
//
//  main.cpp
//  ABC155D
//
#include <iostream>
#include <vector>
#include<algorithm> // sortを使う
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
ll N,K;
vector<ll>A;
// X未満を作ることができるペアの数がK個未満か？
bool fx(ll x) {
    ll count = 0;
    for (int i = 0; i < N; i++) {
// 正の場合
   if (0 <= A[i]) {
     ll l = -1;
     ll r = N;
     while (l + 1 < r) {
       ll border = (l + r) / 2;
       if (A[border] * A[i] < x) {
         l = border;
       } else {
         r = border;
       }
     }
     count += r;
   } else {
// 負の場合
     ll l = -1;
     ll r = N;
     while (l + 1 < r) {
       ll border = (l + r) / 2;
       if (A[border] * A[i] < x) {
         r = border;
       } else {
         l = border;
       }
     }
     count += N - r;
   }
   if (A[i] * A[i] < x) {
     count--;
   }
 }
 count /= 2;
  return count < K;
}
//
int main(int argc, const char * argv[]) {
    const ll INF=ll(1e18)+1; // 無限大の定義
    cin>>N>>K;
    A.resize(N);
    rep(i,N){
        cin>>A.at(i);
    }
    sort(A.begin(),A.end());
    ll left=-INF;
    ll right=INF;
    while(left+1<right){
        ll mid=(left+right)/2;
        if (fx(mid)) {
            left=mid;
        }else{
            right=mid;
        }
    }
    cout<<left<<endl;
    return 0;
}


Measured memory_bytes: 1792
function Main(input) {
    tmp = input.split(" ");
    sub = input.split("\n");
    var a = parseInt(tmp[0], 10);
    var b = parseInt(tmp[1], 10);
    var c = parseInt(tmp[2], 10);
    var d = parseInt(sub[1], 10);
    var arr = [a,b,c];
    arr.sort(function(z,n){
        if( z > n ) return -1;
        if( z < n ) return 1;
        return 0;
	});
    d++;
    //処理
    fint = arr[0];
	for (i=1;i<d;i++) {
			fint = fint*2;
	}
    result = (fint + arr[1] + arr[2])
    //結果
    console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Objects;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		// 自前の例
		assert Objects.equals(
				solve(4, 5, new int[][] { { 1, 4, 1 }, { 2, 3, 1 }, { 3, 2, 1 }, { 3, 4, 1 }, { 1, 2, 1 } }), "inf");
		// 問題の例
		assert Objects.equals(solve(3, 3, new int[][] { { 1, 2, 4 }, { 2, 3, 3 }, { 1, 3, 5 } }), "7");
		assert Objects.equals(solve(2, 2, new int[][] { { 1, 2, 1 }, { 2, 1, 1 } }), "inf");
		assert Objects.equals(solve(6, 5, new int[][] { { 1, 2, -1000000000 }, { 2, 3, -1000000000 },
				{ 3, 4, -1000000000 }, { 4, 5, -1000000000 }, { 5, 6, -1000000000 } }), "-5000000000");

		int n = cin.nextInt();
		int m = cin.nextInt();
		int[][] abcs = new int[m][];
		for (int i = 0; i < abcs.length; i++)
			abcs[i] = new int[] { cin.nextInt(), cin.nextInt(), cin.nextInt() };

		String ans = solve(n, m, abcs);
		cout.println(ans);
	}

	private static String solve(int n, int m, int[][] abcs) {
		// https://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm
		long[] dist = new long[n + 1];
		Arrays.fill(dist, Long.MAX_VALUE / 2);
		dist[1] = 0;
		int[][] edges = new int[abcs.length][];
		for (int i = 0; i < abcs.length; i++)
			edges[i] = new int[] { abcs[i][0], abcs[i][1], -abcs[i][2] };
		for (int i = 2; i < dist.length; i++)
			for (int[] e : edges)
				dist[e[1]] = Math.min(dist[e[1]], dist[e[0]] + e[2]);
		long ans = dist[n];
		// negative-weight cycleの扱いがwikiと違う理由
		// wikiの場合、グラフの中のどこかに含まれるとアウト
		// この問題の場合、1-nの経路の中に含まれるとアウト
		for (int[] e : edges)
			dist[e[1]] = Math.min(dist[e[1]], dist[e[0]] + e[2]);
		if (ans != dist[n])
			return "inf";

		return Long.toString(-ans);
	}

	/**
	 * How to read input in Java — tutorial <br />
	 * By Flatfoot<br />
	 * http://codeforces.com/blog/entry/7018
	 */
	static class FastScanner {
		private BufferedReader br;
		private StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new IllegalStateException(e);
				}
			return st.nextToken();
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				throw new IllegalStateException(e);
			}
			return str;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


Measured memory_bytes: 23892
// https://atcoder.jp/contests/abc169/tasks/abc169_e
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int const maxn = 2e5;
int A[maxn], B[maxn];

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

  rep(i, N) { cin >> A[i] >> B[i]; }
  sort(A, A + N);
  sort(B, B + N);

  int ml, mh;
  if (N % 2 == 1) {
    ml = A[N / 2];
    mh = B[N / 2];
  } else {
    ml = A[N / 2] + A[N / 2 - 1];
    mh = B[N / 2] + B[N / 2 - 1];
  }

  cout << mh - ml + 1;
}

Measured memory_bytes: 5124
import math
N = int(input())
sqrtN = int(math.sqrt(float(N)))

ans = 0
prefnum = []

for div in range(1, sqrtN+1):
  if( N % div == 0):
    quot = int(N/div)
    if((quot-1) > div):
      prefnum.append(int(quot-1))
      
for i in prefnum:
  ans = ans + i

print(ans)

Measured memory_bytes: 3064
import queue

n,x,y = map(int,input().split())
x -= 1
y -= 1
l = [0] * n
for i in range(n):
    for j in range(i+1,n):
        d = min([abs(j-i),abs(x-i)+1+abs(j-y),abs(y-i)+1+(j-x)])
        l[d] += 1
for i in range(1,n):print(l[i])

Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
int n,N,m,ans,ANS,DFN;
char s1[5000050],s2[5000050];
int f[5000050],b[5000050],l[5000050],dfn[5000050],len[5000050];

int main()
{
	int i,j,t;
  scanf("%s",s1+1),n=strlen(s1+1);
  scanf("%s",s2+1),m=strlen(s2+1);
  N=n;
  while(N<=2*m)
    {
	  for(i=1;i<=n;i++) s1[N+i]=s1[i];
	  N+=n;
	}
  for(i=1;i<=N;i++) s1[N+i]=s1[i];
  N*=2;
  j=0;
  for(i=2;i<=N;i++)
    {
	  while(s2[j+1]!=s2[i] && j) j=f[j];
	  if(s2[j+1]==s2[i]) f[i]=j+1,j++;
	}
  j=0;
  for(i=1;i<=N;i++)
    {
	  while(s2[j+1]!=s1[i] && j) j=f[j];
	  if(s2[j+1]==s1[i]) l[i]=j+1,j++;
	  if(j==m) j=f[j];
	}
	i=1;
  for(i=1;i<=N;i++) 
    if(l[i]==m && m!=1) 
	  l[i-m+1]=m,l[i]=0; 
  for(i=1;i<=n;i++)
    {
	  if(l[i]==m)
	    {
	      t=i;
	      ans=0,++DFN;
		  while(1)
		    {
		      if(b[i]||l[i]!=m) {ans+=len[i];break;}
			   dfn[i]=DFN;
			  b[i]=1,ans++;
			  i=(i+m-1)%n+1;
			}
		  if(dfn[i]==DFN){printf("-1\n");return 0;}
		  len[t]=ans;
		  ANS=max(ans,ANS);
		  i=t;
		}
	}
  printf("%d\n",ANS);
}

Measured memory_bytes: 32896
main=do
 [n,m]<-map read.words<$>getLine
 a<-map read.words<$>getLine
 let b=map f$a
 let ans=if all(b!!0==)b then (`div`2)(foldl1 lcm a) else -1
 print$if ans== -1 then 0 else if ans>m then 0 else ((m`div`ans)+1)`div`2
f k
 |k`mod`2==0=1+f(div k 2)
 |True=0

Measured memory_bytes: 56700