akhauriyash/Code-Regression huggingface dataset:
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    N = i_input()
    ans = INF

    for i in range(1, int(math.sqrt(N))+1):
        if N%i != 0:
            continue

        b = N // i
        ans = min(ans, len(str(b)))
    print(ans)

  
 
  
if __name__=="__main__":
    main()


Measured memory_bytes: 67992
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <cstdint>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a.at(i);
	}

	int b = 1;
	int cnt = 1;
	bool flag = false;
	for (int i = 1; i <= n; i++) {
		if (a.at(1) == 2) {
			flag = true;
			break;
		}
		b = a.at(b);
		++cnt;
		if (a.at(b) == 2) {
			flag = true;
			break;
		}
	}

	if (flag) {
		cout << cnt << endl;
	}
	else {
		cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 3780
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
#define rep(i,s,n) for(ll i = (ll)(s); i < (ll)(n); i++)
#define all(a) (a).begin(),a.end()
#define mod 1000000007
using namespace std;
using graph =vector<vector<ll>>;
const ll MAX = 510000;
const ll MOD = 1000000007;

ll 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;
    }
}

// 二項係数計算nCk
ll 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;
}

// 二項係数計算nPk
ll per(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n-k] % MOD) % MOD;
}

// mod. m での a の逆元 a^{-1} を計算する
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

/* ユークリッドの互除法 最大公約数*/
ll gcd(ll a, ll b) {
	return b ? gcd(b,a%b) : a;
}



/*最小公倍数*/

ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}


/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    
    
    cout<<i+1<<" "<<m<<endl;
    cout<<i+1<<" "<<m-t[i]<<endl;
    ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
    return res;
}
*/


//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    ll h,w,a,b;
    cin>>h>>w>>a>>b;
    vector<vector<ll>>c(h,vector<ll>(w,1));
    rep(i,0,h){
        rep(j,0,w){
            c[i][j]=((i<b)^(j<a)?1:0);
        }
    }
    rep(i,0,h){
        rep(j,0,w){
            cout<<c[i][j];
        }
        cout<<endl;
    }

    
    
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
 
using namespace std;
 
#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define dbg cerr << "HU" << endl;
#define NACHO {ios::sync_with_stdio(0); cin.tie(NULL);}
 
typedef long long tint;
typedef long double ld;
 
const int INF = 190000000;
const int MOD = 1e9+7;
const int MAXN = 100001;

int dp[100001][3];

int main(){
	NACHO;
	int n; cin >> n;
	int a, b, c; cin >> a >> b >> c;
	dp[0][0] = a; dp[0][1] = b; dp[0][2] = c;
	forsn(i, 1, n){
		cin >> a >> b >> c;
		dp[i][0] = max(dp[i-1][1], dp[i-1][2])+a;
		dp[i][1] = max(dp[i-1][0], dp[i-1][2])+b;
		dp[i][2] = max(dp[i-1][0], dp[i-1][1])+c;
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << "\n";
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
    public static void main(final String args[]) {
        Scanner scan = new Scanner(System.in);
        String X = scan.next();
        if("ABC".equals(X)){
            System.out.println("ARC");
        }else if("ARC".equals(X)){
            System.out.println("ABC");
        }
    }
}

Measured memory_bytes: 35716
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N);
  vl X(N), Y(N), H(N);
  rep(i, 0, N) {
    in(X[i], Y[i], H[i]);
  }
  rep(i, 0, 101) {
    rep(j, 0, 101) {
      ll HH = 0;
      rep(k, 0, N) {
        if (H[k] > 0) {
          HH = H[k] + abs(X[k] - i) + abs(Y[k] - j);
          break;
        }
      }
      bool ok = true;
      rep(k, 0, N) {
        ll hi = max(HH - abs(X[k] - i) - abs(Y[k] - j), 0ll);
        if (hi != H[k]) {
          ok = false;
        }
      }
      if (ok) {
        print(i, j, HH);
        return;
      }
    }
  }
}


Measured memory_bytes: 256
N,M=map(int,input().split())
S,C=[],[]
for m in range(M):
    s,c=map(int,input().split())
    S.append(s)
    C.append(c)
for i in range(10**N):
    if len(str(i))==N and all(str(i)[s-1]==str(c) for s,c in zip(S,C)):
        print(i)
        break
else:
    print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
#define ll long long
//for (auto &x : a) { cin >> x; }
using namespace std;

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

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

Measured memory_bytes: 3752
def checkN(N,D):
    for each in N:
        if each in D:
            return False
    return True
line1 = input().split(' ')
N = line1[0]
D = input().split(' ')
i = -1
while not checkN(N, D):
    N = str(int(N)+1)
    # i -= 
print(N)



Measured memory_bytes: 2940
"""
map(int,input().split())

"""
S = input()

a = S[::2]
b = S[1::2]

a0 = 0
a1 = 0
b0 = 0
b1 = 0

for i in a:
    if i == '0':
        a0+=1
    else:
        a1+=1

for j in b:
    if j == '0':
        b0+=1
    else:
        b1+=1

r = min(a0,a1,b0,b1)

if r == a0:
    print(r+b1)
elif r == a1:
    print(r+b0)
elif r == b0:
    print(r+a1)
else:
    print(r+a0)


Measured memory_bytes: 3188
#include <iostream>
using namespace std ;
 
bool solve(int x,int y, int z)
{
    if( (x * x) == (y * y + z * z) )
    {
        return true ;
    }
 
    return false ;
}
 
int main()
{
    int N ;
    cin >> N ;
 
    bool ans = false ;
 
    for( int i = 0 ; i < N ; i ++ )
    {
        int a,b,c ;
        cin >> a >> b >> c ;
 
        if( a >= b )
        {
            if( a >= c )      // 最大値はa
            {
                ans = solve(a,b,c) ;
            }
            else if( a < c ) // 最大値はc
            {
                ans = solve(c,a,b) ;
            }
        }
        else if( a < b )
        {
            if( b >= c )      // 最大値はb
            {
                ans = solve(b,a,c) ;
            }
            else if( b < c ) // 最大値はc
            {
                ans = solve(c,a,b) ;
            }
        }
 
        if( ans ){ cout << "YES" << endl ; }
        else{ cout << "NO" << endl ; }
    }
    return 0 ;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

int main() {
    int n, m; cin >> n;
    map<ll,int> d, t;
    rep(i,n) {
        ll D; cin >> D;
        d[D]++;
    }

    cin >> m;
    rep(i,m){
        ll T; cin >> T;
        if(d[T]) {
            d[T]--;
            continue;
        }else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

}





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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int s=0;
  s=max({a,b,c});
  if(s*2==a+b+c){
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
    using namespace std;
    #define pb push_back
    #define mp make_pair
    #define mod 1000000007
    #define f(i,n) for(int i=0;i<(int)n;i++)
    #define Fre(i,a,b) for(int i = a; i < b; i++)
    #define sf(n) scanf("%d", &n)
    #define sff(a,b) scanf("%d %d", &a, &b)
    #define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
    #define pfn(n) printf("%d\n", n)
    #define pfs(n) printf("%d ", n)
    #define ff first
    #define ss second
    #define mem(a,b) memset(a,b,sizeof(a))
    #define READ freopen("in.txt", "r", stdin)
    #define WRITE freopen("out.txt", "w", stdout)
    #define sz size()
    #define number_of_digit(n) __builtin_ffs(n);
    #define ll long long
    #define T int
    #define ld long double
    #define endl "\n"

    bool sortbyf(const pair <int,int> a,const pair <int,int> b)
    {   
        if(a.ff==b.ff){
            return (a.ss<b.ss);
        }
        // return (a.ss< b.ss); 
        return (a.ff < b.ff);
    } 

    // int cnt;
    // bool sortbyabs(const pair <ll,ll> a, const pair <ll,ll> b){
    // // {   if(abs(a.ss)==abs(b.ss)){
    // //         return (abs(a.ff)<abs(b.ff));
    // //     }

    //     return (abs(abs(a.ss)-abs(a.ff)) > abs(abs(b.ss)-abs(b.ff))); 
    // } 


    
    
    int main(){   
        ios_base::sync_with_stdio(false); cin.tie(NULL);
        int n,W;
        cin>>n>>W;
        int w[n],v[n];
        
        f(i,n){
            cin>>w[i]>>v[i];
        }
        ll dp[W+1][n];
        // dp[0]=0;
        for(ll i=0;i<=W;i++){
            // int m=0;
            f(j,n){
                if(i==0){
                    dp[i][j]=0;
                    continue;
                }
                if(j==0){
                    if(i>=w[j]) dp[i][j]=v[j];
                    else dp[i][j]=0;
                    continue;
                }
                if(i-w[j]>=0){
                    // m=max(m, dp[i-w[j]] + v[j]);
                    dp[i][j]=max( v[j] + dp[i-w[j]][j-1] , dp[i][j-1]);
                }
                else{
                    dp[i][j]=dp[i][j-1];
                }
            }

            // dp[i]=m;
        }

        // cout<<dp[W];
        // f(i,W+1) cout<<dp[i]<<" ";
        cout<<*max_element(dp[W], dp[W]+n);
        // f(i,W+1){
        //     f(j,n)cout<<dp[i][j]<<" ";
        //     cout<<"\n";
        // }
    } 

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


int main(){
    int64_t n, total = 0, a, t = pow(10, 9) + 7, ans = 0;
    cin >> n;
    vector<int64_t> vec(n);
    for(int i = 0; i < n; i++) {
        cin >> vec.at(i);
        total += vec.at(i);
    }

    for (int i = 0; i < n - 1; i++){
        total -= vec.at(i);
        a = total % t;
        ans += vec.at(i) * a;
        ans = ans % t;
    }

    cout << ans << endl;

}

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

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

    int MAX=pow(10,5)+1;

    vector<int> ANS(MAX+1);

    for (int i=0;i<8;++i){
        ANS.at(i)=0;
    }

    for (int i=8;i<MAX;++i){
        long long score=1;
        bool flag=false;

        for (int j=2;j<sqrt(i)+1;++j){

            if (i%j==0){
                score*=j;

                if (i/j<i){
                    score*=i/j;
                }
            }

            if (score>=i*2){
                flag = true;
                break;
            }
        }

        if (flag == true ){
            ANS.at(i)=1;
        }
        else{
            ANS.at(i)=0;
        }

    }

    for (int i=1;i<MAX;++i){
        ANS.at(i)+=ANS.at(i-1);
    }

    int que;

    for (int i=0 ;i<Q; ++i){
        cin>>que;
        cout<<ANS.at(que)<<endl;
    }

}



Measured memory_bytes: 3108
#include <cstdio>
 
#define MAX 100000

bool prime[MAX + 1];
int count[MAX + 1];
int N, L, R;

int main() {
  // 素数配列をエラトステネスの篩を使って生成
  // 素数であれば false, 素数でなければ true
  for (int i = 2; i <= MAX; ++i)
    if (!prime[i])
      for (int j = i + i; j <= MAX; j += i)
        prime[j] = true;

  // N と (N + 1) / 2 が素数である要素配列を生成
  // 条件が成立すれば 1、成立しなければ 0
  for (int i = 3; i<= MAX; i += 2)
    if (!prime[i] && !prime[(i + 1) >> 1])
      count[i] = 1;

  // 累積和を生成
  for (int i = 3; i<= MAX; ++ i)
    count[i] += count[i - 1];

  scanf("%d", &N);
  while (N --) {
    scanf("%d%d", &L, &R);
    printf("%d\n", count[R] - count[L - 1]);
  }

  fflush(stdout);
  return 0;
}


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

int main(void){
  int kyori[6];
  for(int i = 0;i<6;i++){
    cin >> kyori[i];
  }
  int d;
  int flag = 0;
  for(int i = 0; i<4;i++){
    for(int j = i+1; j<6-i;j++){
      d=kyori[j]-kyori[i];
      if(d>kyori[5]){
        flag +=1;
      }
    }
  }

  if(flag == 0){
      cout << "Yay!\n";
  }else{
      cout << ":(\n";
  }
  
  return 0;
}

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

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

  int c[h][w];
  int cnt = 1;
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      char s;
      cin >> s;

      if(s=='#'){
        c[i][j] = cnt;
        cnt++;
      }
      else c[i][j] = 0;
    }
  }

  int st = 0;
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      if(c[i][j]!=0){
        st = c[i][j];
      }
      else c[i][j] = st;
    }
    st = 0;
  }

  st = 0;
  for (int i = 0; i < h; i++)
  {
    for (int j = w-1; j >= 0; j--)
    {
      if(c[i][j]!=0){
        st = c[i][j];
      }
      else c[i][j] = st;
    }
    st = 0;
  }

  st = 0;
  for (int j = 0; j < w; j++)
  {
    for (int i = 0; i < h; i++)
    {
      if(c[i][j]!=0){
        st = c[i][j];
      }
      else c[i][j] = st;
    }
    st = 0;
  }

  st = 0;
  for (int j = 0; j < w; j++)
  {
    for (int i = h-1; i >= 0; i--)
    {
      if(c[i][j]!=0){
        st = c[i][j];
      }
      else c[i][j] = st;
    }
    st = 0;
  }

  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      cout << c[i][j] << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int a[1000010];
long long ans,n;
int main(void)
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+1+n);
	for(int i=1;i<n;)
		if(a[i]==a[i+1]) ans+=2,i+=2;
			else i++;
	cout<<n-ans<<"\n";
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <bitset>
#include <set>
#include <map>
#include <string>
#include <math.h>

using namespace std;

#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define swap2(x, y) x=x^y; y=x^y; x=x^y;
#define print(x) if (false) {cout << "[" << #x << " = " << x << "] ";}
#define printNL() if (false) {cout << endl;}

int main() {
    string s, t; cin >> s >> t;
    int minChange = s.size();
    for (int start = 0; start <= s.size() - t.size(); ++start) {
        int change = 0;
        for (int i = 0; i < t.size(); ++i) {
            if (s[start + i] != t[i]) ++change;
        }
        minChange = min(minChange, change);
    }
    cout << minChange << endl;
    return 0;
}


Measured memory_bytes: 3620
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
   int n,a;
   vector<int> V;
   cin >> n;
   for(int i=0;i<n;i++)
   {
       cin >> a;
       V.push_back(a);
   }
   sort(V.begin(),V.end());
   V.erase(unique(V.begin(),V.end()),V.end());
   n= V.size();
   cout << V[n-1] - V[0] << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <functional>
#include <cmath>
#include <limits>

using namespace std;


int main()
{
	long A, B, C, K;
	cin >> A >> B >> C >> K;
	int sum = 0;
	
	if (A > K)
		sum += K;
	else
	{
		sum += A;
		if (B + A < K)
		{
			sum -= K - (A + B);
		}
	}

	cout << sum;

	return 0;
}

Measured memory_bytes: 3636
import heapq
N = int(input())
A = list(map(int, input().split()))

al = A[:N]
heapq.heapify(al)
sal = sum(al)
suml = [sal]
for i in range(N, 2*N):
    if al[0] < A[i]:
        tmp = heapq.heappop(al)
        heapq.heappush(al, A[i])
        sal += A[i]-tmp
    suml.append(sal)

ar = [-a for a in A[2*N:]]
heapq.heapify(ar)
sar = -sum(ar)
sumr = [sar]

ans = -10**15
for i in range(N, 2*N):
    if -ar[0] > A[3*N-1-i]:
        tmp = -heapq.heappop(ar)
        heapq.heappush(ar, -A[3*N-1-i])
        sar += A[3*N-1-i]-tmp
    sumr.append(sar)
for i in range(len(suml)):
    ans = max(ans, suml[i]-sumr[-(i+1)])
print(ans)


Measured memory_bytes: 37212
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)


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

    vector<vector<vector<ll>>> dp(55, vector<vector<ll>>(2600, vector<ll>(55, 0)));
    
    ll sum = 0; dp[0][0][0] = 1;
    
    rep(i, n){
        rep(j, 2501){
            rep(k, i+1){
                dp[i+1][j+X[i]][k+1] += dp[i][j][k];
                dp[i+1][j][k] += dp[i][j][k];
            }
        }
    }
    rep(i, 2501){
        rep(k, 51){
            double d = k;
            if(i / d == a){;
                sum +=  dp[n][i][k];             
            }
        }
    }
    cout << sum -1 << ln;
}




Measured memory_bytes: 67328
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        Arrays.sort(a);

        int b = a[0], c = a[n - 1];
        int l = 1, r = n - 2;
        long v = c - b;
        while (l <= r) {
            int[] w = {Math.abs(b - a[l]), Math.abs(b - a[r]), Math.abs(c - a[l]), Math.abs(c - a[r]), 0};
            int m = Arrays.stream(w).max().getAsInt();
            v += m;
            if (m == w[0]) {
                b = a[l++];
            } else if (m == w[1]) {
                b = a[r--];
            } else if (m == w[2]) {
                c = a[l++];
            } else if (m == w[3]) {
                c = a[r--];
            }
        }
        System.out.println(v);
    }
}

Measured memory_bytes: 64860
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long a[100010],n,k;
long long b[100010];
int main(void)
{
	long long i,n,m;
	scanf("%lld",&n);
	m=1;
	for(i=0;i<n;i++)
	scanf("%lld",&a[i]);
	sort(a,a+n);
	memset(b,0,sizeof(b));
	for(i=0;i<n;i++)
	{
		if(i==0)
		b[i]=b[i]+a[i];
		else
		b[i]=b[i-1]+a[i];
	}
	for(i=n-1;i>0;i--)
	{
		if(b[i-1]*2>=a[i])
		m++;
		else
		break;
	}
	printf("%lld\n",m);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

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

int modinv(int a){
    return modpow(a,MOD-2);
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    
    int res=modpow(10,n);
    res-=modpow(9,n)*2-modpow(8,n);
    res%=MOD;
    if(res<0) cout<<res+MOD<<endl;
    else cout<<res<<endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x; cin>>x;
    int idx=0;
    ll sum=0;
    while(sum<x) sum+=(++idx);
    cout<<idx<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define f(ii,n) for(ii=0;ii<n;ii++)
#define F(ii,a,n) for(ii=a;ii<n;ii++)
#define read(array,n) for(ll i=0;i<n;i++) cin>>array[i];
#define inf 1000000007;
// function to transform string to lowercase --> transform(s.begin(),s.end(),s.begin(),::tolower)
void swap(ll *xp,ll *yp){
	ll temp = *xp;
	*xp = *yp;
	*yp = temp;
}

ll power(ll i,ll j){
	ll prod=1;
	while(j>0){
		if(j&1){
			prod=prod*i;
		}
		j=j>>1;
		i=i*i;
	}
	return prod;
}

void solve(){
	ll s,w;
	cin>>s>>w;
	if(w>=s){
		cout<<"unsafe\n";
	}
	else{
		cout<<"safe\n";
	}

}
int main(){
	// freopen("filename.txt","r",stdin);
	solve();
	
	// ll t;
	// cin>>t;
	// while(t--){
	// 	solve();
	// }
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>

using namespace std;

typedef long long ll;

ll bs(ll t) {
	ll ok = 0, ng = 3000;
	while (ng - ok > 1) {
		ll mid = (ok + ng) / 2;
		if (mid * mid * mid * mid * mid <= t)ok = mid;
		else ng = mid;
	}
	return ok;
}

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

	//A正　B負
	for (ll a = 0; a * a * a * a * a <= X; a++) {
		ll B = bs(X - a * a * a * a * a);
		if (X == a * a * a * a * a + B * B * B * B * B) {
			cout << a << " -" << B << endl;
			return 0;
		}
	}

	//A正 B正
	for (ll a = 0; a <= 200 ; a++) {
		if (a * a * a * a * a < X)continue;
		ll B = bs(a * a * a * a * a - X);
		
		if (X == a * a * a * a * a - B * B * B * B * B) {
			cout << a << " " << B << endl;
			return 0;
		}
	}

	return 0;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


const int MOD = (int)1e9 + 7;
int N;
ll dp[101][4][4][4];    // (A, C, G, T) = (0, 1, 2, 3)

ll solve(){
    REP(n, N) REP(i, 4) REP(j, 4) REP(k, 4) dp[n][i][j][k] = 0;
    REP(i, 4){
        REP(j, 4){
            REP(k, 4){
                if((i == 1 && j == 2 && k == 0) || (i == 2 && j == 1 && k == 0) || (i == 1 && j == 0 && k == 2)) continue;
                dp[3][i][j][k] = 1;
            }
        }
    }
    FOR(n, 3, N){
        REP(i, 4){
            REP(j, 4){
                REP(k, 4){
                    REP(l, 4){
                        if((i == 1 && j == 2 && k == 0) || (i == 2 && j == 1 && k == 0) || (i == 1 && j == 0 && k == 2) || (i == 1 && j == 2 && l == 0) || (i == 1 && k == 2 && l == 0)){
                            continue;
                        }else{
                            dp[n + 1][i][j][k] += dp[n][j][k][l];
                            dp[n + 1][i][j][k] %= MOD;
                        }
                    }
                }
            }
        }
    }
    ll ret = 0;
    REP(i, 4){
        REP(j, 4){
            REP(k, 4){
                ret += dp[N][i][j][k];
                ret %= MOD;
            }
        }
    }
    return ret;
}

signed main(){
    cin >> N;
    PRINT(solve());
    return 0;
}

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

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

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    while (x % 2 == 0) {
      ans++;
      x /= 2;
    }
  }

  cout << ans << endl;
}


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

int main() {
	int N, K, Q; cin >> N >> K >> Q;
  	vector<int> A(Q);
  	for(int i=0; i < Q; i++) cin >> A.at(i);
 
  	int border = Q - K;
    multiset<int> point;
  	for(int i=0; i < Q; i++) point.insert(A.at(i));
  
 	for (int i = 1; i <= N; i++){
      if (border < 0) cout << "Yes" << endl;
      else if (point.count(i) > border) cout << "Yes" << endl;
      else cout << "No" << endl;
    }
}

Measured memory_bytes: 5632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());

		int[] s = new int[N];
		for(int i = 0; i < N; i++){
			s[i] = Integer.parseInt(sc.next());
		}

		for(int i = 0; i < N-1; i++){
			for(int j = N-1; j > i; j--){
				if(s[j] < s[j-1]){
					int temp = s[j];
					s[j] = s[j-1];
					s[j-1] = temp;
				}
			}
		}

		int total = 0;

		for(int i = 0; i < N; i++) total += s[i];

		int i = 0;

		while(total % 10 == 0 && i < N){
			if(s[i] % 10 != 0) total -= s[i];
			i++;
		}

		if(i == N){
			System.out.println(0);
		}else{
			System.out.println(total);
		}

	}

}

Measured memory_bytes: 21972
N, K, S = map(int, input().split())

List = []
tmp = 0
if S == 10 ** 9:
    tmp = 10 ** 9 - 1
else:
    tmp = S + 1

for i in range(0, K):
    List.append(S)
for i in range(K, N):
    List.append(tmp)

print(*List)

Measured memory_bytes: 6560
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

void printarray(int n, int a[])
{
    for (int i = 1; i < n + 1; i++)
    {
        cout << a[i];
        if (i != n)
            cout << " ";
    }
    cout << endl;
}

int cycleanalysis(int n, int a[])
{
    int pos, ret, next;
    pos = 0, ret = 0;
    for (int i = 1; i < n + 1; i++)
    {
        pos = i;
        while (a[pos] != pos)
        {
            ret += (a[pos] + a[a[pos]]);
            next = a[pos];
            swap(a[pos], a[a[pos]]);
            pos = next;
        }
    }

    return ret;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, m, p, q;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    cin >> m;
    int b[m];
    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
    }
    p = min(n, m);
    q = max(n, m);
    int status = -1;
    for (int i = 0; i < p; i++)
    {
        if (a[i] < b[i])
        {
            status = 1;
            break;
        }
        else if (a[i] > b[i])
        {
            status = 0;
            break;
        }
    }
    if (status == -1)
    {
        if (q > p && q == m)
        {
            status = 1;
        }
        else
        {
            status = 0;
        }
    }
    cout << status << endl;
    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int a,b;
    cin >> a >> b;
    if((a&1)&&(b&1)) print("Odd");
    else print("Even");
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3620
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let r: f32 = input();
    println!("{}", r * 2.0 * 3.14159265358979);
}


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

int main() {
  int ans = 0;
  vector<int> a(3);
  rep(i, 3) cin >> a[i];
  sort(a.rbegin(), a.rend());
  if (a[1] % 2 != a[2] % 2) {
    a[0]++;
    a[1]++;
    ans++;
  }
  ans += a[0] - a[1];
  a[2] += a[0] - a[1];
  ans += (a[0] - a[2]) / 2;
  cout << ans << endl;
}

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

using namespace std;

#define USE_IOSTREAM \
{\
	ios::sync_with_stdio(false);\
	cin.tie(0);\
	cout.tie(0);\
}

#define pii pair<int, int>
#define mp make_pair

typedef long long ll;

const int N = 1e5 + 100;
int a[N];
ll sum[N];
ll posiSum[N];

int main()
{
	USE_IOSTREAM;
	int n, K, i, j;
	cin >> n >> K;
	ll ans = 0;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum[i] = sum[i - 1] + a[i];
		posiSum[i] = posiSum[i - 1];
		if (a[i] > 0)
		{
			ans += a[i];
			posiSum[i] += a[i];
		}
	}
	
	ll bestDiff = -1e18;
	for (i = K; i <= n; i++)
	{
		ll blackSum = sum[i] - sum[i - K];
		ll whiteSum = posiSum[i] - posiSum[i - K];
		
		ll curDiff = -whiteSum;
		if (blackSum > 0)
		{
			curDiff += blackSum;
		}
		
		bestDiff = max(bestDiff, curDiff);
	}
	
	ans += bestDiff;
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#include<iostream>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    string s;cin>>s;
    ll cntn=0,cnt=0;
    rep(i,n){
        if(s[i]=='(')cnt++;
        else cnt--;
        if(cnt<0){
            cntn++;
            cnt=0;
        }
    }
    rep(i,cntn)cout<<'(';
    cout<<s;
    rep(i,cnt)cout<<')';
    cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repb(i, n) for (int i = (int)n; i >= 0; i--)
#define reps(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define repsb(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[])
{
    int a,b,t;
    cin>>a>>b;
    
    cout<<max(a,b)+max(max(a,b)-1,min(a,b));


    return 0;
}

Measured memory_bytes: 256
loop{n=gets.to_i;exit if n==0;
h=Hash.new(0)
n.times{gets.split.map{|s|h[s]+=1}}
c=gets[0];
a=h.each.map{|k,v|[-v,k]}.sort.map{|a|a[1]}.select{|a|a[0]==c}
if a.size>0;puts a*' ';
else puts :NA;
end
}


Measured memory_bytes: 7248
#include<stdio.h>

int N,M,y,x;
int a,b,c;

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

int main(){
  int i;
  scanf("%d %d",&N,&M);
  for(i=0;i<M;i++){
    scanf("%d %d",&x,&y);
    a=min(N-x,x-1);
    b=min(N-y,y-1);
    c=min(a,b);
    printf("%d\n",c%3+1);
  }
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<ll> s(n + 1);
	rep(i, n) s[i + 1] = s[i] + a[i];
	map<ll, ll> mp;
	rep(i, n + 1) mp[s[i]]++;
	ll ans = 0;
	for (auto a : mp) ans += a.second * (a.second - 1) / 2;
	cout << ans << endl;
}

Measured memory_bytes: 17768
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
# define M_PI 3.141592
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 

int main()
{
	int h, w;
	while (cin >> h >> w&&h)
	{
		int a[120][120] = {};
		for (int i = 1; i <= h; i++)
		{
			for (int j = 1; j <= w; j++)
			{
				char c; cin >> c;
				int p = 0;
				switch (c)
				{
				case '@':p = 1; break;
				case '#':p = 2; break;
				case '*':p = 3; break;
				}
				a[i][j] = p;
			}
		}
		int ans = 0;
		int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
		for (int i = 1; i <= h; i++)
		{
			for (int j = 1; j <= w; j++)
			{
				if (a[i][j] == 0)continue;
				ans++;
				typedef pair<int, int> pii;
				queue<pii> q;
				q.push(pii(i, j));
				int o = a[i][j];
				a[i][j] = 0;
				while (!q.empty())
				{
					pii now = q.front(); q.pop();
					for (int k = 0; k < 4; k++)
					{
						pii next = now;
						next.first += dx[k];
						next.second += dy[k];
						if (a[next.first][next.second] == o)
						{
							q.push(next);
							a[next.first][next.second] = 0;
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1276
N, K = map(int, input().split())
A = []
 
for i in range(N):
    A.append(0)
 
for i in range(K):
    d = int(input())
    AA = list(map(int, input().split()))
    for j in range(d):
        A[AA[j] - 1] = 1
 
n = 0
for i in range(N):
    if A[i] == 0:
        n += 1
print(n)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define MAX 3
#define MAX2 9

using namespace std;

struct Puzzle{
  int f[MAX2];
  int space;
  string path;

  bool operator < (const Puzzle &p) const {
  int i;
    for(i = 0; i < MAX2; i++){
      if( f[i] == p.f[i] ){
        continue;
      }
      return f[i] > p.f[i];
    }
    return false;
  }
};

string bfs(Puzzle);
bool isTarget(Puzzle);

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
char dir[4] = {'u', 'l', 'd', 'r'};

bool isTarget(Puzzle p){
  int i;
  for(i = 0; i < MAX2; i++){
    if( p.f[i] != (i+1) ){
      return false;
    }
  }
  return true;
}//end of isTarget func

int main(){
  Puzzle in;
  int i;
  for(i = 0; i < MAX2; i++){
    cin >> in.f[i];
    if( in.f[i] == 0 ){
      in.f[i] = MAX2;
      in.space = i;
    }
  }
  string ans = bfs(in);
  cout << ans.size() << endl;
  return 0;
}//end of main func

string bfs(Puzzle s){
  queue<Puzzle> Q;
  map<Puzzle, bool> V;
  Puzzle u,v;
  s.path = "";
  Q.push(s);
  V[s] = true;

  int r,tx,ty;
  int sx,sy;
  int tmp;

  while( !Q.empty() ){
    u = Q.front();
    Q.pop();
    if( isTarget(u) ){
      return u.path;
    }
    sx = u.space / MAX;
    sy = u.space % MAX;
    for(r = 0; r < 4; r++){
      tx = sx + dx[r];
      ty = sy + dy[r];
      if( tx < 0 || ty < 0 || tx >= MAX || ty >= MAX){
        continue;
      }
      v = u;
      /*swap*/
      tmp = v.f[u.space];
      v.f[u.space] = v.f[tx * MAX + ty];
      v.f[tx * MAX + ty] = tmp;

      v.space = tx * MAX + ty;
      if( !V[v] ){
        V[v] = true;
        v.path += dir[r];
        Q.push(v);
      }
    }
  }
  return "unsolvable";
}

Measured memory_bytes: 30652
n, k = [int(i) for i in input().split(" ")]
d = []
ans = [i for i in range(1, n + 1)]
for i in range(k):
    d.append(int(input()))
    A = [int(i) for i in input().split(" ")]
    for delete in A:
        if delete in ans:
            ans.remove(delete)
print(len(ans))


Measured memory_bytes: 9192
// Last Change: 03/22/2019 20:54:10.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll N, X;
  cin >> N >> X;

  ll ipt, minM;
  minM = INT64_MAX;
  for (ll i = 0; i < N; ++i) {
    cin >> ipt;
    X -= ipt;
    minM = min(minM, ipt);
  }

  cout << N + X / minM << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll n,d; cin>>n>>d;
    ll cnt = 0;
    rep(i,n) {
        ll p,q; cin>>p>>q;
        if (d*d >= p*p+q*q) cnt++;
    }

    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
    int N, Q;
    long K;
    scanf("%d %ld %d", &N, &K, &Q);
    int *A;
    A = (int *)calloc(Q, sizeof(int));
    for(int i=1; i<Q+1; i++)
        scanf("%d", &A[i]);
    int *P;
    P = (int *)calloc(N, sizeof(long));
    int sa=K-Q;
    for(int i=1; i<N+1; i++)
        P[i]=sa;
    int i=1;
    for(i=1;i<Q+1;i++)
    {
       P[A[i]]+=1;
    }
    for(int i=1; i<N+1; i++){
        if(P[i]>0)printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1280
def solve():
    N = int(input())
    K = int(input())
    x = list(map(int, input().split()))
    
    ans = 0
    for i in range(N):
        if x[i] < K - x[i]:
            ans += x[i] * 2
        else:
            ans += (K - x[i]) * 2
    print(ans)
    
solve()


Measured memory_bytes: 3060
/*
さいころ

mapを使っているところは普通のサイコロとかなら配列で大丈夫
まぁ、せいぜいO(log24)なのでOKか

参考:
http://www.prefield.com/algorithm/misc/dice.html
*/
#include <bits/stdc++.h>
using namespace std;

//up(上),down(下),front(前),back(後ろ),right(右),left(左)
enum FACE{UP,DOWN,FRONT,BACK,RIGHT,LEFT};
template<typename T>
struct Dice{
    T var[6];
    map<pair<T,T>,int> M;
    vector<Dice> V;
    Dice(){}
    T& operator[](FACE f){return var[f];}
    Dice operator[](int idx){return V[idx];};
    int id(){return M[var[FRONT],var[UP]];}

    void rollR(){roll(UP,LEFT,DOWN,RIGHT);}
    void rollL(){roll(UP,RIGHT,DOWN,LEFT);}
    void rollU(){roll(UP,FRONT,DOWN,BACK);}
    void rollD(){roll(UP,BACK,DOWN,FRONT);}
    void rollT(){roll(FRONT,RIGHT,BACK,LEFT);}
    void rollH(){roll(FRONT,LEFT,BACK,RIGHT);}
    void roll(FACE a,FACE b,FACE c,FACE d){
        int tmp=var[a];
        var[a]=var[b];
        var[b]=var[c];
        var[c]=var[d];
        var[d]=tmp;
    }

    void allDice(){
        int cnt=0;
        V.resize(24);
        Dice d=*this;
        for(int k=0;k<6;(k&1?rollR():rollD()),k++){
            for(int i=0;i<4;rollT(),i++,cnt++){
                V[cnt]=(*this);
                M[{var[FRONT],var[UP]}]=cnt;
            }
        }
        *this=d;
    }


};

signed main(){
    Dice<int> d;
    cin>>d[UP]>>d[FRONT]>>d[RIGHT]>>d[LEFT]>>d[BACK]>>d[DOWN];
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='E') d.rollR();
        if(s[i]=='S') d.rollD();
        if(s[i]=='W') d.rollL();
        if(s[i]=='N') d.rollU();
    }
    cout<<d[UP]<<endl;
}


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

int main(){
  vector<char> a(3);
  for(int i = 0; i < 3; i++){
    cin >> a.at(i);
  }
  for(int i = 0; i < 3; i++){
    if(a.at(i) == '1'){
      cout << '9';
    }else{
      cout << '1';
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

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

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

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int r, c, k;
    cin >> r >> c >> k;
    auto dp = make_v(r, c, 4, 0LL);
    auto v = make_v(r, c, 0);
    for (int i = 0; i < k; ++i) {
        int a, b, cc;
        scanf("%d %d %d", &a, &b ,&cc);
        v[a-1][b-1] = cc;
    }
    dp[0][0][1] = v[0][0];
    for (int i = 0; i < r; ++i) {
        for (int j = 0; j < c; ++j) {
            for (int k = 0; k <= 3; ++k) {
                if(i+1 < r) {
                    chmax(dp[i+1][j][1], dp[i][j][k]+v[i+1][j]);
                    chmax(dp[i+1][j][0], dp[i][j][k]);
                }
                if(j+1 < c) {
                    if(k < 3) chmax(dp[i][j+1][k+1], dp[i][j][k]+v[i][j+1]);
                    chmax(dp[i][j+1][k], dp[i][j][k]);
                }
            }
        }
    }
    cout <<  *max_element(dp.back().back().begin(),dp.back().back().end()) << "\n";

    return 0;
}

Measured memory_bytes: 671376