akhauriyash/Code-Regression huggingface dataset:
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素



signed main(){
  int N;
  cin>>N;
  int h[N];
  int i;
  REPD(i,N)cin>>h[i];
  int cost_dp[N];
  cost_dp[0]=0;
  cost_dp[1]=abs(h[1]-h[0]);
  for(int i=2;i<N;i++){
    cost_dp[i]=min((cost_dp[i-2]+abs(h[i]-h[i-2])),(cost_dp[i-1]+abs(h[i]-h[i-1])));
  }
  cout<<cost_dp[N-1]<<endl;
}

Measured memory_bytes: 1024
package main

import (
        "fmt"
        "strconv"
)

func main() {
        var (
                max_n, a, b int
        )
        fmt.Scan(&max_n, &a, &b)
        total_sum := 0
        for n := 1; n <= max_n; n++ {
                str_n := fmt.Sprintf("%d", n)
                sum := 0
                for i := 0; i < len(str_n); i++ {
                        d, _ := strconv.Atoi(string(str_n[i]))
                        sum += d
                }
                if sum >= a && sum <= b {
                        total_sum += n
                }

        }
        fmt.Println(total_sum)
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    for(int i = a;i < c;i++)cout << "R";
    for(int i = b;i < d;i++)cout << "U";
    for(int i = a;i < c;i++)cout << "L";
    for(int i = b;i < d;i++)cout << "D";
    cout << "D";
    for(int i = a;i <= c;i++)cout << "R";
    for(int i = b;i <= d;i++)cout << "U";
    cout << "LU";
    for(int i = a;i <= c;i++)cout << "L";
    for(int i = b;i <= d;i++)cout << "D";
    cout << "R" << endl;
}

Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  [n, m, q] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    candidates = map VU.fromList $ f n 1 :: [VU.Vector Int]
      where
        f :: Int -> Int -> [[Int]]
        f 0 _ = [[]]
        f l k = do
          i <- [k..m]
          is <- f (pred l) i
          return $ i : is
  abcds <- sequence . replicate q $ unsafeListToTuple . map unsafeTextToInt . T.words <$> T.getLine :: IO [((Int, Int, Int), Int)]
  let
    evaluate :: VU.Vector Int -> Int
    evaluate v = sum . map snd . filter (p . fst) $ abcds
      where
        p :: (Int, Int, Int) -> Bool
        p (x, y, z) = v VU.! pred y - v VU.! pred x == z
  print . maximum . map evaluate $ candidates

unsafeListToTuple :: [Int] -> ((Int, Int, Int), Int)
unsafeListToTuple [w, x, y, z] = ((w, x, y), z)

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 7072
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  int n;cin>>n;
  vector<tuple<ll,ll,ll>> vt;
  for(int i=0;i<n;++i){
    ll x,y,h;cin >>x>>y>>h;
    vt.push_back(make_tuple(x,y,h));
  }
  sort(all(vt), [](tuple<ll,ll,ll>& ta,tuple<ll,ll,ll>& tb){return get<2>(ta) > get<2>(tb);});
  bool found = false;
  ll xout, yout, hout;
  for(int i=0;i<=100;++i){
    for(int j=0;j<=100;++j){
      ll htmp =-1;
      bool isbreak = false;
      for(int k=0;k<n;++k){
        if(htmp<0) htmp = get<2>(vt[k]) + abs(get<0>(vt[k]) - i) + abs(get<1>(vt[k]) - j);
        ll tmp = max(htmp - abs(get<0>(vt[k]) - i) - abs(get<1>(vt[k]) - j), 0LL);
        if (tmp != get<2>(vt[k])) {
          isbreak = true;
          break;
        }
      }
      if(!isbreak) {
        found = true;
        xout = i;
        yout = j;
        hout = htmp;
        break;
      }
    }
    if(found) break;
  }
  cout << xout << " " << yout << " " << hout << endl;
  return 0;
}


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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
use std::collections::VecDeque;
fn main() {
    input!{
        n: usize,
        m: usize,
        ab: [(usize, usize); m],
    }
    let mut adj = vec![Vec::new(); n];
    for (a, b) in ab {
        adj[a - 1].push(b - 1);
        adj[b - 1].push(a - 1);
    }
    let mut guide = vec![n + 1; n];
    let mut dq = VecDeque::new();
    dq.push_back(0);
    while !dq.is_empty() {
        if let Some(t) = dq.pop_front() {
            for i in &adj[t as usize] {
                if guide[*i] != n + 1 { continue; }
                guide[*i] = t;
                dq.push_back(*i);
            }
        }
    }
    println!("Yes");
    for i in &guide[1..] {
        println!("{}", *i + 1);
    }
}


Measured memory_bytes: 16172
//
//  main.cpp
//  3
//
//  Created by RISHAV SINGH MEHTA on 10/01/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,M,X,Y,T,ctr=0;
    ll int fact[1000]={0},P[1000]={0},Q[1000]={0};
    cin>>M;
    for (i=0; i<M; i++) {
        cin>>P[i];
    }
    for (i=0; i<M; i++) {
        cin>>Q[i];
    }fact[0]=1;
    for (i=1; i<=9; i++) {
        fact[i] = fact[i-1] * i ;
    }k=0;l=0;
    vector<ll int > pp,qq;
    for (i=0; i<(M); i++) {
        
        ctr=0;
        for (j=0; j<pp.size(); j++) {
            if (pp[j] < P[i]) {
                ctr=ctr+1;
            }
        }
        k = k + (P[i]-1 -ctr )*(fact[M -(i+1)]);
        pp.push_back(P[i]);
       // cout<<k<<"\t";
    }
    //cout<<endl;
    for (i=0; i<(M); i++) {
        
        ctr=0;
        for (j=0; j<qq.size(); j++) {
            if (qq[j] < Q[i]) {
                ctr=ctr+1;
            }
        }
        
        l = l + (Q[i]-1-ctr)*(fact[M -(i+1)]);
        qq.push_back(Q[i]);
       // cout<<l<<"\t";
    }
    //cout<<"the k is ="<<k<<endl;
    //cout<<"the l is ="<<l<<endl;
    
    cout<<llabs(l - k)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.math.*;
import java.io.*;
import java.util.*;
 
class Main{
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[] l1 = br.readLine().split(" ");
        int N = Integer.parseInt(l1[0]);
        int W = Integer.parseInt(l1[1]);

        long[] wt = new long[N];
        long[] val = new long[N];

        for(int i = 0; i < N; i++){
            String[] l2 = br.readLine().split(" ");
            wt[i] = Long.parseLong(l2[0]);
            val[i] = Long.parseLong(l2[1]);
        }

        long[][] dp = new long[wt.length][W + 1];

        for(int i = 0; i < dp.length; i++){
            for(int j = 0; j <dp[i].length; j++){
                if(i == 0){
                    if(j == 0){
                        dp[i][j] = 0;
                        continue;
                    }
                    if(wt[i] <= j){
                        dp[i][j] = val[i];
                    }
                }else{
                    if(j == 0){
                        dp[i][j] = 0;
                        continue;
                    }
                    if(j < wt[i]){
                        dp[i][j] = dp[i - 1][j];
                        continue;
                    }
                    if(wt[i] <= j){
                        dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - (int)wt[i]] + val[i]);
                    }
                }
            }
        }
        System.out.println(dp[wt.length - 1][W]);
    }
}

Measured memory_bytes: 127616
#include <stdio.h>
int main(void)
{

	int n,i,j,x[4][13]={{0}},no,k;
	char cards;
	


	scanf("%d",&n);
	
	

	while(n>0)
	{
		
		scanf(" %c",&cards);
		scanf("%d",&no);
		

		if(cards =='S')
		{
			k=0;

			
			
		}
	
	
		if(cards =='H')
		{
			k=1;

			
			
		}
	

		if(cards =='C')
		{
			k=2;

			
			
		}
	
		if(cards =='D')
		{
			k=3;

			
			
		}

		x[k][no-1] =1;
		n--;

	}
	
	for(i=0;i<4;i++)
	{
		
		

		for(j=0;j<13;j++)
		{
			if(x[i][j] == 0)
			{
			
			 
				if(i==0)
				{
					cards = 'S';
					
				}

				if(i==1)
				{
					cards = 'H';
					
				}

				if(i==2)
				{
					cards = 'C';
					
				}
				
				if(i==3)
				{
					cards = 'D';
					
				}

				printf("%c %d\n",cards,j+1);
				
			
		
		}
	
	}

	}
	return 0;
	
} 

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int k; cin >> k;
  vector<bool> f(k, false);
  int num = 7;
  int ans = 1;

  while(true) {
    if(num%k == 0) {
      cout << ans << endl;
      return 0;
    }
    if(f[num]) break;
    f[num] = true;
    ++ans;
    num = (num*10)+7;
    num %= k;
  }
  cout << -1 << endl;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 


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

string S; cin >> S;

if (S[2] == S[3] && S[4] == S[5]) cout << "Yes\n";
else cout << "No\n";



return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

// 配列を圧縮する。first に値、second に個数
template <class T> map<T, long long> run_length(vector<T> &v) {
    map<T, long long> ans;
    for (auto &&i : v) {
        if (ans.count(i))
            ans[i]++;
        else
            ans[i] = 1;
    }
    return ans;
}

template <class T> T nCr(T n, T r) {
    if (r > n)
        return 0;
    if (r * 2 > n)
        r = n - r;
    if (r == 0)
        return 1;
    T ans = n;
    for (T i = 2; i <= r; i++) {
        ans *= (T)(n - i + 1);
        ans /= (T)i;
    }
    return ans;
}

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

    ll N;
    scan(N);
    vector<ll> a(N);
    scan(a);
    a.insert(a.begin(), 0);
    partial_sum(all(a), a.begin());
    auto run = run_length(a);
    ll ans   = 0;
    for (auto &&i : run) {
        int n = i.second;
        if (1 < n)
            ans += nCr<ll>(n, 2);
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 14308
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  																						   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;	
const int mod = 1e9+7;																							   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra																													   																				   list<int>::iterator it;																								   
																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS//////////////////////////////////////////////////////


///////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	int a, b;
	cin >> a >> b;
	if(a % 2 == 1 && b % 2 == 1){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	
	
	
	
	
						
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>

using namespace std;

struct Node{
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

Node * find(Node *u, int k)
{
  while(u != NIL && k != u->key)
    {
      if(k < u->key)
	u = u->left;
      else
	u = u->right;
    }

  return u;
}


void insert(int k){
  Node *y=NIL;
  Node *x=root;
  Node *z;

  z=(Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL)
    {
      y=x;
      if(z->key < x->key)
	{
	  x = x->left;
	}
      else
	{
	  x = x->right;
	}
    }

  z->parent = y;

  if(y == NIL)
    {
      root=z;
    }
  else
    {
      if(z->key < y->key)
	{
	  y->left = z;
	}
      else
	{
	  y->right = z;
	}
    }
}


void inoder(Node *u){
  if(u == NIL)
    return;
  inoder(u->left);
  printf(" %d", u->key);
  inoder(u->right);
}

void preoder(Node *u){
  if(u == NIL)
    return;
  printf(" %d", u->key);
  preoder(u->left);
  preoder(u->right);
}

int main(){
  int n, i, x;
  string com;

  scanf("%d", &n);

  for(i=0; i<n; i++)
    {
      cin >> com;
      
      if(com[0] == 'f')
	{
	  scanf("%d", &x);	  
	  Node *t=find(root, x);
	  
	  if(t != NIL)
	    printf("yes\n");
	  else
	    printf("no\n");
	}
      else if(com == "insert")
	{
	  scanf("%d", &x);
	  insert(x);
	}
      else if(com == "print")
	{
	  inoder(root);
	  printf("\n");
	  preoder(root);
	  printf("\n");
	}
    }

  return 0;
}



Measured memory_bytes: 22008
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

int get3Year(){
	return 20*10;
}
int get12Year(){
	return 20*5 + 19*5;
}

int getYear(int num){
	if(num%3==0)return get3Year();
	return get12Year();
}

int getMonth(int year,int month){
	if(year%3==0)return 20;
	if(month%2==1)return 20;
	return 19;
}

int main(){
	int n;
	cin>>n;
	
	rep(i,n){
		int a,b,c;
		cin>>a>>b>>c;
		
		int sum = 0;
		for(int i=a+1;i<1000;i++)sum+=getYear(i);
		for(int j=b+1;j<=10;j++)sum+=getMonth(a,j);
		
		int maxi = getMonth(a,b);
		sum += maxi-c;
		
		printf("%d\n",sum+1);
	}
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    for (int i = 1; i <= 9; i++) for (int j = 1; j <= 9; j++) {
        if (i * j == n) {
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }
    std::cout << "No" << std::endl;

    return 0;
}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define REP(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {
  u32 n;
  set<string> S;
  cin >> n;
  REP(i, n) {
    string s;
    cin >> s;
    S.insert(s);
  }
  cout << S.size();
  return 0;
}


Measured memory_bytes: 19232
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int a[100];

signed main() {
	int i;
	
	cin >> n;
	rep(i, n) cin >> a[i];
	sort(a, a + n, greater<int>());
	
	int f = 0, s = 0;
	rep(i, n) {
		if (i % 2 == 0) f += a[i];
		else s += a[i];
	}
	cout << f - s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ss second
#define ff first
using namespace std;
const int M = 1000000007;

int mod(int x, int m = M){
    x %= m;
    return x < 0 ? x+m : x;
}


signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, ans=0, j;
    cin>>n;

    for(int i=1; i<=n; i++){
        j = n/i;
        ans += j*(j+1)*i/2;
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 3608
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class B
{
	public static void Main()	
	{
		int N = GetInt();
		string s = GetString();
		int max = 0;
		int x = 0;
		for(int i = 0; i < N; i++)
		{
			x += (s[i] == 'I') ? 1 : -1;
			max = Math.Max(max, x);
		}
		Console.WriteLine(max);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 13140
// https://atcoder.jp/contests/abc062/tasks/abc062_b
#include <bits/stdc++.h>
using namespace std;

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<string> a(H + 2);
  rep(i, H) { cin >> a.at(i + 1); }

  rep(h, H + 2) {
    if (h == 0 || h == H + 1) {
      rep(i, W + 2) a.at(h) += '#';
    } else {
      a.at(h) = '#' + a.at(h) + '#';
    }

    cout << a[h] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define MN 100005
#define ll long long
using namespace std;
inline ll in(){
    ll x=0;bool f=0;char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
struct st{
	ll v;
	int id;
}a[MN];
struct edge{
	int to,nxt;
}e[MN<<1];
map <ll,int> mp;
int h[MN],fa[MN],dep[MN],siz[MN];
int n,cnt;
ll sum;
inline bool cmp(st x,st y){return x.v>y.v;}
inline void ins(int x,int y){
	e[++cnt].to=y;e[cnt].nxt=h[x];h[x]=cnt;
}
inline void dfs(int u){
	sum+=1ll*dep[u];
	for (int i=h[u];i;i=e[i].nxt){
		int v=e[i].to;
		if (v==fa[u]) continue;
		dep[v]=dep[u]+1;
		fa[v]=u;dfs(v);
	}
}
int main()
{
	n=in();
	for (int i=1;i<=n;++i){
		a[i].v=in();a[i].id=i;
		mp[a[i].v]=i;siz[i]=1;
	}sort(a+1,a+n+1,cmp);
	for (int i=1;i<n;++i){
		ll d=a[i].v-n+(siz[a[i].id]<<1);
		if (d>=a[i].v||(!mp[d])) {printf("-1");return 0;}
		ins(a[i].id,mp[d]);ins(mp[d],a[i].id);
		siz[mp[d]]+=siz[a[i].id];
	}dfs(a[n].id);
	if (sum!=a[n].v) {printf("-1");return 0;}
	for (int i=1;i<=n;++i)
	if (fa[i]) printf("%d %d\n",fa[i],i);return 0;
}

Measured memory_bytes: 13440
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N = int(input())
A = [int(input()) for _ in range(N)]
A = sorted(A)

def solve(pat):
    ans = []
    for i in range(N // 2):
        if pat:
            ans.append(A[N - 1 - i])
            ans.append(A[i])
        else:
            ans.append(A[i])
            ans.append(A[N - 1 - i])
    if N % 2 == 1:
        ans.append(A[N // 2])

    res = 0
    for i in range(1, N - 1):
        res += abs(ans[i] - ans[i - 1])
    x = abs(ans[-2] - ans[-1])
    y = abs(ans[-1] - ans[0])
    return (max(x, y) + res)

print(max(solve(True), solve(False)))

Measured memory_bytes: 14508
/*input
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
*/
/*

  ####   #    #    ##    #####    ####           #    #
 #       #    #   #  #   #    #  #    #          #    #
  ####   ######  #    #  #    #  #    #          #    #
      #  #    #  ######  #    #  #    #          # ## #
 #    #  #    #  #    #  #    #  #    #          ##  ##
  ####   #    #  #    #  #####    ####  #######  #    #

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
using namespace std;
#define N  100005
lld dp[N][5];
lld n,a[N],b[N],c[N];
void init()
{
	rep(i,0,N)
	{
		a[i]=0,b[i]=0,c[i]=0;
		rep(j,0,5)
		{
			dp[i][j]=-1;
		}
	}
}
lld func(lld pos,lld ty)
{
	if(pos>n)
	{
		return -hell;
	}
	if(pos==n)
	{
		return 0;
	}
	if(dp[pos][ty]!=-1)
	{
		return dp[pos][ty];
	}
	lld ans=0;
	if(ty==1)
	{
		ans+=a[pos];
		ans+=max(func(pos+1,2),func(pos+1,3));
		dp[pos][ty]=ans;
	}
	else if(ty==2)
	{
		ans+=b[pos];
		ans+=max(func(pos+1,1),func(pos+1,3));
		dp[pos][ty]=ans;
	}
	else if(ty==3)
	{
		ans+=c[pos];
		ans+=max(func(pos+1,2),func(pos+1,1));
		dp[pos][ty]=ans;
	}
	return ans;
}	
inline void solve()
{	
	cin >> n;
	init();
	rep(i,0,n)
	{
		cin >> a[i] >> b[i] >> c[i];
	}
	//cout << func(0,1) << " " << func(0,2) << " " << func(0,3) << endl;
	cout << max(max(func(0,1),func(0,2)),func(0,3)) << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int main() {

	long long N;
	cin >> N;
	vector<long long> A(3 * N);
	vector<long long> k(N + 1 , 0);
	priority_queue<long long> st;
	for (long long i = 0; i < 3 * N; i++) {
		cin >> A[i];
	}
	long long res;
	long long sum;
	sum = 0;
	for (long long i = 0; i < N; i++) {
		st.push(-A[i]);
		sum += A[i];
	}
	long long t;
	for (long long i = 0; i <= N; i++) {
		k[i] += sum;
		st.push(-A[N + i]);
		sum -= -A[N + i];
		t = st.top();
		t = -t;
		sum -= t;
		st.pop();
	}
	while (!st.empty())
	{
		st.pop();
	}
	sum = 0;
	for (long long i = 3*N - 1; i >= 2*N; i--) {
		st.push(A[i]);
		sum += -A[i];
	}
	for (long long i = 0; i <= N; i++) {
		k[(N) - i] += sum;
		st.push(A[2 * N - 1 - i]);
		sum -= A[2 * N - 1 - i];
		t = st.top();
		t = -t;
		sum -= t;
		st.pop();
	}
	res = k[0];
	for (long long i = 0; i <= N; i++) {
		res = max(res, k[i]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 4472
s1 = str(input())
s2 = str(input())
diff=[]
for i in range(0,len(s1)-len(s2)+1):
  str1 = s1[i:i+len(s2)]
  #print(str1)
  val=0
  for i in range(len(str1)):
    if(abs(ord(str1[i])-ord(s2[i])) > 0):
      val += 1
  diff.append(val)
print(min(diff))

Measured memory_bytes: 9124
#include <bits/stdc++.h>
            using namespace std;
             
            int main() {
              int K,X;
              cin>>K>>X;
              int a, b;
              a = max(-1000000,X-K+1);
              b = min(1000000,X+K-1);
              for(int i=a; i<=b; i++){
                cout<< i <<" ";
              }
            }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int X[110];
int main()
{
  int N;
  cin>>N;
  for(int i=0;i<N;i++)
    cin>>X[i];
  sort(X,X+N);
  int ans=0;
  for(int i=0;i<N;i++)
    for(int j=i+1;j<N;j++)
      for(int k=j+1;k<N;k++)
        if(X[i]!=X[j]&&X[j]!=X[k]&&X[i]+X[j]>X[k])
          ans++;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3640
;;; body

(defconstant +inf+ 10000000)

(defun main ()
  (let ((n (read)))
    (declare ((unsigned-byte 8) n))
    (let ((a (loop repeat n collect (read))))
      (declare (list a))
      (let ((res +inf+))
        (declare (fixnum res))
        (loop for y of-type (signed-byte 16) from -100 to 100 do
             (let ((tmp (reduce #'+
                                (mapcar (lambda (x)
                                          (expt (- x y) 2))
                                        a))))
               (declare (fixnum tmp))
               (when (< tmp res)
                 (setq res tmp))))
        (format t "~a~&" res)))))

#-swank (main)


Measured memory_bytes: 24840
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int n,d; cin >> n >> d;
	vector<vector<int>> x(n,vector<int>(d));
	rep(i,n)rep(j,d) cin >> x[i][j];
	int ans=0;
	rep(i,n)rep2(j,i+1,n){
		int dist = 0;
		rep(k,d) dist += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
//		cout << dist << endl;
		int r = sqrt(dist);
//		cout << r << endl;
		if(r*r==dist) ans++;
	}
	out(ans);
}




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

bool is_palindrome(string s){
    string t(s.rbegin(),s.rend());
    return s == t;
}

int main(){
    string s;
    cin>>s;
    int n=s.size();
    if(is_palindrome(s) && is_palindrome(s.substr(0,(n-1)/2)) && is_palindrome(s.substr((n+1)/2))){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}


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

typedef long long ll;

const ll M = 998244353;
#define MOD 998244353

vector<ll> fac(300001); 
vector<ll> ifac(300001); 

ll mpow(ll x, ll n){ 
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

ll N,m,K;

int main(){
    
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<200000; i++){
        fac[i+1] = fac[i]*(i+1) % M; 
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }

    cin >> N >> m >> K;

    ll tmp = 1;
    ll s;
    ll fa = 0;
    for(int k=0;k<=K;k++) {
        tmp = mpow(m-1,N-1-k) % M;
        tmp *= m;
        tmp %= M;
        ll ans = comb(N-1,k) % M;
        fa += (tmp*ans) %M;
        fa %= M;
    }
    
    if(fa<0) fa += M;
    cout << fa << endl;;

    
    return 0;
}

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

int main(){
    int N,Y;
    cin >> N >> Y;
    int count = 0;

    for(int x = 0;x<= N;++x){
        for(int y = 0;y <= N-x;++y){
            int z = N - x- y;
            if(x * 10000 + y * 5000 + z * 1000 == Y){
                cout << x <<" "<< y <<" "<< z << endl;
                ++count;
                break;
            } 
        }
        if(count > 0)break;
    }

    if(count == 0){
        cout << "-1 -1 -1" << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
row = list(map(int,(input().split())))
count = 0
for i in range(1,len(row) - 1):
  if row[i - 1] < row[i] < row[i + 1] or row[i - 1] > row[i] > row[i + 1]:
    count +=1
print(count)

Measured memory_bytes: 3060
#include <stdio.h>
 
int main()
{
  int a,b,c,temp;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  
  temp = a;
  a = b;
  b = temp;
  temp = a;
  a = c;
  c = temp;
  printf("%d %d %d\n",a,b,c);
  return 0;
}

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

using pii = pair<int, int>;

int main() {
    int n, m; cin >> n >> m;
    vector<int> cost = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    vector<int> a(m);
    for(int i = 0; i < m; ++i) {
        cin >> a[i];
    }
    sort(rbegin(a), rend(a));

    vector<pii> dp(n + 1, make_pair(-1, -1));
    vector<int> prev(n + 1, -1);
    dp[0] = make_pair(0, 0);
    for(int i = 0; i < n; ++i) {
        for(auto x : a) {
            if(i + cost[x] > n) continue;
            auto t = make_pair(dp[i].first + 1, x);
            if(t > dp[i + cost[x]]) {
                dp[i + cost[x]] = t;
                prev[i + cost[x]] = i;
            }
        }
    }

    string ans;
    int cur = n;
    while(prev[cur] != -1) {
        ans += dp[cur].second + '0';
        cur = prev[cur];
    }
    cout << ans << endl;
}


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






int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main() {
    int answer=0;
    int K;
    cin>>K;
    for(int a=1;a<=K;a++)
    {
        for(int b=1;b<=K;b++)
        {
            for(int c=1;c<=K;c++)
            
        {answer+=gcd(a,gcd(b,c));}
            }
    }
    
    cout<<answer<<endl;
    
}


Measured memory_bytes: 3672
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
const int N=3e5+5;
const int MOD=998244353;
ll F[N], Finv[N], inv[N];
void init(){
    inv[1] = 1;
    for(int i = 2; i < N; i ++){
        inv[i] = (MOD - MOD / i) * 1ll * inv[MOD % i] % MOD;
    }
    F[0] = Finv[0] = 1;
    for(int i = 1; i < N; i ++){
        F[i] = F[i-1] * 1ll * i % MOD;
        Finv[i] = Finv[i-1] * 1ll * inv[i] % MOD;
    }
}
ll c(int n, int m){
    if(m < 0 || m > n) return 0;
    return F[n] * 1ll * Finv[n - m] % MOD * Finv[m] % MOD;
}

int main(void){
    init();
    ll n,a,b,k;
    cin>>n>>a>>b>>k;
    ll ans=0;
    for(int x=0;x<=n;x++){
        if((k-a*x)%b==0){
            ll y=(k-a*x)/b;
            ans=(ans+c(n,x)%MOD*c(n,y))%MOD;
        }
    }
    cout << ans<< endl;
    return 0;
}


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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: u32
    }
    let s = n.to_string().chars().map(|x| {
        match x {
            '1' => '9',
            '9' => '1',
            _   => x
        }
    }).collect::<String>();
    println!("{}", s);
}


Measured memory_bytes: 4352
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
a = []
for i in range(N):
     a.append(int(readline()))

a.sort()

res = 0
cnt = 1
for i in range(1,N):
    if a[i] == a[i-1]:
        cnt+=1
    else:
        if cnt%2:
            res+=1
        else:
            cnt=1

            

if cnt%2:
    print(res+1)
else:
    print(res)



Measured memory_bytes: 7500
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000009;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char in[2100][2100];
int sum[4100][4100];
int rec(int a,int b,int c,int d){
	return sum[c][d]-sum[a][d]-sum[c][b]+sum[a][b];
}
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<a;i++)scanf("%s",in[i]);
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			if(in[i][j]=='1'){
				sum[i*2+1][j*2+1]++;
				if(j<b-1&&in[i][j+1]=='1'){
					sum[i*2+1][j*2+2]--;
				}
				if(i<a-1&&in[i+1][j]=='1'){
					sum[i*2+2][j*2+1]--;
				}
			}
		}
	}
	for(int i=0;i<a*2+3;i++){
		for(int j=0;j<b*2+3;j++){
			sum[i][j+1]+=sum[i][j];
		}
	}
	for(int i=0;i<a*2+3;i++){
		for(int j=0;j<b*2+3;j++){
			sum[i+1][j]+=sum[i][j];
		}
	}
	
	for(int i=0;i<c;i++){
		int p,q,r,s;
		scanf("%d%d%d%d",&p,&q,&r,&s);
		printf("%d\n",rec(p*2-2,q*2-2,r*2-1,s*2-1));
	}
}

Measured memory_bytes: 71424
import java.io.*;

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

		int[] sum = new int[26];
		String sentence;

		while((sentence=br.readLine())!=null){
			for(int i=0; i<sentence.length(); i++){
				char c = sentence.charAt(i);
				c = Character.toLowerCase(c);
				char cc ='a';
				for(int j=0; j<sum.length; j++){
					if(cc==c) sum[j]++;
					cc++;
				}
			}
		}
		char cc = 'a';
		for(int i=0; i<sum.length; i++){
			System.out.println(cc + " : " + sum[i]);
			cc++;
		}
	}
}

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int h, w;
	cin >> h >> w;
	Vec<string> strs(h);
	for (auto&& str : strs) {
		cin >> str;
	}
	for (auto&& str : strs) {
		cout << str << "\n" << str << "\n";
	}
}

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


Measured memory_bytes: 256
s = int(input())
l = [s]
num = s
while True:
    if num % 2 == 0:
        res = num / 2
    else:
        res = num * 3 +1
    l.append(res)
    if len(l) != len(set(l)):
        break
    else:
        num = res
print(len(l))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define check system("pause")
#define all(x) (x).begin(),(x).end()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 0x3f3f3f3f
const ll mod = 1e9+7;
const int N = 1e6+20;
#define dep(i,a,b) for(int i=(a);i>=(b);i--)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define mes(p,b) memset(p,b,sizeof(p))
#define sz(x) int(x.size())
int n,a[N],b[N];
map<ll,int> m; 
int main()
{
  	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n;
	rep(i,1,n) cin>>a[i];
	m[a[1]+1]++;
	ll ans=0;
	rep(j,2,n){
		ans+=m[j-a[j]];
		m[j+a[j]]++;
	}
	cout<<ans;
//	cout<<ans;
  	return 0;
}



Measured memory_bytes: 27152
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

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(void){
  ll N, X;
  cin >> N >> X;
  ll ans = 0;
  REP(i, N){
    ll x;
    cin >> x;
    ans = gcd(ans, labs(x-X));
  }
  cout << ans << endl;
  return 0;
}

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

#define ll long long int 

int main()
{
      ll n;
      cin>>n;
      ll a[n];
      ll b[n];
      ll c[n];
      for(int i=0;i<n;i++)
      {
          cin>>a[i];
      }
      
      for(int i=0;i<n;i++)
      {
          cin>>b[i];
      }

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

      sort(a, a+n);
      sort(b, b+n);
      sort(c, c+n);
      ll cnt=0;
      ll ans[n]={0};
      stack<ll>s;

      for(int i=n-1;i>=0;i--)
        {
           s.push(i);
        }
        stack<ll>temp;
        temp=s;
        for(int i=0;i<n;i++)
        {
            while(!s.empty()&&b[i]>=c[s.top()])
            {
              s.pop();
            }
            if(s.empty())
            {
                ans[i]=0;
            }
            else
            {
                ans[i]=n-s.top();
               // cout<<s.top()<<" "<<n-s.top()<<endl;
            }
        }
        for(int i=n-2;i>=0;i--)
        {
            ans[i]=ans[i+1]+ans[i];
        }
       /*  cout<<endl;
         for(int i=0;i<n;i++)
        {
            cout<<ans[i]<<" ";
        }
        */
    
        ll answer=0;
        s=temp;
        for(int i=0;i<n;i++)
        {
             while(!s.empty()&&a[i]>=b[s.top()])
             {
                 s.pop();
             }
             if(!s.empty())
             {
                 answer+=ans[s.top()];
             }
        }
       // cout<<endl;
        cout<<answer<<endl;
        



    return 0;
}

Measured memory_bytes: 8380
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type Drink struct {
	price, num int
}

type Drinks []*Drink

func (d Drinks) Len() int {
	return len(d)
}

func (d Drinks) Less(i, j int) bool {
	return d[i].price < d[j].price
}

func (d Drinks) Swap(i, j int) {
	d[i], d[j] = d[j], d[i]
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()
	d := make(Drinks, n)
	for i := range d {
		d[i] = &Drink{price: nextInt(), num: nextInt()}
	}
	sort.Sort(d)

	ans := 0
	for i := 0; m > 0; i++ {
		if d[i].num >= m {
			ans += m * d[i].price
			m = 0
		} else {
			ans += d[i].num * d[i].price
			m -= d[i].num
		}
	}
	puts(ans)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 3712
k = input()
for bit in range(1 << 3):
    tmp = int(k[0])
    s = k[0]
    for i in range(3):
        if bit & (1 << i):
            tmp += int(k[i+1])
            s += '+' + k[i+1]
        else:
            tmp -= int(k[i+1])
            s += '-'+k[i+1]
    if tmp == 7:
        print(s + '=7')
        exit(0)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>

using namespace std;

#define loop(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) loop(i,0,n)

bool pos[]={1,0,0};

int main(){
    char a,b,c;
    while(cin>>a>>c>>b){
        swap(pos[a-'A'],pos[b-'A']);
    }
    rep(i,3){
        if(pos[i]){
            cout<<(char)('A'+i)<<endl;
            break;
        }
    }
}

Measured memory_bytes: 1132