akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int DIM = 1e5 + 5;

long long dst[DIM];
vector<pair<int, int>> edg[DIM];

void dfs(int x, int f, long long d) {
    dst[x] = d;
    
    for (pair<int, int> y : edg[x])
        if (y.first != f) dfs(y.first, x, d + y.second);
    
    return;
}

int main(void) {
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    for (int i = 1; i < n; ++i) {
        int x, y, c;
        cin >> x >> y >> c;
        
        edg[x].push_back(make_pair(y, c));
        edg[y].push_back(make_pair(x, c));
    }
    
    int q, k;
    cin >> q >> k;
    
    dfs(k, -1, 0);
    for (int i = 1; i <= q; ++i) {
        int x, y;
        cin >> x >> y;
        
        cout << dst[x] + dst[y] << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 12800
#include<iostream>
#define maxn 36+5
using namespace std;

typedef struct Card {
	char Suit;
	char Value;
}card;

void BubbleSort ( card *A, int N) {
	for( int i = 0; i < N; i++) {
		for( int j = N -1; j > i; j--) {
			if(A[j].Value < A[j - 1].Value) {
				card temp = A[j];
			    A[j] = A[j - 1];
			    A[j - 1] = temp;
			}
		}
	}
}

void SelectionSort ( card *A, int N) {
	for ( int i = 0; i < N; i++) {
		int minj = i;
		for(int j = i; j < N ;j++) {
			if(A[j].Value < A[minj].Value) minj = j;
		}
		card temp = A[i];
		A[i] = A[minj];
		A[minj] = temp;
	}
}

void print( card *A, int N) {
	for( int i = 0; i < N ; i++){
		cout << A[i].Suit << A[i].Value;
		if(i != N -1) cout << " "; 
		else cout << endl;
	}
}

int main() {
	int N;
	card T1[maxn], T2[maxn];
	cin >> N;
	for(int i = 0; i < N; i++) {
		cin >> T1[i].Suit >> T1[i].Value;
		T2[i] = T1[i];
	}
	BubbleSort( T1, N );
	SelectionSort( T2, N );
	int flag = 1;
	for(int i = 0; i < N; i++ ) {
		if(T1[i].Suit != T2[i].Suit) {
			flag = 0;
			break;
		}
	}
	print( T1, N );
	cout << "Stable" << endl;
	print( T2, N );
	if( flag ) cout << "Stable" << endl;
	else cout << "Not stable" << endl;
	return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cstdlib>
#include <typeinfo>

using namespace std;

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


int i,j;

int main(void){
    
    int x,y;
    cin >> x >> y;
    
    if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
        if(y==1||y==3||y==5||y==7||y==8||y==10||y==12){
            cout<<"Yes";
            return 0;
        }
    }
    else if(x==4||x==6||x==9||x==11){
        if(y==4||y==6||y==9||y==11){
            cout<<"Yes";
            return 0;
        }
    }
    else if(x==2&&y==2){
        cout<<"Yes";
        return 0;
    }
    
    cout<<"No";
    
    return 0;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
vector<pii> ls, rs;
bool check() {
	int tot = 0;
	//记到上一节为止的前缀和，且之前任意前缀和>=0
	for(int i=0; i<ls.size(); i++) {
		if(tot+ls[i].first<0)
			return false;
		tot+=ls[i].second;
	}
	for(int i=0; i<rs.size(); i++) {
		if(tot+rs[i].second-rs[i].first<0)
			return false;
		tot+=rs[i].second;
		if(tot<0)
			return false;
	}
	return true;
}
bool cmp(const pii &a,const pii &b) {
	if(a.first==b.first) return a.second>b.second;
	return a.first>b.first;
}
int main() {
	//设'('的权为1，')'的权为-1
	//对于合法括号序列,任意前缀最小值一定大于等于0,且总权值和为0
	//考虑一种最优的拼接方案，如果该方案不成功，则其他方案一定不会成功
	int n;
	cin >> n;
	int sum = 0;//所有序列值总和
	for(int i=1; i<=n; i++) {
		string s;
		cin >> s;
		int cnt= 0, min_pre = 1e9;
		//对于每一个括号序列，cnt记录权值和，min_pre记录任意前缀的最小值
		for(int i=0; i<s.size(); i++) {
			if(s[i]== '(') ++cnt;
			else --cnt;
			min_pre = min(min_pre, cnt);
		}
		sum += cnt;
		if(cnt>=0) ls.push_back(make_pair(min_pre,cnt));
		//该段总和>=0，任意前缀最小值大的先放,一样的话先放总和大的
		else rs.push_back(make_pair(cnt-min_pre,cnt));
		//该段总和<0，cnt+minpre大的先放
	}
	sort(ls.begin(),ls.end(),cmp);
	sort(rs.begin(),rs.end(),cmp);
	if(sum==0&&check())
		puts("Yes");
	else
		puts("No");
	return 0;
}

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

int main(){

    int N, M;
    cin >> N >> M;
    vector<int> A(40, 0);
    for(int i = 0; i < N; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int a;
            cin >> a;
            A[a]++;
        }
    }

    int ans = 0;
    for(int i = 0; i < A.size(); i++){
        if(A[i] == N) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
char ch[1000];
int main(){
	bool C=false,F=false;
	scanf("%s",&ch);
	for(int i=0;i<strlen(ch);i++){
		if(ch[i]=='C') C=true;
		if(ch[i]=='F'&&C==true) F=true;
	}
	if(C&&F) printf("Yes");
	else printf("No");
}

Measured memory_bytes: 128
function main()
    K = parse(Int, readline())

    first_mod = 7 % K

    old_mod = now_mod = first_mod

    cnt = 1
    if first_mod == 0
        print(1)
    else
        flg = false
        for i in 2:K
            now_mod = ((old_mod * 10) + 7) % K
            cnt += 1
            old_mod = now_mod
            if now_mod == 0
                flg = true
                break
            end
            if now_mod == first_mod
                break
            end
        end
        if flg
            print(cnt)
        else
            print(-1)
        end
    end
end

main()

Measured memory_bytes: 155844
//#include<bits/stdc++.h>
#include<iostream>
#include<queue>
#include<iomanip>
#include<cctype>
#include<cstdio>
#include<deque>
#include<utility>
#include<cmath>
#include<ctime>
#include<cstring>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define INF 1000000000
#define ll long long
#define RE register
#define a(i) s[i].A
#define b(i) s[i].B
#define c(i) s[i].C
#define id(i) s[i].id
using namespace std;
char buf[1<<15],*fs,*ft;
inline char getc()
{
    return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline int read()
{
    RE int x=0,f=1;char ch=getc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
    return x*f;
}
const int MAXN=110;
int n,top,k;
int a[MAXN];
int main()
{
	//freopen("1.in","r",stdin);
	n=read();k=read();
	while(n)
	{
		int w=n%k;
		a[++top]=w;
		n/=k;
	}
	//for(int i=top;i>=1;--i)printf("%d",a[i]);
	printf("%d\n",top);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<math.h>
using namespace std;

int main(){

    int n, i;
    i = 1;

    cin >> n;

    while(++i != n+1){
        int x = i;
        if(x % 3 == 0){
            cout << ' ' << i;
            continue;
        }
        while(x){
            if(x % 10 == 3){
                cout << ' ' << i;
                break;
            }
            x = x / 10;
        }
    }
    
    cout << endl;
 
    return 0;
}


Measured memory_bytes: 3100
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n;
	while(cin >> n){
		vector<int> p(n);
		REP(i,n) cin >> p[i];
		vector<int> a(n);
		vector<int> b(n);
		vector<int> v(n);
		REP(i,n){
			v[p[i]-1] = i+1;
		}
		dpite(ALL(v));
		a[0] = 1;
		b[0] = v[0]-1;
		int mi = 0;
		FOR(i,1,n){
			a[i] = max(a[i-1],v[i]-b[i-1])+1;
			b[i] = v[i]-a[i];
			mi = min({mi,a[i],b[i]});
			// assert(a[i] > 0 and b[i] > 0);
		}
		REP(i,n){
			a[i] -= mi-1;
			b[i] -= mi-1;
		}
		pite(ALL(a));
		pite(ALL(b));
		// vector<int> a(n);
		// vector<int> b(n);
		// REP(i,n) cin >> a[i];
		// REP(i,n) cin >> b[i];
		// REP(i,n) cout << a[i]+b[i] << ' ';
		// cout << endl;
	}
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
typedef long long ll;

ll MOD = 1e9 + 7;

vector<ll> factorial;
ll mod_exp(ll x, ll exp) {
    ll res = 1;
    ll base = x % MOD;
    while (exp) {
        if (exp % 2 == 1) {
            res = (res * base) % MOD;
        }
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res;
}

ll nCk(ll n, ll k) {
    if (n < k) return 0;
    ll numerator = factorial[n];
    ll denominator = (factorial[n-k] * factorial[k]) % MOD;
    ll ans = (numerator * mod_exp(denominator, MOD-2)) % MOD;
    return ans;
}

int main() {
    ll N, K; cin >> N >> K;
    vector<ll> nums(N);
    for (ll& x : nums) {
        cin >> x;
    }

    factorial = {1};
    for (ll i = 1; i <= N; i++) {
        factorial.push_back((factorial.back() * i) % MOD);
    }

    ll ans = 0;

    sort(begin(nums), end(nums), [](ll a, ll b){return a > b;});
    for (ll i = 0; i < N-K+1; i++) {
        ll best = (MOD + nums[i]) % MOD;
        ll contribution = (best * nCk(N-i-1, K-1)) % MOD;
        ans = (ans + contribution) % MOD;
    }

    sort(begin(nums), end(nums));
    for (ll i = 0; i < N-K+1; i++) {
        ll best = nums[i] % MOD;
        ll contribution = (best * nCk(N-i-1, K-1)) % MOD;
        ans = (ans + MOD - contribution) % MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 2168
#include <iostream>
#include <vector>
#include <algorithm>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;

string s;

int main() {
	cin>>s;
	ll ans = 0;
	ll md[13] = {};
	ll md_n[13] = {};
	md[0] = 1;
	ll base = 1;
	for(int i = s.size()-1; i >= 0; i--) {
		char c = s[i];
		if(c=='?') {
			for(int num = 0; num <= 9; num++) {
				int shift = base*num % 13;
				for(int j = 0; j < 13; j++) {
					md_n[(j+shift)%13] += md[j];
					md_n[(j+shift)%13] %= MOD;
				}
			}
			for(int j = 0; j < 13; j++) {
				md[j] = md_n[j];
			}
		}else {
			int num = c-'0';
			int shift = base*num % 13;
			for(int j = 0; j < 13; j++) {
				md_n[(j+shift)%13] += md[j];
			}
			for(int j = 0; j < 13; j++) {
				md[j] = md_n[j];
			}
		}
		base *= 10;
		base %= 13;
		for(int j = 0; j < 13; j++) {
			md_n[j] = 0;
		}
	}
	cout << md[5] << endl;
}


Measured memory_bytes: 512
from bisect import bisect_left
import sys
sys.setrecursionlimit(10**6)
def input():
	return sys.stdin.readline()[:-1]
n = int(input())
a = list(map(int, input().split()))
adj = [[] for _ in range(n)]
for _ in range(n-1):
	u, v = map(int, input().split())
	adj[u-1].append(v-1)
	adj[v-1].append(u-1)

INF = 10**10
dp = [INF for _ in range(n)]
ans = [0 for _ in range(n)]

def dfs(x, p):
	ans[x] = bisect_left(dp, INF)
	for v in adj[x]:
		if v == p:
			continue
		ind = bisect_left(dp, a[v])
		pres = dp[ind]
		dp[ind] = a[v]
		dfs(v, x)
		dp[ind] = pres
	return

dp[0] = a[0]
dfs(0, -1)
print(*ans, sep="\n")

Measured memory_bytes: 347988
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int a;
     string s;
     cin >> a >> s;
      if( a >= 3200){
       cout << s << endl;
      }
      if( a < 3200 ) {
       cout << "red" << endl;
      }
      
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  //
  ll m, k;
  cin >> m >> k;
  if (m == 1) {
    if (k == 0) {
      cout << "0 0 1 1" << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }

  if (k >= (1 << m)) {
    cout << -1 << endl;
    return 0;
  }
  cout << k << " ";
  rep(i, (1 << m)) {
    if (i != k) {
      cout << i << " ";
    }
  }
  cout << k << " ";
  for (ll i = (1 << m) - 1; i >= 0; i--) {
    if (i != k) {
      cout << i << " ";
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1792
K, N = [int(a) for a in input().split()]
A = [int(a) for a in input().split()]

max_diff = 0
dsum = 0
for i in range(len(A)):
    if i < len(A)-1:
        diff = A[i+1] - A[i]
    else:
        diff = K - A[i] + A[0]
    dsum += diff
    if diff > max_diff:
        max_diff = diff

ans = dsum - max_diff
print(ans)

Measured memory_bytes: 31532
#include <stdio.h>
int main(void){
    int n,i,f=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        f+=a[i]-1;
    }
    printf("%d\n", f);
    return 0;
}

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

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int w,h,x,y;
    cin >> w >> h >> x >> y;
    cout << (double)w*(double)h/2.0 << " ";
    if(2*x==w&&2*y==h){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 888
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int A[15];
int X[15][15];
int Y[15][15];
int main(){
  int i;
  int res = 0;
  int mask;
  int cnt;
  rd(N);
  for(i=(0);i<(N);i++){
    int j;
    rd(A[i]);
    for(j=(0);j<(A[i]);j++){
      rd(X[i][j]);X[i][j] += (-1);
      rd(Y[i][j]);
    }
  }
  for(mask=(0);mask<(1<<N);mask++){
    cnt = 0;
    for(i=(0);i<(N);i++){
      if(mask & 1<<i){
        int j;
        cnt++;
        for(j=(0);j<(A[i]);j++){
          if( (mask & 1<<X[i][j]) && Y[i][j]==0){
            goto cTE1_r3A;
          }
          if(!(mask & 1<<X[i][j]) && Y[i][j]==1){
            goto cTE1_r3A;
          }
        }
      }
    }
    chmax(res, cnt);
    cTE1_r3A:;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191208-1 [beta]

// --- original code ---
// int N, A[15], X[15][15], Y[15][15];
// {
//   int res = 0, mask, cnt;
//   rd(N);
//   rep(i,N){
//     rd(A[i]);
//     rep(j,A[i]) rd(X[i][j]--, Y[i][j]);
//   }
//   rep(mask,1<<N){
//     cnt = 0;
//     rep(i,N) if(mask & 1<<i){
//       cnt++;
//       rep(j,A[i]){
//         if( (mask & 1<<X[i][j]) && Y[i][j]==0) break_break_continue;
//         if(!(mask & 1<<X[i][j]) && Y[i][j]==1) break_break_continue;
//       }
//     }
//     res >?= cnt;
//   }
//   wt(res);
// }


Measured memory_bytes: 256
#include<stdio.h>
using namespace std;

int main(){
    int a,b,c;
    int sum = 0;
    scanf("%d %d %d",&a,&b,&c);
    for(int x = a;x<=b;x++){
        if(c%x==0){
            sum++;
        }
    }
    printf("%d\n",sum);
}


Measured memory_bytes: 2768
#!/usr/bin/env python3
(*p, ) = map(int, input().split())
n = int(input())

m = min(p[0] * 8, p[1] * 4, p[2] * 2, p[3])
m2 = min(p[0] * 4, p[1] * 2, p[2])

if m == p[3]:
    print(n // 2 * m + n % 2 * m2)
else:
    print(n * m // 2)


Measured memory_bytes: 9164
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.TreeMap;
import java.math.BigDecimal;
import java.math.BigInteger;
    
public class Main{
 
static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE;
static final long LINF=Long.MAX_VALUE;
 
public static void main(String[] args) throws IOException{
InputReader ir=new InputReader(in);
int a=ir.nextInt();
int b=ir.nextInt();
out.println(a*b+" "+(a+b)*2);
out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;
 
 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
  
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }
 
 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public double nextDouble(){return Double.parseDouble(next());}
 
 public BigInteger nextBigInteger(){return new BigInteger(next());}
 
 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }
 
 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
}

Measured memory_bytes: 24280
public class Main{
  public void run(java.io.InputStream in,java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);

    int r, n, i, j, xl, xr, h;
    int[] maxh;
    double t, mint;

    for(;;){
      r = sc.nextInt(); n = sc.nextInt();
      if(r == 0 && n == 0)break;

      maxh = new int[40];   //maxh[i] [i - 20, i - 19]
      for(i = 0;i < 40;i++)maxh[i] = 0;

      for(i = 0;i < n;i++){
        xl = sc.nextInt(); xr = sc.nextInt(); h = sc.nextInt();
        for(j = xl;j < xr;j++){   //silhouette
          if(maxh[j + 20] < h)maxh[j + 20] = h;
        }
      }

      mint = 21;
      for(i = 0;i < r;i++){
        t = (double)maxh[19 + i] + (double)r - Math.sqrt(r * r - i * i);
        if(mint > t)mint = t;
        t = (double)maxh[20 + i] + (double)r - Math.sqrt(r * r - i * i);
        if(mint > t)mint = t;
        t = (double)maxh[19 - i] + (double)r - Math.sqrt(r * r - i * i);
        if(mint > t)mint = t;
        t = (double)maxh[20 - i] + (double)r - Math.sqrt(r * r - i * i);
        if(mint > t)mint = t;
      }
      out.println(mint);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in,System.out);
  }
}

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

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

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

    map<int, int> mp[2];
    for(int i = 0;i < n;i++){
        mp[i%2][v[i]]++;
    }

    priority_queue<pair<int, int> > pq[2];
    pq[0].push({0, -1727});
    pq[1].push({0, -1719});
    for(int i = 0;i < 2;i++){
        for(auto itr = mp[i].begin();itr != mp[i].end();itr++){
            pq[i].push({(*itr).second, (*itr).first});
        }
    }

    if(pq[0].top().second == pq[1].top().second){
        int num1 = n/2-pq[0].top().first;
        int num2 = n/2-pq[1].top().first;
        pq[0].pop();
        pq[1].pop();

        cout << min(num1 + n/2-pq[1].top().first, num2 + n/2-pq[0].top().first) << endl;
    }else{
        cout << n - (pq[0].top().first + pq[1].top().first) << endl;
    }

    return 0;
}


Measured memory_bytes: 6520
#include<cstdio>
using namespace std;
int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    int bindex = b-a;
    int heightb=0;
    for(int k=1;k<=bindex;k++){
        heightb+=k;
    }
    int x = heightb-b;
    printf("%d\n",x);
    return 0;
}

Measured memory_bytes: 128
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <complex>
#include <cstdio>
#include <queue>

using namespace std;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	int Alice = 0, Bob = 0;
	for (int i = 0; i <N; i++) {
		if (i % 2 == 0)
			Alice += a[i];
		else
			Bob += a[i];
	}
	int ans = Alice - Bob;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
lines = readlines.map{|line| line.split(' ').map(&:to_i)}
a=lines[0][1]
b=lines[0][0]
c=lines[1]
c.push(0)
e=0
x=[0]
for i in 0..b-a
  s=c[i+a]-c[i]
  x.push(s+x.last)
end
puts (x.max+c[0..a-1].inject(:+)+a).to_f/2

Measured memory_bytes: 17212
#include <stdio.h>
#include <math.h>

int saitekiapple(int taste[],int N){
    int saiteki=0;
    double jud;
    int i;

    for(i = 0;i < N;i++){
        jud=pow((double)taste[i],2.0);
        if(pow((double)taste[saiteki],2.0)>=jud){
            saiteki=i;
        }
    }

    return saiteki;
}

int main(){
    char input1[11],input2[11];
    int N;
    int L;

    //fgets(input1,10,stdin);
    //sscanf(input1,"%d",&N);
    //fgets(input2,10,stdin);
    //sscanf(input2,"%d",&L);

    scanf("%d",&N);
    scanf("%d",&L);

    int taste[N];

    int i;

    for(i = 0;i < N;i++){
        taste[i] = L + i + 1 - 1;
    }

    int saiteki;
    saiteki=saitekiapple(taste,N);

    int applepietaste=0;

    for(i = 0;i<N;i++){
        applepietaste +=taste[i];
    }
    
    applepietaste = applepietaste - taste[saiteki];

    printf("%d",applepietaste);

    return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define all(v) v.begin(), v.end()
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a;
    cin >> n >> a;
    vector<int> x(n, 0);

    rep(i,n) {
        cin >> x[i];
    }
    vector<vector<vector<ll> > > dp(n+1, vector<vector<ll> >(n+1, vector<ll>(2500+1,0LL)));
    dp[0][0][0] = 1;
    for(int j=1; j<=n; j++){
        for(int k=0; k<=j; k++){
            for(int s=0; s<=2500; s++){
                dp[j][k][s] += dp[j - 1][k][s];
                if (x[j - 1] <= s and k > 0)
                {
                    dp[j][k][s] += dp[j - 1][k - 1][s - x[j - 1]];
                }
            }
        }
    }
    ll ans = 0;
    for(int k=1; k<=n; k++){
        ans += dp[n][k][k*a];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 52224
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define buff ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define xy pair<int, int>
#define x first
#define y second 

#define inf std::numeric_limits<int>().max()

int main() {
	int n;
	cin >> n;
	vector<ll> v(n); 
	for(int i=0; i<n; i++) {
		cin >> v[i];
	}
	vector<ll> s(n);
	s[0] = v[0];
	for(int i=1; i<n; i++) {
		s[i] = (s[i-1]%mod + v[i]%mod) % mod; 
	}
	ll ans = 0;
	for(int i=1; i<n; i++) {
		ans += (v[i]%mod * s[i-1]%mod) % mod;	
		ans %= mod;
	}
	cout << ans << endl;
}



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

ll INF = 1e+9;

int main(){
	string s,t;
	cin >> s >> t;
	ll ans = INF;
	rep(i,s.size() - t.size() + 1){
		ll count = 0;
		rep(j,t.size()){
			if(s[i+ j] != t[j]) count++;
		}
		ans = min(ans, count);
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3624
import copy
n,k = map(int,input().split())
a = list(map(int,input().split()))

flag = 0
for i in range(2**n):
    state = bin(i)[2:]
    state = '0'*(n - len(state)) + state
    state = [int(i) for i in state]
    
    if sum(state)==k:
        a_state = copy.copy(a)
    
        cost = 0
        for j in range(n):
            if state[j]==1:
                cost_j = max(0,max([0]+a_state[:j])+1-a_state[j])
                cost += cost_j
                a_state[j] += cost_j
            
    
    
        if flag ==0:
            ans =cost
        flag+=1
        ans = min(ans,cost)
print(ans)

Measured memory_bytes: 3444
w, h, n = map(int, input().split())

a = [list(map(int, input().split())) for i in range(n)]

x_l, x_r, y_d, y_u = 0, w, 0, h
for x in a:
  if x[2] == 1 and x[0] > x_l:
    x_l = x[0]
  elif x[2] == 2 and x[0] < x_r:
    x_r = x[0]
  elif x[2] == 3 and x[1] > y_d:
    y_d = x[1]
  elif x[2] == 4 and x[1] < y_u:
    y_u = x[1]
if (x_r - x_l) <= 0 or (y_u - y_d) <= 0:
  print(0)
else:
  print((x_r - x_l) * (y_u - y_d))
    

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

using namespace std;
typedef long long ll;
const long long mod=1e9+7; //10^9+7



int main() {
    ll l,r;
    cin >> l >> r;
    if(r-l>=2019){
        cout << 0 << endl;
        return 0;
    }else{
        int min = 2019;
        for(ll i=l; i<r; i++){
            for(ll j=i+1; j<=r; j++){
                int x = (i*j)%2019;
                if(min > x) min = x;
            }
        }
        cout << min << endl;
    }


  return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	
	int N=in();
	REP(i,N){
		double x1,y1,x2,y2,x3,y3;
		cin>>x1>>y1>>x2>>y2>>x3>>y3;

		double a=hypot(x2-x3,y2-y3);
		double b=hypot(x1-x3,y1-y3);
		double c=hypot(x2-x1,y2-y1);
		double coeff1 = a*a*(b*b+c*c-a*a);
		double coeff2 = b*b*(a*a+c*c-b*b);
		double coeff3 = c*c*(b*b+a*a-c*c);

		double x = (coeff1*x1+coeff2*x2+coeff3*x3)/(coeff1+coeff2+coeff3);
		if(abs(x)<=1e-7) x=0;
		double y = (coeff1*y1+coeff2*y2+coeff3*y3)/(coeff1+coeff2+coeff3);
		if(abs(y)<=1e-7) y=0;
		double r = hypot(x-x1,y-y1);
		
		printf("%.3lf %.3lf %.3lf\n",round(x*1000)/1000,round(y*1000)/1000,round(r*1000)/1000);
	}

	return 0;
}


Measured memory_bytes: 3232
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

const int MAX = 0x3f3f3f3f;
const int maxn = 500000 + 5;
int a[maxn];
int L[(maxn >> 1) + 5], R[(maxn >> 1) + 5];
int cnt;

void merge(int left, int mid, int right)
{
    int x = mid - left;
    int y = right - mid;
    for (int i = 0; i < x; i++)
        L[i] = a[left + i];
    for (int i = 0; i < y; i++)
        R[i] = a[mid + i];

    L[x] = R[y] = MAX;
    int i = 0, j = 0;
    for (int k = left; k < right; k++)
    {
        ++cnt;
        if (L[i] <= R[j])
            a[k] = L[i++];
        else
            a[k] = R[j++];
    }
}

void MergeSort(int left, int right)
{
    if (left + 1 < right)
    {
        int mid = (left + right) >> 1;
        MergeSort(left, mid);
        MergeSort(mid, right);
        merge(left, mid, right);
    }
}

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);

    cnt = 0;
    MergeSort(0, n); //左闭右开

    for (int i = 0; i < n - 1; i++)
        printf("%d ", a[i]);
    printf("%d\n", a[n - 1]);
    printf("%d\n", cnt);
    return 0;
}



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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007


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

struct UF
{
	vector<int> par; // 親
	vector<int> sz; // 数
	// 初期化
	UF(int n):par(n),sz(n) {
		for(int i = 0; i < n; i++){
			par[i] = i;sz[i] = 1;
		}
	}
	// 木の根を求める
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		par[x] = y;
		sz[y] += sz[x];
	}
	// xとyが同じ集合ならtrue
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int n){return sz[find(n)];}
};

int mp[111111];


int main(){
	int n,m;cin >> n >> m;
	UF uf(n + 10);
	vector<int> v(n);
	REP(i,n){
		cin >> v[i];
		mp[v[i]] = i;
	}
	REP(i,m){
		int a,b;cin >> a >> b;
		a--;b--;
		uf.unite(a,b);
	}
	
	int ans = 0;
	REP(i,n){
		if(uf.same(v[i]-1,mp[v[i]]))ans++;
	}
	
	cout << ans << endl;
	
	
	return 0;
}


Measured memory_bytes: 1792
def main():
    q, h, s, d = map(int, input().split())
    n = int(input())
    min_1 = min(q*4, h*2, q*2+h, s)
    min_2 = min(min_1*2, d)

    print((n % 2)*min_1 + (n // 2)*min_2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9100
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
c=list(map(int,input().split()))

# MOD combination
def cmb(n, r, mod=10**9+7):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 2*10**5+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans=0
c.sort(reverse=True)
# r=ruiseki(c)
for i in range(n):
    ans+=c[i]*(i+2)
    ans%=mod
ans*=pow(4,n-1,mod)
print(ans%mod)

Measured memory_bytes: 141260
#include <stdio.h>
int sort(int n,int a[],int b[]);
int main() {
    int n;
    scanf("%d",&n);
    int a[n],b[n];
    for(int count = 0;count < n;count++) scanf("%d",&a[count]);
    sort(n,a,b);
//     for(int i = 0;i < n;i++) printf("%d\n",b[i]);
    printf("%d",b[n-1] - b[0]);
    return 0;
}

int sort(int n,int a[],int b[]) {
    int tmp;
    for(int i = n - 2;i >= 0;i--) for(int j = 0;j <= i;j++) if(a[j] > a[j + 1]) {
        tmp = a[j];
        a[j] = a[j + 1];
        a[j + 1] = tmp;
    } 
    for(int i = 0;i < n;i++) b[i] = a[i];
    return 0;
}

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

int main(){
  long N,i,m=0;
  cin >> N;
  vector<long> tHero(N);
  vector<long> tEnemy(N+1);
  for(i=0;i<N+1;++i)
    cin >> tEnemy.at(i);
  for(i=0;i<N;++i)
    cin >> tHero.at(i);
  for(i=0;i<N;++i){
    if(tEnemy.at(i)>=tHero.at(i))
      m += tHero.at(i);
    else{
      m += tEnemy.at(i);
      tHero.at(i) -= tEnemy.at(i);
      if(tEnemy.at(i+1)>=tHero.at(i)){
        m += tHero.at(i);
        tEnemy.at(i+1) -= tHero.at(i);
      }else{
        m += tEnemy.at(i+1);
        tEnemy.at(i+1) = 0;
      }
    }
  }
  cout << m;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    int k,x;
    cin>>k>>x;
    for(int i=-1000000; i<=1000000; i++){
        if(x-k<i&&i<x+k){
            cout<<i<<' ';
        }
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define N_MAX 999999

int main(void){
	/* eratosthenes */
	char a[N_MAX+1]; int i, j;
	a[0]=0, a[1]=0; for(i=2; i<=N_MAX; i++) a[i]=1;
	for(i=2; i<=(int)sqrt(N_MAX); i++)
		if(a[i]!=0) for(j=2*i; j<=N_MAX; j+=i) a[j]=0;
	
	while(scanf("%d",&i)==1){
		int sum=0;
		for(;i>=1;i--) sum+=a[i];
		printf("%d\n",sum);
	}
	
	return 0;
}

Measured memory_bytes: 0
import java.io.*;
import java.util.*;

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        //input
        int num = Integer.parseInt(br.readLine());        
        String[] str = br.readLine().split(" ");
        String[] str_1 = str[0].split("");
        String[] str_2 = str[1].split("");

        // for algorithim
        StringBuilder sb = new StringBuilder();

        // algorithm
        for(int i = 0; i < num; i++){
          sb.append(str_1[i]);
          sb.append(str_2[i]);
        }

        System.out.println(sb);
      }

    }
}

Measured memory_bytes: 23252
#!/usr/bin/env python3
import sys
try:
    from typing import Dict, List
except ImportError:
    pass


def solve(N: int, M: int, A: "List[int]"):
    mn = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    A.sort(reverse=True)
    dp = [-1] * (N + 1)
    dp[0] = 0
    for i in range(1, N + 1):
        m = -1
        for Ai in A:
            if i - mn[Ai] >= 0 and dp[i - mn[Ai]] >= 0:
                m = max(m, dp[i - mn[Ai]] + 1)
        if m >= 0:
            dp[i] = m
    assert dp[N] >= 0
    k = N
    res = []  # type: List[int]
    while dp[k]:
        for Ai in A:
            if k - mn[Ai] >= 0 and dp[k - mn[Ai]] == dp[k] - 1:
                res.append(Ai)
                k -= mn[Ai]
                break

    print("".join(str(d) for d in res))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3684
input = gets.chomp.split(' ').map(&:to_i)
n = input[0]
a = input[1]
b = input[2]
def digit_sum n
  sum = 0
  while n > 0 do
    sum += n % 10
    n /= 10
  end
  sum
end
ans = (1..n).select do |item|
  # digit_sum(item) >= a && digit_sum(item) <= b
  digit_sum(item).between?(a, b)
end
p ans.inject(:+)


Measured memory_bytes: 1916
#include <iostream>

using namespace std;

int main() {
    int A, B, C;
    cin>>A>>B>>C;
    if (A == C || C == 0) cout<<"YES"<<endl;
    else {
        int a = 0;
        while (1) {
            a = (a + A) % B;
            if (a == C) {
                cout<<"YES"<<endl;
                break;
            } else if (a == 0) {
                cout<<"NO"<<endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------
ll a[110][110];
ll b[110][110];
ll c[110][110];
//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    int n,m,l;cin>>n>>m>>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++){
            for(int k=0;k<m;k++){
                c[i][j]+=a[i][k]*b[k][j];
            }
            cout<<c[i][j];
            if(j<l-1)cout<<" ";
        }
        cout<<Endl;
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------


































Measured memory_bytes: 3440
x = gets
until x.nil?
 y = x.to_f
 if y <= 48.00
  puts "light fly"
 elsif y <= 51.00
  puts "fly"
 elsif y <= 54.00
  puts "bantam"
 elsif y <= 57.00
  puts "feather"
 elsif y <= 60.00
  puts "light"
 elsif y <= 64.00
  puts "light welter"
 elsif y <= 69.00
  puts "welter"
 elsif y <= 75.00
  puts "light middle"
 elsif y <= 81.00
  puts "middle"
 elsif y <= 91.00
  puts "light heavy"
 elsif 91.00 < y
  puts "heavy"
 end

 x = gets
end




Measured memory_bytes: 6844
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
int main(void) {
  int n;
  cin >> n;
  priority_queue<int, vector<int>, greater<int> > gq;
  priority_queue<int> lq;
  vector<int> mid(n);
  vector<ll> sumf(n + 1), sums(n + 1);
  ll sum1 = 0, sum2 = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    gq.push(a);
    sum1 += a;
  }
  for (int i = 0; i < n; i++) {
    cin >> mid[i];
  }
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    lq.push(a);
    sum2 += a;
  }
  sumf[0] = sum1;
  for (int i = 0; i < n; i++) {
    gq.push(mid[i]);
    sumf[i + 1] = sumf[i] + mid[i] - gq.top();
    gq.pop();
  }
  sums[n] = sum2;
  for (int i = n - 1; i >= 0; i--) {
    lq.push(mid[i]);
    sums[i] = sums[i + 1] + mid[i] - lq.top();
    lq.pop();
  }
  ll answer = sumf[n] - sums[n];
  for (int i = 0; i < n; i++) {
    if (answer < sumf[i] - sums[i]) {
      answer = sumf[i] - sums[i];
    }
  }
  cout << answer << endl;
  return 0;
}

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

using namespace std;

int main(){
    int N,M,x,bk=0;
    cin >> N >> M;
    vector<int> a(M),sum(N+1);
    sum[0] = 1;
    sum[1] = 1;
    for(int i=0;i<M;i++){
        cin >> x;
        a[i] = x;
    }

    if(M!=0){
        if(a[0]==1){
            sum[1] = 0;
            bk++;
        }
    }

    for(int i=2;i<N+1;i++){
        if(M!=0){
            if(i == a[bk]){
                sum[i] = 0;
                bk++;
                if(bk==M){
                    bk--;
                }
            }else{
            sum[i] = sum[i-2]+sum[i-1];
            sum[i] %= 1000000007;
            }
        }else{
            sum[i] = sum[i-2]+sum[i-1];
            sum[i] %= 1000000007;
        }
    }
    cout << sum[N] << endl;
}

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

using namespace std;
using ll = long long;

int init();
int solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#define MOD 1000000007
#define PI 3.141592653589793238462643383

signed main()
{
	init();
	solve();
}

string s;

int init()
{
	cin >> s;
}

int solve()
{
	string aki = "AKIHABARA";
	int pos = 0;
	rep(i, s.length()) {
		while (aki[pos] != s[i] && aki[pos] == 'A') pos++;
		if (aki[pos] != s[i]) {
			cout << "NO" << endl;
			return 0;
        }
		pos++;
	}
	if (pos > 7) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
""" Created by Jieyi on 9/20/16. """


def block(board, w, h, direction, color):
    # horizontal.
    if direction == 0:
        for i in range(2):
            for j in range(4):
                board[h + i][w + j] = color
    # vertical.
    elif direction == 1:
        for i in range(2):
            for j in range(4):
                board[h + j][w + i] = color


def print_board(board):
    for i in range(len(board)):
        print(board[i])


direct = [(1, 0), (0, 1), (-1, 0), (0, -1)]


def is_goable(board, w, h, color):
    for x, y in direct:
        if board[h + x][w + y] == color:
            return True
    return False


def go_maze(board, s_w, s_h, g_w, g_h):
    place = board[s_h][s_w]
    if place == 0:
        return 'NG'
    w, h = s_w, s_h
    stack = []

    while True:
        board[h][w] = place + 1
        is_no_way = True
        for x, y in direct:
            if board[h + x][w + y] == place:
                w, h = w + y, h + x
                stack.append((w, h))
                is_no_way = False
                break

        if is_no_way:
            if len(stack) == 0 and not is_goable(board, w, h, place):
                return 'NG'
            (w, h) = stack.pop()
        if w == g_w and h == g_h:
            return 'OK'


def main():
    while True:
        w, h = map(int, input().split())
        if w == 0 and h == 0:
            break

        board = [[0 for _ in range(110)] for _ in range(110)]
        s_w, s_h = map(int, input().split())
        g_w, g_h = map(int, input().split())
        for _ in range(int(input())):
            color, direction, w, h = map(int, input().split())
            block(board, w, h, direction, color)

        # print_board(board)
        print(go_maze(board, s_w, s_h, g_w, g_h))


if __name__ == '__main__':
    main()

Measured memory_bytes: 8112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
const ll mo=1000000007;
ll ans=0;
ll dp[0][0];

int main()
{
string s;
cin >> s;

int len=(int)(s.length());

ll kai1=0;
rep(i,len){
    if(i%2==0){
        if(s[i]=='0')kai1++;
    }
    else{
        if(s[i]=='1')kai1++;
    }
}

ans=min(kai1,len-kai1);
cout << ans << endl;
return 0;
}





Measured memory_bytes: 512