akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
def getlist():
  return list(map(int, input().split()))

D = defaultdict(int)

H, W = getlist()
for i in range(H):
  a = input()
  for j in a:
    D[j] += 1

if H % 2 == 0 and W % 2 == 0:
  judge = "Yes"
  for i in D:
    if D[i] % 4 != 0:
      judge = "No"
      break
  print(judge)

elif H % 2 == 0:
  judge = "Yes"
  c2 = 0
  for i in D:
    if D[i] % 4 != 0:
      if D[i] % 2 == 0:
        c2 += 1
      else:
        judge = "No"
        break
  if judge == "No":
      print(judge)
  else:
    if c2 <= int(H // 2):
      print("Yes")
    else:
      print("No")

elif W % 2 == 0:
  judge = "Yes"
  c2 = 0
  for i in D:
    if D[i] % 4 != 0:
      if D[i] % 2 == 0:
        c2 += 1
      else:
        judge = "No"
        break
  if judge == "No":
      print(judge)
  else:
    if c2 <= int(W // 2):
      print("Yes")
    else:
      print("No")

else:
  c1 = 0
  c2 = 0
  for i in D:
    if D[i] % 4 != 0:
      if D[i] % 4 == 2:
        c2 += 1
      else:
        c1 += 1

  if c1 <= 1 and c2 <= int((H - 1) // 2 + (W - 1) // 2):
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 3316
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int hp = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        
        a[0] = sc.nextInt();
        b[0] = sc.nextInt();
        int aMaxDamage = a[0];
        int aMaxIndex = 0;
        for (int i = 1; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            
            if (a[i] > aMaxDamage) {
                aMaxDamage = a[i];
                aMaxIndex = i;
            } else if (a[i] == aMaxDamage) {
                if (b[i] > b[aMaxIndex]) {
                    aMaxIndex = i;
                }
            }
        }
        
        Arrays.sort(b);
        int count = 0;
        
        for (int i = b.length - 1; i >= 0; i--) {
            if (b[i] > aMaxDamage) {
                hp -= b[i];
                count++;
                if (hp <= 0) break;
            } else {
                break;
            }
        }
        
        while (hp > 0) {
            hp -= aMaxDamage;
            count++;
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 83112
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("C:\\Users\\BOG\\Desktop\\output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

int main() {
    fast;
    ll a; cin>>a;
    cout<<360/__gcd(360ll, a);
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF -1
#define MOD 1000000007
#define int long long int
using namespace std;


struct edge { int to,cost;};
typedef pair<int,int> P;
vector <vector <edge> > G;
vector <int> d;

vector <int> x;
vector <int> y;

signed main(){
int N; cin>>N;
G.resize(N+1);
d.resize(N+1,INF);

for(int i=1;i<=N-1;i++){
  int a,b,c; cin>>a>>b>>c;
  edge e; e.to =b; e.cost = c;
  G[a].push_back(e);
  e.to = a;
  G[b].push_back(e);
}

int Q,K; cin>>Q>>K;
d[K] = 0;
priority_queue <P , vector <P> , greater<P> > que;
que.push(P(0,K));

while(!que.empty()){
  P p = que.top();que.pop();
  int v = p.second;
  if(d[v] < p.first) continue;
  for(int i=0 ; i<G[v].size();i++){
    edge e = G[v][i];
    if(d[e.to] > d[v] + e.cost or d[e.to] == -1){
      d[e.to] = d[v] + e.cost;
      que.push(P(d[e.to],e.to));
    }
  }
}


for(int i=0;i<Q;i++){
  int xx,yy;cin>>xx>>yy;
  x.push_back(xx);
  y.push_back(yy);
 
}

for(int i=0;i<Q;i++) cout<< d[x[i]] + d[y[i]] <<endl;



return 0;
}

  

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

int main() {
  double a,b;
  cin >> a >> b;
  double a_min,a_max,b_min,b_max;
  a_min= ceil(a*12.5);
  a_max = ceil((a+1)*12.5-1);
  b_min= b*10;
  b_max = (b+1)*10-1;

  if(a_min>b_max){
    cout << -1 << endl;
  }
  else if(b_min>a_max){
    cout << -1 << endl;
  }
  else{
    cout << max(a_min,b_min) << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  	int N,K;
  	long temp;
  	long sum = 0;
  	
    scanf("%d %d",&N,&K);
	priority_queue<long > monster_HP(N,0);
	
	for(int i = 0;i <N; i++){
	    scanf("%ld",&temp);
	    monster_HP.push(temp);
	}
	for(int i = 0;i < N;i++){
	    if(i>=K){
	        sum += monster_HP.top();
	    }
	    monster_HP.pop();
	}
	printf("%ld\n",sum);
	
  	return 0;
}

Measured memory_bytes: 4864
// AOJ DPL_3_A Largest Square
// 2018.5.4 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

short dp[1405][1405];

int largestSquare(int H, int W, char map[1405][1405])
{
	int r, c, t, ans;
	
	ans = 0;
	for (r = 1; r <= H; r++) for (c = 1; c <= W; c++) {
		if (map[r][c]) dp[r][c] = 0;
		else {
			t = dp[r-1][c-1];
			if (t > 0 && dp[r  ][c-1] < t) t = dp[r  ][c-1];
			if (t > 0 && dp[r-1][c  ] < t) t = dp[r-1][c  ];
			dp[r][c] = ++t;
			if (t > ans) ans = t;
		}
	}
	return ans*ans;
}

char map[1405][1405];
int main()
{
	int H, W, r, c;

	H = in(), W = in();
	for (r = 1; r <= H; r++) for (c = 1; c <= W; c++) {
		map[r][c] = gc() & 0xf, gc();
	}
	printf("%d\n", largestSquare(H, W, map));
	return 0;
}



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

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

bool dfs(int y, int x, vector<vector<int>>& S, vector<vector<int>> const& v) {
    const int h = S.size(), w = S[0].size();
    if(y == h && x == 0) return true;
    const int ny = (x == w - 1 ? y + 1 : y);
    const int nx = (x == w - 1 ? 0 : x + 1);
    if(v[y][x] == 1) {
        return dfs(ny, nx, S, v);
    } else {
        array<int, 4> use = {{0, 0, 1, 1}};
        auto in_range = [&] (int a, int b) {
            return 0 <= a && a < h && 0 <= b && b < w;
        };
        bool res = false;
        do {
            S[y][x] = 0;
            bool ok = true;
            auto searched = [&] (int yy, int xx) {
                return yy < y || (yy == y && xx < x);
            };
            for(int i = 0; i < 4 && ok; ++i) {
                //cout << "i: " << i << endl;
                if(!use[i]) {
                    const int rev = (i + 2) % 4;
                    const int yy = y + dy[i], xx = x + dx[i];
                    ok &= !in_range(yy, xx) || v[yy][xx] == 1 || !(S[yy][xx] & (1 << rev));
                } else {
                    S[y][x] |= 1 << i;
                    const int yy = y + dy[i], xx = x + dx[i];
                    const int rev = (i + 2) % 4;
                    ok &= in_range(yy, xx) && v[yy][xx] == 0 && (!searched(yy, xx) || (S[yy][xx] & (1 << rev)));
                }
            }
            if(ok) {
                res = dfs(ny, nx, S, v);
            }
        } while(!res && next_permutation(begin(use), end(use)));
        return res;
    }
}

int main() {
    int h, w;
    while(cin >> w >> h, h) {
        vector<vector<int>> c(h, vector<int>(w));
        int cnt = 0;
        for(int i = 0; i < h; ++i) {
            for(int j = 0; j < w; ++j) {
                cin >> c[i][j];
                cnt += c[i][j] == 0;
            }
        }

        vector<vector<bool>> vis(h, vector<bool>(w));
        function<int(int, int)> connected = [&] (int y, int x) {
            vis[y][x] = true;
            int res = 1;
            for(int i = 0; i < 4; ++i) {
                const int ny = y + dy[i], nx = x + dx[i];
                if(0 <= ny && ny < h && 0 <= nx && nx < w && c[ny][nx] == 0 && !vis[ny][nx]) {
                    res += connected(ny, nx);
                }
            }
            return res;
        };
        const int sz = [&] {
            for(int i = 0; i < h; ++i) {
                for(int j = 0; j < w; ++j) {
                    if(c[i][j] == 0) {
                        return connected(i, j);
                    }
                }
            }
            return -1;
        }();
        vector<vector<int>> S(h, vector<int>(w));
        cout << (cnt > 0 && sz == cnt && dfs(0, 0, S, c) ? "Yes" : "No") << endl;
    }
}



Measured memory_bytes: 3108
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 10'009;

int a[N];
int b[N];
int f[N];

int main() {
  int m, n;
  scanf("%d%d", &m, &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", a + i, b + i);
  }
  for (int i = 0; i <= m; ++i) {
    f[i] = 1'000'000'000;
  }
  f[0] = 0;
  for (int i = 0; i <= m; ++i) {
    for (int j = 0; j < n; ++j) {
      int ni = min(m, i + a[j]);
      f[ni] = min(f[ni], f[i] + b[j]);
    }
  }
  printf("%d\n", f[m]);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,ans=0;
    string s;
    cin >>n>>s;
    for(int i=0;i<n-2;i++){
    if(s.at(i)=='A' && s.at(i+1)=='B' && s.at(i+2) == 'C')ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
a,b,c=sorted(map(int,input().split()))
counter=0
if a%2==b%2:
	counter+=(b-a)//2
	counter+=c-b
elif a%2==c%2:
	counter+=(c-a)//2
	counter+=(c-b)//2+1+1
elif b%2==c%2:
	counter+=(c-b)//2
	counter+=(c-a)//2+1+1
print(counter)

Measured memory_bytes: 3060
N, A, B = map(int, input().split())
S = input()
counta = 0
countb = 0
for s in S:
    if s =='a':
        if counta + countb < A + B:
            counta += 1
            print('Yes')
        else:
            print('No')
    if s =='b':
        if counta + countb < A + B:
            if countb < B:
                countb += 1
                print('Yes')
            else:
                print('No')                
        else:
            print('No')
    if s=='c':
        print('No')


Measured memory_bytes: 53080
#include<stdio.h>
#define N 44

int main()
{
  int i, n, F[N];

  scanf("%d", &n);

  F[0] = 1;
  F[1] = 1;

  for(i = 2; i < n+2; i++) F[i] = F[i-2] + F[i-1];

  printf("%d\n", F[n]);

  return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;
  
public class Main {
	
  public static void main(String[] args) {
	  Scanner sc=new Scanner(System.in);
	  int x=Integer.parseInt(sc.next());
	  int y=Integer.parseInt(sc.next());
	  int S=2*x+y*2;
	  System.out.println(x*y +" "+ S);
    
  }
}

Measured memory_bytes: 17124
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  1000005

ll spf[N];
void sieve()
{
    rep(i,1,N)
    {
        spf[i]=i;
    }
    for(int i=4;i<N;i+=2)
        spf[i]=2;
    for(ll i=3;i*i<N;i++)
    {
        if(spf[i]==i)
        {
            for(ll j=i*i;j<N;j+=i)
            {
                if(spf[j]==j)
                    spf[j]=i;
            }
        }
    }
}
void solve()
{
    ll ans=0;
    ll n;
    sieve();
    cin>>n;
    rep(i,1,n)
    {
        
        ll x=n-i;
        ll c=0;
        ll res=1;
        while(x!=1)
        {
            ll cur=spf[x];
            c=0;
            while(x%cur==0)
            {
                x/=cur;
                c++;
            }
            c++;
            res*=c;
        }
        ans+=res;

    }
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 11468
n, w = map(int, input().split())
listV, listW = [], []
for i in range(n):
    vi, wi = map(int, input().split())
    listV.append(vi)
    listW.append(wi)

dp =[[-1] * (w+1) for _ in range(n+1)]
for i in range(w+1):
    dp[0][i] = 0

for i in range(n):
    for j in range(w+1):
        if j >= listW[i]:
            dp[i+1][j] = max(dp[i+1][j-listW[i]] + listV[i], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

print(dp[n][w])



Measured memory_bytes: 41884
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

void solve(){
    ll a,b,t; cin>>a>>b>>t;

    ll x = a;
    ll y = b;
    ll ans = 0;
    FOR(i,1,t){
        if(i == x){
            x = x + a;
            ans += b;
        }
    }

    cout<<ans<<endl;
}   

signed main(){

 
    FastRead;    

    ll t;
    t = 1; 
    // cin>>t;
    while(t--) solve();
    
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<deque>
using namespace std;
 
int main(){
	long long n,k,q;
	cin >> n >> k >> q;
	vector<int> A(n,k-q);
	
	vector<int> answer(q,0);
	for(int i=0;i<q;i++){
		cin >> answer[i];
		answer[i]--;
	}
	
	sort(answer.begin(),answer.end());
	
	for(int i=0;i<q;i++){
		A[answer[i]]++;
	}
	
	for(int i=0;i<n;i++){
		if(A[i]>0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 1408
n = int(input())
x = list(map(int, input().split()))
ave = sum(x)//n
ans1 = 0
ans2 = 0
ans3 = 0
for i in x:
    ans1 += (i-ave)**2
    ans2 += (i-ave+1)**2
    ans3 += (i-ave-1)**2
print(min(ans1, ans2, ans3))

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

bool asc(vector<int> p){
    bool can = true;
    for(int i = 0; i < p.size()-1; i++){
        if((p.at(i+1)-p.at(i)) < 0){
            can = false;
            break;
        }
    }
    return can;
}

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p.at(i);
    if(asc(p) == true){
        cout << "YES" << endl;
        return 0;
    }
    for(int i = 0; i < n-1; i++){
        for(int j = i + 1; j < n; j++){
            swap(p.at(i), p.at(j));
            if(asc(p) == true){
                cout << "YES" << endl;
                return 0;
            }
            swap(p.at(i), p.at(j));
        }
    }

    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
ll pow(int n, int e)
{
    ll ans = 1;
    for (int i = 0; i < e; i++)
    {
        ans *= n;
    }
    return ans;
}
int main()
{
    int n, k;
    cin >> n >> k;
    cout << k * pow(k - 1, n - 1) << endl;

    return 0;
}


Measured memory_bytes: 3580
#include <stdio.h>
#include <string.h>
#define BMAX 16
#define MOD 1000000007

int main(void)
{
  int i, j, k, n, x, y, z, xyz, mask, idx = 0, dp[2][1<<BMAX] = {0};
  long res = 1;
  scanf("%d %d %d %d", &n, &x, &y, &z);
  xyz = (1 << (x + y + z - 1)) | (1 << (y + z - 1)) | (1 << (z - 1));
  mask = ((1 << (x + y + z)) - 1) >> 1;
  dp[idx][0] = 1;
  for (i = 0; i < n; i++) {
    memset(dp[idx^1], 0, sizeof(dp[idx^1]));
    for (j = 0; j <= mask; j++) {
      if (dp[idx][j] > 0) {
        for (k = 0; k < 10; k++) {
          int used = (j << (k + 1)) | (1 << k);
          if ((used & xyz) != xyz) dp[idx^1][used&mask] = (dp[idx^1][used&mask] + dp[idx][j]) % MOD;
        }
      }
    }
    idx ^= 1;
  }
  for (i = 0; i < n; i++) res = (res * 10) % MOD;
  for (i = 0; i <= mask; i++) res = (res - dp[idx][i] + MOD) % MOD;
  printf("%ld\n", res);
}

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

int main(){
  string s;
  cin >> s;
  int n=s.length();
  int l=(n-1)/2,r=(n+3)/2;
  bool judge=true;
  for(int i=0;i<n/2;i++){
    if(s[i]!=s[n-i-1]){
      judge=false;
      break;
    }
  }
  for(int i=0;i<l/2;i++){
    if(s[i]!=s[l-i-1]){
      judge=false;
      break;
    }
  }
  for(int i=r;i<n;i++){
    if(s[i]!=s[n-i-1]){
      judge=false;
      break;
    }
  }
  if(judge){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
  double a,b,ave;
  cin >> a >> b;

  ave = (a+b)/2;
  if(ave / (int)ave == 1)
    cout << ave << endl;
  else 
    cout << (int)ave + 1 << endl;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back      
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define pw(x) (1ll<<(x))
#define buli(x) __builtin_popcountll(x)
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define M 924844033
#define N 211111

#define TASK "1"


int n, k;
int was[2022][2][2][2022];
int dp[4444], dp2[4444];
int fu[4444];
int q[4444];

int ww[4444];

using namespace std;

int take(int x, int a, int b, int g) {
	if (g > x) return 0;
	if (g == 0) return 1;
	if (was[x][a][b][g] != -1) return was[x][a][b][g];

	if (x == 1) return (a + b);

	int res = 0;
	res = (res + take(x - 1, 1, b, g)) % M;
	if (a) res = (res + take(x - 1, 1, b, g - 1)) % M;
	res = (res + take(x - 1, 0, b, g - 1)) % M;
	return was[x][a][b][g] = res;
}

int main(){
	#ifdef home
		freopen(TASK".in","r",stdin);	
		freopen(TASK".out","w",stdout);
	#endif		
	ios::sync_with_stdio(false);
	cin >> n >> k;
	for (int i = 0; i<= n; i++) for (int a = 0; a < 2; a++) for (int b = 0; b < 2; b++) for (int j = 0; j <= i; j++) was[i][a][b][j] = -1;

	for (int i = 0; i <= n; i++) dp[i] = 0;
	dp[0] = 1;

	for (int i = 0; i < n; i++) if (!ww[i]) {
		int cnt = 0;
		int x = i;
		while (x < n) {
			ww[x] = 1;
			cnt++;
			x += k + k;
		}
		int hl = 0, hr = 0;
		if (i - k >= 0) hl = 1;
		if (x - k < n) hr = 1;
		
//		cout << cnt << " " << hl << " " << hr << endl;

		for (int j = 0; j <= cnt; j++) q[j] = take(cnt, hl, hr, j);

		for (int j = 0; j <= n; j++) dp2[j] = 0;

		for (int j = 0; j <= n; j++) for (int k = 0; k <= cnt; k++)
			dp2[j + k] = (dp2[j + k] + dp[j] * 1ll * q[k]) % M;
		for (int j = 0; j <= n; j++) dp[j] = dp2[j];
	}
	fu[0] = 1;
	for (int i = 1; i <= n; i++) fu[i] = fu[i - 1] * 1ll * i % M;
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		int t = dp[i] * 1ll * fu[n - i] % M;
		if (i % 2) t = (M - t) % M;
		ans = (ans + t) % M;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 55936
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] inputKX = scan.nextLine().split(" ");
        Integer k = Integer.valueOf(inputKX[0]);
        Integer x = Integer.valueOf(inputKX[1]);

        List<String> results = new ArrayList<String>();
        for(Integer i=x-(k-1); i<=x+(k-1); i++) {
            results.add(i.toString());
        }
        System.out.println(String.join(" ", results));
        scan.close();
    }
}

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

int main(){
	ll N,W;
	cin >> N >> W;
	vector<ll> weights(N), val(N);
	vector<ll> ans(W+1);

	for(ll i=0;i<N;i++){
		cin >> weights[i] >> val[i];
	}


	for(ll i=0;i<N;i++){
	    vector<ll> buff(W+1);
	    for(ll j=0;j<=W;j++){
	        buff[j] = ans[j];
	    }
		for(ll j=weights[i];j<=W;j++){
			buff[j] = max(ans[j], ans[j-weights[i]] + val[i]);
		}
		for(ll j=0;j<=W;j++){
	        ans[j] = buff[j];
	    }
	}

	cout << ans[W];
}

Measured memory_bytes: 1804
from collections import deque
K = int(input())

que = deque(map(str, range(1, 10)))
while K > 1:
    n = que.popleft()
    K -= 1
    R = int(n[-1])
    for r in (R - 1, R, R + 1):
        if 0 <= r <= 9:
            que.append(n + str(r))

print(que[0])


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

//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())

#define PB(a) push_back(a)

#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------
  char b,ans;
  cin >> b;
  switch (b){
    case 'A':
      ans='T';
      break;
    case 'C':
      ans='G';
      break;
    case 'G':
      ans='C';
      break;
    case 'T':
      ans='A';
      break;
  }
//  VI cd(n);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define ull long long
const ull INF = 1ull << 60;

int main (){
  ull H, N;
  cin >> H >> N;
  ull A[N], B[N];
  for (ull i = 0; i < N; ++i) {
    cin >> A[i] >> B[i];
  }
  ull table[H + 1];
  table[0] = 0;
  fill (table + 1, table + H + 1, INF);
  for (ull i = 0; i < H; ++i) {
    for (ull j = 0; j < N; ++j) {
      ull id = min(i + A[j], H);
      table[id] = min(table[id], table[i] + B[j]);
    }
  }

  cout << table[H] << endl;
  return 0;
}


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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)

#define lli long long
#define li long
#define vi vector<int>
#define vli vector<li>
#define vlli viector<lli>
#define pi pair<int,int>
#define vpi vector<pi>

#define INF 100001

using namespace std;

int main() {
    lli n, m;
    
    scanf("%lld %lld", &n, &m);

    lli max_min = 0;
    lli min_max = INF;

    int i;
    REP(i, 0, m-1) {
        lli a, b;
        scanf("%lld %lld", &a, &b);
        max_min = max(max_min, a);
        min_max = min(min_max, b);
    }
    lli ans = min_max - max_min + 1;
    if(ans > 0) cout << ans << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
	char s;
	cin >> s;
	if(s=='A'){cout<<'T'<<endl;}
	else if(s=='T'){cout<<'A'<<endl;}
	else if(s=='G'){cout<<'C'<<endl;}
	else if(s=='C'){cout<<'G'<<endl;}
	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define SIZE 100005

using namespace std;
typedef long long int ll;

int main()
{
    int n;
    cin >> n;
    map<string, uint64_t> mp;
    for (int i=0; i<n; i++)
    {
        string str;
        cin >> str;
        sort(str.begin(), str.end());
        mp[str]++;
    }

    ll sum = 0;
    for (auto& e : mp)
    {
        sum += e.second * (e.second - 1) / 2;
    }
    cout << sum << endl;
    
    return 0;
}


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

int main() {
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  
  if(e-a <= k) {
    cout << "Yay!" << endl;
  }
  else {
    cout << ":(" << endl;
  }
}

  


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>

using namespace std;

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

    int a[5][4][11];
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 10; k++)
            {
                a[i][j][k] = 0;
            }
        }
    }

    int b, f, r, v;

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

    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 10; k++)
            {
                cout << " " << a[i][j][k];
            }
            cout << endl;
        }
        if (i < 3)
        {
            cout << "####################" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3088
n = int(input())
h = list(map(int, input().split()))

ans = 0
tmp = 0

for i in range(n):
    ans += h[i]
    tmp = int(h[i])
    for j in range(i, n):
        if h[j] - tmp >= 0:
            h[j] -= tmp
        else:
            tmp = int(h[j])
            h[j] = 0

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <deque>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
	/* code */
	vector<string> a;
	deque<string> b; 
	int n;
	string ans;

	cin >> n;
	
	for (int i = 0; i < n; ++i)
	{
		string tmp;
		cin >> tmp;
		a.push_back(tmp);
	}

	//int length = a.length();

	if(n%2==1){
		for (int i = 0; i < n; ++i){
			/* code */
			if(i%2==0) b.push_front(a[i]);
			else b.push_back(a[i]);
		}		
	}

	else{
		for (int i = 0; i < n; ++i){
			/* code */
			if(i%2==0) b.push_back(a[i]);
			else b.push_front(a[i]);
		}		
	}

	for (int i = 0; i < b.size(); ++i)
	{
		/* code */
		ans += b[i];
		ans += " ";

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 19572
#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[]) {
    int n,m; cin>>n>>m;
    map<int,vector<int>> mp;
    rep(i,n) {
        int a,b; cin>>a>>b;
        mp[a].push_back(b);
    }

    vector<ll> dp(m+1);
    priority_queue<ll> pq;

    ll ans = 0;
    for (int i = m; i >= 0; --i) {
        for (auto &&e: mp[m-i]) pq.push(e);
        if (pq.empty()) continue;
        ans += pq.top();
        pq.pop();
    }

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

Measured memory_bytes: 11648
from collections import deque
n = int(input())
a = list(map(int,input().split()))
dp = [1000 for i in range(n)]

for i in range(n-1):
    for j in range(i,n):
        if a[i] < a[j]:
            mouke = dp[i] + (dp[i]//a[i])*(a[j]-a[i])
            dp[j] = max(dp[j],mouke)
        if j != 0:
            dp[j] = max(dp[j],dp[j-1])
print(dp[-1])

Measured memory_bytes: 68232
/*
 ============================================================================
 Name        : AtCoder_C.c
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>

int main(void) {
	int Num[3]={0,0,0};
	int f[3]={0,0,0};
	int Max=0;
	int i=0;

	scanf("%d",&Num[0]);
	scanf("%d",&Num[1]);
	scanf("%d",&Num[2]);

	if(Num[0]%2==1){
		f[0]=1;
	}
	if(Num[1]%2==1){
			f[1]=1;
		}
	if(Num[2]%2==1){
			f[2]=1;
	}

	Max=Num[0];
	if(Max<Num[1]){
		Max=Num[1];
	}
	if(Max<Num[2]){
		Max=Num[2];
	}

	if(f[0]+f[1]+f[2]==3 ||f[0]+f[1]+f[2] ==0 ){
		printf("%d", (3*Max-(Num[0]+Num[1]+Num[2]))/2 );
	}
	if(f[0]+f[1]+f[2]==1){
		for(i=0;i<3;i++){
			if(f[i]==0){
				Num[i]++;
			}
		}
		Max=Num[0];
			if(Max<Num[1]){
				Max=Num[1];
			}
			if(Max<Num[2]){
				Max=Num[2];
			}
			printf("%d", (3*Max-(Num[0]+Num[1]+Num[2]))/2 +1);
	}

	if(f[0]+f[1]+f[2]==2){
			for(i=0;i<3;i++){
				if(f[i]==1){
					Num[i]++;
				}
			}
			Max=Num[0];
				if(Max<Num[1]){
					Max=Num[1];
				}
				if(Max<Num[2]){
					Max=Num[2];
				}
				printf("%d", (3*Max-(Num[0]+Num[1]+Num[2]))/2 +1);
		}

	return EXIT_SUCCESS;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define N 100009
using namespace std;
typedef long long LL;

int a[N], vis[N];

int main()
{
    int n;
    memset(vis, 0, sizeof(vis));
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    int ans = 0, pre = 1, nx;
    while(true)
    {
        ans++;
        nx = a[pre];
        if(nx == 2) break;
        if(vis[nx]) break;
        vis[nx] = 1;
        pre = nx;
    }
    if(nx == 2) printf("%d\n", ans);
    else puts("-1");
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
int a[105][105];
char s[105][105];
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i = 0;i<n;i++){
		scanf("%s",s[i]);
	}
	for(int i = 0;i<=n+1;i++){
		if(i == 0||i==n+1){
			for(int j = 0;j<=m+1;j++){
				printf("#");
			}
		}
		else{
			for(int j = 0;j<=m+1;j++){
				if(j==0){
					printf("#");
				}
				else{
					printf("%s#",s[i-1]);
					break;
				}
				
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 128
'use strict'

const main = (input) => {
    input = input.split(' ').map(i => parseInt(i))
    const x1 = input[0]
    const y1 = input[1]
    const x2 = input[2]
    const y2 = input[3]
    const x = x2 - x1
    const y = y2 - y1
    console.log('%d %d %d %d', x2 - y, y2 + x, x1 - y, y1 + x)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 21064
import java.util.*;

public class Main{
		
		public static void main(String args[]){
	
			Scanner sc = new Scanner(System.in);
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			
			
			int amountLeftInBottle1 = a - b;
			int amountRemainingInBottle2 = c - amountLeftInBottle1;
			
			if(amountRemainingInBottle2 <= 0){
				
				amountRemainingInBottle2 = 0;
				
			}
			
			System.out.println(amountRemainingInBottle2);
			
		}
}

Measured memory_bytes: 23892
from sys import stdin
import bisect

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

lin = [[]for _ in range(n)]
lin2 = []

for i in range(m):
    lin[li[i][0]-1].append(li[i][1])

for j in range(n):
    liv = sorted(lin[j])
    lin2.append(liv)

for k in range(m):
    tosi = str(li[k][0]).zfill(6)
    ban =  str(bisect.bisect(lin2[li[k][0]-1],li[k][1])).zfill(6)
    print(tosi+ban)

Measured memory_bytes: 47664
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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 (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int a, b, c, d; cin >> a >> b >> c >> d;

	cout << max({ a*c,a*d,b*c,b * d }) << endl;

	return 0;
}



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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    vector<int> b(n);
    for (int i = 0; i < n; i++) b[i] = a[i] - (i + 1);
    sort(b.begin(), b.end());
    long long ans = 0;
    for (int bi: b) ans += abs(bi - b[n / 2]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
const int INF = pow(2,31)-1;
const int MAX_N = 1<<17;
int n_;
int dat[2*MAX_N-1];

void init(int n) {
  n_ = 1;
  while (n_<n) {
    n_ *= 2;
  }
  for (int i=0; i<2*n_-1; i++) {
    dat[i] = INF;
  }
}
void update(int i,int x) {
  i += n_-1;
  dat[i] = x;
  while (i>0) {
    i = (i-1)/2;
    dat[i] = min(dat[i*2+1],dat[i*2+2]);
  }
}
int find(int x,int y,int k,int l,int r) {
  if (r<=x || y<=l) {
    return INF;
  }
  if (x<=l && r<=y) {
    return dat[k];
  } else {
    int vl = find(x,y,k*2+1,l,(l+r)/2);
    int vr = find(x,y,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
}
int main() {
  int n, q;
  cin >> n >> q;
  init(n);
  for (int i=0; i<q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com==0) {
      update(x,y);
    } else {
      cout << find(x,y+1,0,0,n_) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4060
a[9],b[9],i,x,y;
main(j){
while(scanf("%d%d%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3])>0)
    {  
      x=y=0;
      for(i=0;i<4;i++)
	for(j=0;j<4;j++)
	  if(a[i]==b[j])
	    if(i==j)
	      x++;
	    else
	      y++;
      printf("%d %d\n",x,y);
    }
  exit(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

int main(){
    lli n,m,d,t;
    string ans="YES";
    vector<lli> vec;
    map<lli,lli> map;
    lli i,j;
    cin>>n;
    rep(i,0,n){
        cin>>d;
        map[d]++;
    }
    cin>>m;
    rep(i,0,m){
        cin>>t;
        vec.push_back(t);
    }
    rep(i,0,m){
        map[vec[i]]--;
        if(map[vec[i]]<0){
            ans="NO";
            break;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 14964
def main():
    s = input()

    zero = ["SSS"]
    one = ["RSS","SRS","SSR","RSR"]
    two = ["SRR","RRS"]
    thr = ["RRR"]

    if s in zero:
        print(0)
    elif s in one:
        print(1)
    elif s in two:
        print(2)
    else:
        print(3)
main()

Measured memory_bytes: 9108
// coding on smartphone
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

int main(){
	vector<int> p;
	bool nonp[50000] = {};
	for(int i = 2; i < 50000; i++){
		if(nonp[i]) continue;
		p.push_back(i);
		for(int j = i+i; j < 50000; j+=i) nonp[j] = true;
	}
	
	int m, a, b;
	while(cin >> m >> a >> b, m+a+b){
		int ansa = 0, answ, ansh;
		for(int i = 0; i < p.size(); i++){
			if(p[i] > sqrt(m)) break;
			int x = min(p[i]*b/a, m/p[i]);
			int h = *(upper_bound(p.begin(), p.end(), x) - 1);
			if(p[i]*h > ansa){
				ansa = p[i]*h;
				answ = p[i];
				ansh = h;
			}
		}
		
		cout << answ << " " << ansh << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3188
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = line[0];
            int B = line[1];
            int C = line[2];
            Console.WriteLine(C >= A && C <= B ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 11092
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        List<Integer>[] next = new List[n];
        for(int i=0; i<n; i++) {
            next[i] = new ArrayList<Integer>();
        }

        for(int i=0; i<m; i++) {
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;
            next[a].add(b);
            next[b].add(a);
        }

        boolean[] v = new boolean[n];
        int[] p = new int[n];

        Queue<Integer> q = new LinkedList<>();
        q.add(0);
        while(!q.isEmpty()) {
            int a = q.poll();
            for(int b : next[a]) {
                if(!v[b]) {
                    p[b] = a;
                    q.add(b);
                    v[b] = true;
                }
            }
        }

        boolean yes = true;
        for(boolean bb : v) {
            if(!bb) {
                yes = false;
                break;
            }
        }

        if(yes) {
            System.out.println("Yes");
            for(int i=1; i<n; i++) {
                System.out.println(p[i]+1);
            }
        } else {
            System.out.println("No");
        }

    }



}

Measured memory_bytes: 83992
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N;
    string S, T;
    cin >> N >> S >> T;
    char ans[2 * N];
    for (int i = 0; i < N; i++) {
        ans[2 * i] = S[i];
        ans[2 * i + 1] = T[i];
    }
    string ans_str(ans, 2 * N);
    cout << ans_str << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean[] p = new boolean[50001];
		Arrays.fill(p, true);
		p[0] = p[1] = false;
		for (int i = 2; i < 50001; i++) for (int j = i * 2; j < 50001; j += i)p[j] = false;
		while (sc.hasNextInt()) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			int c = 0;
			for (int i = 2; i <= n / 2; i++) if (p[i] && p[n - i])c++;
			System.out.println(c);
		}
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
signed main(){
    int n , k , d , a , ans , have[105] = {};
    cin >> n >> k;
    for(int i=0 ;i<k ;i++ ){
        cin >> d;
        for(int j=0 ;j<d ;j++ ){
            cin >> a;
            have[a] = 1;
        }
    }
    
    ans = n;
    for(int i=1 ;i<=n ;i++ ){
        ans -= have[i];
    }
    cout << ans << endl;
    return(0);
}

Measured memory_bytes: 3636
object Main {
  def main(args: Array[String]): Unit = {
    val steps = scala.io.StdIn.readLine
    var flag  = true

    (0 until steps.length).foreach({ i =>
      if((i + 1)%2 == 0) {
        if( steps(i).equals('R')) flag = false
      }
      else {
        if( steps(i).equals('L')) flag = false
      }
    })

    if(flag) println("Yes") else println("No")
  }
}

Measured memory_bytes: 25528
#include<cstdio>
#include<iostream>

using namespace std;

#define fr(i,a,b) for(register int i=a;i<=b;i++)
#define fv(i,a,b) for(register int i=a;i>=b;i--)
#define fmax(a,b) ((a)>(b)?(a):(b))
#define fmin(a,b) ((a)<(b)?(a):(b))

int maxn,a,b,c,cc;

inline int v_in(){
	char ch=getchar();int sum=0,f=1;
	while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
	while(isdigit(ch)) sum=(sum<<3)+(sum<<1)+(ch^48),ch=getchar();
	return sum*f;
}

int main(){
	scanf("%d%d%d",&a,&b,&c);
	maxn=fmax(a,fmax(b,c));
	cc=maxn+maxn+maxn-a-b-c;
	if(cc&1) cc+=3;
	printf("%d\n",cc>>1);
	return 0;
}

Measured memory_bytes: 256
#n=int(input())
n,m=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

import math 
import heapq

hq=[(-1)*val for val in al]
heapq.heapify(hq)

for i in range(m):
    mx=(-1)*(heapq.heappop(hq))
    newval=math.floor(mx/2)
    heapq.heappush(hq,(-1)*newval)

print(-sum(hq))

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

int main() {
	int n;
  	cin>>n;
  
  	int a[n];
  	rep(i,n)cin>>a[i];
  
  	int b[n];
  	rep(j,n)cin>>b[j];
  
  	int c[n];
    rep(k,n)cin>>c[k];
  
  int manzoku=0;
  //これは全部足すだけでおｋ
  rep(l,n){
  	manzoku+=b[l];
  }

  //食べ合わせボーナス
  //2個目から数える
  //1個前との差が一つならｃの値を足す
  //a[m-1]-1ってだるいなあ
  for(int m=1;m<n;m++){
  	if(a[m]-a[m-1]==1){
    manzoku+=c[a[m-1]-1];
    }
  }
   	cout<<manzoku<<endl;
      
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BC
import qualified Data.IntMap as M
import Data.Maybe (fromJust)
import Data.List

main = do
  [n,a,b] <- map read . words <$> getLine :: IO [Int]
  h <- sort <$> getIntListBC
  print $ lowerBound h a b

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

getIntListBC :: IO [Int]
getIntListBC = map bsToInt . BC.lines <$> BC.getContents

lowerBound :: [Int] -> Int -> Int -> Int
lowerBound h a b = innerLB (0-1) (maximum h)
  where innerLB lb ub
          | ub - lb > 1 = let mid = lb + (ub - lb) `div` 2
                          in if explode h a b mid then innerLB lb mid
                                                  else innerLB mid ub
          | otherwise   = ub

explode :: [Int] -> Int -> Int -> Int -> Bool
explode h a b k = let add = a - b
                      count = sum . map (divCount add) . filter (>0) $ map (flip (-) (b*k)) h
                  in count <= k

divCount :: Int -> Int -> Int
divCount x n = if mod n x == 0 then div n x
                               else (+1) $ div n x


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 k,q;
    cin >> k >> q;
    vector<int32> d(k);
    REP(i,k)cin >> d[i];
    REP(_,q){
        int32 n,x,m;
        cin >> n >> x >> m;
        int64 an = x;
        int32 cnt = 0;
        REP(i,k){
            int64 num = (n-1-i+k-1)/k;
            an += (d[i]%m)*num;
            if(d[i]%m == 0)cnt += num;
        }
        ANS(n-1-(an/m - x/m)-cnt);
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    vector<ll> dp(n,INT_MAX);
    dp[0]=0;
    for(int i=0;i<n-1;i++)
    {
        dp[i+1]=min(dp[i+1],dp[i]+abs(a[i]-a[i+1]));
        if(i!=n-1)
        {
            dp[i+2]=min(dp[i+2],dp[i]+abs(a[i]-a[i+2]));
        }
    }
    cout<<dp[n-1];

}

Measured memory_bytes: 1792
import numpy as np

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = np.int32(A) - 1

nxt = np.zeros((70, N), dtype=int)
nxt[0] = A
for i in range(0, 69):
    nxt[i + 1] = nxt[i, nxt[i]]

pos = 0
for i, v in enumerate(reversed(bin(K)[2:])):
    if v == '1':
        pos = nxt[i, pos]

print(pos + 1)

Measured memory_bytes: 140108
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
LL N, M, S;
LL A[50];
inline LL ceil(LL d, LL n) {return (d+n-1)/n;}
inline bool ok(LL x) {
  if(M < S-x) return false;
  LL s = 0;
  for(auto i=0; i<N; ++i) s += max(0ll, ceil(A[i]+x+1-N, N+1));
  return s <= x;
}
int main() {
  scanf("%lld", &N);
  M=N*(N-1);
  for(auto i=0; i<N; ++i) scanf("%lld", A+i), S+=A[i];
  LL l = -1, h = 1e18;
  while(l+1 < h) {
    LL m = (l+h)>>1;
    if(ok(m)) h = m;
    else      l = m;
  }
  for(auto x=max(0ll,h-N*N); x<=h; ++x) if(ok(x)) {
    printf("%lld\n",x);
    break;
  }
}


Measured memory_bytes: 256
n,*t=map(int,open(0).read().split())
*z,=zip(t[::2],t[1::2])
m=1e18
for ax,ay in z:
  for bx,by in z:
    p,q=bx-ax,by-ay
    if not p+q:continue
    t=0
    for cx,cy in z:
      for dx,dy in z:
        if dx+p==cx and dy+q==cy:break
      else:t+=1
    if t<m:m=t
print(+(m>1e17)or m)

Measured memory_bytes: 43484
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [x, y]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    const a = 2 * x - y / 2;
    const b = y / 2 - x;
    return `${a >= 0 && b >= 0 && Math.floor(a) == a && Math.floor(b) == b ? "Yes" : "No"}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

/*
2a + 2b = 2x
2a + 4b = y
2b = y - 2x
y > 2x

2a = 2x - (y - 2x)
2a = 4x - y
 */


Measured memory_bytes: 29628
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll long long int
int main()
{
    ll a;
    while(~scanf("%lld",&a))
    {
        ll mod=11;
        ll output=a/mod*2;
        a%=mod;
        if(a>=1&&a<=6)output++;
        if(a>=7&&a<=10)output+=2;
        printf("%lld\n",output);
    }
}

Measured memory_bytes: 128
D=int(input())
c=input().split()
c=[int(a) for a in c]
S=[]
for _ in range(D):
    s=input().split()
    s=[int(a) for a in s]
    S.append(s)

for d in range(D):
    if d%27==0:
        print(20)
    else:
        print(d%27)


Measured memory_bytes: 68104