akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	res := false
	for i := 0; i <= (N%28)/4; i++ {
		if (N-4*i)%7 == 0 && (N-4*i)/7 >= 0 {
			res = true
			break
		}
	}
	if res {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
sub func{
    my$f=shift;
    my$s=0;my$c=0;
    for(@A){
        $s+=$_;
        if($s*$f<1){
            $c+=abs($s)+1;
            $s=$f
        }
    $f*=-1;
    }
    return $c;
}
$n=<>;@A=glob<>;
$p=&func(1);
$q=&func(-1);
$e=($p<$q)?$p:$q;
print$e

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

const int MAX_N = 1000005;
int N;
int as[MAX_N], bs[MAX_N], cs[MAX_N];
int mem[MAX_N][4];

int dp(int day, int prev) {
  if (day == N) return 0;
  if (mem[day][prev] != -1) return mem[day][prev];

  int best = 0;
  if (prev != 1) best =
    std::max(best, dp(day+1, 1) + as[day]);
  if (prev != 2) best =
    std::max(best, dp(day+1, 2) + bs[day]);
  if (prev != 3) best =
    std::max(best, dp(day+1, 3) + cs[day]);
  mem[day][prev] = best;
  return best;
}

int main() {
  memset(mem, -1, sizeof(mem));
  scanf("%d", &N);
  for (int i = 0; i < N; ++i)
    scanf("%d %d %d", as + i, bs + i, cs + i);

  printf("%d\n", dp(0, 0));
}


Measured memory_bytes: 25156
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define ALL(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

int ctoi(const char c) {
	return c - '0';
}
int keta(int a) {
	return to_string(a).size();
}

signed main() {
	int n, m;
	cin >> n >> m;
	if (n == m)cout << "Yes" << endl;
	else cout << "No" << endl;
	
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
neg = len([x for x in a if x < 0])
# print(neg)
pos = []
for ai in a:
    pos.append(abs(ai)) 
pos.sort()

ans = sum(pos)
if neg % 2 != 0:
    ans -= pos[0] * 2

print(ans)

Measured memory_bytes: 15020
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


void solve() {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    for (int i = 0; i < K; i++) {
        vector<int> imos(N+1);
        for (int j = 0; j < N; j++) {
            int l = max(0, j - A[j]);
            int r = min(N, j + A[j] + 1);
            imos[l]++; imos[r]--;
        }

        vector<int> sum(N);
        sum[0] = imos[0];
        for (int j = 1; j < N; j++) sum[j] = sum[j-1] + imos[j];

        if (A == sum) break;

        A = sum;
    }

    for (int i = 0; i < N; i++) {
        cout << A[i] << endl;
    }
}


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

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

#ifdef DEBUG
    #include "debug.h"
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define dump(...)
#endif


// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

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

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

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)




void solve(){
    int A, B, C;
    int K;
    cin >> A >> B >> C >> K;
    int c = 0;
    while(A>=B){
        B*=2;
        c++;
    }
    while(B>=C){
        C*=2;
        c++;
    }
    if(c<=K) Yes;
    else No;
}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000
#define PII pair<int, int>
#define VPII vector<pair<int,int> >

int dijkstra(int n, const vector<vector<int> >& edge, int s, int g) {
  vector<bool> used(n, false);
  vector<int> dist(n, INF);
  dist[s] = 0;
  priority_queue<PII, VPII, greater<PII > >q;
  q.push(make_pair(0, s));
  while(q.size() > 0) {
    PII v = q.top(); q.pop();
    int current = v.second;
    used[current] = true;
    for (int i = 0; i < n; i++) {
      if (edge[current][i] != INF) {
	dist[i] = min(dist[i], dist[current] + edge[current][i]);
	if (!used[i]) {
	  q.push(make_pair(dist[i], i));
	}
      }
    }
  }
  return dist[g];
}

int main() {
  int n, m;
  cin >> n;
  cin >> m;
  vector<vector<int> > edge(n, vector<int>(n, INF));
  for (int i = 0; i < m; i++) {
    int a, b, c, d;
    scanf("%d,%d,%d,%d\n", &a, &b, &c, &d);
    a--; b--;
    edge[a][b] = c;
    edge[b][a] = d;
  }
  int s, g, V, P;
  scanf("%d,%d,%d,%d\n", &s, &g, &V, &P);
  s--; g--;
  int outward = dijkstra(n, edge, s, g);
  int homeward = dijkstra(n, edge, g, s);
  cout << V - P - outward - homeward << endl;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	
  	ll n , w;
  	cin>>n>>w;
  	ll arr[n+10],i, vi , wi, val[n+10],j;
  	for(i=0;i<n;i++){
  		cin>>wi>>vi;
  		arr[i+1]=wi;
  		val[i+1]=vi;
  	}
  	ll dp[w+10][n+10];
  	memset(dp,0,sizeof(dp));
  	for(i=1;i<=w;i++){
  		for(j=1;j<=n;j++){
  			if(i<arr[j])
  				dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
  			else
  			    dp[i][j]=max(dp[i-1][j-1],dp[i-arr[j]][j-1] + val[j]);
  		}
  	}
  	// for(i=0;i<=w;i++){
  	// 	for(j=0;j<=n;j++)
  	// 		cout<<dp[i][j]<<" ";
  	// 	cout<<"\n";
  	// }
  	cout<<dp[w][n]<<" ";
  	return 0;
  	
}

Measured memory_bytes: 89488
#include<stdio.h>
int main(){

  int i,j,n,q,S[100001],T[50001];

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

  scanf("%d", &q );
  for ( i = 0; i < q; i++ ){
    scanf("%d", &T[i] );
  }

  int left,mid,right,key,cnt;
  cnt = 0;

  for ( i = 0; i < q; i++ ){

    left = 0;
    right = n - 1;
    key = T[i];

    while( left < right ){

      if ( key == S[right] ){
	cnt += 1;
	break;
      }

      mid = ( left + right ) / 2;

      if ( S[mid] > key ){
	right = mid;
      } else if ( S[mid] < key ){
	left = mid + 1;
      } else {
	cnt +=1;
	break;
      }

    }

  }

  printf("%d\n", cnt );
  
  return 0;
  
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	long long n,ans=0;
	long long a[100005],b[100005],c[100005],d[100005]={};
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	for(int i=0;i<n;i++){
		cin>>c[i];
	}
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	
	for(int i=n-1;i>=0;i--){
		auto d1=lower_bound(c,c+n,b[i]+1)-c;
		d[i]+=n-d1;
		d[i]+=d[i+1];
	}
	for(int i=0;i<n;i++){
		auto m=lower_bound(b,b+n,a[i]+1)-b;
		ans+=d[m];
	}
	/*
	for(int i=0;i<n;i++){
		auto m=upper_bound(c,c+n,b[i])-c;
		auto l=lower_bound(a,a+n,b[i])-a;
		m=n-m;
		ans+=m*l;
	}
	*/
	cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 6752
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int d[N];
  for(int i=0;i<N;i++){
    cin >> d[i];
  }
  
  sort(d,d+N);
  cout << d[N/2]-d[N/2-1];
  return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define int long long

const int N=6005,mod=998244353;
int fac[N],inv[N],n,m,ans;

int C(int n,int m){
	if(n<m||m<0) return 0;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

int fpow(int x,int y){
	int res=1;
	for(;y;y>>=1,x=x*x%mod) if(y&1) res=res*x%mod;
	return res;
}

void init(int n){
	fac[0]=1;for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
	inv[n]=fpow(fac[n],mod-2);for(int i=n-1;~i;i--) inv[i]=inv[i+1]*(i+1)%mod;
}

int calc(int n){
	int res=2*n<m||m&1;
	for(int i=n;i<n*2;i++){
		if(i<m) res=(res+C(n,i-n))%mod;
		else if(i-m&1){
			int p=i-m+1;
			res=(res+C(n-p,(i-p*2)-(n-p)))%mod;
		}
	}
	return res;
}

signed main(){
	read(n,m);
	init(6e3);
	for(int i=0;i<=n;i++) ans=(ans+C(n,i)*calc(n-i))%mod;
	write(ans);
}

Measured memory_bytes: 3772
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;


int N, K;
vector<int> G[2005];
int dist2[2005];

int cnt(int v){
  int n = 0;
  rep(i,N) dist2[i] = -1;
  queue< pair<int,int> > que;
  que.push(make_pair(v,0));
  while(!que.empty()){
    pair<int,int> p = que.front(); que.pop();
    if(dist2[p.first] != -1) continue;
    dist2[p.first] = p.second;
    n++;
    rep(i,G[p.first].size()){
      if(dist2[G[p.first][i]]==-1 && p.second+1<=K/2) que.push(make_pair(G[p.first][i],p.second+1));
    }
  }
  return N-n;
}
int cnt2(int v1, int v2){
  int n = 0;
  rep(i,N) dist2[i] = -1;
  queue< pair<int,int> > que;
  que.push(make_pair(v1,(K-1)/2));
  que.push(make_pair(v2,(K-1)/2));
  while(!que.empty()){
    pair<int,int> p = que.front(); que.pop();
    if(dist2[p.first] != -1) continue;
    dist2[p.first] = 1;
    n++;
    rep(i,G[p.first].size()){
      if(dist2[G[p.first][i]]==-1 && p.second>0 && G[p.first][i] != v1 && G[p.first][i] != v2)
        que.push(make_pair(G[p.first][i],p.second-1));
    }
  }
  return N-n;
}



int main(){
  ios::sync_with_stdio(false);
  cin >> N >> K;
  vector< pair<int,int> > in;
  rep(i,N-1){
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    G[A].push_back(B);
    G[B].push_back(A);
    in.push_back(make_pair(A,B));
  }
  int ret = N;
  if(K%2==0){
    rep(i,N){
      //cout << i << " " << cnt(i) << endl;
      ret = min(ret, cnt(i));
    }
  }else{
    rep(i,in.size()){
      ret = min(ret, cnt2(in[i].first, in[i].second));
    }
  }
  cout << ret << endl;
  return 0;
}



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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)
string multi[10000+5];
int T[200000+5];
int M[2019];

int main() {
    string S;
    cin >> S;
    ll S_len = (int) (S.length());
    T[S_len] = 0;
    M[0] = 1;
    ll beki = 1;
    FORD(i,S_len-1,0) {
        int num = stoi(S.substr(i,1));
        T[i] = (T[i+1] + num*beki)%2019;
        M[T[i]] += 1;
        beki = (beki*10)%2019;
    }

    ll count = 0;
    FOR(i,0,2019) {
        count += M[i]*(M[i]-1)/2;
    }
    cout << count << endl;
}

Measured memory_bytes: 4840
#include <cstdio>
#include <cstdlib>
using namespace std;
char s[10];
struct node {
	int key;
	node *p,*left,*right;
};
node *NIL,*root=NIL;
void ins (int key) {
	node *p=NIL,*cur=root,*n=(node *)malloc(sizeof(node));
	n->key=key;
	n->left=NIL;
	n->right=NIL;
	while (cur!=NIL) {
		p=cur;
		if (key<cur->key) cur=cur->left;
		else cur=cur->right;
	}
	n->p=p;
	if (p==NIL) root=n;
	else if (key<p->key) p->left=n;
	else p->right=n;
}
node* find (int key,node *cur) {
	while (cur!=NIL&&cur->key!=key) {
		if (key<cur->key) cur=cur->left;
		else cur=cur->right;
	}
	return cur;
}
void preOrder (node *u) {
	if (u==NIL) return;
	printf (" %d",u->key);
	preOrder (u->left);
	preOrder (u->right);
}
void inOrder (node *u) {
	if (u==NIL) return;
	inOrder (u->left);
	printf (" %d",u->key);
	inOrder (u->right);
}
int main () {
	int m;
	scanf ("%d",&m);
	for (int i=0;i<m;i++) {
		scanf ("%s",s);
		if (s[0]=='i') {
			int key;
			scanf ("%d",&key);
			ins (key);
		} else if (s[0]=='f') {
			int key;
			scanf ("%d",&key);
			if (find (key,root)!=NIL) printf ("yes\n");
			else printf ("no\n");
		} else {
			inOrder (root);
			printf ("\n");
			preOrder (root);
			printf ("\n");
		}
	}
    return 0;
}


Measured memory_bytes: 21428
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;



int main(){
    int N;cin >> N;
    int A,B;cin >> A >> B;
    vector<int> h(N);
    rep(i,N)cin >> h[i];

    auto check = [&](ll k){
        ll res = 0;
        rep(i,N){
            if(h[i]-k*B>0){
                res+=((h[i]-k*B)+(A-B)-1)/(A-B);
            }
        }
        if(res<=k)return true;
        else return false;
    };

    int left=0,right=1<<30;
    while(right>left){
        int mid = (left+right)/2;
        if(check(mid))right=mid;
        else left=mid+1;
    }

    cout << left << endl;
    return 0;
}

Measured memory_bytes: 640
n, k = map(int, input().split())

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

print(len(Base_10_to_n(n, k)))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i,n,x,k,p;
  cin>>n>>x;
  p=0;
  for(i=0; i<n; i++){
    cin>>k;
    p=p+k;
    if(p>x){
      break;
    }
  }
  i=i+1;
  cout<<i;
}

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

int dp[101][4][2];

int main(void) {
	string S;
	cin >> S;
	int K;
	cin >> K;

	dp[0][0][0] = 1;
	int x = S.length();
	for (int i = 0; i < x; i++) {
		for (int j = 0; j <= K; j++) {
			for (int k = 0; k <= 1; k++) {
				int nd = S[i] - '0';
				for (int next = 0; next <= 9; next++) {
					int ni = i+1, nj = j, nk = k;
					if (next != 0) nj++;
					if (nj > K) continue;
					if (k == 0) {
						if (next > nd) continue;
						if (next < nd) nk = 1;
					}
					dp[ni][nj][nk] += dp[i][j][k];
				}
			}
		}
	}
	int ans = dp[x][K][0] + dp[x][K][1];
	cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n,x,m = map(int, input().split())

ans = 0
f = [-1]*m # a->f
f[x] = 0

ansl = [x]
curr_x = x
loop_start = -1
for i in range(n-1):
    cnt = i+1
    x2 = (curr_x**2)%m
    if f[x2] == -1:
        ansl.append(x2)
        f[x2] = cnt
    else:
        loop_start = f[x2]
        break
    curr_x = x2
else:
    print(sum(ansl))
    exit()

amari = ansl[0:loop_start]

n_rem = n - loop_start
loop_l = ansl[loop_start:]
loop_len =len(loop_l)
loop_sum = sum(loop_l)

loop_cnt = n_rem//loop_len
loop_amari = n_rem - loop_cnt*loop_len

ans = sum(amari) + sum(loop_l)*loop_cnt + sum(loop_l[:loop_amari])
print(ans)

Measured memory_bytes: 69476
x, y, z = map(int, input().split())
lst = list(map(int, input().split()))
cnt = 0
for _ in range(x):
    lst_a = list(map(int, input().split()))
    total = z
    for i in range(y):
        total += lst[i] * lst_a[i]
    if total > 0:
        cnt += 1
print(cnt)


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

int main(){
    int n,m;
    cin >> n >> m;
    vector<long long> h(n);
    vector<int> flag(n);
    rep(i,n) flag[i] = 1;
    rep(i,n) cin >> h[i];
    rep(i,m){
        int a,b; cin >> a >> b;
        a--; b--;
        if(h[a]>h[b]){
            flag[b] = 0;
        }
        else if(h[a]<h[b]){
            flag[a] = 0;
        }
        else{
            flag[a]=0;
            flag[b]=0;
        }
    }
    int ans=0;
    rep(i,n){
        if(flag[i]) ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 4692
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	int value2,value1,value0;
};

struct Data{
	Data(int arg_music,int arg_new_num,int arg_level_1_num){
		music = arg_music;
		new_num = arg_new_num;
		level_1_num = arg_level_1_num;
	}
	int music,new_num,level_1_num;
};

int dp[51][51][51];
int next_dp[51][51][51];

int main(){

	int N,M;
	scanf("%d %d",&N,&M);

	Info info[N+1];

	for(int i = 1; i <= N; i++){
		scanf("%d %d %d",&info[i].value2,&info[i].value1,&info[i].value0);
	}

	for(int music = 0; music <= N; music++){
		for(int new_num = 0; new_num <= M; new_num++){
			for(int level_1_num = 0; level_1_num <= M; level_1_num++){
				dp[music][new_num][level_1_num] = -BIG_NUM;
				next_dp[music][new_num][level_1_num] = -BIG_NUM;
			}
		}
	}

	dp[0][M][0] = 0;
	next_dp[0][M][0] = 0;

	vector<Data> Updated;

	for(int music = 0; music <= N-1; music++){

		for(int new_num = 0; new_num <= M; new_num++){
			for(int level_1_num = 0; level_1_num <= M; level_1_num++){
				if(dp[music][new_num][level_1_num] == -BIG_NUM)continue;

				for(int oru_num = 0; oru_num <= new_num; oru_num++){

					if(next_dp[music+1][new_num-oru_num][oru_num] < dp[music][new_num][level_1_num]+info[music+1].value0){
						next_dp[music+1][new_num-oru_num][oru_num] = dp[music][new_num][level_1_num]+info[music+1].value0;
						Updated.push_back(Data(music+1,new_num-oru_num,oru_num));
					}

					for(int num_2 = 0; num_2 <= oru_num; num_2++){
						for(int num_1 = 0; num_1 <= level_1_num; num_1++){
							if(num_2+num_1 == 0 || num_2+num_1 > 8)continue;

							int satisfy = num_2*info[music+1].value2+num_1*info[music+1].value1;

							if(next_dp[music+1][new_num-oru_num][oru_num] < dp[music][new_num][level_1_num]+satisfy){
								next_dp[music+1][new_num-oru_num][oru_num] = dp[music][new_num][level_1_num]+satisfy;
								Updated.push_back(Data(music+1,new_num-oru_num,oru_num));
							}
						}
					}
				}
			}
		}

		for(int k = 0; k < Updated.size(); k++){
			dp[Updated[k].music][Updated[k].new_num][Updated[k].level_1_num] = next_dp[Updated[k].music][Updated[k].new_num][Updated[k].level_1_num];
		}
		Updated.clear();
	}

	int ans = -BIG_NUM;
	for(int new_num = 0; new_num <= M; new_num++){
		for(int level_1_num = 0; level_1_num <= M; level_1_num++){
			ans = max(ans,dp[N][new_num][level_1_num]);
		}
	}

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

	return 0;
}

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

int main() {
	int N, Q;
	string S;
	cin >> N >> S >> Q;
	vector<int> K(Q);
	for (auto& x : K) cin >> x;

	vector<int> pD;
	vector<int> cM(N), cC(N);
	vector<long long> hoge(N);

	int cntM = 0, cntC = 0;
	long long cnt = 0;
	for (int i = 0; i < N; ++ i) {
		if (S[i] == 'D') {
			pD.push_back(i);
		} else if (S[i] == 'M') {
			++ cntM;
		} else if (S[i] == 'C') {
			++ cntC;
			cnt += cntM;
		}

		cM[i] = cntM;
		cC[i] = cntC;
		hoge[i] = cnt;
	}

	for (int kk : K) {
		long long r = 0;
		for (auto p : pD) {
			int q = min(N-1, p + kk-1);
			long long cc0 = cC[p], cc1 = cC[q];
			long long cm0 = cM[p], cm1 = cM[q];
			long long hh0 = hoge[p], hh1 = hoge[q];
			long long x = (hh1-hh0) - (cc1-cc0)*cm0;
			//cerr << "D" << p << " C" << q << endl;
			//cerr << cc0 << " " << cc1 << endl;
			//cerr << cm0 << " " << cm1 << endl;
			//cerr << hh0 << " " << hh1 << endl;
			//cerr << x << endl;
			r += x;
		}
		cout << r << endl;
	}
}


Measured memory_bytes: 22524
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>
 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
 
int main() {
  string s, t;
  cin >> s >> t;
  int n = sz(s), m = sz(t);
  vector<vector<int>> is(26);
  rep(i,n) is[s[i]-'a'].push_back(i);
  rep(i,n) is[s[i]-'a'].push_back(i+n);
  ll ans = 0;
  int p = 0; // after p
  rep(i,m) {
    int c = t[i]-'a';
    if (sz(is[c]) == 0) {
      puts("-1");
      return 0;
    }
    p = *lower_bound(is[c].begin(), is[c].end(), p)+1;
    if (p >= n) {
      p -= n;
      ans += n;
    }
  }
  ans += p;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#define N_MAX 101

using namespace std;

int main(){

  while( 1 ){
    int n, m;
    int table[ N_MAX ][ N_MAX ];
    int possible[ N_MAX ];
    cin >> n;
    if( !n ){ return 0; }
    for( int i = 1; i <= n; i++ ){
      possible[ i ] = 1;
      for( int j = 1; j <= n; j++ ){
        table[ i ][ j ] = 0;
      }
    }

    for( int i = 1; i <= n; i++ ){
      cin >> m;
      for( int j = 0; j < m; j++ ){
        int temp;
        cin >> temp;
        table[ i ][ temp ] = 1;
      }
    }
    int k;
    cin >> k;
    for( int i = 0; i < k; i++ ){
      int temp;
      cin >> temp;
      for( int j = 1; j <= n; j++ ){
        if( !table[ j ][ temp ] ){
          possible[ j ] = 0;
        }
      }
    }
    int crimer = -1;
    int counter = 0;
    for( int i = 1; i <= n; i++ ){
      if( possible[ i ] ){
        crimer = i;
        counter++;
      }
      if( counter >= 2 ){
        crimer = -1;
        break;
      }
    }
    cout << crimer << endl;
  } 
}

Measured memory_bytes: 908
#include<iostream>
#include<algorithm>

using namespace std;

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

int main(){
    int n;
    cin >> n;
    pair<int, int> a[n];
    rep(i, n) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a, a + n);
    rep(i, n) cout << a[i].second + 1 << " ";
    cout << endl;

}

Measured memory_bytes: 1536
q, h, s, d = map(int, input().split())
n = int(input())

twoL = [q * 8, h * 4, s * 2, d]
twoL.sort()

if n % 2 == 0 :
    print(twoL[0] * (n // 2))
else :
    L = [q * 4, h * 2, s]
    L.sort()
    print(twoL[0] * (n // 2) + L[0])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=3005,INF=1<<29;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N,M;cin>>N>>M;
        vector<double> A(N),B(N),C(N);
        for(int i=0;i<N;i++){
            cin>>A[i]>>B[i]>>C[i];
        }
        vector<int> S(N);
        for(int i=0;i<M;i++) S[i]=1;
        sort(all(S));
        
        double ans=0.0;
        
        do{
            double sum=0;
            
            for(int i=0;i<N;i++){
                for(int j=i+1;j<N;j++){
                    if(S[i]&&S[j]){
                        sum+=(A[i]-A[j])*(A[i]-A[j]);
                        sum+=(B[i]-B[j])*(B[i]-B[j]);
                        sum+=(C[i]-C[j])*(C[i]-C[j]);
                    }
                }
            }
            
            ans=max(ans,sum);
            
        }while(next_permutation(all(S)));
        
        cout<<setprecision(25)<<ans<<endl;
        
        break;
    }
}



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

int main() {
	int n, k, count = 0;
	cin >> n >> k;
	vector<int> nusuke(n);
	for (int i = 0; i < k; i++) {
		int d = 0;
		cin >> d;
		vector<int> a(d);
		for (int j = 0; j < d; j++) {
			cin >> a.at(j);
			nusuke.at(a.at(j) - 1)++;
		}
	}
	for (int i = 0; i < n; i++) {
		if (nusuke.at(i) == 0) {
			count++;
		}
	}
	cout << count << endl;
}

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

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

	vector<string> A(n);
	char C[l];
	for(int i=0;i<n;i++){
		cin >> C;
		A.push_back(C);
	}

	sort(A.begin(),A.end());

	for(int i=0;i<A.size();i++)	cout << A[i];

	return 0;
}


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

const int mod = 1e9+7;
const int maxn = 2e6+10;

ll fac[maxn];
ll inv[maxn];

ll qpow(ll a, ll b) {
    ll res = 1;
    while(b) {
        if(b&1)
            res = res*a%mod;
        a = a*a%mod;
        b >>= 1;
    }
    return res;
}

ll C(ll n, ll m) {
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

ll solve(ll r, ll c) {
    return (C(r+c+2, r+1)-1+mod)%mod;
}

int main() {
    int r1, c1, r2, c2;
    scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
    fac[0] = inv[0] = 1;
    for(int i=1; i<=r2+c2+5; i++) {
        fac[i] = fac[i-1]*i%mod;
        inv[i] = qpow(fac[i], mod-2);
    }
    ll ans = solve(r2, c2)-solve(r1-1, c2)-solve(r2, c1-1)+solve(r1-1, c1-1);
    ans = ((ans%mod)+mod)%mod;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 31488
N,x = gets.to_i,gets
c,x = x.scan(?1).count, x.to_i(2)
R = [1,-1].map { m = c+_1; x%m if m>1 }
M = {0=>1}
X = (N-1).downto(0).map {|n|
  b = x[n]
  r,m = R[b],c+1-b-b
  if m < 2
    m - 2
  elsif b > 0
    (0 > r-=2.pow(n,m)) ? r+m : r
  else
    (c < r+=2.pow(n,m)) ? r-m : r
  end
}
I = [*0...N].sort_by! {X[_1]}
S = []
I.each {|i|
  next  if 1 > x=X[i]
  until c=M[x]
    S << x
    b,c = x+x,0
    c+=b[0] while 0 < (b>>=1)
    x %= c
  end
  M[x] = c+=1  while x=S.pop
}
X.each {|x| p x<0 ? x+2 : M[x]}

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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

int main(int argc, char **argv)
{
	ll N; cin >> N;
	map<ll, ll> m;
	REP(i, N)
	{
		ll a; cin >> a;
		++m[a];
	}


	if (N & 1)
	{
		ll res{1};
		bool ok{true};
		if (m[0] != 1)
			ok = false;
		FOR(i, 1, N)
		{
			if (i%2 == 0)
			{
				if (m[i] != 2)
					ok = false;
				(res *= 2) %= MOD;
			}
			else
			{
				if (m[i] != 0)
					ok = false;
			}
		}
		if (ok)
			std::cout << res << std::endl;
		else
			std::cout << 0 << std::endl;
	}
	else
	{
		bool ok{true};
		ll res{1};
		FOR(i, 1, N)
		{
			if (i & 1)
			{
				if (m[i] != 2)
					ok = false;
				(res *= 2) %= MOD;
			}
			else
			{
				if (m[i] != 0)
					ok = false;
			}
		}

		if (ok)
			std::cout << res << std::endl;
		else
			std::cout << 0 << std::endl;
	}
}


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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	int n;
	cin >> n;
	vector<pair<int, int>> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i].first >> v[i].second;
	}
	sort(v.begin(), v.end(), [](const pair<int, int> &a, const pair<int, int> &b) {
		return a.second < b.second;
	});
	long long c = 0;
	for (int i = 0; i < n; i++) {
		if (c + v[i].first > v[i].second) {
			cout << "No\n";
			return 0;
		}
		c += v[i].first;
	}
	cout << "Yes\n";
}


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

int main()
{
	ll t = 0;
	ll x = 0;
	for(int i=0;i<3;i++)
	{
		int temp;
		cin>>temp;
		if(temp==5)
		{
			t++;
		}
		else if(temp==7)
		{
			x++;
		}
	}
	if(t==2 && x==1)
	{
		cout<<"YES";
	}
	else
	cout<<"NO";
}

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

int main(){
  long long n,m; cin>>n>>m;
  long long res=0;
  if(n*2<=m){
    res+=n;
    m-=n*2;
    res+=m/4;
  }else{
    res+=m/2;
  }
  cout<<res<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
#include <stdio.h>
using namespace std;

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int64 n;
    cin >> n;
    if (n % 2 == 1 || n < 10) cout << 0;
    else{
        int64 res = 0;
        n /= 2;
        while (n > 0){
            res += n / 5;
            n /= 5;
        }
        cout << res;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<char> group(n);
  for (int i = 0; i < n; i++) {
    cin >> group[i];
  }
  vector<vector<int>> grh(n);
  vector<int> cntA(n, 0);
  vector<int> cntB(n, 0);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    for (int k = 0; k < 2; k++) {
      grh[a].push_back(b);
      if (group[a] == 'A') {
        cntA[b]++;
      } else {
        cntB[b]++;
      }
      swap(a, b);
    }
  }
  vector<bool> hbdel(n, false);
  stack<int> del;
  for (int i = 0; i < n; i++) {
    if (!(cntA[i] && cntB[i])) {
      del.push(i);
     hbdel[i] = true;
    }
  }
  while (!del.empty()) {
    int crr = del.top();
    del.pop();
    for (int nxt : grh[crr]) {
      if (hbdel[nxt]) {
        continue;
      }
      if (group[crr] == 'A') {
        cntA[nxt]--;
      } else {
        cntB[nxt]--;
      }
      if (!(cntA[nxt] && cntB[nxt])) {
        del.push(nxt);
        hbdel[nxt] = true;
      }
    }
  }
  bool ret = false;
  for (int i = 0; i < n; i++) {
    if(!hbdel[i]) {
      ret = true;
    }
  }
  if (ret) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
  return 0;
}

Measured memory_bytes: 12160
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int n;
  char s[101];
  scanf("%d %s", &n, s);

  int ans = 0;
  rep(i, 0, n) { // 切れ目を全探索
    int cnt = 0;
    int alp[26] = {0};
    rep(front, 0, i) {
      int c = (int)(s[front] - 'a');
      alp[c] = 1;
    }
    rep(back, i, n) {
      int c = (int)(s[back] - 'a');
      if (alp[c]) {
        cnt++;
        alp[c] = 0;
      }
    }
    ans = max(ans, cnt);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
l,r=map(int,input().split())
if r-l>=2019:
    ans=0
else:
    ans=2018
    l=l%2019
    r=r%2019
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            ans=min(ans,i*j%2019)
print(ans)

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

using pll = std::pair<long long, long long>;

int main()
{
	int a, b, q;
	scanf("%d%d%d", &a, &b, &q);
	std::vector<long long> shrine(a), temple(b);
	std::vector<pll> merged(a + b);
	std::vector<bool> is_temple(a + b);
	for (auto& e: shrine) scanf("%lld", &e);
	for (auto& e: temple) scanf("%lld", &e);
	shrine.push_back(1LL << 60);
	temple.push_back(1LL << 60);
	int s_i{}, t_i{};
	for (int i{}; i < a + b; i++)
	{
		if (shrine[s_i] < temple[t_i])
		{
			merged[i].first = shrine[s_i];
			s_i++;
		}
		else
		{
			merged[i].first = temple[t_i];
			is_temple[i] = true;
			t_i++;
		}
	}
	long long s_near{-(1LL << 60)}, t_near{-(1LL << 60)};
	for (int i{}; i < a + b; i++)
	{
		if (is_temple[i])
		{
			merged[i].second = merged[i].first - s_near;
			t_near = merged[i].first;
		}
		else
		{
			merged[i].second = merged[i].first - t_near;
			s_near = merged[i].first;
		}
	}
	s_near = (1LL << 60);
	t_near = (1LL << 60);
	for (int i{a + b - 1}; i >= 0; i--)
	{
		if (is_temple[i])
		{
			merged[i].second = std::min(merged[i].second, s_near - merged[i].first);
			t_near = merged[i].first;
		}
		else
		{
			merged[i].second = std::min(merged[i].second, t_near - merged[i].first);
			s_near = merged[i].first;
		}
	}
	merged.push_back({1LL << 60, 1LL << 60});

	for (int loop{}; loop < q; loop++)
	{
		long long x;
		scanf("%lld", &x);
		auto lb{std::lower_bound(merged.begin(), merged.end(), pll(x, 0))};
		long long dist_min{lb->first - x + lb->second};
		if (lb != merged.begin() && lb->first != x)
			dist_min = std::min(dist_min, x - (lb - 1)->first + (lb - 1)->second);
		printf("%lld\n", dist_min);
	}
	
	return 0;
}

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

class Dice{
  private:
    int* num;
  public:
    Dice(){
      num = new int[6];
    };
    ~Dice(){
      delete[] num;
    };
    void DiceSet(int index, int x){
      num[index] = x;
    };
    void DiceRoll(char x){
      switch(x){
        case 'E':
	  SwapFour(num[0],num[2],num[5],num[3]);
	  break;
	case 'S':
	  SwapFour(num[0],num[1],num[5],num[4]);
	  break;
	case 'W':
	  SwapFour(num[0],num[3],num[5],num[2]);
	  break;
	case 'N':
	  SwapFour(num[0],num[4],num[5],num[1]);
	  break;
      }
    };
    int DicePutTop(){
      return num[0];
    }
    int DicePutX(int x){
      return num[x];
    }
  private:
    // a->b->c->d->a
    void SwapFour(int &a, int &b, int &c, int &d){
      a ^= b; b ^= a; a ^= b;
      a ^= c; c ^= a; a ^= c;
      a ^= d; d ^= a; a ^= d;
    }
};

int main(){
  Dice dice;
  int label, n, top, front;

  for(int i=0;i<6;i++){
    cin >> label;
    dice.DiceSet(i,label);
  }
  cin >> n;
  while(n--){
    cin >> top >> front;
    if(dice.DicePutX(3) == top) dice.DiceRoll('E');
    if(dice.DicePutX(2) == top) dice.DiceRoll('W');
    while(dice.DicePutX(0) != top) dice.DiceRoll('N');
    while(dice.DicePutX(1) != front){
      dice.DiceRoll('E'); dice.DiceRoll('N'); dice.DiceRoll('W');
    }
    cout << dice.DicePutX(2) << endl;
  }
}


Measured memory_bytes: 3112
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll X;
  cin>>X;
  ll k = 1;
  ll ans;
  while(true){
    if(((360-(k*X))%360)==0){
      ans = k;
      break;
    }
    k++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int binpow(int a, int b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

ll gcd(ll a,ll b)
{
    if (b==0) return a;
    return gcd(b,a%b);
}
string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m;
    cin>>n>>m;
    string s[n];
    for (int i=0;i<n;++i)
    {
        cin>>s[i];
    }
    ll a[n][m];
    a[0][0]=1;
    for (int j=1;j<m;++j)
    {
        if (s[0][j]=='#')
        {
            a[0][j]=0;
        }
        else
        {
            a[0][j]=a[0][j-1];
        }
    }
    for (int i=1;i<n;++i)
    {
        if (s[i][0]=='#')
        {
            a[i][0]=0;
        }
        else
        {
            a[i][0]=a[i-1][0];
        }
    }
    for (int i=1;i<n;++i)
    {
        for (int j=1;j<m;++j)
        {
            if (s[i][j]=='#')
            {
                a[i][j]=0;
            }
            else
            {
                a[i][j]=a[i-1][j]+a[i][j-1];
                a[i][j]%=1000000007;
            }
        }
    }
    cout<<a[n-1][m-1];
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  float n;
  cin>>n;
  n = ceil(n/2);
  cout<<n;
}

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

int main() {
  int H,W;
  cin >> H >> W;
  int dx[8]={1,1,1,0,-1,-1,-1,0};
  int dy[8]={1,0,-1,-1,-1,0,1,1};
  vector<string> str(H);
  for (int i=0; i<H; i++){
    cin >> str[i];
  }
  for(int i=0; i<W; i++){
    for(int j=0; j<H; j++){
      if(str[j][i]=='#') continue;
      int num=0;
      for(int k=0; k<8; k++){
        int x=i+dx[k], y=j+dy[k];
        if(x<0||x>=W||y<0||y>=H) continue;
        else if(str[y][x]=='#') num++;
      }
      str[j][i]=char(num)+'0';
    }
  }
  for(int i=0; i<H; i++){
    cout << str[i] << "\n";
  }
  return 0;
}

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

int64_t MOD = 998244353;

int64_t N_MAX = 3010;

int64_t dp[3010][3010];

//modの割り算
// a/bをa*modint(b,MOD) %MODに変換
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

//繰り返し二乗法
int64_t powmod(int64_t x, int64_t n) { 
  int64_t ans = 1;
  while (n > 0) {
    if ((n & 1) == 1) {
      ans = ans * x;
      ans %= MOD;
    }
    x = x * x;//一周する度にx, x^2, x^4, x^8となる
    x %= MOD;
    n >>= 1; //桁をずらす n = n >> 1
  }
  return ans;
}

int main(){
  int N, S;
  cin >> N >> S;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec[i];
  }
  for(int i=0; i<N; i++){
    int x = vec[i];
    dp[i+1][x] = powmod(2,N-1);
    for(int j=0; j<N_MAX; j++){
      dp[i+1][j] += dp[i][j];
      if(j + x < N_MAX){
        int64_t y = dp[i][j];
        y = (y*modinv(2,MOD)) %MOD;
        dp[i+1][j+x] += y;
      }
      dp[i+1][j] %= MOD;
    }
  }
  cout << dp[N][S] << endl;
}


Measured memory_bytes: 74160
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>

#define nl "\n"

using namespace std;

int n, k, q, a;
int main(){
    cin >> n >> k >> q;
    vector<int> v(n, k);

    for(int i = 0; i < q; i++){
        cin >> a;
        v[a-1] = v[a-1] + 1;
    }

    for(int i = 0; i < n; i++){
        v[i] = v[i] - q;
        if(v[i] > 0){
            cout << "Yes" << nl;
        } else{
            cout << "No" << nl;
        }
    }





}

//g++ -std=c++14 comp.cpp -o b; ./b.exe


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

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

#define endl '\n'
#define ff first
#define ss second
#define int long long
#define pb push_back
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define Max 5000001
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define d0(a) cout<<a<<' ';
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<' '<<b<<endl;
#define d3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define d4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define d5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
#define d6(a,b,c,d,e,f) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<endl;

const ll N=1e5+5,mod=1e9+7,bit=61;
const ld PI=acos(-1.00);


signed main()
{
    fast;

    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll a,b,k;
        cin>>k;
        cin>>a>>b;
        bool p=0;
        f(i,a,b)
        {
            if(i%k==0)
            {
                p=1;
            }
        }
        if(p)
        {
            cout<<"OK\n";
        }
        else
        {
            cout<<"NG\n";
        }
    }
    return 0;
}


















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

using namespace std;

int N;
int arr[104], chk[104], ans[104];

int main(){
    scanf("%d", &N);
    for(int i=1;i<=N;++i) scanf("%d", arr+i);
    for(int i=N;i>=1;--i){
        for(int j=N;j>=1;--j) if(!chk[j]){
            int cnt = 0;
            for(int x=1;x<=j;++x) if(!chk[x]) ++cnt;
            if(arr[j]==cnt){
                ans[i] = arr[j]; chk[j] = 1; break;
            }
        }
        if(!ans[i]){
            puts("-1"); return 0;
        }
    }
    for(int i=1;i<=N;++i) printf("%d\n", ans[i]);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    while(1){
        int a,b;cin>>a>>b;
        if(a==0&&b==0)return 0;
        if(a<=b)cout<<a<<" "<<b<<endl;
        else cout<<b<<" "<<a<<endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 100000000;
const ll half_inf = 0x3f3f3f3f;
const ll inf = 0x7fffffff;
const ll mod = 998244353;
const ll maxn = 2000005;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k,a,b;
    scanf("%d%d",&a,&b); 
    if(b>=a)
    printf("unsafe");
	else printf("safe");    
    return 0;
}




Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
const int N = 100005, MOD = 1E9 + 7;
int n, m, a[N], ans[N];
int main(int argc, char const *argv[])
{
	cin >> n >> m;
	for (int i = 1; i <= m; ++i)
	{
		int u;
		cin >> u;
		a[u] = 1;
	}
	ans[0] = 1;
	ans[1] = (a[1] == 0);
	for (int i = 2; i <= n; ++i)
	{
		if (a[i])
			continue;
		ans[i] = (1LL * ans[i - 1] + 1LL * ans[i - 2]) % MOD;
	}
	cout << ans[n] << '\n';
	return 0;
}

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

typedef long long ll;

int main() {
#ifdef TooLazy
    freopen("in.txt", "r", stdin);
#endif /// TooLazy

    map<ll, ll> mp;
    map<ll, int> vis;
    ll n, ara[100005];
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> ara[i];
        mp[ara[i]]++;
    }

    sort(ara, ara+n);

    ll a = 0, b = 0, ans = 0;

    for(int i=n-1; i>=0; i--) {
        ll x = ara[i];
        if( mp[x] > 1 ) {
            a = x;
            vis[x] = 1;
            break;
        }
    }

    for(int i=n-1; i>=0; i--) {
        ll x = ara[i];
        if( mp[x] > 1 && vis[x]==0) {
            b = x;
            break;
        }
    }

    ans = a * b;

    for(int i=n-1; i>=0; i--) {
        ll x = ara[i];
        if(mp[x] > 3 ) {
            if( x * x > ans ) {
                ans = x*x;
                break;
            }
        }
    }

    cout << ans << "\n";

    return 0;
}



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

using namespace std;

int main()
{
    string N;
    cin >> N;
    int sum = 0;
    for (int i = 0; i < N.size(); ++i)
    {
        sum += N[i] - 48;
    }
    if (sum % 9 == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

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

  ll ret = 0;

  ret = n * (n - 1) / 2;

  cout << ret << endl;

  return 0;
}


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

int main(){
    int K;
    cin >> K;
    long long l = 7;
    for(int i = 1; i < K + 10; i++){
        if(l%K == 0){
            cout << i << endl;
            return 0;
        }
        l = (10*l + 7)%K;
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3580