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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

string s;
ll cnt[30];

int main(){
	cin.sync_with_stdio(false);
  cin>>s;
  ll n=s.length();
  rep(i,n){
    cnt[s[i]-'a']++;
  }
  ll res=n*(n+1)/2+1;
  rep(i,30)res-=cnt[i]*(cnt[i]+1)/2;
  cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
const int S=1<<10;
char s[S][S];
void work(int x1,int y1,int x2,int y2){
	if(x1==x2){s[x1][y1]=1;return;}
	int mix=(x1+x2)/2,miy=(y1+y2)/2;
	s[mix][miy]=1;
	work(x1,y1,mix-1,miy-1),work(x1,miy+1,mix-1,y2),
	work(mix+1,y1,x2,miy-1),work(mix+1,miy+1,x2,y2);
}
int main(){
	int n,m,w;scanf("%d%d",&n,&m);
	w=max(n,m);work(1,1,(1<<w)-1,(1<<w)-1);
	for(int i=1;i<(1<<n);i++){
		for(int j=1;j<(1<<m);j++)putchar(s[i][j]+'0');
		puts("");
	}
	
	return 0;
} 

Measured memory_bytes: 2304
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

struct Pair{ Pair(int k, int p) : key(k), point(p) {} int key, point; };
bool operator == (Pair l, Pair r)
{   return l.key == r.key;  }
bool operator < (Pair l, Pair r)
{   return l.key < r.key;   }

vector<string> split(string str, string delim)
{
    vector<string> result;
    int cutAt;
    while( (cutAt = str.find_first_of(delim)) != str.npos )
    {
        if(cutAt > 0)
        {
            result.push_back(str.substr(0, cutAt));
        }
        str = str.substr(cutAt + 1);
    }
    if(str.length() > 0)
    {
        result.push_back(str);
    }
	return result;
}

const int C = 10000;
int main()
{
    vector<Pair> p;
    string buf;
    
    while(getline(cin, buf))
    {
        if(buf.empty()) break;
        vector<string> v = split(buf, ",");
        
        bool f = true;
        rep(i, p.size()) if(p[i].key == atoi(v[0].c_str()))
        {
            p[i].point++;
            f = false;
            break;
        }
        if(f) p.push_back(Pair(atoi(v[0].c_str()), 1));
    }
    
    sort(ALL(p));
    
    while(cin >> buf)
    {
        vector<string> v = split(buf, ",");
        rep(i, p.size()) if(p[i].key == atoi(v[0].c_str()))
        {
            if(p[i].point > 0) p[i].point -= C;
            p[i].point++;
        }
    }
    
    rep(i, p.size()) if(p[i].point < 0)
    {
        cout << p[i].key << " " << p[i].point + C << endl;
    }
}

Measured memory_bytes: 0
package main

import (
	"fmt"
)

func main() {
	var (
		n, a, b, ans int
	)

	fmt.Scan(&n, &a, &b)

	for i := 1; i <= n; i++ {
		temp := i
		count := 0

		for {
			if temp < 10 {
				count += temp
				break
			} else {
				count += temp % 10
				temp /= 10
			}
		}

		if a <= count && count <= b {
			//fmt.Println("\n#########")
			//fmt.Println(i)
			//fmt.Println(count)
			ans += i
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <math.h>
using namespace std;


int main() {

    int N,M,C;
    cin >> N >> M >> C;
    int B[M],A[N][M];

    for(int i=0;i<M;i++){
        cin >> B[i];
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cin >> A[i][j];
        }
    }
    int ans = 0;
    for(int i=0;i<N;i++){
        int sum = 0;
        for(int j=0;j<M;j++){
            sum += B[j]*A[i][j];
        }
        if(sum+C>0){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                String s = sc.next();
                long[] q = new long[3];
                for(int i = 0 ; i < n ; i++){
                        if(s.charAt(i) == 'R') q[0]++;
                        else if(s.charAt(i) == 'G') q[1]++;
                        else q[2]++;
                }
                sc.close();
                long yono = q[0] * q[1] * q[2];
                for(int i = 0 ; i < n - 2 ; i++){
                        for(int j = i + 1 ; j <= n - 2 ; j++){
                                if(2 * j - i < n && s.charAt(i) != s.charAt(j) && s.charAt(j) != s.charAt(2 * j - i) && s.charAt(2 * j - i) != s.charAt(i)) yono--;
                        }
                }
                System.out.println(yono);
        }
}

Measured memory_bytes: 37196
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    int n;
    cin >> n;
    int ans = 0;
    REP(i, n){
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

mod = 10**9+7
mm = a[0]

def gcd(a,b):
    if b>a:
        a,b=b,a
    if b==0:
        return a
    else:
        return gcd(b,a%b)

def lcs(a,b):
    return (a*b)//(gcd(a,b))

for i in range(1,n):
    mm = lcs(mm,a[i])

ans = 0
for i in range(n):
    ans += mm//a[i]

print(ans%mod)


Measured memory_bytes: 4084
# In peace, in love, in war, everything is the same

import math

deg = [0] * 200005
n=int(input())
ar = list(map(int, input().split()))

for i in range(n-1):
    deg[ar[i]] = deg[ar[i]] + 1

for i in range(1, n+1, 1):
    print(deg[i])

Measured memory_bytes: 33288
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl            "\n"
#define pi              acos(-1)
#define ordered_set     tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MAX             100005
#define MOD             1000000007

typedef long long ll;

char grid[1005][1005];
ll dp[1005][1005];

int main()
{
    ll h,w;

    cin>>h>>w;

    for(ll i=1; i<=h; i++)
        for(ll j=1; j<=w; j++)
            cin>>grid[i][j];

    dp[1][1] = 1;

    for(ll i=2; i<=h; i++)
        if(grid[i][1]!='#')
            dp[i][1] = dp[i-1][1];

    for(ll i=2; i<=w; i++)
        if(grid[1][i]!='#')
            dp[1][i] = dp[1][i-1];

    for(ll i=2; i<=h; i++)
    {
        for(ll j=2; j<=w; j++)
        {
            if(grid[i][j]=='#')
                dp[i][j] = 0;
            else
                dp[i][j] = ((dp[i-1][j]%MOD)+(dp[i][j-1]%MOD))%MOD;
        }
    }

    cout<<dp[h][w];
}


Measured memory_bytes: 9088
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <utility>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <queue>
using namespace std;
 
#define LL   long long
#define ld   long double
#define pii  pair<int,int>
#define pLL  pair<LL,LL>
#define vint vector<int>
#define vLL  vector<LL>
 
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define MP make_pair
#define PB push_back
 
#define Si(x) scanf("%d",&(x));
#define Sii(x,y) scanf("%d %d",&(x),&(y));
#define Siii(x,y,z) scanf("%d %d %d",&(x),&(y),&(z));
#define SL(x) scanf("%lld",&(x));
#define SLL(x,y) scanf("%lld %lld",&(x),&(y));
#define SLLL(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z));
 
#define Pi(x) printf("%d\n",(x));
#define Pii(x,y) printf("%d %d\n",(x),(y));
#define Piii(x,y,z) printf("%d %d %d\n",(x),(y),(z));
#define Piiii(x,y,z,w) printf("%d %d %d %d\n",(x),(y),(z),(w));
#define Piiiii(a,b,c,d,e) printf("%d %d %d %d %d\n",(a),(b),(c),(d),(e));
#define Piiiiii(a,b,c,d,e,f) printf("%d %d %d %d %d %d\n",(a),(b),(c),(d),(e),(f));
#define PL(x) printf("%lld\n",(x)*1LL);
#define PLL(x,y) printf("%lld %lld\n",(x)*1LL,(y)*1LL);
#define PLLL(x,y,z) printf("%lld %lld %lld\n",(x)*1LL,(y)*1LL,(z)*1LL);
#define PLLLL(x,y,z,w) printf("%lld %lld %lld %lld\n",(x)*1LL,(y)*1LL,(z)*1LL,(w)*1LL);
 
#define Pi1(x) printf("%d",  (x));
#define PiL(x) printf("%lld",(x));
#define Pspace putchar(' ');
#define Pendl  puts("");
 
#define MEM0(x) memset( (x), 0, sizeof( (x) ) )
#define MEM1(x) memset( (x),-1, sizeof( (x) ) )
#define REP1(i,n)  for (int i = 1; (n) >= i ; ++i)
#define REP0(i,n)  for (int i = 0; (n) >  i ; ++i)
#define REP(L,R,k) for (int i = (L); (R) >= i; i+= (k) )
 
int myRnd(int L,int R) {
    return abs(( (rand()<<15)|rand() ) ) % (R-L+1) + L;
}
 
const int N = 1e5 + 6;
int dp[N];
 
int main () {
    srand(time(NULL));
    int k;
    Si(k);
    MEM1(dp);

    priority_queue<pii,vector<pii>,greater<pii> > pq;

    int ans=-1;
    for (int i=9;i>=1;i--) {
        dp[i%k] = i;
        pq.push({i,i%k});
    }
    while (!pq.empty()) {
        pii p=pq.top();
        pq.pop();

        if (dp[p.S] != p.F) continue;
        REP0(i,10) {
            int nxt=p.S*10+i;
            nxt %= k;

            if (nxt == 0) {
                if (ans == -1) ans = p.F + i;
                else ans = min(ans,p.F+i);
            }
            else {
                if (dp[nxt] == -1) {
                    dp[nxt] = p.F + i;
                    pq.push({dp[nxt],nxt});
                }
                else if (p.F + i < dp[nxt]) {
                    dp[nxt] = p.F + i;
                    pq.push({dp[nxt],nxt});
                }
            }
        }
    }
    Pi(ans);
}

Measured memory_bytes: 2804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxL = 1e18;
const int maxm = 1e5 + 10;
int n, tot;
ll L, ans;
map<ll, ll> sg;
char s[maxm];
int ch[maxm][2];
inline ll lowbit(ll x) { return x & (-x);}
inline int newnode(int& now)
{ 
	return now ? now : now = ++tot;
}
void insert(int& root)
{
	int now = newnode(root);
	int m = strlen(s + 1);
	for(int i = 1; i <= m; ++i)
		now = newnode(ch[now][s[i] - '0']);
}
void dfs(int x, int dep)
{
	if(!x)
	{
		ans ^= lowbit(L - dep + 1); //sg
		return;
	}
	if(!ch[x][0] && !ch[x][1]) return;
	dfs(ch[x][0], dep + 1);
	dfs(ch[x][1], dep + 1);
}
int main()
{
	int root = 0;
	scanf("%d%lld", &n, &L);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%s", s + 1);
		insert(root);
	}
	dfs(root, 0);
	if(ans) puts("Alice");
	else puts("Bob");
	return 0;
}
/*
void pre()
{
	sg[0] = 0;
	for(ll i = 1; i <= maxL; i <<= 1)
	{
		set<ll> mex;
		for(ll j = 1; j <= i; j <<= 1)
		{
			ll x = i - j, cur = 0;
			for(ll k = 1; k <= x; k <<= 1)
				if(x & k)
					cur ^= sg[k];
			mex.insert(cur);
		}
		ll ret = 0;
		while(mex.find(ret) != mex.end())
			++ret;
		sg[i] = ret;
		//cout << i << ' ' << sg[i] << ' ' << lowbit(int(log2(i))) << endl;
	}
}
*/
/*
2 3
0
10
*/


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

int main() {
  int n; cin >> n;
  long long l0 = 2, l1 = 1;
  
  if(n==0) {cout << l0 << endl; return 0;}
  if(n==1) {cout << l1 << endl; return 0;}
  long long l2;
  for(int i = 2; i <= n; i++){
    l2 = l0 + l1;
    l0 = l1;
    l1 = l2;
  }
  cout << l2 << endl;
    
  return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int n, m;
int a[100002];
ll ans;

int main() {

	priority_queue<int> que;
	
	cin >> n >> m;
	rep(i, n)cin >> a[i];
	rep(i, n)que.push(a[i]);

	rep(i, m) {
		int l;
		l = que.top() / 2;
		que.pop();

		que.push(l);
	}

	while (!que.empty()) {
		ans += que.top();
		que.pop();
	}

	cout << ans << endl;

	

	return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

ll lcm(ll a, ll b){
    ll g = gcd(a, b);
    return (a / g) * b;
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int cnt = 1,ans = 0;
    for (int i = 0; i < n; ++i) {
        if(a[i] == cnt){
            cnt++;
            ans++;  // 1があった
        }
    }
    if(cnt == 1) cout << -1 << endl;
    else cout << n-ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
  int i,j,v,n,m,k;
  int V[110][110];

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d%d",&v,&m);
    if(m != 0){
      for(j = 0; j < m; j++){
	scanf("%d",&k);
	V[v-1][k-1] = 1;
      }
    }
  }

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

Measured memory_bytes: 648
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
 
#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif
 
const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;
 
class Combi {
private:
	vector<lint> fac, inv, finv;
 
	void init(int N) {
		fac[0] = fac[1] = 1; inv[1] = 1; finv[0] = finv[1] = 1;
 
		for (int i = 2; i < N; i++) {
			fac[i] = fac[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
			finv[i] = finv[i - 1] * inv[i] % MOD;
		}
	}
 
public:
	Combi(int N = 10000) : fac(N + 1), inv(N + 1), finv(N + 1) { init(N + 1); }
 
	lint Cmod(int n, int k) {
		if (n < k) return 0;
		if (n < 0 || k < 0) return 0;
		return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}
 
	lint Pmod(int n, int k) {
		if (n < k) return 0;
		if (n < 0 || k < 0) return 0;
		return fac[n] * finv[n - k] % MOD;
	}
};
 
int main() {
 
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
 
	int N, K;
	cin >> N >> K;
 
	Combi C;
 
	for (int i = 1; i <= K; i++) cout << C.Cmod(N - K + 1, i) * C.Cmod(K - 1, i - 1) % MOD << "\n";
 
	return 0;
}

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

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

int N,a[100010],b[100010],c[100010];
int dpa[100010],dpb[100010],dpc[100010];

int main(void) {
	scanf("%d",&N);
	REP(i,N) {
		scanf("%d%d%d", &a[i], &b[i], &c[i]);
		dpa[i] = max(a[i]+dpb[i-1],a[i]+dpc[i-1]);
		dpb[i] = max(b[i]+dpa[i-1],b[i]+dpc[i-1]);
		dpc[i] = max(c[i]+dpa[i-1],c[i]+dpb[i-1]); 
	}
	printf("%d\n",max(dpa[N-1],max(dpb[N-1],dpc[N-1])));
	return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = (int)1e6 + 34;
//const ll INF = (ll)1e18 + 41;
const int INF = (int)1e9 + 41;
const ll MD = (ll)1e9 + 7;

int dp[N];
void solve() {
    ll x;
    cin >> x;
    if (x == 0) {
        cout << "0\n";
        return;
    }

    string ans = "";
    ll pw = 1;
    while (x != 0) {
        if ((x / pw) % 2 != 0) {
            x -= pw;
            ans.push_back('1');
        } else {
            ans.push_back('0');
        }
        pw *= -2;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << "\n";
}

int main() {
#ifdef MADE_BY_SERT
    freopen("a.in", "r", stdin);
    solve();
    solve();
#endif // MADE_BY_SERT
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   int h,w;
   cin>>h>>w;
   while(h--)
   {
      string str;
      cin>>str;
      cout<<str<<endl<<str<<endl;
   }   
    return 0;
}








Measured memory_bytes: 3604
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int A, B;
  cin >> A >> B;
  int ans = -1;
  for (int i = 1; i <= 10000; ++i) {
    if (int(i * 0.08) == A && int(i * 0.10) == B) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        
        int result = 0;
        if (n%k != 0) result = 1;

        System.out.println(result);
    }
}


Measured memory_bytes: 35924
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ins insert
#define vi vector<int>
const int mxN=2e5;
 
int main () 
{
    int d,t,s;
    cin >> d >> t >> s;
    if(t*s>=d)
        cout << "Yes";
    else
    {
        cout << "No";
    }
}

Measured memory_bytes: 3640
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var h = int.Parse(line[0]);
            var w = int.Parse(line[1]);
            if (h == 0 && w == 0) break;
            var map = new bool[h, w];
            var zc = new int[w];
            for (int i = 0; i < h; i++)
            {
                line = Console.ReadLine().Trim().Split(' ');
                var a = Array.ConvertAll(line, int.Parse);
                for (int j = 0; j < w; j++)
                    if (a[j] == 1) map[i, j] = true;
                    else zc[j]++;
            }
            var ans = getAns(map, zc, h, w);
            Console.WriteLine(ans);
        }
    }
    static int countMax0(bool[,] map, int[] zc, int h, int w, List<int> rv)
    {
        var ans = 0;
        for (int i = 0; i < w; i++)
        {
            var ocount = 0;
            foreach (var x in rv)
                if (map[x, i]) ocount++;
                else ocount--;
            ans += Max(zc[i] + ocount, h - zc[i] - ocount);
        }
        return ans;
    }
    static int getAns(bool[,] map, int[] zc, int h, int w)
    {
        var ans = 0;
        var imax = 1 << h;
        for (int i = 0; i < imax; i++)
        {
            var rv = new List<int>();
            for (int j = 0; j < h; j++)
                if (((i >> j) & 1) == 1) rv.Add(j);
            var t = countMax0(map, zc, h, w, rv);
            ans = Max(ans, t);
        }
        return ans;
    }
}




Measured memory_bytes: 29344
import java.util.Scanner;
import java.io.*;

public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn = null;
		int[] input = new int[10000];
		int index = 0;
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			while( stdIn.hasNext() ){
				if( stdIn.hasNextInt() ){
					input[index] = stdIn.nextInt();
					index++;
				} else {
					stdIn.next();
				}
			}
			String[] num = {"1","2","4","8","16","32","64","128","256","512"};
			for(int i = 0; i < index; i++){
				String str = Integer.toBinaryString(input[i]);
				StringBuilder result = new StringBuilder();
				for(int j = 0; j < str.length(); j++){
					if( str.charAt(str.length()-1-j) == '1' ){
						result.append(num[j] + " ");
					}
				}
				result.deleteCharAt(result.length()-1);
				System.out.println(result);
			}
		} finally {
			if( stdIn != null ){
				stdIn.close();
			}
		}
	}
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  map<int, int> Map;
  
  /* iさんがK個の料理を好き */
  for(int i=0; i<N; i++)  {
    int K;
    cin >> K;
    for(int k=0; k<K; k++) {
      int tmp;
      cin >> tmp;
      Map[tmp]++;
    }
  }
  
  int num = 0;
  for(auto m:Map) {
    if(m.second == N) {
      num++;
    }
  }
  
  cout << num << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool a[10000001];
int main(){
  long long b[5000]={0},c=0,i,j;
  for(i=2;i<10000001;i++){
    if(!a[i])for(j=i+i;j<10000001;j+=i)a[j]=1;
  }
  for(i=5;i<10000001-9;i++)if(a[i]==0&&a[i+2]==0&&a[i+6]==0&&a[i+8]==0)b[c++]=i+8;
  while(scanf("%d",&j),j){
    for(i=0;i<c;i++){
      if(j<b[i])break;
    }
    if(i--);
    cout<<b[i]<<endl;
  }
}

Measured memory_bytes: 12940
'use strict'

function Main(input) {
  const W = Number(input.split(" ")[0])
  const H = Number(input.split(" ")[1])
  const x = Number(input.split(" ")[2])
  const y = Number(input.split(" ")[3])
  const area = W * H

  let ok = 0
  if(x === W / 2 && y === H / 2) {
    ok = 1
  }

  console.log(area / 2, ok)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim())

Measured memory_bytes: 11724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll N,M;
    cin >> N >> M;
    vector<pair<ll,ll>> A(N);
    REP(i,N){
        cin >> A[i].F >> A[i].S;
    }
    sort(ALL(A));
    ll cost = 0;
    REP(i,N){
        cost += A[i].F*min(A[i].S,M);
        M -= A[i].S;
        if(M < 1)break;
    }
    cout << cost << "\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, digitDP, treeDP//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vl flag, D; vll path;
//***********//
int main() {
	cin >> N;
	vl A(N), B(N);
	for (i = 0; i < N; i++) cin >> A[i];
	for (i = 0; i < N; i++) cin >> B[i];
	priority_queue<pll> Q;
	for (i = 0; i < N; i++) {
		if (B[i] < A[i]) {
			co(-1);
			exit(0);
		}else if(A[i]!=B[i]) Q.push(mp(B[i],i));
	}
	while (!Q.empty()) {
		pll P = Q.top();
		Q.pop();
		ll f = P.first;
		ll s = P.second;
		//debug(f, s);
		if (A[s] == B[s]) continue;
		ll left = s - 1;
		ll right = s + 1;
		if (s == 0) left = N - 1;
		if (s == N - 1)right = 0;
		ll D = f - A[s];
		if (D > 0) {
			ll R = D / (B[left] + B[right]);
			if (R == 0) {
				co(-1);
				exit(0);
			}
			f -= (B[left] + B[right]) * R;
			B[s] = f;
			//debug(f);
			ans += R;
			if (A[s] != B[s]) Q.push(mp(f, s));
		}
		else {
			co(-1);
			exit(0);
		}
	}
	co(ans);
}

Measured memory_bytes: 10492
//! Framework <https://github.com/vain0x/procon>

#![allow(non_snake_case)]
#![allow(unused_imports)]

use std::collections::*;

pub struct Scan(Box<dyn Iterator<Item = &'static str>>); // '

impl Scan {
    fn new() -> Self {
        let mut buf = String::new();
        let read_line = move || {
            std::io::stdin().read_line(&mut buf).unwrap();
            Box::leak(buf.split_off(0).into_boxed_str()).split_whitespace()
        };
        Scan(Box::new(std::iter::repeat_with(read_line).flatten()))
    }

    pub fn word<T: std::str::FromStr>(&mut self) -> T {
        self.0.next().unwrap().parse().ok().unwrap()
    }

    pub fn list<T: std::str::FromStr>(&mut self, len: usize) -> Vec<T> {
        std::iter::repeat_with(|| self.word()).take(len).collect()
    }
}

fn main() {
    let mut scan = Scan::new();

    let H1 = scan.word::<usize>();
    let M1 = scan.word::<usize>();
    let H2 = scan.word::<usize>();
    let M2 = scan.word::<usize>();
    let K = scan.word::<usize>();

    let t = (H2 * 60 + M2) - (H1 * 60 + M1) - K;

    println!("{}", t);
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
 
// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
 
using namespace std;
using namespace __gnu_pbds;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define endl "\n"
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
const int INF = 1e16;
const double PI = acos(-1);
const int N = 1e6 + 7;
int mod = 1e9 + 7;

const int maxn = 3e3 + 7;
int dp[maxn][maxn];

int32_t main()
{
    IOS;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    string s;
    cin >> s;
    dp[1][1] = 1;
    vector<int> pref(n+1, 0);
    for(int i = 0; i < s.size(); i++)
    {
        int k = i + 2;
        for(int j = 1; j <= n; j++)
        {
            pref[j] = pref[j-1] + dp[k-1][j];
            pref[j] %= mod;
        }
        for(int j = 1; j <= k; j++)
        {
            int l, r;
            if(s[i] == '<')
                l = 1, r = j - 1;
            else
                l = j, r = k;
            if(l <= r)
                dp[k][j] = (pref[r] - pref[l-1] + mod) % mod;
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++)
        ans += dp[n][i], ans %= mod;
    cout << ans << endl;
    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int mod = 1e9+7;

void solve() {
  long long n, k; scanf("%lld%lld", &n, &k);
  long long ans = 0;
  for (long long i = k; i <= n+1; ++i) {
    long long min_ = i*(i-1)/2;
    long long max_ = n*(n+1)/2 - (n-i)*(n-i+1)/2;
    ans = (ans + (max_ - min_ + 1)) % mod;
  }
  printf("%lld", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3848
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main(){
  int T;
  while(cin >> T, T){
    vector<int> t(T);
    for(int i = 0; i < T; ++i){
      cin >> t[i];
    }
    int N;
    cin >> N;
    int d, m;
    vector< pair<int,int> > V;
    for(int i = 0; i < N; ++i){
      cin >> d >> m;
      --d;
      V.emplace_back(d,m);
    }
    sort(V.begin(), V.end());
    int ans = 0, e = N;
    while(e > 0){
      for(int k = 0; k <= V[e-1].first; ++k){
        int tmp = -1;
        bool f = false;
        for(int i = 0; i < e; ++i){
          if(V[i].first < k) continue;
          if(tmp == -1){
            tmp = i;
            f = true;
          }
          if(V[i].second < t[(V[i].first-k)%T]){
            f = false;
            break;
          }
        }
        if(f){
          e = tmp;
          if(k != 0) ++ans;
          break;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
int n;
map<int,int> mp;
int ans;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	while(n--){
		int a;
		cin>>a;
		mp[a]++;
	}
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
		if((it->se)<(it->fi)) ans+=it->se;
		else ans+=(it->se)-(it->fi);
	}
	cout<<ans;
	re 0;
}

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

int main() {
    int a;
    cin >> a >> a >> a >> a;
    cout << (a == 1) << endl;
}

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

int main() {
	int a, b, c, rec=0, dia=0;
	char com;
	while (cin >> a >> com >> b >> com >> c) {
		if (a * a + b * b == c * c) {
			rec++;
		}
		else if (a == b) {
			dia++;
		}
	}

	cout << rec << endl;
	cout << dia << endl;

	return 0;
}

Measured memory_bytes: 1160
while true
  n, k = gets.split.map(&:to_i)
  break if n == 0
  a = []
  n.times{|i|
    a.push(gets.to_i)
  }
  sum = 0
  k.times{|i|
    sum += a[i]
  }
  ans = sum
  k.upto(n-1){|i|
    sum += a[i]
    sum -= a[i-k]
    ans = [ans, sum].max
  }
  p ans
end

Measured memory_bytes: 7028
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>
#include <sstream>
#include <iomanip>

using namespace std;

using Graph = vector<vector<int> >;

vector<int> seen;



int main()
{
	int A,B;

	cin >> A >> B;

	int ans = max(0, A - 2 * B);

	//printf("%d %d %lld", xi, yi, H + gap);

	cout << ans;
	

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <array>
#include <algorithm>
#include <set>
#include <iomanip>
#include <cstdio>

using namespace std;

#define int long long

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

	string s;
	int a, d;

	cin >> a >> s >> d;

	auto c = s[d - 1];

	for (auto& ss : s)
	{
		ss = (c == ss ? c : '*');
	}

	cout << s << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
    int N,i,min,level,sum=1;
    scanf("%d",&N);
    for(i=0; i<N; i++) {
        scanf("%d",&level);
        if(i==0) min=level;
        if(level<min) {
            min=level;
            sum++;
        }
    }
    printf("%d\n",sum);
    return 0;
}

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

int main(){
  ll a,b,c,x;
  cin>>a>>b>>c>>x;
  ll ans = 0;
  REP(i,a+1){
    REP(j,b+1){
      REP(k,c+1){
        ll sum = 500*i+100*j+50*k;
        if(sum == x){
          ans++;
        }
      }
    }
  }
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#define re register
using namespace std;
const int Mxdt=100000;	//单次大小 
inline char gc(){
	static char buf[Mxdt],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,Mxdt,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
int n,ch[1000002][26],val[1000002][26],f[1000002][26],tot,anss[26];
long long ans;
char s[1000002];
vector<char>ss[200002];
struct node{
	int id,len;
	bool operator <(const node x){
		return len>x.len;
	}
}p[200002];
inline int read(){
	re int t=0;re char v=gc();
	while(v<'0')v=gc();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=gc();
	return t;
}
inline void work(char*t){
	re int m=strlen(t+1),nw=0,ia=0;
	for(re int i=1;i<m;++i){
		nw=ch[nw][t[i]-'a'];
		if(!nw){
			ia=1;
			break;
		}
	}
	if(!ia){
		ans+=val[nw][t[m]-'a'];
	}nw=0;
	for(re int i=1;i<=m+1;++i)for(re int j=0;j<=25;++j)f[i][j]=0;
	for(re int i=m;i;--i)for(re int j=0;j<=25;++j)f[i][j]=(f[i+1][j]||(t[i]==(j+'a')));
	for(re int i=0;i<=25;++i)anss[i]+=f[1][i];
	for(re int i=1;i<=m;++i){
		if(!ch[nw][t[i]-'a'])ch[nw][t[i]-'a']=++tot;
		nw=ch[nw][t[i]-'a'];
		for(re int j=0;j<=25;++j)val[nw][j]+=f[i+1][j]; 
	}
	
}
signed main(){
	n=read();
	for(re int i=1;i<=n;++i){
	scanf("%s",s+1),p[i].len=strlen(s+1),p[i].id=i,reverse(s+1,s+p[i].len+1);for(re int j=1;j<=p[i].len;++j)ss[i].push_back(s[j]);}
	sort(p+1,p+n+1);
	for(re int ii=1;ii<=n;++ii){
		re int i=p[ii].id;
		if(ss[i].size()>1){
		for(re int j=0;j<ss[i].size();++j)s[j+1]=ss[i][j];
		s[ss[i].size()+1]='\0';work(s);
		}
		else ans+=anss[ss[i][0]-'a'];
	}
	printf("%lld",ans);
}


Measured memory_bytes: 308888
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

str s;
int ans;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='+')ans++;
        else ans--;
    }
    cout<<ans<<newl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    
    static int[] s;
    static int top;

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        s = new int[200];
        top = 0;
        
        while(sc.hasNext()){
            String st = sc.next();
            int a, b;
            if(st.equals("+")){
                b = pop();
                a = pop();
                push(a+b);
            }else if(st.equals("-")){
                b = pop();
                a = pop();
                push(a-b);
            }else if(st.equals("*")){
                b = pop();
                a = pop();
                push(b*a);
            }else{
                push(Integer.parseInt(st));
            }
        }
        
        System.out.println(pop());
    }
    
    static void push(int x){
        top++;
        s[top] = x;
    }
    
    static int pop(){
        top--;
        return s[top+1];
    }
}


Measured memory_bytes: 26224
#include <cstdio>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

#define N 111111
typedef int ll;
ll p[N];
vector<ll> dat[1<<18]; //Nより大きい2^(k+1)

void init(int k,int l,int r)
{
  dat[k].clear();
  if( r-l == 1 ) {
    dat[k].push_back(p[l]);
  } else {
    int lch = k*2+1, rch = k*2+2;
    init(lch,l,(l+r)/2);
    init(rch,(l+r)/2,r);
    dat[k].resize(r-l);
    merge(dat[lch].begin(),dat[lch].end(),
          dat[rch].begin(),dat[rch].end(),
          dat[k].begin());
  }
}

int ab(int a){return a<0?-a:a;}

int query(int i,int j,ll D,int k,int l,int r)
{
  if( j <= l || r <= i ) return INT_MAX;
  else if( i <= l && r <= j ) {
    int idx = lower_bound(dat[k].begin(),dat[k].end(),D)-dat[k].begin();
    int a = INT_MAX;
    //printf("%d %d %d %ld %d\n",i,j,D,dat[k].size(),idx);
    for( int i = -1; i <= 1; i++ ) {
      if( 0 <= i+idx && i+idx < int(dat[k].size()) ) {
        //printf("%d:",dat[k][i+idx]);
        a = min(a,ab(D-dat[k][i+idx]));
      }
    }
    //puts("");
    return a;
    //return upper_bound(dat[k].begin(),dat[k].end(),y)-lower_bound(dat[k].begin(),dat[k].end(),x);
  }
  int lc = query(i,j,D,k*2+1,l,(l+r)/2);
  int rc = query(i,j,D,k*2+2,(l+r)/2,r);
  return min(lc,rc);
}

int main(void)
{
  int n,q;
  scanf("%d",&n);
  for( int i = 0; i < n; i++ ) scanf("%d",p+i);
  init(0,0,n);
  scanf("%d",&q);
  for( int i = 0; i < q; i++ ) {
    int l,r,d;
    scanf("%d%d%d",&l,&r,&d);
    printf("%d\n",query(l,r+1,d,0,0,n));
  }
  return 0;
}


Measured memory_bytes: 18820
#!/usr/bin/env python
# coding: utf-8

# In[19]:


N = int(input())


# In[20]:


k = len(str(N))
if N%(10**(k-1)) == 10**(k-1) - 1:
    print(int(N/(10**(k-1))) + 9*(k-1))
else:
    print(int(N/(10**(k-1))) + 9*(k-1) - 1)


# In[ ]:






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

int main()
{
	int n;
	double t, m;
	double AngleT = 360.0/12.0;
	double AngleT2 = 360.0/12.0/60.0;
	double AngleM = 360.0/60.0;
	double dif;
	cin>>n;
	while (scanf("%lf:%lf",&t,&m) != EOF) {
		dif = t*AngleT + m*AngleT2 - m*AngleM;
		if (dif<0.0) dif*=-1;
		if (dif>180.0)dif -= 360.0;
		if (dif<0.0) dif*=-1;
		if (dif<30.0) cout<<"alert"<<endl;
		else if (dif<90.0) cout<<"warning"<<endl;
		else cout<<"safe"<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
# include "iostream"
# include "cstdio"

using namespace std;

int num(int x){
	int ans=0;
	while(x){
		ans+=(x%10);
		x/=10; 
	}
	return ans; 
} 

int main(){
	int n,x,ans=1000000007;
	scanf("%d",&n);
	for(register int i=1;i<=n/2;i++){
		x=n-i;
		if(num(x)+num(i)<ans){
			ans=num(x)+num(i); 
		} 
	}
	printf("%d",ans);
	return 0; 
} 

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  string S;
  cin>>S;
  if(S[0]==S[1]||S[1]==S[2]||S[2]==S[3]) cout<<"Bad"<<endl;
  else cout<<"Good"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
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()
{
int a,b;
cin >> a >> b;

cout << max(0,a-2*b) << endl;

return 0;
}

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

int main(){
	
  int n;
  cin>>n;
  int odds = 0;
  for(int i = 1 ; i <= n ; ++i)
    if(i&1)
      odds++;
  
  cout<<fixed<<setprecision(10)<<(double)odds/n<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < n; ++i)
#define forn1(i, n) for (int i = 1; i <= n; ++i)
#define pb push_back
#define fr first
#define sc second
const int MAXN = 65535 + 5;
const double INF = 2e9;
const ll MOD = 1e9 + 7;
int gg[20][20];
int used[20];
int ans = 0;

void check(int n)
{
  int cnt = 0;
  for (int i = 0; i < n; ++i)
  {
    if (!used[i])continue;
    ++cnt;
    for (int j = 0; j < n; ++j)
    {
      if (gg[i][j] == 1)
      {
        if (used[j] != 1)return;
      }
      if (gg[i][j] == 0)
      {
        if (used[j] == 1)return;
      }
    }
  }
  ans = max(ans, cnt);
}

void dfs(int cnt, int n)
{
  if (cnt == n)
  {
    check(n);
    return;
  }
  used[cnt] = 1;
  dfs(cnt + 1, n);
  used[cnt] = 0;
  dfs(cnt + 1, n);
}

//#define DEBUG

int main(){
  FastIO;
  #ifdef DEBUG
    freopen("input.txt", "r", stdin);
  #endif
  int n;
  cin >> n;
  forn(i, 20)
  {
    forn(j, 20)
    {
      gg[i][j] = -1;
    }
  }
  forn(i, n)
  {
    int k;
    cin >> k;
    forn(j, k)
    {
      int a, b;
      cin >> a >> b;
      --a;
      gg[i][a] = b;
    }
  }
  dfs(0, n);
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
const int mod = 1000000007;
int n, q, l[309], r[309], x[309], p[309], dp[309][309][309];
int main() {
	scanf("%d %d", &n, &q);
	for (int i = 0; i < q; i++) scanf("%d %d %d", &l[i], &r[i], &x[i]), l[i]--;
	for (int i = 0; i < q; i++) {
		for (int j = i + 1; j < q; j++) {
			if (r[i] > r[j]) {
				swap(l[i], l[j]);
				swap(r[i], r[j]);
				swap(x[i], x[j]);
			}
		}
	}
	for (int i = 0; i < q; i++) {
		for (int j = r[i]; j <= n; j++) p[j]++;
	}
	dp[0][0][0] = 1;
	int ret = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n; k++) {
				int t = max({ i, j, k }), t3 = min({ i, j, k }) - 1, t2 = i + j + k - t - t3 - 2; bool flag = false;
				for (int k2 = t == 0 ? 0 : p[t - 1]; k2 < p[t]; k2++) {
					if (x[k2] == 1 && l[k2] <= t2) flag = true;
					if (x[k2] == 2 && (l[k2] > t2 || l[k2] <= t3)) flag = true;
					if (x[k2] == 3 && l[k2] > t3) flag = true;
				}
				if (flag) continue;
				if (t == n) {
					ret += dp[i][j][k];
					if (ret >= mod) ret -= mod;
				}
				else {
					dp[t + 1][j][k] += dp[i][j][k]; if (dp[t + 1][j][k] >= mod) dp[t + 1][j][k] -= mod;
					dp[i][t + 1][k] += dp[i][j][k]; if (dp[i][t + 1][k] >= mod) dp[i][t + 1][k] -= mod;
					dp[i][j][t + 1] += dp[i][j][k]; if (dp[i][j][t + 1] >= mod) dp[i][j][t + 1] -= mod;
				}
			}
		}
	}
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 112896
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
Ken_n,City_n = (int(i) for i in input().split())
city ={i:[] for i in range(1,Ken_n+1)}
for i in range(1,City_n+1):
    p,y = (int(i) for i in input().split())
    city[p].append((y,i))

city_ID ={i:0 for i in range(1,City_n +1)}
for i in range(1,Ken_n +1):
    city[i].sort()
    
    for j in range(len(city[i])):
        city_ID[city[i][j][1]] = "{0:06d}".format(i) +"{0:06d}".format(j+1)

for i in range(1,City_n +1):
    print(city_ID[i])

Measured memory_bytes: 58940
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)
 
#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(50)
 
const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;
 
// typedef long long ll;
#define int long long
#define double long double
 
template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
 
typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

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

  int N, A, B; cin >> N >> A >> B;
  if((B-A) & 1){
    int AA = N-A, BB = N-B;
    cout << min((A-1+1+B-1), (BB+1+AA)) / 2 << endl;
  } else {
    cout << (B-A) / 2 << endl;
  }
}

Measured memory_bytes: 384
// ABC043_A
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define vl vector<ll>
#define pll pair<ll, ll>
#define F first
#define S second

int main() {
    // input
    ll N, sum = 0;
    cin >> N;
    REP(i, N) sum += i+1;
    cout << sum << "\n";
    // calculation
    
    
    return 0;
}

Measured memory_bytes: 256