akhauriyash/Code-Regression huggingface dataset:
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include<ext/rope>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> P;
#define X real()
#define Y imag()
ld restant(P p){return abs(p);}
//polar(x,y) mag=l,arg=y
//typedef unordered_set<ll> usll;
//typedef unordered_multiset<ll> umsll;
typedef multiset<ll> msll;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll> > vpll;
typedef priority_queue<ll> pqll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
//typedef unordered_multiset<int> umsi;
//typedef unordered_set<int> usi;
typedef pair<int,int> pi;
typedef vector<pair<int,int> > vpi;
typedef vector<pair<double,double> > vpd;
typedef pair<double,double> pd;
typedef priority_queue<int> pqi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ind_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ind_setll;
#define in insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define be begin
#define en end
#define itr iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mo 1000000007
#define inf 1000000000000000001
#define ninf -1000000000000000001
#define ima INT_MAX
#define imi INT_MIN
#define oncnt __builtin_popcount
#define zerobegin __builtin_clz
#define zeroend __builtin_ctz
#define parity __builtin_parity
#define all(x) x.be(),x.en()
#define eps 1e-9
const ld pii=3.14159265359;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return((a-b+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}


int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{	
int n;
cin>>n;
int d;
cin>>d;
si s;
for(int i=0;i<d;i++)
{
	int x;
	cin>>x;
	s.insert(x);
}

while(true)
{
	bool f=true;
	int k=n;
	while(k)
	{int r=k%10;
	if(s.find(r)!=s.end())
	{
		f=false;
		break;
	}
		k=k/10;
	}
	if(f)
	{
		cout<<n;
		break;
	}
	n++;
}

}return 0;}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))

class SegmentTree:
    def __init__(self,data,op,default):
        N = len(data)
        self.N = N
        self.op = op
        self.default = default
        self.l = 2**((N-1).bit_length())
        self.data = [default]*self.l + data + [default]*(self.l-N)
        for i in range(self.l-1,0,-1):
            self.data[i] = op(self.data[2*i], self.data[2*i+1])

    def get_data(self):
        return self.data[self.l:self.l + self.N]

    def set(self,i,val):
        i += self.l
        self.data[i] = val
        i = i//2
        while i > 0:
            self.data[i] = self.op(self.data[2*i], self.data[2*i+1])
            i = i//2

    def get(self,i,j):
        i += self.l
        j += self.l
        s = self.default 
        while j-i > 0:
            if i & 1:
                s = self.op(s,self.data[i])
                i += 1
            if j & 1:
                s = self.op(s,self.data[j-1])
                j -= 1
            i = i//2
            j = j//2
        return s

AI = [(a,i) for i,a in enumerate(A)]

inf = 10**10
seg = SegmentTree(AI,min,(inf,inf))

cand = [(0,N)]

ans = 0
while cand:
    temp = []
    for l,r in cand:
        m, i = seg.get(l,r)
        ans += m * (i-l+1) * (r-i)
        if l < i:
            temp.append([l,i])
        if i+1 < r:
            temp.append([i+1,r])
    cand = temp

print(ans)




Measured memory_bytes: 122416
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

lli n;

int main(void){
    cin >> n;
    lli v = n%10;
    if(v == 2 || v == 4 || v == 5 || v == 7 || v == 9) cout << "hon" << endl;
    else if(v == 0 || v == 1 || v == 6 || v == 8) cout << "pon" << endl;
    else if(v == 3) cout << "bon" << endl; 
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i,n) repi(i,0,n)
 
string S;
int dp[2222][2222];
int trans[2222][2222];

int rec(int L, int R) {
  int& ret = dp[L][R];
  if(ret + 1) return ret;
  int& recons = trans[L][R];
  if(L > R) return ret = 0;
  if(S[L] == S[R]) {
    recons = 0;
    return ret = rec(L + 1, R - 1) + (L == R ? 1 : 2);
  }
 
  int r1 = rec(L + 1, R);
  int r2 = rec(L, R - 1);
 
  if(r1 > r2) {
    recons = 1;
    return ret = r1;
  }
  else {
    recons = 2;
    return ret = r2;
  }
 
}
 
int main() {
  while(cin >> S) {
 
    for(int i=0; i<2222; i++)
      for(int j=0; j<2222; j++)
        dp[i][j] = trans[i][j] = -1;
 
    int N = S.size();
    rec(0, N);
    int L = 0, R = N;
    string res;
    while(L < R) {
      if(trans[L][R] == 0) res += S[L], L ++, R --;
      if(trans[L][R] == 1) L ++;
      if(trans[L][R] == 2) R --;
    }
    cout << res;
    if(L == R) cout << S[L];
    reverse(res.begin(), res.end());
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 41720
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>

using namespace std;

int main() {
  int sx, sy, tx, ty, dx, dy;
  cin>>sx>>sy>>tx>>ty;
  dx = tx - sx;
  dy = ty - sy;

  for(int i = 1; i <= dy; i++) putchar('U');
  for(int i = 1; i <= dx; i++) putchar('R');
  for(int i = 1; i <= dy; i++) putchar('D');
  for(int i = 1; i <= dx; i++) putchar('L');

  putchar('L');
  for(int i = 1; i <= dy+1; i++) putchar('U');
  for(int i = 1; i <= dx+1; i++) putchar('R');
  putchar('D');
  putchar('R');
  for(int i = 1; i <= dy+1; i++) putchar('D');
  for(int i = 1; i <= dx+1; i++) putchar('L');
  putchar('U');
  puts("");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
inline int read(){
	int n=0,f=1;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if (c=='-') c=getchar(),f=-1;
	for(;c>='0'&&c<='9';c=getchar()) n=n*10+c-48;
	return n*f;
}
const int maxn=1e6+5;
int k[maxn],ne[maxn],g[maxn],num;
int f[maxn],i,n,ro1,ro2,x[maxn];
int q[maxn],cnt;
bool bz[maxn],bk[maxn];
void add(int x,int y){
	ne[++num]=k[x],k[x]=num,g[num]=y;
	ne[++num]=k[y],k[y]=num,g[num]=x;
}
void dfs(int x){
	for(int i=k[x];i;i=k[x]){
		k[x]=ne[i];
		if (bk[i]) continue;
		bk[i^1]=1,dfs(g[i]);
	}q[++cnt]=x;
}
int main(){
	n=read();
	num=1;
	fo(i,1,n) {
		f[i]=read();
		if (f[i]!=-1) add(f[i],i),bz[f[i]]^=1,bz[i]^=1;
		else bz[ro1=i]^=1;
	}
	fo(i,1,n) {
		f[n+i]=read();
		if (f[n+i]!=-1) f[n+i]+=n,add(f[n+i],n+i),bz[f[n+i]]^=1,bz[n+i]^=1;
		else bz[ro2=n+i]^=1;
	}
	fo(i,1,n) if (bz[i]^bz[n+i]) return puts("IMPOSSIBLE"),0;
	puts("POSSIBLE");
	fo(i,1,n) if (bz[i]) add(i,i+n);
	int ro=n<<1|1; 
	add(ro,ro1),add(ro,ro2);
	dfs(ro);
	fo(i,1,cnt-1)if (q[i]-q[i+1]==n) x[q[i+1]]=-1;
	fo(i,1,n) {
		if (!x[i]&&bz[i]) x[i]=1;
		printf("%d ",x[i]);
	}
}

Measured memory_bytes: 31232
from fractions import gcd

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

if n == 1:
	if a[0] == k:
		print("POSSIBLE")
	else:
		print("IMPOSSIBLE")
else:
	if k in a:
		print("POSSIBLE")
	elif k > max(a):
		print("IMPOSSIBLE")
	else:
		g = gcd(a[0], a[1])
		for i in range(2, n):
			g = gcd(g, a[i])

		if k % g == 0:
			print("POSSIBLE")
		else:
			print("IMPOSSIBLE")


Measured memory_bytes: 16048
import heapq
def main():

    N, D, A = map(int, input().split())
    XH = []
    for _ in range(N):
        X, H = map(int, input().split())
        XH.append([X, H])

    if N == 1:
        x, h = XH[0]
        if h % A == 0: return h // A
        return h // A + 1

    XH.sort()
    ans = 0
    B = [[XH[0][0], XH[0][1], 0]]
    j = 0
    k = 0
    count = [0]
    while j < N or len(B) > 0:
        if len(B) > 0:
            x, h, i = heapq.heappop(B)
            h -= (count[k]- count[i])*A
            if h > 0:
                if h % A == 0: n = h // A
                else: n = h // A + 1
                ans += n
                count.append(count[-1]+n)
                while j < N and XH[j][0] <= x + 2*D:
                    heapq.heappush(B, [XH[j][0], XH[j][1], k])
                    j += 1
                k += 1
        else:
            heapq.heappush(B, [XH[j][0], XH[j][1], k])
            j += 1

    return ans

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 112028
#define F(p,n,m)(p*(f-d)*(n-e)>p*(m-d)*(g-e)&&p*(d-h)*(n-i)>p*(m-h)*(e-i))
#define G(p,n,m),p=(h-f)*(n-g)-(m-f)*(i-g)
main(z){float d,e,f,g,h,i,m,n,M,N,p,q;for(scanf("%d",&z);z--;puts((F(p,n,m)^F(q,N,M))?"OK":"NG"))scanf("%f%f%f%f%f%f%f%f%f%f",&d,&e,&f,&g,&h,&i,&m,&n,&M,&N)G(p,n,m)G(q,N,M);}

Measured memory_bytes: 616
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  int X,a=0,b=0;
  cin >> X;
  for(int i=0; i<X; i++){
    a += 1;
    b += a;
    if(b>=X){
      cout << a << endl;
      return 0;
    }
  }
}

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


vector<int> input(int Q){
  vector<int> z(Q);
  for (int i = 0; i < Q; i++) {
    cin >> z.at(i);
  }
  return z;
}



int main(){
  int N;
  int Q = 3;
  int R;

  vector<int> A = input(Q);
  vector<int> B = input(Q);
  vector<int> C = input(Q);

  cin >> N;
  vector<int> v(N);
  for (size_t i = 0; i < N; i++) {
    cin >> v.at(i);
  }

  for (size_t j = 0; j < Q; j++) {
    for (size_t i = 0; i < N; i++) {
      if(A.at(j) == v.at(i)){
        A.at(j) = 0 ;
      }
      else if(B.at(j) == v.at(i)){
        B.at(j) = 0 ;
      }
      else if(C.at(j) == v.at(i)){
        C.at(j) = 0 ;
      }
    }
  }


  if(A.at(0) + A.at(1) + A. at(2) == 0){
    cout << "Yes" << endl;
  }
  else if(B.at(0) + B.at(1) + B.at(2) == 0){
    cout << "Yes" << endl;
  }
  else if (C.at(0) + C.at(1) + C.at(2) == 0) {
    cout << "Yes" << endl;
  }
  else if(A.at(0) + B.at(0) + C.at(0) == 0){
    cout << "Yes" << endl;
  }
  else if (A.at(1) + B.at(1) + C.at(1) == 0) {
    cout << "Yes" << endl;
  }
  else if (A.at(2) + B.at(2) + C. at(2) == 0) {
    cout << "Yes" << endl;
  }
  else if(A.at(0) + B.at(1) + C.at(2) == 0){
    cout << "Yes" << endl;
  }
  else if (A.at(2) + B.at(1) + C.at(0) == 0) {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

ll dp[1005][10005];

int main() {
    ll H,N;
    cin>>H>>N;
    vector<vector<ll>> v(N,vector<ll>(2));
    rep(i,N) cin>>v[i][0]>>v[i][1];
    rep(i,10005){
        dp[0][i]=((i-1)/v[0][0]+1)*v[0][1];
    }
  	rep(i,1005) dp[i][0] = 0;
    for(int i = 1; i < N; i++){
        for(int j = 1; j <= H; j++){
            if(j>v[i][0]) dp[i][j]=min(dp[i-1][j],dp[i][j-v[i][0]]+v[i][1]);
            else dp[i][j] = min(dp[i-1][j],v[i][1]);
        }
    }
    cout<<dp[N-1][H]<<endl;
}

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

void solve(long long N, vector<string> S){
  long long ans = 1;
  long long M = 1000000007;
  long long type = 0;
	for ( long long i = 0; i < N; i++ ) {
    if (S[0][i] == S[1][i]) {
      if ( type == 0 ) {
        ans = 3;
        type = 1;
      } else if ( type == 1 ) {
        ans *= 2;
      } else if ( type == 2 ) {
        ans *= 1;
        type = 1;
      }
    } else if ( i < S[0].length() - 1 &&  S[0][i] == S[0][i+1] && S[1][i] == S[1][i+1] ) {
      i += 1;
      if ( type == 0 ) {
        ans = 6;
        type = 2;
      } else if ( type == 1 ) {
        ans *= 2;
        type = 2;
      } else if ( type == 2 ) {
        ans *= 3;
      }
    }
    ans %= M;
  }
  cout << ans << endl;
}

int main(){	
	long long N;
	vector<string> S(2-1+1);
	scanf("%lld",&N);
	for(int i = 0 ; i <= 2-1 ; i++){
		cin >> S[i];
	}
	solve(N, S);
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;

ll dp[100001];

int main(void){
    cin.tie(0);
	ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vl h(n);
    rep(i,n){
        cin>>h[i];
        dp[i] = inf;
    }
    dp[0] = 0;
    rep(i,n){
        if(i+1<n) dp[i+1] = min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        if(i+2<n) dp[i+2] = min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#define int long long
int32_t main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int x,a,b;
    cin>>x>>a>>b;
    x -= a;
    x -= (x/b)*b;
    cout<<x;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

int all753(int digit){
    return (int)pow(3, digit) - 3 * (int)pow(2, digit) + 3;
}

int make(int digit, int serial){
    int ans = 0;
    int mp[] = {3, 5, 7};
    bool f[] = {0, 0, 0};
    rep(i, digit){
        ans += (int)pow(10, i) * mp[(serial/(int)pow(3,i))%3];
        f[(serial/(int)pow(3,i))%3] = 1;
    }
    if(f[0] && f[1] && f[2]) return ans;
    else return -1;
}

void solve(int n){
    int digit = (int)log10(n)+1;
    int ans = 0;
    rea(i, 3, digit){
        ans += all753(i);
    }
    rep(i, (int)pow(3, digit)){
        int x = make(digit, i);
        if(x != -1 && x <= n){
            ans++;
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	// s[i + 2] = s[i] + s[i+1]
	const mod = 1000000007
	var n, m int
	fmt.Scan(&n, &m)
	s := make([]int64, n+1)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	var a int
	for i := 0; i < m; i++ {
		sc.Scan()
		a, _ = strconv.Atoi(sc.Text())
		s[a] = -1 // broken floor
	}
	if s[0] >= 0 {
		s[0] = 1
	}
	if s[1] >= 0 {
		s[1] = 1
	}
	for i := 0; i < n-1; i++ {
		if s[i+2] < 0 {
			continue
		}
		if s[i] >= 0 {
			s[i+2] = s[i]
		}
		if s[i+1] >= 0 {
			s[i+2] = (s[i+2] + s[i+1]) % mod
		}
	}
	fmt.Println(s[n])
}


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

int main() {
    string S;
    cin >>S;
    if(S == "Sunny") cout << "Cloudy" <<endl;
    else if(S == "Cloudy") cout << "Rainy" <<endl;
    else cout << "Sunny" <<endl;
}

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

int main()
{
    string s;
    string alphabet = "abcdefghijklmnopqrstuvwxyz";
    cin >> s;
    int a[26] = {0};
    for (size_t i = 0; i < s.length(); i++)
    {
        a[s[i] - 'a'] = 1;
    }
    for (size_t i = 0; i < 26; i++)
    {
        if (a[i] == 0)
        {
            cout << alphabet[i] << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

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

int main() {
    string S;
    cin >> S;
    int v = 0;
    for(int i=0; i<S.size(); ++i) {
        if(S[i] == 'o') ++v;
    }
    if(v + 15 - S.size() >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

using ll = long long;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}

int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N, M; cin >> N >> M;
  vector<vector<int>> tmp(N + 1);
  int a, b;
  REP(i, M) {
    cin >> a >> b;
    tmp[b].push_back(a);
  }

  string ans = "IMPOSSIBLE";
  REP(i, tmp[N].size()) {
    if(vector_finder(tmp[tmp[N][i]], 1)) {
      ans = "POSSIBLE";
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 8576
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <queue>
#include <math.h>
using namespace std;
#define lol long long



int main()
{
	lol N;
	cin >> N;
	lol rN = sqrt(N);
	lol ans = 0;
	for (lol x = 1; x < rN + 1; x++) {
		if (N % x == 0) {
			lol m = (N / x) - 1;
			if (m > x) {
				ans += m;
			}
		}
	}
	cout << ans << endl;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int n, m; cin >> n >> m;

	int ret = 0;
	if (n == 1) ret = m;
	else if (n == m ) ret = 1;
	else {
		int div = m / n;
		for (int i = 1; i <= div; i++) {
			int mod = (m - i * n) % i;
			if (mod == 0) ret = i;
		}
	}
	cout << ret << '\n';
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#define int long long
using namespace std;
const int N = 1e6 + 5, inf = 1e18;
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
int n, s, t, p1, p2, p3, p4, mc, mf, cnt = 1, head[N], to[N], val[N], vis[N], dis[N], nxt[N], cost[N], flow[N], last[N], pre[N];
void add(int x, int y, int w, int c) {
	to[++ cnt] = y; val[cnt] = w; cost[cnt] = c; nxt[cnt] = head[x]; head[x] = cnt;
	to[++ cnt] = x; val[cnt] = 0; cost[cnt] = - c; nxt[cnt] = head[y]; head[y] = cnt;
}
queue <int> q;
bool spfa() {
	for(int i = s; i <= t; ++ i) dis[i] = -inf, flow[i] = inf;
	q.push(s); vis[s] = 1; dis[s] = 0; pre[t] = -1;
	while(! q.empty()) {
		int x = q.front(); q.pop(); vis[x] = 0;
		for(int i = head[x]; i; i = nxt[i]) {
			if(val[i] && dis[to[i]] < dis[x] + cost[i]) {
				dis[to[i]] = dis[x] + cost[i];
				flow[to[i]] = min(flow[x], val[i]);
				pre[to[i]] = x; last[to[i]] = i;
				if(! vis[to[i]]) vis[to[i]] = 1, q.push(to[i]);
			}
		}
	}
	return pre[t] != -1;
}
void mcmf() {
	while(spfa()) {
		int now = t; mc += flow[t] * dis[t];
		while(now != s) {
			val[last[now]] -= flow[t];
			val[last[now] ^ 1] += flow[t];
			now = pre[now];
		}
	}
}
signed main() {
	n = read(); s = 0; p1 = 2 * n + 1; p2 = p1 + 1; p3 = p2 + 1; p4 = p3 + 1; t = p4 + 1;
	for(int i = 1, x, y, z; i <= n; ++ i) {
		x = read(); y = read(); z = read();
		add(s, i, z, 0);
		add(i, p1, inf, x + y); add(i, p2, inf, x - y);
		add(i, p3, inf, - x + y); add(i, p4, inf, - x - y); 
	}
	for(int i = 1, x, y, z; i <= n; ++ i) {
		x = read(); y = read(); z = read();
		add(i + n, t, z, 0);
		add(p1, i + n, inf, - x - y); add(p2, i + n, inf, - x + y);
		add(p3, i + n, inf, x - y); add(p4, i + n, inf, x + y);
	}
	mcmf();
	printf("%lld\n", mc);
	return 0;
}


Measured memory_bytes: 19320
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <stack>
#include <set>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

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

const int INF = 1 << 29;
const double EPS = 1e-10;


int main() {
  int n_cases; cin >> n_cases;
  while (n_cases--) {
    string s; cin >> s;
    vi ch, num;
    rep(i, s.size()) {
      int c = s[i] - '0';
      if (ch.size() != 0 && ch.back() == c) {
        num[num.size() - 1]++;
      }
      else {
        ch.pb(c);
        num.pb(0);
      }
    }

    string table[] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    rep(i, ch.size()) {
      if (ch[i] == 0) continue;
      cout << table[ch[i] - 1][num[i] % table[ch[i] - 1].size()];
    }

    cout << endl;
  }
  
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  int maxm = -1;
  int sum = 0;
  rep(i, n) {
    int p;
    cin >> p;
    maxm = max(p, maxm);
    sum += p;
  }
  sum -= maxm / 2;
  
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	rep(i, N) cin >> A[i];
	vector<ll> cnt(N + 1, 0);
	rep(i, N) {
		cnt[A[i]]++;
	}
	sort(all(cnt), greater<int>());
	int sum = 0;
	for (ll i = K; i < N; i++) {
		sum += cnt[i];
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 3328
from collections import deque

n,m=map(int,input().split())

tree=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  tree[a].append(b)
  tree[b].append(a)

dist=[-1 for i in range(n)]
dist[0]=0

ans=[-1 for i in range(n)]
ans[0]=0

dq=deque()
dq.append(0)
while dq:
  x=dq.popleft()
  for i in tree[x]:
    if ans[i]==-1:
      ans[i]=x
      dq.append(i)

if -1 in ans:
  print('No')
  exit()

print('Yes')
for i in ans[1:]:
  print(i+1)

Measured memory_bytes: 35516
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int x = sc.nextInt();

		int absPos[] = new int[n];

		for(int i = 0; i < n; i++){
			absPos[i] = Math.abs(x - sc.nextInt());
		}

		int gcd = absPos[0];
		for(int i = 1; i < n; i++){
			gcd = gcd(gcd, absPos[i]);
		}

		System.out.println(gcd);
	}

	static int gcd(int a, int b){
        int tmp;

        while (a % b != 0)
        {
            tmp = b;
            b = a % b;
            a = tmp;
        }
        return b;
    }
}


Measured memory_bytes: 50036
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int num[200005],good[200005];
int main()
{
    memset(num,0,sizeof(num));
    int n,mint=1000000000,i,x,k,numgood;
    numgood=0;
    scanf("%d%d",&n,&k);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&x);
        num[x]++;
    }
    for(i=1;i<=200000;i++)
    if(num[i]!=0)
    {
        numgood++;
        good[numgood]=num[i];
    }
    sort(good+1,good+numgood+1);
    int sum;
    sum=0;
    i=0;
    while(numgood>k)
    {
        i++;
        sum=sum+good[i];
        numgood--;
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b, c, d, e;
    string s, t;
    cin >> a;
    int ans = INF;
    rep(i, 10) {
        if(a <= (i + 1) * 1000) ans = min(ans, 1000 * (i + 1) - a);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define in insert
#define REP(i,n) for (int i = 1; i <= n; i++)
#define matrix vector<vector<ll> > 
using namespace std;
 
const ll N = 2e5+2;
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll LOG = 25;
 
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll n;
ll a[N];
ll st[N][LOG+1];
ll query(ll l,ll r){
	l--,r--;
	ll xori = 0;
	for(ll j = LOG;j>=0;j--){
		if((1ll<<j) <= (r-l+1)){
			xori ^= st[l][j];
			l+=(1ll<<j);
		}
	}
	return xori;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	// ifstream fin ("sound.in");
	// ofstream fout("sound.out");
	
	
	cin >> n;
	ll ans = 0;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i =0;i<n;i++){
		st[i][0] = a[i+1];
	}
	ll pre[n+1];
	pre[0] = 0;
	for(int i =1;i<=n;i++) pre[i] = pre[i-1] + a[i];
	for(int j =1;j<=LOG;j++){
		for(int i =0;i+(1ll<<j) <= n;i++){
			st[i][j] = st[i][j-1] ^ st[i+(1ll<<(j-1))][j-1];
		}
	}
	for(int i =1;i<=n;i++){
		ll lo = i,hi = n;
		ll idx = -1;
		while(lo <= hi){
			ll mid = (lo+hi)>>1LL;
			ll x = query(i,mid);
			ll sum = pre[mid]-pre[i-1];
			x ^= sum;
			if(x != 0){
				hi=mid-1;
			}
			else{
				lo =mid+1;
				idx = max(idx,mid);
			}
		}
		if(idx != -1){
			ans += (idx-i+1);
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 44032
#include <stdio.h>

int main(void)
{
	char str[128];
	int i, j;

	while (scanf("%s", str) != EOF){
		for (i = 0; str[i] != '\0'; i++){
			if (str[i] == '@'){
				for (j = 0; j < str[i + 1] - '0'; j++){
					printf("%c", str[i + 2]);
				}

				i += 2;
			}
			else {
				printf("%c", str[i]);
			}
		}

		puts("");
	}

	return (0);
}

Measured memory_bytes: 956
fun main(args: Array<String>) = p35()

fun p35() {
    data class Item(val value: Int, val weight: Int)

    val (n, w) = readLine()!!.split(' ').map { it.toInt() }
    val items = Array(n) {
        val (value, weight) = readLine()!!.split(' ').map { it.toInt() }
        Item(value, weight)
    }

    val dp = Array(n) { IntArray(w + 1) }

    for ((index, item) in items.withIndex()) {
        for (weightLimit in 0..w) {
            // not choose item
            if (index != 0) dp[index][weightLimit] = Math.max(dp[index][weightLimit], dp[index - 1][weightLimit])

            // choose item
            val weightSum = weightLimit + item.weight
            if (weightSum <= w) {
                dp[index][weightSum] = if (index == 0) item.value else Math.max(
                    dp[index - 1][weightSum],
                    if (weightSum <= w) dp[index - 1][weightSum - item.weight] + item.value else 0
                )
            }
        }
    }

    val answer = dp.last().last()

    println(answer)
}



Measured memory_bytes: 37168
package main

import (
	"fmt"
)

func main() {
	var time int
	fmt.Scanln(&time)
	hour := time / 3600
	minute := (time - hour*3600) / 60
	second := time - hour*3600 - minute*60
	fmt.Printf("%d:%d:%d\n",hour,minute,second)
	return
}



Measured memory_bytes: 1128
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

scoreMap = {'r': P, 'p': S, 's': R}

score = 0
for i in range(0, K):
  a, b = scoreMap[T[i]], 0
  for j in range(i+K, N, K):
    na = b + scoreMap[T[j]]
    if T[j] != T[j-K]:
      na = max(na, a + scoreMap[T[j]])
    nb = max(a, b)
    a, b = na, nb
  score += max(a, b)
print(score)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    ll n;   cin >> n;
    vector<ll> p, q;
    vector<pair<ll, ll>> point(n);
    map<pair<ll, ll>, ll> key;
    REP(i, n) {
        cin >> point[i].first >> point[i].second;
        key[point[i]] += 1; 
    }
    sort(ALL(point));
    vector<pair<ll, ll>> arg;
    REP(i, n){
        FOR(j, i+1, n){
            arg.emplace_back(point[i].first-point[j].first, point[i].second-point[j].second);
        }
    }
    ll res=LINF;
    if(0<arg.size()){
        REP(k, arg.size()){
            ll dx = arg[k].first, dy=arg[k].second, tmp=0;
            REP(i, n){
                ll x=point[i].first, y=point[i].second;
                if(!key.count({x-dx, y-dy})){
                    tmp += 1;
                }
            }
            res = min(res, tmp);
        }
    }else res=1;
    cout << res << endl;
}


Measured memory_bytes: 3660
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=4000050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	bitset<SIZE> B;
	B[0]=1;
	int sum=0;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		sum+=a;
		B|=B<<a;
	}
	for(int i=(sum+1)/2;1;i++){
		if(B[i]){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1792
import numpy as np
h, w = map(int, input().split())
s = np.array([list(input()) for _ in range(h)])
w1, w2 = np.array(["."]*h), np.array(["."]*(w+2))
s = np.hstack((w1.reshape(len(w1),1), s))
s = np.hstack((s, w1.reshape(len(w1),1)))
s = np.vstack((w2, s))
s = np.vstack((s, w2))
dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]
for i in range(1, h+1, 1):
    for j in range(1, w+1, 1):
        now = s[i][j]
        c = 0
        if now == ".":
            continue
        for d in range(4):
            x = j + dx[d]
            y = i + dy[d]
            if now == s[y][x]:
                c += 1
        if c == 0:
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 13352
void main(){
	int a, b;
	readf("%d %d", &a, &b);
	writeln(b%a==0? a+b: b-a);
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


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

#define rep(i,n) for(int i=0;i<n;i++)

int main()
{
   int n,k;
    cin>>n>>k;
   int count=0;
   while(n>0)
   {
       n=n/k;
       count++;
   }
   cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using P = pair <int, int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
const int mod = 1000000007;

int digit_divisor(int n){
    vector<int> res;
    for(int i = 1;i<=n;++i){
        if(n%i==0) res.push_back(i);
    }
    return res.size();
}

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1;i<=n;i+=2){
        if(digit_divisor(i)==8) ans ++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

import static java.lang.Integer.parseInt;

/**
 * Pattern - Largest Square
 */
public class Main {

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

		int H, W;
		H = sc.nextInt();
		W = sc.nextInt();

		int[][] dp = new int[H + 1][W + 1];

		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				dp[i][j] = parseInt(sc.next()) == 1 ? 0 : 1;
			}
		}

		int max = 0;

		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				if (dp[i][j] == 1) {
					dp[i][j] = Math.min(dp[i - 1][j - 1], Math.min(dp[i - 1][j], dp[i][j - 1])) + 1;
					max = Math.max(max, dp[i][j]);
				}
			}
		}

		System.out.println(max * max);

	}
}

Measured memory_bytes: 182472
# AOJ 0048
# Class
# 5/1/2019

min = 40.00
max = 150.00

measure = [min, 48.00, 51.00, 54.00, 57.00, 60.00, 64.00, 69.00, 75.00, 81.00, 91.00, max]
className = ['light fly',
         'fly',
         'bantam',
         'feather',
         'light',
         'light welter',
         'welter',
         'light middle',
         'middle',
         'light heavy',
         'heavy']

while True:
    try:
        weight = float(input())
    except:
        break;
    for i in range(11):
        if(measure[i] < weight and weight <= measure[i + 1]):
            print(className[i])



Measured memory_bytes: 5576
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;


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

	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    s = list(input().rstrip())
    res = 10000000000000000000000
    for i in range(len(s)-2):
        n = int(s[i])*100 + int(s[i+1])*10 + int(s[i+2])
        res = min(res, abs(n-753))
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import sys
def s():
 n,k=map(int,input().split())
 w=list(map(int,sys.stdin.readlines()))
 def f():
  c=t=0
  for j in w:
   t+=j
   if t>m:
    t=j
    c+=1
    if c>=k:return 0
  return 1
 l,r=max(w),sum(w)
 while l<r:
  m=(l+r)//2
  if f():r=m
  else:l=m+1
 print(r)
if'__main__'==__name__:s()


Measured memory_bytes: 15828
#include <bits/stdc++.h>
using namespace std;
#pragma optimize("O0")

int A[55];
bool boleh[55];
int B[55];
int C[55];
int indx[55];
long long ncr[55][55];

long long ncrUpTo[55][55];

int8_t cnt2[(1<<18)+5];
int s[55];

int main(){
    int N, K, S, T;
    scanf("%d%d%d%d", &N, &K, &S, &T);

    if( ((S&T) == S) && ((S|T) == T) ){
    }else{
        printf("0");
        return 0;
    }

    memset(ncr, 0, sizeof(ncr));
    ncr[0][0] = 1;
    for(int i = 1; i <= N; i ++){
        ncr[i][0] = 1;
        for(int j = 1; j <= i; j ++){
            ncr[i][j] = ncr[i-1][j] + ncr[i-1][j-1];
        }
    }

    ncrUpTo[0][0] = 0;
    for(int i = 1; i <= N; i ++){
        ncrUpTo[i][0] = 0;
        for(int j = 1; j <= N; j ++){
            ncrUpTo[i][j] = ncrUpTo[i][j-1] + ncr[i][j];
        }
    }

    for(int i = 0; i < N; i ++){
        scanf("%d", &A[i]);
        boleh[i] = true;
        //printf("A[%d]=%d\n", i, A[i]);
    }

    int L = 0;
    for(int i = 0; i < 20; i ++){
        if( (S&(1<<i)) == (T&(1<<i)) ){
            for(int j = 0; j < N; j ++){
                if( (S&(1<<i)) != (A[j]&(1<<i)) ){
                    boleh[j] = false;
                    //printf("boleh[%d]=false\n", j);
                }
            }
        }else{
            indx[L ++] = i;
        }
    }

    for(int i = 0; i < L; i ++){
        for(int j = 0; j < N; j ++){
            if(A[j]&(1<<indx[i])){
                B[j] |= (1<<i);
            }
        }
    }

    int M = 0;
    for(int i = 0; i < N; i ++){
        if(boleh[i]){
            C[M ++] = B[i];
        }
    }

    for(int i = 0; i < M; i ++){
        //printf("C[%d]=%d\n", i, C[i]);
    }

    memset(cnt2, 0, sizeof(cnt2));
    long long ans = 0;
    for(int U = 0; U < (1<<L); U ++){
        long long f = 0;

        int sizeS = 0;
        for(int i = 0; i < M; i ++){
            if(!cnt2[U&C[i]]){s[sizeS++] = (U&C[i]);}
            cnt2[U&C[i]] ++;
        }

        for(int k = 0; k < sizeS; k ++){
            int j = s[k];
            int cnt = cnt2[j];
            f += ncrUpTo[cnt][K];
            cnt2[j] = 0;
        }

        int temp = __builtin_popcount(U);
        if(temp&1){
            ans -= f;
        }else{
            ans += f;
        }
    }

    printf("%lld", ans);
    return 0;
}


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

using namespace std;

int main(int argc, char const *argv[]) {
        int cnt = 0;
        string W, txt;
        cin >> W;
        while(cin >> txt) {
                for(int i = 0; i < txt.size(); i++) {
                        if(isupper(txt[i])) txt[i] = char(tolower(txt[i]));
                }
                if(txt == "END_OF_TEXT") break;
                if(txt == W) cnt++;
        }
        cout << cnt << '\n';
        return 0;
}



Measured memory_bytes: 3200
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int mxn = 5000;
int n, k;
ll a[mxn], b[mxn];
vector<ll> v;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	
	for(int i = 0; i < n; i++){
	    cin >> a[i];
	    a[i]--;
	} 
	for(int i = 0; i < n; i++) cin >> b[i];
	
	ll ret = -0x3f3f3f3f3f3f3f3f;
	for(int i = 0; i < n; i++){
	    int x = 1;
	    v = {0, b[i]};
	    ret = max(ret, b[i]);
	    for(int j = a[i]; j != i; j = a[j], x++){
	        v.push_back(v.back() + b[j]);
	        if(x < k) ret = max(ret, v.back());
	    }
	    for(int j = 0; j <= (k % x); j++){
    	    if(k >= x || j) ret = max(ret, v.back() * (k / x) + v[j]); 
	    }
	    if(k >= x) for(int j = 0; j <= x; j++){ 
	        if(k >= 2 * x || j) ret = max(ret, v.back() * (k / x - 1) + v[j]);
	    }
	}
	
	cout << ret << endl;

	return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	for(int i = a; i < c; i++) {
		cout << "R";
	}
	for(int i = b; i < d; i++) {
		cout << "U";
	}
	for(int i = a; i < c; i++) {
		cout << "L";
	}
	for(int i = b; i < d; i++) {
		cout << "D";
	}
	cout << "D";
	for(int i = a; i <= c; i++) {
		cout << "R";
	}
	for(int i = b; i <= d; i++) {
		cout << "U";
	}
	cout << "L";
	cout << "U";
	for(int i = a; i <= c; i++){
		cout << "L";
	}
	for(int i = b; i <= d; i++) {
		cout << "D";
	}
	cout << "R";
	return 0;	
}


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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 998244353ll;
const ll MAXN = (ll) 2e6 + 10;
const ll INF = (ll) 10000000000ll;
const ld EPS = (ld) 1e-8;

ll a[4];
ll b[] = {1,4,7,9};
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> a[0] >> a[1] >> a[2] >> a[3];
	sort(a, a + 4);
	for(int i = 0;i<4;i++) if(a[i] != b[i]) return cout << "NO", 0;
	cout << "YES";	
	return 0;
}


/*
6
7 3 4 2 3 1
                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;

const ll mod = 1000000007;
const int N = 1e5+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll 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-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
ll a[N];
ll p[62];
void add(ll x) {
    repd(i, 60, 0) {
        if(!(x&(1ll<<i))) continue;
        if(p[i]) x ^= p[i];
        else {
            p[i] = x;
            break;
        }
    }
}
int main() {
    /*
        假设我们分成两个部分A和B,那么A^B = sum, 我们要使得A+B最大，B可以看成是sum里面分出A集合
        考虑二进制第i位的1的数量为奇数,那么我们不论如何分那么这位的i对于答案是没有影响的,因为要么A1B0,要么B0A1
        所以我们就要考虑第i位的1的数量是偶数的
        首先我们重构a数组,把所有奇数的1都去除(因为不影响结果
        偶数数量的1的位置sum对应的那位二进制肯定是0，那么0的位置如果我们提取出1的话，那么这个位置也变成了1,那么加起来就很nice，
        而且就是要优先保证高位的1被提取出来
        想想新的a数组求最大值子集异或和的过程，就是高位有1的话，并且当前的最大值的这个位置没有1就异或,这样就是相当于提取高位1的过程
    */
    int n; scanf("%d",&n);
    ll sum = 0;
    rep(i, 0, n) scanf("%lld",a+i), sum ^= a[i];
    rep(i, 0, 60) if(sum & (1ll<<i)) {
        rep(j, 0, n) if(a[j] & (1ll<<i)) a[j] ^= (1ll<<i);
    }
    rep(i, 0, n) add(a[i]);
    ll ret = 0;
    repd(i, 60, 0) if(!(ret&(1ll<<i))) ret ^= p[i];
    printf("%lld\n", (sum ^ ret) + ret);
    return 0;
}


Measured memory_bytes: 1024