akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
#include <queue>
#define int long long
using namespace std;
struct Vertex{int num; int ind;};
vector<Vertex> rmq;
int n, m, ai, ans;
vector<int> data;
void go(int i, int l, int r, int num, int ind){
    if (r - l == 1){
        num += rmq[i].num;
        ind += rmq[i].ind;
        ans = min(ans, num - l * ind);
        return;
    }
    int mm = (l + r) / 2;
    go(2*i+1, l, mm, num + rmq[i].num, ind + rmq[i].ind);
    go(2*i+2, mm, r, num + rmq[i].num, ind + rmq[i].ind);
}
void change(int i, int l, int r, int l1, int r1, int first, int second){
    if (l1 >= r1) return;
    if (l1 == l && r1 == r){
        rmq[i].num += first;
        rmq[i].ind += second;
        return;
    }
    int mm = (l + r) / 2;
    change(2*i+1, l, mm, l1, min(r1, mm), first, second);
    change(2*i+2, mm, r, max(l1, mm), r1 , first, second);
}
signed main()
{
    cin >> n >> m;
    for (int i=0;i<n;i++){
        cin >> ai;
        data.push_back(ai-1);
    }
    for (int i=0;i<4*m;i++){
        Vertex v;
        v.num = 0;
        v.ind = 0;
        rmq.push_back(v);
    }
    for (int i=0;i<n-1;i++){
        int f = data[i];
        int s = data[i+1];
        if (f < s){
            change(0, 0, m, f+1, s+1, s+1, 1);
            change(0, 0, m, 0, f+1, (s-f), 0);
            change(0, 0, m, s+1, m, (s-f), 0);
        }
        else{
            change(0, 0, m, s+1, f+1, (s+m-f), 0);
            change(0, 0, m, f+1, m, m+s+1, 1);
            change(0, 0, m, 0, s+1, s+1, 1);
        }
    }
    ans = 1e18;
    go(0, 0, m, 0, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10988
#include"bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define Forr(i,a,b) for(int i=a;i>b;i--)
typedef long long ll;
double PI = 3.14159265;
using namespace std;
using Graph = vector<vector<int>>;
using Field = vector<string>;
using DGraph = vector<vector<pair<int, int>>>;

const long long INF = 1LL << 60;
//---//
int w[110], v[110];
ll dp[100010][110];

int main() {
	int N,W; cin >> N >> W;

	rep(i, N)cin >> w[i] >> v[i];

	rep(i, 100010)rep(j, 110)dp[i][j] = INT_MAX;
	dp[0][0] = 0;
	rep(i, N) {
		For(j, 0, 100001) {
			if (j >= v[i])dp[j][i + 1] = min(dp[j - v[i]][i] + w[i], dp[j][i]);
			else dp[j][i + 1] = dp[j][i];
		}
	}
	
	Forr(i, 100000, 0)if (dp[i][N] <= W){
		cout << i << endl;
		break;
	}

	return 0;
}


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

using namespace std;

int main(){

long long n,a,b;
cin >> n >> a>> b;

long long c,d,ans;
c = n/(a + b);

d = n%(a + b);


if (d > a)
{
   d = a;
}
ans = c * a + d;
cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll N, T;
  cin >> N >> T;
  vector<ll> t(N);
  rep(i, N) cin >> t[i];
  t.pb(ll(1e+10));

  ll ans = 0;
  rep(i, N) { ans += min(T, t[i + 1] - t[i]); }
  cout << ans << endl;
}

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

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	int a[100][100];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < h; i++) {
		int sum = 0;
		for (int j = 0; j < w; j++) {
			cout << a[i][j] << " ";
			sum += a[i][j];
		}
		cout << sum << endl;
	}

	int sumsum = 0;
	for (int i = 0; i < w; i++) {
		int sum = 0;	
		for (int j = 0; j < h; j++) {
			sum += a[j][i];
			sumsum += a[j][i];
		}
		cout << sum << " ";
	}
	cout << sumsum << endl;

	return 0;
}


Measured memory_bytes: 3120
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    string week[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string today;
    cin >> today;
    for (int i = 0; i < 7; i++) {
        if (today == week[i]) {
            int next = 7 - i;
            cout << next << "\n";
        }
    }
    return 0;
}


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

#define pb push_back
#define ss second
#define ff first
#define N 20004
#define inf 1000000007
#define ll long long
#define mid(a,b) (a+b)/2
#define pii pair<int,int>

using namespace std;

int n,h,a[N],b[N],dis[N],mn = inf;

int main()
{
	scanf("%d%d",&h,&n);
	for(int i = 1;i <= 2e4;i++) dis[i] = inf;
	for(int i = 1;i <= n;i++)
		scanf("%d%d",&a[i],&b[i]);
	for(int i = 1;i <= n;i++){
		for(int j = 0;j <= h;j++){
			if(dis[j + a[i]] > dis[j] + b[i]){
				dis[j + a[i]] = dis[j] + b[i];
			}
			if(j + a[i] >= h)
				mn = min(mn,dis[j + a[i]]);
		}
	}
	printf("%d",mn);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    set<int> se;
    int n; cin >> n;
    rep(i,n){
        int d; cin >> d;
        se.insert(d);
    }
    cout << se.size() << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    vector<P> v;
    for(int i = 0; i < N; i++){
        long long int A, B;
        cin >> A >> B;
        v.push_back(P(B, A));
    }
    sort(v.begin(), v.end());
    long long int S = 0;
    for(P p : v){
        S += p.second;
        if(S > p.first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 6384
n,m = map(int,input().split())
a_list = [input() for _ in range(n)]
b_list = [input() for _ in range(m)]
count = 0
res = []
for i in range(n-m+1):
    for j in range(n-m+1):
        f = True
        for k in range(m):
            for l in range(m):
                if a_list[i+k][j+l] != b_list[k][l]:
                    f = False
                    break
            if not f:
                break
        if f:
            print('Yes')
            exit()
print('No')

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

void solve(long long A, long long B, long long C, long long D)
{
    if (A + B == C + D)
    {
        cout << "Balanced" << endl;
    }
    else
    {
        cout << (A + B > C + D ? "Left" : "Right") << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    long long D;
    scanf("%lld", &D);
    solve(A, B, C, D);
    return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << x << '\n'
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
//---------------------------------------------------------------------------------------------------
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
void solve()
{
  lli a = 0, b = 0, c = 0, h = 0, n = 0, w = 0, ans = 0, count = 0;
  string s = "", t = "";
  vector<pair<lli, lli>> pr;
  map<lli, lli> mp;
  set<lli> st;

  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  vlli d(n);
  rep(i, 0, n)
  {
    cin >> d[i];
  }
  SORT(d);
  rep(i, 0, n)
  {
    rep(j, i, n)
    {
      rep(k, j, n)
      {
        if (i < j && j < k && k > i)
        {
          if ((d[i] != d[j] && d[j] != d[k] && d[k] != d[i]) && (d[i] + d[j] > d[k] && d[j] + d[k] > d[i] && d[k] + d[i] > d[j]))
          {
            ans++;
          }
        }
      }
    }
  }

  out(ans);
}

//---------------------------------------------------------------------------------------------------
signed main()
{
  solve();
}

Measured memory_bytes: 3640
/*
Problem:Integers on a tree 
Algorithm:pq
Status:
*/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <utility>
#include <list>
#include <ctime>
#include <memory.h>
#include <stack>
#include <stdio.h>
#include <string.h>

using namespace std;

const int INF=1e9+7;

int a[100005];
vector<int> nei[100005];
int n,k;
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > Q;

void shit() {
	cout<<"No"<<endl;
	exit(0);
}

int main()
{
	#ifndef ZZZYT
		//freopen(".in","r",stdin);
		//freopen(".out","w",stdout);
	#endif
	
	for(int i=0;i<100000;i++){
		a[i]=-1;
	}
	
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		x--;y--;
		nei[x].push_back(y);
		nei[y].push_back(x);
	}
	scanf("%d",&k);
	for(int i=0;i<k;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		x--;
		a[x]=y;
		Q.push(make_pair(y,x));
	}
	
	while(!Q.empty()){
		int x=Q.top().second;
		int y=Q.top().first;
		Q.pop();
		for(int i=0;i<nei[x].size();i++){
			if(a[nei[x][i]]==-1){
				a[nei[x][i]]=y+1;
				Q.push(make_pair(y+1,nei[x][i]));
			}
			else{
				if(abs(a[nei[x][i]]-y)!=1){
					shit();
				}
			}
		}
	}
	
	cout<<"Yes"<<endl;
	for(int i=0;i<n;i++){
		cout<<a[i]<<endl;
	}
	
	return 0;
}


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

int	main()
{
	int	n, cont;
	cin >> n;

	cont = 0;
	for (int i = 0; i < n; i++)
	{
		int	l, m;
		cin >> l >> m;
		cont += m - l + 1;
	}
	cout << cont << endl;
}



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

#define ll long long
#define ld long double
#define ull unsigned long long
#define pw(x) (1LL << (x))

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"

using namespace std;

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

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

    bool G[n + 1][n + 1] = {false};

    for (int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        G[a][b] = G[b][a] = true;
    }

    int cnt = 0;

    vector<int> v(n);
    for (int i = 0; i < n; ++i)
        v[i] = i + 1;

    do
    {
        bool valid = true;
        for (int i = 0; i < v.size() - 1; ++i)
        {
            if (!G[v[i]][v[i + 1]])
            {
                valid = false;
                break;
            }
        }

        if (valid)
        {
            ++cnt;

            // for (int x : v)
            //     cout << x << " ";
            // cout << '\n';
        }

    } while (next_permutation(v.begin() + 1, v.end()));

    cout << cnt << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

/* add vars here */

int h,w;
char a[101][101];

/* add your algorithm here */

int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
    }
  }

  vector<int> wa;
  vector<int> ha;


  rep(i,h) {
    char s = a[i][0];
    if (s == '#') continue;
    for (int j = 1; j < w; ++j) {
      if (s != a[i][j]) break;
      if (j == w-1) {
        wa.pb(i);
      }
    }
  }


  rep(i,w) {
    char s = a[0][i];
    if (s == '#') continue;
    for (int j = 1; j < h; ++j) {
      if (s != a[j][i]) break;
      if (j == h-1) {
        ha.pb(i);
      }
    }
  }



  for (int i = 0; i < h; ++i) {
    bool flag = true;
    for (auto itr = wa.begin(); itr != wa.end(); ++itr) {
      if (*itr == i) {
        flag = false;
        break;
      }
    }
    if (!flag) continue;
    for (int j = 0; j < w; ++j) {
      bool flag2 = true;
      for (auto itr = ha.begin(); itr != ha.end(); ++itr) {
        if (*itr == j) {
          flag2 = false;
          break;
        }
      }
      if (!flag2) continue;
      cout << a[i][j];
    }
    cout << endl;
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
int l[10];
int A[4];
int m[10];
int ans = INF;
int func(vector<int> v,int X){
	int M = v.size();
	int ret = INF;
	for(int i=1;i<(1<<M);i++){
		int cnt = 0;
		int res = 0;
		int sum = 0;
		for(int j=0;j<M;j++){
			if((i>>j)&1){
				cnt++;
				sum+=l[v[j]];
			}
		}
		res += 10*(cnt-1);
		res += abs(sum-X);
		ret = min(ret,res);
	}
	return ret;
}
void dfs(int d){
	if(d==N){
		int res = 0;
		for(int i=0;i<3;i++){
			vector<int> vec;
			for(int j=0;j<N;j++){
				if(m[j]==i)vec.pb(j);
			}
			if(vec.size()==0)return;
			res += func(vec,A[i]);
		}
		ans = min(ans,res);
		return;
	}
	for(int i=0;i<3;i++){
		m[d]=i;
		dfs(d+1);
	}
}
int main(){
	cin >> N;
	for(int i=0;i<3;i++)cin >> A[i];
	for(int i=0;i<N;i++)cin >> l[i];
	dfs(0);
	cout << ans << endl;
	return 0;
}

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

long long gcd(long long a, long long b) {
    if (b == 0) {
        return a;
    }
    else {
        return gcd(b, a % b);
    }
}
long long lcm2(long long a, long long b) {
    long long d = gcd(a, b);
    return a / d * b;
}

int main()
{
    ll a, b,ans;
    ll c,d;

    cin >> a >> b >> c >> d;

    //a未満のcで割り切れる個数
    ll c1 = (a-1) / c;
    //b以下のcで割り切れる個数
    ll c2 = b / c;
    //a未満のdで割り切れる個数
    ll d1 = (a - 1) / d;
    //b以下のcで割り切れる個数
    ll d2 = b / d;
    //c*dの最小公倍数
    ll cd = lcm2(c, d);
    //a未満のc*dの公倍数で割り切れる個数
    ll cd1 = (a - 1) / cd;
    //b以下のc*dの公倍数で割り切れる個数
    ll cd2 = b / cd;

    ans = (b - a) + 1 - (c2 - c1) - (d2 - d1) + (cd2 - cd1);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3560
//
//  main.c
//  Amida, the City of Miracle
//
//  Created by x15071xx on 2016/06/09.
//  Copyright ?? 2016??´ AIT. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    
    
    
    while (1) {
        
        int n,m,a,i,j,h,p,q;
        int field[1002][200] ={0};
        scanf("%d %d %d",&n,&m,&a);
        
        if (n==0 && m==0 && a==0) {
            break;
        }
        
        for (i=0; i<n; i++) {
            field[0][i*2] = i+1;
            field[1001][i*2] = i+1;
            //??????
            for (j=1; j < 1001; j++) {
                field[j][i*2] = 1;
            }
        }
        
        for (i=0; i<m; i++) {
            scanf("%d %d %d",&h,&p,&q);
            
            field[1001-h][p+q-2] = 1;
            
        }
        
        //?????????
        int y = a*2-2;
        for (i=0; i < 1001; i++) {
            
            if (field[i][y+1] == 1) {
                y+=2;
                continue;
            }
            if (field[i][y-1] == 1) {
                y-=2;
                continue;
            }
        }
        
        
        printf("%d\n",field[1001][y]);
        

    }
    return 0;
}

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

long long MOD=1000000007;
vector<long long> c(26,0);

int main(){
	int N;
	string S;
	cin >> N >> S;
	for(int i=0;i<N;i++){
		c[S[i]-'a']++;
	}
	
	long long ans=1;
	for(int i=0;i<26;i++){
		ans*=c[i]+1;
		if(ans>=MOD)ans%=MOD;
	}
	ans+=MOD-1;
	ans%=MOD;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

class Solution {
public:
	void solve() {
		int n, m;
		cin >> n >> m;
		vector<int> h(n, 0);
		for (int i = 0; i < n; i++) cin >> h[i];
		vector<bool> ok(n, true);
		for (int i = 0; i < m; i++) {
			int a, b;
			cin >> a >> b;
			a--, b--;
			if (h[a] >= h[b]) ok[b] = false;
			if (h[b] >= h[a]) ok[a] = false;
		}
		int ans = 0;
		for (int i = 0; i < n; i++)
			if (ok[i]) ans++;
		cout << ans << "\n";

		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 3740
def solve(nu,mu,du):
    E = []
    vs = [False]*nu
    vs[0] = True

    while True:
        min_dist,ind = float("inf"),float("inf")
        for i in xrange(len(du)):
            p_from = du[i][0]
            p_to = du[i][1]
            if ( vs[p_from] and not vs[p_to] ) or ( not vs[p_from] and vs[p_to]):
                if min_dist > du[i][2]:
                    min_dist,ind,pf,pt = du[i][2],i,p_from,p_to
        E.append(min_dist)
        vs[pf] = vs[pt] = True
        du.pop(ind)
        if all(vs):
            break
        for i in xrange(len(du)):
            try:
                if vs[du[i][0]] and vs[du[i][1]]:
                    du.pop(i)
            except:
                pass

    print sum(E)/100 - len(E)

while True:
    n = input()
    if n == 0:
        exit()
    m = input()
    data = []
    for i in xrange(m):
        data.append( map(int,raw_input().split(",")) )
    solve(n,m,data)

Measured memory_bytes: 4884
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
using ll = long long;
int MOD = 1e9 + 7;
using namespace std;
ll GCD(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    else
    {
        return GCD(y, x % y);
    }
}
ll LCM(ll x, ll y)
{
    return x / GCD(x, y) * y;
}
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main()
{
    vector<vector<ll>> reg = {
        {0, 0, 0},
        {0, 0, 1},
        {0, 1, 0},
        {1, 0, 0},
        {1, 1, 0},
        {0, 1, 1},
        {1, 0, 1},
        {1, 1, 1}
    };
    ll n, m;
    cin >> n >> m;
    vector<ll> X(n);
    vector<ll> Y(n);
    vector<ll> Z(n);
    for (int i = 0; i < n;i++){
        ll x, y, z;
        cin >> x >> y >> z;
        X[i] = x;
        Y[i] = y;
        Z[i] = z;
    }
    ll MAX = 0;
    for (int i = 0; i < 8;i++){
        priority_queue<ll> q;
        for (int j = 0; j< n;j++){
            ll sum = 0;
            if(reg[i][0]==0){
                sum += X[j];
            }else{
                sum -= X[j];
            }
            if (reg[i][1] == 0)
            {
                sum += Y[j];
            }
            else
            {
                sum -= Y[j];
            }
            if (reg[i][2] == 0)
            {
                sum += Z[j];
            }
            else
            {
                sum -= Z[j];
            }
            q.push(sum);
        }
        ll k = 0;
        for (int i = 0; i<m;i++){
            k += q.top();
            q.pop();
        }
        MAX = max(MAX, k);
    }
    cout << MAX << endl;
}


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

bool table[1000][1000][1000]{false};

int main(){

    int n,p[3],count=0;

    cin >> n;

    for(int i=0;i<n;i++){
      cin >> p[0] >> p[1] >> p[2];
      sort(p,p+3);
      if(table[p[0]][p[1]][p[2]]){
        count++;
      }
      else{
        table[p[0]][p[1]][p[2]] = true;
      }
    }

    cout << count << endl;


    return 0;
}

Measured memory_bytes: 7092
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x) memset(x , 0 , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

signed main(){
  ios::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  int x = N / 1000 + (N % 1000 != 0);
  int p = 1000 * x;
  cout << p - N << '\n';
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// 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 l[55],p[55];

ll solve(ll n,ll x){
    if(n==0){
        return 1;
    }
    if(x<=1){
        return 0;
    }else if(x < l[n-1]+2){
        return solve(n-1,x-1);
    }else if(x==l[n-1]+2){
        return p[n-1]+1;
    }else if(x < l[n]){
        return solve(n-1,x-l[n-1]-2)+p[n-1]+1;
    }else{
        return p[n];
    }
}

int main() {
    ll n,x;cin>>n>>x;
    l[0]=1;p[0]=1;
    rep(i,n){
        l[i+1] = l[i]*2+3;
        p[i+1] = p[i]*2+1;
    }

    ll ans = solve(n,x);
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    if(N>=64){
        cout<<64<<endl;
    }else if(N>=32){
        cout<<32<<endl;
    }else if(N>=16){
        cout<<16<<endl;
    }else if(N>=8){
        cout<<8<<endl;
    }else if(N>=4){
        cout<<4<<endl;
    }else if(N>=2){
        cout<<2<<endl;
    }else{
        cout<<1<<endl;
    }



    return 0;
    

}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int N, n, i, j,k,l;
	char a,b,c;
	vector<char> s, t,u;
	while (cin >> N) {
		if (N == 0)break;
		s.clear();
		t.clear();
		u.clear();
		for (i = 0; i < N; i++) {
			cin >> a >> b;
			s.push_back(a);
			t.push_back(b);
		}
		cin >> n;
		for (j = 0; j < n; j++) {
			cin >> c;
			for (k = 0; k < N; k++) {
				if (s[k] == c) {
					c = t[k];
					break;
				}
			}
			u.push_back(c);
		}
		for (l = 0; l < n; l++) {
			cout << u[l];
		}
		cout << endl;
	}
	return 0;
}

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

int n,m,dp[1<<12],a[1000],b,c,x[1000];

int main(){
    cin>>n>>m;
    n=1<<n;
    rep(i,m){
        cin>>a[i]>>b;
        rep(j,b){
            cin>>c;
            x[i]+=1<<(c-1);
        }
    }
    rep(i,n)dp[i]=1e9;
    dp[0]=0;
    rep(i,m)rep(j,n){
        dp[x[i]|j]=min(dp[x[i]|j],dp[j]+a[i]);
    }
    cout<<(dp[n-1]<1e9?dp[n-1]:-1)<<endl;
}

Measured memory_bytes: 256
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(A[k-1])


Measured memory_bytes: 2940
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
  var a = Number(lines[0]);
  var b = Number(lines[1]);
  var c = Number(lines[2]);
  var d = Number(lines[3]);
  var e = Number(lines[4]);
  var ans = 0;
  var info = [];
 
  info.push(a);
  info.push(b);
  info.push(c);
  info.push(d);
  info.push(e);
 
  var amari = [];
  amari.push(a%10);
  amari.push(b%10);
  amari.push(c%10);
  amari.push(d%10);
  amari.push(e%10);
  var amari_t = amari.filter(function(value){
    return !(value == 0);
  });
 
  var min = Math.min(...amari_t);
 
  var index = amari.indexOf(min);
 
  for(i=0; i<5; i++){
    if(i==index){
      continue;
      console.log('A');
    }
    ans += info[i]
    if(ans%10 !== 0){
      while(ans%10 !== 0){
        ans++;
      }
    }
  }
 
  ans += info[index];
  if(Number.isNaN(ans)){
    ans = 0;
    ans = a + b + c + d + e;
  }
 
  console.log(ans);

});


Measured memory_bytes: 7628
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


#define int ll

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}


void solve() {
    int n, p;
    cin >> n >> p;
    map<int, int> cnt;
    string s;
    cin >> s;
    if (p <= 10) {
        int geko[10] = {};
        int ans = 0;
        for (int q = 0; q < s.length(); ++q) {
            int neko[10] = {};
            for (int t = 0; t < p; ++t) {
                int target = t * 10 + s[q] - '0';
                neko[target % p] += geko[t];
            }
            neko[(s[q] - '0') % p]++;
            for (int t = 0; t < p; ++t) {
                geko[t] = neko[t];
            }
            ans += geko[0];
        }
        cout << ans << endl;
        return;
    }
    reverse(ALL(s));
    int now = 0;
    int ans = 0;
    cnt[now] = 1;
    int ta = 1;
    for (int q = 0; q < s.length(); ++q) {
        now += ta * (ll)(s[q] - '0');
        now %= p;
        ans += cnt[now];
        cnt[now]++;
        ta *= 10LL;
        ta %= p;
    }
    cout << ans << endl;
}

#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 1044
from collections import Counter

N = int(input())
a_list = list(map(int, input().split()))
am_list = list(map(lambda x: x - 1, a_list))
ap_list = list(map(lambda x: x + 1, a_list))
data = a_list + am_list + ap_list
c = Counter(data)
print(c.most_common(1)[0][1])


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

int main() {
    while(1){
        string s;
        cin >> s;
        if (s == "#") break;
        int y, m, d;
        cin >> y >> m >> d;
        if(y > 31 || (y == 31 && m >= 5)){
            printf("? %d %d %d\n", y - 30, m, d);
        } else {
            printf("HEISEI %d %d %d\n", y, m, d);
        }
    }
    return 0;
}


Measured memory_bytes: 3176
#include <iostream>
#include <vector>
using namespace std;
vector<bool> passed(100010, false);
vector<int> button(100010);

int dfs(int cnt, int now){
    if(now == 2) return cnt;
    if(passed[now]) return -1;
    
    passed[now] = true;
    return dfs(cnt+1, button[now]);
}

int main(void){
    int n; cin>>n;
    for(int i = 1; i <= n; ++i)cin>>button[i];
    int res = dfs(0,1);
    cout<<res<<endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
int main() {
	char a[255];
	
	scanf("%s", a);
	
	int len = strlen(a);
	
	for(int i = 0; i < len; i++) {
		
		int sum = 0;
		
		if(a[i] == 'B' && i != 0) {
			int j = i;
			int k = 1;
			
		while(a[j] == 'B') {
			a[i-k] = 'B';
			k++;
			j++;
		}
		
		sum++;
		}
	}
	for(int i = 0; i < len; i++) {
		
		if(a[i] != 'B') {
			printf("%c", a[i]);
		}
	}
	
	return 0;
	
}


Measured memory_bytes: 1648
import sys
sys.setrecursionlimit(10 ** 7)
n = int(input())

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


ans = [0]*(n-1)

def col(now,color):
    c = 1
    for [b,j] in graph[now-1]:
        if c == color:
            c += 1
        ans[j-1] = c
        col(b,c)
        c += 1  

col(1,0)
print(max(ans))
for i in range(1,n):
    print(ans[i-1])


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

int main() {
  // 入力を受け取る
  int N,AC,WA,TLE,RE;
  cin >> N;
  
  AC=0;WA=0;TLE=0;RE=0;

  for(int i = 0;i < N;i++){
    string S;
    cin >> S;
    if(S.at(0) == 'A'){AC++;}
    if(S.at(0) == 'W'){WA++;}
    if(S.at(0) == 'T'){TLE++;}
    if(S.at(0) == 'R'){RE++;}
  }
  
  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
  
}


Measured memory_bytes: 3628
#! /usr/bin/python3

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

even_count = 0
odd_count = 0

for i in range(N):
    if A[i] % 2 == 0:
        even_count += 1
    else:
        odd_count += 1
    
even_count += odd_count // 2
odd_count = odd_count % 2

if odd_count == 1:
    print("NO")
else:
    print("YES")

    

Measured memory_bytes: 14112
#include <stdio.h>
#include <stdlib.h>
//枝刈り全探索……

int ans=45;
int p;
int a[16];
int L1dist(){
	int ret=0;
	for(int i=0;i<16;i++)if(a[i]!=15)ret+=abs(i/4-a[i]/4)+abs(i%4-a[i]%4);
	return ret;
}
int swap(int i,int j){int t=a[i];a[i]=a[j];a[j]=t;}

void f(int pre,int movs){
	int d=L1dist();
	if(movs+d>ans)return;
	if(d==0){
		ans=movs;
		return;
	}
	if(pre!=1&&p>3  )swap(p,p-4),p-=4,f(0,movs+1),p+=4,swap(p,p-4);
	if(pre!=0&&p<12 )swap(p,p+4),p+=4,f(1,movs+1),p-=4,swap(p,p+4);
	if(pre!=3&&p%4>0)swap(p,p-1),p-=1,f(2,movs+1),p+=1,swap(p,p-1);
	if(pre!=2&&p%4<3)swap(p,p+1),p+=1,f(3,movs+1),p-=1,swap(p,p+1);
}

int main(){
	for(int i=0;i<16;i++){
		int t;
		scanf("%d",&t);
		if(t)a[i]=t-1;
		else{
			a[i]=15;
			p=i;
		}
	}
	f(-1,0);
	printf("%d\n",ans);
}


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

const int N = 1e6;
const int mo0 = 998244353;
const int mo1 = 1004535809;

int n;
string str[N + 5];

bool ed[N + 5];
int ch[N + 5][26], tot;

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
#endif

    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        cin >> str[i];
        reverse(str[i].begin(), str[i].end());
    }

    sort(str + 1, str + n + 1, [&] (string a, string b) {
            return a.length() < b.length();
            });

    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        static int cnt[30];
        memset (cnt, 0, sizeof cnt);

        int u = 0;
        for (int j = 0; j < (int) str[i].length(); ++j) {
            for (int c = 0; c < 26; ++ c) if (ch[u][c] && ed[ch[u][c]]) {
                ++ cnt[c];
            }

            ans = ans + cnt[str[i][j] - 'a'];
            cnt[str[i][j] - 'a'] = 0;

            if (!ch[u][str[i][j] - 'a']) 
                ch[u][str[i][j] - 'a'] = ++ tot;
            u = ch[u][str[i][j] - 'a'];
        }
        ed[u] = true;
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 138804
def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    num_list.sort()

    for i in range(n-1):
        num_list[i+1] = (num_list[i]+num_list[i+1]) / 2

    print(num_list[n-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;

int main(void){
    while(true){
        int n;
        cin >> n;
        if(n == 0) return 0;
        
        vector<ll> a(n);
        For(i, n) cin >> a[i];
        sort(a.begin(), a.end());
        
        ll ans = 1e18;
        For(i, n-1) ans = min(ans, a[i+1] - a[i]);
        cout << ans << "\n";
    }
}


Measured memory_bytes: 3056
import bisect

x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

p.sort()

temp = 100
temp2 = 0

if(n == 0):
    print(x)
else:
    for i in range(102):
        temp3 = abs(x-i)
        if(temp3 < temp):
            flag = 1
            for j in p:
                if(i == j):
                    flag = 0
            if(flag == 1):
                temp2 = i
                temp = temp3
    print(temp2)

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

const int MAX_N = 200;
int a[MAX_N];

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

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

    int ans = (1 << 28);
    for (int val = -100; val <= 100; val++) {
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += (a[i] - val) * (a[i] - val);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner io = new Scanner(System.in);
		int N = io.nextInt();
		int M = io.nextInt();
		int[] town = new int[N+1];
		
		for(int i=0;i<M;i++){
			town[io.nextInt()] ++;
			town[io.nextInt()] ++;
		}
		
		for(int i=1;i<=N;i++){
			System.out.println(town[i]);
		}
		
	}
		
}	

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int r;cin>>r;
    cout<<3*r*r<<endl;
}

Measured memory_bytes: 3528
fn run() {
    proconio::input! {
        mut s: proconio::marker::Chars,
        k: usize,
    }
    for c in "01".chars() {
        while s.last().map_or(false, |p| *p == c) {
            s.pop();
        }
        s.reverse();
    }
    let mut a = vec![];
    for c in s {
        if c == '0' {
            a.push(0);
        } else {
            *a.last_mut().unwrap() += 1;
        }
    }
    let k = std::cmp::min(k, a.iter().sum());
    // [取り出した回数][挿入した回数]
    const MOD: u64 = 998_244_353;
    let mut dp = vec![vec![1u64]];
    for a in a.into_iter().rev() {
        let len = std::cmp::min(k + 1, dp.len() + a);
        let mut next = vec![vec![0; len]; len];
        // 挿入
        for (i, (next, dp)) in next.iter_mut().zip(dp.iter()).enumerate() {
            let mut s = 0;
            for (a, b) in next.iter_mut().zip(dp.iter()).take(i + 1) {
                *a = s + *b;
                s = *a;
            }
        }
        // 取り出す
        for (i, dp) in dp.iter().enumerate() {
            for (j, &v) in dp.iter().enumerate().take(i + 1) {
                for next in next.iter_mut().skip(i + 1).take(a) {
                    next[j] += v;
                }
            }
        }
        dp = next;
        dp.iter_mut().for_each(|dp| dp.iter_mut().for_each(|v| *v %= MOD));
    }
    let ans = dp.into_iter().map(|dp| dp.into_iter().sum::<u64>()).sum::<u64>() % MOD;
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 2700
N,M=map(int, input().split())
AB=[]
for i in range(N):
  AB.append(list(map(int,input().split())))
AB.sort()
count=0
summary=0
for i in range(N):
  for j in range(AB[i][1]):
    summary+=AB[i][0]
    count+=1
    if count==M:
      print(summary)
      break
  else:
    continue
  break

Measured memory_bytes: 27760
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.lang.System.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		B(sc);
	}
	
	public static void A(Scanner sc) {
		int m = sc.nextInt();
		out.println(24-m+24);
	}
	
	public static void B(Scanner sc) {
		int a = sc.nextInt();
		int b = sc.nextInt();
		String s = sc.next();
		Pattern p = Pattern.compile("[0-9]{"+ a + "}-[0-9]{" + b + "}");
		Matcher m = p.matcher(s);
		if(m.find()) out.println("Yes");
		else out.println("No");
	}
}

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

int main(){
    int N, Y;
    cin >> N >> Y;
    int A = 0;
    int B = 0;
    int C = 0;

    for(int i = 0; i <= N; i++){
        int s = N-i;
        for(int k = 0; k <= s; k++){
            if(10000 * i + 5000 * k + 1000 * (s-k) == Y){
                A = i;
                B = k;
                C = s-k;
            }
        }
    }
    if(A == 0 & B == 0 & C == 0){
        cout << -1 << endl;
        cout << -1 << endl;
        cout << -1 << endl;
    }
    else{
        cout << A << endl;
        cout << B << endl;
        cout << C << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
typedef vector<P> Pol;
D eps=1e-9;
D dot(P a,P b){return real(conj(a)*b);}
D cro(P a,P b){return imag(conj(a)*b);}
int ccw(P a,P b,P c){
	if(cro(b-a,c-a)>eps) return 1;
	if(cro(b-a,c-a)<-eps) return -1;
	return 0;
}
P perp(L l,P p){
	D t=dot(p-l.fs,l.fs-l.sc)/norm(l.fs-l.sc);
	return l.fs+t*(l.fs-l.sc);
}
P refl(L l,P p){
	return p+2.0*(perp(l,p)-p);
}
int main(){
	while(true){
		int N;
		cin>>N;
		if(N==0) break;
		P s;
		{
			int x,y;
			cin>>x>>y;
			s=P(x,y);
		}
		Pol pol_;
		rep(i,N){
			int x,y;
			cin>>x>>y;
			pol_.pb(P(x,y));
		}
		int o[8]={};
		rep(i,N) o[i]=i;
		int ans=0;
		do{
			Pol pol=pol_;
			P ri=pol[o[0]],le=pol[(o[0]+1)%N];
			bool ok=1;
			rep(i,N){
				P a=pol[o[i]],b=pol[(o[i]+1)%N];
				if(i%2) swap(a,b);
				if(ccw(s,ri,a)==1) ri=a;
				if(ccw(s,le,b)==-1) le=b;
				if(ccw(s,ri,le)!=1){
					ok=0;
					break;
				}
				L l=L(pol[o[i]],pol[(o[i]+1)%N]);
				rep(j,N) pol[j]=refl(l,pol[j]);
			}
			if(ok) ans++;
		}while(next_permutation(o,o+N));
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1220
x = input().split()
height = [int(input()) for n in range(int(x[0]))]
height.sort()
check_new = 0
check_old = max(height)
for n in range(int(x[0]) - int(x[1]) + 1):
    check_new = height[int(x[1]) - 1 + n] - height[n]
    if check_new <= check_old:
        check_old = check_new
    
print(check_old)

Measured memory_bytes: 7384
import sys
readline = sys.stdin.readline

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

d = {}
for a in A:
    if str(a) in d:
        d[str(a)] += 1
    else:
        d[str(a)] = 1

ans = 0
count = 1
for k, v in sorted(d.items(), key=lambda x: -x[1]):
    if count > K:
        ans += v
    count += 1        
print(ans)


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

int main() {
  string s,t;
  cin>>s>>t;
  vector<ll> v1(30, 0);
  vector<ll> v2(30, 0);
  rep(i,s.size()) {
    ll si = s[i]-'a';
    ll ti = t[i]-'a';
    v1[si]++;
    v2[ti]++;
    if(v1[si] != v2[ti]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 776
h, w = map(int, input().split())
c = [list(map(int, input().split())) for i in range(10)]
a = [list(map(int, input().split())) for i in range(h)]
for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])
sum = 0
for i in range(h):
    for j in range(w):
        if a[i][j] >= 0:
            sum += c[a[i][j]][1]
print(sum)

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

using namespace std;

int dirs[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
//int dirs[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};

int inf=1e9;

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("inp.in","r",stdin);
    //freopen("outp.out","w",stdout);
    int nb_rows, nb_cols;
    //cin >> nb_rows >> nb_cols;
    scanf(" %d %d", &nb_rows, &nb_cols);
    vector< vector<char> > grid(nb_rows, vector<char>(nb_cols));
    for(int i=0; i<nb_rows; i++)
    {
        for(int j=0; j<nb_cols; j++)
        {
            //cin >> grid[i][j];
            scanf(" %c", &grid[i][j]);
        }
    }
    /*for(int i=0; i<nb_rows; i++)
    {
        for(int j=0; j<nb_cols; j++)
        {
            cout << grid[i][j];
        }
        cout << endl;
    }*/
    int n=nb_rows*nb_cols;
    vector< vector<int> > dist(n, vector<int>(n,inf));
    for(int i=0; i<n; i++) dist[i][i]=0;
    for(int i=0; i<nb_rows; i++)
    {
        for(int j=0; j<nb_cols; j++)
        {
            if(grid[i][j]=='#') continue;
            for(int k=0; k<4; k++)
            {
                int new_row=i+dirs[k][0];
                int new_col=j+dirs[k][1];
                if(!(0<=new_row && new_row<nb_rows && 0 <= new_col && new_col<nb_cols)) continue;
                if(grid[new_row][new_col]=='#') continue;
                int node1=i*nb_cols+j;
                int node2=new_row*nb_cols+new_col;
                /*if(node1==6)
                {
                    cerr << "i and j: " << i << " " << j << endl;
                    cerr << grid[i][j] << endl;
                }*/
                dist[node1][node2]=dist[node2][node1]=1;
            }
        }
    }
    /*for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            cout << i << " " << j << " " << dist[i][j] << endl;
        }
    }*/
    for(int via=0; via<n; via++)
    {
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<n; j++)
            {
                dist[i][j]=min(dist[i][j],dist[i][via]+dist[via][j]);
            }
        }
    }
    int ans=0;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            if(dist[i][j]>=inf) continue;
            ans=max(ans,dist[i][j]);
        }
    }
    cout << ans << endl;
    //cout << dist[4][10] << endl;
    return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int x, n;
  cin >> x >> n;
  
  vector<int> a(n);
  vector<bool> exist(102, false);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    exist.at(a.at(i)) = true;
  }
  
  int ans = 0;
  for (int i = 0; i <= 101; i++) {
    if (exist[i] == false && abs(ans - x) > abs(x - i)) ans = i;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 3656