akhauriyash/Code-Regression huggingface dataset:
n, ma, mb = gets.strip.split.map(&:to_i)
abc = readlines.map {|line| line.strip.split.map(&:to_i) }

limit = 40*10
medicine_limit = 40
INF = 10**12

dp = Array.new( medicine_limit+1 ) { Array.new( limit+1 ) { [INF]*(limit+1) } }
dp[0][0][0]=0

abc.each_with_index do |abc, abci|
  a, b, c = abc
#  dp[abci][a][b]=c if dp[abci][a][b]==INF
#  dp[abci][a][b] = [ c, dp[abci][a][b] ].min

  limit.times do |i|
    limit.times do |j|
      next if dp[abci][i][j]==INF

      dp[abci+1][i][j] = [ dp[abci+1][i][j], dp[abci][i][j] ].min
      dp[abci+1][i+a][j+b] = [ dp[abci+1][i+a][j+b], dp[abci][i][j]+c ].min

    end
  end
end

result = INF

limit.times do |i|
  limit.times do |j|
    ii = (i+1)
    jj= (j+1)
    if (ii*mb == jj*ma)
      result = [ dp[n][ii][jj], result ].min
    end
  end
end

if result == INF
  p -1
  exit
end

p result



Measured memory_bytes: 55292
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<functional>
#include<map>
#include<stack>
#include<set>
#include<cmath>

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

#define EPS 1e-6

using namespace std;


int main(){

	string s;
	getline(cin,s);

	int n=s.size();

	rep(i,n){

	if(s[i]-'a'>=0 && s[i]-'a'<=25){
	s[i]=s[i]-'a'+65;
	cout << s[i];
	}
	else cout << s[i];

	}

    cout << endl;

    return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
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;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main(){
  ll n,k,r,s,p;
  cin>>n>>k>>r>>s>>p;
  string t;
  cin>>t;
  ll ans=0;
  rep(i,n){
    if(i<n-k){
      if(t[i]=='x') continue;
      if(t[i]=='r'){
        ans+=p;
        if(t[i+k]=='r'){
          t[i+k]='x';
        }
      }
      if(t[i]=='s'){
        ans+=r;
        if(t[i+k]=='s'){
          t[i+k]='x';
        }
      }
      if(t[i]=='p'){
        ans+=s;
        if(t[i+k]=='p'){
          t[i+k]='x';
        }
      }
    }else{
      if(t[i]=='x') continue;
      if(t[i]=='r'){
        ans+=p;
      }
      if(t[i]=='s'){
        ans+=r;
      }
      if(t[i]=='p'){
        ans+=s;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3780
#include <stdio.h>
int GCD(int a, int b)
{
	return b == 0 ? a : GCD(b, a%b);
}
long long int lcm(long long int a, long long int b)
{
	return (a*b / GCD(a, b));
}

int main()
{ int a, b; while (scanf("%d%d", &a, &b) != EOF)printf("%d %d\n", GCD(a, b),lcm(a,b)); return 0; }

Measured memory_bytes: 2712
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int N,a[55555]={},k=0,b[55555]={},l=0;
    bool flag ;

    cin >> N;

    for(int i=2;i<=55555;i++){
        flag =0;
        for(int j=2;j<i;j++){
            if(i%j==0){
                flag = 1;
                break;
            }
        }
        if(flag==0){
            a[k]=i;
            k+=1;
        }
    }
    //55555までの素数をa[0]からa[k]まで格納
    
    for(int i=0;i<=k;i++){

        if((a[i]%5)==1){
            b[l]=a[i];
            l+=1;
        }

    }
    
    for(int m=0;m<N;m++){
        cout << b[m] << " ";
    }
    
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOJALDS11D
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var rList = new List<Int32>();

            for (var i = 0; i < n; i++)
            {
                rList.Add(int.Parse(Console.ReadLine()));
            }

            int maxv = -2000000000;
            int minv = rList[0];

            for (int i = 1; i < n; i++)
            {
                maxv = Math.Max(maxv, rList[i] - minv);
                minv = Math.Min(minv, rList[i]);
            }

            Console.WriteLine("{0}",maxv);
            Console.ReadLine();
        }
    }
}



Measured memory_bytes: 21424
n,*a=map(int,open(0).read().split())
b=[0]*-~n
for i in range(n,0,-1):
    t=0
    for j in range(i,n+1,i):
        t+=b[j]
    b[i]=(t+a[i-1])%2
c=[i for i,b in enumerate(b)if b]
print(len(c),*c)

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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    bool ok = 1;
    int tmp = 0;
    int curx = 0, cury = 0;
    for (int i = 0; i < n; ++i) {
        int t, x, y; cin >> t >> x >> y;
        int t1 = t - tmp;
        int dis = abs(curx - x) + abs(cury - y);
        ok &= (dis <= t1 && (t1 - dis) % 2 == 0);
        tmp = t;    
        curx = x, cury = y;
    }
    cout << (ok ? "Yes" : "No");
        return 0; 
}

Measured memory_bytes: 256
#include <stdio.h>
int counter(int z){
    if(z==0) return 0;
    else return counter(z>>1)+(z&1);
}
int main(void){
    int n,i,j,k,max=0,cnt,flag=1;
    int a[20],x[20][20],y[20][20];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        for(j=0;j<a[i];j++){
            scanf("%d %d",&x[i][j],&y[i][j]);
        }
    }
    for(i=0;i<(1<<n);i++){
        flag=1;
        for(j=0;j<n;j++){
            if(!(i&(1<<j))) continue;
            for(k=0;k<a[j];k++){
                if((i>>(x[j][k]-1)&1)^y[j][k]){
                    flag=0;
                    break;
                }
            }
        }
        if(flag){
            cnt=counter(i);
            if(max<cnt) max=cnt;
        }
    }
    printf("%d\n",max);
    return 0;
}

Measured memory_bytes: 128
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
#include<stack>
#include<queue>
#include <cassert>
using namespace std;

 
int main(){
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if(s == u){
        a--;
    }
    else{
        b--;
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
/*
      author : nishi5451
      created: 11.08.2020 21:54:50
*/

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


int main(){
    string s;
    cin >> s;
    if(s[3]==s[2] || s[2]==s[1] || s[1]==s[0])
        cout << "Bad" << endl;
    else cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 3572
N = int(input())
A = list(map(int, input().split()))
ans = 0
MOD = 10 ** 9 + 7
s = 0
for i in range(N - 1):
	s += A[i]
	tmp = s * A[i + 1]
	ans += (tmp % MOD)
print(ans % MOD)


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

int main() {
  int N, K;
  cin >> N >> K;
  int cnt=0;
  do{
   cnt++;
  }while(N = N/K);
  cout << cnt << endl;
  return 0;
}




Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int main() {
	ll n,k;cin>>n>>k;
	ll ans=pow(n/k,3);
	if(k%2==0) ans+=pow((n+k/2)/k,3);
	cout<<ans<<endl;
}


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

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef set<int> si;
typedef set<ll> sll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

const double pi = acos(-1.0);
const long long INF = 2e18;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define in insert
#define endl "\n"

#define sqr(a) ((a) * (a))
#define jor(a) !(a&1)// jor means EVEN number
#define bjor(a) (a&1)// bjor means ODD number

#define all(a)  a.begin(), a.end()
#define mem(arr, b) memset(arr, b, sizeof(arr)) //memset only for -1 and 0
//fill(a, a+n, 5) //fill for any value

#define for0(i,b) for(int i=0;i<(b);i++)
#define for1(i,b) for(int i=1;i<=(b);i++)
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define forba(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fileRead freopen("input.txt", "r", stdin);
#define fileWrite freopen("output.txt", "w", stdout);

void print(int a[], int n){ // for testing or debugging
    for(int i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
}

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

int main()
{
    int n; cin>>n;
    int a[n];
    for0(i,n) cin>>a[i];
    
    int dp[n] = {0};/// dp[x] means min cost to reach a[x]
    dp[0] = 0;
    dp[1] = abs(a[0]-a[1]);

    for(int i=2; i<n; i++){
        dp[i] = min( dp[i-1]+abs(a[i]-a[i-1]),
                    dp[i-2]+abs(a[i]-a[i-2]) );
    }

    cout<<dp[n-1];
}

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

using namespace std;

bool judge(
  int64_t H, int64_t W, int64_t N, 
  int64_t sr, int64_t sc, 
  const string &S, const string &T,
  int64_t dy, int64_t dx, char s, char t
)
{
  int64_t y = sr - 1, x = sc - 1;
  for (int64_t n = 0; n < N; ++n) {
    if (S[n] == s) { y += dy; x += dx; }
    if (!((0 <= y && y < H) && (0 <= x && x < W))) { return false; }
    if (T[n] == t) { y -= dy; x -= dx; }
    if (!((0 <= y && y < H) && (0 <= x && x < W))) { y += dy; x += dx; }
  }
  return (0 <= y && y < H) && (0 <= x && x < W);
}

int main()
{
  int64_t H, W, N;
  cin >> H >> W >> N;
  
  int64_t sr, sc;
  cin >> sr >> sc;
  
  string S, T;
  cin >> S >> T;
  
  bool flag = true;
  flag &= judge(H, W, N, sr, sc, S, T,  0, +1, 'R', 'L');
  flag &= judge(H, W, N, sr, sc, S, T,  0, -1, 'L', 'R');
  flag &= judge(H, W, N, sr, sc, S, T, +1,  0, 'D', 'U');
  flag &= judge(H, W, N, sr, sc, S, T, -1,  0, 'U', 'D');
  cout << (flag ? "YES" : "NO") << endl;
  
  return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
            using namespace std;
            #define rep(i,b) for(i=0;i<b;++i)
            #define repp(i,a,b) for(i=a;i<b;++i)
            #define endl "\n"
            #define pi 3.14159265358979323846
            //#define LLONG_MAX 99999999999999
            typedef long long int lli;
            int main(){
                lli i,t,n,j,k,m,g;
                cin>>n;
                if(n==1){
                    cout<<0<<endl;
                    return 0;
                }
                vector<vector<pair<lli,lli>>> v(n+1);
                rep(i,n-1){
                    cin>>m>>g>>k;
                    v[m].push_back({g,k});
                    v[g].push_back({m,k});
                }
                vector<lli> ans(n+1);
                rep(i,n+1)ans[i]=-1;
                ans[1]=0;
                queue<lli> q;
                q.push(1);
                while(!q.empty()){
                    m=q.front();
                    //cout<<m<<" "<<v[m].size()<<endl;
                    q.pop();
                    rep(i,v[m].size()){
                        if(ans[v[m][i].first]==-1){
                            //cout<<m<<" "<<v[m][i].first<<endl;
                            q.push(v[m][i].first);
                            if(v[m][i].second%2==0){
                                ans[v[m][i].first]=ans[m];
                            }
                            else{
                                ans[v[m][i].first]=(ans[m]+1)%2;
                            }
                        }
                    }
                }
                repp(i,1,n+1)cout<<ans[i]<<endl;

                return 0;
            }


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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

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

int main()
{
    int h, w, K;
    cin >> h >> w >> K;
    vector<string> vs(h);
    REP(i, h)
    cin >> vs[i];
    vector<vector<int>> a(h, vector<int>(w, 0));
    REP(i, h)
    {
        REP(j, w)
        {
            if (i != 0)
                a[i][j] += a[i - 1][j];
            if (j != 0)
                a[i][j] += a[i][j - 1];
            if (i != 0 && j != 0)
                a[i][j] -= a[i - 1][j - 1];
            if (vs[i][j] == '1')
                a[i][j]++;
        }
    }
    int n = 1;
    REP(i, h - 1)
    n *= 2;
    int ans = 2000;
    REP(i, n)
    {
        int cnt = 0;
        vector<pair<int, int>> hcut;
        int up = 0;
        REP(j, h)
        {
            if ((i >> j) & 1) {
                cnt++;
                hcut.push_back({ up, j });
                up = j + 1;
            }
            if (j == h - 1) {
                hcut.push_back({ up, j });
            }
        }

        int start = 0;
        bool able = true;
        REP(j, w)
        {
            REP(k, hcut.size())
            {
                int whitecnt = a[hcut[k].second][j];
                if (hcut[k].first != 0)
                    whitecnt -= a[hcut[k].first - 1][j];
                if (start != 0)
                    whitecnt -= a[hcut[k].second][start - 1];
                if (hcut[k].first != 0 && start != 0)
                    whitecnt += a[hcut[k].first - 1][start - 1];
                if (whitecnt > K) {
                    if (j == start) {
                        able = false;
                        break;
                    }
                    start=j;
                    cnt++;
                    j--;
                    break;
                }
            }
            if (!able)
                break;
        }
        if(able){
            ans=min(ans,cnt);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3660
program abc129c
  implicit none
  integer :: n, m, i
  integer,dimension(:),allocatable :: s, a
  read *, n, m
  allocate(s(-1:n))
  s = 1
  s(-1) = 0
  if (m/=0) then
     allocate(a(m))
     read *, a
     s(a) = 0
  end if
  do i = 1,n
     if (s(i)/=0) s(i) = mod(s(i-1)+s(i-2),10**9+7)
  end do
  print *, s(n)
end program abc129c


Measured memory_bytes: 1536
n = int(input())
words = [input() for i in range(n)]

if len(set(words)) != n:
    print("No")
else:
    can = True
    for i in range(1, n):
        if words[i-1][len(words[i-1])-1] != words[i][0]:
            can = False
    if can:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 510000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	edge(int _t) : t(_t) {}
};
bool use[100010];


vector<edge> te[100010];
vector<edge> fe[100010];

void Solve() {

	string s;
	cin >> s;
	string exp = "CODEFESTIVAL2016";
	int res = 0;
	for (size_t i = 0; i < s.size(); i++)
	{
		if (s[i] != exp[i]) res++;
	}

	cout << res << endl;
}


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



Measured memory_bytes: 6400
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const int mod = 1e9+7;
const int N = 1e5+5;
//int a[N];

int main()

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

    int a, b;

    cin >> a >> b;

    if (a == 2 || b == 2) cout << "No";
    else cout << "Yes";

    return 0;
}


Measured memory_bytes: 256
/*
 * Biborno
 * fb.com/mfmejbah
 * fmejbah@gmail.com
 *
 * A.cpp
 * Date: 04 Mar 2017
 */

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  n *= 2;
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  sort(a, a + n);
  int ans = 0;
  for (int i = (n & 1); i < n; i += 2) {
    ans += a[i];
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 256
//https://agc028.contest.atcoder.jp/tasks/agc028_b
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,i,j,a[100005],inv[100005],ans=0; 
const ll mod=1e9+7;
int main()
{
	scanf("%lld",&n);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]);
	inv[1]=1;
	for(i=2;i<=n;i++)inv[i]=(-inv[mod%i]*(mod/i)%mod+mod)%mod;
	for(i=2;i<=n;i++)inv[i]=(inv[i-1]+inv[i])%mod;
	for(i=1;i<=n;i++)ans=(ans+a[i]*(inv[i]+inv[n-i+1]-1+mod)%mod)%mod;
	for(i=1;i<=n;i++)ans=ans*i%mod;
	printf("%lld",ans);
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int s = n - 1 >= 2;

    auto f = [&](ll k) {
        ll t = n;
        while (t % k == 0) t /= k;
        if (t % k == 1) s++;
    };

    for (ll i = 1; i * i <= n; i++) {
        ll q = n / i;
        ll r = n % i;

        if (r == 0) {
            if (i >= 2) f(i);
            if (i < q) f(q);
        }
        if (r == 1) {
            s += (i >= 2) + (i < q);
        }
    }

    cout << s << 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 repr(i, n) for (int i = n-1; i >= n; i--)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
const int mod = 1e9+7;

const ll INF = 1e14;
const int MAX = 1e4;

struct edge {int to, cost;};
vector<edge> graph[MAX]; // 隣接リスト
ll dist[MAX]; // 始点からの距離

void bellman_ford(int n, int s, bool &flag) {
    fill(dist, dist+MAX, INF);
    dist[s] = 0;
    for (int i = 0; i < n; i++) { // 頂点の数ループ
        rep(from, n) {
            for (edge e : graph[from]) {
                if (dist[e.to] > dist[from] + e.cost) {
                    dist[e.to] = dist[from] + e.cost;
                    if (i >= n-1 and e.to == n-1) { // 負の閉路の検出
                        flag = true;
                        return;
                    }
                }
            }
        }
    }
}

int main() {
    // input
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int from, to, cost;
        cin >> from >> to >> cost;
        from--; to--; cost *= -1;
        graph[from].push_back({to, cost});
    }
    // solve
    bool flag = false;
    bellman_ford(n, 0, flag);
    if (not flag) {
        cout << -dist[n-1] << "\n";
    } else {
        cout << "inf" << "\n";
    }
}

Measured memory_bytes: 3936
#include <algorithm>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using ll = long long int;
#define int ll

const int MOD = 1e9 + 7;
const int INF = 1e15 + 373;

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

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> init_vector2(size_t n0, size_t n1, T e = T()) {
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> init_vector3(size_t n0, size_t n1, size_t n2, T e = T()) {
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    for (T e : v) {
        os << e << ", ";
    }
    os << "]";
    return os;
}

int gcd(int a, int b) {
    while (b != 0) {
        int m = a % b;
        a = b;
        b = m;
    }
    return a;
}

signed main() {
    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    rep(i, n) { cin >> a[i]; }

    int m = a[0];
    rep(i, n) { m = gcd(m, a[i]); }

    cout << (k <= *max_element(a.begin(), a.end()) && k % m == 0 ? "POSSIBLE"
                                                                 : "IMPOSSIBLE")
         << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){
  int n,p;
  cin >> n >> p;
  ll ans=0;
  ll nxt=0;
  ll cnt=0;
  rep(i,n){
    ll t; cin >> t;
    if(nxt<=t){ 
      ans += (nxt-cnt); 
      nxt=t+p; 
      cnt=t;
    } else {
      nxt=t+p;
    }
  }
  ans+=nxt-cnt;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    string s, t; cin >> s >> t;
    string ans = "";
    for(int i = 0; i < s.size() + t.size(); ++i){
        if(i % 2 == 0)ans += s[i/2];
        else ans += t[i/2];
    }
    cout << ans << endl;
}

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

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

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

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


int main() {
  int n, k;
  cin>>n>>k;
  COMinit();
  if (k >= n) {
    cout<<COM(n + n - 1, n - 1)<<endl;
    return 0;
  }
  long long ans = 0;
  for (int i=1; i<=k; i++) {
    ans += COM(i + n - i- 1, n - i -1) * COM(n, i) % MOD;
    ans %= MOD;
  }
  if (k >= 2) {
    ans += 1;
    ans %= MOD;
  }
  cout<<ans % MOD<<endl;
}

Measured memory_bytes: 12160
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;

int main()
{
    int n, m, n_pow = 0, ans = 0;
    cin >> n >> m;
    vector< vector<int> > s(m);
    vector<int> p(m);
    
    for (auto & ss:s)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; ++j)
        {
            int tmp;
            cin >> tmp;
            ss.push_back(tmp-1);
        }
    }
    for (auto &tp : p) cin >> tp;
    n_pow = (1<<n);
     
    for (int i = 0; i < n_pow; ++i)
    {
        bitset<10> bs(i);
        int index = 0;
        bool fail = false;
        for (auto & ss:s) {
            int t = 0;
            for (auto & ts : ss) t+=(int)bs[ts];
            if (t%2 != p[index++]) {
                fail = true;
                break;
            }
        }
      	ans += !fail;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long int 
using namespace std;
int main(){
    ll n;
    cin>>n;
    ll ans = 100;
    ll i=0;
    while(ans<n){
        i++;
        ans = ans*(1.01);
    }
    cout<<i;
}


Measured memory_bytes: 3624
#include <cassert>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

using namespace std;

int vs[100000+10];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d", &vs[i]);
  }
  int res = 1;
  REP(i, 2) {
    int v = vs[i];
    for(int g = 1; g*g <= v; ++g) {
      if(v % g == 0) {
        {
          int d = g;
          int cnt = 0;
          REP(k, n) {
            if(vs[k] % d != 0) {
              ++cnt;
              if(cnt > 1) {
                break;
              }
            }
          }
          if(cnt <= 1) {
            res = max(res, d);
          }
        }
        {
          int d = v / g;
          int cnt = 0;
          REP(k, n) {
            if(vs[k] % d != 0) {
              ++cnt;
              if(cnt > 1) {
                break;
              }
            }
          }
          if(cnt <= 1) {
            res = max(res, d);
          }
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, A = map(int, readline().split())
X = list(map(int,readline().split()))
Y = [x-A for x in X]
dp = {0:1}

for y in Y:
    tmp = list(dp.items())
    for k,v in tmp:
        dp[k+y] = dp.get(k+y,0) + v
print(dp[0]-1) 

Measured memory_bytes: 66524
#include <iostream>
#include <sstream>

using namespace std;


int main() {
    int w, h;

    while (1) {
        cin >> h >> w;
        if (!w && !h) {
            break;
        }
        stringstream ss1, ss2;
        for (int i = 0; i < w; ++i) {
            ss1 << '#';
            ss2 << (!i || i == w - 1 ? '#' : '.');
        }
        string str1 = ss1.str(), str2 = ss2.str();
        for (int j = 0; j < h; ++j) {
            cout << (!j || j == h - 1 ? str1 : str2) << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  vector<int> P(n); rep(i, n) cin >> P[i];
  vector<bool> isLarger(n);
  rep(i, n-1) if(P[i] < P[i+1]) isLarger[i+1] = true;
  vector<int> sum(n+1);
  rep(i, n) sum[i+1] = sum[i] + isLarger[i];
  int cnt = 0;
  set<int> st;
  rep(i, k) st.insert(P[i]);
  int ans = 0;
  int sorted = 0;
  if(sum[k]-sum[1] == k-1) sorted++;
  else ans++;
  REP(i, k, n) {
    if(sum[i+1]-sum[i-k+2] == k-1) sorted++;
    else if(*st.begin() != P[i-k] || *st.rbegin() >= P[i]) ans++;
    st.erase(P[i-k]);
    st.insert(P[i]);
  }
  cout << ans+(sorted>0) << "\n";
  return 0;
}


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

int main()
{
	int M;
	bool ok=false;
	while(cin>>M && M!=0){
		if(ok) cout<<endl;
		ok=true;
		int m[4];
		int ans[4];
		for(int i=0;i<4;i++){
			cin>>m[i];
			ans[i]=m[i];
		}

		int have=m[0]*10+m[1]*50+m[2]*100+m[3]*500;

		M=have-M;

//		cout<<M<<endl;
		ans[3]-=M/500;
		M%=500;
//		cout<<M<<endl;
		ans[2]-=M/100;
		M%=100;
//		cout<<M<<endl;
		ans[1]-=M/50;
		M%=50;
//		cout<<M<<endl;
		ans[0]-=M/10;
//		cout<<M<<endl;
		
		if(ans[0]>0) cout<<10<<" "<<ans[0]<<endl;
		if(ans[1]>0) cout<<50<<" "<<ans[1]<<endl;
		if(ans[2]>0) cout<<100<<" "<<ans[2]<<endl;
		if(ans[3]>0) cout<<500<<" "<<ans[3]<<endl;
	}
	return 0;
}

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

#define ll long long

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string s,t,u;
	int a,b;
	cin >> s >> t;
	cin >> a >> b;
	cin >> u;
	if(u==s)
		a--;
	else
		b--;
	cout << a <<" " << b;
}

Measured memory_bytes: 256
import copy
from collections import deque

#反省bfsだと計算量が多くなってしまうパターンだった。bfsが正解。
def dfs(x,y,z,grid,H,W):
    if(x-1>=0):
        if(grid[y][x-1]>z or grid[y][x-1]==0):
            grid[y][x-1]=z+1
            dfs(x-1,y,z+1,grid,H,W)
    if(x+1<W):
        if(grid[y][x+1]>z or grid[y][x+1]==0):
            grid[y][x+1]=z+1
            dfs(x+1,y,z+1,grid,H,W)
    if(y-1>=0):
        if(grid[y-1][x]>z or grid[y-1][x]==0):
            grid[y-1][x]=z+1
            dfs(x,y-1,z+1,grid,H,W)
    if(y+1<H):
        if(grid[y+1][x]>z or grid[y+1][x]==0):
            grid[y+1][x]=z+1
            dfs(x,y+1,z+1,grid,H,W)
    return 0
    
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def bfs(x,y,grid,H,W):
    dist=[[0 for _ in range(W)] for _ in range(H)]
    que=deque()
    que.append((y,x))
    dist[y][x]=1
    while(len(que)>0):
        y,x=que.popleft()
        for i in range(4):
            nx=x+dx[i]
            ny=y+dy[i]
            if(0 <= nx < W) and (0 <= ny < H) and grid[ny][nx]==0 and dist[ny][nx] == 0:
                que.append((ny,nx))
                dist[ny][nx]=dist[y][x]+1
    return( max([max(dist[i]) for i in range(H)]))
    
H,W=map(int,input().split())
grid=[]
tmp=[]
for i in range(H):
    S=str(input())
    tmp=[]
    for j in range(W):
        if(S[j]=="."):
            tmp.append(0)
        else:
            tmp.append(-1)
    grid.append(tmp)
ans=0
result=0
for i in range(W):
    for j in range(H):
        if(grid[j][i]==0):
                ans=bfs(i,j,grid,H,W)
                result=max(result,ans)
print(result-1)

Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
	IOS;
	int n, x, l, current = 0, count =1;

	cin >> n >> x;

	while(n--){
		cin >> l;
		current = current + l;
		if(current <= x)
			count++;
	} 

	cout << count << endl;



	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[])
{
    int n;
    scanf("%d", &n);

    int p = 0;
    for (int i = 0; i < n; ++i) {
        int l, r;
        scanf("%d %d", &l, &r);
        p += r - l + 1;
    }
    printf("%d\n", p);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S; cin >> S;
  int N = S.size();
  long long cnt = 0, cntA = 0;
  for(int i = 0; i < N; ++i){
    if(S[i] == 'A'){
      cntA++;
    }
    else if(S[i] == 'C'){
      cntA = 0;
    }
    else {
      if(S[i + 1] == 'C'){
	++i;
	cnt += cntA;
      }
      else if(S[i + 1] == 'B'){
	++i;
	cntA = 0;	
      }
      else{
	cntA = 0;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;

int N;
string S;

void Input()
{
	cin >> N;
	cin >> S;
}

int main()
{
	Input();
	char before = '0';
	int count = 0;
	for (char c : S) {
		if (before != c) count++;
		before = c;
	}


	cout << count << endl;

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
int a[1000];
int main(){
	int n,m;
	while(scanf("%d%d",&n,&m)&&!(n==0&&m==0)){
		for(int i=0; i<n; i++){
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		bool ok = false;
		int goo = -1;
		for(int i=n-1; i>=1; i--){
			for(int j=i-1; j>=0; j--){
				int sum = a[i]+a[j];
				if(sum<=m){
					ok = true;
					goo = max(goo,sum);
				}
			}
		}
		if(ok==false){
			printf("NONE\n");

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


Measured memory_bytes: 3220
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int N, ans = 0;
	scanf("%d", &N);
	int d[N];
	for (int i = 0; i < N; ++i) scanf("%d", &d[i]);
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) ans += d[i] * d[j];
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define mxn 1003
#define pb push_back

using namespace std;
typedef long long ll;

int N, K, T;

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

    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    cin >> N;
    if (N%10 == 3)
        cout << "bon\n";
    else if (N%10 == 0 || N%10 == 1 || N%10 == 6 || N%10 == 8)
        cout << "pon\n";
    else cout << "hon\n";

    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define ll long long
//不要再爆long long了！！！！！！！！不要再爆long long了！！！！！！！ 

int main()
{
	int l,r,t,s=0;
	cin>>l>>r>>t;
	for(int i=l;i<=r;i++)
	{
		if(i%t==0)s++;
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int cn(ldouble x, ll value) {
    int res = 0;
    int count = -1, point = -1;
    ldouble a = x;
    ll y = floorl(a);
    rep(i, 9) {
        a = a - floorl(a);
        string str = to_string(a);
        y *= 10;
        if(str.length() >= 2 && str[2] != '0') {
            count = i+1;
            y += str[2] - '0';
        }
        a *= (ldouble)10;
    }
    while(y % value == 0) {
        y /= value;
        res++;
    }
    return res;
}

int main(){
    // 小数点以下第9桁まで表示させる
    cout.precision(15);
    cout << fixed;
    ll ans = 0;
    int n, count = 0;
    cin >> n;
    vector<ldouble> a(n);
    // 整数かどうかを判定する
    vector<int> b(n, -1);
    vector<vector<ll> > even(50, vector<ll>(50, 0));
    rep(i, n) {
        cin >> a[i];
    }
    vector<bool> flag(n, false);
    rep(i, n-1) {
        if(a[i] == (ldouble)0){
            flag[i] = true;
            ans += (n-1);
        }
    }
    rep(i, n) {
        if(flag[i]) continue;
        int x = cn(a[i],2), y = cn(a[i],5);
        rep(two, 50) {
            rep(five, 50) {
                if(two + x >= 18 && five + y >= 18) {
                    ans += even[two][five];
                }
            }
        }
        even[x][y]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7220
s=input()
a=int(s[:2])
b=int(s[2:])
if 1<= a <= 12 and 1<= b <= 12:
	print('AMBIGUOUS')
elif 1 <= a <= 12 and (b==0 or 13 <= b):
	print('MMYY')
elif 1 <= b <= 12 and (a==0 or 13 <= a):
	print('YYMM')
else:
	print('NA')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int W, H, n; cin >> W >> H >> n;
    pair<int, int> w = {0, W}, h = {0, H};
    for(int i = 0; i < n; i++)
    {
        int x, y, a; cin >> x >> y >> a;
        if(a == 1) w.first = max(w.first, x);
        if(a == 2) w.second = min(w.second, x);
        if(a == 3) h.first = max(h.first, y);
        if(a == 4) h.second = min(h.second, y);
    }
    if(h.second - h.first <= 0 || w.second - w.first <= 0) cout << 0 << endl;
    else cout << (w.second - w.first) * (h.second - h.first) << endl;
    return 0;
}



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

using namespace std;

int N, K;
char sir[109];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%s\n%d", sir + 1, &K), N = strlen (sir + 1);
bool ok = 0;
for (int i=1; i<=N; i++)
    if (sir[i] != sir[1])
    {
        ok = 1;
        break;
    }
if (!ok)
{
    printf ("%lld\n", (1LL * N * K) / 2);
    return 0;
}
if (sir[1] == sir[N])
{
    int bg = 1, nd = N;
    while (sir[bg + 1] == sir[1]) bg++;
    while (sir[nd - 1] == sir[N]) nd--;
    long long ans = bg / 2 + (N - nd + 1) / 2 + 1LL * (K - 1) * ((bg + N - nd + 1) / 2);
    for (int i=bg + 1; i<nd; i++)
    {
        int j = i;
        while (j < N && sir[j + 1] == sir[i])
            j ++;
        ans += 1LL * K * ((j - i + 1) / 2);
        i = j;
    }
    printf ("%lld\n", ans);
    return 0;
}
long long ans = 0;
for (int i=1; i<=N; i++)
{
    int j = i;
    while (j < N && sir[j + 1] == sir[i])
        j ++;
    ans += (j - i + 1) / 2;
    i = j;
}
ans = 1LL * ans * K;
printf ("%lld\n", ans);
return 0;
}


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

using namespace std;

int A[10];
bool B[10];
map <int, int> mp;

int main() {
	for (int i = 1; i <= 9; i++) {
		scanf("%d", A + i);
		mp[A[i]] = i;
		B[i] = false;
	}
	int N;
	scanf("%d", &N);
	while(N--) {
		int aux;
		scanf("%d", &aux);
		if (mp[aux] != 0) {
			B[mp[aux]] = true;
		}
	}
	string ans = "No";
	if (B[1] && B[2] && B[3]) {
		ans = "Yes";
	}
	if (B[4] && B[5] && B[6]) {
		ans = "Yes";
	}
	if (B[7] && B[8] && B[9]) {
		ans = "Yes";
	}
	if (B[1] && B[4] && B[7]) {
		ans = "Yes";
	}
	if (B[2] && B[5] && B[8]) {
		ans = "Yes";
	}
	if (B[3] && B[6] && B[9]) {
		ans = "Yes";
	}
	if (B[1] && B[5] && B[9]) {
		ans = "Yes";
	}
	if (B[3] && B[5] && B[7]) {
		ans = "Yes";
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	if (a >= b) {
		cout << "delicious";
	}
	else if (b <= (a + x)) {
		cout << "safe";
	}
	else {
		cout << "dangerous";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
int main(){
    using namespace std;
    long long int n,m,l,i,j,k;
    long long x;
    cin >> n >> m >> l;
    long long a[n][m];
    long long b[m][l];
    long long c[n][l];
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            cin >> x;
            a[i][j] = x;
        }
    }
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            cin >> x;
            b[i][j] = x;
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            x = 0;
            for(k=0;k<m;k++){
                x += a[i][k]*b[k][j];
            }
            cout << x;
            if(j<l-1){
                cout << " ";
            }
        }
        cout << endl;
    }
    return 0;
}

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef queue<int> qi;
typedef pair<int,int> P;

const int limit=50;
int n,m;
int a[limit],b[limit];
bool graph[limit][limit];
bool visited[limit];

void dfs(int v){
    visited[v]=true;
    rp(k,n){
        if(graph[v][k]==false){
            continue;
        }
        if(visited[k]==true){
            continue;
        }
        dfs(k);
    }
}

int main(){
    cin >> n >> m;
    rp(i,m){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    }
    int ans=0;
    rp(i,m){
        graph[a[i]][b[i]]=false;
        graph[b[i]][a[i]]=false;
        rp(j,n){
            visited[j]=false;
        }
        dfs(0);
        bool bridge=false;
        rp(j,n){
            if(visited[j]==false){
                bridge=true;
            }
        }
        if(bridge){
            ans++;
        }
        graph[a[i]][b[i]]=true;
        graph[b[i]][a[i]]=true;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define rep(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
string maze[13];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

void bfs(int x, int y){
	maze[y][x] = '0';
	rep(i, 4){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(nx >= 0 && nx <= 12 && ny >= 0 && ny <= 12 && maze[ny][nx] == '1'){
			maze[ny][nx] = '0';
			bfs(nx, ny);
		}
	}
}

int main(void){
	int w, h;
	while(cin >> maze[0]){
		rep(i, 11){
			cin >> maze[i+1];
		}
		int cnt = 0;
		rep(i, 12){
			rep(j, 12){
				if(maze[i][j] == '1'){
					bfs(j, i);
					cnt++;
				}
			}
		}
		FIN(cnt);
	}
	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 1200
n = int(input())
ans = ""
for i in range(3,n+1):
    if i >= 3000 and (str(i)[-4]) == "3":
        ans += " " + str(i)
    elif i >= 300 and (str(i)[-3]) == "3":
        ans += " " + str(i)
    elif i >= 30 and (str(i)[-2]) == "3":
        ans += " " + str(i)
    elif (i % 3 == 0) or (i % 10 == 3):
        ans += " " + str(i)
print(ans)


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

using namespace std;

int main(){
    string n;
    cin>>n;
    int ans=0;
    for(auto x:n){
        ans+=(int)(x-'0');
    }
    if(ans%9){
        cout<<"No\n";
    }
    else{
        cout<<"Yes\n";
    }
    return 0;
}

Measured memory_bytes: 3748
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')

def main():
  a, b = map(int, readline().split())
  if a>9 or b>9:
    print('-1')
  else:
    print(a*b)
  
  
if __name__ == '__main__':
  main()

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

using namespace std;

int main () {
    int n = 0;
    cin >> n;
    vector<vector<int>> odd(100000, vector<int>(2)), even(100000, vector<int>(2));
    for (int i=0; i<100000; i++) {
        odd.at(i).at(1) = even.at(i).at(1) = i;
    }
    int buf = 0;
    for (int i=0; i<n/2; i++) {
        cin >> buf;
        buf--;
        odd.at(buf).at(0)++;
        cin >> buf;
        buf--;
        even.at(buf).at(0)++;
    }
    sort(odd.begin(), odd.end());
    reverse(odd.begin(), odd.end());
    sort(even.begin(), even.end());
    reverse(even.begin(), even.end());
    if (odd.at(0).at(1) != even.at(0).at(1)) {
        cout << n - odd.at(0).at(0) - even.at(0).at(0) << endl;
        return 0;
    }
    if (odd.at(1).at(0) + even.at(0).at(0) > odd.at(0).at(0) + even.at(1).at(0)) {
        cout << n - odd.at(1).at(0) - even.at(0).at(0) << endl;
    }
    else {
        cout << n - odd.at(0).at(0) - even.at(1).at(0) << endl;
    }
    return 0;    
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  cout << (1000-n%1000)%1000 << endl;
  return 0;
}

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

   int n;
   
   scanf("%d",&n);
   
   n=n%10;
   
   if     (n==3)         printf("bon");
   else if(n<2)          printf("pon");
   else if(n==6 || n==8) printf("pon");
   else                  printf("hon");
   
   return 0;
   }

Measured memory_bytes: 1692
n = STDIN.gets.to_i

p = [0, 0]
n.times {|i|
        input = STDIN.gets.split(' ')
        t = input[0]
        h = input[1]

        if t > h then
                p[0] += 3
        elsif t < h then
                p[1] += 3
        else
                p[0] += 1
                p[1] += 1
        end
}

puts p.join(' ')

Measured memory_bytes: 6096
#include<iostream>
#include<vector>
#include<math.h>
#include<string>
#include<algorithm>
#include<cstdlib>

typedef long long ll;
typedef unsigned short int unsi;
typedef unsigned int uni;
typedef unsigned long int unli;

using namespace std;


int main(){
	int N;
	int W[100];
	int W_sum = 0;
	int S = 0;
	int t;
	int Ans=10000000;
	

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> W[i-1];
		W_sum += W[i-1];
	}

	for (int i = 1; i <= N; i++) {
		S += W[i - 1];
		t = abs(W_sum - S * 2);
		
		if (Ans <= t) {
			break;
		}else{
			Ans = t;
		}
	}
	cout << Ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int d,x;cin>>d>>x;
  int a[n];for(int i=0;i<n;i++)cin>>a[i];
  int sum=0;
  for(int i=0;i<n;i++){
    sum+=(d-1)/a[i]+1;
  }
  cout<<x+sum<<endl;
}

Measured memory_bytes: 256