akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		while(in.hasNext()){
			try{
				int hit = 0;
				int blow = 0;
				int[] all = new int [10];
				int[] a = new int [4];
				int[] b = new int [4];
				for(int i = 0;i < 4;i++){
					a[i] = in.nextInt();
					all[a[i]] = 1;
				}
				for(int i = 0;i < 4;i++){
					b[i] = in.nextInt();
					if(a[i] == b[i]){
						hit++;
					}else{
						for(int j = 0;j < 4;j++){
							if(a[j] == b[i]){
								blow++;
							}
						}
					}
				}
				System.out.println(hit +" "+blow);
			}catch(Exception e){
				System.exit(0);
			}
		}
	}
}

Measured memory_bytes: 18136
from collections import Counter

import sys
input = sys.stdin.readline

S = list(input().rstrip())
A = Counter(S)

P = list(A.values())
ok = True
if len(P) == 2:
    if P[0] == 1 and P[1] == 1:
        ok = True
    else:
        ok = False
elif len(P) == 1:
    if P[0] == 1:
        ok = True
    else:
        ok = False
else:
    P.sort()
    if P[-1] - P[0] > 1:
        ok = False
print("YES" if ok else "NO")

Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int A, B, C, D;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> A >> B >> C >> D;
    int cnt = 0;
    while(A > 0 && C > 0){
        if(cnt & 1) A -= D;
        else C -= B;
        cnt++;
    }
    cout << (cnt & 1 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;

int ans = -1;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int ans = max<int>({
        10 * a + b + c,
        a + b * 10 + c,
        a + b + c * 10,
    });
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
#include <list>
#include <iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
#define all(s) s.begin(),s.end()
typedef long long ll;
typedef pair<string,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
const ll MODatc = 1000000007;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.first<secondElof.first;
}
bool pairCompare2(P firstElof,P secondElof){
    return (firstElof.second)%1000>(secondElof.second)%1000;
}
bool less_mod1000(int lhs, int rhs) {
  if ((lhs - rhs) % 1000 != 0)
    return lhs % 1000 < rhs % 1000;
  else // 5で割った余りが等しいなら普通に大小比較する
    return lhs < rhs;
}
string Alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alpha="abcdefghijklmnopqrstuvwxyz";
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n;cin>>n;
    ll d[n];
    rep(i,0,n)cin>>d[i];
    ll sum=0;
    rep(i,0,n-1){
      rep(j,i+1,n)sum+=d[i]*d[j];
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
while True:
    a, op, b = input().split(" ")
    if op == "?":
        break
    elif op == "+":
        print( int(a) + int(b) )
    elif op == "-":
        print( int(a) - int(b) )
    elif op == "*":
        print( int(a) * int(b) )
    elif op == "/":
        print( int(a) // int(b) )

Measured memory_bytes: 7640
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> k(m);
  vector<vector<int>> s(m);
  vector<int> p(m);

  for (int i = 0; i < m; ++i) {
    cin >> k[i];
    s[i].resize(k[i]);
    for (int j = 0; j < k[i]; ++j) {
      cin >> s[i][j];
      --s[i][j];
    }
  }
  for (int k = 0; k < m; ++k) {
    cin >> p[k];
  }

  int ans = 0;
  for (int bits = 0; bits < (1 << n); ++bits) {
    bool all_ok = true;
    for (int i = 0; i < m; ++i) {
      int cnt = 0;
      for (int j = 0; j < k[i]; ++j) {
        if ((bits >> s[i][j]) & 1) cnt++;
      }
      if (p[i] != (cnt % 2)) all_ok = false;
    }
    if (all_ok) ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3172
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


	int N;
	cin >> N;

	int A[200000], B[200000];
	rep(i, N) {
		cin >> A[i] >> B[i];
	}

	sort(A, A + N);
	sort(B, B + N);

	if (N % 2) {
		int a = A[(N - 1) / 2];
		int b = B[(N - 1) / 2];
		co(b - a + 1);
	}
	else {
		int a = A[N / 2] + A[N / 2 - 1];
		int b = B[N / 2] + B[N / 2 - 1];
		co(b - a + 1);
	}



	Would you please return 0;
}

Measured memory_bytes: 5152
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d;
  string s;
  long long ans = 0;
  
  cin >> a >> b;

  if(a == b) s = "Draw";
  else if(a == 1 || a > b && b != 1) s = "Alice";
  else s = "Bob";
  
  cout << s << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int a, b, k; cin >> a >> b >> k;
    vector<int> v;
    for (int i = 0; i < k; i++) {
        if (a + i >= a && a + i <= b) v.push_back(a + i);
    }

    for (int i = 0; i < k; i++) {
        if (b - i > 0 && b - i <= b && b - i >= a) v.push_back(b - i);
    }

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    for (int x : v) cout << x << endl;
    return 0;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    
  if (a % 2 == 1 && b % 2 == 1){
    cout << "Odd" << endl;  
  }
  else{
    cout << "Even" << endl;
  }
}


Measured memory_bytes: 256
al=[chr(ord('a') + i) for i in range(26)]
N=int(input())
ans=[[] for _ in range(N)]
ans[0].append("a")

if N==1:
  print("a")
else:
  for i in range(1,N):    
    for item in ans[i-1]:
      lis=list(item)
      st=set(lis)
      for j in range(len(st)+1):
        ans[i].append(item +chr(ord('a') + j))
  for answer in ans[-1]:
    print(answer)

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

using namespace std;

int main(){
  int n,d,x;
  cin >> n >> d >> x;
  
  int a[n];
  int choco = 0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    //cout << "a:" << ((d - 1) / a[i]) + 1 << endl;
    choco += ((d - 1) / a[i]) + 1;
  }
  cout << choco + x << endl;  
}

Measured memory_bytes: 256
import math

n = m = int(raw_input())
r = int(math.sqrt(n))
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]
 
prime=[]
for i in range(r):
    if p[i]:
        prime.append(i+1)

a = []
for i in range(len(prime)):
    if n % prime[i] == 0:
        j = prime[i]
        while n % j == 0:
            n /= j
            a.append(j)
if n == m:
    print str(m)+":",m
elif n != 1:
    print str(m)+":"," ".join(map(str, a)),n
else:
        print str(m)+":"," ".join(map(str, a))

Measured memory_bytes: 5768
import sys
input = sys.stdin.readline
def main():
    N, M, X = map(int, input().split())
    C = [list(map(int, input().split())) for i in range(N)]
    # print(C)
    pCOST = float("inf")
    for bit in range(1<<N):
        COST = 0
        SJ = [0]*M
        for j in range(N):
            if bit>>j & 1:
            # if bit>>(j+1) & 1:
                COST += C[j][0]
                for k in range(1,M+1):
                    SJ[k-1] += C[j][k]
        for l in range(M):
            if SJ[l] >= X:
                continue
            else:
                COST = float("inf")
                break
        pCOST = min(pCOST, COST)
    if pCOST == float('inf'):
        print(-1)
    else:
        print(pCOST)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9228
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

typedef pair<int, int> P;

int main() {

	int n, c;
	cin >> n >> c;

	vector< vector<int> > d(c, vector<int>(c, 0));

	for (int i = 0; i < c; i++) {
		for (int j = 0; j < c; j++) {
			cin >> d[i][j];
		}
	}

	vector< vector<int> > cc(n, vector<int>(n, 0));

	vector<P> a1, a2, a3;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> cc[i][j];
			if ((i + j) % 3 == 0) {
				a3.push_back(P(i, j));
			}
			else if ((i + j) % 3 == 1) {
				a1.push_back(P(i, j));
			}
			else {
				a2.push_back(P(i, j));
			}
		}
	}

	long long int ans = 1010 * 500 * 500;

	vector<long long int> a11(c,0);
	vector<long long int> a22(c,0);
	vector<long long int> a33(c,0);

	for (int i = 0; i < c; i++) {
		for (int j = 0; j < a1.size(); j++) {
			P p = a1[j];
			a11[i] += d[cc[p.first][p.second] - 1][i];
		}
		for (int j = 0; j < a2.size(); j++) {
			P p = a2[j];
			a22[i] += d[cc[p.first][p.second] - 1][i];
		}
		for (int j = 0; j < a3.size(); j++) {
			P p = a3[j];
			a33[i] += d[cc[p.first][p.second] - 1][i];
		}
	}

	for (int i = 0; i < c; i++) {
		for (int j = 0; j < c; j++) {
			for (int k = 0; k < c; k++) {
				if (i != j&&j != k&&k != i) {
					long long int MIN = 0;
					MIN = a11[i] + a22[j] + a33[k];
					ans = min(ans, MIN);
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
	int x,y;
	cin >> x >> y;
	while(!(x==0&&y==0)){
		if(x<y) cout << x << " " << y << endl;
		else cout << y << " " << x << endl;
		cin >> x >> y;
	}
	return 0;
}



Measured memory_bytes: 3072
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> h(n); REP(i, n) cin >> h[i];
  reverse(ALL(h));
  int pos = 0, ans = 0;
  while (pos < n) {
    int j = pos;
    while (j + 1 < n && h[j] <= h[j + 1]) ++j;
    ans = max(ans, j - pos);
    pos = j + 1;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, N) for(int i = 0; i < N; i++)
 
int main()
{
  int N, M;
  
  while(cin >> N >> M, N || M) {
    int A[1005] = {0};
    vector<int>sum;
    int maxv = 0;
    sum.push_back(0);
    for(int i = 1; i <= N; i++) {
      cin >> A[i];
      Rep(j, i + 1) {
	if(A[i] + A[j] <= M) sum.push_back(A[i] + A[j]);
      }
    }
    sort(sum.begin(), sum.end());
    Rep(i, sum.size()) {
      maxv = max(maxv, sum[i] + *(upper_bound(sum.begin(), sum.end(), M - sum[i]) - 1));
    }
    cout << maxv << endl;
  }
  return 0;
}

Measured memory_bytes: 6804
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int N;
 scanf("%d", &N);
  bool t=true;
  
  int A[N];
  for (int i=0; i<N; i++) scanf("%d", &A[i]);
sort(A,A+N);
  for (int i=0; i<N-1; i++){
    if (A[i]==A[i+1]) t=false;
  }
  if (t) printf ("YES\n");
    else printf ("NO\n");
}

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

using namespace std;

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) {
            ++num;
            n /= p;
        }
        res.emplace_back(make_pair(p, num));
    }
    if (n != 1) {
        res.emplace_back(make_pair(n, 1));
    }
    return res;
}

int main() {
    long long a, b;
    cin >> a >> b;

    long long g = __gcd(a, b);
    cout << prime_factorize(g).size() + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/functional/hash.hpp>
//example: unordered_set< pair<int,int>,boost::hash< std::pair<int, int> > > used;
//priority_queue< pair<int,pair<int,int> >, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int> > > > pqueue;    //cost, vertex(行き先)
using namespace std;

#define MODULE 1000000007
#define MP make_pair
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
template<typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val){ //usage: int dp[10][10]; Fill(dp,INF);
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef pair<int, int> P;
typedef long long LL;
const int INF = INT_MAX / 2;    //int_max->2*e+9 LLの時はLLONG_MAX
/*const int MAXN = 100001;

struct edge {
    edge(int to, int cost) : to(to), cost(cost) {}
    int to, cost;
};
vector<edge> graph[MAXN];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};*/

//-----Template---------
int n;
int a[20001];
int p[20001];
int main(){
    ios::sync_with_stdio(false); //cout<< fixed << setprecision(10);
    cin>>n;
    for (int i = 1; i <= n; ++i) {
        cin>>p[i];
    }
    for (int i = 1; i <= n; ++i) {
        a[i]=20010*i;
    }
    for (int i = 1; i <=n ; ++i) {
        a[p[i]]+=i;
    }

    for (int i = 1; i <= n; ++i) {
        cout<<a[i];
        if(i!=n)
            cout<<" ";
    }
    cout<<endl;
    for (int i = n; i >0; --i) {
        cout<<20010*i;
        if(i!=1)
            cout<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
const int maxn=3100;
int dp[maxn][maxn];
int pa[maxn][maxn];
int main()
{
    string a,b;
    cin>>a;
    cin>>b;
    int  lena=a.length();
    int  lenb=b.length();
    memset(dp,0,sizeof(dp));
    for(int i=0;i<=lena;i++)
    {
        for(int j=0;j<=lenb;j++)
        {
            if(i==0||j==0)
            {
                dp[i][j]=0;
            }
            else if(a[i-1]==b[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
                pa[i][j]=1;
            }
            else if(a[i-1]!=b[j-1])
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                if(dp[i][j]==dp[i][j-1]) pa[i][j]=2;
                else pa[i][j]=3;
            }
        }
    }
    int  x=lena;
    int  y=lenb;
    string ans;
    while(x>0&&y>0)
    {
        if(pa[x][y]==1)
        {
            ans.push_back(b[y-1]);
            x--;
            y--;
        }
        else if(pa[x][y]==2)
        {
            y--;
        }
        else if(pa[x][y]==3)
        {
            x--;
        }
      //  cout<<x<<' '<<y<<endl;
    }
    if(!ans.empty())
    for(int i=ans.length()-1;i>=0;i--)
    {
        cout<<ans[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 77484
#include <assert.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#ifndef __DEBUG__
    #define debug NULL
#else
    #define debug printf("%s %d\n", __FUNCTION__, __LINE__);
#endif
const int inf = 2147483647;

const int maxn = 1e5 + 10;
int a[maxn];
int main(int argc, char **argv) {
    int n;
    int data;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &data);
        a[data]++;
    }
    int ans = 0;
    for (int i = 1; i < maxn - 1; i++) 
        ans = max(ans, a[i - 1] + a[i] + a[i + 1]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1000000007;
signed main(){
  int H,W;
  cin>>H>>W;
  vector<string> A(H);
  for(string &S:A)
    cin>>S;
  vector<vector<int>> B(H+1,vector<int>(W+1,0));
  B[0][1]=1;
  for(int i=1;i<=H;i++)
    for(int j=1;j<=W;j++)
      if(A[i-1][j-1]=='.')
        B[i][j]=(B[i-1][j]+B[i][j-1])%mod;
  cout<<B[H][W]<<endl;
}

Measured memory_bytes: 13024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<pii>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> dp(M + 1, vector<int>((1 << N) + 5, INF));
    dp[0][0] = 0;
    for(int i = 0; i < M; ++i) {
        int a, b, bit = 0;
        cin >> a >> b;
        for(int j = 0; j < b; ++j) {
            int c;
            cin >> c;
            c--;
            bit |= (1 << c);
        }
        for(int j = 0; j < (1 << N); ++j) {
            if(dp[i][j] >= INF)
                continue;
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            dp[i + 1][j | bit] = min(dp[i + 1][j | bit], dp[i][j] + a);
        }
    }
    int ans = dp[M][(1 << N) - 1];
    cout << (ans >= INF ? -1 : ans) << endl;
    return 0;
}


Measured memory_bytes: 16384
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6 + 10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

x, y = map(int, input().split())

n = (2 * x - y) / 3
m = (2 * y - x) / 3
mod = 10 ** 9 + 7

if int(n) == n and int(m) == m:
    n = int(n)
    m = int(m)
    ans = cmb(n + m, n, mod)
    ans %= mod
    print(ans)

else:
    print(0)


Measured memory_bytes: 122000
N = int(input())
#s = input()
#S = []
#for i in range(N):
S = input().split(" ")
SUM = 0
for i in range(N):
    temp = int(S[i])
    temtem = 1 / temp
    SUM += temtem
Ans = 1 / SUM
print(Ans)

Measured memory_bytes: 2940
// A.

#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	const char *s[] = { "Christmas Eve Eve Eve", "Christmas Eve Eve", "Christmas Eve", "Christmas" };
	int d;
	cin >> d;
	cout << s[d - 22] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF (int)1e9
#define MOD 0
//#define int ll
using namespace std;
typedef vector<int> vi;

signed main(){
    ll count = 1,n;
    string s;
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> s;
    ll ih[100];
    rep(i,100) ih[i] = 1;
    rep(i,n) {
        ih[s[i] - 'a']++;
    }
    rep(i,100) {
        count *= ih[i];
        count %= (ll)1e9 + 7;
    }
    cout << count - 1  << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
//l={1,2,3,4}
//sort(l,l+N,greater<int>());	降順ソート
//sort(l,l+N);	昇順ソート
//string 変数　　変数.size()で数字化


int main(void)
{
	int n;
	string test;
	cin >> n >> test;

	int x = 0;
	int ma[105];
	for (int i = 0; i < n; i++) {
		if (test[i] == 'I')
			x++;
		else
			x--;
		ma[i] = x;
	}
	sort(ma, ma + n, greater<int>());
	if (ma[0] < 0)
		cout << 0 << endl;
	else
		cout << ma[0] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;

int main(){
   long long q,h,s,d,n;
   cin>>q>>h>>s>>d>>n;
   long long m=min({q*4,h*2,s});
   long long ans;
   if(m*2<=d)ans=m*n;
   else {
      if(n%2==0)ans=d*n/2;
      else ans=n/2*d+m;
   }
   cout<<ans<<endl;

}

   


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

int main(){
    int n;
    vector<int> A;
    int amax = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        int ai;
        cin >> ai;
        A.push_back(ai);
        amax = max(amax, ai);
    }
    vector<int> C(amax+1, 0);

    for(int i = 0; i < n; i++){
        C[A[i]]++;
    }
    for(int i = 1; i <= amax; i++){
        if (C[i] == 0)continue;
        if (C[i] >= 2)C[i] = 0;
        int now = i;
        for(int j = 2; j * now <= amax; j++){
            C[now * j] = 0;
        }
    }
    int ans = 0;
    for(int i = 1; i <= amax; i++){
        ans += C[i];
    }
    cout << ans << endl;
    return 0;
}

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

void chmax(ll &a, ll b){
  if( a < b){ swap(a,b);}
  return ;}

int main(){
  
  ll N,W; cin >> N >> W;
  vector<ll> w(N); vector<ll> v(N);
  for(ll i = 0; i < N; i++){  cin >> w[i] >> v[i];}
  
  ll dp[110][100100];
  for(int i = 0; i < 110; i++){
    for(int j = 0; j < 100100; j++){ 
      dp[i][j] = 0LL;}}
  
  dp[0][w[0]] = v[0];
  
  for(int i = 0; i < N-1; i++){
    for(int j = 0; j < 100100; j++){
      
        
        chmax( dp[i+1][j], dp[i][j]);
      if( j+w[i+1] <= W){ 
        chmax( dp[i+1][j+w[i+1]], dp[i][j]+v[i+1]); }
  }
}
 
  ll ans = 0;
  
  for(int i  =0; i <= W; i++){
    chmax( ans, dp[N-1][i]);}
  
  cout << ans << endl; return 0;}
    
    

Measured memory_bytes: 86272
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    d, t, s = MI()
    ans = "Yes" if t * s >= d else "No"
    print(ans)


main()


Measured memory_bytes: 64700
using System;


namespace ConsoleApplication35
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] ss = s.Split(' ');
            int W = int.Parse(ss[0]);
            int H = int.Parse(ss[1]);
            int x = int.Parse(ss[2]);
            int y = int.Parse(ss[3]);
            int r = int.Parse(ss[4]);
            if(r <= x && (x + r) <= W && r <= y && (y + r) <= H && x > 0 && y > 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 8824
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+7;

int x[100004], y[100004], b[100004];
int sx[100004], sy[100004];
signed main(){
	int n, m, xx, yy;
	scanf("%lld%lld", &n, &m);
	for(int i = 1;i <= n;i++)scanf("%lld", &x[i]);
	for(int i = 1;i <= m;i++)scanf("%lld", &y[i]);
	xx = x[1], yy = y[1];
	if(xx < 0)for(int i = 1;i <= n;i++)x[i] = (x[i]-xx)%mod;
	if(yy < 0)for(int i = 1;i <= m;i++)y[i] = (y[i]-yy)%mod;
	
	for(int i = 1;i <= n;i++)sx[i] = (sx[i-1]+x[i])%mod;
	for(int i = 1;i <= m;i++)sy[i] = (sy[i-1]+y[i])%mod;
	int s = 0, sb = 0;
	
	for(int i = 1;i < m;i++){
		b[i] = (2*mod+(sy[m]-sy[i])-((m-i)*y[i])%mod)%mod;
		sb = (sb+b[i])%mod;
	}
	for(int i = 1;i < n;i++){
		int a = (2*mod+(sx[n]-sx[i])-((n-i)*x[i])%mod)%mod;
		//printf("%lld %lld\n", a, b);
		s = (s+a*sb)%mod;
	}
	printf("%lld\n", s);
	/*for(int i = 1;i <= n;i++)printf("%lld ", sx[i]);
	printf("\n");
	for(int i = 1;i <= m;i++)printf("%lld ", sy[i]);*/
	return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  long long a, b, c;
  cin >> a >> b >> c;
  long long num = c - (a + b);
  bool is_ok;
  if (num <= 0)
    is_ok = false;
  else
  {
    is_ok = 4 * a * b < num * num;
  }
  printYesNo(is_ok);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define int long long 
typedef long long ll;

typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=200005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

ll qmult(ll X, ll Y, ll M) {    
    return X * Y % M;
}

ll qexp(ll A, ll B, ll M) {
    if (B == 0) return 1; 
    ll half = qexp(A, B/2, M);
    half = qmult(half, half, M);
    half %= M;
    if (B%2==1) half *= A%M;
    return half%M;
}

int A[MAXN], N, pc;
int rem, remp, remn;

int f(int x){
	assert(x >= 0);
	if (x==0) return 0;
	x = x%__builtin_popcountll(x);
	return 1 + f(x);
}

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	FOR(i,1,N) {
		char c; cin >> c;
		if (c == '0') A[i] = 0;
		else A[i] = 1;
		pc += A[i];
	}
	if (pc == 0){
		remp = 0, remn = 0;
	}
	else{
		FOR(i,1,N){
			int tmp = qexp(2, N-i, pc);
			rem = (rem + tmp)%pc;
			tmp = A[i] * qexp(2, N-i, pc+1);
			remp = (remp + tmp)%(pc+1);
			if (pc != 1) tmp = A[i] * qexp(2, N-i, pc-1);
			if (pc != 1) remn = (remn + tmp)%(pc-1);
		}
	}
	//db(rem), db(pc);
	int cur_pc, tmp_rem;
	FOR(i,1,N){
		if (A[i] == 0){
			cur_pc = pc + 1;
			tmp_rem = (remp + qexp(2, N-i, cur_pc)) % cur_pc;
			cout << 1 + f(tmp_rem) << "\n";
		}
		else{
			cur_pc = pc - 1;
			if (cur_pc == 0) cout<<"0\n";
			else{
				tmp_rem = (remn - qexp(2, N-i, cur_pc)) % cur_pc;
				tmp_rem = (tmp_rem + cur_pc) % cur_pc;
				cout << 1 + f(tmp_rem) << "\n";
			}
		}
	}
	//db(f(7));
}


Measured memory_bytes: 5168
#include<stdio.h>
int main(void){
	int input, i, j, people;
	while (scanf(" %d", &people), people){
		int age[7] = { 0 };
		for (i = 0; i<people; i++){
			scanf(" %d", &input);
			for (j = 1; input-10*j>=0 && j<7; j++){
			}
			age[j - 1]++;
			//printf("    %d\n", j-1);
		}
		for (i = 0; i < 7; i++){
			printf("%d\n", age[i]);
		}
	}
	return 0;
}

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

const int N = 109;

int n, a[N]={}, sum = 0;

int main(){
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a[i];
        sum += a[i];
    }

    if(sum % 10 != 0){
        cout << sum << endl;
        return 0;
    }

    sort(a,a+n);
    for(int i=0; i<n && sum % 10 == 0; i++)
        if(a[i] % 10 != 0) sum -= a[i];

    if(sum % 10 == 0) cout << "0\n";
    else cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
 
#include <iostream>
#include <algorithm>
 
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <cstring>
#include <string>
#include <utility>
#include <array>
#include <complex>
#include <valarray>
 
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
 
 
using namespace std;
#define int long long
 
typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;
 
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
 
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll INFLL = 1LL<<62;
const double EPS = 1e-12;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;
 
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod
#define inside(y, x, h, w) (0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false

int n;
int f[105][5][2], p[105][10];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n) {
        rep(j, 5) {
            rep(k, 2) {
                cin >> f[i][j][k];
            }
        }
    }
    rep(i, n) {
        rep(j, 11) {
            cin >> p[i][j];
        }
    }
    int ans = -INFLL;
    rep2(i, 1, 1<<10) {
        bool used[10] = {};
        rep(j, 10) {
            if (i>>j & 1) {
                used[j] = true;
            }
        }/*
        bool ok = false;
        for (int j = 0; i < 10; j += 1) {
            if (used[j]) {
                ok = true;
                break;
            }
        }
        if (!ok) continue;
        */
        int tmp = 0;
        int cnt[n] = {};
        rep(j, 10) {
            if (!used[j]) continue;
            rep(k, n) {
                if (f[k][j/2][j%2] == 1) cnt[k]++;
            }
        }
        rep(i, n) tmp += p[i][cnt[i]];
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int n, m;
        cin >> n >> m;
        vector<string> fie(n);
        rep(i, 0, n) cin >> fie[i];

        vector<vector<ll> > dp(n, vector<ll>(m));
        if (fie[0][0] == '.') dp[0][0] = 1;

        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if (fie[i][j] == '.') {
                    if (i + 1 < n && fie[i + 1][j] == '.') {
                        dp[i + 1][j] += dp[i][j];
                        dp[i + 1][j] %= MOD;
                    }

                    if (j + 1 < m && fie[i][j + 1] == '.') {
                        dp[i][j + 1] += dp[i][j];
                        dp[i][j + 1] %= MOD;
                    }
                }
            }
        }

        cout << dp[n - 1][m - 1] << endl;


    }
};


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

    Solve().solve();


    return 0;
}


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

int main() {
	string s;
	cin >> s;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='A' && s[i+1]=='C')
		 {
		 	cout << "Yes";
		 	return 0;
		 }
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    ans = {}
    for x in a:
        sbin = bin(x)[2:][::-1]
        for i, c in enumerate(sbin):
            if c != '1':
                continue
            if i in ans:
                ans[i] += 1
            else:
                ans[i] = 1
    for x in ans.values():
        if x % 2 != 0:
            print('No')
            return
    print('Yes')


if __name__ == "__main__":
    main()


Measured memory_bytes: 14116
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var n = cin.ReadInt;
            var m = cin.ReadInt;
            if(n == m) WriteLine("Yes");
            else WriteLine("No");
            // 解答はココに書く

        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll m;cin>>m;
  print(48-m);
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 2e5+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------
map<int,int> mp;

void work(){
    int N;
    scanf("%d",&N);
    LL ans=0;
    for(int i=1;i<=N;i++){
        int a; scanf("%d",&a);
        ans+=mp[i-a];
        mp[i+a]++;
    }
    printf("%lld\n",ans);
}


///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}











Measured memory_bytes: 20824
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int ABCD = sc.nextInt() + sc.nextInt() - sc.nextInt() - sc.nextInt();
		
		if(ABCD == 0) System.out.println("Balanced");
		else System.out.println(ABCD > 0 ? "Left" : "Right");
	}
}

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

struct Point {double x,y;};

void koch(int n, Point a, Point b){
    if(n==0) return;

    Point s,t,u;
    double th=M_PI*60.0/180.0;

    s.x = (2.0*a.x + b.x) / 3.0;
    s.y = (2.0*a.y + b.y) / 3.0;
    t.x = (a.x + 2.0*b.x) / 3.0;
    t.y = (a.y + 2.0*b.y) / 3.0;
    u.x = (t.x-s.x)*cos(th) - (t.y-s.y)*sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y)*cos(th) + s.y;

    koch(n-1, a, s);
    printf("%lf %lf\n", s.x, s.y);
    koch(n-1, s, u);
    printf("%lf %lf\n", u.x, u.y);
    koch(n-1, u, t);
    printf("%lf %lf\n", t.x, t.y);
    koch(n-1, t, b);
 }

 int main(){
     int n;
     scanf("%d", &n);
     Point a,b;
     a.x=0.0; a.y=0.0;b.x=100;b.y=0;
     printf("%lf %lf\n", a.x, a.y);
     koch(n,a,b);
     printf("%lf %lf\n", b.x, b.y);
     return 0;



 }


Measured memory_bytes: 3220
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	string s;
  	cin >> s;
  	rep(i,2) {
		if(s[i+0] == s[i+1] && s[i+1] == s[i+2]){
  			cout << "Yes" << endl;
        	return;
        } 
    }
  	cout << "No" << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


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

int main()
{
  int N, M;
  while (cin >> N >> M) {
    if (N == 0 && M == 0)
      break;

    vector<int> C(M);
    for (int i = 0; i < M; ++i)
      scanf("%d", &C[i]);

    vector<int> X(N);
    for (int i = 0; i < N; ++i)
      scanf("%d", &X[i]);

    const int INF = 1 << 30;
    static int dp[20000+1][256];
    for (int i = 0; i < 20000+1; ++i) {
      for (int j = 0; j < 256; ++j)
	dp[i][j] = INF;
    }
    dp[0][128] = 0;

    for (unsigned int i = 0; i < X.size(); ++i) {
      for (int j = 0; j < 256; ++j) {
	for (unsigned int k = 0; k < C.size(); ++k) {
	  int XX = j+C[k];
	  if (XX < 0)
	    XX = 0;
	  if (XX > 255)
	    XX = 255;
	  dp[i+1][XX] = min(dp[i+1][XX], dp[i][j] + (X[i]-XX)*(X[i]-XX));
	}
      }
    }

    int ans = INF;
    for (int i = 0; i < 256; ++i)
      ans = min(ans, dp[N][i]);

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

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

using namespace std;
const int maxn = 1e5+10;
int n,m,k;
int f[maxn];
int main(){
	cin >> n >>k;
	for(int i=1;i<=k;i++){
		int cnt,t;
		cin >> cnt;
		while(cnt--){
			cin >> t;
			f[t]++;
		}
	}
	int res = 0;
	for(int i=1;i<=n;i++){
		if(!f[i]) res++; 
	}
	cout << res << endl;
	return 0;
} 

Measured memory_bytes: 3612
p = 10**9+7
S = input().strip()
N = len(S)
dp = [[0 for _ in range(13)] for _ in range(N+1)]
for m in range(13):
    dp[0][0] = 1
for i in range(1,N+1):
    for m in range(13):
        if S[i-1]=="?":
            for j in range(10):
                dp[i][(m*10+j)%13] = (dp[i][(m*10+j)%13]+dp[i-1][m])%p
        else:
            dp[i][(m*10+int(S[i-1]))%13] = (dp[i][(m*10+int(S[i-1]))%13]+dp[i-1][m])%p
print(dp[N][5])

Measured memory_bytes: 91508
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    int a,b;
    cin >> a >> b;
    if(a <= 5)cout << 0 << endl;
    else if(a >= 13)cout << b << endl;
    else cout << b/2 << endl;

    

    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc127.contest.atcoder.jp/tasks/abc127_a

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

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
typedef long long ll;

struct UnionFind {
    vector<int> parent;
    int size;

    UnionFind(int n) :parent(n, -1), size(n) {}

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (size_of(x) < size_of(y)) swap(x, y);
        parent[x] += parent[y]; parent[y] = x; size--;
        return true;
    }

    int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }

    bool same(int x, int y) { return root(x) == root(y); }

    int size_of(int x) { return -parent[root(x)]; }
};

signed main(signed argc, char *argv[]) {
    int N;
    cin >> N;
    vector<int> x(N), y(N);
    for(int i = 0; i < N; i++) cin >> x[i] >> y[i];

    vector<pair<pair<int, int>, int>> v(N);
    for(int i = 0; i < N; i++) {
        v[i].first = make_pair(x[i], y[i]);
        v[i].second = i;
    }

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

    UnionFind uf(N);
    for(int i = 1; i < N; i++) {
        if (v[i - 1].first.first == v[i].first.first) {
            uf.unite(v[i - 1].second, v[i].second);
        }
    }

    for(int i = 0; i < N; i++) {
        swap(v[i].first.first, v[i].first.second);
    }

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

    for(int i = 1; i < N; i++) {
        if (v[i - 1].first.first == v[i].first.first) {
            uf.unite(v[i - 1].second, v[i].second);
        }
    }

    vector<vector<int>>u(N);
    for(int i = 0; i < N; i++) {
        u[uf.root(i)].emplace_back(i);
    }

    ll sum = 0;
    for(int i = 0; i < u.size(); i++) {
        set<int>a, b;
        for (auto w : u[i]) {
            a.insert(x[w]);
            b.insert(y[w]);
        }
        sum += a.size() * b.size();
    }
    cout << sum - N << endl;

    return 0;
}

Measured memory_bytes: 9976
import math

def can(X):
    training = 0
    for i in range(N):
        training += max(math.ceil(A[i] - X / F[i]), 0)
    return training <= K

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort(reverse=True)
F.sort()

a = 0
b = max(A) * max(F) * N
c = 0

while (b - a) >= 1:
    c = (a + b) / 2
    if can(c):
        b = c
    else:
        a = c

res = math.floor(c)

if can(res):
    print(res)
else:
    print(res + 1)

Measured memory_bytes: 114104
#pragma GCC optimize ("-O3")
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zer ll(0)

int main()
{
    fast_cin();
    int n,k;
    cin>>n>>k;
    v32 perm(n);
    v32 ind(n);
    v32 dp(n, 1);
    bool flg = 0;
    v32 maxLen(n);
    int out = 1;
    forn(i, n)
    {
    	cin>>perm[i];
    	ind[perm[i]] = i;
    }
    forsn(i, 1, n)
    {
    	if(perm[i] > perm[i-1])
    	{
    		dp[i] = dp[i-1]+1;
    	}
    }

    if(k == n)
    {
    	cout<<1<<'\n';
    	return 0;
    }
    if(dp[k-1] == k)
    {
    	flg = 1;
    }
    priority_queue<int> mxm;
    priority_queue<int, vector<int>, greater<int> > mnm;
    forn(i, k)
    {
    	if(i != k-1)
    	{
    		mnm.push(perm[i]);
    	}
    	mxm.push(perm[i]);
    }
    forsn(i, k, n)
    {
    	while(!mnm.empty() && ind[mnm.top()] < i-k)
    	{
    		mnm.pop();
    	}
    	mnm.push(perm[i-1]);
    	while(!mxm.empty() && ind[mxm.top()] < i-k+1)
    	{
    		mxm.pop();
    	}
    	mxm.push(perm[i]);
    	if(mxm.top() != perm[i] || mnm.top() != perm[i-k])
    	{
 			if(dp[i] == k)
 			{
 				if(flg == 1)
 				{
 					out--;
 				}
 				flg = 1;
 			}
    		out++;
    	}
    }
    cout<<out<<'\n';
    return 0;
}


Measured memory_bytes: 5228