akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define F first
#define S second

#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define int long long
#define ll long long

const int N = 1e2 + 5, K = 1e5 + 5;
int dp[K], n, a[N];

int rec(int k){
	if(dp[k] != -1)
		return dp[k];
	bool flag = false;
	for(int i = 0 ; i < n ; i++){
		if(k - a[i] >= 0)
			flag |= (!rec(k - a[i]));	
	}
	return dp[k] = flag;
}
	
void solve(){
	int k;
	cin >> n >> k;
	for(int i = 0 ; i < n ; i++){
		cin >> a[i]; 			
	}
	memset(dp, -1, sizeof dp); 	
	int res = rec(k);
	if(res)
		cout << "First";
	else
		cout << "Second";
}

signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}

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

int main()
{
    string s;
    stack<char> T;

    cin >> s;
    int cnt = 0;

    for (int i = 0; i < (int)s.length(); i++) {
        if (!T.empty() && T.top() != s[i]) T.pop(), cnt += 2;

        else T.push(s[i]);
    }

    cout << cnt << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pr pair<int,int>
#define endl "\n"
#define MOD 1000000007 // 10^9 + 7
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
#define all(c) (c).begin(), (c).end()

using namespace std;

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

	//freopen("addin.txt","r",stdin);
	//freopen("addout.txt","w",stdout);

	double a,b;
	cin >> a >> b;
	double k = (a/2)+(b/2);
	if(k ==  int(k)) cout<<int(k)<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int,int> pii;
typedef priority_queue<int,vector<int>,greater<int> > small_heap;
typedef priority_queue<int> big_heap;
int n,m;
vector<int>v[60];
ll path[60];
void dfs(int x,int fa,ll num){
    path[x]=num;
    for(auto vv:v[x]){
        if(vv==fa)continue;
        dfs(vv,x,num|(1ll<<vv));
    }
}
ll info[60];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n-1;i++){
        int x,y;scanf("%d%d",&x,&y);
        v[x].push_back(y);v[y].push_back(x);
    }
    dfs(1,0,0ll);
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        int x,y;scanf("%d%d",&x,&y);
        info[i]=(path[x]^path[y]);
    }
    ll maxstate=(1ll<<m)-1;
    ll ans=0ll;
    for(int i=0;i<=maxstate;i++)
    {
        ll num=0ll;
        int cnt=0;
        for(int j=0;j<=m-1;j++)
        {
            if(i&(1<<j))
            {
                cnt++;
                num|=info[j];
            }
        }
        int free=n-1-__builtin_popcountll(num);
        ans+=(1ll<<free) * (cnt & 1 ? -1ll : 1ll);//这边奇为减，是因为直接计算合法的总数，2^ n-1  --
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
MOD = 10 ** 9 + 7
if N == 1:
  print(0)
  exit()
a = pow(10, N, MOD)
b = pow(9, N, MOD)
c = pow(8, N, MOD)
ans = (a - (2 * b) + c) % MOD
if ans < 0:
  ans += MOD
print(ans)

Measured memory_bytes: 8848
n,p = map(int,input().split())
a = list(map(int,list(input())))
ans = 0
if p == 2:
  for i in range(n):
    if a[i]%2==0:
      ans += i+1
elif p == 5:
  for i in range(n):
    if a[i]==5 or a[i]==0:
      ans += i+1
else:
  b = 0
  c = [0 for i in range(p)]
  c[0] = 1
  for i in range(n):
    b = (b+pow(10,n-i,p)*a[i])%p
    c[b] += 1
  c = list(map(lambda x:x*(x-1)//2,c))
  ans = sum(c)
print(ans)

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

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> A(H);
  for(int i=0;i<H;i++){
    string S;
    cin >> S;
    A.at(i)=S;
  }
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++){
      if(A.at(i).at(j)=='#')
        continue;
      int a=0;
      if(i!=0 && j!=0)
        if(A.at(i-1).at(j-1)=='#')
          a++;
      if(i!=0)
        if(A.at(i-1).at(j)=='#')
          a++;
      if(i!=0 && j!=W-1)
        if(A.at(i-1).at(j+1)=='#')
          a++;
      if(j!=W-1)
        if(A.at(i).at(j+1)=='#')
          a++;
      if(j!=W-1 && i!=H-1)
        if(A.at(i+1).at(j+1)=='#')
          a++;
      if(i!=H-1)
        if(A.at(i+1).at(j)=='#')
          a++;
      if(i!=H-1 && j!=0)
        if(A.at(i+1).at(j-1)=='#')
          a++;
      if(j!=0)
        if(A.at(i).at(j-1)=='#')
          a++;
      if(a==0)
        A.at(i).at(j)='0';
      else if(a==1)
        A.at(i).at(j)='1';
      else if(a==2)
        A.at(i).at(j)='2';
      else if(a==3)
        A.at(i).at(j)='3';
      else if(a==4)
        A.at(i).at(j)='4';
      else if(a==5)
        A.at(i).at(j)='5';
      else if(a==6)
        A.at(i).at(j)='6';
      else if(a==7)
        A.at(i).at(j)='7';
      else if(a==8)
        A.at(i).at(j)='8';
    }
  for(int i=0;i<H;i++)
    cout << A.at(i) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int A[100000];
int B[100000];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        {
            cin>>A[i];
            B[i]=A[i];
        }
        
    sort(B+1,B+n+1);//调用头文件<algorithm>里的排序函数


    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(A[i]!=B[i])//统计初始序列和排序好后序列对应位置有多少个不同
            cnt++;
    }

/*
    for(int i=1;i<=n;i++)
        cout<<A[i]<<" ";
    cout<<endl;

    for(int i=1;i<=n;i++)
        cout<<B[i]<<" ";
    cout<<endl;
*/
    if(cnt==2||cnt==0)//如果没有不同或者有两个不同可以通过一次对调来符合要求
        cout<<"YES";
    else
        cout<<"NO";

    return 0;
}

Measured memory_bytes: 256
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
#import io,os; input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #for pypy
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

class DisjSet: 
    def __init__(self,n): 
        self.rank = [1]*n 
        self.parent = [i for i in range(n)] 

    def find(self,x): 
        if self.parent[x] != x:
            self.parent[x] = self.find(self.parent[x]) 
        return self.parent[x]

    def Union(self,x,y):
        xset = self.find(x) 
        yset = self.find(y)
        if xset == yset: return

        if self.rank[xset] < self.rank[yset]: 
            self.parent[xset] = yset 
        elif self.rank[xset] > self.rank[yset]: 
            self.parent[yset] = xset 
        else: 
            self.parent[yset] = xset 
            self.rank[xset] += 1

n,m = ip()
obj = DisjSet(n)
for i in range(m):
    a,b = ip()
    obj.Union(a-1,b-1)
dt = {}
for i in range(n):
    p = obj.find(i)
    dt[p] = dt.get(p,0)+1
print(len(dt.keys())-1)
    


Measured memory_bytes: 88160
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define F(i,n) for(int i=0;i<n;i++)
#define G(i,j,n) for(int i=j;i<n;i++)
int main()
{
ll n,x,t;
cin>> n >>x >>t;
if(n%x ==0)
{
    cout<< t*(n/x);

}
else
{
cout<< t*(n/x +1);
}
return 0;
}


Measured memory_bytes: 3632
n = gets.chomp.to_i
a = gets.chomp.split().map(&:to_i)
b = gets.chomp.split().map(&:to_i)
c = gets.chomp.split().map(&:to_i)

a.sort!
b.sort!
c.sort!

# p a, b, c

ans = 0
b.each do |e|
#  p ['loop', e]
  aa_index = a.bsearch_index{|x| e <= x}
#  p ['aa_i', aa_index]
  aa_index ||= n

  cc_index = c.bsearch_index{|x| e < x}
#  p ['cc_i', cc_index]
  next if cc_index.nil?

#  p [e, ' ', aa_index, n-cc_index]
  ans += aa_index * (n-cc_index)
end

puts ans

Measured memory_bytes: 26704
import sys
from fractions import gcd
from functools import reduce

sys.setrecursionlimit(2147483647)

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def main():
    N = int(input())
    A = list(map(int, input().split()))

    lcm = lcm_list(A)
    S = 0
    for i in range(N):
        S += lcm // A[i]

    print(round(S % (round(1e9) + 7)))

main()


Measured memory_bytes: 6100
import collections
S = input()
N = len(S)
mod = 2019
div = [0]*(N+1)
for i in range(N):
    div[i+1] = (div[i] + int(S[N-1-i])*pow(10,i,mod))%mod
d = collections.Counter(div[1::])
ans = d[0]
for i in d.values():
    ans += i*(i-1)//2
print(ans) 

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

typedef long long int64;

const int MAXN = 3000 + 10;

int n, m, q;
int a[MAXN][MAXN];
int64 f[MAXN][MAXN][4];

#define chkmax(x, y) x = std::max(x, y)

int main() {
// #ifndef ONLINE_JUDGE
//     freopen("e.in", "r", stdin);
//     freopen("e.out", "w", stdout);
// #endif

    int i, j, k;
    int x, y;

    scanf("%d %d %d", &n, &m, &q);
    for (i = 1; i <= q; i++) {
        scanf("%d %d", &x, &y);
        scanf("%d", &a[x][y]);
    }

    for (i = 1; i <= n; i++) {
        for (j = 1; j <= m; j++) {
            for (k = 1; k < 4; k++) {
                chkmax(f[i][j][k], f[i - 1][j][3] + a[i][j]);
                chkmax(f[i][j][k], f[i][j - 1][k - 1] + a[i][j]);
            }
            for (k = 1; k < 4; k++)
                chkmax(f[i][j][k], f[i][j][k - 1]);
            for (k = 0; k < 4; k++)
                chkmax(f[i][j][k], f[i][j - 1][k]);
        }
        for (j = 1; j <= m; j++)
            for (k = 0; k < 4; k++)
                f[i][j][k] = std::max(f[i][j][k], f[i][j - 1][k]);
    }
    printf("%lld\n", f[n][m][3]);
    return 0;
}

Measured memory_bytes: 319168
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
#define ll long long 
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-48,ch=getchar();}
	return x*f;
}

struct Node{
	int x,y,z;
	Node(int a,int b,int c){x=a,y=b,z=c;}
};
queue<Node>q;
char mp[1010][1010];
int dis[1010][1010];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int main(){
	int n=read(),m=read();
	for(int i=1;i<=n;i++){
		scanf("%s",mp[i]+1);
		for(int j=1;j<=m;j++){
			if(mp[i][j]=='#')
				q.push(Node(i,j,0));
		}
	}
	memset(dis,0x3f,sizeof dis);
	int ans=0;
	while(!q.empty()){
		Node u=q.front();q.pop();
		if(dis[u.x][u.y]<=u.z) continue;
		dis[u.x][u.y]=u.z;
		ans=max(ans,u.z);
		for(int i=0;i<4;i++){
			int xx=dx[i]+u.x,yy=dy[i]+u.y;
			if(xx<1||xx>n||yy<1||yy>m||mp[xx][yy]=='#')continue;
			q.push(Node(xx,yy,u.z+1));
		}
	}
	printf("%d\n",ans);
	return 0;
}
  

Measured memory_bytes: 20768
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    int X; cin >> X;
    while (1) {
        for (int A = 2; A <= sqrt(X); ++A) {
            if (X % A == 0) { goto xyz; }
        }
        cout << X << endl;
        break;
    xyz:;
        ++X;
    }

}

Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>

#define FOR(i, a) for(int i=0;i<(int)a;++i)
typedef long long ll;
using namespace std;

void solver() {
    int T;
    cin >> T;
    int h = T / 3600;
    int m = (T - h * 3600) / 60;
    int s = (T - h * 3600 - m * 60);
    cout << h << ":" << m << ":" << s << endl;
}

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

Measured memory_bytes: 3092
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}

	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=5e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}

	const int N=1e6+10;
	//------------------FIXED------------------
	bool okW[N],okS[N];
	void main()
	{
		int A=qread(),B=qread(),C=qread(),D=qread(),E=qread(),F=qread();
		fo(i,0,30) fo(j,0,30) okW[i*A+j*B]=1;fo(i,0,3000) fo(j,0,3000) okS[i*C+j*D]=1;
		pair<db,pii> ans={0,{0,0}};
		fo(s,0,3000) fo(w,0,30) if(s+w*100<=F and s<=w*E and okS[s] and okW[w] and s+w>0) chmax(ans,{ 1.0*s/(s+100*w),{s,w} });
		write1(ans.SE.FR+ans.SE.SE*100),write(ans.SE.FR);
 	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s\n",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 384
N,T = list(map(int, input().split()))
A = list(map(int, input().split()))

prof = 0
_min = A[0]
setA = set()
answer = 0

for a in A:
  setA.add(a)
  if a > prof+_min:
    prof = a-_min
    answer = 1
    continue
  if _min < a <= prof+_min:
    if a-prof in setA:
      answer +=1    
    continue
  if a<_min:
    _min = a
    continue
    
print(answer)

Measured memory_bytes: 14484
import bisect


def solve(mid):
    cnt = 0
    l = n
    r = n
    for i in range(n):
        while True:
            if l == 0:
                break
            if a[l - 1] < mid - a[i]:
                break
            l -= 1
        cnt += (r - l)
    return cnt >= m
    

n, m = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)

ok = 0
ng = 10 ** 18
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid

ru = [0] * (n + 1)
for i in range(n):
    ru[i + 1] = ru[i] + a[i]

ans = 0
r = n
ok = ok + 1
cnt = 0
for i in range(n):
    l = bisect.bisect_left(a, ok - a[i])
    cnt += (r - l)
    ans += (r - l) * a[i] + (ru[r] - ru[l])
ans += (ok - 1) * (m - cnt)
print(ans)


Measured memory_bytes: 56332
#include<bits/stdc++.h>
using namespace std;
int dp[100006];
int arr[100006];
int k;
int fun(int n ){
	
  if(n==1) return 0;
  if(dp[n]!=-1)return dp[n];
  int ans = INT_MAX;
  for(int i =1;i<=k;i++){
      if(n-i >=1){
        ans= min(ans,abs(arr[n]-arr[n-i])+fun(n-i));
      }else break;
  }
  return dp[n]=ans;
  
  
//   if(n>=3)dp[n]=min(abs(arr[n]-arr[n-2])+fun(n-2),abs(arr[n]-arr[n-1])+fun(n-1));
//   else dp[n]=abs(arr[n]-arr[n-1])+fun(n-1);
//   return dp[n];
}


int main(){
int n ;
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>arr[i],dp[i]=-1;
cout<<fun(n)<<endl;
return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
int main(){
    int k;

    cin >> k;

    int arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << arr[k-1];
}

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


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    string s;
    cin >> s;

    string x = "CODEFESTIVAL2016";

    int ans = 0;
    rep(i, 16) {
        if(s[i] != x[i]) {
            ans++;
        }
    }

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Y = sc.nextInt();
        int res10000 = -1, res5000 = -1, res1000 = -1;
        for(int i = 0; i <= N; i++) {
            for(int j = 0; j + i <= N; j++) {
                int k = N - i - j;
                int total = 10000*i + 5000*j + 1000*k;
                if(total == Y) {
                    res10000 = i;
                    res5000 = j;
                    res1000 = k;
                }
            }
        }
        System.out.println(res10000 + " " + res5000 + " " + res1000);
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

typedef long long ll;
ll n, m, x = 1, a[N];

ll gcd(ll p, ll q) {
	if (q == 0) return p;
	return gcd(q, p % q);
}

int main()
{
	ll i, t;
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
		a[i] /= 2;
		x *= a[i] / gcd(x, a[i]);
	}
    for (i = 0; i < n; i++) {
		if (x / a[i] % 2 == 0) {puts("0"); return 0;}
    }
    t = m / x;
    t = (t + 1) / 2;
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.awt.Point;
import java.io.*;
import java.nio.Buffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeSet;

import javax.swing.event.TreeSelectionEvent;
import javax.swing.plaf.basic.BasicTreeUI.TreeCancelEditingAction;

import org.omg.PortableInterceptor.INACTIVE;
public class Main {


public static void D(BufferedReader br)throws Exception
{
	String in = br.readLine();
	StringTokenizer st=new StringTokenizer(in);
	int n=Integer.parseInt(st.nextToken());
	int W=Integer.parseInt(st.nextToken());
	long[][]ks=new long [n+1][W+1];
	int[]items=new int[n+1];
	int[]weights=new int[n+1];
	int sw=0;
	long sv=0;
	for(int i=1;i<n+1;i++)
	{
		in=br.readLine();
		st=new StringTokenizer(in);
		weights[i]=Integer.parseInt(st.nextToken());
		items[i]=Integer.parseInt(st.nextToken());
		sw+=weights[i];
		sv+=items[i];
				
	}
	if(sw<=W)
	{
		System.out.println(sv);
		return;
	}
	
	for(int i=1;i<n+1;i++)
	{
		for(int w=1;w<W+1;w++)
		{
			long not=ks[i-1][w];
			long take=0;
			if(weights[i]<=w)
			{
				take=items[i]+ks[i-1][w-weights[i]];
			}
			ks[i][w]=Math.max(not, take);
		}
	}
	System.out.println(ks[n][W]);
}
public static void main(String[]args) throws Exception
{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	D(br);

	
}
	
}


Measured memory_bytes: 126292
// Code by ajcxsu
// Problem: fft

#include<bits/stdc++.h>
#define MOD (998244353)
using namespace std;

template<typename T> inline void gn(T &x) {
    char ch=getchar(), pl=0; x=0;
    while(!isdigit(ch)) pl=(ch=='-'), ch=getchar();
    while(isdigit(ch)) x=x*10+ch-'0', ch=getchar(); x*=pl?-1:1;
}

int qpow(int x, int y) {
    int ret=1;
    while(y) {
        if(y&1) ret=1ll*ret*x%MOD;
        x=1ll*x*x%MOD, y>>=1;
    }
    return ret;
}

const int N=2e6+10;
int fac[N], finv[N];
int C(int x, int y) { return 1ll*fac[x]*finv[y]%MOD*finv[x-y]%MOD; }

int main() {
    finv[0]=fac[0]=fac[1]=finv[1]=1;
    for(int i=2; i<N; i++) finv[i]=MOD-1ll*MOD/i*finv[MOD%i]%MOD, fac[i]=1ll*i*fac[i-1]%MOD;
    for(int i=2; i<N; i++) finv[i]=1ll*finv[i]*finv[i-1]%MOD;
    int n, m;
    gn(n), gn(m);
    if(n<m) swap(n, m);
    int ans=0;
    for(int i=1; i<=m; i++) ans=(ans+1ll*C(2*i, i)*C(n+m-2*i, n-i))%MOD;
    ans=1ll*ans*qpow(C(n+m, m)*2, MOD-2)%MOD;
    (ans+=n)%=MOD;
    // printf("%d\n", (n+m-ans+MOD)%MOD);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 16000
# -*- coding: utf-8 -*-

H,W,K = map(int, input().split())
x1,y1,x2,y2 = map(int, input().split())

C = [input() for _ in range(H)]
T = [[-1 for _ in range(W)] for _ in range(H)]
T[x1-1][y1-1] = 0

que = {(x1-1,y1-1):0}
step = 1

while len(que)>0:
  que_next = {}
  for q in que.keys():
    x,y = q[0],q[1]
    for i in range(1,K+1):
      if x-i<0:
        break
      if C[x-i][y]=='@' or T[x-i][y]==1:
        break
      if x-i==x2-1 and y==y2-1:
        print(step)
        exit()
      que_next[(x-i,y)] = 0
    for i in range(1,K+1):
      if x+i>H-1:
        break
      if C[x+i][y]=='@' or T[x+i][y]==1:
        break
      if x+i==x2-1 and y==y2-1:
        print(step)
        exit()
      que_next[(x+i,y)] = 0
    for i in range(1,K+1):
      if y-i<0:
        break
      if C[x][y-i]=='@' or T[x][y-i]==1:
        break
      if x==x2-1 and y-i==y2-1:
        print(step)
        exit()
      que_next[(x,y-i)] = 0
    for i in range(1,K+1):
      if y+i>W-1:
        break
      if C[x][y+i]=='@' or T[x][y+i]==1:
        break
      if x==x2-1 and y+i==y2-1:
        print(step)
        exit()
      que_next[(x,y+i)] = 0
  que = que_next
  for q in que.keys():
    T[q[0]][q[1]] = 1
  step += 1

print(-1)

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

int main(){
	int a,b;
	cin >> a >> b;
	if ((a>b && b!=1)|| (a==1 && b>a)){
		cout << "Alice" << endl;
	}else if (a==b){
		cout << "Draw" << endl;
	}else{
		cout << "Bob" << endl;
	}
}

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll,ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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


int main() {
    int N, M, X, ans = MOD;
    cin >> N >> M >> X;
    int C[15];
    int A[15][15];
    rep(i, N) {
        cin >> C[i];
        rep(j, M) {
            cin >> A[i][j];
        }
    } 

    //R個の全探索(2^R通り)
    for (int bit = 0; bit < (1 << N); bit++) {
        int coin = 0;
        int Asum[15] = {0};
        for (int i = 0; i < N; i++) {
            //i番目のビットが立っていた時の処理
            if (bit & (1<<i)) {
                coin += C[i];
                rep(j, M) {
                    Asum[j] += A[i][j];
                }     
            }
        }

        bool flag = true;
        rep(i, M){
            if(Asum[i] < X) {
                flag = false;
                break;
            }
        }

        if(flag) {
            ans = min(ans, coin);
        }
    }
    if(ans == MOD) ans = -1;

    //string ans = ( flag ? "Yes" : "No" );
    //printf("%.8lf", ans);
    cout << ans;
    cout << "\n";
    return 0;
}


Measured memory_bytes: 3600
#import math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
mod=10**9+7
def factorial(x): #階乗計算
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): #約数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): #素因数分解配列
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト
    s=list(input())
    ans=0
    n=len(s)
    for i in range(n-1):
        if s[i]!=s[i+1]:
            ans+=1
    print(ans)
main()

Measured memory_bytes: 49520
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

void chmax(ll &x, ll y) {
    if (x < y) x = y;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int R, C, K;
    cin >> R >> C >> K;

    vector<vll> v(R + 1, vll(C + 1, 0));
    REP(i, K) {
        int r, c; ll vv;
        cin >> r >> c >> vv;
        --r; --c;
        v[r][c] = vv;
    }

    vector<vector<vll>> dp(R + 1, vector<vll>(C + 1, vll(4, 0)));

    REP(i, R) REP(j, C) {
        REP(k, 4) {
            chmax(dp[i + 1][j][k], dp[i][j][k]);
            chmax(dp[i][j + 1][k], dp[i][j][k]);
        }
        if (v[i][j] > 0) {
            REP(k, 3) {
                chmax(dp[i][j + 1][k + 1], dp[i][j][k] + v[i][j]);
            }

            REP(k, 3) {
                chmax(dp[i + 1][j][0], dp[i][j][k] + v[i][j]);
            }
        }
    }

    REP(i, 4) {
        chmax(dp[R][C][i], dp[R-1][C][i]);
        chmax(dp[R][C][i], dp[R][C-1][i]);
    }

    print(*max_element(ALL(dp[R][C])));

}


Measured memory_bytes: 707192
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <string>
#include <functional>
#include <math.h>
#include <utility>
#define INF 1001001001
using namespace std;
typedef pair<int,int> P;
int N,K;
struct Taxi{
	int C,R,ans;
	vector<int> ed1,ed2;
	bool flag;
	Taxi():flag(false),ans(INF){}
}taxi[5010];
int main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++){
		cin>>taxi[i].C>>taxi[i].R;
	}
	for(int i=0;i<K;i++){
		int a,b;cin>>a>>b;a--;b--;
		taxi[a].ed1.push_back(b);
		taxi[b].ed1.push_back(a);
	}
	for(int i=0;i<N;i++){
		queue<int> que;
		que.push(i);
		for(int k=0;k<taxi[i].R;k++){
			queue<int> que2;
			while(!que.empty()){	
				int X=que.front();que.pop();
				for(int j=0;j<(int)taxi[X].ed1.size();j++){
					int to=taxi[X].ed1[j];
					if(!taxi[to].flag){
						taxi[to].flag=true;
						que2.push(to);
					}
				}
			}
			que=que2;
		}
		for(int k=0;k<N;k++){ 
			if(taxi[k].flag&&i!=k)taxi[i].ed2.push_back(k);
			taxi[k].flag=false;
		}
		
	}

	priority_queue<P,vector<P>,greater<P> > pque;
	pque.push(make_pair(0,0));
	while(pque.size()){
		P tmp=pque.top();pque.pop();
		int cost=tmp.first;
		int t=tmp.second;
		if(taxi[t].ans<=cost)continue;
		taxi[t].ans=cost;
		if(t==N-1)break;
		for(vector<int>::iterator it=taxi[t].ed2.begin();it!=taxi[t].ed2.end();it++){
			int to=*it;
			if(taxi[to].ans==INF)pque.push(make_pair(cost+taxi[t].C,to));
		}
	}
	cout<<taxi[N-1].ans<<endl;
	return 0;
}

Measured memory_bytes: 134548
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
// template<class T> T gabs(const T& x) { return max(x, -x); }
// #define abs gabs

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
    return 0;
}

Measured memory_bytes: 888
//package atcoder.beginner_171;

import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    public static void main (String[] args) throws Exception {

        String s = "27";

//        br = new BufferedReader(new StringReader(s));
        br = new BufferedReader(new InputStreamReader(System.in));
        bw = new BufferedWriter(new OutputStreamWriter(System.out));

        rl(); long N=nlo();

        StringBuffer sb=new StringBuffer();
        while (N>26) {
            char c=(char)(N%26);
            if (c>0) {
                c+=96;
                N/=26;
            } else {
                c='z';
                N=(N-26)/26;
            }
            sb.insert(0, c);
        }

        char c=(char)(N%26);
        if (c>0) c+=96; else c='z';
        sb.insert(0, c);

        bw.write(sb.toString());
        bw.newLine();
        bw.flush();

    }

    static BufferedReader br;
    static BufferedWriter bw;
    static StringTokenizer st;
    static void rl() throws Exception{
        st = new StringTokenizer(br.readLine());
    }
    static long nlo(){
        return Long.parseLong(st.nextToken());
    }
    static int nin(){
        return Integer.parseInt(st.nextToken());
    }
    /*private static void te(){
      }*/
    static double ndo(){
        return Double.parseDouble(st.nextToken());
    }
    static char[] nca(){
        return st.nextToken().toCharArray();
    }
    static String nstr(){
        return st.nextToken();
    }
}

Measured memory_bytes: 32560
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()

C = Counter()
for _ in range(N):
    l = LIST()
    l = l[1:]
    for a in l:
        C[a] += 1

cnt = 0
for v in C.values():
    if v == N:
        cnt += 1
print(cnt)


Measured memory_bytes: 5788
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i,0,n)
#define BFOR(bit,a,b) for(int bit = (a); bit < (1<<(b)); ++bit)
#define BREP(bit,n) BFOR(bit,0,n)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  if(n < 1200) cout << "ABC" << endl;
  else if(n < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;

}

Measured memory_bytes: 3588
# coding=utf-8
# Date: 2020-04-07 00:38

import sys
sys.setrecursionlimit(10**6)

get = lambda: int(raw_input().strip())
getl = lambda: raw_input().strip()
gets = lambda: map(int, raw_input().strip().split())
getss = lambda n: [gets() for _ in xrange(n)]

n = get()
G = [[] for i in xrange(n + 1)]
for i in xrange(n - 1):
    i, j = gets()
    G[i].append(j)
    G[j].append(i)
mod = 10**9 + 7


def dfs(i, pre=0):
    black, white = 1, 1
    for j in G[i]:
        if j == pre: continue
        b, w = dfs(j, i)
        black = black * w % mod
        white = white * (b + w) % mod
    return [black, white]
print sum(dfs(1)) % mod


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

signed main(){

  int64_t n;
  cin>>n;

  auto digit_sum = [](int64_t n){
    int res = 0;
    while(n){
      res+=n%10;
      n/=10;
    }
    return res;
  };

  int dig = to_string(n).size()-1;
  int64_t tmp = to_string(n)[0]-'0'-1;
  for(int i=0;i<dig;++i)tmp = tmp*10+9;
  int ans = max(digit_sum(n),digit_sum(tmp));
  cout<<(ans)<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200001],n;
int check(int mid)
{
	int i,s=0,tmp,cnt=0;
	for(i=1;i<=n;i++)
	{
		tmp=a[i]-cnt-1;
		if(tmp==0)
			cnt++;
		else
			s++;
	}
//	printf("%d %d\n",mid,s);
	return s<=mid;
}
int main()
{
	int ld,rd,mid,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	ld=0;
	rd=n-1;
	while(ld<rd)
	{
		mid=(ld+rd)/2;
		if(check(mid))
		{
			rd=mid;
//			printf("%d\n",mid);
		}
		else
			ld=mid+1;
	}
	if(!check(rd))
		rd=-1;
	printf("%d",rd);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int n,m;
int a[100001];
bool cmp(pii x,pii y){
    return x.se>y.se;
}
pii ones[100001];
int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(int i=0;i<m;i++)
        cin>>ones[i].fi>>ones[i].se;
    sort(a,a+n);
    sort(ones,ones+m,cmp);
    int now=0,cnt=0,pos=0;
    while(now<n && pos<n){
        cnt=ones[now].fi;
        while(cnt-- && a[pos]<ones[now].se)
            a[pos++]=ones[now].se;
        now++;
    }
    ll ans=0;
    for(int i=0;i<n;i++)
        ans+=a[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1408
n, x, y = input().split(" ")
n, x, y = int(n), int(x), int(y)
ans = [0] * (n - 1)

for i in range(n - 1):
    for j in range(i + 1, n):
        now = 0
        if (j <= x - 1):
            ans[j - i - 1] += 1

        elif(j > x - 1 and j <= y - 1 and i <= x - 1):
            now = now + x - 1 - i
            if (j - (x - 1) >= (y - 1) - j + 1):
                now = now + (y - 1) - j + 1
            else:
                now = now + j - (x - 1)
            ans[now - 1] += 1

        elif(j > x - 1 and j <= y - 1 and i > x - 1):
            if (j - i >= (i - (x - 1)) + ((y - 1) - j) + 1):
                now = (i - (x - 1)) + ((y - 1) - j) + 1
            else:
                now = j - i
            ans[now - 1] += 1

        elif(j > y - 1 and i <= x - 1):
            now = now + x - 1 - i
            now = now + j - (y - 1) + 1
            ans[now - 1] += 1

        elif(j > y - 1 and i > x - 1 and i < y - 1):
            if((y - 1) - i >= i - (x - 1) + 1):
                now = now + i - (x - 1) + 1
            else:
                now = now + (y - 1) - i
            now = now + j - (y - 1)
            ans[now - 1] += 1

        elif(i >= y - 1):
            ans[j - i - 1] += 1
print(*ans)

Measured memory_bytes: 46812
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

#define MAX_M 2048
#define MAX_N 2048

int dp[MAX_M][MAX_N][2];

int main()
{
    int M, N;
    char ch;
    cin >> M >> N;
    vector<int> S(M), T(N);
    for (int i = 0; i < M; i++) {
        cin >> ch;
        S[i] = (ch == 'I' ? 1 : 0);
    }
    for (int i = 0; i < N; i++) {
        cin >> ch;
        T[i] = (ch == 'I' ? 1 : 0);
    }
    
    memset(dp, -1, sizeof(dp));
    
    for (int i = 0; i < M; i++) {
        if (S[i] == 1) {
            for (int j = 0; j < N; j++) {
                dp[i+1][j][1] = 1;
            }
        }
    }
    
    for (int i = 0; i < N; i++) {
        if (T[i] == 1) {
            for (int j = 0; j < M; j++) {
                dp[j][i+1][1] = 1;
            }
        }
    }
    
    for (int i = 0; i <= M; i++) {
        for (int j = 0; j <= N; j++) {
            for (int k = 0; k < 2; k++) {
                if (dp[i][j][k] == -1) continue;
                if (S[i] == 1-k) {                    
                    dp[i+1][j][1-k] = max(dp[i+1][j][1-k],
                                          dp[i][j][k] + 1);
                }
                if (T[j] == 1-k) {
                    dp[i][j+1][1-k] = max(dp[i][j+1][1-k],
                                          dp[i][j][k] + 1);
                }                
            }
        }
    }
    
    int res = 0;
    for (int i = 0; i <= M; i++) {
        for (int j = 0; j <= N; j++) {
            res = max(res, dp[i][j][1]);   
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 33988
#include <bits/stdc++.h>
#define ms(x, a) memset(x, a, sizeof(x))
#define oo 100000000
#define ll long long int
#define MOD 1000000007
using namespace std;
int main()
{
    ll h,a;
    cin>>h>>a;
    ll i=0;
    while(h>0){h-=a;i++;}
    cout<<i;

    return 0;
}



Measured memory_bytes: 256
s = int(input())
a = [s]

def make_a(i):
    if a[i-1] % 2 == 0:
        ai = a[i-1] // 2
        if ai in a:
            print(i + 1)
            exit()
        else:
            a.append(ai)
    else:
        ai = 3 * a[i-1] + 1
        if ai in a:
            print(i + 1)
            exit()
        else:
            a.append(ai)
    return make_a(i+1)

make_a(1)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a>b){//bをa回
    for(int i=0;i<a;i++){
      cout<<b;
    }cout<<endl;
  }
  else //aをb回
    for(int i=0;i<b;i++){
      cout<<a;
    }cout<<endl;
}

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

int main() {
  int N;
  cin >> N;
  if (N/10%111 == 0) {
    cout << "Yes" << endl;
  }
  else if (N%1000%111 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
    


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

// const int M = 9;
int n, m, q;
vector<int> a, b, c, d;
int cnt = 0;
int ma = -1;

void dfs(vector<int> &A)
{
    // 終端条件 n まで
    if (A.size() == n)
    {
        for (int i = 0;i < q; i++)
        {
            if (A[b[i] - 1] - A[a[i] - 1] == c[i]) {
                cnt += d[i];
            }
        }
        ma = max(cnt, ma);
        cnt = 0;
        return;
    }

    int prev_last = (A.empty() ? 1 : A.back());
    for (int v = prev_last; v <= m; v++)
    {
        A.push_back(v);
        dfs(A);
        A.pop_back();
    }
}

int main()
{
    cin >> n >> m >> q;
    for (int i = 0; i < q; i++)
    {
        int x, y, z, w;
        cin >> x >> y >> z >> w;
        a.push_back(x);
        b.push_back(y);
        c.push_back(z);
        d.push_back(w);
    }
    vector<int> A;
    dfs(A);
    cout << ma << endl;
}

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

const int MAX = 11000000;
bool isin[MAX];
int main() {
  int n; cin >> n;
  vector<int> d(n); for (int i = 0; i < n; ++i) cin >> d[i];
  for (int i = 0; i < n; ++i) {
	int tmp = 0;
	for (int j = i; j < n; ++j) {
	  tmp *= 10;
	  tmp += d[j];
	  if (tmp >= MAX) break;
	  isin[tmp] = true;
	}
  }
  int res = 0;
  for (int i = 0; i < MAX; ++i) if (!isin[i]) {
	  res = i;
	  break;
	}
  cout << res << endl;
}



Measured memory_bytes: 7284
import itertools
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]
A_itr = itertools.combinations_with_replacement(range(1, M+1), N)
max_score = 0
for A in A_itr:
    score = 0
    for j_abcd in abcd:
        if A[j_abcd[1]-1]-A[j_abcd[0]-1] == j_abcd[2]:
            score += j_abcd[3]
    max_score = max(max_score, score)
print(max_score)

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

template <typename T, T (*op)(T, T), T (*ie)()> class SegmentTree {
private:
  int N, size, log;
  vector<T> D;
  void apply(int k) { D.at(k) = op(D.at(2 * k), D.at(2 * k + 1)); }
  int ceil_pow(int n) {
    int x = 0;
    while ((1U << x) < (unsigned int)(n)) x++;
    return x;
  }

public:
  SegmentTree() : SegmentTree(0) {}
  SegmentTree(int n) : SegmentTree(vector<T>(n, ie())) {}
  SegmentTree(const vector<T> &v) : N((int)v.size()) {
    log = ceil_pow(N);
    size = 1 << log;
    D = vector<T>(2 * size, ie());
    for (int i = 0; i < N; i++) D.at(size + i) = v.at(i);
    for (int i = size - 1; i >= 1; i--) apply(i);
  }
  void set(int p, T x) {
    p += size;
    D.at(p) = x;
    for (int i = 1; i <= log; i++) apply(p >> i);
  }
  T get(int p) { return D.at(p + size); }
  T query(int l, int r) {
    r++;
    T sml = ie(), smr = ie();
    l += size, r += size;
    while (l < r) {
      if (l & 1) sml = op(sml, D.at(l++));
      if (r & 1) smr = op(D.at(--r), smr);
      l >>= 1, r >>= 1;
    }
    return op(sml, smr);
  }
  T query_all() { return D.at(1); }
  template <bool (*f)(T)> int max_right(int l) {
    return max_right(l, [](T x) { return f(x); });
  }
  template <class F> int max_right(int l, F f) {
    if (l == N) return N;
    l += size;
    T sm = ie();
    do {
      while (l % 2 == 0) l >>= 1;
      if (!f(op(sm, D.at(l)))) {
        while (l < size) {
          l = (2 * l);
          if (f(op(sm, D.at(l)))) sm = op(sm, D.at(l++));
        }
        return l - size;
      }
      sm = op(sm, D.at(l++));
    } while ((l & -l) != l);
    return N;
  }
  template <bool (*f)(T)> int min_left(int r) {
    return min_left(r, [](T x) { return f(x); });
  }
  template <class F> int min_left(int r, F f) {
    if (r == 0) return 0;
    r += size;
    T sm = ie();
    do {
      r--;
      while (r > 1 && (r % 2)) r >>= 1;
      if (!f(op(D.at(r), sm))) {
        while (r < size) {
          r = (2 * r + 1);
          if (f(op(D.at(r), sm))) sm = op(D.at(r--), sm);
        }
        return r + 1 - size;
      }
      sm = op(D.at(r), sm);
    } while ((r & -r) != r);
    return 0;
  }
};

using mono = int;
mono op(mono a, mono b) { return max(a, b); };
mono ie() { return 0; };

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  int MX = 3e5;
  SegmentTree<mono, op, ie> ST(MX + 1);
  for (int i = 0; i < N; i++) {
    int l = max(0, A.at(i) - K);
    int r = min(MX, A.at(i) + K);
    ST.set(A.at(i), ST.query(l, r) + 1);
  }
  cout << ST.query_all() << "\n";
}

Measured memory_bytes: 9800
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int a, b;
	cin >> a >> b;
	int ans = a + b;
	if (ans >= 24)ans -= 24;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int n,i,a[200000],b[200000],l,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
	    scanf("%d",&a[i]);
	}
	l=0;
	for(i=n-1;i>=0;i-=2){
	    b[l]=a[i];
		l++;
	}
	if(n%2==0){
		for(i=0;i<n;i+=2){
			b[l]=a[i];
			l++;
		}
	}
	else if(n%2!=0){
		for(i=1;i<n;i+=2){
			b[l]=a[i];
			l++;
		}
	}
	for(i=0;i<n;i++){
	    if(i==n-1) printf("%d\n",b[i]);
		else printf("%d ",b[i]);
	}
	return 0;
}

Measured memory_bytes: 3712
def resolve():
    import sys
    import numpy as np

    read = sys.stdin.read
    readline = sys.stdin.readline

    N, K = map(int, readline().split())
    h = np.array(read().split(), np.int32)

    # 貰うDP
    inf = 10 ** 9
    dp = np.full(N, inf, np.int64)
    dp[0] = 0


    for i, e in enumerate(h[1:], 1):
        lb = max(0, i - K)
        dp[i] = np.min(dp[lb:i] + np.abs(h[lb:i] - e))

    print(dp[-1])

    
resolve()


Measured memory_bytes: 37684