akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <iostream>
#include <string>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

int main() {
    int n = 0;  // < 15
    cin >> n;

    struct test {
        int person;
        int value;
    };

    vector<vector<test>> testimony(n);
    rep(i, 0, n) {
        int m = 0;
        cin >> m;
        vector<test> tmp(m);
        rep(j, 0, m) {
            cin >> tmp[j].person >> tmp[j].value;
        }
        testimony[i] = tmp;
    }

    int ans = 0;
    // bit全探索: 2^n
    rep(i, 0, (1 << n)) {
        // cout << "---" << endl;
        vector<int> guess(n, 0);
        vector<int> honestIdx;
        // n: 仮定
        rep(j, 0, n) {
            if (i & (1 << j)) {
                guess[j] = 1;
                honestIdx.push_back(j);
            }
        }

        //
        // for (int v : guess) {
        //     cout << v << " ";
        // }
        // cout << endl;
        //

        bool isSuccess = true;
        // n: 正直全員にたいして
        // rep(j, 0, n) {
        rep(j, 0, honestIdx.size()) {
            // if (guess[j] > 1) {
            //     continue;
            // }

            // n: 証言全てに矛盾がないか
            for (test t : testimony[honestIdx[j]]) {
                // for (int v : guess) {
                //     cout << v << " ";
                // }
                // cout << endl;

                // printf("%d: %d, %d -> %d\n", honestIdx[j], t.person, t.value, guess[t.person -
                // 1]);
                if (guess[t.person - 1] != t.value) {
                    // cout << "fauld" << endl;
                    isSuccess = false;
                    break;
                }
            }
            if (!isSuccess) {
                break;
            }
        }
        // cout << "is suc" << isSuccess << endl;
        if (isSuccess) {
            // cout << __builtin_popcount(i) << endl;
            ans = max(ans, __builtin_popcount(i));
        }
    }

    cout << ans << endl;

    // debug
    // for (vector<test> tmp : testimony) {
    //     for (test val : tmp) {
    //         cout << val.person << ":" << val.value << endl;
    //     }
    // }
    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

ll solve(int n, const vector<ll> &a) {
	vector<ll> abses = a;
	transform(begin(abses), end(abses), begin(abses), [](ll v) { return abs(v); });
	ll sum = accumulate(begin(abses), end(abses), 0LL);

	ll minusCnt = accumulate(begin(a), end(a), 0LL, [](ll acc, ll v) { return acc + (v < 0LL); });
	if (minusCnt % 2LL == 0LL) {
		return sum;
	}


	ll mi = *min_element(begin(abses), end(abses));
	return sum -(2LL * mi);
}

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

	int n;
	cin >> n;

	vector<ll> a(n);
	for (auto &v : a) {
		cin >> v;
	}

	ll ans = solve(n, a);
	cout << ans << endl;
	return 0;
}


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

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	
	if((a == 5 || a == 7) && (b == 5 || b == 7) && (c == 5 || c == 7)){
		if((a+b+c) < 18){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}else{
		cout << "NO" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
 
int main() {
  ll a,v,b,w,t;
  cin>>a>>v>>b>>w>>t;
  if(v<=w){
    cout<<"NO"<<endl;
  }
  else if((abs(a-b)+v-w-1)/(v-w)>t){
    cout<<"NO"<<endl;
  }
  else{
    cout<<"YES"<<endl;
  }
}

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

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

int main(){
    ll A, B; cin >> A >> B;
    ll C, D; cin >> C >> D;

    ll l = C*D/gcd(C,D);

    //B以下で割り切れないもの
    ll num1=B;
    num1 -=B/C;
    num1 -=B/D;
    num1 +=B/l; 


    //A-1以下で
    ll num2=A-1;
    num2 -=(A-1)/C;
    num2 -=(A-1)/D;
    num2 +=(A-1)/l; 

    cout << num1- num2 << endl;
}

Measured memory_bytes: 256
from fractions import gcd
import sys

input = sys.stdin.buffer.readline
mod = 10 ** 9 + 7


def modinv(a, mod):
    return pow(a, mod - 2, mod)


n = int(input())
if n == 1:
    print(1)
    exit()
A = list(map(int, input().split()))
lcm = A[0]
for i in range(n):
    g = gcd(lcm, A[i])
    lcm *= A[i] // g
ans = 0
for i in range(n):
    gyaku = modinv(A[i], mod)
    ans += lcm * gyaku
    ans %= mod
print(ans)


Measured memory_bytes: 5948
#include<iostream>
#include<string>
using namespace std;
 
int main(){
  string n;
  cin >> n;
  for(int i = 0;i < 3;i++){
    if(n.at(i) == '7'){
      cout << "Yes";
      break;
    }
    if(i == 2){
      if(n.at(2) != '7'){
      cout << "No";
    }
    }
  }
}

Measured memory_bytes: 3612
while True:
    x=input().split()
    W, H = int(x[0]), int(x[1])
    if W==0 and H==0:
        break
    hantei=True
    for i in range(W):
        if hantei:
            if H%2 == 0:
                print("#."*(H//2))
            elif H%2 == 1:
                print("#."*(H//2)+"#")
            hantei=False
        else:
            if H%2 == 0:
                print(".#"*(H//2))
            elif H%2 == 1:
                print(".#"*(H//2)+".")
            hantei = True
    print("")

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

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

  int now_find = 1;
  int cnt = 0;
  for(int i = 0; i < N; i++){
    if(a[i] == now_find){
      now_find++;
    }else{
      cnt++;
    }
  }
  if(now_find == 1){
    cout << -1 << endl;
  }else{
    cout << cnt << endl;
  }
  
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>

int main() {
  int a, b, c; std::cin >> a >> b >> c;
  if ((a == b && c != a) || (b == c && a != b) || (c == a && b != c))
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
      
  return 0;
}


Measured memory_bytes: 3612
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    prt((1000-(N%1000))%1000);

    return 0;
}



Measured memory_bytes: 3652
#include <stdio.h>

int main(int argc, char const* argv[])
{
    //1<A,H<100
    int takaA,takaH;
    int aoA,aoH;
    int takaC,aoC;
    if (scanf("%d%d%d%d",&takaH,&takaA,&aoH,&aoA)!=4) {
        return -1;
    }
    takaC=aoH/takaA;
    aoC=takaH/aoA;
    if(aoH%takaA!=0) takaC++;
    if(takaH%aoA!=0) aoC++;
    if(takaC<=aoC) printf("Yes\n");
    else printf("No\n");
    return 0;
}

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

int main(){
  int n;
  cin>>n;
  
  n %= 1000;
  
  if(n == 0){
    cout<<0<<endl;
    return 0;
  }
  
  cout<<1000 - n<<endl;
  return 0;
}


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

const int NIL=-1;
const int MAX=100000;

int n, color[MAX];
vector<int> G[MAX];

void dfs(int v, int id){
    stack<int> s;
    s.push(v);
    color[v]=id;

    while(!s.empty()){
        int u=s.top(); s.pop();
        for(int i=0; i<G[u].size(); i++){
            int v1=G[u][i];
            if(color[v1]==NIL){
                color[v1]=id;
                s.push(v1);
            }    
        }
    }
}

void assignColor(){
    int id=1;

    for(int i=0; i<n; i++) color[i]=NIL;
    for(int i=0; i<n; i++){
        if(color[i]==NIL){
            dfs(i,id++);
        }
    }
}

int main(void){
    int m; cin >> n >> m;

    for(int i=0; i<m; i++){
        int s,t; scanf("%d %d", &s, &t);
        G[s].push_back(t);
        G[t].push_back(s);
    }

    assignColor();

    int q; cin >> q;
    for(int i=0; i<q; i++){
        int s,t; scanf("%d %d", &s, &t);
        if(color[s]==color[t]) printf("yes\n");
        else printf("no\n");
    }

    return 0;
}


Measured memory_bytes: 8924
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mes(a,b) memset((a),(b),sizeof((a)))
#define syio std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
#define lson l, mid, rt << 1
#define rson mid+1, r, rt << 1 | 1
typedef long long ll;
typedef long double real;
typedef pair<int, int> pii;

const int oo = ~0u >> 2;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mxn = 100033;
inline int read(){
    int x = 0,f = 1;char c = getchar();
    while(!isdigit(c))f = c == '-' ? -1 : 1,c = getchar();
    while(isdigit(c))x = x * 10 + c - '0',c = getchar();
    return x * f;
}
string s, t;
int main()
{
    syio;
    cin>>s>>t;
    int mi = inf;
    for (int i = 0; i <= s.size() - t.size(); ++ i)
    {
        int cnt = 0;
        for (int j = 0, k = i; j < t.size(); ++ j, ++ k)
        if (s[k] != t[j]) cnt ++;
        mi = min(mi, cnt);
    }
    cout<<mi<<endl;
    return 0;
}


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

int N,H,W;

int AB[1010][2];

int main(void)
{
    cin >> N >> H >> W;

    int cnt=0;

    rep(i,N)
    {
        rep(j,2)
        {
            cin >> AB[i][j];
        }
    }

    rep(i,N)
    {
        if(AB[i][0]>=H&&AB[i][1]>=W)
        {
            cnt++;
        }
    }

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

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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=100010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};
ll n,m;
ll memo[100010]={};
vector<vector<ll> >e(100005);
ll dfs(ll now){
  if(memo[now]>0)return memo[now];
  for(int i=0;i<e[now].size();i++){
    memo[now]=max(memo[now],dfs(e[now][i])+1);
    // cout<<now<<" "<<e[now][i]<<" "<<memo[now]<<endl;
  }
  return max(memo[now],0LL);
}
int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    ll a,b;cin>>a>>b;
    a--;b--;
    e[a].pb(b);
  }
  ll ans=0;
  for(int i=0;i<n+10;i++)memo[i]=-1;
  for(int i=0;i<n;i++)
    dfs(i);
  for(int i=0;i<n+1;i++){
    ans=max(ans,memo[i]);
  }
  cout<<ans<<endl;
  return 0;
}


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

double r;

double calc(int x, int h){
     return h-sqrt(pow(r,2)-pow(x,2))+r;
}

int main(){
    int n;
    int map[50];
    while(cin>>r>>n,r!=0){
        fill(map, map+50,0);
        int xl,xr,h;
        for(int i=0;i<n;i++){
            cin>>xl>>xr>>h;
            for(int x=xl;x<xr;x++){
                if(map[x+25]<h)map[x+25]=h;
            }
        }
        double ans=calc(0,map[25]);
        for(int x=floor(-r)+1;x<=ceil(r)-1;x++){
            ans=min({ans,calc(x,map[25+x-1]),calc(x,map[25+x])});
        }
        cout.precision(8);
        cout<<fixed;
        cout<<ans<<endl;
    }
    return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main()
{
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    if (s < t)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    int d;
    cin >> d;
    mp[d]++;
  }
  
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int t;
    cin >> t;
    if (mp[t] == 0) {
      puts("NO");
      return 0;
    }
    mp[t]--;
  }
  puts("YES");
  return 0;
}

Measured memory_bytes: 9600
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

#define MIN(a,b) ((a) < (b) ? (a) : (b))

void run (void) {
  i32 n, e, t;
  scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &n, &e, &t);
  i32 *x = (i32 *) calloc (n + 2, sizeof (i32));
  for (i32 i = 1; i <= n; ++i) {
    scanf ("%" SCNi32, x + i);
  }
  x[n + 1] = e;
  i64 *dp = (i64 *) calloc (n + 1, sizeof (i64));
  i64 min = (i64) n * t + e;
  for (i32 i = 1, j = 1; i <= n; ++i) {
    dp[i] = dp[i - 1] + x[i] - x[i - 1] + t;
    for (; 2 * (x[i] - x[j]) >= t; ++j) {
      min = MIN(min, dp[j - 1] + x[j] - x[j - 1] - (i64) 3 * x[j]);
    }
    dp[i] = MIN(dp[i], min + (i64) 3 * x[i]);
    if (j < i) {
      i64 p = dp[j - 1] + x[j] - x[j - 1];
      p += t;
      p += x[i] - x[j];
      dp[i] = MIN(dp[i], p);
    }
  }
  printf("%" PRIi64 "\n", dp[n] + e - x[n]);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 1280
a=gets.chomp.split("")
b=gets.chomp.to_i
an=true
b.times do 
  c=gets.chomp.split
  if c[0]=="1"
    an=!an
  elsif (c[1]=="1"&&an)||(c[1]=="2"&&!an)
    a.unshift(c[2])
  else a.push(c[2])
  end
end
if !an
  a=a.reverse
end
puts a.join

Measured memory_bytes: 30844
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,f,r;
  while(cin>>m>>f>>r&&(m!=-1||f!=-1||r!=-1)){
    if(m==-1||f==-1) cout<<"F"<<endl;
    else if(m+f>=80) cout<<"A"<<endl;
    else if(m+f>=65) cout<<"B"<<endl;
    else if(m+f>=50||(m+f>=30&&r>=50)) cout<<"C"<<endl;
    else if(m+f>=30) cout<<"D"<<endl;
    else cout<<"F"<<endl;
  }
  return 0;
}



Measured memory_bytes: 3064
N, M, K = map(int, input().split())
mod = 998244353

l_lis = [1]
r_lis = [1]

l, r = 1, 1
for j in range(K+1):
    l = l*(j+1)%mod
    r = r*(N-j-1)%mod
    l_lis.append(l)
    r_lis.append(r)

def comb(a, b):
    global mod
    l = l_lis[b]
    r = r_lis[b]
    return (r*pow(l, mod-2, mod))%mod
 
ans = 0
for i in range(K+1):
    ans += comb(N-1, i)*M*pow((M-1), (N-1-i), mod)%mod

print(ans%mod)

Measured memory_bytes: 95680
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    String s = sc.next();

    String str = "";
    for (int i = 0; i < s.length(); i++) {
      switch (s.charAt(i)) {
        case '0':
          str = str + "0";
          break;
        case '1':
          str = str + "1";
          break;
        case 'B':
          if (str.length() > 0) {
            str = str.substring(0, (str.length() - 1));
          }
          break;
      }
    }

    System.out.println(str);
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <cstring>
using namespace std;

bool cells[502][502];
int lft[502][502];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, W;
    while (cin >> H >> W, H) {
        string s;
        for (int i=1; i<=H; ++i) {
            cin >> s;
            for (int j=1; j<=W; ++j) {
                cells[i][j] = s[j-1] == '*';
            }
        }
        for (int i=1; i<=H; ++i) {
            for (int j=1; j<=W; ++j) {
                lft[i][j] = (cells[i][j] ? 0 : lft[i][j-1] + 1);
            }
        }
        for (int i=1; i<=W; ++i) {
            lft[H+1][i] = 0;
        }
        int ans = 0;
        for (int i=1; i<=W; ++i) {
            stack<pair<int,int> > st;
            for (int j=1; j<=H+1; ++j) {
                int t = -1;
                while ( ! st.empty() && lft[j][i] < st.top().first) {
                    ans = max(ans, st.top().first * (j - st.top().second));
                    t = st.top().second;
                    st.pop();
                }
                if (0 < t) {
                    st.push(make_pair(lft[j][i], t));
                } else {
                    st.push(make_pair(lft[j][i], j));
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int G,R;

int main(){
	cin >> G >> R;
	cout << 2*R-G << endl;
	return 0;
}


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

int N=100000;

long Low(long n){
  if(n%10 == 0){
    return 0;
  }
  else{
    return n*10+(n%10-1);
  }
}

long Middle(long n){
  return n*10+n%10;
}

long High(long n){
  if(n%10 == 9){
    return 0;
  }
  else{
    return n*10+(n%10+1);
  }
}
  

int main(void){
  int K;
  cin >> K;
  
  long A[100002];
  for (int i=0;i<=8;i++){
    A[i]=i+1;
  }
  int pre=0,count=9;
  
  while(1){
    if (Low(A[pre]) != 0){
      A[count]=Low(A[pre]);
      count++;
    }
    
    A[count]=Middle(A[pre]);
    count++;
    
    if (High(A[pre]) != 0){
      A[count]=High(A[pre]);
      count++;
    }
    
    pre++;
    
    if(count>=N){
      break;
    }
  }
  
  cout << A[K-1] << endl;
  
  
  return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <cstdio>
#include <math.h>
#include <utility>
#include <list>
#include <functional>
#include <queue>
using namespace std;

#define ll long long
#define vecint vector<int>
#define Pii pair<int, int>

#define REP(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define print(a) cout << a << endl

#define MOD 1000000007
#define NIL -1

int N,Ma,Mb;

int dp[40+1][400][400];
int c[40],b[40],a[40];

void init(){
    rep(i,N+1){
        rep(j,N*10){
            rep(k,N*10){
                dp[i][j][k]=40*100+1;
            }
        }
    }
    dp[0][0][0]=0;
}

void solve(){
    init();
    rep(i,N){
        rep(j,N*10){
            rep(k,N*10){
                if(dp[i][j][k]==100*40+1) continue;
                dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
                dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
            }
        }
    }
    int ans=40*100+1;
    REP(i,1,N+1){
        REP(j,1,N*10){
            REP(k,1,N*10){
                if(j*Mb==k*Ma){
//                    print(dp[i][j][k]);
                    ans=min(ans,dp[i][j][k]);
                }
//                print(dp[i][j][k]);
            }
        }
    }
    if(ans==40*100+1){
        print("-1");
    }else{
        print(ans);
    }
    return;
}



int main(){
    cin>>N>>Ma>>Mb;
    rep(i,N){
        cin>>a[i]>>b[i]>>c[i];
    }
    solve();
    return 0;
}


Measured memory_bytes: 25856
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>

using namespace std;

#define MOD 1000000007
#define INF 2147483647
#define ll long long

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

	if (n / 10 == 9 || n % 10 == 9) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	return (0);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
const int N=100005;
int f[N],a[N];
int main()
{
	int n;
	scanf("%d",&n);
	memset(f,0x3f,sizeof(f));
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	f[1]=0;
	for(int i=2;i<=n;i++){
		if(i-1>=1) f[i]=min(f[i],f[i-1]+abs(a[i]-a[i-1]));
		if(i-2>=1) f[i]=min(f[i],f[i-2]+abs(a[i]-a[i-2])); 
	}
	printf("%d\n",f[n]);
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var p = Input();
		var s = p[0];
		var t = p[1];
		for(int i = 0; i < n; i++)
		{
			Console.Write("{0}{1}", s[i], t[i]);
		}
		Console.WriteLine();
	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 13140
#include<iostream>
#include <string>
#include<algorithm>
#include <set>
#include <cmath>
using namespace std;

int main(void){
	ios::sync_with_stdio(false);
	int N,i1,i2,i3,i4,j;
	cin >> N;
	j = 0;
	i1 = N / 1000;
	i2 = (N - i1 * 1000) / 100;
	i3 = (N - i1 * 1000 - i2 * 100) / 10;
	i4 = N - i1 * 1000 - i2 * 100 - i3 * 10;
	if (i1==2) j += 1;
	if (i2 == 2) j += 1;
	if (i3 == 2) j += 1;
	if (i4 == 2) j += 1;
	cout << j;
	return 0;
}


Measured memory_bytes: 256
class Q1166
  def printArray ary
    n = ary.length
    a = ary[0].length
    for i in 0..n - 1
      for j in 0..a - 1
        print(ary[i][j].to_s + " ")
      end
      puts ""
    end
  end
  def makeField w,h
    nh = 2*h - 1
    nw = 2*w - 1
    field = Array.new(nh).map{Array.new(nw,1000)}
    for i in 0..nh - 1
      t = gets
      for j in 0..nw - 1
        if (t[j] == ?0) then field[i][j] = -1
        elsif(t[j] == ?1) then field[i][j] = -2
        end
      end
    end
    field

  end
  def doIt
    arg = gets.split(" ").map{|x| x.to_i}
      pos = Struct.new("Position", :h, :w)
    while(arg[0] + arg[1] != 0)
      field = makeField arg[0],arg[1]
      #print field
      queue = Array.new
      queue.push(pos.new(0, 0))
      field[0][0] = 1
      nh = 2*arg[1] - 1
      nw = 2*arg[0] - 1
      while 0 < queue.length
        #print queue
        p = queue.shift
        h = p.h
        w = p.w
        v = field[h][w] + 1
        th = h - 2
        #puts("h = " + h.to_s + ", w = " + w.to_s + ", nh = " + nh.to_s + ", nw = " + nw.to_s)
        if(0 <= th && field[th + 1][w] == -1 && field[th][w] > v)
          field[th][w] = v
          queue.push(pos.new(th, w))
        end
        th = h + 2
        #puts field[th - 1][w]
        #puts v
        if(th < nh && field[th - 1][w] == -1 && field[th][w] > v)
          field[th][w] = v
          queue.push(pos.new(th, w))
        end
        tw = w - 2
        if(0 <= tw && field[h][tw + 1] == -1 && field[h][tw] > v)
          field[h][tw] = v
          queue.push(pos.new(h, tw))
        end
        tw = w + 2
        if(tw < nw && field[h][tw - 1] == -1 && field[h][tw] > v)
          field[h][tw] = v
          queue.push(pos.new(h, tw))
        end
      end
      #printArray field
      puts(field[nh - 1][nw - 1] == 1000? 0 : field[nh - 1][nw - 1])
      arg = gets.split(" ").map{|x| x.to_i}
    end
  end
end

Q1166.new.doIt

Measured memory_bytes: 3012
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i,N) cin >> a[i];
  int sum=0;
  rep(i,N) sum+=a[i];
  int ave=sum/N;
  int ans1=0, ans2=0;
  rep(i,N) ans1+=(ave-a[i])*(ave-a[i]);
  ave++;
  rep(i,N) ans2+=(ave-a[i])*(ave-a[i]);
  cout << min(ans1,ans2) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
string mojiretu;
  cin>>mojiretu;
int i=0;
  int nagasa;
  nagasa=mojiretu.size();
  int flag=0;
  int kiroku=0;
while(i<nagasa){
if((mojiretu.at(i) == 'A')||(mojiretu.at(i) == 'T')||(mojiretu.at(i) == 'C')||(mojiretu.at(i) == 'G')){
flag++;
}else{
if(flag>kiroku){kiroku=flag;}
flag=0;
}
i++;
}
  if(i=nagasa){
  if(flag>kiroku){kiroku=flag;}
  }
  cout<<kiroku<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String s = sc.next();
            int left = s.indexOf('A');
            int right = s.lastIndexOf('Z');
            System.out.println(right - left + 1);
        }
    }
}


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

int main() {
    int N; cin >> N;
    vector<int> ans(N);
    for(int i = 0; i < N - 1; ++i) {
        int a; cin >> a;
        a--;
        ans[a]++;
    }
    for(int i = 0; i < N; ++i) cout << ans[i] << '\n';
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] == cnt+1) cnt++;
    }
    if (cnt > 0) cout << N-cnt << endl;
    else cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var h, w int
	fmt.Fscan(r, &h)
	fmt.Fscan(r, &w)

	grid := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Fscan(r, &grid[i])
	}

	dy := []int{1, 0}
	dx := []int{0, 1}

	cost := make([][]int, h)
	for i := 0; i < h; i++ {
		cost[i] = make([]int, w)
		for j := 0; j < w; j++ {
			cost[i][j] = math.MaxInt64
		}
	}
	if grid[0][0] == '#' {
		cost[0][0] = 1
	} else {
		cost[0][0] = 0
	}

	var q Queue
	// スタート地点をpush
	q.push(Point{0, 0})

	for !q.empty() {
		p, _ := q.pop()
		x := p.x
		y := p.y

		for i := 0; i < 2; i++ {
			ny := y + dy[i]
			nx := x + dx[i]

			if ny >= h || nx >= w {
				//グリッド外は探索不要
				continue
			}

			if cost[y][x] >= cost[ny][nx] {
				//コストが最小にならない経路は探索不要
				continue
			}

			tmpCost := cost[y][x]
			if grid[y][x] == '.' && grid[ny][nx] == '#' {
				// 白->黒への移動の場合はコスト+1
				tmpCost++
			}
			cost[ny][nx] = tmpCost

			q.push(Point{nx, ny})
		}

	}

	fmt.Println(cost[h-1][w-1])
}

// Point ...
type Point struct {
	x int
	y int
}

// Queue ...
type Queue []Point

// pop ...
func (q *Queue) empty() bool {
	return len(*q) == 0
}

// push ...
func (q *Queue) push(i Point) {
	*q = append(*q, i)
}

// pop ...
func (q *Queue) pop() (Point, bool) {
	if q.empty() {
		return Point{0, 0}, false
	} else {
		res := (*q)[0]
		*q = (*q)[1:]
		return res, true
	}
}

// mod combination
func modpow(a, n, mod int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % mod
		}
		a = a * a % mod
		n = n / 2
	}
	return res
}

func modcomb(n, a, mod int) int {
	x := 1
	y := 1
	for i := 0; i < a; i++ {
		x = x * (n - i)
		x %= mod
		y = y * (i + 1)
		y %= mod
	}
	return x * modpow(y, mod-2, mod) % mod
}

func modfactorial(n, mod int) int {
	result := 1
	for i := 1; i <= n; i++ {
		result = (result * i) % mod
	}
	return result
}

// Utility

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func primeFactor(x int) map[int]int {
	res := make(map[int]int)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			res[i]++
			x = x / i
		}
	}
	if x != 1 {
		res[x] = 1
	}
	return res
}

func divisor(x int) []int {
	res := make([]int, 0)
	for i := 1; i*i <= x; i++ {
		if x%i == 0 {
			res = append(res, i)
			if i != x/i {
				res = append(res, x/i)
			}
		}
	}
	return res
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;


struct Segment_tree {
    private:
        int n;
        vector<int> node;
        int parent(int x) {return (x-1) / 2;}
        int left(int x) {return x * 2 + 1;}
        int right(int x) {return x * 2 + 2;}
    public:
        void _new(vector<int> v) {
            int sz = v.size();
            n = 1;
            while(n < sz) n*=2;
            node.resize(2*n - 1, INT_MAX);
            rp(i, 0, sz) {
                node.at(i+n-1) = v.at(i);
            }
            for(int i = n-2; i>=0; i--) {
                node.at(i) = min(node.at(i*2+1), node.at(i*2+2));
            }
        }
        void update(int x, int v) {
            x += (n - 1);
            node.at(x) = v;
            while(x > 0) {
                x = (x-1) / 2;
                node.at(x) = min(node.at(x*2+1), node.at(x*2+2));
                
            }
        }
        int find(int x, int y, int k=0, int l=0, int r=-1) {
            if(r == -1) r = n;
            if(y <= l || r <= x) return INT_MAX;
            else if(x <= l && r <= y) return node.at(k);
            else {
                int a = find(x, y, k*2+1, l, (l+r)/2);
                int b = find(x, y, k*2+2, (l+r)/2, r);
                return min(a, b);
            }
        }
};


int main() {
    int n, q;
    cin >> n >> q;
    Segment_tree seg;
    seg._new(vector<int>(n, INT_MAX));
    while(q--) {
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0) seg.update(x, y);
        else cout << seg.find(x, y+1) << endl;
    }
    return 0;
}


Measured memory_bytes: 4172
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).trim().split('\n');
main();

function main(){
  for(var i = 0, len = input.length; i < len; i++){
    var c = input[i].split(' ').map(Number);
    
    var xa1 = c[0],
    ya1 = c[1],
    xa2 = c[2],
    ya2 = c[3],
    xb1 = c[4],
    yb1 = c[5],
    xb2 = c[6],
    yb2 = c[7];

    var r = (xa1 <= xb2 && xb1 <= xa2) &&
      (ya1 <= yb2 && yb1 <= ya2);

    console.log(r?'YES':'NO');
  }
}

Measured memory_bytes: 7644
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;




//#[proconio::fastout]
fn main() {
    input! {
        k: usize,
        s: Bytes,
    }
    if s.len() <= k {
        println!("{}", std::str::from_utf8(&s).unwrap());
    } else {
        println!("{}...", std::str::from_utf8(&s[0..k]).unwrap());
    }

}



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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    long long base=0;
    for(int i=0;i<n;i++) base^=a[i];
    vector<int> events(40,0);
    for(int i=0;i<n;i++){
        for(int j=0;;j++){
            if((a[i]>>j)&1){
                events[j]=true;
                break;
            }
        }
    }

    vector<int> dpf(40,n+1);
    vector<int> dpt(40,n+1);
    dpf[0]=dpt[0]=0;
    for(int i=0;i<40;i++){
        if((base>>i)&1) dpf[i+1]=dpf[i];
        else dpt[i+1]=dpt[i];
        if(events[i]){
            if((base>>i)&1) dpt[i+1]=min(dpf[i]+1,dpt[i+1]);
            else dpf[i+1]=min(dpt[i]+1,dpf[i+1]);
        }
    }
    cout<<(dpt[39]==n+1 ? -1 : dpt[39])<<endl;
    return 0;
}

Measured memory_bytes: 640
H,W=map(int,input().split())
S=[input() for _ in range(H)]

res=[[] for i in range(H)]
for i in range(H):
  count=0
  for j in range(W):
    if S[i][j]=='#':
      if j != 0 and S[i][j-1]=='.':
        res[i].append(count)
      res[i].append(0)
      count=0
      continue
    else:
      count += 1
      if j == W-1:
        res[i].append(count)

cum = [[] for i in range(len(res))]
for i in range(len(res)):
  for j in range(len(res[i])):
    if res[i][j]==0:cum[i].append(0)
    else:cum[i].extend([res[i][j]]*res[i][j])

res=[[] for i in range(W)]
for i in range(W):
  count=0
  for j in range(H):
    if S[j][i]=='#':
      if j != 0 and S[j-1][i]=='.':
        res[i].append(count)
      res[i].append(0)
      count=0
      continue
    else:
      count += 1
      if j == H-1:
        res[i].append(count)

cum2 = [[] for i in range(len(res))]
for i in range(len(res)):
  for j in range(len(res[i])):
    if res[i][j]==0:cum2[i].append(0)
    else:cum2[i].extend([res[i][j]]*res[i][j])

ans=0
for i in range(H):
  for j in range(W):
    tmp = cum[i][j]+cum2[j][i]-1
    if tmp > ans:ans=tmp

print(ans)

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



int main(){
    int n;
    int ac=0;
    int ans;
    cin >> n;
    for(int i=1;i<=n;i++){
        int count=0;
        int tmp=i;
        while(tmp%2==0){
            count++;
            tmp/=2;
        }
        if(count>=ac){
            ans=i;
            ac=count;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
M = 10**9+7
N = int(input())
X = np.array(list(map(int,input().split())),dtype='int64')

D = X[1:]-X[:N-1]

ans = 0
s = 0
nn = 1
for n in range(1,N):
    nn *= n
    nn %= M

for i,d in enumerate(D):
    s = (s + pow((i+1),M-2,M))%M
    ns = (nn*s) % M
    ans = (ans + ns*d %M ) % M

print(ans)

Measured memory_bytes: 29916
#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;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define EPS (1e-7)
#define INF 1e18

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

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

const ll mod=1e9+7;
const int MAX_N=300;

int main(){
	int n;
	int ans=0;
	cin>>n;
	int d[n+1];
	int min_id=0;
	d[0]=0;
	for(int i=1;i<n+1;i++){
		cin>>d[i];
	}
	if(n>=24)ans=0;
	else if(n==23){
		int hours[13];
		fill(hours,hours+13,0);
		for(int i=0;i<n+1;i++){
			hours[d[i]]++;
		}
		bool judge=true;
		for(int i=0;i<13;i++){
			if(i==0 || i==12){
				if(hours[i]>1)judge=false;
			}else{
				if(hours[i]>2)judge=false;
			}
		}
		if(judge)ans=1;
	}else{
		for(int i=0;i<(1<<n);i++){
			int min_time=12;
			int time[n+1];
			time[0]=0;
			for(int j=0;j<n;j++){
				if(((i>>j)&1)==1)time[j+1]=24-d[j+1];
				else time[j+1]=d[j+1];
			}
			for(int j=0;j<n+1;j++){
				for(int k=j+1;k<n+1;k++){
					min_time=min(min_time,min(24-abs(time[j]-time[k]),abs(time[j]-time[k])));
				}
			}
			ans=max(ans,min_time);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            // 写経
            var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var ans = 1L;

            for (var a = 1L; a * a <= nm[1]; a++)
            {
                if (nm[1] % a != 0) continue;

                var b = nm[1] / a;

                if (a * nm[0] <= nm[1]) ans = Math.Max(ans, a);
                if (b * nm[0] <= nm[1]) ans = Math.Max(ans, b);
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
# -*- coding: utf-8 -*-
n = int(input())

ans = pow(10, 30)
for i in range(1, int(pow(n, 0.5)) + 1):
    if n / i == n // i:
        j = n // i
        if i + j - 2 < ans:
            ans = i + j - 2
print(ans)


Measured memory_bytes: 2940
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int[] ns = new int[4];
        for (int i = 0; i < 4; i++) {
            ns[i] = sc.nextInt();
        }
        Arrays.sort(ns);
        if (ns[0] == 1 && ns[1] == 4 && ns[2] == 7 && ns[3] == 9) {
            System.out.println("YES");
            return;
        }

        System.out.println("NO");
    }
}


Measured memory_bytes: 23636
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			int num = scn.nextInt();
			int cnt = scn.nextInt();

            Set<Integer> nums = new HashSet<>();
			for(int i=0; i<cnt; i++) {
				nums.add(scn.nextInt());
			}

			for(int i=0; ; i++) {
				int tgt=num-i;
				if(!nums.contains(tgt)) {
					System.out.println(tgt);
					break;
				}
				tgt=num+i;
				if(!nums.contains(tgt)) {
					System.out.println(tgt);
					break;
				}
			}
		}
	}
}


Measured memory_bytes: 35928
N,X,Y = list(map(int, input().split()))

ans = [0]*(N+1)

for i in range(1,N+1):
    for j in range(i+1,N+1):
        ans[min(j-i,abs(j-Y)+abs(i-X)+1)] += 1

for j in range(1,N):
    print(ans[j])



Measured memory_bytes: 3444
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;





int main(){

	ll r,D,x2000;
	scanf("%lld %lld %lld",&r,&D,&x2000);

	ll pre = x2000;
	for(int i = 0; i < 10; i++){

		printf("%lld\n",r*pre-D);
		pre = r*pre-D;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007


void solve()
{
	ll a,b,c;
      cin>>a>>b>>c;
      if(a+b+c<22)
      cout<<"win";
      else
      cout<<"bust";
    return;
}

int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();
        
        return 0;
}

Measured memory_bytes: 3616
//
//  main.swift
//  AtCoder
//
//  Copyright © 2020 dazy. All rights reserved.
//

import Foundation

func readString() -> String {
    readLine()!
}

func readStringArray() -> [String] {
    readString().components(separatedBy: " ")
}

func readInt() -> Int {
    Int(readString())!
}

func readIntArray() -> [Int] {
    readStringArray().map { Int($0)! }
}

func readStringTupple() -> (String, String) {
    let array = readStringArray()
    return (array[0], array[1])
}

func readStringTupple() -> (String, String, String) {
    let array = readStringArray()
    return (array[0], array[1], array[2])
}

func readIntTupple() -> (Int, Int) {
    let array = readIntArray()
    return (array[0], array[1])
}

func readIntTupple() -> (Int, Int, Int) {
    let array = readIntArray()
    return (array[0], array[1], array[2])
}


let (n, k) = readIntTupple()
var s = [Bool](repeating: true, count: n + 1)
s[0] = false
for _ in 0..<k {
    let _ = readInt()
    let a = readIntArray()
    for i in a {
        s[i] = false
    }
}
print(s.filter { $0 }.count)


Measured memory_bytes: 14184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,mod=1e9+7;
char s[N];
int n;
ll dp[N][13];
int main()
{
    scanf("%s",s+1);
    int n=strlen(s+1);
    if(s[1]=='?')
        for(int i=0;i<=9;i++)
        dp[1][i]=1;
    else dp[1][s[1]-'0']=1;
    for(int i=2;i<=n;i++)
        for(int j=0;j<13;j++)
        {
            if(s[i]=='?')
                for(int k=0;k<=9;k++)
                    dp[i][(j*10+k)%13]=(dp[i][(j*10+k)%13]+dp[i-1][j])%mod;
            else dp[i][(j*10+s[i]-'0')%13]=(dp[i][(j*10+s[i]-'0')%13]+dp[i-1][j])%mod;
        }
    printf("%lld\n",dp[n][5]);
}


Measured memory_bytes: 10496
from math import log
n = int(input())


# def make_list(n, x):
#     return [x ** i for i in range(1, int(log(n, x))+1)]
#
#
# sixes = make_list(n, 6)
# nines = make_list(n, 9)
# nums = [1] + sixes + nines

nums = [1]
i = 1
num = 1
while num <= n:
    num = 6 ** i
    nums.append(num)
    i += 1
i = 1
num = 1
while num <= n:
    num = 9 ** i
    nums.append(num)
    i += 1


dp = [float('inf')] * (n+1)
dp[0] = 0
for num in nums:
    for i in range(1, n+1):
        if i >= num:
            dp[i] = min(dp[i], dp[i-num]+1)
print(dp[n])


Measured memory_bytes: 6900
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    vector<int> v(5);
    for (auto &&i : v) scanf("%d", &i);
    sort(v.begin(), v.end());
    int ret = INF<int>;
    do {
        int ans = 0;
        for (int i = 0; i < 5; ++i) {
            if(ans%10) ans = (ans+9)/10*10;
            ans += v[i];
        }
        ret = min(ret, ans);
    }while(next_permutation(v.begin(), v.end()));
    cout << ret << "\n";
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque
import sys


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


s = S()
t = S()

ans = 0
for i in range(3):
    if s[i] == t[i]:
        ans += 1
print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>
#include <set>

using namespace std;

int main(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    
    set<string> st;
    for(int i = 1; i <= k; i++){
        if(i > s.size()){
            break;
        }
        for(int j = 0; j <= s.size() - i; j++){
            st.insert(s.substr(j, i));
        }
    }
    auto a = st.begin();
    for(int i = 0; i < k - 1; i++){
        a++;
    }
    cout << *a;
}

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

////// Union Find https://atcoder.jp/contests/atc001/tasks/unionfind_a
// 引用資料：https://mickey24.hatenablog.com/entry/20090602/1243950241
// 経路圧縮のみ実装？ 深さ１の部分木を生成

class DisjointSet {
private:
    vector<int> p;              // 頂点 i の所属している集合の root を記録する or 集合の root には自分を含む要素数が負の数で記録してある
    int count;                  // 集合の数を記録(１となったときすべての要素が一つにまとまったことを示す)

    // 所属している集合の root を調べる
    int root(int x) {         
        return p[x] < 0 ? x : p[x] = root(p[x]);
    }

public:
    // コンストラクタ　要素数の提示が必要
    DisjointSet(int size) {
        p.resize(size, -1); 
        count = size;
    }
    // 集合同士の結合
    bool unite_set(int x, int y) {          
        int rootX = root(x);
        int rootY = root(y);

        if (rootX != rootY) {                       // 同集合内でのループが起こらないように
            if (p[rootX] > p[rootY]) {              // 自分を含む要素数が多い方を rootX とする  
                swap(rootX, rootY); 
            }
            p[rootX] += p[rootY];                   // 自分を含む要素数を p[rootX] に渡す
            p[rootY] = rootX;                       // root を変更
            count--;                                // 集合同士がつながったので、集合の数を一つ減らす
            return true;
        }
        return false;
    }
    // 集合の要素数を算出
    int number_of_elements(int x){
        int rootX = root(x);
        return abs(p[rootX]);
    }
    // 同じ集合に属しているか調べる
    bool is_same_set(int x, int y) {          
        if (root(x) == root(y)) {
            return true;
        }
        return false;
    }
    // 集合の数を出力
    int number_of_sets() {
        return count;
    }
};

int main() {
    // 入力
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> edge;
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--;  b--;
        edge.push_back(make_pair(a, b));
    }

    DisjointSet islandSet(n);        // コンストラクト、インスタンス化
    // k頂点の往来の組み合わせを先に算出
    vector<long> combi(n+1);
    combi[1] = 0;
    for (int i = 2; i <= n; i++){
        combi[i] = combi[i-1] + i-1;
    }
    
    // 壊れるのが遅い橋から考える
    long inconvTmp = combi[n];
    vector<long> inconv;
    inconv.push_back(inconvTmp);
    for (int i = m-1; i >= 1; i--){
        // 
        pair<int, int> edgeTmp = edge[i];
        int bfr1Elements = islandSet.number_of_elements(edgeTmp.first);
        int bfr2Elements = islandSet.number_of_elements(edgeTmp.second);
        bool isUnite = islandSet.unite_set(edgeTmp.first, edgeTmp.second);
        if (isUnite){
            inconvTmp = inconvTmp - combi[bfr1Elements+bfr2Elements] + combi[bfr1Elements] + combi[bfr2Elements];
        }
        inconv.push_back( inconvTmp );
    }
    for (auto itr = inconv.end() - 1; itr != inconv.begin() - 1; itr--){
        cout << *itr << endl;
    }

    return 0;
}


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

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		int l=500, u=0;
		for(int i=0; i<n; i++){
			int sum=0;
			for(int i=0; i<5; i++){
				int a;
				cin >> a;
				sum += a;
			}
			l = min(l, sum);
			u = max(u, sum);
		}
		cout << u << " " << l << endl;
	}
	return 0;
}



Measured memory_bytes: 2984
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string.h>
#include <deque>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;



int main() {
	string s;
	getline(cin,s);

	for (int i = 0; i < s.length(); i++) {
		if (65 <= s[i] && s[i] <= 90) s[i] += 32;
		else if (97 <= s[i] && s[i] <= 122)s[i] -= 32;

	}

	cout << s << endl;


	return 0;
}

Measured memory_bytes: 3192