akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>
#include <string>
#include <iostream>
using namespace std;

class Dice {

private:
	int TOP = 0; int FRONT = 1; int RIGHT = 2; int LEFT = 3; int BACK = 4; int BOTTOM = 5;
	void swap(int tp, int fr, int bt, int ri, int lf, int bk);

public:
	int pips[6];
	bool equals(int d[6]);
	void rotate(char op);
	void spin();
	void setTopAndFront(int top, int front);
};

bool Dice::equals(int d[6]) {
	for (int i = 0; i < 6; i++) {
		if (pips[i] != d[i]) {
			return false;
		}
	}
	return true;
}

void Dice::rotate(char op) {
	switch (op) {
	case 'N': swap(FRONT, BOTTOM, RIGHT, LEFT, TOP, BACK); break;
	case 'S': swap(BACK, TOP, RIGHT, LEFT, BOTTOM, FRONT); break;
	case 'E': swap(LEFT, FRONT, TOP, BOTTOM, BACK, RIGHT); break;
	case 'W': swap(RIGHT, FRONT, BOTTOM, TOP, BACK, LEFT); break;
	}
}

void Dice::spin() {
	swap(TOP, LEFT, FRONT, BACK, RIGHT, BOTTOM);
}

void Dice::swap(int tp, int fr, int ri, int lf, int bk, int bt) {
	int wk[6] = { pips[tp], pips[fr], pips[ri], pips[lf], pips[bk], pips[bt] };
	for (int i = 0; i < 6; i++) pips[i] = wk[i];
}

void Dice::setTopAndFront(int top, int front) {
	if (pips[LEFT] == top) rotate('E');
	if (pips[RIGHT] == top) rotate('W');
	while (pips[TOP] != top) { rotate('N'); }
	while (pips[FRONT] != front) { spin(); }
}

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

	Dice d[100];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 6; j++) {
			cin >> d[i].pips[j];
		}
	}

	bool f = true;
	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			if (d[i].equals(d[j].pips)) {
				f = false;
			}

			for (int k = 0; k < 4; k++) {
				d[j].rotate('E');
				for (int l = 0; l < 4; l++) {
					if (d[i].equals(d[j].pips)) {
						f = false;
					}
					d[j].rotate('N');
				}
			}

			for (int k = 0; k < 4; k++) {
				d[j].rotate('W');
				for (int l = 0; l < 4; l++) {
					if (d[i].equals(d[j].pips)) {
						f = false;
					}
					d[j].rotate('N');
				}
			}
		}
	}

	if (f) cout << "Yes" << "\n";
	else cout << "No" << "\n";
}


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

#define reb(i,b,n) for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n) reb(i,0,n)
#define rreb(i,b,n) for(int i = b-1; i >= n; i--)
#define rrep(i,n) reb(i,n,0)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v) for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vall(x) (x).begin(), (x).end()
#define rvall(x) (x).rbegin(), (x).rend()
#define vsort(v) sort(vall(v))
#define rvsort(v) sort(rvall(v))
#define len(array) (sizeof (array) / sizeof *(array))
#define aall(x) x, x+len(x)
#define asort(x) sort(aall(x))
#define rasort(a, type) sort(aall(a), greater<type>())
#define afill(a, v) fill(aall(a), v)
#define afill2(a, v, type) fill((type *)a, (type *)(a + len(a)), v)
#define sz(x) (int)(x).size()
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define pb push_back
#define _USE_MATH_DEFINES
#define priArr(table, n) rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define priAr2(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;

using namespace std;
using std::stringstream;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline std::string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class F, class T> inline void convert(const F &f, T &t){stringstream ss;ss<<f;ss>>t;}
template<class T> inline T sqr(T x) {return x*x;}

typedef long long ll; typedef unsigned long long ull;
typedef pair <int, int> P; typedef pair <int, P> PP;
typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<string> vs;
typedef vector<ll> vl; typedef vector<P > vP; typedef vector<char> vc;
typedef long double ld;

const static int INF = 0x3f3f3f3f;
const static ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const static double EPS = 1e-9;
const static ll MOD = 1000000007LL;

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

int main(int argc, char *argv[])
{
    int t;
    cin >> t;
    cout << 48-t << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int main(){
    int n,q; cin >>n >> q;
    string s; cin >> s;
    int l,r;

    int cnt[100010];
    cnt[0] = 0;
    for(int i = 1; i < n; i++){
        if(s[i-1] == 'A' && s[i] == 'C'){
            cnt[i] = cnt[i-1]+1;
        } else cnt[i] = cnt[i-1];
    }
    for(int i = 0; i < q; i++){
        cin >> l >> r;
        l--; r--;
        int ans = cnt[r]-cnt[l];
        cout << ans << endl;
    }
    cout << endl;
}



Measured memory_bytes: 1408
from collections import Counter
from string import ascii_lowercase

A = input()


# 英小文字xについて、Aに含まれるxの個数をc[x]で表す。
# 解は、1 + c['a'](c['b'] + ... + c['z']) +
# c['b'](c['c'] + ... + c['z']) + c['y']['z'] である。
c = Counter(A)
ans = 1 + sum(
    c[x] * sum(c[y] for y in ascii_lowercase if x < y)
    for x in ascii_lowercase
)

print(ans)


Measured memory_bytes: 4144
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}

int T, t[40];
int N;
int M[200];
int last, dp[200];

// x日目以降の最小
int rec(int x){
    if(x >= last) return 0;
    int & res = dp[x];
    if(res != -1) return res;
    int ans = 1<<29;
    bool ok = true;
    for(int i=x; i<=last; i++){
        if(M[i] < t[(i-x)%T]){
            ok = false;
            break;
        }
    }
    if(ok) return 0;
    for(int i=x+1; i<=last; i++){
        ans = min(1+rec(i) , ans);
        if(M[i] < t[(i-x)%T]) break;
    }
    return res = ans;
}

int main(){
#ifdef LOCAL
    freopen("in","r",stdin);
#endif
    while(cin>>T && T){
        memset(dp,-1,sizeof(dp));
        rep(i,200) M[i] = 24;
        rep(i,T) cin >> t[i];
        cin >> N;
        rep(i,N){
            int x,y;
            cin >> x >> y;
            M[x] = min(M[x],y);
            last = max(last, x);
        }
        cout << rec(1) << endl;
    }
}

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

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

  double ans = 0;
  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j < n; j++ ) {
      ans += sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) );
    }
  }
  ans /= n;

  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 3852
#include <stdio.h>
#include <string.h>

int main(int argc, char const *argv[])
{
  char str[201];
  while( scanf(" %s", str) ){
    if ( !strcmp(str, "-" ) ) break;

    int m, h = 0, b, i;
    scanf("%d", &m);
    
    for(i = 0; m > i; i++){
      scanf("%d", &b);
      h += b;
    }
      h %= strlen(str);
    for(i = h; strlen(str) + h > i; i++){
      printf("%c", str[i%strlen(str)]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2052
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int q, a, b;
signed main() {
	cin >> q;
	rep(i, q) {
		cin >> a >> b;
		int mi = min(a, b), ma = max(a, b) + 1;
		while (mi + 1 < ma) {
			int md = (mi + ma) / 2;
			if (md * md < a * b)mi = md;
			else ma = md;
		}
		int c = mi;
		if (a == b || abs(a - b) == 1)cout << min(a, b) * 2 - 2 << endl;
		else if (c * (c + 1) >= a * b)cout << c * 2 - 2 << endl;
		else cout << c * 2 - 1 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef pair<double, int> pdi;
typedef vector<pdi> vdi;
typedef vector<vdi> vvdi;

const int MAX_V = 1000;
const int MAX_E = 1000000;
const double INF = 1001001001;

int V, E;
double ans[MAX_V];
vvdi edges(MAX_E);
bool visited[MAX_V];

int n;

double dist(double x[2], double y[2], double r[2]) {
  return max(sqrt(pow(x[0] - x[1], 2) + pow(y[0] - y[1], 2)) - r[0] - r[1], 0.0);
}

void input() {
  double tx, ty, tr;
  double xs, ys, xt, yt;
  double x[MAX_V+2], y[MAX_V+2], r[MAX_V+2];
  cin >> xs >> ys >> xt >> yt;
  cin >> n;
  V = n + 2; E = V * (V - 1) / 2;
  x[0] = xs; y[0] = ys; r[0] = 0.0;
  for (int i=0; i<n; i++) {
    cin >> tx >> ty >> tr;
    x[i+1] = tx; y[i+1] = ty; r[i+1] = tr;
  }
  x[n+1] = xt; y[n+1] = yt; r[n+1] = 0.0;

  for (int i=0; i<n+2; i++) {
    for (int j=i+1; j<n+2; j++) {
      double xd[2] = { x[i], x[j] }, yd[2] = { y[i], y[j] }, rd[2] = { r[i], r[j] };
      double d = dist(xd, yd, rd);
      edges[i].PB(MP(d, j));
      edges[j].PB(MP(d, i));
    }
  }
}

void solve() {
  rep(i, V) { ans[i] = INF; visited[i] = false; }
  priority_queue<pdi, vdi, greater<pdi> > que;
  que.push(MP(0.0, 0));

  while(!que.empty()) {
    pdi u = que.top(); que.pop();
    if(visited[u.S]) continue;
    visited[u.S] = true;
    ans[u.S] = u.F;
    for(vdi::iterator it=edges[u.S].begin();it!=edges[u.S].end();++it) {
      if(!visited[it->S]) {
        que.push(MP(ans[u.S]+it->F, it->S));
      }
    }
  }
}

int main() {
  input();
  solve();

  printf("%.10lf\n", ans[n+1]);
  return 0;
}


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

int main(){
    int N;  cin >> N;
    vector<ll> a(3*N);
    for(int i=0; i<3*N; i++) cin >> a[i];

    vector<ll> p(N+1), m(N+1);
    priority_queue<ll, vector<ll>, greater<ll>> q1;
    priority_queue<ll> q2;

    ll sum = 0;
    for(int i=0; i<N; i++){
        sum += a[i];
        q1.push(a[i]);
    }
    p[0] = sum;
    for(int i=1; i<=N; i++){
        q1.push(a[N-1+i]);
        ll v = q1.top();
        sum = sum + a[N-1+i] - v;
        q1.pop();
        p[i] = sum;
    }

    sum = 0;
    for(int i=3*N-1; i>=2*N; i--){
        sum += a[i];
        q2.push(a[i]);
    }
    m[N] = sum;
    for(int i=N-1; i>=0; i--){
        q2.push(a[N+i]);
        ll v = q2.top();
        sum = sum + a[N+i] - v;
        q2.pop();
        m[i] = sum;
    }

    ll ans = -1e18;
    for(int i=0; i<=N; i++){
        ans = max(ans, p[i]-m[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 6516
# AtCoder Beginner Contest 086
# C - Traveling

N=int(input())

T=0
X,Y=0,0

for i in range (N):
    t, x, y =map(int,input().split())
    time =t-T
    distance=abs((x+y)-(X+Y))
    if time >= distance and time%2==distance%2:
        T=t
        X,Y=x,y
    else :
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 9156
#include <stdio.h>

int main(void){

	int N,K,i,k,l,num,dig;
  	int j=0,flag=0;
  	scanf("%d %d",&N,&K);
  	int A[K+1];
  	for(i=0;i<K;i++){
      scanf("%d",&A[i]);
    }
  	int D[5];
  	for(i=N;i<=100000;i++){
      	num=i;
     	while(num){
    		dig = num % 10;
        	D[j]=dig;
    		num = num / 10;
        	j++;
        }
      	D[j]=100;
      	j=0;
      	//printf("%d%d%d%d%d\n",D[0],D[1],D[2],D[3],D[4]);
      	for(k=0;k<K;k++){
        	for(l=0;l<6;l++){
            	if(A[k]==D[l])flag=1;
            }
        }
      	if(flag==0)break;
      	flag=0;
  	}

  	
  	printf("%d\n",i);
  	return 0;
}



Measured memory_bytes: 1732
#include<iostream>
#include <string>
#include <vector>

typedef long long ll;

using namespace std;
int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> s(h);

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

	vector<bool> row(h, false);
	vector<bool> col(w, false);

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] != '.') row[i] = true;
		}
	}

	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			if (s[j][i] != '.') col[i] = true;
		}
	}
	
	for (int i = 0; i < h; i++) {
		if (row[i]) {
			for (int j = 0; j < w; j++) {
				if (col[j]) cout << s[i][j];
			}
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
N, P = map(int, input().split())
A = [int(a) for a in input().split()]
dp=[[0,0] for _  in range(N)]
dp[0]=[2,0]
for i in range(1,N):
    if A[i-1]%2 ==0:
        dp[i][0]=dp[i-1][0]*2
        dp[i][1]=dp[i-1][1]*2
    else:
        dp[i][0]=dp[i-1][0]*2
        dp[i][1]+=dp[i-1][0]
        P=1
print(dp[N-1][P])

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

int main(void){
    int H,W; cin >> H >> W;
    vector<long long> A;    
    long long tmp,a,b,c,v;
    
    tmp=pow(10,10);
    
    for(long long h=1; h<H; h++){
        long long l=H-h;
        a=W*h;
        b=W*(l/2);
        c=W*(l-(l/2));
        v=max(a,max(b,c))-min(a,min(b,c));
        tmp=min(tmp,v);
    }
    A.push_back(tmp);
   

    tmp=pow(10,10);
    for(long long h=1; h<H; h++){
        long long l=H-h;
        a=W*h;
        b=l*(W/2);
        c=l*(W-(W/2));
        v=max(a,max(b,c))-min(a,min(b,c));
        tmp=min(tmp,v);
    }
    A.push_back(tmp);

    tmp=pow(10,10);
    for(long long  w=1; w<W; w++){
        long long l=W-w;
        a=H*w;
        b=H*(l/2);
        c=H*(l-l/2);
        v=max(a,max(b,c))-min(a,min(b,c));
        tmp=min(tmp,v);
    }
    A.push_back(tmp);

    tmp=pow(10,10);
    for(long long  w=1; w<W; w++){
        long long l=W-w;
        a=H*w;
        b=l*(H/2);
        c=l*(H-H/2);
        v=max(a,max(b,c))-min(a,min(b,c));
        tmp=min(tmp,v);
    }
    A.push_back(tmp);

    sort(A.begin(), A.end());
    cout << A[0] << endl;


    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
const int N=14;
int m[N][N]={0};
int f(int y,int x){
	if(m[y][x]==1){
		m[y][x]=0;
		f(y,x-1);
		f(y,x+1);
		f(y-1,x);
		f(y+1,x);
	}
	return 1;
}
int solve(){
	int c=0,i;
	for(i=0;i<N;i++){
		int *p,*q=m[i];
		while(true){
			p=std::find(q,q+N,1);
			if(p==q+N)break;
			c+=f(i,p-q);
		}
	}
	std::cout<<c<<"\n";
	return 0;
}
int main(){
	int y=0;
	std::string s;
	while(getline(std::cin,s)){
		if(y<12){
			y++;
			for(int i=1;i<N-1;i++)m[y][i]=s[i-1]-'0';
		}else y=solve();
	}
	solve();
}

Measured memory_bytes: 1176
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

import heapq
import collections

a_all = []
for i in range(n):
    a_all.append(ab[i][0])

key_all = list(set(a_all))
key_all.sort()

d = dict()
for k in key_all:
    d[k] = []

for i in range(n):
    a = ab[i][0]
    b = ab[i][1]
    d[a].append(b)

ans = 0
l = []
for i in range(1, m+1):
    if key_all != []:
        if i == key_all[0]:
            for v in d[i]:
                heapq.heappush(l, -1 * v)

            heapq.heappop(key_all)

    if l != []:
        ans += heapq.heappop(l) * -1

print(ans)


Measured memory_bytes: 88912
import java.util.Scanner;

public class Main{
	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);

		int a;
		int b;
		int c;

		a = scan.nextInt();
		b = scan.nextInt();
		c = scan.nextInt();

		if(a < b && b < c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26140
#include<stdio.h>
int main()
{
	int n,m,i;
	scanf("%d%d",&n,&m);
	if(m>n)
	{
		for(i=0;i<m;i++)
		printf("%d",n);
	}
	else
	{
		for(i=0;i<n;i++)
		printf("%d",m);
	}
	return 0;
} 

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

int main(){
    vector<int> x(3);
    cin >> x.at(0) >> x.at(1) >> x.at(2);
    sort(x.begin(), x.end());
    reverse(x.begin(), x.end());
    cout << x.at(0) * 10 + x.at(1) + x.at(2) <<endl;
    return 0;
}

Measured memory_bytes: 256
import java.awt.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
import java.lang.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Problem ThanhYeuThu = new Problem();
		ThanhYeuThu.solve();
	}
	static class Problem {
		public void solve() {
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			double a[] = new double [n];
			for (int i = 0; i < n; i++) a[i] = sc.nextDouble();
			double DP[][] = new double [n][n + 1];
			double MaxValue = 1;
			DP[0][0] = MaxValue - a[0];
			DP[0][1] = a[0];
			for (int i = 1; i < n; i++) {
				for (int j = 0; j <= n; j++) {
					DP[i][j] = DP[i - 1][j] * (MaxValue - a[i]);
					if (j > 0) {
						DP[i][j] += DP[i - 1][j - 1] * a[i];
					}
				}
			}
			double Res = 0;
			for (int i = 0; i <= n; i++) {
				int j = n - i;
				if (i > j) Res += DP[n - 1][i];
			}
			System.out.printf("%.10f",Res);
		}
	}

}


Measured memory_bytes: 122776
#include<bits/stdc++.h>
typedef int LL;
const LL maxn=1e6+9;
inline LL Read(){
	LL x(0),f(1); char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1; c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3)+(x<<1)+c-'0'; c=getchar();
	}return x*f;
}
LL T,n,flag(1);
LL a[maxn];
int main(){
	n=Read();
	for(LL i=1;i<=n;++i){
		a[i]=Read();
		if(i==1){
			--a[i];
		}else{
			if(a[i]>a[i-1]) --a[i];
			if(a[i]<a[i-1]) flag=false;
		}
	}
	if(!flag) puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 640
use std::io::{Read, StdoutLock};
use std::io::{stdout, BufWriter, Write};
use std::str::{SplitWhitespace, FromStr};
use std::fmt::Display;
use std::collections::{HashMap, VecDeque};

struct IO<'a> {
    sw: SplitWhitespace<'a>,
    bw: BufWriter<StdoutLock<'a>>,
}

impl IO<'_> {
    pub fn read<T: FromStr>(&mut self) -> T where
        <T as std::str::FromStr>::Err: std::fmt::Debug {
        self.sw.next().unwrap().parse().unwrap()
    }
    #[allow(dead_code)]
    pub fn writeln<T: Display>(&mut self, s: T) {
        self.bw.write(format!("{}\n", s).as_bytes()).unwrap();
    }
    #[allow(dead_code)]
    pub fn writeln_n(&mut self, mut n: usize) {
        if n == 0 {
            self.bw.write(b"0\n").unwrap();
        }
        let mut buf: Vec<u8> = Vec::new();
        while n != 0 {
            buf.push((n % 10) as u8 + 48);
            n /= 10;
        }
        buf.reverse();
        buf.push(b'\n');
        self.bw.write(buf.as_slice()).unwrap();
    }
}

// AtCoder Beginner Contest 146 D - Coloring Edges on Tree
fn main() {
    /* BEGIN TEMPLATE */
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let sw = buf.split_whitespace();
    let _stdout = stdout();
    let bw = BufWriter::new(_stdout.lock());
    let mut io = IO{sw, bw};
    /* END TEMPLATE */

    let n: usize = io.read();
    let mut tree: Vec<Vec<usize>> = vec![Vec::new(); n+1];
    let mut edges: Vec<(usize, usize)> = Vec::with_capacity(n-1);
    let mut edge_colors: HashMap<(usize, usize), usize> = HashMap::new();
    (0..n-1).for_each(|_| {
        let (a, b): (usize, usize) = (io.read(), io.read());
        tree[a].push(b);
        tree[b].push(a);
        if a < b {
            edges.push((a, b));
        } else {
            edges.push((b, a));
        }
    });
    let mut colors: Vec<usize> = vec![0; n+1];
    let mut done = vec![false; n+1];
    done[1] = true;
    colors[1] = 0;
    let mut count = colors[1];
    let mut queue: VecDeque<usize> = VecDeque::new();
    queue.push_back(1);
    while !queue.is_empty() {
        let length = queue.len();
        (0..length).for_each(|_|{
            let mut color: usize = 0;
            let front = queue.pop_front().unwrap();
            tree[front].iter().for_each(|&t|{
                if !done[t] {
                    color += 1;
                    if color == colors[front] {
                        color += 1;
                    }
                    colors[t] = color;
                    if color > count {
                        count = color;
                    }
                    done[t] = true;
                    queue.push_back(t);
                    if front < t {
                        *edge_colors.entry((front, t)).or_default() = color;
                    } else {
                        *edge_colors.entry((t, front)).or_default() = color;
                    }
                }
            });
        })
    }
    io.writeln_n(count);
    edges.iter().for_each(|&edge| {
        io.writeln_n(*edge_colors.entry(edge).or_default());
    })
}

Measured memory_bytes: 16668
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn min (a: &i64, b: &i64)-> i64{
    if *a <= 0i64 {*b}
    else if *b <= 0i64  {*a}
    else if *a < *b {*a}
    else {*b}
}

fn abs (a: &i64, b: &i64) -> i64{
    if *a - *b <= 0 {*b - *a} else {*a - *b}
}

use std::collections::VecDeque;
fn main(){
    input!{
        a: isize,
        b: isize,
        c: isize
    }
    print!("{}", if b+c-a < 0 {0} else {b+c-a})
}


Measured memory_bytes: 4352
# -*- coding: utf-8 -*-

def input_one_number():
    return int(input())

def input_multiple_number():
    return map(int, input().split())

def input_multiple_number_as_list():
    return list(map(int, input().split()))


h1,m1,h2,m2,k = input_multiple_number()

m = 0
m += (h2-h1)*60
m += (m2-m1)

print(m-k)

Measured memory_bytes: 9172
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)

int N,M;

int fact(int n){
	int dim=1;
	for(int i=0;i<n;i++){
		dim=(dim*(i+1))%MOD;
	}
	return dim;
}

signed main(){
	cin>>N>>M;
	if(abs(N-M)>=2){
		cout<<0<<endl;
	}
	else if(N==M){
		cout<<((fact(N)*fact(M))%MOD)*2%MOD;
	}
	else{
		cout<<(fact(M)*fact(N))%MOD<<endl;
	}
	return 0;
}


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

int main() {
  long long N;
  cin >> N;
  long long sum=0;
  
  for (long long i=1; i<=N; i++) {
    if (i%3!=0 && i%5!=0) {
      sum+=i;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main() {
  char S[100000];
  int length, count = 0;
  for (length = 0; cin >> S[length]; length++);
  
  for (int i = 0; i < length - 1; i++)
    if (S[i] != S[i + 1]) count++;

  printf("%d",count);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
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;} //最小公倍数

//-------------------------------------------------
//



//-------------------------------------------------


int main()
{
  ll N;
  cin >>N;
  
  if(N%2==1){
    cout <<0<<endl;
  }else{
    cout <<N/10+
      N/50+
      N/250+
  
N/1250+
N/6250+
N/31250+
N/156250+
N/781250+
N/3906250+
N/19531250+
N/97656250+
N/488281250+
N/2441406250+
N/12207031250+
N/61035156250+
N/305175781250+
N/1525878906250+
N/7629394531250+
N/38146972656250+
N/190734863281250+
N/953674316406250+
N/4768371582031250+
N/23841857910156250+
N/119209289550781250+
N/596046447753906250+
N/2980232238769531250<<endl;
      
  }
  
}





Measured memory_bytes: 384
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
# from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    points = [tuple(map(int, input().split())) for _ in range(N)]
    base_point = [(x,y,h) for x,y,h in points if h > 0][0]
    for cx in range(101):
        for cy in range(101):
            H = abs(cx-base_point[0])+abs(cy-base_point[1])+base_point[2]
            for x,y,h in points:
                if h != max(H-abs(cx-x)-abs(cy-y),0): break
            else:
                print(cx,cy,H)
                return 0

if __name__ == '__main__':
    main()

Measured memory_bytes: 3944
#include<bits/stdc++.h>
using namespace std;
int main(){
	int  n,m;
	cin>>n>>m;
	int  a[n];
	float sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	sum=sum/(4*m);
	int count =0;
	for(int i=0;i<n;i++){
		if(sum<=a[i]){
			count++;
		}
	}
	if(count>=m){
		cout<<"Yes"<<endl;
	}else {
		cout<<"No"<<endl;
	}
	return 0;
}


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

int main() {
 int n, m, l;
 cin >> n >> m >> l;
 long long a[n][m];
 long long b[m][l];
 long c [n][l];

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

 for (int i = 0; i < n; i++) { 
   for (int j = 0; j < l; j++) {
     c[i][j] = 0;    
     for (int k = 0; k < m; k++) {
       c[i][j] += a[i][k] * b[k][j]; 
     }
   }
 }

 for (int i = 0; i < n; i++) {
  for (int j = 0; j < l; j++) {
    if (j != 0) cout << " ";
    cout << c[i][j];
  }
  cout << endl;
 }
 return 0;
}

Measured memory_bytes: 1400
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define ll long long int
#define fab(a,b,i) for(int i=a;i<b;i++)
#define pb push_back
#define db double
#define mp make_pair
#define endl "\n"
#define f first
#define se second
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
int n;
ll h[200005],a[200005],seg[4*200005];
vector<ll > dp(400005);
void update(ll node,ll s,ll e,ll ind ,ll val)
{
	if(s==e)
	{
		seg[node]=val;
		//dp[ind]=val;
	}
	else
	{
		ll mid=s+(e-s)/2;
		if(ind<=mid)
			update(2*node,s,mid,ind,val);
		else
			update(2*node+1,mid+1,e,ind,val);

	
	seg[node]=max(seg[2*node],seg[2*node+1]);
	}
}
ll query(ll node,ll s,ll e,ll l, ll r)
{
	if(s>r or e<l)
		return 0;
	if(l<=s and e<=r)
		return seg[node];

	ll mid=s+(e-s)/2;
	return max(query(2*node,s,mid,l,r),query(2*node+1,mid+1,e,l,r));

}
int main()
{ quick;

	cin>>n;
	fab(0,n,i)
	cin>>h[i];
	fab(0,n,i)
	cin>>a[i];
	vector<ll> v(n+1,0),sum(n+1,0);
	v[1]=h[0];
	sum[1]=a[0];
	int lisptr=2;
	int i=1;
	
	fab(0,n,i)
	{
		ll res=query(1,0,n+1,0,h[i]-1);
		//cout<<"res:"<<res<<" "<<i<<endl;
		dp[h[i]]=max(dp[h[i]],res+a[i]);
		update(1,0,n+1,h[i],dp[h[i]]);
	}
	/*fab(0,4*n,i)
	{
		cout<<dp[i]<<endl;
	}*/
	cout<<query(1,0,n+1,0,n+1)<<endl;

	//cout<<query(1,0,n+1,n+1,n+1)<<endl;

	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

vector<ll> A(100000);

string solve(ll N){
    ll sum = 0;
    rep(i,N) sum += A[i];
    sum /= 2;
    rep(i,N) if(i%2 == 1) sum -= A[i];

    vector<int> ans(N);
    rep(i,N){
        ans[i] = sum*2;
        sum = A[i] - sum;
    }
    rep(i,N) cout << ans[i] << " ";
    return "";
}
int main(){
    ll N; cin >> N;
    rep(i,N) cin >> A[i];
    pr(solve(N));
    return 0;
}

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

int main(){
	int N;
  	int num;
  	int count;
  	int ans_num = 1;
  	int ans_count = 0;
  
  	cin >> N;
  	
  for(int i=1; i<=N; i++){
    num = i;
    count = 0;
    
    while( num % 2 == 0){
      num /= 2;
      count += 1;
    }
    
    if(count > ans_count){
      ans_count = count;
      ans_num = i;
    }
    
  }
  
  cout <<  ans_num << endl;
  
}

Measured memory_bytes: 256
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#define MOD 998244353

LLI dp[3005][3005];
int main() {
    int A,B,C,D;
    cin >> A >> B >> C >> D;

    int i,j;
    dp[C][D] = 1;
    for (i = C; i >= A; i--) {
        for (j = D; j >= B; j--) {
            if ((i < C) || (j < D)) dp[i][j] = (dp[i+1][j]*j+dp[i][j+1]*i-dp[i+1][j+1]*i*j) % MOD;
        }
    }
    cout << (dp[A][B]+MOD) % MOD << endl;

    return 0;
}



Measured memory_bytes: 74020
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>

#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

ll gcd(ll a, ll b) {
  if (a == 0 || b == 0) return a + b;
  if (b > a) return gcd(b, a);
  return gcd(b, a % b);
}

ll dp[2010][2010];

int main(void) {

  ll n;
  pair<ll, ll> a[2500];
  cin >> n;
  rep(i, n) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }

  sort(a, a + n, greater< pair<ll, ll> >());
  for (ll x = 0; x < n; x++) {
    for (ll y = 0; y <= x + 1; y++) {
      dp[x + 1][y] = dp[x][y] + a[x].first*abs(a[x].second-(n-x+y));
      if (x < y) dp[x + 1][y] = 0;
      if (y > 0) {
	dp[x+1][y] = max(dp[x+1][y], dp[x][y-1] + a[x].first*abs(a[x].second-y));
      }
    }
  }

  ll ans = 0;
  for (int i = 0; i <= n; i++) ans = max(ans, dp[n][i]);

  cout << ans << endl;

}

  


Measured memory_bytes: 26276
import java.util.Scanner;

public class Main {
	static int n, m, k;
	static int[][] time, cost;

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			n = sc.nextInt();
			m = sc.nextInt();
			if (n == 0 && m == 0)
				break;
			time = new int[m + 1][m + 1];
			cost = new int[m + 1][m + 1];
			for (int i = 0; i <= m; i++) {
				for (int j = 0; j <= m; j++) {
					cost[i][j] = cost[j][i] = 999999;
					time[i][j] = time[j][i] = 999999;
				}
			}
			int x, y;
			for (int i = 0; i < n; i++) {
				x = sc.nextInt();
				y = sc.nextInt();
				cost[x][y] = cost[y][x] = sc.nextInt();
				time[x][y] = time[y][x] = sc.nextInt();
			}
			initSolution();

			k = sc.nextInt();
			int start, end, condition;
			for (int i = 0; i < k; i++) {
				start = sc.nextInt();
				end = sc.nextInt();
				condition = sc.nextInt();
				if (condition == 0) {
					System.out.println(cost[start][end]);
				} else
					System.out.println(time[start][end]);
			}
		}

	}

	public static void initSolution() {
		for (int k = 1; k <= m; k++) {
			for (int i = 1; i <= m; i++) {
				for (int j = 1; j <= m; j++) {
					if (time[i][j] > time[i][k] + time[j][k])
						time[i][j] = time[i][k] + time[j][k];
					if (cost[i][j] > cost[i][k] + cost[j][k])
						cost[i][j] = cost[i][k] + cost[j][k];
				}
			}
		}
	}
}



Measured memory_bytes: 76588
N = int(input())
s = []
for i in range(N):
    si = list(input())
    si.sort()
    si = ''.join(si)
    s.append(si)
s.sort()

id = 1
now = s[0]
count = 0
ans = 0
while True:
    if id == N:
        if count != 0:
            ans += count*(count+1)//2
        break
    if s[id] == now:
        id += 1
        count += 1
        continue
    else:
        ans += count*(count+1)//2
        count = 0
        now = s[id]
        id += 1
print(ans)

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  string S; cin >> S;
  VI cnt(4);
  REP(i,SZ(S)) cnt[S[i]-'A']++;

  if((cnt['N'-'A'] && !cnt['S'-'A'])
	 || (!cnt['N'-'A'] && cnt['S'-'A'])
	 || (cnt['W'-'A'] && !cnt['E'-'A'])
	 || (!cnt['W'-'A'] && cnt['E'-'A']))
	cout << "No" << endl;
  else
	cout << "Yes" << endl;
  
  return 0;
}


Measured memory_bytes: 256
# coding=utf-8

###
### for atcorder program
###

import sys

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def get_input():
    N = []
    while True:
        try:
            N.append(input())
        except EOFError:
            break
    return N

def main():


    N = get_input()
    for i, row in enumerate(N):
        N[i] = row.lower()
    abc = [chr(ord('a') + i) for i in range(26)]
    ans = []
    
    for i in abc:
        temp = 0
        for j in N:
            temp += j.count(i)
        ans.append(i+' : {}'.format(temp))

    for i in ans:
        print(i)

if __name__ == '__main__':
    main()




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

int main(void){
	int n,m;
	cin >> n >> m;
	int **a = new int*[n];
	for(int i = 0; i < n; i++ ){
		a[i] = new int[m];
	}
	int *b = new int[m];
	
	for(int i = 0; i < n; i++ ){
		for(int j = 0; j < m; j++ ){
			cin >> a[i][j];
		}
	}
	for(int i = 0; i < m; i++ ){
		cin >> b[i];
	}
	for(int i = 0; i < n; i++ ){
		int temp = 0;
		for(int j = 0; j < m; j++ ){
			temp += a[i][j] * b[j];
		}
		cout << temp << endl;
	}
	for( int i = 0; i < n; i++ ){
		delete[] a[i];
	}
	delete[] a;
	delete[] b;
	
	return 0;
}

Measured memory_bytes: 1236
#include <iostream>

using namespace std;

int main(void)
{
    int H, W, A, B, i, j;

    cin >> H >> W >> A >> B;

    for(i=1; i<=H; i++){
        for(j=1; j<=W; j++){
            if((j<=A && i<=B) || (j>A && i>B)){
                cout << 0;
            }
            else{
                cout << 1;
            }
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

namespace flw {
	const int N = 1000000 + 7;
	struct flow {
		int n, st, ed;
		int lay[N], gap[N], cur[N], pre[N];
		struct edge {
			int to, nex, cap;
		} e[N];
		int fir[N], eid = 1;

		void addedge(int u, int v, int c);
		void addflow(int u, int v);
		int isap();
	};

	void flow::addedge(int u, int v, int c) {
		e[++eid] = (edge){ v, fir[u], c }, fir[u] = eid;
	}
	void flow::addflow(int u, int v) {
		addedge(u, v, 1), addedge(v, u, 0);
	}
	int flow::isap() {
		std::queue<int> q; q.push(ed);
		std::fill(lay + 1, lay + n + 1, -1), lay[ed] = 0;
		for (int s; q.size(); ) {
			s = q.front(), q.pop();
			for (int i = fir[s]; i; i = e[i].nex)
				if (lay[e[i].to] == -1 && e[i ^ 1].cap)
					++gap[lay[e[i].to] = lay[s] + 1], q.push(e[i].to);
		}
		std::copy(fir + 1, fir + n + 1, cur + 1);

		int maxflow = 0, s = st;
		while (lay[st] < n) {
			if (s == ed)
				for (++maxflow; s != st; s = pre[s], --e[cur[s]].cap, ++e[cur[s] ^ 1].cap);
			for (int &i = cur[s]; i; i = e[i].nex)
				if (lay[s] == lay[e[i].to] + 1 && e[i].cap)
					{ pre[e[i].to] = s; break; }
			if (cur[s]) { s = e[cur[s]].to; continue; }
			if (!--gap[lay[s]]) break;
			++gap[++lay[s]], cur[s] = fir[s];
			if (s != st) s = pre[s];
		}
		return maxflow;
	}
}

const int N = 400000 + 7;

int n;
flw::flow f;
int u[N];
std::vector<int> v[N];
int g[N], h[N], k;

int fa[N];
int getfa(int x) {
	return fa[x] == x ? x : fa[x] = getfa(fa[x]);
}

int main() {
	scanf("%d", &n);
	f.st = n * 2, f.ed = f.n = f.st + 1;
	for (int i = 1, x, y; i < n; ++i) {
		scanf("%d", &y);
		while (y--) scanf("%d", &x), f.addflow(x, n + i), v[x].push_back(i);
		f.addflow(f.st, i), f.addflow(n + i, f.ed);
	}
	if (f.isap() < n - 1) return printf("-1"), 0;
	for (int i = 1; i < n; ++i)
		for (int j = f.fir[n + i]; j; j = f.e[j].nex)
			if (f.e[j].cap) u[i] = f.e[j].to;
	for (int i = 1; i <= n; ++i) fa[i] = i;
	std::queue<int> q; q.push(n);
	for (int s; q.size(); ) {
		s = q.front(), q.pop();
		for (auto i : v[s])
			if (u[i]) q.push(u[i]), fa[getfa(g[i] = s)] = getfa(h[i] = u[i]), u[i] = 0;
	}
	for (int i = 1; i <= n; ++i)
		if (getfa(i) != getfa(1)) return printf("-1"), 0;
	for (int i = 1; i < n; ++i)
		printf("%d %d\n", g[i], h[i]);
	return 0;
}


Measured memory_bytes: 44408
from heapq import heappush, heappop
import functools
def sorted_by(a, b):
    if a[0] > b[0]:
        return a[0] - b[0]
    if a[0] == b[0]:
        return b[1] - a[1]
    return -1

def solve(n, m, a, b):
    v = sorted(zip(a, b), key=functools.cmp_to_key(sorted_by))
    i = 0
    q = []
    ans = 0
    for t in range(1, m+1):
        while (i < n) and (v[i][0] <= t):
            heappush(q, -v[i][1])
            i += 1
        if len(q) > 0:
            ans -= heappop(q)
    return ans

n, m = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(n, m, a, b))

Measured memory_bytes: 23384
#include <stdio.h>

int n, s, cnt;

void dfs(int i, int sum, int n){
    if(sum==s&&!n){
        cnt++;
        return;
    }
    if(i==10||!n) return;
    dfs(i+1,sum,n);
    dfs(i+1,sum+i,n-1);
}

int main(){
	while(1){
		scanf("%d%d",&n,&s);
		if(n==0&&s==0){
			break;
		}
		cnt=0;
		dfs(0,0,n);
		printf("%d\n",cnt);
	}

    return 0;
}

Measured memory_bytes: 2580
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <tuple>
#include <type_traits>

using namespace std;
using ll = long long;

ll attack(ll H) {
	if (H == 1) return 1;

	return attack(H / 2) * 2 + 1;
}

int main()
{
	ll H;
	cin >> H;

	cout << attack(H) << endl;
}

Measured memory_bytes: 760
#include<iostream>
class dice
{
private:
	int _top, _botom, _front, _back, _right, _left;
public:
	dice(int top, int botom, int front, int back, int right, int left): _top(top), _botom(botom), _front(front), _back(back), _right(right), _left(left) {};
	void roll(char dir)
	{
		int temp;
		switch(dir)
		{
			case 'E':
				temp = _top;
				_top = _left;
				_left = _botom;
				_botom = _right;
				_right = temp;
				break;
			case 'W':
				temp = _top;
				_top = _right;
				_right = _botom;
				_botom = _left;
				_left = temp;
				break;
			case 'S':
				temp = _top;
				_top = _front;
				_front = _botom;
				_botom = _back;
				_back = temp;
				break;
			case 'N':
				temp = _top;
				_top = _back;
				_back = _botom;
				_botom = _front;
				_front = temp;
				break;
		}
	}
	int top()
	{
		return _top;
	}
};
int main()
{
	int top, botom, front, back, right, left;
	std::cin >> top >> back >> right >> left >> front >> botom;
	dice d(top, botom, front, back, right, left);
	char order[101];
	std::cin >> order;
	for(int i = 0; order[i] != '\0'; i++)
	{
		d.roll(order[i]);
	}
	std::cout << d.top() << std::endl;
	return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;
int n,s[111111],ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x=0; scanf("%d",&x);
		s[x-1]++; s[x]++; s[x+1]++;
	}
	for(int i=0;i<=100005;i++) ans=max(ans,s[i]);
	printf("%d",ans);
}


Measured memory_bytes: 640
def dfs(v, u=0):
    global n, t, d, f, reached
    if len(reached) == n:
        return

    d[u] = t
    t += 1

    reached.add(u + 1)
    for ui in range(v[u][1]):
        next = v[u][2 + ui]
        if next in reached:
            continue
        dfs(v, next - 1)

    f[u] = t
    t += 1


n = int(input())
v = []
for _ in range(n):
    v.append(list(map(int, input().split())))

t = 1
d = [0] * n
f = [0] * n
reached = set()


for ui in range(n):
    if ui + 1 not in reached:
        dfs(v, ui)

for ui in range(n):
    print('%d %d %d' % (ui + 1, d[ui], f[ui]))


Measured memory_bytes: 5628
s = input()
#最後の文字が何で、いくつ続いているかを記録していく。
last_c = ''
stock_count = 0
remove_count = 0

for c in s:
	# 文字をストック
	if last_c == c:
		stock_count += 1
		continue
		
	# 新しく文字をストック
	# 対消滅でストックがない場合がある。
	if stock_count == 0:
		last_c = c
		stock_count += 1
		continue
		
	stock_count -= 1
	remove_count += 1
	
print(remove_count*2)

Measured memory_bytes: 3188
#include<stdio.h>
int main(){ 
  int n,m,i,j,dust,check,a[100][100];
  scanf("%d",&n); 
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      a[i][j] = 0;
    }
  }
  for(i = 0; i < n; i++){
    scanf("%d%d",&dust,&m);
    if(m != 0){
      for(j = 0; j < m; j++){
	scanf("%d",&check);
	a[i][check-1] = 1;
      }
    }
  }
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      if(j == n-1)printf("%d",a[i][j]);
      else printf("%d ",a[i][j]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 636