akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

typedef vector< vector<int> > VVI;

struct edge {
	int to, cost;
	edge(int t, int c) :to(t), cost(c) {}
};
typedef pair<int, int> P; // firstは最短距離, secondは頂点の番号

const int INF = (1e9);

void wFloyd ( VVI &v )
{
	int len = v.size();

	for (int k = 0; k < len; ++k)
	{
		for (int i = 0; i < len; ++i)
		{
			for (int j = 0; j < len; ++j)
			{
				v[i][j] = min(v[i][j], v[i][k] + v[k][j]);
			}
		}
	}
}

int dijkstra ( int s, int e, int size, vector< vector<edge> > &graph )
{
	priority_queue< P, vector<P>, greater<P> > que;
	vector<int> cost(size, INF);

	cost[s] = 0;
	que.push(P(0, s));

	while (!que.empty())
	{
		P p = que.top(); que.pop();
		int v = p.second;

		if (cost[v] < p.first) continue;

		for (int i = 0, ilen = graph[v].size(); i < ilen; ++i)
		{
			edge e = graph[v][i];
			if (cost[e.to] > (cost[v] + e.cost))
			{
				cost[e.to] = cost[v] + e.cost;
				que.push(P(cost[e.to], e.to));
			}
		}
	}

	return cost[e];
}

int main ( void )
{
	int n, k;

	while (cin >> n >> k, (n | k))
	{
		//VVI v(n, vector<int>(n, INF));
		vector< vector<edge> > v(n);

		for (int i = 0; i < k; ++i)
		{
			int x;

			cin >> x;

			if (x)
			{
				int c, d, e;

				cin >> c >> d >> e;

				--c; --d;

				bool hit = false;

				for (int j = 0, jlen = v[c].size(); j < jlen && !hit; ++j)
				{
					if ((v[c][j].to == d) && (v[c][j].cost > e))
					{
						v[c][j].cost = e;
						hit = true;
					}
				}

				if (!hit) v[c].push_back(edge(d, e));

				hit = false;

				for (int j = 0, jlen = v[d].size(); j < jlen && !hit; ++j)
				{
					if ((v[d][j].to == c) && (v[d][j].cost > e))
					{
						v[d][j].cost = e;
						hit = true;
					}
				}

				if (!hit) v[d].push_back(edge(c, e));

				//v[c].push_back(edge(d, e));
				//v[d].push_back(edge(c, e));
				
				//if ((v[c][d] > e) || (v[d][c] > e))
				//{
				//	v[c][d] = v[d][c] = e;
				//	wFloyd(v);
				//}
			}
			else
			{
				int a, b;

				cin >> a >> b;

				--a; --b;

				int cost = dijkstra(a, b, n, v);

				if (cost == INF)
				{
					cout << -1 << endl;
				}
				else
				{
					cout << cost << endl;
				}

				//if (v[a][b] == INF)
				//{
				//	cout << -1 << endl;
				//}
				//else
				//{
				//	cout << v[a][b] << endl;
				//}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int r, c, k; cin >> r >> c >> k;
  vector<vector<ll>> V(r, vector<ll>(c));
  rep(i, k) {
    int r, c; ll v;
    cin >> r >> c >> v;
    r--; c--;
    V[r][c] = v;
  }
  vector<vector<ll>> dp(r+1, vector<ll>(c+1));
  rep(i, r) {
    vector<vector<ll>> dp2(c+1, vector<ll>(4));
    rep(j, c+1) {
      dp2[j][0] = dp[i][j];
      if(j) dp2[j][1] = dp[i][j]+V[i][j-1];
    }
    rep(j, c) {
      rep(k, 4) {
        dp2[j+1][k] = max(dp2[j][k], dp2[j+1][k]);
        if(k+1<4) dp2[j+1][k+1] = max(dp2[j][k]+V[i][j], dp2[j+1][k+1]);
      }
    }
    rep(j, c+1) {
      dp[i+1][j] = max({dp2[j][0], dp2[j][1], dp2[j][2], dp2[j][3]});
    }
  }
  cout << dp[r][c] << endk;
  return 0;
}


Measured memory_bytes: 144428
import std.stdio;
import std.conv;
import std.string;

void main()
{
  string s = chomp(readln()); // ??????????????????
  int x = to!int(s.split(" ")[0]);
  int y = to!int(s.split(" ")[1]);
  write(x*y);
  write(" ");
  writeln(2*x+2*y);
}

Measured memory_bytes: 2476
N = int(input())
L=[0]*N
for x in range(1,200):
    for y in range(x,200):
        for z in range(y,200):
            f=x**2+y**2+z**2+x*y+y*z+z*x
            if f<=N:
                #print(f,x,y,z)
                if x==y==z:
                    L[f-1]+=1
                    #print(f,x,y,z)
                elif x!=y and y!=z and y!=z:
                    L[f-1]+=6
                else:
                    L[f-1]+=3
                    #print(f,x,y,z)
for i in range(N):
    print(L[i])

Measured memory_bytes: 69068
n=int(input())
h=list(map(int,input().split()))
x=[]
c=0
if n==1:print(0)
else:
    for i in range(n-1):
        if h[i]>=h[i+1]:
            c+=1
            x.append(c)
        else:
            c=0
            x.append(c)
    print(max(x))

Measured memory_bytes: 15020
N=int(input())
A=list(map(int,input().split()))
su=0
mi=float("inf")
micount=0
for i in range(N):
    su=su+abs(A[i])
    if A[i]<0:
        micount=micount+1
    if mi>abs(A[i]):
        mi=abs(A[i])
if micount%2==1:
    su=su-2*mi
print(su)

Measured memory_bytes: 64752
# -*- coding: utf-8 -*-
import sys


def assignColor():
    for i in range(n):
        if C[i] == -1:
            #BFS(i)
            DFS(i)

def BFS(start):
    global C
    Q = [start]
    C[start] = start

    while len(Q) != 0:
        u = Q.pop(0)
        v = [i for i in G[u] if C[i] == -1] # v := ??£??\???????????????????????¢?´¢??????????????????
        
        for i in v:
            Q.append(i)
            C[i] = C[start]

#@profile
def DFS(start):
    S = [start]
    C[start] = start
    while len(S) != 0:
        u = S.pop(0)
        for i in G[u]:
            if C[i] == -1:
                C[i] = start
                S.append(i)

if __name__ == "__main__":
    _input = sys.stdin.readlines()
    n, m = list(map(int, _input[0].split()))
    G = [[] for i in range(n)]
    C = [-1]*n
    
    for i in range(m):
        s, t = list(map(int, _input[i+1].split()))
        G[s].append(t)
        G[t].append(s)
    assignColor()
    q = int(_input[m+1])
    for i in range(q):
        s, t = list(map(int, _input[m+i+2].split()))
        if C[s] == C[t]:
            print("yes")
        else:
            print("no")
            

Measured memory_bytes: 41016
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)


def main():
    q = I()
    aa = [LI() for _ in range(q)]

    bt = aa[0][2]
    m = 2 ** 20
    c = collections.defaultdict(int)
    lq = [inf]
    rq = [inf]
    c[-inf] = 1
    c[inf] = 1
    x = aa[0][1]
    c[x] = 1
    xl = 0
    lc = 0
    xr = 0
    rc = 0
    r = []
    for t in aa[1:]:
        if t[0] == 2:
            r.append('{} {}'.format(x, xl+xr+bt))
        else:
            _,a,b = t
            bt += b
            if a == x:
                c[x] += 1
                continue
            c[a] += 1
            if c[a] == 1:
                if a < x:
                    heapq.heappush(lq,-a)
                else:
                    heapq.heappush(rq,a)
            xc = c[x]
            if a < x:
                xl += x - a
                lc += 1
                t = xl + xr
                nx = -lq[0]
                nc = c[nx]
                s = x - nx
                nt = xl - lc * s + xr + (rc+xc) * s
                if nt <= t:
                    xl -= lc * s
                    xr += (rc+xc) * s
                    lc -= nc
                    rc += xc
                    heapq.heappush(rq,x)
                    x = nx
                    heapq.heappop(lq)
            else:
                xr += a - x
                rc += 1
                t = xl + xr
                nx = rq[0]
                nc = c[nx]
                s = nx - x
                nt = xl + (lc+xc) * s + xr - rc * s
                if nt < t:
                    xl += (lc+xc) * s
                    xr -= rc * s
                    lc += xc
                    rc -= nc
                    heapq.heappush(lq,-x)
                    x = nx
                    heapq.heappop(rq)

    return '\n'.join(r)


print(main())



Measured memory_bytes: 68948
#include<iostream>
using namespace std;
int cnt=0,s;
void kumiawase(int i,int n,int ALL){
    for(;i<10;i++){
        if(n==1){
            if(s==ALL+i){
                cnt++;
            }
            continue;
        }
        kumiawase(i+1,n-1,ALL+i);
    }
}

int main()
{
    int n,i=0;
    while(cin>>n>>s){
        if(n==0&&s==0) break;
        if(i==50) break;
        kumiawase(0,n,0);
        cout<<cnt<<endl;
        cnt=0;
        i++;
    }
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main()
{
    int a,b;
    cin >>a>>b;
    if (a==b)
    {
        cout <<"Draw";
    }
    else if (a==1)
    {
        cout <<"Alice";
    }
    else if (b==1)
    {
        cout <<"Bob";
    }
    else if (a>b)
    {
        cout <<"Alice";
    }
    else if (b>a)
    {
        cout <<"Bob";
    }
    return 0;
}


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

double a, b, x;

void init() {
	scanf("%lf%lf%lf", &a, &b, &x); 
	return ;
}

void solve() {
	double V = a * a * b, h, xx;
	if(x == V / 2) {
		printf("%.10lf", atan(a/b)*180.0/3.14159265358979323);
	}
	if(x < V / 2) {
		h = 2.0 * x / a / b;
		printf("%.10lf", 90.0-atan(h/b)*180.0/3.14159265358979323);
	}
	if(x > V / 2) {
		xx = x - V / 2;
		h = 2.0 * xx / a / a;
		printf("%.10lf", 90.0-atan(a/(b-h))*180.0/3.14159265358979323);
	}
	return ;
}

int main() {
	init();
	solve();
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		
		int n=s.nextInt();
		int[]v=new int[n];
		int[]a=new int[n];
		int[]b=new int[n];
		Arrays.setAll(v,i->s.nextInt()-1);
		Arrays.setAll(a,i->i+1);
		Arrays.setAll(b,i->n-i);
		
		for(int i=1;i<n;++i) {
			for(int j=v[i];j<n;++j)
				a[j]+=i;
			for(int j=v[i];j>=0;--j)
				b[j]+=i;
		}
		
		System.out.println(Arrays.stream(a).mapToObj(String::valueOf).collect(Collectors.joining(" ")));
		System.out.println(Arrays.stream(b).mapToObj(String::valueOf).collect(Collectors.joining(" ")));
	}
}


Measured memory_bytes: 43816
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;

class Main{
        public static void main(String args[]){
                Scanner sc = new Scanner(System.in);
                String[] s = new String[3];
                for(int i=0;i<3;i++){
                        s[i] = sc.next();
                }
                char[] c = new char[3];
                for(int i=0;i<3;i++){
                        c[i] = s[i].charAt(i);
                }
                for(int i=0;i<3;i++){
                        System.out.print(c[i]);
                }
        }
}


Measured memory_bytes: 21844
import numpy as np

a = np.zeros((3,3))
for i in range(3):
    a[i] = np.asarray(input().split(), dtype=np.int32)

n = int(input())

for i in range(n):
    a[a == int(input())] = 0

for i in range(3):
    if a[i][0] == 0 and a[i][1] == 0 and a[i][2] == 0:
        print("Yes")
        break
    if a[0][i] == 0 and a[1][i] == 0 and a[2][i] == 0:
        print("Yes")
        break
    if i == 2:
        if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
            print("Yes")
            break
        elif a[2][0] == 0 and a[1][1] == 0 and a[0][2] == 0:
            print("Yes")
            break
        else:
            print("No")


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

void solve(){
    string str;
    cin >> str;

    int n = str.size() - 1;
    ll ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        string s = {str[0]};
        for (int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                ans += stol(s);
                s = {str[j+1]};
            } else {
                s += str[j+1];
            }
        }
        ans += stol(s);
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m,k;
  cin >> n >> m >> k;
  string s[n];
  rep(i,n) R s[i];
  int ans=0;
  rep(t,1<<n) {
    rep(r,1<<m) {
      int c=0;
      rep(i,n) {
        rep(j,m) {
          if(t&(1<<i)) continue;
          if(r&(1<<j)) continue;
          if(s[i][j]=='#') c++;
        }
      }
      if(c==k) ans++;
    }
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3652
import re

def main():
    s = input().replace("?", ".")
    t = input()
    ans = []

    for i in range(len(s)-len(t)+1):
        if not re.match(s[i:i+len(t)], t):
            continue
        tmp = (s[:i] + t + s[i+len(t):]).replace(".", "a")
        ans.append(tmp)

    if not ans:
        print("UNRESTORABLE")
    else:
        print(min(ans))

if __name__ == "__main__":
    main()

Measured memory_bytes: 9824
#include <stack>
#include <stdio.h>
#include <string.h>

typedef struct {
    int left;
    int right;
    int area;
} POND;

int main() {
    std::stack<int> S1;
    std::stack<POND> S2;
    char buf[20000 + 1];
    scanf("%s", buf);
    int right, left, area;
    for (int i = 0; i < strlen(buf); i++) {
        // printf("%c\n", buf[i]);
        if (buf[i] == '\\') {
            S1.push(i);
        } else if (buf[i] == '/') {
            if (S1.empty()) {
                continue;
            }
            left = S1.top();
            S1.pop();
            right = i;
            area = i - left;
            while (!S2.empty() && S2.top().left > left) {
                area += S2.top().area;
                S2.pop();
            }
            S2.push({left, right, area});
        } else {
            // do nothing
        }
    }
    int cnt = 0;
    std::stack<int> S3;
    while (!S2.empty()) {
        area = S2.top().area;
        S2.pop();
        cnt += area;
        S3.push(area);
    }
    printf("%d\n", cnt);
    printf("%d", S3.size());
    while (!S3.empty()) {
        printf(" %d", S3.top());
        S3.pop();
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2844
//AUTHOR:BlackBox Inc.//
#include<bits/stdc++.h>
#include<unordered_map>
#include<tr1/unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define endl "\n"
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace std::tr1;

int main()
{
#ifdef RAHUL
    freopen("input.txt","r",stdin);
#endif
int n;
cin>>n;
std::vector<int> v;
std::vector<int> v1;

for (int i = 0; i < n; ++i)
{
	/* code */
	int x;
	cin>>x;
	v.push_back(x);
	v1.push_back(x);
}
sort(v.begin(),v.end(),greater<int>());
int j=0;
for (int i = 0; i < n; ++i)
{
	/* code */
	if(v[j]!=v1[i]){
		cout<<v[j]<<endl;
	}
	else{
		j++;
		cout<<v[j]<<endl;
		j--;
	}
	
}

return 0;
}

Measured memory_bytes: 3436
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;

int main() {
	ll x;
	cin >> x;
	ll k = x / 11;
	x %= 11;
	ll ans = k * 2;
	if (x > 0) {
		if (k % 2 == 0) {
			if (x <= 6) ans++;
			else ans += 2;
		}
		else {
			if (x <= 5) ans++;
			else ans += 2;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main()
{
    long long a, b, x;
    cin >> a >> b >> x;
    if (a == 0)
        cout << b / x + 1 << endl;
    else
        cout << b / x - (a - 1) / x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n,k;cin>>n>>k;
  vector<ll> x_plus(1),x_minus(1);
  ll temp;
  rep(i,n){
  	cin>>temp;
  	if(temp>=0){
  		x_plus.pb(temp);
  	}else{
  		x_minus.pb(-1*temp);
  	}
  }
  sort(all(x_minus));

  ll ans=INF;
  rep(i,x_plus.size()){
	  if(k-i<x_minus.size()){
	  	if(i==0){
	  		ans=min(ans,x_minus[k]);
	  	}else if(i==x_plus.size()-1&&i>k){
	  		ans=min(ans,x_plus[i]);
	  	}else{
	  		ans=min(ans,2*x_plus[i]+x_minus[k-i]);
  			ans=min(ans,x_plus[i]+2*x_minus[k-i]);
	  	}
	  }
  }

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

Measured memory_bytes: 1656
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        if (n < 105) {
            System.out.println(0);
        } else if (n < 135) {
            System.out.println(1);
        } else if (n < 165) {
            System.out.println(2);
        } else if (n < 189){
            System.out.println(3);
        } else if ( n < 195){
            System.out.println(4);
        } else {
            System.out.println(5);
        }
    }

}

Measured memory_bytes: 21844
N = int(input())
S = input()
r = S.count("R")
g = S.count("G")
b = S.count("B")
ans = r*g*b
for i in range(0,N-2) :
    for j in range(i+1,N-1) :
        k = j + (j - i)
        if k < N :
            if (S[i] != S[j]) and (S[i] != S[k]) and (S[j] != S[k]) :
                ans -= 1
print(ans) 

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

int main() {
    int a,b,c; scanf("%d %d %d", &a, &b, &c);

    if (a == b && a != c) {
        puts("Yes");
    } else if (a == c && a != b) {
        puts("Yes");
    } else if (b == c && a != b) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> trp;
typedef vector<ll> vi;
typedef vector<pll> vp;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define pob         pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define sc3(a,b,c)  cin>>a>>b>>c
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"Yes"<<endl
#define prN         cout<<"No"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define	mp3(a,b,c)  make_pair(a,make_pair(b,c))
#define se          second
#define fi          first 
#define sse         second.second
#define sfi         second.first
#define soA         sort(A+1,A+1+n)
#define so(A,n)     sort(A+1,A+1+n)
#define sov(v)      sort(all(v))
#define sovr(v)     sort(all(v),greater<ll>())
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	sc2(m,k);
	f1(i,1e5){
		if(i*8/100==m and i*10/100==k)rpr(i);
	}
	pr(-1);
	
	
	
	
	
	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	if(fopen("locin.txt", "r"))INPUT;
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	} 		
}

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

asum = 0
for ai in a:
    asum += ai
msum = 0
for ai in a:
    if ai>=(asum/(4*m)):
        msum += 1
if msum>=m:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>W(N);
  vector<int>sum(N);
  int wa=0;
  for(int i=0;i<N;i++){
    cin>>W.at(i);
    wa=wa+W.at(i);
    sum.at(i)=wa;
  }
  int ans=sum.at(N-1);
  for(int i=0;i<N;i++){
    ans=min(ans,abs(sum.at(N-1)-2*sum.at(i)));
  }
  cout<<ans<<endl;
}

    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  ll ans=0;
  for(int bit=0; bit<60; bit++){
    int ones=0;//立っているビットの数
    rep(i,n){
      if(a[i]&1ll<<bit) ones++;
    }
  ans = (ll(ans) + (1ll << bit) % MOD * ones % MOD * (n-ones)) % MOD;
  }
  cout << ans << endl;
  return 0;
}


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

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

  int num = number.length() - 1;

  //cout << num << endl;

  if (number[num] == '2' || number[num] == '4' || number[num] == '5' || number[num] == '7' || number[num] == '9')
  {
    cout << "hon" << endl;
  }

  if (number[num] == '0' || number[num] == '1' || number[num] == '6' || number[num] == '8')
  {
    cout << "pon" << endl;
  }

  if (number[num] == '3')
  {
    cout << "bon" << endl;
  }
}

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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int K;
  cin >> K;
  char X = S.at(K - 1);
  for(int i = 0; i < N; i++){
    if(S.at(i) != X) S.at(i) = '*';
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, m;
vector<int> vec[1010];
bool bl[1010];
bool g[1010][1010];
vector<int> ve;
vector<int> ans;

bool dfs(int v, int p) {
	bl[v] = true;
	for (int i = 0; i < (int)vec[v].size(); i++) {
		if (vec[v][i] == p) {
			ve.push_back(v);
			return true;
		}
		if (bl[vec[v][i]])continue;
		if (dfs(vec[v][i], p)) {
			ve.push_back(v);
			return true;
		}
	}
	return false;
}

signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		vec[a].push_back(b);
		g[a][b] = true;
	}
	for (int i = 1; i <= n; i++) {
		fill(bl, bl + n + 1, false);
		if (dfs(i, i)) break;
	}
	if (ve.empty()) {
		cout << -1 << endl;
		return 0;
	}
	reverse(all(ve));
	int s = 0;
	bool bl2 = false;
	for (int i = 0; i < (int)ve.size(); i++) {
		for (int j = (int)ans.size() - 1; j >= 0; j--) {
			if (g[ve[i]][ans[j]]) {
				s = j;
				bl2 = true;
				break;
			}
		}
		ans.push_back(ve[i]);
		if (bl2)break;
		int k = i + 1;
		for (int j = i + 1; j < (int)ve.size(); j++) {
			if (g[ve[i]][ve[j]])k = j;
		}
		i = k - 1;
	}
	cout << (int)ans.size() - s << endl;
	for (int i = s; i < (int)ans.size(); i++)cout << ans[i] << endl;
}

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


int main(void){

  int N;
  int i, k, len[2];
  int sum, up;

  char m[101], n[101];
  char x[2][101];
  char result[101];


  scanf("%d", &N);
  while(N>0){
    scanf("%s", m);
    scanf("%s", n);

    if(strlen(m)>80 || strlen(n)>80){
      printf("overflow\n");
    }
    else{
      memset(result, '\0', 101);
      memset(x[0], '\0', 101);
      memset(x[1], '\0', 101);
      
      len[0] = strlen(m);
      for(i=0; i<len[0]+1;  i++){
	x[0][i]=m[len[0]-1-i];
      }
      len[1] = strlen(n);
      for(i=0; i<len[1]+1; i++){
	x[1][i] = n[len[1]-1-i];
      }
   
      
      if(len[0]<len[1]) k=0;
      else k=1;
      
      up=0;
      for(i=0; i<len[k]; i++){
	sum = (x[0][i]-48)+(x[1][i]-48)+up;
	result[i]=sum%10+48;
	if(sum>=10) up=1;
	else up=0;
      }
      k=(k+1)%2;
      for(; i<len[k]; i++){
	sum = x[k][i]-48+up;
	result[i]=sum%10+48;
	if(sum>=10) up=1;
	else up=0;
      }
      
      if(up==1){
	result[i]=up+48;
      }
      
      k=strlen(result);
      if(k>80){
	printf("overflow\n");
      }
      else{
	for(i=0; i<k+1; i++){
	  m[i] = result[k-1-i];
	  //printf("%c", result[i]);
	}
	m[k]='\0';
	printf("%s\n", m);
	//printf("\n");
      }
    }

    N--;
  }
  
  return(0);
}



Measured memory_bytes: 2040
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>


using namespace std;

int main(){
    int N,Q;
    cin >> N >> Q;
    string s;
    cin >> s;
    int l[Q];
    int r[Q];
    for(int i=1;i<=Q;i++)cin >> l[i] >> r[i];

    int dp[N];
    
    dp[0] =0;
    for(int i=1;i<N;i++){
        if(s[i-1]=='A'&& s[i]=='C')dp[i]=dp[i-1]+1;
        else dp[i]=dp[i-1];

        //cout << dp[i];

        
    }

    for(int q=1;q<=Q;q++)cout << dp[r[q]-1]-dp[l[q]-1] << endl;
    

    

}


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	string s, t, t2;
	int best = 100, cnt;
	
	cin>>s;
	
	for (char c = 'a'; c <= 'z'; ++c)
	{
		cnt = 0;
		t = s;
		while (count(t.begin(), t.end(), t[0]) != t.size())
		{
			t2 = "";
			for (int i = 0; i < t.size() - 1; ++i)
			{
				if (t[i + 1] == c)
					t2 += c;
				else t2 += t[i];
			}
			t = t2;
			++cnt;
		}
//		cout<<c<<' '<<t<<' '<<cnt<<endl;
		best = min(best, cnt);
	}
	
	cout<<best<<'\n';
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int M1,M2,D1,D2;
  
  scanf("%d",&M1);
  scanf("%d",&D1);
  scanf("%d",&M2);
  scanf("%d",&D2);
  
  if((D2 == 1)&&(M1 + 1 == M2)){
  if(D1 == 31){
    if((M1%2 == 1)&&(M1 < 8)){
      printf("1\n");
    }
    else if((M1%2 == 0)&&(M1 > 7)&&(M1 < 13)){
      printf("1\n");
      }
    else{
      printf("0\n");
    }
  }
  else if(D1 == 30){
    if(((M1%2 == 0)&&(M1 < 7))||((M1%2 == 1)&&(M1 > 8)&&(M1 < 12))){
      printf("1\n");
    }
    else{
      printf("0\n");
    }
  }
  else if((D1 == 28)&&(M1 == 2)){
    printf("1\n");
  }
  else{
    printf("0\n");
  }
  }
  else{
    printf("0\n");
  }
  
  return 0;
}

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

long d[3333] = {1};
int main() {
    int n, s, p = 998244353;
    cin >> n >> s;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        for(int j = s; j >= 0; j--) {
            d[j] += d[j];
            if(j >= a)
                d[j] += d[j - a];
            d[j] %= p;
        }
    }
    cout << d[s] << endl;
    return 0;
}


Measured memory_bytes: 3660
import java.util.Scanner;
import java.lang.Math;

class Main {
    public static void main(String[] args) {
        // input
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int X = Math.max(2 * A - 1, Math.max(A + B, 2 * B - 1));
        scanner.close();
        // output
        System.out.println(X);
        System.out.flush();
    }
}

Measured memory_bytes: 23124
n = int(input())
ans = 0
if 100 <= n <= 111:
  ans = 111
elif 112 <= n <= 222:
  ans = 222
elif 223 <= n <= 333:
  ans = 333
elif 334 <= n <= 444:
  ans = 444
elif 445 <= n <= 555:
  ans = 555
elif 556 <= n <= 666:
  ans = 666
elif 667 <= n <= 777:
  ans = 777
elif 778 <= n <= 888:
  ans = 888
elif 889 <= n <= 999:
  ans = 999
print(ans)

Measured memory_bytes: 3064
/**
*   Bismillahir Rahmanir Rahim.
*   Imtiaz_rafi
*   PCIU, CHITTAGONG
**/
#include<bits/stdc++.h>
using namespace std;
#define speed() ios::sync_with_stdio(0);cin.tie(0);
#define file() freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define rep(i,a) for(ll i=0;i<a;i++)
#define rep1(i,begin,end) for(ll i=begin;i<=end;i++)
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define all(v)   v.begin(),v.end()
#define rall(v)   v.rbegin(),v.rend()
#define pb push_back
#define pf push_front
#define mp make_pair
#define pi acos(-1)
// bitshift (1LL<<(3)) *2^3
typedef long long int ll;
typedef vector<ll>vi;
typedef map<ll,ll>mi;
typedef pair<ll,ll>pll;
typedef vector<pll> vll;
typedef set<ll>st;
typedef set<char>sc;
ll dx[] = {-1,+1,0,0,+1,-1,+1,-1};
ll dy[] = {0,0,-1,+1,+1,+1,-1,-1};
const ll mx = 1e5+123;
const ll MOD = 1e9+7;

template <class T> T power(T a,T b){a%=MOD;if(!a) return 0;T p=1;while(b>0){if(b&1){p*=a;p%=MOD;}a*=a;a%=MOD;b=b>>1;}return p;}
template <class T> void print(vector<T> &v){for(T u:v){cout<<u<<" ";}cout<<endl;}
template <class T> T gcd(T a, T b){return (b!=0?gcd<T>(b,a%b):a);}
template <class T> T lcm(T a, T b){return (a/gcd<T>(a,b)*b);}

ll BS(ll l,ll r,ll a[],ll k){ll mid,i=-1;while(l<=r){mid=(l+r)>>1;if(a[mid]==k){return i=mid;/*r=mid-1;*/}if(a[mid]<k) l=mid+1;if(a[mid]>k) r=mid-1;}return i;}

int main()
{
    speed();
    ll t,a,b,c,i,d;
    cin>>a>>b>>c;
    if(a%b!=0)
    {
        d=((a/b)+1)*c;
        cout<<d<<endl;
    }
    else
        {
            d=((a/b))*c;
            cout<<d<<endl;
        }




return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<int> V(N);
  for (int i = 0; i < N; i++) cin >> V.at(i);

  int ans = 0;
  for (int l = 0; l <= min(K, N); l++) {
    for (int r = 0; l + r <= min(K, N); r++) {
      vector<int> v;
      for (int i = 0; i < l; i++) v.push_back(V.at(i));
      for (int i = 0; i < r; i++) v.push_back(V.at(N - 1 - i));
      sort(v.begin(), v.end());
      int sum = 0;
      for (int i = 0; i < v.size(); i++)
        if (v.at(i) > 0 || i >= K - r - l) sum += v.at(i);
      ans = max(ans, sum);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#define MOD 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
int a,b;
int cntxor(int k){
    int s=pow(2,k);
    int x;
    if(a<s)x=0;
    else x=(a-1-s+1)/(2*s)*s+min(s,(a-1-s+1)%(2*s));
    int y;
    if(b<s)return 0;
    else{
        y=(b-s+1)/(2*s)*s+min(s,(b-s+1)%(2*s));
    }
    int c=y-x;
    return c%2==0?0:s;
}
signed main(){
    cin>>a>>b;
    int ans=0;
    for(int i=0;i<40;i++){
        ans+=cntxor(i);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;
bool chk(ll x,ll y,ll z)
{
    ll a[3];
    a[0]=x,a[1]=y,a[2]=z;
    sort(a,a+3);
    if(a[0]+a[1]>a[2] && a[0]!=a[1] && a[1]!=a[2])
    {
        return true;
    }
    return false;
}
int main()
{
    ft
    ll t,i,j,k,n,m,l=0,r;
    cin>>n;
    ll a[n+1];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            for(k=j+1;k<n;k++)
            {
                if(chk(a[i],a[j],a[k])==true)
                {
                    l++;
                }
            }
        }
    }
    cout<<l<<"\n";
    return 0;
}



Measured memory_bytes: 3652
import math
N = 10**5+1
numbers = [i for i in range(2,N+1)]
primes = []
x = numbers[0]
while x <= math.ceil(math.sqrt(N))+1:
    x = numbers[0]
    primes.append(x)
    numbers = [num for num in numbers if num%x != 0]
pset = set(primes) | set(numbers)
oddPrimes = [number for number in pset if (number+1)//2 in pset]
oddPrimes.sort()
#print(oddPrimes)
cumsum = [0 for _ in range(N+1)]
j=0
length = len(oddPrimes)
nextOP = oddPrimes[j]
for i in range(1,N+1):
    if i != nextOP:
        cumsum[i] = cumsum[i-1]
    else:
        cumsum[i] = cumsum[i-1] + 1
        if j+1 < length:
            j += 1
            nextOP = oddPrimes[j]
        else:
            nextOP = -1
Q = int(input())
for _ in range(Q):
    l,r = map(int,input().split())
    print(cumsum[r]-cumsum[l-1])

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

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

const int maxn =100+10;

int H,W;
char field[maxn][maxn];

void dfs(int x,int y,char tree){
    field[x][y]='.';

    for(int i=0;i<4;i++){
        int nx=x+dx[i];
        int ny=y+dy[i];

        if(nx>=0&&nx<H&&ny>=0&&ny<W&&field[nx][ny]==tree){
            dfs(nx,ny,tree);
        }
    }
}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    while(cin>>H>>W&&H&&W){
        for(int i=0;i<H;i++){
            cin>>field[i];
        }

        int cnt=0;

        for(int x=0;x<H;x++){
            for(int  y=0;y<W;y++){
                if(field[x][y]!='.'){
                    dfs(x,y,field[x][y]);
                    cnt++;
                }
            }
        }

        cout<<cnt<<endl;
    }

    return 0;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;
 
const int N=1050005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
inline void read(int &x){
	x=0;char ch=getchar(),rev=0;
	while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=rev?-x:x;
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}
int w,h,n,cnt,ans,x[N],y[N],yy[N],sta[N][2],g[N][2],top[2];
int p[N<<1],flag[N<<1];
 
inline void ins(int x){if(x>=1&&x<h) yy[++cnt]=x;}
inline int get(int y){return lower_bound(yy+1,yy+cnt+1,y)-yy;}
inline void add(int k,int b){p[k]+=b;flag[k]+=b;}
inline void push(int k){
	if(!flag[k]) return;
	add(ls,flag[k]);add(rs,flag[k]);
	flag[k]=0;
}
void ch(int l,int r,int x,int y,int k,int b){
	if(x<=l&&r<=y){add(k,b);return;}
	push(k);
	int mid=l+r>>1;
	if(x<=mid) ch(l,mid,x,y,ls,b);
	if(y>mid) ch(mid+1,r,x,y,rs,b);
	p[k]=max(p[ls],p[rs]);
}
void build(int l,int r,int k){
	if(l==r){p[k]=-yy[l];return;}
	int mid=l+r>>1;
	build(l,mid,ls);build(mid+1,r,rs);
	p[k]=max(p[ls],p[rs]);
}
void solve(int mid){
	clr(flag,0);clr(top,0);cnt=0;
	ins(1);ins(h-1);
	for(int i=1;i<=n;i++){
		ins(y[i]);
		ins(y[i]-1);
		ins(y[i]+1);
	}
	sort(yy+1,yy+cnt+1);
	cnt=unique(yy+1,yy+cnt+1)-yy-1;
	if(!cnt){printf("%d\n",(w+h)*2);exit(0);}
	build(1,cnt,1);
	for(int i=1;i<=cnt;i++)
		g[i][0]=mid,g[i][1]=w-mid;
	for(int i=1;i<=n;i++){
		if(!y[i]||y[i]==h) continue;
		if(x[i]<=mid) gmin(g[get(y[i])][0],mid-x[i]); else gmin(g[get(y[i])][1],x[i]-mid);
	}
	for(int i=1;i<=cnt;i++){
		for(int x=0;x<2;x++){
			int last=i;
			ch(1,cnt,i,i,1,g[i][x]);
			while(top[x]&&g[sta[top[x]][x]][x]>g[i][x]){
				int l=sta[top[x]-1][x]+1,r=sta[top[x]][x];
				ch(1,cnt,l,r,1,g[i][x]-g[r][x]);
				top[x]--;
			}
			sta[++top[x]][x]=i;
		}
		gmax(ans,(p[1]+yy[i]+2)*2);
	}
}
 
int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	scanf("%d%d%d",&w,&h,&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&x[i],&y[i]);
	solve(w/2);
	for(int i=1;i<=n;i++)
		swap(x[i],y[i]);
	swap(w,h);solve(w/2);
	printf("%d\n",max(ans,max(w,h)*2+2));
	return 0;
}

Measured memory_bytes: 37120
import java.util.*;

public class Main{

public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int[] mountains = new int[10];

for(int i=0; i<10; i++){
mountains[i] = sc.nextInt();
}

Arrays.sort(mountains);
System.out.println(mountains[9]);
System.out.println(mountains[8]);
System.out.println(mountains[7]);
}


}

Measured memory_bytes: 26176
#include <stdio.h>
#include <stdlib.h>
int comp(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}
int main() {
  int n,x[200000],y[200000],i;
  scanf("%d",&n);
  for (i = 0;i<n;i++) {
    scanf("%d",&x[i]);
    y[i]=x[i];
  }
  qsort(x, n, sizeof(int), comp);
  for (i = 0;i < n;i++) {
    if (y[i]<=x[n/2-1]) {
      printf("%d\n",x[n/2]);
    } else {
      printf("%d\n",x[n/2-1]);
    }
  }
  return 0;
}

Measured memory_bytes: 3704
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
using namespace std;
const int MAXN=200005;
int n, t=0;
struct work{
	int l, l1;
};
work w[MAXN];
bool cmp(work a, work b)
{
	return a.l1<b.l1;
}
int main()
{
	cin>>n;
	for(int i=1; i<=n; i++)
		cin>>w[i].l>>w[i].l1;
	sort(w+1, w+n+1, cmp);
	for(int i=1; i<=n; i++)
	{
		t+=w[i].l;
		if(t>w[i].l1)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
using namespace std;
typedef long long int ll;
const ll INF = 1LL << 50;
struct edge{int from,to;ll cost;};
int N,M;
edge es[2002];
ll dist[1001];
int main(){
  cin >> N >> M;
  for(int i=0;i<M;i++){
    int a,b;
    ll c;
    cin >> a >> b >> c;
    c=-c;
    a--;b--;
    es[i].from=a; es[i].to=b;es[i].cost=c;
  }
  for(int i=0;i<N;i++)dist[i]=INF;
  dist[0]=0;
  for(int i=0;i<N-1;i++){
    for(int j=0;j<M;j++){
      edge e;
      e=es[j];
      if(dist[e.from] ==INF)continue;
      if(dist[e.to] > dist[e.from] + e.cost)
	dist[e.to] = dist[e.from] + e.cost; 
    }
  }
  ll ans=dist[N-1];

  bool negative[1001];
  for(int i=0;i<N;i++)negative[i]=false;
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      edge e;
      e=es[j];
      if(dist[e.from] ==INF)continue;
      if(dist[e.to] > dist[e.from] + e.cost){
	dist[e.to] = dist[e.from] + e.cost;
	negative[e.to]=true;
      }
      if(negative[e.from]==true)negative[e.to]=true;
    }
  }

  if(negative[N-1])cout << "inf" << endl;
  else cout << -ans << endl;
  return 0;
}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    ll n; cin >> n;
    ll ans = 1;

    for(ll i = 1; i <= n; i++){
        ans *= i;
        ans %= ll(1e9 + 7);
    }cout << ans;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	
  public static void main(String[] args) {
      
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();

    int kei;

    kei = n * a;

    if(kei > b) {
        System.out.println(b);
    } else {
        System.out.println(kei);
    }
    
  }


}

Measured memory_bytes: 21844
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let N: u32 = read();
    let A: u32 = read();
    let B: u32 = read();

    let mut SUM: u32 = 0;

    for i in 0..N+1 {
        let mut num = i;
        let mut dig: u32;
        let mut sum: u32 = 0;
        while num != 0 {
            dig = num % 10;
            sum = sum + dig;
            num = num / 10;
        }

        if A <= sum {
            if sum <= B {
                SUM += i;
            }
        }
    }

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


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            String[] input;

            input = in.readLine().split(" ");
            int n = Integer.parseInt(input[0]);
            int m = Integer.parseInt(input[1]);
            int l = Integer.parseInt(input[2]);

            int[][] A = new int[n][m];
            int[][] B = new int[m][l];

            for (int i = 0; i < n; i++) {
                String[] line = in.readLine().split(" ");
                for (int j = 0; j < m; j++) {
                    A[i][j] = Integer.parseInt(line[j]);
                }
            }
            for (int i = 0; i < m; i++) {
                String[] line = in.readLine().split(" ");
                for (int j = 0; j < l; j++) {
                    B[i][j] = Integer.parseInt(line[j]);
                }
            }

            long[][] C = new long[n][l];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < l; j++) {
                    // C[i][j]を求める
                    long cij = 0;
                    for (int k = 0; k < m; k++) {
                        cij += A[i][k] * B[k][j];
                    }
                    C[i][j] = cij;
                }
            }

//            StringBuilder out = new StringBuilder();
            for (int i = 0; i < n; i++) {
                List<String> sarr = Arrays.stream(C[i]).mapToObj(String::valueOf).collect(Collectors.toList());
//                out.append(String.join(" ", sarr));
//                out.append("\n");
                System.out.println(String.join(" ", sarr));
            }
//            System.out.print(out);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.exit(0);
    }
}



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

std::string s;

int main(){
 std::cin >> s;
 std::sort(s.begin(), s.end());
 char start = 'a';
 std::vector<int> alp(26, 0);

 for(int i = 0; i < s.size(); ++i){
  for(int j = 0; j < 26; ++j){
   if(start+j == s[i]){
    alp[j] = 1;
   }
  }
 }
 int count = 0;
 for(int i = 0; i < 26; ++i){
  if (alp[i] == 1){
    count++;
  }
 }
 if (count == 26){
  std::cout << "None" << std::endl;
  return 0;
 }
 for(int i = 0; i < 26; ++i){
  if (alp[i] == 0){
   std::cout << static_cast<char>(start+i) <<std::endl;
   return 0;
  }
 }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
long long RepeatSquaring(long long N, long long P){
    if (P == 0) return 1;
    if (P % 2 == 0) {
        long long t = RepeatSquaring(N, P / 2);
        return t * t;
    }
    return N * RepeatSquaring(N, P - 1);
}
int main(){
  int N,P;cin>>N>>P;
  for(int i=0;i<N;i++){
    int a;cin>>a;
    if(a%2==1){
      cout<<RepeatSquaring(2,N-1)<<endl;
      return 0;
    }
  }
  if(P==0)cout<<RepeatSquaring(2,N)<<endl;
  else puts("0");
}

Measured memory_bytes: 3592