akhauriyash/Code-Regression huggingface dataset:
//tree distfromroot and calcparent
//tenka12016-B
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}

typedef struct{
int val;
int node;
}sd;

int sdsortfnc(const void *a,const void *b){
if(((sd*)a)->val > ((sd*)b)->val){return -1;}
if(((sd*)a)->val < ((sd*)b)->val){return 1;}
return 0;
}

typedef struct{
    long long st;
    long long fi;
    long long kr;
}rs;

typedef struct{
    long long st;
    long long kz;
}mkj;

int sortfnc(const void *a,const void *b){
if(((rs*)a)->st == ((rs*)b)->st){return 0;}
if(((rs*)a)->st < ((rs*)b)->st){return -1;}
return 1;
}

void makemkj(rs g[],mkj x[],long long n){
    long long i,ms=0,nst=g[0].st;
    for(i=1;i<n;i++){
        if(g[i].st!=g[i-1].st){
            x[nst].kz=i-ms;
            x[nst].st=ms;
            nst=g[i].st;ms=i;
        }
    }
    x[nst].kz=n-ms;
    x[nst].st=ms;
}

int dist[524288],par[524288];
void dfs(int t,int l,int bp,rs g[],mkj x[]){
  int i;
  if(dist[t]<=l){return;}
  dist[t]=l;
  par[t]=bp;
  for(i=x[t].st;i<x[t].st+x[t].kz;i++){
    dfs(g[i].fi,l+1,t,g,x);
  }
}

int main(void){
    int i,j,n,m,k,a,b,c,h,w,r=0,l,t;
    int res=0,num[524288];
    int v[524288],p[524288];
    rs g[524288];
    mkj x[524288];
    sd dat[524288];
    scanf("%d%d",&n,&k);
    scanf("%d",&t);
    if(t!=1){r++;}
    for(i=2;i<=n;i++){
      scanf("%d",&a);
      g[2*i-4].st=i;
      g[2*i-4].fi=a;
      g[2*i-4].kr=1;
      g[2*i-3].st=a;
      g[2*i-3].fi=i;
      g[2*i-3].kr=1;
    }
    qsort(g,2*(n-1),sizeof(g[0]),sortfnc);
    makemkj(g,x,2*(n-1));
    for(i=0;i<=n;i++){
      dist[i]=inf;
      num[i]=0;
    }
    dfs(1,0,0,g,x);
    for(i=1;i<=n;i++){
      dat[i-1].node=i;
      dat[i-1].val=dist[i];
    }
    qsort(dat,n,sizeof(dat[0]),sdsortfnc);
    for(i=0;i<n-1;i++){
      w=dat[i].node;
      h=0;
      for(j=x[w].st;j<x[w].st+x[w].kz;j++){
        if(par[w]==g[j].fi){continue;}
        h=max(h,num[g[j].fi]);
      }
      num[w]=h+1;
      if(dist[w]!=1 && num[w]==k){r++;num[w]=0;}
      //printf("%d %d %d %d\n",i,n-1,w,num[w]);
    }
    printf("%d\n",r);
    return 0;
}


Measured memory_bytes: 27692
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    ll a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;
    bool flag=0;
    if (abs(a-b)<=(v-w)*t || a==b) flag=1; 
    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;
     
 
    return 0;   
}

Measured memory_bytes: 3564
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    ll x = 0;
    cin >> x;
    if (x%11 == 0) {
        cout << x/11*2 << endl;
    }
    else if (x%11 <= 6) {
        cout << x/11*2 + 1 << endl;
    }
    else {
        cout << x/11*2 + 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a[100005],b[100005],n,cnt=0,sum=0;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]<0)
			cnt++;
	    b[i]=abs(a[i]);	
	    sum+=b[i];
	 }
	 sort(b,b+n);
	 if(cnt%2==0)
	 	cout<<sum<<endl;
	else
		cout<<sum-b[0]-b[0]<<endl;
	return 0;
}

Measured memory_bytes: 5140
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int n,p,w,g,y=0;
  string s;
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>s;
    if(s=="P")p=1;
    if(s=="W")w=1;
    if(s=="G")g=1;
    if(s=="Y")y=1;
  }
  n=p+w+g;
  if(n==3){
    if(y==1){
      cout<<"Four"<<endl;
      return 0;
    }
    cout<<"Three"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
const int mod=1e9+7;

int main(){
  int N;
  cin>>N;
  vector<int>A(N);
  map<int,int>k;
  for(int i=0;i<N;i++){
    cin>>A[i];
    k[A[i]]++;
  }
  int cnt=0;
  for(auto c:k){
    if(c.second%2==0){
      cnt++;
    }
  }

  if(cnt%2==0){cout<<k.size()<<endl;}
  else{cout<<k.size()-1<<endl;}

  return 0;                       
}

Measured memory_bytes: 8180
#include <bits/stdc++.h>
using namespace std;
#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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = LLONG_MAX;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
int main() {
    long double w,h,x,y;cin>>w>>h>>x>>y;
    cout << w*h/2 << ' ';
    if(w/2==x&&h/2==y) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3764
#define _CRT_SECURE_NO_WARINGS
#include <iostream>
#include <iomanip>
#include <map>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <fstream>
#include <map>
#include <unordered_map>
using namespace std;
typedef int me;
typedef long long ll;
typedef unsigned long long ull;
#define andrew               \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)
#define endl '\n'
#define sz(v) (int)(v.size())
#define all(v) v.begin(), v.end()
#define PI 3.1415926535
#define sin(i) (long double)sin(i *PI / 180.0)
#define cos(i) (long double)cos(i * PI/ 180.0)
ll gcd(ll x, ll y)
{
    return (y == 0) ? x : gcd(y, x % y);
}
ull lcm(ll x, ll y) { return x / gcd(x, y) * y; }
int dy8[] = { 0, 0, 1, -1, 1, -1, -1, 1 };
int dx8[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int id8[] = { 0, 1, 2, 3, 4, 5, 6, 7 };

int main()
{
    andrew;
    int n, m;
    cin >> n >> m;
    vector<vector<char>>v(n, vector<char>(m));
    vector<vector<ll>>mem(n+1, vector<ll>(m+1));

    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= m; j++)
            mem[i][j] = 0;

    mem[n - 1][m - 1] = 1;
    v[n - 1][m - 1] = 'a';
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> v[i][j];
  
    for (int i = n - 1; i >= 0; i--)
    {
        for (int j = m - 1; j >= 0; j--)
        {
            if (v[i][j] == '.')
            {
                
                mem[i][j] = ((mem[i][j] % 1000000007) + (mem[i + 1][j] % 1000000007)) % 1000000007;
                mem[i][j] = ((mem[i][j] % 1000000007) + (mem[i][j + 1] % 1000000007)) % 1000000007;
            }
        }
    }

    cout << mem[0][0] << endl;

    
  
}
/*
3
0 6
6 0
3 4
*/

Measured memory_bytes: 12180
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<queue>
#include<unordered_map>
#include<map>
#include<stack>
#include<bits/stdc++.h>
#include<string.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
//#define f first
//#define s second
#define respr(fir,sec) for(int i=0;i<=fir;i++){for(int j=0;j<=sec;j++){cout << res[i][j] << " ";}cout << "\n";}
#define pb push_back
//#define INF (1LL<<31)
using namespace std;
using namespace __gnu_pbds;
const int mod = 1e9+7;
const ll MAX = 1000000000000000000;
const ll INF = 1000000000;
typedef pair<int,ll> pii;
typedef pair<ll,int> pi;
typedef tuple<long long,int> tp;
typedef tuple<int,int,long long> tu;
typedef multimap<pii , int> mpp;
typedef priority_queue< tp , vector<tp>, greater<tp>>  minheap;
typedef priority_queue<pii , vector<pii>> maxheap;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>  new_data_set;
const int nax=105;
//const int nax1 = 105;

int main()
{
	FASTIO;
	int n,k;
	cin >> n >> k;
	vector<int> arr(n);

	
	for(int i=0;i<n;i++){
			cin >> arr[i];
	}
	
	vector<int> dp(n, INF);
	dp[0]=0;
	
	for(int i=0;i<n;i++){
		for(int j=1;j<=k;j++){
			if(i+j <n)
				dp[i+j] = min(dp[i+j], dp[i]+abs(arr[i+j]-arr[i]));
		}
	}
	
	cout << dp[n-1] << "\n";
	

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

template<typename T>
int partition(vector<T> &a, int p, int r) {
    T x = a[r];
    int i = p-1;
    for(int j=p; j<r; j++) {
        if(a[j]<=x) {
            i++;
            swap(a[i], a[j]);
        }
    }
    swap(a[i+1], a[r]);
    return i+1;
}

template<typename T>
void quicksort(vector<T> &a, int p, int r) {
    if(p < r) {
        int q = partition(a, p, r);
        quicksort(a, p, q-1);
        quicksort(a, q+1, r);
    }
}

struct card {
    string suit;
    int rank;
    card() {}
    //card(string s, int r) : suit(s), rank(r) {}
};

bool operator<(const card &a, const card &b) {
    return a.rank < b.rank;
}
bool operator<=(const card &a, const card &b) {
    return a.rank <= b.rank;
}
bool operator==(const card &a, const card &b) {
    return a.suit == b.suit && a.rank == b.rank;
}

ostream& operator<<(ostream &os, const card &a) {
    os << a.suit << " " << a.rank;
    return os;
}

istream& operator>>(istream &is, card &a) {
    is >> a.suit >> a.rank;
    return is;
}

int main() {
    int n;
    cin >> n;
    vector<card> cs(n);
    for(int i=0; i<n; i++) cin >> cs[i];
    vector<card> copy(cs);
    quicksort(cs, 0, n-1);
    stable_sort(copy.begin(), copy.end());
    cout << (cs==copy ? "Stable" : "Not stable") << endl;
    for(auto&& c : cs) cout << c << endl;
}


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

#define ll long long int

int main() {

    int N;
    vector<pair<ll, ll>> T;

    cin >> N;

    ll A, B;

    for (ll i = 0; i < N; i++) {
        cin >> A >> B;
        T.push_back(make_pair(B, A));
    }

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

    int time = 0;
    for (int i = 0; i < N; i++) {
        time += T[i].second;
        if (time > T[i].first) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 6572
#include<cstdio>
using namespace std;
int n,m,x,y,cnt[100005];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i){
		scanf("%d%d",&x,&y);
		++cnt[x];++cnt[y];
	}
	for(int i=1;i<=n;++i) if(cnt[i]&1){puts("NO");return 0;}
	puts("YES");
}

Measured memory_bytes: 512
def f(x):
  a=x
  c=0
  while 1:
    A=list(set(a))
    B=[a.count(e) for e in A]
    b=[B[A.index(e)] for e in a]
    if a==b: return c,a
    a=b
    c+=1
  return

while 1:
  n=input()
  if n==0: break
  c,x= f(map(int,raw_input().split()))
  print c
  print " ".join(map(str,x))

Measured memory_bytes: 4232
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
signed main(){
    int n,m;
    cin>>n>>m;
    cout<<((n-m)*100+1900*m)*(1<<m)<<endl;
    return 0;
}

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

using ll = long long;
const ll amari = 1e9+7;
#define ben(a) a.begin(),a.end()

int main(){
	int n;
	string a,b,c;
	cin >> n >> a >> b >> c;
	int sum = 0;
	for(int i = 0; i < n; i++){
		if(a[i] == b[i] && b[i] == c[i] && a[i] == c[i])sum += 0;
		else if(a[i] != b[i] && b[i] != c[i] && a[i] != c[i])sum += 2;
		else sum++;
	}
	cout << sum << endl;
	return 0;
}

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

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

	int N; lglg K; cin >> N >> K;
	lglg a[N]; for (int i=0; i<N; ++i) cin >> a[i];
	lglg f[N]; for (int i=0; i<N; ++i) cin >> f[i];

	sort(a,a+N);
	sort(f,f+N,greater<lglg>());

	lglg result = 1e13;
	for (lglg b=1e13; b>=1; b/=2) {
		while (result-b >= 0) {
			lglg req = 0;
			for (int i=0; i<N; ++i) {
				lglg val = a[i]-(result-b)/f[i];
				if (val > 0) req += val;
			}
			if (req > K) break;
			result -= b;
		}
	}
	cout << result;
}

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

const int N=2e5+5;
int n,bit[N];
string s;
vector<int> pos[26];

void upd(int x){
	for(;x<N;x=x|(x+1))
		bit[x]++;
}

int get(int l,int r){
	int res=0;
	for(int x=r;x>=0;x=(x&(x+1))-1)
		res+=bit[x];
	for(int x=l-1;x>=0;x=(x&(x+1))-1)
		res-=bit[x];
	return res;
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>s;
	n=s.size();
	for(int i=0;i<n;++i)
		pos[s[i]-'a'].push_back(i);
	int odd=0;
	for(int i=0;i<26;++i)
		if(int(pos[i].size())&1) odd++;
	if((n%2==0&&odd>0)||(n%2==1&&odd!=1)) exit(puts("-1")*0);
	vector<pair<int,int>> p;
	ll res=0;
	for(int i=0;i<26;++i){
		if(pos[i].empty()) continue;
		if(int(pos[i].size())%2==1){
			int mid=pos[i][int(pos[i].size())/2];
			for(int j=0;j<26;++j)
				for(int k=0;k<int(pos[j].size())/2;++k){
					if(pos[j][k]>mid) ++res;
					if(pos[j][int(pos[j].size())-1-k]<mid) ++res;
				}
		}
		int l=0,r=pos[i].size()-1;
		while(l<r){
			p.emplace_back(pos[i][l],pos[i][r]);
			++l,--r;
		}
	}
	sort(p.begin(),p.end());
	//count number of inversions
	for(int i=0;i<int(p.size());++i){
		int l=p[i].first;
		int r=p[i].second;
		res+=2*get(0,l); //case ...A..A..B..B.
		res+=get(l,r); //case ...A..B..A..B..
		upd(r);
	}
	cout<<res<<'\n';
}




Measured memory_bytes: 6480
from itertools import combinations as cmb

n=int(input())

idx=[0,0,0,0,0]

for i in range(n):
    s=input()
    ss=s[0]
    if ss=="M":
        idx[0]+=1
    elif ss=="A":
        idx[1]+=1
    elif ss=="R":
        idx[2]+=1
    elif ss=="C":
        idx[3]+=1
    elif ss=="H":
        idx[4]+=1

ans=0
for a,b,c in cmb(idx,3):
    ans+=a*b*c

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

int sum(int x)
{
    int ret = 0;
    while (x)
    {
        ret += x % 10;
        x /= 10;
    }
    return ret;
}

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

    int n, a, b;
    cin >> n >> a >> b;

    int ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        int s = sum(i);
        if (a <= s && s <= b) ans += i;
    }

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int n,m;
const int maxy = 8000000;
bool ok[maxy];

void solve(){
    for(int i=0;i<maxy;i++) ok[i] = false;

    int cnt = 0;
    for(int i=m;i<maxy;i++){
        if(ok[i]) continue;
        ok[i] = true;
        for(int j=2;i*j<maxy;j++) ok[i*j] = true;
        cnt++;
        if(cnt == n) break;
    }

    for(int i=m;i<maxy;i++){
        if(!ok[i]){
            cout << i << endl;
            return;
        }
    }
}

int main(){
    while(1){
        cin >> m >> n;
        if(n==0 and m==0) break;
        solve();
    }
}



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

int main() {
    vector<int> A(3);
    cin >> A.at(0) >> A.at(1) >> A.at(2);
    
    sort(A.begin(), A.end());
    
    cout << A.at(0) << " " << A.at(1) << " " << A.at(2) << endl;
}


Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_map>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(container) container.begin(), container.end()
#define RevRange(container) container.rbegin(), container.rend()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
using namespace std;
using ll = long long;

int main(){
    Cin(int, n);
    Cin(int, m);
    Cins(int, n, as);
    
    unordered_map<int, int> ns;
    ns[0] = 1;
    int acc = 0;
    For(i, n){
        acc = (acc + as[i]) % m;
        ns[acc] ++;
    }

    ll ans = 0;
    for(auto e : ns){
        ans += (ll)e.second * (e.second-1) / 2;
    }
    Cout(ans);
}


Measured memory_bytes: 4108
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
 
int main() {
    int i,j,n;   
    string o;
    n=3;
    char s[n][n];
    rep(i,n){
      rep(j,n){
        cin>>s[i][j];
      }
    }
   rep(i,n){
     cout<<s[i][i];
   }
  cout<<endl;

}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program
{
    static void Main()
    {
        string input;
        while((input = Console.ReadLine()) != null)
        {
            double[] nums = input.Split(' ')
                                .Select(val => double.Parse(val))
                                .ToArray();
            double x = 0.0, y = 0.0;
            if(nums[0] != 0 && nums[4] != 0)
            {
                double a0 = nums[0];
                for(int i = 0; i < 3; i++)
                {
                    nums[i] /= a0;
                }
                double d1 = nums[3];
                for (int i = 3; i < 6; i++)
                {
                    nums[i] -= d1 * nums[i - 3];
                }
                double e2 = nums[4];
                for (int i = 4; i < 6; i++)
                {
                    nums[i] /= e2;
                }
                y = nums[5];
                x = nums[2] - nums[1] * y;
                
            }
            else if(nums[0] == 0 && nums[1] != 0)
            {
                y = nums[2] / nums[1];
                x = (nums[5] - nums[3] * y) / nums[4];
            }
            else if(nums[3] != 0 && nums[4] == 0)
            {
                x = nums[5] / nums[3];
                y = (nums[2] - nums[0] * x) / nums[1];
            }
            else Console.WriteLine("unknown");
            x = Math.Round(1000.0 * x, MidpointRounding.AwayFromZero) / 1000.0;
            y = Math.Round(1000.0 * y, MidpointRounding.AwayFromZero) / 1000.0;
            Console.WriteLine("{0:F3} {1:F3}", x, y);
        }
    }
}

Measured memory_bytes: 9620
import math
n=int(input())
l1=math.ceil(math.log(n,6))
l2=math.ceil(math.log(n,9))
dp=[i for i in range(n+1)]
for i in range(1,l1+1):
    for j in range(n):
        if j+6**i<n+1:
            dp[j+6**i]=min(dp[j]+1,dp[j+6**i])
for i in range(1,l1+1):
    for j in range(n):
        if j+9**i<n+1:
            dp[j+9**i]=min(dp[j]+1,dp[j+9**i])
print(dp[-1])

Measured memory_bytes: 45040
#include <stdio.h>
#include <stdlib.h>

int n,l[200];

int comp(const void *a, const void *b){
    int aa = *(int*)a;
    int bb = *(int*)b;
    if(aa<bb) return -1;
    if(aa==bb)return 0;
    return 1;
}

int main(){
    int i,sum;
    scanf("%d",&n);
    n*=2;
    for(i=0;i<n;i++){
        scanf("%d",&l[i]);
    }
    qsort(l,n,sizeof(int),comp);

    sum=0;
    for(i=0;i<n;i+=2){
        sum+=l[i];
    }
    printf("%d\n",sum);
}


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

#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)


using namespace std;
using ll = long long;

void solve() {
    int n, k;
    cin >> n >> k;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        sum += min(k - x, x);
    }
    cout << sum*2 << endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e12;


int main(){
    string s,t;
    cin>>s>>t;
    int n = s.size();
    int nt = t.size();
    vector<vector<ll> > g(n,vector<ll>(26,inf) );
    vector<ll> tt(nt,-1);
    for(int i=0;i<nt;i++) tt[i] = t[i]-'a';
    s = s + s;
    vector<ll> ss(2*n+1,-1);
    vector<bool> used(26,false);
    for(int i=0;i<nt;i++) used[tt[i]] = true;
    for(int i=0;i<2*n;i++)ss[i] = s[i]-'a';
    for(int i=0;i<26;i++){
	int now = 2*n;
	for(int j=2*n-1;j>=n;j--){
	    if(ss[j] == i){
		now = j;
	    }
	}
	if(now == 2*n){
	    if(used[i]){
		cout<<-1<<endl;
		return 0;
	    }
	    continue;
	}
	for(int j=n-1;j>=0;j--){
	    g[j][i] = now-j;
	    if(ss[j] == i) now = j;
	}
    }
    ll now = n;
    for(int i=n-1;i>=0;i--){
	if(tt[0] == ss[i])now = i;
    }
    for(int i=1;i<nt;i++){
	now += g[now%n][tt[i]];
    }
    cout<<now+1<<endl;

    return 0;
}


Measured memory_bytes: 27392
#define _GLIBCXX_DEBUG
// #include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>

typedef long long ll;
typedef std::vector< int > VI;

const double EPS = 1e-10;
const double PI  = acos(-1);
const ll     INF = 1 << 30;

int main(int argc, char* argv[])
{
  ll n;
  std::cin >> n;

  std::vector< ll > va(n, 0);
  std::vector< ll >::iterator it;
  std::map< ll, ll > judge;
  std::map< ll, ll >::iterator itm;
  // std::string s;

  for (ll i = 0; i < n; i++) {
    std::cin >> va[i];
  }

  for (it = va.begin(); it != va.end(); it++) {
    judge[*it] = judge[*it] == 0 ? 1 : 0;
  }

  ll ans = 0;
  for (itm = judge.begin(); itm != judge.end(); itm++) {
    ans += itm->second;
  }

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


Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include<map>
#include<set>
using namespace std;

int main() {
    int n, a;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(), v.end());
    bool f = 1;
    for (int i = 0; i < n - 1; i++) {
        if (v[i] == v[i + 1]) f = 0;
    }
    if (f) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 1528
# coding: utf-8
 
K_MAX = 2500
k, s = list(map(int, input().split()))
 
smz = [False] * (2 * K_MAX + 1)
 
for i in range(k + 1):
    if 0 <= s - i <= 2 * k: smz[s - i] = True
 
cnt = 0
for i in range(k + 1):
    for j in range(k + 1):
        if smz[i + j]:
            cnt += 1
 
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define inf 999999999
using namespace std;
int n,k;
string s;
int ans=0;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='L'&&i==0) continue;
		if(s[i]=='R'&&i==s.length()-1) continue;
		if(s[i]=='L'&&s[i-1]=='L') ans++;
		if(s[i]=='R'&&s[i+1]=='R') ans++;
	}
	cout<<min(ans+2*k,n-1)<<endl;
	return 0;
}

Measured memory_bytes: 512
import sys

input = sys.stdin.readline

N,M = map(int,input().split())

sel = [0] * N

for i in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    sel[a] += 1
    sel[b] += 1

ans = "YES"
for j in range(N):
    if sel[j] % 2 == 1:
        ans = "NO"

print(ans)


Measured memory_bytes: 3828
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include <random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ");
//#define double long double

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int MAX = 200060;
const double pi = acos(-1);
const ll INF = 1e16;


ll d[303][303];
ll dist[303][303];
void solve() {
	int N, M, L; cin >> N >> M >> L;
	REP(i, N) {
		REP(j, N) {
			d[i][j] = INF;
			d[j][i] = INF;
			dist[i][j] = INF;
			dist[j][i] = INF;
		}
	}
	REP(i, M) {
		int A, B, C; cin >> A >> B >> C;
		A--, B--;
		if (C <= L) {
			d[A][B] = C;
			d[B][A] = C;
		}
	}
	REP(k, N) {	//kが中継点
		REP(i, N) {
			REP(j, N) {
				d[i][j] = min(d[i][j], (d[i][k] + d[k][j]));
			}
		}
	}
	REP(i, N) {
		REP(j, N) {
			if (d[i][j] <= L)dist[i][j] = 1;
		}
	}
	REP(k, N) {	//kが中継点
		REP(i, N) {
			REP(j, N) {
				dist[i][j] = min(dist[i][j], (dist[i][k] + dist[k][j]));
			}
		}
	}
	int Q; cin >> Q;
	while (Q--) {
		int s, t; cin >> s >> t; s--, t--;
		int cost = dist[s][t];
		//print(cost);
		if (cost >= INF)print(-1)
		else print(cost-1);
	}
}


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

	solve();
}


Measured memory_bytes: 1920
use proconio::input;
use std::collections::BTreeSet;
use std::ops::Bound::Excluded;
use std::ops::Bound::Unbounded;
use rand::Rng;

const C:usize = 26;
const N_ITER:usize = 4000000;

fn main() {

    input!{
        d:usize,
        c:[i32;C],
        s:[[i32;C];d],
    };
    let mut t:Vec<usize> = vec![0;d];
    let mut occs = vec![BTreeSet::<i32>::new();C];
    for occ in &mut occs {
        occ.insert(-1);
    }
    let mut ans = 0;
    for (day,&ti) in t.iter().enumerate() {
        ans += s[day][ti];
        occs[ti].insert(day as i32);
        for j in 0..26 {
            let sc = (c[j] as i32) * ((day as i32) -*occs[j].iter().last().unwrap());
            ans -= sc;
        }
    }
    for occ in &mut occs {
        occ.insert(d as i32);
    }    

    let sum_lr = |l,r,n| n*(l+r)/2;
    let mut rng = rand::thread_rng();
    
    for turn in 0..N_ITER {
        let d = rng.gen::<usize>()%d;
        let q = rng.gen::<usize>()%C;
        let pre_q = t[d];
        let q = if q==pre_q {rng.gen::<usize>()%C} else {q};
        let pre_ans = ans;
        let mut try_change = |d:usize,q:usize|{
            let pre_q = t[d];
            ans-=s[d][pre_q];
            ans+=s[d][q];
            t[d]=q;
            let d = d as i32;
            // for pre_q
            let mut calc = |q:usize,is_ins:bool| {
                if is_ins {
                    occs[q].insert(d);
                }
                else {
                    occs[q].remove(&d);
                }
                let pre_d = *occs[q].range((Unbounded,Excluded(&d))).last().unwrap();
                let nex_d = *occs[q].range((Excluded(&d),Unbounded)).next().unwrap();
                let lbig = d - pre_d;
                let rbig = nex_d - pre_d -1;
                let lsml = 0;
                let rsml = nex_d-d-1;
                let sc = sum_lr(lbig,rbig,nex_d-d)-sum_lr(lsml,rsml,nex_d-d);
                sc
            };
            
            ans -= calc(pre_q,false)*c[pre_q];
            ans += calc(q,true)*c[q];
            ans
        };
        let now_ans = try_change(d,q);
        let x = rng.gen::<usize>()%N_ITER;
        if now_ans<=pre_ans{
            try_change(d,pre_q);
        }
    }

    for tv in t {
        println!("{}",tv+1);
    }
}




Measured memory_bytes: 2712
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define sz size()
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}




int main(void) {
	int a, b; cin >> a >> b;
	int num = 1, i = 0;
	while (num < b) {
		num += a - 1;
		i++;
	}
	cout << i << endl;
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> x(n);
	rep(i, n) cin >> x.at(i);

	int dist = __INT_MAX__;
	rep(p, 101){
		int d = 0;
		rep(i, n){
			d += pow((x.at(i)-p), 2);
		}
		dist = min(dist, d);
	}

	cout << dist << endl;

	return 0;
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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; }
 
const ll MAX = 100010;

class UnionFind
{
private:
    int par[MAX];
    int rank[MAX];
public:
    UnionFind(int N);
    int find(int x);
    void unite(int x, int y);
    bool same(int x, int y);
};

//コンストラクタ
UnionFind::UnionFind(int N)
{
    for(int i=0; i<N; i++)
    {
        par[i]=i;
        rank[i]=0;
    }
 }

//木の根を求める
int UnionFind::find(int x)
{
    if(par[x]==x)
    {
        return x;
    }
    else
    {
        return par[x]=find(par[x]);
    }
}
//位数の大きい木に統合する
void UnionFind::unite(int x, int y)
{
    x=find(x);
    y=find(y);

    if(x==y)
        return;

    if(rank[x] < rank[y])
    {
        par[x]=y;
    }
else
    {
        par[y]=x;
 
        if(rank[x]==rank[y])
        {
            rank[x]++;
        }
    }
}

//同じ根を持つならtrueを返す
bool UnionFind::same(int x, int y)
{
    return find(x)==find(y);
}

int main()
{
    int N, M, K;
    cin >> N >> M >> K;

    UnionFind *tree = new UnionFind(N);
    
    int cnt[N];
    rep(i, N)
    {
      cnt[i]=1;
    }
    
    vector<P> ab(M);
    
    rep(i, M)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        ab[i]=P(a, b);
        if(!tree->same(a,b))
        {
          int tmp = cnt[tree->find(a)];
          cnt[tree->find(a)]+=cnt[tree->find(b)];
          cnt[tree->find(b)]+=tmp;
          tree->unite(a, b);
        }
    }

    rep(i, N)
    {
      cnt[i]=cnt[tree->find(i)];
    }

    rep(i, M)
    {
      cnt[ab[i].first]--;
      cnt[ab[i].second]--;    
    } 

    rep(i, K)
    {
        int c, d;
        cin >> c >> d;
        c--; d--;
        if(tree->same(c, d))
        {
            cnt[c]--;
            cnt[d]--;
        }
    }
    
    rep(i, N)
    {
        cout << cnt[i]-1 << " ";
    }

    cout << endl;
 
    return 0;
}
 

//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find



Measured memory_bytes: 2816
import sys
n,m = map(int, input().split())
a = []
b = []
for i in range(n):
  a.append(list(input()))
  
for i in range(m):
  b.append(list(input()))


#

  
  
for i in range(n-m+1):
  for j in range(n-m+1):
    flag = True
    for x in range(m):
      for y in range(m):
        if b[x][y] !=  a[i+x][j+y]:
          flag = False
          break
      if not flag:
        break
    else:
      print("Yes")
      sys.exit()
     
    

print("No")
      

Measured memory_bytes: 3064
N, K = map(int, input().split())
MOD = 998244353
S = []

for _ in range(K):
    l, r = map(int, input().split())
    S.append((l, r))

dp = [0] * (N + 1)
accDp = [0] * (N + 1)
dp[1] = 1
accDp[1] = 1

for i in range(2, N + 1):
    for l, r in S:
        r, l = max(0, i - l), max(1, i - r)
        dp[i] += accDp[r] - accDp[l - 1]
    dp[i] %= MOD
    accDp[i] = (accDp[i - 1] + dp[i]) % MOD

print(dp[N])


Measured memory_bytes: 76948
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int A,B;
    cin >> A >> B;
    if(A>=13) {cout << B << endl; return 0;}
    if(A<=5)  {cout << 0 << endl; return 0;}
    cout << B/2 << endl;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll x,y;
    cin >> x  >> y;
    if(x+y<=1) cout << "Brown\n";
    else if(x+y>1 && abs(x-y)<=1) cout << "Brown\n";
    else cout << "Alice\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.lang.Math;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
			int A = sc.nextInt();
      		int B = sc.nextInt();
      		int H = sc.nextInt();
      		int M = sc.nextInt();
      		double rad = Math.abs(H*30 + M*0.5 - M*6);
      		if(rad >= 180){
            rad = 360 - rad;
            }
      		double C = 0;
      		
      		C  =  Math.pow(A,2)+Math.pow(B,2) - 2*A*B*Math.cos(Math.toRadians(rad));
      
		System.out.println(Math.pow(C,0.5));
	}
 
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n;
  cin >> n;

  int num = n;
  int a = 0;

  while(num > 0)
  {
    a += num % 10;
    num /= 10;
  }
  cout << (n % a == 0 ? "Yes" : "No");
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

int main() {
  int N, M, X, minM=1200001;
  cin >> N >> M >> X;
  vector<vector<int>> A(N, vector<int>(M+1));
  rep(i, N){
    rep(j, M+1) cin >> A.at(i).at(j);
  }
  rep(i, (1<<N)){
    bitset<12> bs(i);
    bool B=0;
    vector<int> SumA(M+1, 0);
    rep(j, N){
      rep(k, M+1) if(bs.test(j)) SumA.at(k)+=A.at(j).at(k);
    }
    rep(j, M){
      if(SumA.at(j+1)<X){
        B=1;
        break;
      }
    }
    if(B==0) minM=min(minM, SumA.at(0));
  }
  if(minM==1200001) cout << -1 << endl;
  else cout << minM << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define gc getchar_unlocked
#define cases int t;  cin>>t;   while(t--)
ll mod =1e9+7;
//template<typename T> 
inline ll pwr(ll base,ll n){ll ans=1;while(n>0){ if(n%2==1)ans=ans*base;  base=base*base; n/=2;} return ans;}
struct range{int l,h;}; 
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s,t;
    cin>>s>>t;

    int ct=0;
    for(int i=0;i<s.length();i++)
    {
      if(s[i]==t[i])ct++;
    }
    cout<<ct;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,n) for(ll i=n-1;i>=0;i--)
#define rloop(i,a,b) for(ll i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define precision cout<<fixed<<setprecision(10)
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
#define setbits(x) __builtin_popcountll(x)
const double pi=3.1415926535897932384626;
//const ll mod = 998244353;
const ll mod=1e9+7;
int main()
{
  IOS
  ll x;
  cin>>x;
  if(x>=400&&x<600) cout<<8;
  else if(x>=600&&x<800) cout<<7;
  else if(x>=800&&x<1000) cout<<6;
  else if(x>=1000&&x<1200) cout<<5;
  else if(x>=1200&&x<1400) cout<<4;
   else if(x>=1400&&x<1600) cout<<3;
     else if(x>=1600&&x<1800) cout<<2;
       else if(x>=1800&&x<2000) cout<<1;




  return 0;
}

Measured memory_bytes: 3608
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D[] = new int[N];
		for(int i=0; i<N; i++) {
			D[i] = sc.nextInt();
		}
		Arrays.sort(D);
		int count = 1;
		for(int i=0; i<N-1; i++) {
			if(D[i]<D[i+1])count++;
		}
		System.out.println(count);
		sc.close();
	}

}

Measured memory_bytes: 22100
#include <iostream>

using namespace std;
int main(void){
    // Your code here!
    int f=0;
    int s;
    
    cin >> s;
    
    int uu=s/100;
    int dd=s-uu*100;
    if(uu <= 12 && uu!=0){
        if(dd<=12&& dd!=0){
            cout << "AMBIGUOUS"<<endl;
        } else cout << "MMYY"<<endl;
    }else if(dd <= 12 && dd!=0){
        if(uu<=12&& uu!=0){
            cout << "AMBIGUOUS"<<endl;
        } else cout << "YYMM"<<endl;
    }else{
        cout <<"NA"<<endl;
    }
    
    

    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
ac=[False for i in range(N+1)] # 1-i
wa=[0 for i in range(N+1)]
for i in range(M):
    p,S=input().split()
    p=int(p)
    if not ac[p]:
        if S=='AC':
            ac[p]=True
        elif S=='WA':
            wa[p]+=1
ans_ac=sum(ac)
ans_p=sum([wa[i] for i in range(N+1) if ac[i]])

# print(ac)
# print(wa)

print(ans_ac,ans_p)

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

int main()
{
  int n, x;
  map <int, int> cnt;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> x;
    cnt[x]++;
  }

  if (cnt.size() == 1 && cnt.count(0)) cout << "Yes" << endl;
  else if (n % 3 == 0)
  {
    int ans = 1;
    vector <int> a;
    for (auto u : cnt)
      if (u.second % (n / 3)) ans = 0;
      else
        for (int i = 0; i < u.second / (n / 3); i++)
          a.push_back(u.first);
    ans &= (a.size() == 3 && (a[0] ^ a[1]) == a[2]);
    cout << (ans ? "Yes" : "No") << endl;
  }
  else cout << "No" << endl;
}


Measured memory_bytes: 3840
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  int cnt=0;
  rep(i, N-1){
    if(S[i]==S[i+1]) cnt++;
  }
  int ans = min(cnt+2*K, N-1);
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define all(a) a.begin(), a.end()
#define len(a) (int)a.size()

using namespace std;

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

void solve(){
	int n = 5;
	set <int> s;
	for(int i = 0; i < n; i++){
		int tmp;
		cin >> tmp;
		s.insert(tmp);
	}
	
	for(int i = 1; i <= 5; i++)
		if(!s.count(i)){
			cout << i << endl;
			return;
		}	
}

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


Measured memory_bytes: 3580
from collections import Counter
class Prime:
    def __init__(self, N):
        smallestPrime = [i for i in range(N + 1)]

        for i in range(2, N + 1):
            if smallestPrime[i] != i:
                continue
            for p in range(i * 2, N + 1, i):
                if smallestPrime[p] == p:
                    smallestPrime[p] = i

        self.smallestPrime = smallestPrime

    def isPrime(self, n):
        return n > 1 and self.smallestPrime[n] == n

    def factorization(self, n):
        ret = Counter()
        while n > 1:
            p = self.smallestPrime[n]
            ret[p] += 1
            n //= p
        return ret

N = int(input())
prime = Prime(N + 100)

ans = 0
for c in range(1, N):
    cnt = 1
    for c in prime.factorization(N - c).values():
        cnt *= c + 1
    ans += cnt
print(ans)


Measured memory_bytes: 148528
#include <iostream>
#include <vector>
#include <climits>
#include <stdint.h>
using namespace std;

int sum(int d) {
  int result = 0;
  while (0 < d) {
    result += d % 10;
    d /= 10;
  }
  return result;
}

int solve(int n) {
  int min = INT_MAX;
  for (int a = 1; a < n; ++a) {
    int b = n - a;
    int accum = sum(a) + sum(b);
    if (accum < min) {
      min = accum;
    }
  }
  return min;
}

void test() {
  cout << (solve(15) == 6) << "\n";
  cout << (solve(100000) == 10) << "\n";
}

int main() {
  int n;
  cin >> n;
  cout << solve(n) << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

template <typename T>
T pow(T a, ll n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= a; 
        a *= a;
        n >>= 1;
    }
    return ret;
}

template <ll mod>
class ModInt {
private:
    ll num;
public:
    ModInt() {};
    ModInt(ll n) { num = n % mod; }
    ModInt inv() const { return pow(*this, mod-2); }
    explicit operator ll() const { return num; }

    ModInt& operator+=(const ModInt& a) {
        num += a.num; 
        if (num >= mod) num -= mod; 
        return *this;
    }
    ModInt& operator-=(const ModInt& a) {
        if (num < a.num) num += mod;
        num -= a.num;
        return *this;
    }
    ModInt& operator*=(const ModInt& a) {
        num = num * a.num % mod;
        return *this;
    }
    ModInt& operator/=(const ModInt& a) { return *this *= a.inv(); }
    friend ModInt operator+(const ModInt& a, const ModInt& b) { return ModInt(a) += b; }
    friend ModInt operator-(const ModInt& a, const ModInt& b) { return ModInt(a) -= b; }
    friend ModInt operator*(const ModInt& a, const ModInt& b) { return ModInt(a) *= b; }
    friend ModInt operator/(const ModInt& a, const ModInt& b) { return ModInt(a) /= b; }

    friend ostream& operator<<(ostream& os, const ModInt& a) { return os << a.num; }
    friend istream& operator>>(istream& is, ModInt& a) {
        ll tmp;
        is >> tmp;
        a.num = tmp % mod;
        return is;
    }
};
using mint = ModInt<1000000007>;

mint dp[201][100001];

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> s(n);
    for (auto &e: s) cin >> e;
    sort(s.begin(), s.end(), greater<int>());

    dp[0][x] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= x; ++j) {
            dp[i+1][j%s[i]] += dp[i][j];
            dp[i+1][j] += dp[i][j] * (n - i - 1);
        }
    }

    mint ans = 0;
    for (int j = 0; j <= x; ++j) {
        ans += dp[n][j] * j;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 156544