akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

int N;
vector<vector<int>> G;
int A[1001000] = {INF};
int T[1001000] = {INF};
int used_a[1001000] = {-1};
int used_t[1001000] = {-1};

void dfs_a(int node, int depth) {
    used_a[node] = 1;
    A[node] = depth;
    for (auto i : G[node]) {
        if (used_a[i] != 1) {
            dfs_a(i, depth + 1);
        }
    }
}

void dfs_t(int node, int depth) {
    used_t[node] = 1;
    T[node] = depth;
    // if (depth < A[node]) {
    for (auto i : G[node]) {
        if (used_t[i] != 1) {
            dfs_t(i, depth + 1);
        }
    }
    //}
}

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

    cin >> N;
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G.resize(N + 2); // adjacency list

    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs_a(v, 0);
    dfs_t(u, 0);

    int ans = 0;
    REP(i, N) {
        if (A[i] > T[i]) {
            chmax(ans, A[i] - 1);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9856
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <functional> 
// using namespace __gnu_pbds;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MaX 300005
using namespace std;

 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
   	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
// typedef tree<int, null_type, less<int>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//     new_data_set; 
bool isprime(ll n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}
const int N=1e3+5;
int a[N];
int main()
{
	fast();
	int n,i,k;
	cin>>n>>k;
	rep(i,n)
		cin>>a[i];
	int ans=0;
	sort(a,a+n);
	rep(i,k)
		ans+=a[i];
	cout<<ans;
}






/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀⠀⠀⠀
*/

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int n;cin>>n;
    for(int i=0;i<n;i++)
    {
    	cout<<"ACL";
    }
    return 0;
}

Measured memory_bytes: 3608
s = raw_input()

ans = 0

def dfs(s, nw):
    global ans
    if s == '':
        ans += eval(nw)
        return
    if nw == '':
        dfs(s[1:], nw + s[0])
    else:
        dfs(s[1:], nw + s[0])
        dfs(s[1:], nw + '+' + s[0])

dfs(s, '')
print ans


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
ll cnt = 0;
const ll MOD = 1e9 + 7;
int H,W;vector<vector<bool>> visited;
vector<string> S; ll b,w;

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

void dfs(int s,int t){
  visited[s][t] = true;
  if( S[s][t] == '#'){ b++;} else{ w++;}
  for(int k = 0; k < 4; k++){
    int p = s+dx[k]; int q = t+dy[k];
    if( p < 0 || p >= H || q < 0 || q >= W){ continue;}
    if(S[p][q] != S[s][t]){
     if(visited[p][q]){ //こうなることはないと思うが...
                       continue;}
      dfs(p,q);}
  }
  return ;
}
      
       
    
  
int main(){
  cin >> H >> W; S.resize(H);
  visited = vector<vector<bool>> (H,vector<bool>(W,false));
  for(int i = 0; i < H; i++){ cin >> S[i];}
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(visited[i][j]){continue;}
      b = 0; w = 0;
      dfs(i,j);  cnt += b*w; 
    }
  }
  
      
 cout << cnt << endl; return 0;}

Measured memory_bytes: 15488
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var AL=Arr.shift();
var abc=["",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"];
abc=abc.map(function(v){return v.split("");});
for(var i=0;i<AL;i++){
   var arr=Arr[i].split("").map(Number);
   var str="";
   var a="";
   var n=-1;
   arr.forEach(function(v){
      if(v>0){
         n++;
         a=abc[v][n%abc[v].length];
      }else{
         str+=a;
         n=-1;
         a="";
      }
   });
console.log(str);
}

Measured memory_bytes: 10592
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << "\n"
using namespace std;
using ll = long long;

signed main() {
    IO;
    int ans = 0, l, r, d;
    cin >> l >> r >> d;
    for(int i = l; i <= r; ++i) if(i % d == 0) ++ans;
    cout << ans;
    // int tests = 1;
    // cin >> tests;
    // for(int test = 1; test <= tests; ++test) {
        
    // }
    return 0;
}

Measured memory_bytes: 3604
#C - Train Ticket
A = list(map(int,input()))    

for i in range(1<<3):
    culc = A[0]
    box = []
    for j in range(3):
        mask = 1<<j
        if mask & i != 0:
            culc += A[j+1]
            box.append('+')
        else:
            culc -= A[j+1]
            box.append('-')
    if culc == 7:
        break
ans = [0]*7
ans[::2]=[str(i) for i in A]
ans[1::2]=box
ans.append('=7')
print(''.join(ans))

Measured memory_bytes: 9208
#include <iostream>


using namespace std;

int main()
{
int S;
cin>>S;
int a_1=S/100;
int a_2=S%100;
if((1<=a_1 && a_1<=12) && (1<=a_2 && a_2<=12)){
  cout<<"AMBIGUOUS"<<endl;
}
else if(1<=a_1 && a_1<=12){
  cout<<"MMYY"<<endl;
}
else if(1<=a_2 && a_2<=12){
  cout<<"YYMM"<<endl;
}
else{
  cout<<"NA"<<endl;
}
return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
	int n;
	
	scanf("%d",&n);
	if ((n%2)==1) n=n*2;
	printf("%d",n); 
	
	return 0;
}


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

int const MAXH = 10;
int const MAXW = 1000;
int const MAXHS = 1 << MAXH-1;

int S[MAXW][MAXH], H, W, K;
int buf[MAXH], buf1[MAXH];

int main() {
  std::cin >> H >> W >> K;
  int HS = 1 << H-1;
  for(int h = 0; h < H; ++h) {
    std::string s; std::cin >> s;
    for(int w = 0; w < W; ++w) S[w][h] = (s[w]=='0')? 0: 1;
  }
  int ans = H+W;
  for(int s = 0; s < HS; ++s) {
    int curr = 0;
    for(int t = s; t > 0; t&=t-1) ++curr;
    std::fill_n(buf, H, 0);
    for(int w = 0; w < W; ++w) {
      std::copy_n(S[w], H, buf1);
      for(int h = 1; h < H; ++h) if((s&1<<h-1)==0) buf1[h]+=buf1[h-1];
      for(int h = 0; h < H; ++h) if(buf1[h] > K) {
        curr = H+W;
      }
      bool cut = false;
      for(int h = 0; h < H; ++h) {
        buf[h] += buf1[h];
        if(buf[h] > K) { cut = true; break; }
      }
      if(cut) {
        ++curr;
        std::copy_n(buf1, H, buf);
      }
    }
    ans = std::min(ans, curr);
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c,d,e,i,j,l=1,max=0;
	int n[200005];
	int m[200005];
scanf("%d",&a);
e=a;c=a;
for(i=1;i<=a;i++)
{
scanf("%d",&n[i]);
m[i]=n[i];	
}
sort(m+1,m+1+a);
l=1;
while(e--)
{
	if(m[a]==n[l])
	printf("%d\n",m[a-1]);
	else
	printf("%d\n",m[a]);
	l++;
}
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int H, W; cin >> H >> W;
    vector<vector<bool>> visited(H, vector<bool>(W));
    vector<string> A(H);
    queue<tuple<int, int, int>> Q;
    for (auto &s : A) cin >> s;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (A[i][j] == '#') {
                Q.emplace(0, i, j);
            }
        }
    }
    int di[] = {+1, -1, 0, 0};
    int dj[] = {0, 0, +1, -1};
    int ans = 0;
    while (!Q.empty()) {
        int dist, i, j; tie(dist, i, j) = Q.front();
        Q.pop();
        if (visited[i][j]) continue;
        visited[i][j] = true;
        ans = max(dist, ans);
        for (int k = 0; k < 4; k++) {
            int newi = i + di[k];
            int newj = j + dj[k];
            if (0 <= newi && newi < H && 0 <= newj && newj < W) {
                Q.emplace(dist+1, newi, newj);
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

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

int s, n, t, m, p;

bool minutes[7 * 24 * 60];

int wbits, tbits;

double ck(int start){
  int cnt = 0;
  for(int i = 0; i < m; i++, start += t){
    bool flag = true;
    for(int j = 0; j <= s; j++){
      if(!minutes[(start + j) % (7 * 24 * 60)]){
        flag = false;
        break;
      }
    }
    cnt += flag;
  }
  return( 1.0 - pow( 1.0 - 1.0/p, (double)cnt * n));
}


inline int todays(int i){
  return(i / (24 * 60));
}
inline bool totime(int i){
  int tm = i % (24 * 60) / 24;
  return(tm >= 18 || tm < 6);
}

int main(){
  string weekday, time ;
  while( cin >> s >> n >> t >> weekday >> time >> p >> m, m){
    if(weekday == "All") wbits = (1 << 7) - 1;
    else wbits = 1 ;
    if(time == "Night") tbits = 1;
    else if(time == "Day") tbits = 2;
    else tbits = 3; 

    double ans = 0.0;
    for(int i = 7 * 24 * 60 - 1; i >= 0; i--){
      if(wbits >> todays(i) & 1 && (tbits & (1 << ((i/360+1)%4/2)))) minutes[i] = true;
      else minutes[i] = false;
    }

    for(int i = 24 * 60 - 1; i >= 0; i--){
      ans = max( ans, ck(i));
    }
    cout << fixed << setprecision(16) << ans << endl;
  }
}

Measured memory_bytes: 1344
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int main() {
  ll n, m;
  scanf("%lld %lld", &n, &m);
  ll ans;
  ans = min(n, m/2);
  m -= ans * 2;
  ans += m/4;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 888
N, M = gets.split.map(&:to_i)
COSTS = [0,2,5,5,4,5,6,3,7,6]
A = gets.split.map(&:to_i).sort.reverse

MIN = A.map do |a|
  COSTS[a]
end.min

# dp[i]: マッチをi本使ったときの最大の桁数
# dp[i] = max(dp[i - COSTS(A[j])] + 1| j = 1 ~ M)
dp = Array.new(N + 7) {-1}

dp[0] = 0

0.upto(N - 1) do |i|
  next if dp[i] == -1

  A.each do |a|
    dp[i + COSTS[a]] = [dp[i + COSTS[a]], dp[i] + 1].max
  end
end

ans = ''
remaining = dp[N]
match = N

# 大きい桁から決めていく
while match > 0
  # p "match #{match} remaining #{remaining}"
  A.each do |a|
    if match - COSTS[a] < 0
      next
    end

    if dp[match - COSTS[a]] < 0
      next
    end

    # p "a: #{a} digit: #{dp[match - COSTS[a]]} from #{match - COSTS[a]}"

    if dp[match - COSTS[a]] + 1 == remaining
      # p "choose #{a}"
      ans = ans + a.to_s
      match -= COSTS[a]
      remaining -= 1
      break
    end
  end
end

puts ans


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

bool is_integer(double x){
    return floor(x)==x;
}

int main(){
    int64_t h;cin >> h;
    int64_t result =0;
    double fl =log2f(h);

    int64_t count=0;
    while(h>=1){
        result+=pow(2,count);
        count++;
        h/=2;
    }
    cout <<result<<endl;

}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a, b, c, d, e, f;
int main() {
	while (true) {
		cin >> a >> b >> c >> d >> e >> f;
		if (a + b + c + d + e + f == 0) { break; }
		int money = a * 15 + b * 15 + c * 7 + d * 2;
		int times = f - e - 5 * a - 3 * b;
		int sikin = times * 3;
		money -= sikin;
		money += a * 5 * 13 + b * 3 * 13;
		cout << 100 + money << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc079.contest.atcoder.jp/tasks/abc079_c>
問題文============================================================
 駅の待合室に座っているjoisinoお姉ちゃんは、切符を眺めています。
 
 切符には 4 つの 0 以上 9 以下の整数 A,B,C,D が整理番号としてこの順に書かれています。
 
 A op1 B op2 C op3 D = 7 となるように、op1,op2,op3 に + か - を入れて式を作って下さい。
 
 なお、答えが存在しない入力は与えられず、また答えが複数存在する場合はどれを出力してもよいものとします。
 
=================================================================

解説=============================================================
貪欲全探索
================================================================
*/
bool f = false;

void solve(int dep,const string& S,string op,int sum) {
    if (f)return;
    if (dep == 4) {
        if (sum == 7) {
            f = true;
            cout << (char)S[0] << (char)op[0] << (char)S[1] <<(char)op[1]
                <<(char)S[2] << (char)op[2] <<(char) S[3] << "=7" << endl;
        }
        return;
    }
    string temp1 = op;
    string temp2 = op;
    
    temp1 += '+'; solve(dep + 1, S, temp1, sum + (S[dep] - '0'));
    temp2 += '-'; solve(dep + 1, S, temp2, sum - (S[dep] - '0'));
}

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    string ABCD; cin >> ABCD;
    string op;
    solve(1,ABCD,op,ABCD[0] - '0');
    return 0;
}


Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
a = N.times.map { gets.split.map(&:to_i) }

foodsLove = Array.new(M)
allLoveCount = 0
M.times{|i| foodsLove[i]=0}

N.times { |people|
  a[people][0].times do |foodsnum|
      foodsLove[a[people][foodsnum+1]-1] += 1
  end
}

foodsLove.each do |f|
  if f==N
    allLoveCount+=1
  end
end

print allLoveCount

Measured memory_bytes: 3836
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdin = new Scanner(System.in);
		String s =stdin.next();
		int cnt=0;
		for(int i=0;i<3;i++) {
			if(s.charAt(i)=='o') {
				cnt++;
			}
		}
		System.out.println(100*cnt+700);


	}

}


Measured memory_bytes: 21844
n=int(input())
a,b=map(int,input().split())
c=int(input())
A=a
C=c
top=[]
for i in range(n):
    top.append(int(input()))
top.sort(reverse=True)
ans=C/A
for i in top:
    C+=i
    A+=b
    now=C/A
    if ans<now:ans=now
    elif ans>=now:break
print(int(ans))


Measured memory_bytes: 5596
from sys import stdin
from itertools import product

N, *xyh = map(int, stdin.read().split())

xyh = list(zip(*[iter(xyh)] * 3))
xyh.sort(key=lambda x: -x[2])

x1, y1, h1 = xyh[0]
for X, Y in product(range(101), range(101)):
    H = h1 + abs(x1-X) + abs(y1-Y)
    if all(max(H-abs(x-X)-abs(y-Y), 0) == h for x, y, h in xyh[1:]):
        print(X, Y, H)
        break

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int n, k; cin >> n >> k;
  cout << n - (k - 1) << endl;
}


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

typedef pair<string,string> P;

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

  int n; cin >> n;
  string s; cin >> s;

  map<P,int> mp;
  for(int i = 0; i < 1 << n; i++){
    string red,blue;
    for(int j = 0; j < n; j++){
      if(1 & i >> j) red += s[j];
      else blue += s[j];
    }
    mp[P(red,blue)] += 1;
  }

  int ans = 0;
  for(int i = 0; i < 1 << n; i++){
    string red,blue;
    for(int j = 0; j < n; j++){
      if(1 & i >> j) red += s[n+j];
      else blue += s[n+j];
    }

    reverse(red.begin(),red.end());
    reverse(blue.begin(),blue.end());
    if(mp.find(P(red,blue)) != mp.end()){
      ans += mp[P(red,blue)];
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 46080
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n;
	long long int a[100000];
	cin >> n;
	int count[3];
	count[0] = 0;
	count[1] = 0;
	count[2] = 0;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		if(a[i] % 4 == 0){
			count[0]++;
		}else if(a[i] % 2){
			count[2]++;
		}else{
			count[1]++;
		}
	}
	if(count[2] <= count[0]){
		cout << "Yes" << endl;
		return 0;
	}
	if(count[1] == 0 && count[2] == count[0] + 1){
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll D, N;
    cin >> D >> N;

    if(D==0){
        if(N==100){
            cout << N+1 << endl;
        }
        else{
            cout << N << endl;
        }
        return 0;
    }
    if(D==1){
        if(N==100){
            cout << N*100 + 100 << endl;
        }
        else{
            cout << N*100 << endl;
        }
        return 0;
    }
    if(D==2){
        if(N==100){
            cout << N*10000 + 10000 << endl;
        }
        else{
            cout << N*10000 << endl;
        }
        return 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 +7;
const ll MAXN = 1e6 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,k;
	cin>>n>>k;
	ll base=1,res=0;
	ll cnt=0;
	while(n){
		cnt++;
		n/=k;
	}
	cout<<cnt;
	return 0;
}


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

int main(){
  int a[41]={1,4,8,9,16,25,27,32,36,49,64,81,100,121,125,128,144,169,196,216,225,243,256,289,324,343,361,400,441,484,512,529,576,625,676,729,784,841,900,961,1000};
  int x;
  cin >> x;
  int ans=0;
  for(int i=0; i<41; i++){
    if(a[i] > x){
      break;
    }
    ans = a[i];
  }
  cout << ans << endl;
}


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

#define int long long

const int N = 3e5 + 7;
const int mod = 1e9 + 7;

void add(int &a, int b) {
    a += b;
    if (a >= mod) a -= mod;
    if (a < 0) a += mod;
}

int mul(int a, int b) {
    return (a * (ll) b) % mod;
}

int pw(int x, int n) {
    int res = 1;
    while (n > 0) {
        if (n % 2 == 1) {
            res = mul(res, x);
            n--;
        }
        x = mul(x, x);
        n /= 2;
    }
    return res;
}

int fact[N];
int rfact[N];

int C(int n, int k) {
    return mul(fact[n], mul(rfact[n - k], rfact[k]));
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    fact[0] = 1;
    for (int i = 1; i < N; i++) {
        fact[i] = mul(fact[i - 1], i);
    }
    rfact[N - 1] = pw(fact[N - 1], mod - 2);
    for (int i = N - 2; i >= 0; i--) {
        rfact[i] = mul(rfact[i + 1], i + 1);
    }
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    int ans = 0;
    for (int j = b + 1; j <= w; j++) {
        int i = h - a;
        int cnt = C(i - 1 + j - 1, i - 1);
        int kek = C(h - i + w - j - 1, h - i - 1);
        add(ans, mul(cnt, kek));
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i = a; i<n; i++)
#define per(i,a,n) for (int i = n-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define all(now) (now).begin(),(now).end()
#define fi first
#define se second
#define SZ(now) ((int)(now).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod = 1000000007;
inline int read(int &n){char c=getchar();int x=0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+(c-'0');c=getchar();}return n = x*f;}
ll powmod(ll a,ll b,ll mod) {ll res = 1; a%=mod; assert(b>=0); for(;b; b>>=1){if(b&1)res = res*a%mod; a = a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N = 1e2+7;
int T,n,m;
int x[N],y[N],d[N];
int main()
{
    //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int L;
    scanf("%d", &L);

    if(L<=60){
        printf("2 %d\n", L);
        rep(i,0,L){
            printf("1 2 %d\n", i);
        }
        return 0;
    }

    int len = 0;
    while(1<<len <= L)
        ++len;

    n = len, m = 0;
    rep(i,0,len-1){
        x[++m] = i + 1;
        y[m] = i + 2;
        d[m] = 0;
        x[++m] = i + 1;
        y[m] = i + 2;
        d[m] = 1<<i;        
    }

    per(i,0,len-1){
        if(L&(1<<i)){
            x[++m] = i + 1;
            y[m] = n;
            d[m] = L >> (i + 1) << (i + 1);
        }
    }

    printf("%d %d\n", n, m);
    rep(i,1,m+1){
        printf("%d %d %d\n", x[i], y[i], d[i]);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    uint64_t total = 0;
    for(int i=1;i<n+1;i++){
        if((i%3 != 0)  && (i%5 != 0)){
            total += i;
        }
    }

    cout << total;
    
    return 0;
}

Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

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

        final int n = sc.nextInt();

        final int[] d = new int[n];
        for (int i = 0; i < n; i++) {
            d[i] = sc.nextInt();
        }

        int[] x = new int[100010];

        for (int i = 0; i < n; i++) {
            x[d[i]]++;
        }

        for (int i = 1; i < 100010; i++) {
            x[i] += x[i-1];
        }

        System.out.println(IntStream.of(x).filter(i -> i == (n / 2)).count());

    }
}


Measured memory_bytes: 51012
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int a, b, d;
	while(cin >> a >> b >> d) {
		if(a == 0 && b == 0 && d == 0) break;

		int g = __gcd(a, b);
		a /= g;
		b /= g;
		d /= g;

		int x = INF, y = INF, sum = INF, prod = INF;

		for(int i = 0; i < 50000; i++ ) { 
			int c = d - a * i;
			if(abs(c) % b == 0) {
				int j = abs(c / b);

				if(i + j < sum) {
					sum = i + j;
					prod = a*i + b*j;
					x = i;
					y = j;
				} else if(i + j == sum && a*i + b*j < prod) {
					sum = i + j;
					prod = a*i + b*j;
					x = i;
					y = j;
				}
			}
		}

		for(int j = 0; j < 50000; j++) {
			int c = d - b * j;
			if(abs(c) % a == 0) {
				int i = abs(c / a);
				if(i + j < sum) {
					sum = i + j;
					prod = a*i + b*j;
					x = i;
					y = j;
				} else if(i + j == sum && a*i + b*j < prod) {
					sum = i + j;
					prod = a*i + b*j;
					x = i;
					y = j;
				}
			}
		}

		cout << x << " " << y << endl;
	}
	return 0;
}

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

vector<ll> ans;
vector<vector<int>> node;

void score(int now, int parent=-1) {
    rep(i, node[now].size()) {
        if (node[now][i] == parent) continue;
        ans[node[now][i]] += ans[now];
        score(node[now][i], now);
    }
}

void solve() {
    int n, q;
    cin >> n >> q;
    ans.resize(n);
    node.resize(n);

    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        node[a].push_back(b);
        node[b].push_back(a);
    }

    rep(i, q) {
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    score(0);
    rep(i, n) {
        if (i == 0) {
            cout << ans[i];
        } else {
            cout << " " << ans[i];
        }
    }
    cout << endl;
}

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


Measured memory_bytes: 24320
#include<iostream>
#include<algorithm>
using namespace std;
int H,W,K;
string s[10];
main()
{
	cin>>H>>W>>K;
	for(int i=0;i<H;i++)cin>>s[i];
	int ans=1e9;
	for(int z=0;z<1<<H-1;z++)
	{
		int cnt[15]={};
		int now=__builtin_popcount(z);
		bool out=false;
		for(int j=0;j<W;j++)
		{
			int id=0;
			bool take=false;
			for(int k=0;k<H;k++)
			{
				cnt[id]+=s[k][j]=='1';
				if(cnt[id]>K)take=true;
				if(z>>k&1)id++;
			}
			if(take)
			{
				now++;
				for(int k=0;k<=id;k++)cnt[k]=0;
				id=0;
				for(int k=0;k<H;k++)
				{
					cnt[id]+=s[k][j]=='1';
					if(cnt[id]>K)out=true;
					if(z>>k&1)id++;
				}
			}
		}
		if(!out&&ans>now)
		{
			ans=now;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
W ,H, N = map(int,input().split())

x_min = 0
x_max = W
y_min = 0
y_max = H

for i in range(N):
    x_tmp, y_tmp, a_tmp = map(int,input().split())
    if a_tmp == 1:
        x_min = max(x_tmp, x_min)
    elif a_tmp == 2:
        x_max = min(x_tmp, x_max)
    elif a_tmp == 3:
        y_min = max(y_tmp, y_min)
    else:
        y_max = min(y_tmp, y_max)

if x_min >= x_max or y_min >= y_max:
    print(0)
else:
    print((x_max-x_min)*(y_max-y_min))

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
    stack<int> S;
    S.push(r);
    color[r] = c;
    
    while(!S.empty()) {
        int u = S.top();
        S.pop();
        for(int i = 0; i < G[u].size(); i++) {
            int v = G[u][i];
            if(color[v] == NIL) {
                color[v] = c;
                S.push(v);
            }
        }
    }
}

void assignColor() {
    int id = 1;
    for(int i = 0; i < n; i++) color[i] = NIL;
    for(int u = 0; u < n; u++) {
        if(color[u] == NIL) dfs(u, id++);
    }
}

int main() {
    int s, t, m, q;
    
    cin >> n >> m;
    
    for(int i = 0; i < m; i++) {
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    
    assignColor();
    
    cin >> q;
    
    for(int i = 0; i < q; i++) {
        cin >> s >> t;
        if(color[s] == color[t]) {
            cout << "yes" << endl;
        }else {
            cout << "no" << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 8948
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n,k;cin>>n>>k;
    ll r,s,p;cin>>r>>s>>p;
    string t;cin>>t;
    bool state[n];mset(state);
    ll cnt=0;
    for(int i=0;i<n;i++){
        if(i<k){
            if(t[i]=='r')cnt+=p;
            if(t[i]=='p')cnt+=s;
            if(t[i]=='s')cnt+=r;
            state[i]=true;
            continue;
        }
        if(!state[i-k]||t[i]!=t[i-k]){
            if(t[i]=='r')cnt+=p;
            if(t[i]=='p')cnt+=s;
            if(t[i]=='s')cnt+=r;
            state[i]=true;
            continue;
        }
    }
    cout<<cnt<<"\n";
}


Measured memory_bytes: 3780
#include<stdio.h>

int main(){
   int s,a[1000000],n;
   scanf("%d",&s);
   a[0] = s;
   for(int i = 1;i < 1000000;i++){
      if(a[i-1]%2 == 0){
         a[i] = a[i-1]/2;
      }else{
         a[i] = a[i-1]*3+1;
      }
   }
   for(int i = 1;i < 1000000;i++){
      for(int j = 0;j < i;j++){
         if(a[i] == a[j]){
            printf("%d",i+1);
            return 0;
         }
      }
   }
}


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

Aset = set(A)
lst = {}
for i in Aset:
    lst[i] = 0
    
for i in range(N):
    lst[A[i]] += 1

Q = int(input())

# 最初の全てのA_iの和
ans_init = 0
for i in lst:
    ans_init += i*lst[i]

# 初期値からのプラスマイナス分
ans_pm = 0
ans = []
for i in range(Q):
    B, C = map(int, input().split())
    if B in lst:
        # 更新する前に、lst中のkeyがBの個数をBnumに記憶しておく。
        Bnum = lst[B]
        # lstを更新
        if C in lst:
            lst[C] += lst[B]
            lst.pop(B)
        else:
            lst[C] = lst[B]
            lst.pop(B)
    
        # 初期値からの増減分をここで算出。
        ans_pm += Bnum*(C-B)
        ans.append(ans_init + ans_pm)
        
    else:
        ans.append(ans_init + ans_pm)

for i in ans:
    print(i)

Measured memory_bytes: 26100
#include <iostream>
#include <vector>
using namespace std;
//
bool negative=true;
struct edge{int from;int to;int cost;};
struct bellman{
	//
	int v,e;
	vector<edge> G;
	vector<int> D;
	//
	bellman(int n,int m){
		v=n;e=m;
		D.resize(v);
		fill(D.begin(),D.end(),1e9+7);
	}
	//
	void add_edge(int from,int to,int cost){
		G.push_back((edge){from,to,cost});
	}
	//
	vector<int> dist(int s){
		D[s]=0;
		for(int i=0;i<v;i++){
			bool f=false;
			for(int j=0;j<e;j++){
				edge &e=G[j];
				if(D[e.from]!=1e9+7&&D[e.to]>D[e.from]+e.cost){
					D[e.to]=D[e.from]+e.cost;
					f=true;
					if(i==v-1){
						negative=false;
						break;
					}
				}
			}
			if(!negative){
				break;
			}
			if(!f){
				break;
			}
		}
		return D;
	}
};
//
int main(){
	int V,E,r;
	cin>>V>>E>>r;
	bellman be(V,E);
	for(int i=0;i<E;i++){
		int s,t,d;
		cin>>s>>t>>d;
		be.add_edge(s,t,d);
	}
	vector<int> ans=be.dist(r);
	if(!negative){
		cout<<"NEGATIVE CYCLE"<<endl;
		return 0;
	}
	for(int i=0;i<V;i++){
		if(ans[i]==1e9+7){
			cout<<"INF"<<endl;
		}else{
			cout<<ans[i]<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3192
#include <iostream>

using namespace std;

long long gcd(long long a, long long b)
{
    if(b==0)    return a;
    return gcd(b,a%b);
}

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

int main()
{
    long long a,b;
    while(cin>>a>>b)
    {
        cout << gcd(a,b) << ' ' << lcm(a,b) << endl;
    }
    return 0;
}

Measured memory_bytes: 1156
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(S == T) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inp_ll;

const int MAXN = 100010;
const int MAXM = 1000010;
const int INF = 1000000000;
const int MOD = 998244353;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

int s[MAXN];

int main()
{
	
	int n, m;
	cin >> n >> m;
	map<int, int> F;
	F[0] = 1;
	ll ans = 0;
	for (int i = 1; i <= n; ++ i)
	{
		int x;
		scanf("%d", &x);
		s[i] = (s[i-1]+x)%m;
		ans += F[s[i]];
		F[s[i]] ++;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3584
[n, a, b] = map(int, input().split(" "))
total_sum = 0

for i in range(n):
    num = i + 1
    numbers = []
    while num > 0:
        numbers += [num % 10]
        num = num // 10
    if sum(numbers) >= a and sum(numbers) <= b:
        total_sum += i + 1

print(total_sum)

Measured memory_bytes: 3060
#include <iostream>


using std::cout;
using std::cin;
using std::endl;

int main()
{
    int row, column;
    cin >> row >> column;

    int** spread_in = new int*[row];
    for (int i = 0; i < row; i++) {
        spread_in[i] = new int[column];
    }

    int in;
    int sum_all = 0;
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < column; j++) {
            cin >> in;
            spread_in[i][j] = in;
            sum_all += in;
        }
    }

    int sum_row[row];
    for (int i = 0; i < row; i++) {
        sum_row[i] = 0;
        for (int j = 0; j < column; j++) {
            sum_row[i] += spread_in[i][j];
        }
    }

    int sum_column[column];
    for (int j = 0; j < column; j++) {
        sum_column[j] = 0;
        for (int i = 0; i < row; i++) {
            sum_column[j] += spread_in[i][j];
        }
    }

    int spread_out[row + 1][column + 1];
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < column; j++) {
            spread_out[i][j] = spread_in[i][j];
        }
    }
    for (int i = 0; i < row; i++) {
        spread_out[i][column] = sum_row[i];
    }
    for (int j = 0; j < column; j++) {
        spread_out[row][j] = sum_column[j];
    }
    spread_out[row][column] = sum_all;

    for (int i = 0; i < row + 1; i++) {
        for (int j = 0; j < column + 1; j++) {
            if (j != 0) {
                cout << " ";
            }
            cout << spread_out[i][j];
        }
        cout << endl;
    }

    for (int i = 0; i < row; i++) {
        delete[] spread_in[i];
    }
    delete[] spread_in;

    return 0;
}

Measured memory_bytes: 1272
x = int(input())
if x < 100:
    print(0)
    exit()

i = 0
while 105 * i + 1 < 100 * (i + 1):
    if 105 * i + 1 <= x < 100 * (i + 1):
        print(0)
        exit()
    i += 1
print(1)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-5)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

void solve(int n){
	vi v(n);
	fcout(10);
	int s=0,a=0,c=0;
	double minh=INF;
	rep(i,n)cin>>v[i];
	rep(i,16)rep(j,16)rep(k,16){
		int r=i;
		vi o(256);
		rep(l,n){
			r=(r*j+k)%256;
			o[(r+v[l])%256]++;
		}
		double h=0;
		rep(l,256){
			if(o[l]){
				h-=o[l]*(log(o[l])-log(n));
			}
		}
		if(minh>h+EPS){minh=h;s=i;a=j;c=k;}
	}
	puta(s,a,c);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while(cin>>n,n)solve(n);
}



Measured memory_bytes: 3436
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e9;
int m1,d1,m2,d2;
int main(){
	cin>>m1>>d1;cin>>m2>>d2;
	if(m2==m1)cout<<0<<endl;
	else{
		if(m1==1||m1==3||m1==5||m1==7||m1==8
		||m1==10||m1==12){
			if(d1<31)cout<<0<<endl;
			else cout<<1<<endl; 
		}
		else if(m1==2){
			if(d1==28)cout<<1<<endl;
			else cout<<0<<endl;
		}
		else if(d1<30)cout<<0<<endl;
		else cout<<1<<endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=110;
typedef long long ll;
const double pi=acos(-1);
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
struct point {
    int x,y,id;
    double len() {
        return sqrt(1ll*x*x+1ll*y*y);
    }
} p[N],st[N];
point operator+(const point &a,const point &b) {
    return {a.x+b.x,a.y+b.y};
}
point operator-(const point &a,const point &b) {
    return {a.x-b.x,a.y-b.y};
}
ll operator*(const point &a,const point &b) {
    return 1ll*a.x*b.y-1ll*a.y*b.x;
}
bool operator<(const point &a,const point &b) {
    return a.x==b.x?a.y<b.y:a.x<b.x;
}
int n,tp=0;
double ans[N];
int main() {
    n=gi();
    if(n==2) return puts("0.5\n0.5"),0;
    for(int i=1;i<=n;i++) p[i].x=gi(),p[i].y=gi(),p[i].id=i;
    sort(p+1,p+n+1);
    for(int i=1;i<=n;i++) {
        while(tp>1&&(p[i]-st[tp])*(st[tp-1]-st[tp])>=0) --tp;
        st[++tp]=p[i];
    }
    for(int i=n,j=tp;i;i--) {
        while(tp>j&&(p[i]-st[tp])*(st[tp-1]-st[tp])>=0) --tp;
        st[++tp]=p[i];
    }
    for(int i=1;i<tp;i++) {
        point A=st[i+1]-st[i],B;
        if(i>1) B=st[i]-st[i-1];
        else B=st[i]-st[tp-1];
        double a=A.len(),b=B.len(),c=(A+B).len();
        ans[st[i].id]=(pi-acos((a*a+b*b-c*c)/2/a/b))/2/pi;
    }
    for(int i=1;i<=n;i++) printf("%.10lf\n",ans[i]);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define mp(x,y) make_pair(x,y)
#define ALL(a) a.begin(),a.end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define pii pair<int,int>
#define INF 1<<29
#define MAX 101010
using namespace std;

int h,w,n;
ll x[MAX],y[MAX],cx[MAX],cy[MAX];

ll calc(ll X,ll Y){
 ll ma=0LL;
 ll tot=0LL;
 FOR(i,n){
  ll d=labs(X-x[i])+labs(Y-y[i]);
  ma=max(ma,d);
  tot+=d;
 }
 return 2*tot-ma;
}

void solve(){
 cin>>h>>w;
 cin>>n;
 FOR(i,n) cin>>x[i]>>y[i];
 FOR(i,n) cx[i]=x[i];
 FOR(i,n) cy[i]=y[i];
 sort(cx,cx+n);
 sort(cy,cy+n);
 ll mx[2],my[2];
 mx[0]=cx[(n-1)>>1];
 mx[1]=cx[n>>1];
 my[0]=cy[(n-1)>>1];
 my[1]=cy[n>>1];
 ll mi=LONG_MAX/4,miX,miY;
 FOR(i,2){
  FOR(j,2){
   ll ret=calc(mx[i],my[j]);
   if(ret<mi){
    mi=ret;
    miX=mx[i];
    miY=my[j];
   }
  }
 }
 cout<<mi<<endl;
 cout<<miX<<" "<<miY<<endl;
}

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

Measured memory_bytes: 6292
#include <iostream>
#include <unordered_map>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef long long LL;
#define REPD(i,a,b) for (LL i=(a);i<(b);i++)
#define REP(i,n) REPD(i,0,n)

using namespace std;


LL inputValue(){
  LL a;
  cin >> a;
  return a;
};

vector<LL> inputVector(LL a){
  vector<LL> rv;
  REP(i, a){
    LL input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}

vector<string> inputVectorString(LL a){
  vector<string> rv;
  REP(i, a){
    string input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}
vector<vector<LL>> inputVector2D(LL a, LL b){
  vector<vector<LL>> rv;
  REP(i, a){
    rv.push_back(vector<LL>());
    REP(j, b) {
      LL input;
      cin >> input;
      rv.at(i).push_back(input);
    }
  }
  return rv;
}

#if 1
#define debug(d) debug1(__LINE__,#d, d)
void debug1(LL line, const char* name, vector<LL>& v) {
  cout << line << ":" << name << ":vector<LL>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, LL i) {
  cout << line << ":" << name << ":LL " << i << endl;;
}
void debug1(LL line, const char* name, vector<string>& v) {
  cout << line << ":" << name << ":vector<string>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, vector<vector<LL>>& v) {
  cout << line << ":" << name << ":vector<vector<LL>>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    REP(j, (LL)v.at(i).size()) {
      cout << v.at(i).at(j) << " ";
    }
    cout << ", ";
  }
  cout << endl;
}
#else
#define debug(n)
#endif

int main(int argc, const char * argv[]) {
  // source code
  LL n = inputValue();
  LL q = inputValue();

  unordered_map<LL,LL> tree;
  REPD(i, 1, n) {
    LL a = inputValue();
    LL b = inputValue();
    tree[b] = a;
  }
  unordered_map<LL,LL> score;
  REP(i, q) {
    LL p = inputValue();
    LL x = inputValue();
    score[p] += x;
  }
  unordered_map<LL,LL> totalScore;
  std::function<LL(LL)> findScore = [&findScore, &score, &tree, &totalScore](LL c){
    if(totalScore.count(c) == 1) {
      return totalScore[c];
    }
    LL s = 0;
    if (score.count(c) == 1) {
      s += score[c];
    }
    if (c != 1) {
      s += findScore(tree[c]); 
    }
    totalScore[c] = s;
    return s;
  };
  REPD(i, 1, n+1) {
    /*
    LL s= 0;
    LL c = i;
    if (score.count(c) == 1) {
      s += score[c];
    }
    while(c != 1) {
      c = tree[c];
      if (score.count(c) == 1) {
        s += score[c];
      }
    }
    */
    if (i!=1) cout << " ";
    cout << findScore(i);
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 26952
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n;
    string s;
    stack<char> st;

    cin >> s;

    ll ans = 0;

    for (int i = 0; i < s.size(); i++)
    {
        if (st.size() == 0 || st.top() == s[i])
        {
            st.push(s[i]);
        }
        else
        {
            ans += 2;

            st.pop();
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 512