akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {
    
    int N; cin >> N;
    int x[N]; rep(i,N) cin >> x[i];

    int mn = INF; int mx = 0;
    rep(i,N) {
        mn = min(mn, x[i]);
        mx = max(mx, x[i]);
    }

    int ans = INF;
    for (int p = mn; p <= mx; ++p) {
        int cost = 0;
        rep(i,N) cost += pow(x[i] - p, 2);
        ans = min(ans, cost);
    }
    out(ans);

    
    return 0;
}






Measured memory_bytes: 256
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
const int INF = 1001001001;

int main()
{
    int n,x,tmp=0;
    in n>>x;
    vector<int> l(n);
    rep(i,n)in l[i];
    int ans=0;
    rep(i,n)
    {
        tmp+=l[i];
        if(tmp<=x)ans++;
        else break;
    }
    cout<<ans+1<<endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

bool is_path[10][10][10][10];
const char ch_dir[] = {'U','R','D','L'};

void dfs(int sx,int sy,int dir){
  for(int i=0;i<4;i++){
    int next_dir = (dir + i + 3) % 4;
    int dx = tx[next_dir] + sx;
    int dy = ty[next_dir] + sy;
    if(dx < 0 || dx > 4 || dy < 0 || dy > 4) continue;
    if(!is_path[sx][sy][dx][dy]) continue;

    printf("%c",ch_dir[next_dir]);
    if(dx == 0 && dy == 0) return;

    dfs(dx,dy,next_dir);
    break;
  }
}

int main(){

  memset(is_path,false,sizeof(is_path));
  for(int i=0;i<9;i++){
    char buf[8];
    scanf("%s",buf);
    int y = i / 2;
    
    if(i % 2 == 0){
      for(int x=0;x<4;x++){
	if(buf[x] == '1'){
	  is_path[x][y][x+1][y] = true;
	  is_path[x+1][y][x][y] = true;
	}
      }
    }
    else if(i % 2 != 0){
      for(int x=0;x<5;x++){
	if(buf[x] == '1'){
	  is_path[x][y][x][y+1] = true;
	  is_path[x][y+1][x][y] = true;
	}
      }
    }
  }

  dfs(0,0,1);
  printf("\n");
}

Measured memory_bytes: 1112
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <ll, ll> pll;
const ll M=1e9+7;
ll inf=1e18;
int main()
{
    fast;
    int n;
    cin>>n;
    vector <ll> v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    ll dp[n][n];
    for(int l=n-1;l>=0;l--){
        for(int r=l;r<n;r++){
            if(l==r)
                dp[l][r]=v[l];
            else
                dp[l][r]=max(v[l]-dp[l+1][r],v[r]-dp[l][r-1]);
        }
    }
    cout<<dp[0][n-1];
}


Measured memory_bytes: 46464
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ll n;
    cin >> n;
    int a= 0 , t = 0 , w = 0, r =  0 ;
    string temp ;
    while(n--){
        cin >> temp;
        if(temp == "AC")
        a+=1;
        else if(temp == "WA")
        w+=1;
        else if(temp == "TLE")
        t+=1;
        else r+=1;

    }
    cout << "AC x "<< a<<"\n";
    cout << "WA x "<< w<<"\n";
    cout << "TLE x "<< t<<"\n";
    cout << "RE x "<< r<<"\n";
}

Measured memory_bytes: 3632
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define INF_LL 1000000000000000000LL
#define INF 200000000
#define MOD 998244353
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// typedef float double;
// typedef priority_queue prique;
typedef pair<ll, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vi> matrix;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}

struct edge {
    int to;
    ll cost;
    edge(int t, ll c) { to = t, cost = c; }
};

int main() {
    int n, q;
    cin >> n >> q;
    fenwick_tree<ll> fw(n);
    rep(i, n) {
        int a;
        cin >> a;
        fw.add(i, a);
    }
    rep(i, q) {
        int t, p, x;
        cin >> t >> p >> x;
        if(t == 0) {
            fw.add(p, x);
        } else {
            cout << fw.sum(p, x) << endl;
        }
    }
}


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

using namespace std;

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

const double PI=3.14159265358979323846;

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

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

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

int A, B, C;
vs32 l;

int solve(int x, int y, int z)
{
    vs32 temp(l);

    int ret = 1e6;
    do
    {
        vs32 syn(3, 0);
        int tt = (x + y + z - 3) * 10;
        rep (i, x) syn[0] += temp[i];
        for (int i = x; i < x + y; ++i) syn[1] += temp[i];
        for (int i = x + y; i < x + y + z; ++i) syn[2] += temp[i];
        sort(syn.begin(), syn.end());
        tt += abs(A - syn[2]) + abs(B - syn[1]) + abs(C - syn[0]);
        ret = MIN(ret, tt);
    } while (next_permutation(temp.begin(), temp.end()));
    return ret;
}

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

    int n;
    cin >> n >> A >> B >> C;

    l.resize(n);
    rep (i, n) cin >> l[i];
    sort(l.begin(), l.end());

    int ans = 1e6;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n - i; ++j)
        {
            for (int k = 1; k <= n - i - j; ++k)
            {
                ans = MIN(ans, solve(i, j, k));
            }
        }
    }

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



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

int main(){
	string s;
	cin >> s;
	int ans=999;
	for(int i=0; i<=s.size()-3; i++){
		int n = (s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0');
		ans = min(ans, abs(n-753));
	}

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


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

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int product = 0;
  for(int i = 1; i <= N; i++){
    int sum = 0;
    int x = i;
    while(x != 0){
      sum += x % 10;
      x /= 10;
    }
    if(sum >= A && sum <= B){
      product += i;
    }
  }
  cout << product << endl;
    
      
      
    
}
  

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
vi dy = { 0,0,1,-1 };
vi dx = { 1,-1,0,0 };
constexpr auto INF = 1050000000;
constexpr auto MOD = 1000000007;

int main() {
	int a,b,c,d,e,f;
	cin >> a >> b >> c >> d >> e >> f;

	double mxc = 0;
	int answ = 100*a, ansc = 0;

	rep(i, 31)rep(j, 31)rep(k, 3001) {
		if (i == 0 && j == 0)continue;
		if (f < (100 * a * i + 100 * b * j + c * k))continue;
		if (e * (a * i + b * j) < c * k)continue;
		int l1 = (f - (100 * a * i + 100 * b * j + c * k))/d;
		int l2 = (e * (a * i + b * j) - c * k) / d;
		int l = min(l1, l2);
		

		int water = 100 * a * i + 100 * b * j;
		int nacl = c * k + d * l;

		double cc = nacl / ((double)water + nacl);
		if (mxc < cc) {
			answ = water + nacl;
			ansc = nacl;
			mxc = cc;
		}
	}
	cout << answ << " " << ansc << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define F first
#define S second
#define FBO find_by_order
#define OOK order_of_key
#define mset(m,v) memset((m),(v),sizeof(m))
#define inrep int TC;cin>>TC;while(TC--)
#define cppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PI 3.1415926535897932384626433832795028841971693993751
#define trace1(x) cerr<<#x<<": "<<x<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<"\n"
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"\n"

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

// SOLUTION

int main() {
	cppio;
	int x, a, b;
	cin >> x >> a >> b;
	x -= a;
	cout << x % b;
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
shop_list = [list(map(int, input().split())) for i in range(N)]
shop_list.sort()
#print(shop_list)

remain = M
total_pay = 0
cur = 0
while remain > 0:
    buy = min(shop_list[cur][1], remain)
    total_pay = total_pay + shop_list[cur][0] * buy
    remain = remain - buy
    cur = cur + 1
#    print("buy:", buy, "total:", total_pay, "remain:", remain)
print(total_pay)

Measured memory_bytes: 27880
#include <stdio.h>

int main(void){

	int VertLines, HorLines;
	scanf("%d%d", &VertLines, &HorLines);
	
	int i;
	int Locations[VertLines];
	for(i = 0; i < VertLines; i++){
		Locations[i] = i+1;
	}


	int Temp, j,k;
	for(i = 0; i < HorLines; i++){
		scanf("%d,%d", &j, &k);
		j--; k--;
		Temp = Locations[j];
		Locations[j] = Locations[k];
		Locations[k] = Temp;
	}

	for(i = 0; i < VertLines; i++){
		printf("%d\n", Locations[i]);
	}
	
	return 0;
}

Measured memory_bytes: 596
// ※※※ 解答不能 ※※※
// quang氏.
// https://atcoder.jp/contests/abc127/submissions/5614198
#include <bits/stdc++.h>
using namespace std;

const int N = 200010;
const int MOD = (int)1e9 + 7;

inline int add(int u, int v){
    return (u += v) >= MOD ? u - MOD : u;
}

inline int sub(int u, int v){
    return (u -= v) < 0 ? u + MOD : u;
}

inline int mul(int u, int v){
    return (long long)u * v % MOD;
}

inline int power(int u, int v){
    int res = 1;
    while(v){
        if (v & 1) res = mul(res, u);
        u = mul(u, u);
        v >>= 1;
    }
    return res;
}

inline int inv(int u){
    return power(u, MOD - 2);
}

int n, m, k;
int fac[N];

int main(){
    scanf("%d %d %d", &n, &m, &k);
    fac[0] = 1;
    for(int i = 1; i <= n * m; i++) fac[i] = mul(fac[i - 1], i);
    int delta = mul(fac[n * m - 2], inv(mul(fac[k - 2], fac[n * m - k])));
    auto get = [&](int n, int m){
        int res = mul(m, m);
        res = mul(res, n - 1);
        res = mul(res, n);
        res = mul(res, n + 1);
        res = mul(res, inv(6));
        return res;
    };
    int res = add(get(n, m), get(m, n));
    res = mul(res, delta);
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=200010,M=99999999;
const long double pi=acos(-1.0);
int v[N];
struct Dat {
    int x,y;
    inline bool operator < (const Dat &A) const {return x<A.x;}
} g[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int a,b,A,B,t=0,tp=0,n;
    cin>>a>>b>>A>>B;
    if(a>A) swap(a,A),swap(b,B);
    if(b>B) b=M-b,B=M-B,t=1;
    cin>>n;
    for(int i=1;i<=n;i++) {
	int x=gi(),y=gi();
	if(x<a||x>A) continue;
	if(t) y=M-y;
	if(y<b||y>B) continue;
	g[++tp]=(Dat){x,y};
    }
    long double ans=(A-a+B-b)*100.0;
    sort(g+1,g+1+tp);
    int k=0;
    for(int i=1;i<=tp;i++) {
	if(g[i].y>=v[k]) v[++k]=g[i].y;
	else v[lower_bound(v+1,v+1+k,g[i].y)-v]=g[i].y;
    }
    if(k==A-a+1||k==B-b+1) ans+=5*pi;
    ans+=k*(5*pi-20);
    printf("%.20Lf",ans);
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

int main(){
	int n;
	cin >> n;
	if(n==25){
		cout << "Christmas" << endl;
	}
	else if (n == 24)
	{
		cout << "Christmas Eve" << endl;
	}
	else if(n == 23)
	{
		cout << "Christmas Eve Eve" << endl;
	}else if (n == 22)
	{
		cout << "Christmas Eve Eve Eve" << endl;
	}
	else

		return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
    int h, w;
    while (cin >> h >> w, h || w) {
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
                if ((y + x) % 2 == 0) {
                    cout << "#";
                } else {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define N 200005
#define M 1000000007
#define ll long long

string k;
int d, n;
ll dp[N][105][2];

ll cal(int i, int rm, int is)
{
    if(i == n) return rm? 0 : 1;
    if(dp[i][rm][is] != -1) return dp[i][rm][is];
    int mx = is? (k[i] - '0') : 9;
    dp[i][rm][is] = 0;
    for(int j = 0; j <= mx; j++)
    {
        dp[i][rm][is] = (dp[i][rm][is] + cal(i + 1, (rm + j) % d, (is && j == mx) ? true : false)) % M;
    }
    return dp[i][rm][is];
}


int main()
{
    memset(dp, -1, sizeof(dp));
    cin >> k >> d;
    n = k.size();
    cout << (cal(0, 0, 1) - 1 + M) % M << endl;
}



Measured memory_bytes: 329344
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    int N,M;cin >> N >> M;
       map<int, vector<int>> vec;
       for(int i = 0;i < N;i++){
           int b,c;cin >> b >> c;
           vec[b].push_back(c);
       }
       LL ans = 0;
       priority_queue<int> que;
       for(int i = 1;i <= M;i++){
           if(vec.find(i) == vec.end()){
               if(que.empty())continue;
               ans += que.top();
               que.pop();
           }else{
               for(auto a : vec[i])que.push(a);
               ans += que.top();
               que.pop();
           }
       }
       cout<<ans<<endl;
}


Measured memory_bytes: 10880
N , X =map(int,input().split())
sums = []
i = X
result =[]
a = []
for i in range(N):
    sums.append(i+X)
for j in range(N):
    a.append(abs(sums[j]))

if sum(sums) ==abs(sum(sums)):
    print(sum(sums) - min(a))
else :
    print(sum(sums) + min(a))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  cin >> N;
  va.resize(N);
  rep(i, 0, N - 1) { cin >> va[i]; };
  ;
}
void solve() {
  set<int> st;
  for (auto x : va) {
    st.insert(x);
  }
  if (st.size() == N) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  cout << endl;

  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long n;
	cin>>n;
	long long cur=0,x=0;
	while(cur++<n){
		if(!(cur%3==0||cur%5==0)){
			x+=cur;
		}
	}
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cmath>
#include <cstring>

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)
#define SCANFD(x) scanf("%d",&x)

long size=0;
long num[10];

long dfs(long i,long sum,long psum){
    if(i==size-1)
        return sum+psum*10+num[i];
    
    return dfs(i+1,sum,psum*10+num[i]) + dfs(i+1,sum+psum*10+num[i],0);
}

int main(){
    vector<char> S;
    long res;
    char buf;

    while(1){
        scanf("%c",&buf);
        if(buf=='\n')
            break;
        size++;
        S.push_back(buf);
    }    

    REPI(size){
        num[i] = S[i] - '0';
    }

    res = dfs(0,0,0);
    printf("%ld\n",res);

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
bc = []
for i in range(m):
    bc.append(list(map(int, input().split())))
bc.sort(key=lambda x: x[1], reverse=True)

for i in bc:
    if a[0] < i[1]:
        for j in range(i[0]):
            if a[0] < i[1]:
                a.append(i[1])
                del a[0]
            else:
                break
    else:
        break
        
print(sum(a))


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

int main(){
    string s;
    cin >> s;
    int n = s.length();

    int now = 0;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '<'){
            ans += now;
            now++;
        }else{
            int cou = 0; 
            int flag = 0;
            while(1){
                if(s[i] == '<' || i == n){
                    break;
                }
                ans += cou;
                cou++;
                i++;
            }

            if(now > cou){
                ans += now;
            }else{
                ans += cou;
            }
            now = 0;
            i--;
        }
    }

    if(s[n - 1] == '<'){
        ans += now;
    }


    cout << ans << endl;
}

Measured memory_bytes: 900
#include <stdio.h>

int main(void)
{
	int game_no;
	int base;
	int life;
	int point;
	char event[9];
	
	scanf("%d", &game_no);
	
	while (game_no--){
		point = 0;
		base = 0;
		life = 3;
		
		while (life){
			scanf("%s", event);
			switch (event[0]){
			  case 'H':
			  	base++;
				if (base > 3){
					point++;
					base = 3;
				}
				if (event[1] == 'O'){
					point += base;
					base = 0;
				}
			  	break;
				
		  	  default:
		  		life--;
				break;
			}
		}
		
		printf("%d\n", point);
	}
	
	return (0);
}

Measured memory_bytes: 0
import itertools, math
N = int(input())
d = [list(map(int,input().split())) for k in range(N)]
ans = 0
for e in itertools.permutations(d):
    temp = 0
    for k in range(len(e)-1):
        temp += math.sqrt((e[k][0] - e[k+1][0])**2 + (e[k][1] - e[k+1][1])**2)
    ans += temp
f = 1
for k in range(2,N+1):
    f *= k

print(ans/f)


Measured memory_bytes: 42476
#include<stdio.h>

int main(){
	int i,j,k,l,n,m;
	int q,w,e,r,t,y;
	int a[100002];

//acwhile(1){
	scanf("%d",&n);
//if(n==0)break;
	for(i = 0;i < 100002;i++)a[i]=0;
	for(i = 0;i < n;i++){
		scanf("%d%d",&q,&w);
		a[q]++;
		a[w+1]--;
	}
	w = 0;
	q = a[0];
	for(i = 1;i < 100002;i++){
		q += a[i];
		if(q+1 >= i)w=i-1;
	}
	printf("%d\n",w);
//}
	return 0;
}

Measured memory_bytes: 988
N=int(input())
A=list(map(int,input().split()))
dic={}
for i in range(N):
  if(A[i] not in dic):
    dic[A[i]]=1
  else:
    dic[A[i]]+=1
Q=int(input())
s=sum(A)
for i in range(Q):
  B,C=list(map(int,input().split()))
  t=dic.get(B,0)
  s=s - t*B
  s=s + t*C
  print(s)
  if(C in dic):
    dic[C]+=t
  else:
    dic[C]=t
  dic[B]=0

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

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

struct UnionFind
{
    vector<int> parent;
    vector<int> friends;
    UnionFind(int n) : parent(n), friends(n) {
        for(int i = 0; i < n; i++) parent[i] = i;
        friends.assign(n, 1);
    }

    int root(int x){
        return x == parent[x] ? x : (parent[x] = root(parent[x]));
    }

    void unite(int x, int y){
        int rx = root(x), ry = root(y);
        if(rx != ry){
            parent[rx] = parent[ry];
            friends[ry] += friends[rx];
            friends[rx] = 0;
        }
        return;
    }

    bool isSame(int x, int y){
        return root(x) == root(y);
    }

    int count(int x){
        return friends[root(x)];
    }
};

int main()
{
    int n, m, k; cin >> n >> m >> k;
    UnionFind u(n);
    vector<vector<int> > blocked(n);
    rep(i, m){
        int ai, bi; cin >> ai >> bi;
        --ai, --bi;
        u.unite(ai, bi);
        blocked[ai].push_back(bi);
        blocked[bi].push_back(ai);
    }

    rep(j, k){
        int cj, dj; cin >> cj >> dj;
        --cj, --dj;
        blocked[cj].push_back(dj);
        blocked[dj].push_back(cj);
    }
    rep(i, n){
        int cnt = u.count(i);
        for(auto b : blocked[i]){
            if(u.isSame(i, b)) cnt--;
        }
        cout << cnt-1; // cnt includes i itself
        if(i == n-1) cout << endl;
        else cout << " ";
    }
    
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> color(9);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a >= 3200) color.at(8)++;
        else color.at(a / 400)++;
    }
    
    int minimum = 0, maximum;
    for (int i = 0; i < 8; i++) {
        if (color.at(i) > 0) minimum++;
    }

    maximum = minimum + color.at(8);
    if (minimum == 0) minimum++;

    cout << minimum << " " << maximum << endl;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define forn(i,n) for(int i = 0; i < (int) n; i++)
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
typedef long long ll;

void solve() {
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  vector<int> cst(6);
  cst[2] = a;
  cst[3] = b;
  cst[5] = c;

  map<ll, ll> dist;
  set<ll> done;
  priority_queue<pair<ll, ll>> q;
  dist[n] = 0;
  dist[0] = 5e11;
  q.push({0, n});

  while(!q.empty()) {
    ll D = q.top().first;
    ll u = q.top().second;
    q.pop();
//    cout << "working on " << u << " (" << -D << ")\n";
    if (done.find(u) != done.end()) continue;
    done.insert(u);
    if (u == 0) {
      cout << dist[u] << "\n";
      return;
    }

    for(int s : vector<int> {2, 3, 5}) {
      if (u % s == 0 && (!dist.count(u / s) || dist[u / s] > dist[u] + cst[s])) {
        dist[u / s] = dist[u] + cst[s];
        q.push({ -dist[u / s], u / s});
      }

      if (u % s != 0) {
        if (!dist.count((u - u % s) / s) || dist[(u - u % s) / s] > dist[u] + d * (u % s) + cst[s]) {
          dist[(u - u % s) / s] = dist[u] + d * (u % s) + cst[s];
          q.push({ -dist[(u - u % s) / s], (u - u % s) / s});
        }
        if (!dist.count((u + s - u % s) / s) || dist[(u + s - u % s) / s] > dist[u] + d * (s - u % s) + cst[s]) {
          dist[(u + s - u % s) / s] = dist[u] + d * (s - u % s) + cst[s];
          q.push({ -dist[(u + s - u % s) / s], (u + s - u % s) / s});
        }
      }
    }

    if (d <= (dist[0] - dist[u]) / u && d * u + dist[u] < dist[0]){
      dist[0] = d * u + dist[u];
      q.push({-dist[0], 0});
    }
  }
}

int main() {
  ios;
  int t;
  cin >> t;
  while(t--) solve();
}


Measured memory_bytes: 4960
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	if((a*b)%2) cout<<"Odd"<<endl;
	else cout<<"Even"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;


int main() {
    int c[4][4];
    for (int i = 1; i <= 3; i++) {
        for (int j = 1; j <= 3; j++)cin >> c[i][j];
    }
    bool ans = true;
    int t = c[2][1] - c[1][1];
    for (int i = 2; i <= 3; i++) if (c[2][i] - c[1][i] != t)ans = false;
    t = c[3][1] - c[2][1];
    for (int i = 2; i <= 3; i++) if (c[3][i] - c[2][i] != t)ans = false;
    t = c[1][2] - c[1][1];
    for (int i = 2; i <= 3; i++) if (c[i][2] - c[i][1] != t)ans = false;
    t = c[1][3] - c[1][2];
    for (int i = 2; i <= 3; i++) if (c[i][3] - c[i][2] != t)ans = false;
    if (ans)Yes;
    else No;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static IntStream REPS(int v){
		return IntStream.range(0,v);
	}
	static IntStream REPS(int l,int r){
		return IntStream.rangeClosed(l,r);
	}
	static IntStream INS(int n){
		return REPS(n).map(i->getInt());
	}
	static int getInt(){
		return Integer.parseInt(s.next());
	}
	
	public static void main(String[] __){
		String str=s.next();
		HashMap<Character,ArrayList<Integer>> h=new HashMap<>();
		for(char c='a';c<='z';c++){
			h.put(c,new ArrayList<>());
			h.get(c).add(-1);
		}
		
		for(int i=0;i<str.length();i++){
			final char c=str.charAt(i);
			h.get(c).add(i);
		}
		
		for(char c='a';c<='z';c++){
			h.get(c).add(str.length());
		}
		
		/*
		Entry<Character,ArrayList<Integer>> target=h.entrySet().stream().min(Entry.comparingByValue(
				Comparator.<ArrayList<Integer>>comparingInt(o->{
					int max=-114514;
					for(int i=1;i<o.size();i++)
						max=Math.max(max,o.get(i)-o.get(i-1));
					return max;
				}))
				).get();
		
		System.out.println(target.getKey());
		System.out.println(target.getValue());
		*/
		
		//h.entrySet().forEach(System.out::println);
		
		
		System.out.println(h.values().stream().mapToInt(o->{
			int max=-114514;
			for(int i=1;i<o.size();i++)
				max=Math.max(max,o.get(i)-o.get(i-1));
			return max;
		}).min().getAsInt()-1);
	}
}


Measured memory_bytes: 26964
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=200010;
const LL inf=(1LL<<60);
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
int n;LL d,a[Maxn];
struct Node{LL v;int x;Node(LL _v=0,int _x=0){v=_v;x=_x;}};
bool operator<(Node a,Node b){return a.v<b.v;}
struct Seg{int l,r,lc,rc,pos;Node p[5];}tr[Maxn<<1];
int tot;
void up(int x)
{
	int lc=tr[x].lc,rc=tr[x].rc;
	for(int i=0;i<5;i++)
	if(tr[lc].p[i]<tr[rc].p[i])
	{
		tr[x].p[i]=tr[lc].p[i];
		if(i==4)tr[x].pos=tr[lc].pos;
	}
	else
	{
		tr[x].p[i]=tr[rc].p[i];
		if(i==4)tr[x].pos=tr[rc].pos;
	}
	if(tr[lc].p[2].v!=inf&&tr[rc].p[1].v!=inf)
	{
//		puts("ok");
		LL t=tr[lc].p[2].v+tr[rc].p[1].v;
//		printf("t=%lld\n",t);
		if(t<tr[x].p[4].v)tr[x].p[4]=Node(t,tr[lc].p[2].x),tr[x].pos=tr[rc].p[1].x;
	}
	if(tr[lc].p[0].v!=inf&&tr[rc].p[3].v!=inf)
	{
		LL t=tr[lc].p[0].v+tr[rc].p[3].v;
		if(t<tr[x].p[4].v)tr[x].p[4]=Node(t,tr[rc].p[3].x),tr[x].pos=tr[lc].p[0].x;
	}
}
void build(int l,int r)
{
	int x=++tot;
	tr[x].l=l;tr[x].r=r;
	for(int i=0;i<5;i++)tr[x].p[i]=Node(inf,0);
	if(l==r)
	{
		if(l!=1)
		{
			tr[x].p[0]=Node(a[l]-(LL)l*d,l);
			tr[x].p[1]=Node(a[l]+(LL)l*d,l);
			tr[x].p[2]=tr[x].p[3]=tr[x].p[4]=Node(inf,0);
		}
		else
		{
			tr[x].p[0]=tr[x].p[1]=tr[x].p[4]=Node(inf,0);
			tr[x].p[2]=Node(a[l]-(LL)l*d,l);
			tr[x].p[3]=Node(a[l]+(LL)l*d,l);
		}		
		return;
	}
	int mid=l+r>>1;
	tr[x].lc=tot+1,build(l,mid);
	tr[x].rc=tot+1,build(mid+1,r);
	up(x);
}
void modify(int x,int p)
{
	for(int i=0;i<5;i++)tr[x].p[i]=Node(inf,0);
	if(tr[x].l==tr[x].r)
	{
		int l=tr[x].l;
		tr[x].p[0]=tr[x].p[1]=tr[x].p[4]=Node(inf,0);
		tr[x].p[2]=Node(a[l]-(LL)l*d,l);
		tr[x].p[3]=Node(a[l]+(LL)l*d,l);
		return;
	}
	int mid=tr[x].l+tr[x].r>>1,lc=tr[x].lc,rc=tr[x].rc;
	if(p<=mid)modify(lc,p);
	else modify(rc,p);
	up(x);
}
int main()
{
	n=read(),d=read();
	for(int i=1;i<=n;i++)a[i]=read();
	build(1,n);
	
	int m=n-1;LL ans=0;
	while(m--)
	{
//		for(int i=1;i<=tot;i++)printf("%d %d %d %lld\n",i,tr[i].l,tr[i].r,tr[i].p[4].v);
		ans+=tr[1].p[4].v;
//		printf("#  %lld %d\n",tr[1].p[4].v,tr[1].pos);
		modify(1,tr[1].pos);
		
	}
	printf("%lld",ans);
}

Measured memory_bytes: 42496
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define str string
#define fori(i,n) for(long long i=1;i<=n;++i)
#define forj(j,n) for(long long j=1;j<=n;++j)
#define fork(k,n) for(long long k=1;k<=n;++k)
#define fors(i,ssz) for(long long i=0;i<s.size();++i)
#define Need_for_Speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
using namespace std;
ll n,a[100005],k,dp[100005],mn;
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
    	cin>>a[i];
	}
	dp[1]=0;
	for(int i=2;i<=n;i++){
		mn=dp[i-1]+abs(a[i]-a[i-1]);
		for(int j=1;j<=k;j++){
			if(i-j<1)
			break;
			mn=min(mn,dp[i-j]+abs(a[i]-a[i-j]));
		}
		dp[i]=mn;
	}
	cout<<dp[n];
}
	
	
	

Measured memory_bytes: 5168
#include<stdio.h>
#include<math.h>
int main(void)
{
	int N;
	int i;
	int number[4];
	int amari[3];
	scanf("%d", &N);
	for (i = 0; i < 4; i++)
	{
		number[i] = N % int(pow(10, i + 1)) / int(pow(10, i));
	}
	for (i = 0; i < 3; i++)
	{
		amari[i] = number[i] - number[i + 1];
	}
	if ((amari[0]==0&&amari[1]==0)||(amari[1]==0&&amari[2]==0))
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
}

Measured memory_bytes: 256
# /usr/bin/python
# -*- coding: utf-8 -*-
from collections import deque,defaultdict


N = int(input())

colors = [-1 for _ in range(N)]
tree = [{} for _ in range(N)]
for _ in range(N-1):
  u,v,w = map(int, input().split())
  tree[u-1][v-1] = w % 2
  tree[v-1][u-1] = w % 2

visiting = deque([0])
colors[0] = 0
while len(visiting) > 0:
  p = visiting.popleft()
  for q in tree[p]:
    if colors[q] < 0:
      colors[q] = (tree[p][q]+colors[p]) % 2
      visiting.append(q)

for c in colors:
  print(c)

Measured memory_bytes: 88096
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include <bits/stdc++.h>

using namespace std;
static const unsigned long long  MOD=1000000007;

int n;
string s;

uint64_t dp[100005][13];
//dp[i][j]=
//先頭i文字として考えられるもののうち、
//13で割ったあまりがjであるものの数



int main(){

int i,j,ki;
uint64_t res=0;

cin >> s;
n=s.size();//文字列の長さ

dp[0][0]=1;//先頭0文字を13で割ったあまりが0=1個
for(i=0;i<n;i++){
    int c;
    if(s[i]=='?')c=-1;
    else c=s[i]-'0';//文字を数字に変換

    for(j=0;j<10;j++){//jは
        if(c!=-1 && c!=j)continue;
        for(ki=0;ki<13;ki++){
            dp[i+1][(ki*10+j)%13]+=dp[i][ki];
            }
    }
    for(j=0;j<13;j++)dp[i+1][j]%=MOD;//求めたiについてのdpをMODをとっておく
}
res=dp[n][5];

cout<<res<<endl;



 return 0;
}

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

using namespace std;

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

	int n;
	cin >> n;

	vector<int> ans;
	ans.resize(n);

	for(int i = 1; i < n; ++i) {
		int x;
		cin >> x;
		++ans[x - 1];
	}

	for(int i : ans) {
		cout << i << '\n';
	}

	return 0;
}


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

int n, m;
vector<int> v[8];
bool visited[8] = {false};

int func(int current){
    bool allvisited = true;
    FOR(i, n){
        if(visited[i] == false) allvisited = false;
    }

    if(allvisited) return 1;

    int ret = 0;
    FOR(i, v[current].size() ){
        if(visited[v[current][i]] == true) continue;

        visited[v[current][i]] = true;
        ret += func(v[current][i]);
        visited[v[current][i]] = false;
    }

    return ret;
}

int main() {
    cin >> n >> m;
    FOR(i, m){
        int x, y;
        cin >> x >> y;
        v[x - 1].push_back(y - 1);
        v[y - 1].push_back(x - 1);
    }

    visited[0] = true;
    cout << func(0) << endl;

    return 0;
}


Measured memory_bytes: 256
s = gets.chomp
while s.size > 0
  if s[0, 5] == 'dream'
    s.slice!(0, 5)
    if s[0, 2] == 'er' && s[0, 5] != 'erase'
      s.slice!(0, 2)
    end
  elsif s[0, 5] == 'erase'
    s.slice!(0, 5)
    s.slice!(0) if s[0] == 'r'
  else
    puts 'NO'
    exit
  end
end
puts 'YES'


Measured memory_bytes: 78076
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
int main(){
  ll A,B;
  cin>>A>>B;
  if(A==1 && B==1){cout<<1000000<<endl;}
  else{cout<<max((ll)0,100000*(4-A))+max((ll)0,100000*(4-B))<<endl;}
}

Measured memory_bytes: 256
#include <stdio.h>
#define NIL -1
void preorder(int u);
void inorder(int u);
void postorder(int u);

typedef struct Node{
int p;
int l;
  int r;
} node;
  
node T[10005];
int n;

int main(){
  int i,v,left,right,root=0;

  scanf("%d",&n);
  //ini
  for(i=0;i<n;i++) T[i].p=-1;
  
  //input
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&left,&right); 
    T[v].l=left;
    T[v].r=right;
    if(left!=NIL) T[left].p=v;
    if(right!=NIL) T[right].p=v;
  }

  for(i=0;i<n;i++){
    if(T[i].p==NIL) root=i;
  }

  //print
  printf("Preorder\n");
  preorder(root);
  printf("\n");
  printf("Inorder\n");
  inorder(root);
  printf("\n");
  printf("Postorder\n");
  postorder(root);
  printf("\n");

  return 0;
}

void preorder(int u){
  if(u==NIL) return;  
  printf(" %d",u);
  preorder(T[u].l);
  preorder(T[u].r);
}

void inorder(int u){
  if(u==NIL) return;
  inorder(T[u].l);
  printf(" %d",u);
  inorder(T[u].r);
}

void postorder(int u){
  if(u==NIL) return;
  postorder(T[u].l);
  postorder(T[u].r);
  printf(" %d",u);
}

Measured memory_bytes: 620
import java.util.*;

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a = sc.nextInt();
        long b = sc.nextInt();
        long k = sc.nextLong();
        Combination comb = new Combination(n + 1);
        long total = 0;
        for (int i = 0; i * a <= k; i++) {
            if ((k - i * a) % b != 0) {
                continue;
            }
            int j = (int)((k - i * a) / b);
            total += (comb.getComb(n, i) * comb.getComb(n, j)) % MOD;
            total %= MOD;
        }
        System.out.println(total);
    }
}

class Combination {
    static final int MOD = 998244353;
    long[] fac;
    long[] finv;
    long[] inv;
    
    public Combination (int size) {
        fac = new long [size];
        finv = new long [size];
        inv = new long [size];
        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < size; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    
    
    public long getComb(int n, int k) {
        if (n < k || n < 0 || k < 0) {
            return 0;
        }
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
    
}




Measured memory_bytes: 33492
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] food = new int[M];
		for(int i = 0; i < N; i++) {
			int K = sc.nextInt();
			for (int j = 0; j < K ; j++) {
				food[sc.nextInt()-1]++;
			}
		}
		int ans = 0;
		for (int i = 0; i < M; i++) {
			if (food[i] == N) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 22612
#include <stdio.h>
long int factorial (int n);

int main () {
	int n;
	while (scanf ("%d", &n) != EOF) {
		printf ("%ld\n", factorial (n));
	}
	return 0;	
}

long int factorial (int n) {
	if (n > 1) {
		return n * factorial(n-1);
	} else if (n == 1) {
		return n;
	} else {
		return 0;
	}
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>

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

using namespace std;
typedef long long ll;

const int INF = INT32_MAX;

int main() {
    int n; cin >> n;
    vector<vector<int>> dp(n+1, vector<int>(3, 0));
    vector<int> event(3);
    rep(i, n) {
        rep(j, 3) cin >> event[j];
        rep(j, 3) rep(k, 3) {
            if (j == k) continue;
            dp[i+1][k] = max(dp[i+1][k], dp[i][j] + event[k]);
        }
    }

    int ans = 0;
    rep(i, 3) ans = max(ans, dp[n][i]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
using namespace std;
int main()
{
    int h, w, k, cnt, ans = 0, b = 0;
    int c[6][6] = {}, hc[6] = {}, wc[6] = {};
    char tmp;
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> tmp;
            c[i][j] = (tmp == '#' ? 1 : 0);
            hc[i] += c[i][j];
            wc[j] += c[i][j];
            b += c[i][j];
        }
    }
    for (int n = 0; n < (1 << h); n++) {
        for (int m = 0; m < (1 << w); m++) {
            cnt = b;
            for (int i = 0; i < h; i++) {
                if ((n >> i) & 1) cnt -= hc[i];
            }
            for (int j = 0; j < w; j++) {
                if ((m >> j) & 1) cnt -= wc[j];
            }
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (((n >> i) & 1) && ((m >> j) & 1)) {
                        cnt += c[i][j];
                    }
                }
            }
            if (cnt == k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	map<int,int>mp;
	mp[1]=3;
	mp[2]=2;
	mp[3]=1;
	int x, y;
	cin>>x>>y;
	int ans = mp[x]+mp[y];
	if(x==1 && y==1)
		ans +=4;
	cout<<ans*100000<<endl;
	return 0;
}

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

using namespace std;

int main()

{
    long long int ans=0,i,n,ara[200005];
    scanf("%lld",&n);
    for(i=0;i<n;i++){
        scanf("%lld",&ara[i]);
    }
    ans=0;
    for(i=1;i<n;i++){
        if(ara[i]<ara[i-1]){
            ans+=(ara[i-1]-ara[i]);
            ara[i]=ara[i-1];
        }
    }
    printf("%lld\n",ans);

    return 0;
}

Measured memory_bytes: 5316
def prime(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N = int(input())
a = prime(N)
a.sort()
import copy
b = copy.copy(a)
b = list(set(b))
b.sort()

ret = 0
for i in b:
    cnt = 0
    idx=0
    while True:
        idx += 1
        cnt = cnt + idx
        if a.count(i) >= cnt:
            ret += 1
        else:
            break

print(ret)

Measured memory_bytes: 9224
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) std::cin>>(P)
#define IN2(P1,P2) std::cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) std::cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) std::cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) std::cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) std::cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) std::cout<<P<<std::endl
#define OUT2(P1,P2) std::cout<<P1<<" "<<P2<<std::endl
#define OUT3(P1,P2,P3) std::cout<<P1<<" "<<P2<<" "<<P3<<std::endl
#define OUTS(I,N,V) REP(I,N) std::cout<<V[i]<<std::endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
typedef unsigned long ul;
typedef vector<vector<int> > graph;
const long long INF = 1LL<<60;
ul N,M,i,v,x,y,ans,dp[100001];
graph G;
vector<ul> indeg;
queue<ul> q;
inline void solve(){
  IN2(N,M);
  G.resize(N,vector<int>());
  indeg.resize(N);
  REP(i,M){
    IN2(x,y);
    --x;--y;
    G[x].push_back(y);
    indeg[y]++;
  }
  REP(v,N)if(indeg[v]==0)q.push(v);
  while(!q.empty()){
    v=q.front();q.pop();
    for(auto nv:G[v]){
      indeg[nv]--;
      if(indeg[nv]==0){
        q.push(nv);
        chmax(dp[nv],dp[v]+1);
      }
    }
  }
  REP(v,N)chmax(ans,dp[v]);
  OUT(ans);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 7296
while (True):
    a, b = list(map(int, input().split(" ")))
    if(a == 0 and b == 0):
        break
    # print(a, b)
    score = [[0] for i in range(b)]
    for i in range(b):
        score[i] = list(map(int, input().split()))
    sum = 0
    maxSum = 0
    for i in range(a):
        sum = 0
        for j in range(b):
            sum += score[j][i]
            if (sum > maxSum):
                maxSum = sum
    print(maxSum)



Measured memory_bytes: 7676