akhauriyash/Code-Regression huggingface dataset:
//
//ARC 080
//D
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int H, W, n;
    cin >> H >> W >> n;

    vector<int> a(n);
    REP(i, n) cin >> a[i];
    //sort(RALL(a));

    vector<vector<int>> ans(H, vector<int>(W, 0));
    int h = 0;
    int w = 0;
    REP(i, n){
        REP(j, a[i]){
            ans[h][w]=i+1;
            if (h%2==0){
                w++;
                if (w==W) {
                    h++;
                    w--;
                }
            }else{
                w--;
                if (w<0) {
                    h++;
                    w=0;
                }
            }
        }
    }
    REP(h,H){
        REP(w,W) {
            cout << ans[h][w] << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3640
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

signed main() {
    int N;
    int maxa = -1;
    int mina = INF;

    cin >> N;

    int A[N];

    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        maxa = max(maxa, a);
        mina = min(mina, a);
        A[i] = a;
    }

    if (maxa - mina > 1) {
        cout << "No" << endl;
        return 0;
    }

    if (maxa == mina) {
        if (N >= maxa * 2 || N - 1 == maxa) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }

        return 0;
    }

    int mina_num = 0;
    int maxa_num = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] == mina) mina_num++;
        if (A[i] == maxa) maxa_num++;
    }

    if (mina_num < maxa && maxa_num >= 2 *(maxa - mina_num)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fats ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
    fats;
    ll n,k,j=1;cin>>n>>k;
    ll a[n];
    for(ll i=1;i<=n;i++)cin>>a[i];
    if(n==3)cout<<"No";
    else
    {
        for(ll i=k+1;i<=n;i++)
        {
            if(a[i]>a[j])cout<<"Yes\n";
            else cout<<"No\n";
            j++;
        }
    }
}

Measured memory_bytes: 5180
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin >> s;
    long long int q;
    cin >> q;
      
    for(long long int i=0;i<q;i++){
        string in;
        cin >> in;
        if(in=="print"){
            long long int a,b;
            cin>>a>>b;
            cout<< s.substr(a,b-a+1)<<endl;
              
        }else if(in=="reverse"){
            long long int a,b;
            cin>>a>>b;
            string k=s;
            for(long long int j=a;j<=b;j++){
                s[j]=k[a+b-j];
            }
        }else if (in=="replace"){
            long long int a,b;
            cin>>a>>b;
            for(long long int j=a;j<=b;j++){
                char c;
                cin>>c;
                s[j]=c;
            }
        }
    }
}



Measured memory_bytes: 3176
n = int(input())
a = list(map(int, input().split()))

d = {}
for i in range(n):
  if a[i] in d:
    d[a[i]] += 1
  else:
    d[a[i]] = 1
ans = 0
for j in d.values():
  ans += j*(j-1)//2
for i in range(n):
  x = d[a[i]]
  print(ans-(x*(x-1)//2)+((x-1)*(x-2)//2))

Measured memory_bytes: 24996
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

const ll M = 998244353;

void solve() {
	int n;
	cin >> n;
	vector<int> v(n);
	vector<int> c(n);
	rep(i,n) cin >> v[i];

	int mx = 0;
	for (int i = 0; i < n; i++) {
		mx = max(mx, v[i]);
		c[v[i]]++;
	}
	if (c[0] != 1 || v[0] != 0) {
		cout << 0 << endl;
		return;
	}

	ll ans = 1;
	for (int i = 0; i <= mx; i++) {
		int k = c[i+1];
		ll temp = 1;
		for (int j = 0; j < k; j++) {
			temp *= c[i];
			temp %= M;
		}
		ans *= temp;
		ans %= M;
	}
	cout << ans << endl;
} 

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

Measured memory_bytes: 3936
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    string s;
    bool start=true;
    while(getline(cin,s,' ')){
        
        if(s[s.size()-1]=='.' || s[s.size()-1]==',')s.erase(s.end()-1);
        if(3<=s.size()&&s.size()<=6){
            if(start){
                cout<<s;
                start=false;   
            }else cout<<" "<<s;
        }
        
    }
    cout<<endl;
    
    return 0;
}



Measured memory_bytes: 3008
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n;
    ll a, b;
    cin >> n >> a >> b;
    
    vector<ll> v(n);
    for(auto&i : v){
        cin >> i;
    }

    ll ans = 0;

    for(int i=1; i<n; i++){
        ans += min((v[i]-v[i-1])*a, b);
    }

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

Measured memory_bytes: 1024
import math

k = int(input())
list = [0]*201
for b in range(1, k + 1):
    for c in range(1, k + 1):
        list[math.gcd(b, c)] += 1
list_2 = [0]*201
for i in range(k):
    for a in range(1, k + 1):
        list_2[i + 1] += math.gcd(i + 1, a)*list[i + 1]
print(sum(list_2))


Measured memory_bytes: 9188
#include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	
	int n;
	int b[100][100]={};
	
	while( cin >> n && n!=0)
	{
		
		REP(i,n){REP(j,n){b[i][j]=0;}}
		
		REP(i,n)
		{
			int k;
			cin >> k;
			REP(j,k)
			{
				int l;
				cin >> l;
				b[i][l-1] ++;
			}
		}

		int hanin[100]={};
		REP(i,n){	hanin[i]=1;}
		
		int k;
		cin >> k;
		REP(i,k)
		{
			int l;
			cin >> l;
			REP(j,n){
			if(b[j][l-1]==0){	hanin[j] =0;	}
		}}
		
		int sum(0);
		int ans(0);
		REP(i,n){ if(hanin[i]==1){sum+=hanin[i];	ans+=(i+1);}}
		
		if(sum==1){	cout << ans << endl;	}
		else cout << -1 << endl;
		
	}
	return 0 ;
}

Measured memory_bytes: 1208
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const [n, k] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const [, ..._h] = stdin.trim().split('\n')
const h = _h.map(Number)

const s = h.sort((a, b) => a - b)

const getMin = _ => {
  let min = Infinity
  for (let i = 0; i <= s.length - k; i++) {
    const diff = s[i + k - 1] - s[i]
    min = min > diff ? diff : min
  }
  return min
}

console.log(getMin())


Measured memory_bytes: 30100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    ll A,P;
    cin>>A>>P;
    cout<<(A*3+P)/2<<endl;
}


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

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, a, s=0;
	cin>>n;
	while(n--) {
	    cin>>a;
	    s += a-1;
	}
	cout<<s;
}

Measured memory_bytes: 256
import sys
f = sys.stdin

def take2(iterable):
    i = iter(iterable)
    while True:
        yield next(i), next(i)
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
# 砂時計型の場合は考慮しない
def is_convex(a, b, c, d):
    v1 = cross(a - b, b - c)
    v2 = cross(b - c, c - d)
    v3 = cross(c - d, d - a)
    v4 = cross(d - a, a - b)    
    return 0 < v1 * v2 and 0 < v2 * v3 and 0 < v3 * v4

for line in f:
    a, b, c, d = [x + y *1j for x, y in take2(map(float, line.split(',')))]
    
    print('YES' if is_convex(a,b,c,d) else 'NO')

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

int main(){
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double angle=abs((30*h+0.5*m)-6*m);
	if(angle>180){
		angle=360-angle;
	}
	double d=angle*(3.141592653589793/180);
	d=cos(d);
	double c=(a*a)+(b*b)-2*b*a*d;
	double ans=sqrt(c);
	cout<<setprecision(20)<<ans<<endl;
	//cout<<angle<<" "<<c<<" "<<d<<" "<<a*a+b*b<<endl;
	//while(cin>>a){
	//	cout<<cos(a)<<endl;
	//}
}

Measured memory_bytes: 4256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
using namespace std;
typedef pair<int, int>p;
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
vector<long long> divisor(long long n) {
	vector< long long> ret;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}
struct LazySegmentTree {
private:
	int n;
	vector<int> node, lazy;
	vector<bool> lazyFlag;

public:
	LazySegmentTree(vector<int> v) {
		int sz = (int)v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1);
		lazy.resize(2 * n - 1, INT_MAX);
		lazyFlag.resize(2 * n - 1, false);

		for (int i = 0; i<sz; i++) node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
	}

	void lazyEvaluate(int k, int l, int r) {
		if (lazyFlag[k]) {
			node[k] = lazy[k];
			if (r - l > 1) {
				lazy[k * 2 + 1] = lazy[k * 2 + 2] = lazy[k];
				lazyFlag[k * 2 + 1] = lazyFlag[k * 2 + 2] = true;
			}
			lazyFlag[k] = false;
		}
	}

	void update(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] = x;
			lazyFlag[k] = true;
			lazyEvaluate(k, l, r);
		}
		else {
			update(a, b, x, 2 * k + 1, l, (l + r) / 2);
			update(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = min(node[2 * k + 1], node[2 * k + 2]);
		}
	}

	int find(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return INT_MAX;
		if (a <= l && r <= b) return node[k];
		int vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
};
long long mod = 1000000007;
long long a, b, c, d;
long long num(long long x) {
	long long k = x / c + x / d - x / (c*d / gcd(c, d));
	return x - k;
}
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(16);
	cin >> a >> b >> c >> d;
	cout << num(b) - num(a - 1);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#define int long long
int K,X;
signed main(){
  cin >> K >> X;
  int a=X-K+1,b=X+K-1;
  for(int i=max(a,-1000000);i<=min(b,1000000)-1;i++) cout << i << " ";
  cout << min(b,1000000) << endl;
  return 0;
}


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

int main(){
    int N, H;
    cin >> N >> H;
    vector<int> a(N), b(N);
    rep(i, N) cin >> a[i] >> b[i];
    sort(all(a), greater<>());
    int mx_a = a[0];
    sort(all(b), greater<>());
    int cnt = 0, dmg = 0;
    rep(i, N) {
        if (b[i] > mx_a) {
            dmg += b[i];
            cnt++;
        } else {
            break;
        }

        if (dmg >= H) break;
    }
    int rem = H - dmg;
    if (rem > 0) cnt += (rem + mx_a - 1) / mx_a;
    cout << cnt << endl;
    return 0;
}

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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x)      cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x)      cout << ((x) ? "YES" : "NO") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )

struct act {
	ll a;
	ll b;
	ll c;
};

int main(int argc, const char* argv[]) {
	ll n;
	cin >> n;
	vector<ll> a(n), b(n), c(n);
	rep(i, n) {
		cin >> a[i] >> b[i] >> c[i];
	}

	vector<act> dp(n);

	dp[0].a = a[0];
	dp[0].b = b[0];
	dp[0].c = c[0];

	repd(i, 1, n) {
		dp[i].a = max(dp[i-1].b + a[i], dp[i-1].c + a[i]);
		dp[i].b = max(dp[i-1].c + b[i], dp[i-1].a + b[i]);
		dp[i].c = max(dp[i-1].a + c[i], dp[i-1].b + c[i]);
	}

	cout << max({dp.back().a, dp.back().b, dp.back().c}) << endl;

	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, K; cin >> N >> K;
	int ans = 0;
	for (; N; N /= K) ans++;
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
//  RAKSHIT KADAM
 #include <bits/stdc++.h>
 
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
 #warning !!!check the size of arrayss!!!
 
 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define newMOD  998244353
 #define MAX 300006
            
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define endl "\n"
 #define x first
 #define y second
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define INF 1000000000000000005
 #define vi vector<ll>
#define pi 3.1415926535897932384626433832795
#define Endl endl
#define lb lower_bound
#define ub upper_bound
using namespace std;
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}
 
//ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}}

void solve()
{
    ll n,k,sk;cin>>n>>k>>sk;
    string s;cin>>s;
    vi p,q;ll pp=0;
    
    for(ll i=0;i<n && pp<k;i++)
    {
        if(s[i]=='o')
        {
            p.pb(i);
            i+=sk;
            pp++;
        }
    }
    pp=k;
    for(ll i=n-1;i>=0 && pp;i--)
    {
        if(s[i]=='o')
        {
            q.pb(i);
            i-=sk;
            pp--;
        }
    }
    reverse(q.begin(),q.end());
    vi ans;
    
    for(ll i=0;i<p.size();i++)
    {
        if(p[i]==q[i])ans.pb(p[i]+1);
    }
  
    for(auto it:ans)
    {
        cout<<it<<endl;
    }
}
signed main()
{
 
   
    Need_for_speed(activated);
//satisfy
//    {
//   solve();
//    }

  solve();
    return 0;
    
}
 


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

int main(){
	int a[26]={};
	string s;
	cin >> s;
	for(int i=0;i<s.size();++i){
		a[s[i]-'a']++;
	}
	for(int i=0;i<26;++i){
		if(a[i]>1){
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+3;
int used[N],cnt;
double n,sum;
int k;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	int a[n+1];
	int mn=1000000000;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]<mn){
			mn=a[i];
			cnt++;
		}
	}
	cout<<cnt;
	
}

Measured memory_bytes: 1024
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <tuple>
#include <iomanip>
using namespace std;
int main(void){
 int N,M;
 cin>>N>>M;
 tuple<int,int,int> data[M];
 for(int i=0;i<M;i++){
 int p,y;
 cin>>p>>y;
 data[i]=make_tuple(y,p,i);
 }
 sort(data,data+M);
 int count[N+1];
 fill(count,count+N+1,0);
 pair<int,int> id[M];
 for(int i=0;i<M;i++){
  int y,p,j;
  tie(y,p,j)=data[i];
  count[p]++;
  id[j]=make_pair(p,count[p]);
 }
 for(int i=0;i<M;i++){
  cout<<setw(6)<<setfill('0')<<id[i].first;
  cout<<setw(6)<<setfill('0')<<id[i].second<<endl;
 }
 return 0;
}


Measured memory_bytes: 3840
H, W = map(int, input().split())
l = []
l.append([input() for i in range(H)])
B = []
b = 0
m = 0
for i in range(H):
    for j in range(W):
        if l[0][i][j] == '#':
            B.append([i, j])
for i in B:
    for j in B:
        if i == j:
            pass
        elif i[0] == j[0] and i[1] - 1 <= j[1] <= i[1] + 1:
            m = 1
        elif i[0] - 1 <= j[0] <= i[0] + 1 and i[1] == j[1]:
            m = 1
        else:
            pass
    if m == 0:
        b = 1
        print('No')
        break
    else:
        m = 0
if b == 0:
    print('Yes')


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)

int main(){
    string s,t;
    cin>>s;

    int i=0;
    bool judge=true;

    while(t.size()<s.size()){
        if(s.substr(i,5)=="dream"){
            t+="dream";
            i+=5;
            if(s.substr(i,2)=="er"){
                if(s[i+2]=='a'){
                    continue;
                }else{
                    t+="er";
                    i+=2;
                }
            }
        }else if(s.substr(i,6)=="eraser"){
            t+="eraser";
            i+=6;
        }else if(s.substr(i,5)=="erase"){
            t+="erase";
            i+=5;
        }else{
            judge=false;
            break;
        }
    }

    cout<<(judge ? "YES" : "NO")<<endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> x(b);
    for (int i = 0; i < b; i++) {
        x[i] = a * (i + 1) % b;
    }
    int count = 0;
    for (int i = 0; i < b; i++) {
        if (c == x[i]) {
            count++;
        }
    }
    if (count != 0) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

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

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> C(N);

    REP(i, N){
        cin >> C[i];
    }

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

    vector<ll> MP(N+1, 0);

    // 2^Nの前処理
    REP(i, N+1){
        if(i == 0){
            MP[0] = 1;
            continue;
        }
        MP[i] = MP[i-1]*2;
        MP[i] = MP[i] % MOD;
        // cout << MP[i] << endl;
    }

    ll ans = 0;

    REP(i, N){
        ll temp = 0;
        temp += (MP[N-1]*C[i]) % MOD;
        temp = temp % MOD;

        temp += (((MP[N-2]*(N-1-i))%MOD)*C[i])%MOD;
        temp += temp % MOD;
        // cout << temp << endl;
        ans += temp;
        ans = ans % MOD;
    }
    ans = (ans*MP[N-1]) % MOD;

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

Measured memory_bytes: 6376
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s,t;
	cin>>s;
	stringstream ss(s);
	while(getline(ss,t,','))
		cout<<t<<' ';
	return 0;
}

Measured memory_bytes: 256
n,nn=map(int,input().split())
l=[list(map(int,input().split()))for i in range(nn)]
l.reverse()
m=[[1,i] for i in range(n)]
ans=[]
ans.append(n*(n-1)//2)
for a,b in l:  #10^5
  #print(m)
  a-=1
  b-=1
  while a!=m[a][1]:
    a=m[a][1]
  while b!=m[b][1]:
    b=m[b][1]
  if a==b:
    ans.append(ans[len(ans)-1])
    continue
  #a!=b
  ans.append(ans[len(ans)-1]-m[a][0]*m[b][0])
  if a<b:
    a,b=b,a
  #a>=b
  m[a][0]+=m[b][0]
  m[b][0]=0
  m[b][1]=a
ans.reverse()
for a in ans[1:]:
  print(a)

Measured memory_bytes: 42428
import sys
input = sys.stdin.readline
H,N = [int(i) for i in input().split()]
A = [0] * N
B = [0] * N
for i in range(N) :
    a,b = [int(i) for i in input().split()]
    A[i] = a
    B[i] = b
dp = [[(10**9+7)] * (H+1) for _ in range(N)]
for j in range(H+1):
    if j <= A[0]:
        dp[0][j] = B[0]
    if j > A[0]:
        dp[0][j] = dp[0][j-A[0]] + B[0]
for i in range(1,N):
    for j in range(H+1):
        if j == 0:
            dp[i][j] = min(dp[i-1][0],B[i])
        if j <= A[i]:
            dp[i][j] = min(dp[i-1][j],B[i])
        if j > A[i]:
            dp[i][j] = min(dp[i-1][j],dp[i][j-A[i]]+B[i])
print(dp[N-1][H])

Measured memory_bytes: 120796
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;
typedef long long int ll;

int r,s,p;

int getScore(char com, int user) {
    if (com == 'r' && user == 2) {
        return p;
    }
    if (com == 's' && user == 0) {
        return r;
    }
    if (com == 'p' && user == 1) {
        return s;
    }
    return 0;
}

int main() {
    int n, k;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;

    vector< vector<ll> > memo(3, vector<ll>(n, 0));

    for (int i = 0; i < k; i++) {
        int prevIdx = i;
        // r = 0, s = 1, p = 2
        memo[0][i] = getScore(t[i], 0);
        memo[1][i] = getScore(t[i], 1);
        memo[2][i] = getScore(t[i], 2);
        for (int nextIdx = prevIdx + k; nextIdx < n; nextIdx += k) {
            for (int waza = 0; waza < 3; waza++) {
                int score = getScore(t[nextIdx], waza);
                ll finalScore = 0;
                for (int prevWaza = 0; prevWaza < 3; prevWaza++) {
                    if (waza == prevWaza) {
                        continue;
                    }
                    finalScore = max(finalScore, memo[prevWaza][prevIdx] + score);
                }
                memo[waza][nextIdx] = finalScore;
            }
            prevIdx = nextIdx;
        }

    }
    ll ans = 0;
    for (int j = n - k; j < n; j++) {
        ans += max(max(memo[0][j], memo[1][j]), memo[2][j]);
    }

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

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 1e18
#define common cout << "Case #" << w+1 << ": "  


int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a>=0 and c>=0)
        cout << b*1LL*d << endl;
    else if(a>=0)
    {
        if(d>=0)
            cout << b*1LL*d << endl;
        else
            cout << a*1LL*d << endl;
    }
    else if(c>=0)
    {
        if(b>=0)
            cout << b*1LL*d << endl;
        else
            cout << c*1LL*b << endl;
    }
    else
    {
        lli x=a*1LL*c;
        lli y=b*1LL*d;
        cout << max(x,y) << endl;   
    }
}

Measured memory_bytes: 3672
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    long long A;
    long long B;
    long long C;
    long long K;

    long long ans = 0;

    cin >> A >> B >> C >> K;

    long long minV = min(A, K);
    ans += minV;
    K -= minV;

    minV = min(B, K);
    K -= minV;

    minV = min(C, K);
    ans -= minV;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    string s, t;

    cin >> n >> s >> t;
    rep(i, n) cout << s[i] << t[i];
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 3588
n = int(input())


flug = False

for i in range(9):
  pe = n%(i+1)
  if pe == 0:
    res = n/(i+1)
    #print(res)
    if res<10:
      flug = True
      break
 

if flug == True:
  print("Yes")
  
else:
  print("No")

Measured memory_bytes: 2940
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


object Main extends App {
    val in = new InputReader(System.in)
    val pw = new PrintWriter(System.out)

    val MOD = 1e9.toLong + 7
    val n, m = in.next().toInt
    val s = new Array[Int](n+1)
    val t = new Array[Int](m+1)
    for (i <- 1 to n) {
        s(i) = in.next().toInt
    }
    for (i <- 1 to m) {
        t(i) = in.next().toInt
    }

    val imos = Array.ofDim[Long](n+1, m+1)
    val dp = Array.ofDim[Long](n+1, m+1)
    for (i <- 1 to n) {
        for (j <- 1 to m) {
            if (s(i) == t(j)) {
                dp(i)(j) = imos(i-1)(j-1) + 1
                dp(i)(j) %= MOD
            }
            imos(i)(j) = imos(i-1)(j) + imos(i)(j-1) - imos(i-1)(j-1)
            if (imos(i)(j) < 0) {
                imos(i)(j) += MOD
            }
            imos(i)(j) %= MOD
            imos(i)(j) += dp(i)(j)
            imos(i)(j) %= MOD
        }
    }

    var ans = 0L
    for (i <- 1 to n) {
        for (j <- 1 to m) {
            ans += dp(i)(j)
            ans %= MOD
        }
    }
    println((ans + 1) % MOD) // 空文字列の分も足す


}

Measured memory_bytes: 114440
//https://atcoder.jp/contests/arc100/tasks/arc100_c
#include <bits/stdc++.h>
using namespace std;

using ii = pair <int, int>;

const int N = 18;
ii dp[1 << N]; int a[1 << N], ans;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n; cin >> n;
    for (int i = 0; i < (1 << n); i++) {
        cin >> a[i];
    }
    dp[0] = {a[0], 0};
    for (int i = 1; i < (1 << n); i++) {
        for (int j = 0; j < n; j++)
            if (i & (1 << j))
                dp[i] = max(dp[i], dp[i ^ (1 << j)]);
        for (int j = 0; j < n; j++)
            if (dp[i].second & (1 << j))
                ans = max(ans, dp[i].first + dp[i ^ (1 << j)].first);
        ans = max(ans, dp[i].first + a[i]);
        dp[i] = max(dp[i], {a[i], i});
        cout << ans << '\n';
    }
}

Measured memory_bytes: 6660
#include <iostream>
#include <string>
using namespace std;
int main(){
     string S,T;
     int flag =0;
     cin >>S >> T;
     for (int i=0;i<S.length();i++){
          if (S[i]!=T[i]){
               flag++;
               break;
          }
     }
     if (flag != 0){
          cout << "No" <<endl;
     }else{
          cout <<"Yes" <<endl;
     }

}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N = 305;
const ll inf = 1e18;

int n, a[N][N];
ll ans, dis[N][N];

vector<pair<int,pii> > edg;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=n;j++) {
			scanf("%d",&a[i][j]);
			if(i < j) edg.push_back({a[i][j], {i,j}});
			dis[i][j] = inf;
		}
	}
	sort(edg.begin(), edg.end());
	for(auto &T : edg) {
		int A = T.Y.X, B = T.Y.Y, C = T.X;
		long long D = inf;
		for(int i=1;i<=n;i++) {
			D = min(D, dis[A][i] + dis[i][B]);
		}
		if(D < C) {
			puts("-1");
			return 0;
		}
		if(D > C) {
			ans += C;
		}
		dis[A][B] = C;
		dis[B][A] = C;
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 2040
//数学をしたほうが実装は楽だと思うけど、さきほどやってみたらバグ死したので、桁DP + 2分探索します。
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;

//a[i] … 10進数における下位i(>=0)桁目.
vector<int> add(vector<int> a, vector<int> b, int n) {
	for (int i = 0; i < n; i++) {
		a[i] += b[i];
		if (i + 1 < n) { a[i + 1] += a[i] / 10; a[i] %= 10; }
	}
	return a;
}

vector<int> sub(vector<int> a, vector<int> b, int n) {
	for (int i = 0; i < n; i++) {
		a[i] -= b[i];
		if (i + 1 < n && a[i] < 0) {
			int kariru = ((-a[i]) + 9) / 10;
			a[i] += 10 * kariru;
			a[i + 1] -= kariru;
		}
	}
	return a;
}

//2で割る
vector<int> half(vector<int> a, int n) {
	vector<int> ret(n, 0);
	int val = 0;
	for (int i = n - 1; i >= 0; i--) {
		val *= 10;
		val += a[i];
		ret[i] = val / 2;
		val -= ret[i] * 2;
	}
	return ret;
}

int bitCnt[1024];
void initBitCnt() {
	for (int i = 0; i < 1024; i++) {
		bitCnt[i] = 0;
		for (int j = 0; j < 10; j++) {
			if ((i >> j) & 1) bitCnt[i]++;
		}
	}
}

//桁DPで, a以下の短歌数を数える.
int INF = 1e+18;
int dp[101][1024][2];	//dp[残り桁数][今までに使った数の集合(leading 0はカウントしない)][aと一致しているか]

int dfs(int ketasu, int used, bool flag, vector<int> &a) {
	if (bitCnt[used] > 2) return 0;
	if (ketasu == 0) return (bitCnt[used] == 2);
	if (dp[ketasu][used][flag] != -1) return dp[ketasu][used][flag];
	
	int ret = 0;
	for (int i = 0; i < 10; i++) {	//次の桁をiにする
		if (flag && a[ketasu - 1] < i) break;
		
		int nUsed;
		if (used == 0 && i == 0) nUsed = 0;
		else nUsed = (used | (1 << i));
		ret += dfs(ketasu - 1, nUsed, flag && a[ketasu - 1] == i, a);
	}
	return dp[ketasu][used][flag] = ret;
}

//メモの初期化
void initDp() {
	for (int i = 0; i < 101; i++) for (int j = 0; j < 1024; j++) for (int k = 0; k < 2; k++) dp[i][j][k] = -1;
}

//2分探索の終了条件
bool isContinue(vector<int> st, vector<int> ed, int n) {
	vector<int> res = sub(ed, st, n);
	
	if (res[0] >= 2) return true;
	for (int i = 1; i < n; i++) {
		if (res[i] != 0) return true;
	}
	return false;
}

int n;

void solve() {
	initBitCnt();
	
	int i, cnt = 0;
	for (i = 1; ; i++) {
		cnt += 81 * ((1LL << (i - 1)) - 1);
		if (cnt >= n) break;
	}
	int ketasu = i;
	
	vector<int> st(ketasu), ed(ketasu), mid(ketasu);
	for (i = 0; i < ketasu; i++) st[i] = 0;
	for (i = 0; i < ketasu; i++) ed[i] = 9;
	
	//2分探索. xxxooo, (st, ed]
	while (isContinue(st, ed, ketasu)) {
		mid = add(st, ed, ketasu);
		mid = half(mid, ketasu);
		initDp();
		int res = dfs(ketasu, 0, true, mid);
		if (res >= n) ed = mid;
		else st = mid;
	}
	
	for (i = ketasu - 1; i >= 0; i--) {
		if (ed[i] != 0) break;
	}
	for (; i >= 0; i--) {
		cout << ed[i];
	}
	cout << endl;
}

signed main() {	
	while (cin >> n) {
		if (!n) break;
		solve();
	}
	return 0;
}


Measured memory_bytes: 4780
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=100005;

int n,m,ans;
int a[N],b[N];
int cnt[N];

struct DSU
{
	int fa[N],sz[N];
	void init()
	{
		for(int i=1;i<=n;i++) fa[i]=i;
		for(int i=1;i<=n;i++) sz[i]=1;
	}
	int find(int x)
	{
		return fa[x]=(fa[x]==x?x:find(fa[x]));
	}
	void unite(int x,int y)
	{
		x=find(x); y=find(y);
		if(x==y) return;
		ans-=sz[x]*sz[y];
		sz[y]+=sz[x];
		fa[x]=y;
	}
}dsu;

signed main()
{
	
	cin>>n>>m;
	for(int i=1;i<=m;i++)
		cin>>a[i]>>b[i];
	ans=n*(n-1)/2;
	dsu.init();
	for(int i=m;i>=1;i--)
	{
		cnt[i]=ans;
		dsu.unite(a[i],b[i]);
	}
	for(int i=1;i<=m;i++)
		cout<<cnt[i]<<'\n';
	
	return 0;
}

Measured memory_bytes: 5248
#include <iostream>

using namespace std;


int calc(int K){
    if( K < 0){return -1;}

    if( K % 2 == 0){ return -1; }

    

    int ans = 1; 
    unsigned long long sevens = 7;
    for( int i = 0; i <= K; i++){
        sevens = sevens % K;
        if( sevens == 0){ return ans;}

        ans++;
        sevens = sevens*10 + 7;
    }
    return -1;
};




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

    int answer = calc(K);

    cout << answer;

}

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


#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int N = 2e5 + 10;


using namespace std;

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  IOS;

  int n;
  cin >> n;

  string s;

  ll cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;

  while (n--)
  {
    cin >> s;

    if (s == "AC")
    {
      cnt1++;
    }

    else if (s == "TLE")
    {
      cnt3++;
    }

    else if (s == "WA")
    {
      cnt2++;
    }

    else
    {
      cnt4++;
    }
  }

  cout << "AC" << " " << 'x' << " " << cnt1 << endl;
  cout << "WA" << " " << 'x' << " " << cnt2 << endl;
  cout << "TLE" << " " << 'x' << " " << cnt3 << endl;
  cout << "RE" << " " << 'x' << " " << cnt4 << endl;



  return 0;
}


Measured memory_bytes: 3672
N = int(input())
L = list(map(int, input().split()))

ans = 0
for i in range(N):
    for j in range(N):
        for k in range(N):
            if L[i] != L[j] and L[j] != L[k] and L[k] != L[i] and abs(L[i] - L[j]) < L[k] < L[i] + L[j]:
                ans += 1
print(ans // 6)


Measured memory_bytes: 9164
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



int main() {
  int n, x;
  cin >> n >> x;
  vector<int> m(n);
  rep(i, n) {
    cin >> m[i];
    x -= m[i];
  }

  sort(all(m));

  cout << n + x / m[0] << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;
typedef long long ll;
typedef long double ld;

ll temp1,temp2,temp;
char tempc;

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

#define N 1000000007
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define pi pair<int,int>
#define pl pair<ll,ll>
#define int ll
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)

ll binpow(ll a, ll b)
{
    a%=N;b=b%(N-1);
    ll res=1;
    while(b>0)
    {
        if(b&1) res=res*a%N;
        a=a*a%N;
        b>>=1;
    }
    return res%N;
}

int simpow(int a,int b)
{
    // b=b%(N-1);
    ll res=1;
    while(b>0)
    {
        if(b&1) res=res*a;
        a=a*a;
        b>>=1;
    }
    return res;
}

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

int mini(int a,int b)
{
    if(a<b) return a;
    return b;
}

// struct DSU {
//     vector<int> sz;
//     vector<int> parent;
 
//     void make_set(int v) {
//         parent[v] = v;
//         sz[v] = 1;
//     }
 
//     int find_set(int v) {
//         if (v == parent[v])
//             return v;
//         return parent[v] = find_set(parent[v]);
//     }
 
//     void union_sets(int a, int b) {
//         a = find_set(a);
//         b = find_set(b);
//         if (a != b) {
//             if (sz[a] < sz[b])
//                 swap(a, b);
//             parent[b] = a;
//             sz[a] += sz[b];
//         }
//     }
 
//     DSU(int n) {
//         sz.resize(n+1);
//         parent.resize(n+1);
//         for (int i = 1; i <= n; i++) make_set(i);
//     }
// };

signed main()
{
    fast;
    int x; cin >> x;
    cout << 360/gcd(360,x) << endl;
}

Measured memory_bytes: 3588
import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

def check(a, b):
    ans = 0
    for i in range(len(a)):
        if a[i] != b[i]:
            ans += 1
    return ans

s = input()
t = input()
n = len(t)
ans = 10 ** 10
for i in range(len(s) - n + 1):
    ans = min(ans, check(s[i: i + n], t))
print(ans)

Measured memory_bytes: 9100
n, t = [int(_) for _ in input().split()]
e = [[int(_) for _ in input().split()] for _ in range(n)]

c = 1001
for i in range(n):
    if e[i][1] <= t:
        c = min(c, e[i][0])
if c <= 1000:
    print(str(c))
else:
    print('TLE')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  int n;
  cin>>n;
  int fx = 0;
  int x = n;
  while(x != 0) {
    fx += x % 10;
    x /= 10;
  }
  if(n % fx == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>

using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> PP;

int fie[101][101];
bool fie2[101][101];
int cox[11],coy[11];
int m,n,s,sn;
int ans=0;
const int dx1[6]={-1,-1,-1,0,1,0};
const int dx0[6]={0,-1,0,1,1,1};
const int dy[6]={-1,0,1,-1,0,1};
const int INF=100000;

void bfs(int x,int y){
	queue<PP> que;
	que.push(PP(0,P(x,y)));
	fie[x][y]=0;
	while(que.size()){
		PP p=que.front();que.pop();
		int v=p.first,kx=p.second.first,ky=p.second.second;
		for(int i=0;i<6;i++){
			int fx=kx,fy=ky+dy[i];
			if(ky%2==1)fx+=dx1[i];
			if(ky%2==0)fx+=dx0[i];
			if(fx>=1 && fx<=m && fy>=1 && fy<=n){
				if(fie[fx][fy]>v+1){
					que.push(PP(v+1,P(fx,fy)));
					fie[fx][fy]=v+1;
				}
			}
		}
	}
}

int bfs2(int x,int y){
	memset(fie2,false,sizeof(fie2));
	int res=1;
	if(fie[x][y]==0)return 0;
	queue<PP> que;
	que.push(PP(0,P(x,y)));
	fie2[x][y]=true;
	while(que.size()){
		PP p=que.front();que.pop();
		int v=p.first,kx=p.second.first,ky=p.second.second;
		for(int i=0;i<6;i++){
			int fx=kx,fy=ky+dy[i];
			if(ky%2==1)fx+=dx1[i];
			if(ky%2==0)fx+=dx0[i];
			if(fx>=1 && fx<=m && fy>=1 && fy<=n){
				if(fie[fx][fy]>v+1 && fie2[fx][fy]==false){
					que.push(PP(v+1,P(fx,fy)));
					res++;
					fie2[fx][fy]=true;
				}
			}
		}
	}
	return res;
}

int main(void){
	while(1){
		scanf("%d",&m);
		if(m==0)break;
		scanf("%d",&n);
		for(int i=0;i<=100;i++){
			for(int j=0;j<=100;j++){
				fie[i][j]=INF;
			}
		}
		ans=0;
		scanf("%d",&s);
		for(int i=0;i<s;i++){
			int x,y;
			scanf("%d%d",&x,&y);
			bfs(x,y);
		}
		scanf("%d",&sn);
		for(int i=0;i<sn;i++){
			int x,y;
			scanf("%d%d",&x,&y);
			ans=max(ans,bfs2(x,y));
		}
		printf("%d\n",ans);
	}
    return 0;
}

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

int main() {
    int n;
    string c;
    cin >> n >> c;
    int r = 0;
    for (int i = 0; i < n; i++) {
        if (c[i] == 'R') {
            r++;
        }
    }
    int ans = 0;
    for (int i = 0; i < r; i++) {
        if (c[i] == 'W') {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3752
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>

using namespace std;
using ll = long long;

unsigned gcd(unsigned a, unsigned b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

int main() {
    ll q,h,s,d,n,ans=0;
    cin >> q>>h>>s>>d;
    cin >> n;
    if(q*2<h)   h=q*2;
    if(h*2<s)   s=h*2;
    if(s*2<d)   d=s*2;
    ans+=(n/2)*d;
    n=n%2;
    cout << ans+n*s << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define PI acos(-1)
#define ll long long int
#define MOD (int) (1e9+7)
#define in_arr(ar) for(int i=0;i<sizeof(ar)/sizeof(ar[0]);i++)cin>>ar[i];
#define val(x) cout<<"Value of "<<(#x)<<" is "<<x<<endl;
 
 
 
int main()
{
	long double a,b;
	cin>>a>>b;
	ll fao = a*b;
	cout<<fao<<endl;
}

Measured memory_bytes: 3748
/***************************************************************
	File name: A.cpp
	Author: ljfcnyali
	Create time: 2019年10月27日 星期日 19时54分27秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) 
#define mem(a) memset ( (a), 0, sizeof ( a ) ) 
#define str(a) strlen ( a ) 
#define pii pair<int, int>
typedef long long LL;

int main()
{
    int a, b; scanf("%d%d", &a, &b);
    if ( a > 9 || b > 9 ) puts("-1");
    else printf("%d\n", a * b);
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<functional>
#include<map>
#include<cstring>
#include<iostream>

using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> PP;
int fie[21][21];
int dp[21][21][1<<10];
int w,h;
int rx,ry;
int sx[4]={1,0,-1,0};
int sy[4]={0,1,0,-1};
int dcnt;

int bfs(){
	queue<PP> que;
	memset(dp,-1,sizeof(dp));
	dp[rx][ry][0]=0;
	que.push(PP(0,P(rx,ry)));
	while(que.size()){
		PP q=que.front();
		que.pop();
		int x=q.second.first,y=q.second.second,bit=q.first;
		if(bit==(1<<dcnt)-1)return dp[x][y][bit];
		for(int i=0;i<4;i++){
			int nx=x+sx[i],ny=y+sy[i];
			if(nx>=0 && nx<w && ny>=0 && ny<h){
				if(fie[nx][ny]==0 && dp[nx][ny][bit]==-1){
					dp[nx][ny][bit]=dp[x][y][bit]+1;
					que.push(PP(bit,P(nx,ny)));
				}
				if(fie[nx][ny]>0){
					int nbit=bit|(1<<(fie[nx][ny]-1));
					if(dp[nx][ny][nbit]==-1){
						dp[nx][ny][nbit]=dp[x][y][bit]+1;
						que.push(PP(nbit,P(nx,ny)));
					}
				}
			}
		}
	}
	return -1;
}

int main(void){
	while(1){
		scanf("%d %d",&w,&h);
		if(w+h==0)break;
		dcnt=0;
		for(int i=0;i<h;i++){
			string str;
			cin >> str;
			for(int j=0;j<w;j++){
				if(str[j]=='o'){
					fie[j][i]=0;
					rx=j,ry=i;
				}
				if(str[j]=='.'){
					fie[j][i]=0;
				}
				if(str[j]=='*'){
					dcnt++;
					fie[j][i]=dcnt;
				}
				if(str[j]=='x'){
					fie[j][i]=-1;
				}
			}
		}
		printf("%d\n",bfs());
	}
	return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

int main() {
    string s;
    cin >> s;
    int a = 0;
    
    if (s[0] == '1') a++;
    if (s[1] == '1') a++;
    if (s[2] == '1') a++;

    cout << a << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-4;
bool eq(double a, double b)
{
	return abs(a - b) < Eps;
}

using namespace std;

int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		pair<int, int> best[4];
		pair<int, int> worst[3];
		for (int i = 0; i < 4; ++i)
			best[i] = make_pair(10000000, 0);
		for (int i = 0; i < 3; ++i)
			worst[i] = make_pair(0, 0);
		while (n--)
		{
			int id;
			scanf("%d", &id);
			int total = 0;
			for (int i = 0; i < 4; ++i)
			{
				int m, s;
				scanf("%d %d", &m, &s);
				total += m*60 + s;
			}
			best[3] = worst[0] = make_pair(total, id);
			sort(best, best+4);
			sort(worst, worst+3);
		}
		printf("%d\n%d\n%d\n", best[0].second, best[1].second, worst[1].second);
	}

	return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(n);i++)

using namespace std;


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

    ll tp = t[0];
    ll ap = a[0];
    rep(i, n){
        if(t[i] == a[i]){
            ll m = max(tp, ap);
            tp = ap = m;
        }
        else{
            while (tp % t[i] != 0)  tp++;
            while (ap % a[i] != 0)  ap++;

            ll tt = tp/t[i];
            ll at = ap/a[i];
            if(tt < at) tp = at*t[i];
            if(at < tt) ap = tt*a[i];
        }
    }

    cout << tp + ap << endl;


    return 0;
}

Measured memory_bytes: 384