akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <tuple>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)

int main()
{

  int H, W;
  cin >> H >> W;

  string board[110];

  bool goodx[110], goody[110];
  rep(i, 110)
  {
    goodx[i] = false;
    goody[i] = false;
  }

  rep(i, H)
  {
    cin >> board[i];
  }

  rep(i, H)
  {
    rep(j, W)
    {
      if (board[i][j] == '#')
      {
        goodx[i] = true;
        goody[j] = true;
      }
    }
  }

  rep(i, H)
  {
    if (goodx[i])
    {
      rep(j, W)
      {
        if (goody[j])
        {
          cout << board[i][j];
        }
      }
      cout << endl;
    }
  }
}

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

int main(void) {
  long long N, M;
  cin >> N >> M;
  long long A = 0;
  for (int i = 0; i < M; i++) {
    long long tmp;
    cin >> tmp;
    A += tmp;
  }
  cout << max(-1LL, N - A) << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main()
{
    // 文字列の入力
    string s;
    cin >> s;
  	if(s == "ABC")
    {
      cout <<  "ARC";
    }else if(s =="ARC")
	{
      cout << "ABC";
    }
  return 0;
 }

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
constexpr int MAX_N = 1E5;
int n, m;
int a[2 * MAX_N];
int ans;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 0; i < 2 * n; ++i)
        cin >> a[i];
    sort(a, a + 2 * n);
    int l = 0, r = n;
    while (l < r) {
        int x = (l + r) / 2;
        bool ok = true;
        for (int i = 0; i < n - x; ++i)
            if (a[2 * x + i] + a[2 * n - i - 1] < m)
                ok = false;
        if (ok)
            r = x;
        else
            l = x + 1;
    }
    for (int i = 0; i < l; ++i)
        ans = max(ans, a[i] + a[2 * l - i - 1]);
    for (int i = 0; i < n - l; ++i)
        ans = max(ans, a[2 * l + i] + a[2 * n - i - 1] - m);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 1000 + 100;
const int MAXM = 5000 + 100;
const int INF = 0x1f1f1f1f;

int n;
int f[MAXN][2];
vector<int> edg[MAXN];

void no()
{
	cout << "IMPOSSIBLE" << endl;
	exit(0);
}

void yes()
{
	cout << "POSSIBLE" << endl;
	exit(0);
}

void dfs(int x, int fa)
{
	for(int i = 0; i < edg[x].size(); i++)
		if(edg[x][i] != fa)
			dfs(edg[x][i], x);
	static int g[MAXM];
	memset(g, 31, sizeof(g));
	g[0] = 0;
	for(int i = 0; i < edg[x].size(); i++)
		if(edg[x][i] != fa)
		{
			int y = edg[x][i];
			for(int j = f[x][0]; j >= 0; j--)
				if(g[j] < INF)
				{
					int val = g[j];
					g[j] = INF;
					if(j + f[y][0] <= f[x][0])
						g[j + f[y][0]] = min(g[j + f[y][0]], val + f[y][1]);
					if(j + f[y][1] <= f[x][0])
						g[j + f[y][1]] = min(g[j + f[y][1]], val + f[y][0]);
				}
			// cerr << y << " : ";
			// for(int j = 0; j <= f[x][0]; j++)
			// 	cerr << g[j] << ' ';
			// cerr << endl;
		}
	f[x][1] = INF;
	for(int i = 0; i <= f[x][0]; i++)
		f[x][1] = min(f[x][1], g[i]);
	if(f[x][1] >= INF)
		no();
	// cerr << x << ' ' << f[x][0] << ' ' << f[x][1] << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n;
	for(int i = 2; i <= n; i++)
	{
		int x;
		cin >> x;
		edg[x].push_back(i), edg[i].push_back(x);
	}
	for(int i = 1; i <= n; i++)
		cin >> f[i][0];

	dfs(1, 0);
	yes();

	return 0;
}


Measured memory_bytes: 384
import Text.Printf

main = do
    s1 <- getLine
    s2 <- getLine
    s3 <- getLine
    
    let xs = map (\x -> read x :: Double) $ words s2
    let ys = map (\x -> read x :: Double) $ words s3
    
    printf "%.8f\n" (dist 1 xs ys)
    printf "%.8f\n" (dist 2 xs ys)
    printf "%.8f\n" (dist 3 xs ys)
    printf "%.8f\n" (distInf xs ys)

dist p xs ys = (**(1/p)) $ sum $ zipWith (\x y -> (abs $ x-y) ** p) xs ys
distInf xs ys = maximum $ map (\(x,y) -> abs $ x-y) $ zip xs ys


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

int main() {
  string s;
  cin>>s;
  int a,z;
  
  rep(i,s.size()){
    if (s[i]=='A') {
      a=i;
      break;
    }
  }
  
  rep(i,s.size()){
    if (s[s.size()-1-i]=='Z') {
      z=s.size()-1-i;
      break;
    }
  }
      
  cout<<z-a+1<<endl;
  return 0;  
    

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef long long ll;
typedef pair<ll,ll> P;
const int INF=INT_MAX / 3;
const ll LINF=LLONG_MAX / 3LL;
#define CONST 1000000007
#define EPS (1e-8)
#define PB push_back
#define MP make_pair
#define sz(a) ((int)(a).size())
#define reps(i,n,m) for(int i=(n);i<int(m);i++)
#define rep(i,n) reps(i,0,n)
#define SORT(a) sort((a).begin(),(a).end())
ll mod(ll a,ll m){return (a%m+m)%m;}
int dx[9]={0,1,0,-1,1,1,-1,-1,0},dy[9]={1,0,-1,0,1,-1,1,-1,0};
ll n,m;
int main(){
  ll x;
  cin >> x;
  ll n = sqrt(2 * x) - 1;
  while(1) {
    if(2*x<=n * (n+1)) {
      cout<<n<<endl;
      return 0;
    }
    n++;
  }
  return 0;
}


Measured memory_bytes: 256
import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Data.Array.IArray
import           Data.Array.IO
import           Data.Array.MArray

readi :: B.ByteString -> Int
readi b | Just (n, _) <- B.readInt b = n

paint :: Array Int [Int] -> IOArray Int Int -> IO ()
paint g d = do
    let (s, t) = bounds g
    forM_ [s .. t] $ \i -> do
        c <- readArray d i
        when (c == -1) $ go i i
  where
    go :: Int -> Int -> IO ()
    go c k = do
        writeArray d k c
        cs <- filterM (fmap (== -1) . readArray d) (g ! k)
        mapM_ (go c) cs

main :: IO ()
main = do
    [n, m] <- fmap readi . B.words <$> B.getLine
    mss <-
        accumArray (flip (:)) [] (0, n - 1) .
        concatMap ((\[a, b] -> [(a, b), (b, a)]) . fmap readi . B.words) <$>
        replicateM m B.getLine :: IO (Array Int [Int])
    q <- readi <$> B.getLine
    qss <-
        fmap ((\[a, b] -> (a, b)) . fmap readi . B.words) <$>
        replicateM q B.getLine
    d <- newArray (0, n - 1) (-1) :: IO (IOArray Int Int)

    paint mss d

    forM_ qss $ \(i, j) -> do
        vi <- readArray d i
        vj <- readArray d j
        if vi == vj
            then putStrLn "yes"
            else putStrLn "no"



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

bool judge(int i){
  if(i<2) return false;
  else{
    for(int j = 2; j*j <= i; j++){
      if(i%j == 0 ) return false;
    }
    return true;
  }
}

int main() {
  int x; cin >> x;
  //cout << judge(5) << endl;
  while(true){
    if(judge(x) == true) break;
    else x++;
  }
  cout << x << endl;
}


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

int main()
{
    int n,r,sum;
    cin>>n;
    sum=0;
    r=n;
    while(r>0)
    {
        sum+=(r%10);
        r/=10;
    }
    if(n%sum==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

int main(){
  int A,B,C,D,E;
  cin>>A>>B>>C;
  D=0;
  E=0;
  vector<int> V(B);
  for(int i=0;i<B;i++)
    cin>>V.at(i);
  for(int i=0;i<B;i++){
     if(V.at(i)<C)
       D++;
     if(V.at(i)>C)
       E++;
  }
     if(D>E)
       cout<<E<<endl;
  else
    cout<<D<<endl;
}


Measured memory_bytes: 256
a = int(input())
x = []
for i in range(a):
    c,d,e = map(int, input().split())#a,b,c,d or n,k
    x.append([c,d,e])
dp =[[0, 0, 0] for _ in [0]*(a+1)]
dp[0][0] = x[0][0]
dp[0][1] = x[0][1]
dp[0][2] = x[0][2]
for n in range(3):
    for i,h in enumerate(x):
        for n in range(3):
            if i !=0:
                dp[i][n] = max(dp[i-1][(n+1)%3],dp[i-1][(n+2)%3])+h[n]
        #print(dp)
#print(dp)
print(max(dp[a-1]))

Measured memory_bytes: 78808
#include <iostream>

using namespace std;

int main(void){
  int z;
  while(cin>>z,z){
    int mx=0;
    for(int x=1;x<=z;++x){
      for(int y=1;y<=z;++y){
        if(x*x*x+y*y*y<=z*z*z) mx=max(x*x*x+y*y*y,mx);
      }
    }
    cout<<z*z*z-mx<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cmath>
#include <iomanip>
const double PI = acos(-1);
using namespace std;

int main(int argc, char const *argv[])
{
	double a, b, C;
	cin >> a >> b >> C;
	C = PI * C / 180;

	double s, l, h;
	s = a * b * sin(C) / 2;
	l = a + b + sqrt(a*a + b*b - 2*a*b*cos(C));
	h = 2 * s / a;

	cout << setprecision(10) << s << endl << l << endl << h << endl;
	return 0;
}

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

typedef long long LL;
void solve(long long N, long long K, std::vector<long long> t,
           std::vector<long long> d) {
  vector<pair<LL, LL>> data;
  for (int i = 0; i < N; i++) {
    data.push_back(pair<LL, LL>(d[i], t[i]));
  }
  sort(data.begin(), data.end());
  reverse(data.begin(), data.end());

  vector<int> used(N + 1, -1);
  LL score = 0;
  for (int i = 0; i < K; i++) {
    score += data[i].first;
    if (used[data[i].second] == -1) used[data[i].second] = i;
  }
  LL maxim = 0;
  LL tps = 0;
  for (int i = 0; i <= N; i++)
    if (used[i] >= 0) tps++;
  maxim = tps * tps + score;

  int itrR = K;
  int itrL = K - 1;
  while (true) {
    while (itrR < N) {
      if (used[data[itrR].second] == -1) {
        score += data[itrR].first;
        used[data[itrR].second] = itrR;
        break;
      }
      itrR++;
    }
    while (itrL >= 0) {
      if (used[data[itrL].second] != itrL) {
        score -= data[itrL].first;
        itrL--;
        break;
      }
      itrL--;
    }
    if (itrR == N || itrL == -1) break;
    tps += 1;
    maxim = max(maxim, score + tps * tps);
  }
  cout << maxim << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> t(N);
  std::vector<long long> d(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &t[i]);
    scanf("%lld", &d[i]);
  }
  solve(N, K, std::move(t), std::move(d));
  return 0;
}


Measured memory_bytes: 3956
import math

N=int(input())
d=[0]*N
str=input().split(' ')
for i in range(0,N):
    d[i]=int(str[i])

result=0

for i in range(0,len(d)):
    for j in range(i+1,len(d)):
        result+=d[i]*d[j]

print(result)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.IO.Pipes;

namespace cswork
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

            char[] cs = new char[] { ' ' };

            public Scanner()
            {
                s = new string[0];
                i = 0;
            }

            public string next()
            {
                if (i < s.Length) return s[i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();

                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

            public long nextLong()
            {
                return long.Parse(next());
            }

            public double nextDouble()
            {
                return double.Parse(next());
            }
        }

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        void Omame()
        {
            cin = new Scanner();
            int N = cin.nextInt();

            List<long> balls = new List<long>();
            List<int> pickUpBall = new List<int>();
            for (int i = 0; i < N; i++)
            {
                balls.Add(0);
            }
            for (int i = 0; i < N; i++)
            {
                int ball = cin.nextInt() - 1;
                balls[ball]++;
                pickUpBall.Add(ball);
            }

            long ans = 0;
            for (int i = 0; i < N; i++)
            {
                if (balls[i] >= 2)
                {
                    ans += Choose(balls[i]);
                }
            }

            for (int i = 0; i < N; i++)
            {
                int ball = pickUpBall[i];
                long tmp = ans;
                if (balls[ball] > 2)
                {
                    long a = Choose(balls[ball]);
                    long b = Choose(balls[ball] - 1);
                    tmp -= a - b;
                }
                else if(balls[ball] == 2)
                {
                    tmp--;
                }
                Console.WriteLine(tmp);
            }
        }

        long Choose(long n)
        {
            return n * (n - 1) / 2;
        }

    }
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N; ll H;
Pll P[int(1e5+5)], Q[int(1e5+5)];

int main(){
  cin >> N >> H;
  for (int i = 0; i < N; i++){
    cin >> P[i].fi >> P[i].se;
    Q[i] = {P[i].se, P[i].fi};
  }
  sort(P, P + N, greater<Pll>());
  sort(Q, Q + N, greater<Pll>());

  ll ans = 0;
  for (int i = 0; i < N; i++){
    if (Q[i].fi < P[0].fi) break;
    ans++; H -= Q[i].fi;
    if (H <= 0){
      cout << ans << endl;
      return 0;
    }
  }
  ans += H / P[0].fi;
  if (H % P[0].fi != 0) ans++;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6728
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  int K, len;
  string S;
  cin >> K >> S;
  len = S.length();
  if (len <= K) {
    cout << S << endl;
  } else {
    string tmp;
    tmp = S.substr(0, K);
    cout << tmp << "..." << endl;
    // printf("...\n");
  }
  return 0;
}

Measured memory_bytes: 3640
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 = read::<i32>();
    let t = (read::<i32>() - read::<i32>()) * 1000;
    let mut ans = 10000000;
    let mut id = 0;
    let mut i = 0;
    for h in (0..n).map(|_| read::<i32>()) {
        let now = (t - h * 6).abs();
        i += 1;
        if now < ans {
            ans = now;
            id = i
        }
    }
    println!("{}", id);
}


Measured memory_bytes: 4352
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=2e5+10;
int n,k,l; map<pair<int,int>,int> mp;
struct Dsu{
	int f[N];
	void init(int n){for(int i=1;i<=n;i++)	f[i]=i;}
	int find(int x){return x==f[x]?x:f[x]=find(f[x]);}
	void merge(int x,int y){f[find(x)]=find(y);}
}t1,t2;
signed main(){
	cin>>n>>k>>l;
	t1.init(n),t2.init(n);
	for(int i=1,a,b;i<=k;i++)	cin>>a>>b,t1.merge(a,b);
	for(int i=1,a,b;i<=l;i++)	cin>>a>>b,t2.merge(a,b);
	for(int i=1;i<=n;i++)	mp[{t1.find(i),t2.find(i)}]++;
	for(int i=1;i<=n;i++)	printf("%d ",mp[{t1.find(i),t2.find(i)}]);
	return 0;
}


Measured memory_bytes: 16364
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

vi adj[2005];
int sol[2005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int x, y;
    cin >> x >> y;
    for (int i = 1; i < n; ++i)
    {
        adj[i].push_back(i + 1);
        adj[i + 1].push_back(i);
    }
    adj[x].push_back(y);
    adj[y].push_back(x);
    for (int i = 1; i <= n; ++i)
    {
        queue<int> q;
        q.push(i);
        vi d(n + 1, 1e9);
        d[i] = 0;
        while (!q.empty())
        {
            int x = q.front();
            q.pop();
            for (int y : adj[x])
            {
                if (d[y] == 1e9)
                {
                    d[y] = d[x] + 1;
                    q.push(y);
                }
            }
        }
        for (int i = 1; i <= n; ++i)
        {
            sol[d[i]]++;
        }
    }
    for (int i = 1; i < n; ++i)
        cout << sol[i] / 2 << '\n';
}


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

/*解説AC*/

int ans;
int h, w;
vector<string> v;

struct unionfind{
    vector<int> d;
    unionfind(int n=0) : d(n, -1){}
    int find(int x) {//根を返す関数
        if(d[x]<0) return x;
        return d[x]=find(d[x]);//d[x]にfind[d[x]]の値を代入してそれを返している．これにより根に全ての子を繋げられる．
    }
    bool unite(int x, int y){
        x=find(x);y=find(y);
        if(x == y) return false;
        if(d[x]>d[y]) swap(x, y);//-なので逆にしている
        d[x]+=d[y];//連結成分サイズを保持している
        d[y]=x;//yの根をxにしている
        return true;
    }
    bool same(int x, int y){return find(x)==find(y);}//同じかどうかを判定
    int size(int x){return -d[find(x)];}//連結成分の数を返す
};

 
int main(void){
    cin>>h>>w;
    v.resize(h);
    ans = 0;
    rep(i, h) cin>>v[i];
    unionfind uf(h*(w+1));
    vector<int> dx = {0, 1, 0, -1};
    vector<int> dy = {1, 0, -1, 0};
    rep(i, h)rep(j, w){
        char c = v[i][j];
        rep(k, 4){
            int nx = i+dx[k];
            int ny = j+dy[k];
            if(nx<0||ny<0||nx>=h||ny>=w) continue;
            if(v[nx][ny] != c) uf.unite(i*w+j, nx*w+ny);
        }
    }
    map<int, pair<int, int> > mp;
    rep(i, h*w){
        int ny = i%w;
        int nx = i/w;
        if(v[nx][ny] == '#') mp[uf.find(i)].first ++;
        else mp[uf.find(i)].second ++;
    }
    ll ans = 0;
    for(auto p : mp){
        ans += (ll)p.second.first*(ll)p.second.second;
    }
    cout<<ans<<endl;
    return 0;
}

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

int  main()
{
	int  i,n,a,b,s=0,t=0,p;
	
	cin>>n>>a>>b;
	
	for(i=1; i<=n; i++)
	{
		p=i;
		s=0;
		while(p!=0)
		{
			s+=p%10;
			p/=10;
		}
		
		if(s>=a && s<=b)
		   t+=i;
	}
	
	cout<<t<<endl;
	
	return 0;
}

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

public class Main {

	static long pmod = 1000000007L;

	public static void main(String[] args) throws IOException {

//		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//		PrintWriter op = new PrintWriter(System.out);
//		StringTokenizer ste = new StringTokenizer(br.readLine());
//
//		StringBuilder ash = new StringBuilder();
//		for (int tcs = Integer.parseInt(ste.nextToken()) - 1; tcs >= 0; --tcs) {
//
//			ste = new StringTokenizer(br.readLine());
//			String s1 = ste.nextToken();
//
//		}
//		op.print(ash);
//		op.flush();
		Scanner scn = new Scanner(System.in);
		String n = scn.next();
		char ch = n.charAt(n.length() - 1);
		if (ch == '3')
			System.out.println("bon");
		else if (ch == '0' || ch == '1' || ch == '6' || ch == '8')
			System.out.println("pon");
		else
			System.out.println("hon");

	}
}

Measured memory_bytes: 35680
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){
    
    ll A, B;
    cin >> A >> B;
    ll ans = 0;
    for(ll i = A; i <= B; i++){
        stringstream ss;
        ss << i;
        string s = ss.str();
        string t = s;
        reverse(t.begin(), t.end());
        if(s == t)ans++;
    }
    cout << ans << endl;
    
    return 0;
}

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

H = list(map(int,input().split()))
T = [True]*n
A=[0]*m
B=[0]*m
for i in range(m):
    A[i],B[i] = map(int,input().split())

box=[[0] for _ in range(n)]
for i in range(m):
    if H[A[i] -1] - H[B[i] -1] < 0:
        box[A[i] -1].append(1)
        box[B[i] -1].append(0)
        
    elif H[A[i] -1] - H[B[i] -1]==0:
        box[A[i] -1].append(1)
        box[B[i] -1].append(1)
        
    elif H[A[i] -1] - H[B[i] -1] > 0:
        box[A[i] -1].append(0)
        box[B[i] -1].append(1)
        
for i in range(n):
    if sum(box[i])==0:
        T[i] =True
    else:
        T[i] = False

print(T.count(True))


Measured memory_bytes: 34656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;

  int x=0;
  string tmp;
  
  for(int i=A; i<=B; i++){
    tmp = to_string(i);
  	if(tmp[0] == tmp[4] && tmp[1] == tmp[3]) x++;
  }
  
  cout << x << endl;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
 
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;

ll score[105];
ll dp_sub[105];
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(a,b)<<" "<<max(0,a+b-n)<<endl;
}

Measured memory_bytes: 256
import math

K, A, B = map(int, input().split(' '))


if B - A <= 2 or K <= A:
    biscuit = K + 1
    
else:
    if (K - A) % 2 != 0:
        b = math.ceil((K - A) / 2)
        a = math.floor((K - A) / 2)
        biscuit = b * B - a * A
        
    else:
        b = math.ceil((K - A - 1) / 2)
        a = math.floor((K - A - 1) / 2)
        biscuit = b * B - a * A + 1
    
print(biscuit)

Measured memory_bytes: 3064
N = gets.to_i
A = gets.strip.split.map(&:to_i)
B = gets.strip.split.map(&:to_i)
C = gets.strip.split.map(&:to_i)
answer = 0

A.sort!
B.sort!{|a,b| b <=> a}
C.sort!{|a,b| b <=> a}
b = []

for i in 0..N-1

    if B[i] < C[N-1]

        b[i] = N

    elsif B[i] >= C[0]

        b[i] = 0

    else

        b[i] = (0..N).bsearch{|n| B[i] >= C[n]}

    end

end

for i in 0..N-1

    if A[N-1] < B[i]

        answer += b[i] * N 

    elsif A[0] >= B[i]

        answer += 0

    else
        
        answer += (0..N).bsearch{|n| B[i] <= A[n]} * b[i]

    end

end

puts answer 


Measured memory_bytes: 32852
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a, b;
    cin >> a >> b ;
    //*/

    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;

    sort(vec.begin(), vec.end());
    //*/
    
    //*
    if( a == b ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    //*/
    
    //cout << a / b + min(a % b, 1) << endl;
    
    return 0; 
}


Measured memory_bytes: 3672
#include<iostream>
using namespace std;
int main(){
    int a;
    cin>>a;
    int m;
    string s;
    bool c[4][14]={0};
    for(int i=0;i<a;i++){
        cin>>s;   
        cin>>m;
        if(s=="S")
          c[0][m-1]=1;
        if(s=="H")
          c[1][m-1]=1;
        if(s=="C")
          c[2][m-1]=1;
        if(s=="D")
          c[3][m-1]=1;
    }
  
    for(int i=0;i<13;i++){
        if(c[0][i]==0)
            cout<<"S "<<i+1<<endl;
    }
    for(int i=0;i<13;i++){
        if(c[1][i]==0)
            cout<<"H "<<i+1<<endl;
    }
    for(int i=0;i<13;i++){
        if(c[2][i]==0)
            cout<<"C "<<i+1<<endl;
    }
    for(int i=0;i<13;i++){
        if(c[3][i]==0)
            cout<<"D "<<i+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 1208
#include<iostream>
using namespace std;
int main(){
	long n;
	cin >> n;
	long a[5];
	for(int i=0;i<5;i++) cin >> a[i];

	long ans=0;
	for(int i=0;i<5;i++){
		if(i!=0)ans=max(ans,n/min(a[i],a[i-1])+(n%min(a[i],a[i-1])?1:0));
		else ans=max(ans,n/a[i]+(n%a[i]?1:0));
	}
	cout << ans+4 << endl;
	return 0;
}


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


int main()
{
    int t=1;
    //cin>>t;

    while( t-- )
    {
        int n,k;
        cin>>n>>k;

        int p[n];

        for( int i=0 ; i<n ; i++ )
            cin>>p[i];

        sort( p,p+n );

        ll ans=0;
        for( int i=0 ; i<k ; i++ )
            ans+=p[i];

        cout<<ans;
    }
    return 0;
}


Measured memory_bytes: 3572
if __name__ == '__main__':
	#全探索
	S = input()
	s_len = len(S)
	s1 = {"A","C","G","T"}
	
	m_len = 0
	for x in range(s_len):
		for y in range(x+1,s_len+1):
			s2 = set(S[x:y])
			s_union =  s1.union(s2)
			if len(s_union) == 4:
				m_len = max(m_len,len(S[x:y]))
	print(m_len)


Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
const int64_t INF=9999999999999999;
int main() {
 int A,B,K;
 cin>>A>>B>>K;
 vector<int>y;
 for(int i=1;i<=100;i++){
     if(A%i==0&&B%i==0){y.push_back(i);}}
  cout<<y[y.size()-K]<<endl;
 
 return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
using P = pair<int, int>;
struct SegmentTree{
  int n;
  vector<P> v;
  vector<vector<int> > dat;
  SegmentTree(){};
  SegmentTree(int n,vector<P> v):v(v){init(n);build();};
  
  void init(int n_){
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,vector<int>());
  }  
  void build(){
    for(auto p:v)
      dat[p.first+n].emplace_back(p.second);    
    for(int i=0;i<n;i++)
      sort(dat[i+n].begin(),dat[i+n].end());
    
    for(int i=n-1;i;i--){
      dat[i].reserve(dat[(i<<1)|0].size()+dat[(i<<1)|1].size());
      merge(dat[(i<<1)|0].begin(),dat[(i<<1)|0].end(),
	    dat[(i<<1)|1].begin(),dat[(i<<1)|1].end(),
	    back_inserter(dat[i]));
    }
  }
  // [a,b) * [c,d)
  inline int query(int a,int b,int c,int d){
    int res=0;
    auto calc=[a,b,c,d](vector<int> &x){
      auto latte=lower_bound(x.begin(),x.end(),d);
      auto malta=lower_bound(x.begin(),x.end(),c);
      return int(latte-malta);
    };
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) res+=calc(dat[l++]);
      if(r&1) res+=calc(dat[--r]);
    }
    return res;
  }
  
};

signed ABC106_D(){
  int n,m,q;
  scanf("%d %d %d",&n,&m,&q);
  vector<int> x(m),y(m);
  for(int i=0;i<m;i++) scanf("%d %d",&x[i],&y[i]);
 
  vector<P> vp;
  for(int i=0;i<m;i++) vp.emplace_back(x[i],y[i]);
 
  SegmentTree seg(n+1,vp);
 
  for(int i=0;i<q;i++){
    int a,b;
    scanf("%d %d",&a,&b);
    printf("%d\n",seg.query(a,b+1,a,b+1));    
  }
  return 0;
}

//END CUT HERE
signed main(){
  ABC106_D();
  return 0;
}


Measured memory_bytes: 14704
#include<bits/stdc++.h>
using namespace std;
#define int long long
main(){
    int n;
    cin>>n;
    vector<int>a;
    for(int i=0;i<n;++i){
        int x;
        cin>>x;
        a.push_back(x);
    }
    sort(a.begin(),a.end());
    int ans=a[n-1];
    int cnt=2;
    int tmp=n-2;
    while(tmp){
        if(tmp>=2){
            ans+=2*a[n-cnt++];
            tmp-=2;
        }else{
            ans+=a[n-cnt++];
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5364
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;
const int INF = INT_MAX / 2;

typedef long long ll;

int main(){
	int N;
	while(cin >> N, N)
	{
		string ans;
		int w = 1;
		while(w < 1e9) w *= 8;
		while(w > 0)
		{
			ans.push_back('0' + N / w);
			N %= w;
			w /= 8;
		}
		bool flag = true;
		for(int i = 0; i < ans.size(); i++)
		{
			char out = ans[i];
			if(flag && out == '0') continue;
			flag = false;
			if(out >= '4') out++;
			if(out >= '6') out++;
			printf("%c", out);
		}puts("");
	}
	return 0;
}

Measured memory_bytes: 1176
#include<iostream>
#include<algorithm>
#include<climits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const int NMAX=1<<17;
int n;
int a[210];
int main(){
  scan(n);
  rep(i,n)scan(a[i]);
  int res=INT_MAX;
  rep(i,n){
    int cnt=0;
    while(a[i]%2==0){
      cnt++;
      a[i]/=2;
    }
    res=min(res,cnt);
  }
  prin(res);
  return 0;
}


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

int main(){
  int D, G;
  cin >> D >> G;
  vector<int> p(D);
  vector<int> c(D);
  for (int i=0; i<D; i++){
    cin >> p[i] >> c[i];
  }
  int ans = 1000000000;
  for(int i=0; i< (1 << D);i++){
    int score=0, solved=0, other=-1, hoge=i;
    for (int j=0; j<D; j++){
      if (hoge&1){
        score += 100*(j+1)*p[j]+c[j];
        solved += p[j];
      } else {
        other = j;
      }
      hoge >>= 1;
    }
    if (score < G){
      if (G > score+p[other]*100*(other+1)) continue;
      solved += ceil((G-score)/(double)(100*(other+1)));
    }
    ans = min(ans, solved);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#define ll long long
const int N=4005,mo=1e9+7;
int n,k,i,fact[N],inv[N],fv[N];
void init(){
	fact[1]=fact[0]=inv[1]=fv[0]=fv[1]=1;
	for (i=2;i<=n+k;i++){
		fact[i]=(ll)fact[i-1]*i%mo;
		inv[i]=(ll)inv[mo%i]*(mo-mo/i)%mo;
		fv[i]=(ll)fv[i-1]*inv[i]%mo;
	}
}
int C(int n,int m){
	return (ll)fact[n]*fv[m]%mo*fv[n-m]%mo;
}
int cal(int n,int m){return m>=0?C(n+m,n):0;}
int main(){
	scanf("%d%d",&n,&k);init();
	if (n==1&&k==1){puts("1");return 0;}
	int ans=(cal(n-2,k-1)-cal(n,k-3)+mo)%mo;
	for (i=n-k-1;i>0;i--) ans=2ll*ans%mo;
	printf("%d",ans);
}

Measured memory_bytes: 256
//hail to jwalaji
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main(){
lli d,t,s;
cin>>d>>t>>s;
if(d<=t*s){
    cout<<"Yes"<<endl;
}
else{
    cout<<"No"<<endl;
}
return 0;
}


Measured memory_bytes: 3564
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int amount = sc.nextInt();
        int num = sc.nextInt();
        if((amount % 500) <= num){
                System.out.println("Yes");
        } else{
                System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
a,b,c=map(int,input().split())
if a==b==c:
  print(-(a%2<1))
else:
  s=0
  while a%2<1and b%2<1and c%2<1:
    a,b,c=(b+c)//2,(c+a)//2,(a+b)//2
    s+=1
  print(s)

Measured memory_bytes: 39888
#include <stdio.h>
#include <stdlib.h>

#define n_max 2000000
#define a_max 10000

int main(){
  unsigned short *A, *B;
  int C[a_max+1];
  int n, i, j;

  scanf("%d",&n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for(i=0;i<=a_max;i++) C[i]=0;
  
  for(i=0;i<n;i++){
    scanf("%d",&A[i+1]);
    C[A[i+1]]++;
  }

  for(i=1;i<=a_max;i++) C[i]=C[i]+C[i-1];

  for(j=n;j>0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

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

  return 0;
}



Measured memory_bytes: 9560
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;


int main() {

  ll N; cin >> N;
  vector<ll>  A(N), B(N), C(N);
  ll ans = 0;

  REP(i, N) cin >> A[i];
  REP(i, N) cin >> B[i];
  REP(i, N) cin >> C[i];

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());


  REP(i, N){
    auto Ait = lower_bound(A.begin(), A.end(), B[i]);
    ll Aindex = Ait - A.begin();
    auto Cit = upper_bound(C.begin(), C.end(), B[i]);
    ll Cindex = Cit - C.begin();

    //index個
    ll Anum = Aindex;
    //N - index個
    ll Cnum = N - Cindex;

    ans += Anum * Cnum;

  }

  cout << ans << endl;
    
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 2560
n = input()

hon = {'2', '4', '5', '7', '9'}
pon = {'0', '1', '6', '8'}
bon = {'3'}

if n:
  one = n[-1]
  
  if one in hon:
    print('hon')
  elif one in pon:
    print('pon')
  else:
    # 残り３のみなのでelse
    print('bon')

Measured memory_bytes: 9080
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.text.DecimalFormat;

public class Main {
	static boolean debug = false;

	public static void main(String[] args) throws IOException {

		UserScanner scan = new UserScanner();
		PrintWriter pwriter = new PrintWriter(System.out);
		int n = scan.nextInt();
		int m = scan.nextInt();
		Coin c = new Coin(n, m);
		for (int i = 0; i < m; i++)
			c.addDenom(i, scan.nextInt());
		pwriter.println(c.getAnswer(n));

		pwriter.flush();
		scan.close();
		System.exit(0);
	}
}

class Coin {
	int[] denom;
	int[][] hist;

	public Coin(int n, int m) {
		denom = new int[m];
		hist = new int[n + 1][m];
	}

	public int getAnswer(int n) {
		return getPieces(n, denom.length - 1);
	}

	private int getPieces(int n, int dix) {
		if (n == 0)
			return 0;
		if (n < 0 || dix < 0)
			return Integer.MAX_VALUE / 2;
		if (hist[n][dix] != 0)
			return hist[n][dix];

		int min = Math.min(getPieces(n - denom[dix], dix) + 1, getPieces(n, dix - 1));
		hist[n][dix] = min;
		return min;
	}

	public void addDenom(int i, int d) {
		denom[i] = d;
	}

}

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

	private boolean read() throws IOException {
		ptr = 0;
		buflen = in.read(buffer);
		if (buflen <= 0)
			return false;
		else
			return true;
	}

	private byte getByte() throws IOException {
		if (ptr >= buflen)
			read();
		if (isCtlSpace(buffer[ptr])) {
			return -1;
		} else
			return buffer[ptr++];
	}

	private void skipCtlSpace() throws IOException {
		if (ptr >= buflen)
			read();
		if (isCtlSpace(buffer[ptr])) {
			ptr++;
			skipCtlSpace();
		}
	}

	private boolean isCtlSpace(byte b) {
		if (b <= ' ' || b > '~')
			return true;
		else
			return false;
	}

	public void close() throws IOException {
		in.close();
	}

	public String next() throws IOException {
		skipCtlSpace();
		StringBuilder sb = new StringBuilder();
		byte b;
		while ((b = getByte()) != -1) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() throws IOException {
		skipCtlSpace();
		int n = 0;
		boolean minus = false;
		byte b;
		while ((b = getByte()) != -1) {
			if (b == '-')
				minus = true;
			else {
				n *= 10;
				n += (b - '0');
			}
		}
		if (minus)
			return n * -1;
		else
			return n;
	}
}

Measured memory_bytes: 30396
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    bool b = true;
    rep(i, s.size())
    {
        if (i % 2 == 0) {
            b = b && (s[i] == 'R' || s[i] == 'U' || s[i] == 'D');
        } else {
            b = b && (s[i] == 'L' || s[i] == 'U' || s[i] == 'D');
        }
    }
    cout << (b ? "Yes" : "No") << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    ll n,c;cin>>n>>c;
    vl x(n),v(n);
    vl a1(1,0),a2(1,0),b1(1,0),b2(1,0),c1(1,0),c2(1,0),d1(1,0),d2(1,0);
    rep(i,n)cin>>x[i]>>v[i];
    ll suma=0;
    rep(i,n){
        suma+=v[i];
        if(suma-x[i]>a1[a1.size()-1]){
            a1.PB(suma-x[i]);
            a2.PB(x[i]);
        }
        if(suma-2*x[i]>b1[b1.size()-1]&&x[i]<c/2){
            b1.PB(suma-2*x[i]);
            b2.PB(x[i]);
        }
    }
    ll sumc=0;
    for(int i=n-1;i>=0;--i){
        sumc+=v[i];
        if(sumc-(c-x[i])>c1[c1.size()-1]){
            c1.PB(sumc-(c-x[i]));
            c2.PB(c-x[i]);
        }
        if(sumc-2*(c-x[i])>d1[d1.size()-1]&&(c-x[i])<c/2){
            d1.PB(sumc-2*(c-x[i]));
            d2.PB(c-x[i]);
        }
    }
    ll ans1=a1[a1.size()-1];
    for(int i=1;i<b1.size();++i){
        ll sum=0;
        sum+=b1[i];
        int k=lower_bound(all(c2),c-2*b2[i])-c2.begin();
        sum+=c1[k-1];
        if(ans1<sum)ans1=sum;
    }
    ll ans2=c1[c1.size()-1];
    for(int i=1;i<d1.size();++i){
        ll sum=0;
        sum+=d1[i];
        int k=lower_bound(all(a2),c-2*d2[i])-a2.begin();
        sum+=a1[k-1];
        if(ans2<sum)ans2=sum;
    }
    cout<<max(ans1,ans2)<<endl;
}

Measured memory_bytes: 6748
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ii = pair<int, int>;
using ll = long long;

int32_t main(){
	ios::sync_with_stdio(0);
	vector<int> vs(5);
	for(auto &x:vs) cin >> x;
	int w = 1;
	for(auto x:vs){
		if(not x){
			cout << w << endl;
			return 0;
		} ++w;
	}
}


Measured memory_bytes: 3612
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque

H,W=map(int, sys.stdin.readline().split())
CH,CW=map(int, sys.stdin.readline().split())
CH-=1
CW-=1
DH,DW=map(int, sys.stdin.readline().split())
DH-=1
DW-=1
S=[ sys.stdin.readline().strip() for _ in range(H) ]

D=[(0,1),(0,-1),(1,0),(-1,0)]
WARP=[]
for dh in range(-2,3):
    for dw in range(-2,3):
        if abs(dh)+abs(dw)<=1: continue
        WARP.append((dh,dw))

d=defaultdict(lambda: float("inf")) #スタート地点から各マスまでの距離

q=deque()
q.append((CH,CW))
d[(CH,CW)]=0

while q:
    fro_h, fro_w=q.popleft()
    if (fro_h, fro_w)==(DH,DW):
        print d[(fro_h, fro_w)]
        quit()
    for dh,dw in D:
        to_h, to_w=fro_h+dh, fro_w+dw
        if 0<=to_h<H and 0<=to_w<W and S[to_h][to_w]=="." and d[(fro_h, fro_w)]<d[(to_h, to_w)]:
            d[(to_h, to_w)]=d[(fro_h, fro_w)]
            q.appendleft((to_h, to_w))
    for dh,dw in WARP:
        to_h, to_w=fro_h+dh, fro_w+dw
        if 0<=to_h<H and 0<=to_w<W and S[to_h][to_w]=="." and d[(fro_h, fro_w)]+1<d[(to_h, to_w)]:
            d[(to_h, to_w)]=d[(fro_h, fro_w)]+1
            q.append((to_h, to_w))

print -1


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

int main()
{
	int N;
	cin >> N;
	vector<int> L( N * 2 );
	for( int i = 0; i < N * 2; i++ ) {
		cin >> L[i];
	}

	sort( L.rbegin(), L.rend() );
	int ans = 0;
	for( int i = 0; i < N * 2; i += 2 ) {
		ans += L[i + 1];
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <map>
#include <numeric>
using namespace std;
#define elif else if
#define echo cout <<
#define read cin >>
#define fin << '\n'
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define alles(obj) obj.begin(), obj.end()
#define bash push_back
#define makePair make_pair
// type-define
#define String string
#define Stack stack
#define Queue queue
#define pQueue priority_queue
#define Vector vector
#define Pair pair
#define Map map
typedef long long llong;
typedef bool boolean;
typedef Pair<int,int> Pii;
typedef Vector<int> Vi;
// utils
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
boolean isMovable(int x,int y,int w,int h){return (x>=0&&y>=0&&x<w&&y<h);}
const int INF = 1 << 29;

Vector<Pii> cnt1;
Vector<Pii> cnt2;

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

    int n;
    read n;
    for ( int i = 0; i < 100100; i++ ) {
        cnt1.bash( makePair ( 0, i ) );
        cnt2.bash( makePair ( 0, i ) );
    }
    for ( int i = 0; i < n; i++ ) {
        int a;
        read a;
        if ( i&1 ) {
            cnt1[a].first++;
        }
        else {
            cnt2[a].first++;
        }
    }
    sort(alles(cnt1), greater<Pii>());
    sort(alles(cnt2), greater<Pii>());
    int maxv = n;
    for ( int i = 0; i < 100; i++ ) {
        for ( int j = 0; j < 100; j++ ) {
            if ( cnt1[i].second != cnt2[j].second ) {
                maxv = min ( maxv, n-cnt1[i].first-cnt2[j].first );
            }
        }
    }
    echo maxv fin;


    return 0;
}


Measured memory_bytes: 2036
s = input()
t = input()
tra = {}
f = True
for i in range(len(s)):
    if s[i] in tra.keys():
        if tra[s[i]] != t[i]:
            f = False
            break
    else:
        if t[i] in tra.values():
            f = False
            break
        else:
            tra[s[i]] = t[i]
print("Yes" if f == True else "No")

Measured memory_bytes: 3632
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

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

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int gcd(int a, int b){
   int tmp;
   while(a%b==0){
      tmp=a%b;
      a=b;
      b=tmp;
   }
}

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

bool prime_number(int n){
   vector<bool> i;
   if(n < 2){
      return false;
   }
   else if(n == 2){
      return true;
   }
   if(n % 2 == 0){
      return false;
   }
   for(int i=3;i<=n/i;i+=2){
      if(n % i == 0) return false;
      return true;
   }
}

int main(){
   string s;
   
   while(getline(cin,s)){
   REP(i,s.size()-4){
      if(s.substr(i,5)=="apple") s.replace(i,5,"peach");
      else if(s.substr(i,5)=="peach") s.replace(i,5,"apple");
   }
   cout << s << endl;
   }
}

Measured memory_bytes: 1192
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String[] n = sc.next().split("");

        String result = "No";
        if (n[0].equals(n[1]) && n[0].equals(n[2]) || n[1].equals(n[2]) && n[1].equals(n[3])) result = "Yes";
        if (n[0].equals(n[1]) && n[0].equals(n[2]) && n[0].equals(n[3])) result = "Yes";
        System.out.println(result);
    }
}


Measured memory_bytes: 35788