akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <map>
#define ll long long
using namespace std;
int ans;
int num[100010];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%d",&num[i]);

    }
    ans=0;
    for(int i=1;i<=n;i++){
        if(num[i]==i){
            ans++;
            swap(num[i],num[i+1]);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = list(map(int,read().split()))
mod = 998244353

sum_a = sum(a)
dp = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_rg = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_rb = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_r = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_r[0][0] = 1
tot = 0

for i in range(1,n+1):
    ai = a[i-1]
    tot += ai
    for j in range(tot+1):
        dp_rg[i][j] += dp_rg[i-1][j] + dp_r[i-1][j]
        dp_rb[i][j] += dp_rb[i-1][j] + dp_r[i-1][j]
        dp[i][j] += dp[i-1][j] * 2 + dp_rb[i-1][j] + dp_rg[i-1][j]

        if(j >= ai):
            dp_r[i][j] += dp_r[i-1][j-ai]
            dp_rg[i][j] += dp_rg[i-1][j-ai]
            dp_rb[i][j] += dp_rb[i-1][j-ai]
            dp[i][j] += dp[i-1][j-ai]
        dp_rg[i][j] %= mod
        dp_rb[i][j] %= mod
        dp[i][j] %= mod

r_over = sum(dp[-1][(1+sum_a)//2:]) % mod
ans = (pow(3,n,mod) - 3*pow(2,n,mod) + 3 - 3*r_over)%mod
print(ans)

Measured memory_bytes: 913168
#include <iostream>
#include <sstream>  // istringstream
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main()
{   
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    // そもそも今回の形式だと分割して入力されていた
    // istringstream iss(s);
    // string ss;
    // while (iss >> ss) {
    //     cout << ss << endl;
    // }

    cout << "A" << s2[0] << "C" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>

using As = std::multimap<int64_t, bool>;

template <typename Map>
void print_map(const Map &c, const std::string &name)
{
  std::cout << name << ": ";
  std::for_each(c.cbegin(), c.cend(),
                [](auto &x) { std::cout << x.first << ":" << x.second << ", "; });
  std::cout << std::endl;
}

void update(As &lefts, As &rights,
            int64_t &n, int64_t &min)
{
  int64_t a, b;
  std::cin >> a >> b;

  min += b;

  if(n == 0) {
    lefts.insert(std::make_pair(a, true));
    // print_map(lefts, "first left");
    n++;
    return;
  }

  int64_t old_argmin = lefts.rbegin()->first;
  int64_t old_right_0 = rights.begin()->first;
  // bool appends_left = a <= old_argmin;  // this is NG {-3} -2 {3}
  bool appends_left = (a < old_argmin) ||
                      (old_argmin <= a && a <= old_right_0 && n % 2 == 0);

  // prepair before appending
  if(appends_left && n%2 == 1) {
    // remove lefts[-1] and append it to rights
    auto old = *(--lefts.cend());
    lefts.erase(--lefts.cend());
    rights.insert(old);
  } if(!appends_left && n%2 == 0) {
    // remove right[0] and append it to lefts
    auto old = *rights.begin();
    rights.erase(rights.begin());
    lefts.insert(old);
  }

  // append a
  auto new_a = std::make_pair(a, true);
  if(appends_left) {
    lefts.insert(new_a);
  } else {
    rights.insert(new_a);
  }

  // update min
  int64_t new_argmin = (--lefts.end())->first;
  if(appends_left && n%2 != 0) {
    min += std::abs(old_argmin - new_argmin);
  }
  min += std::abs(new_argmin - a);

  n++;
}

void print( As &lefts, As &rights,
            int64_t n, int64_t min)
{
  int64_t argmin = lefts.rbegin()->first;
  std::cout << argmin << " " << min << std::endl;
}

int main()
{
  int Q;
  std::cin >> Q;

  As lefts, rights;
  int64_t n = 0;         // number of added |x-a| + b
  int64_t min = 0;   // mimimum now

  for(int i=0; i<Q; i++) {
    int c;
    std::cin >> c;
    if(c == 1) {
      update(lefts, rights, n, min);
    } else if(c == 2) {
      print(lefts, rights, n, min);
    }
  }

  return 0;
}


Measured memory_bytes: 16056
fun calc(h: Long): Long {
    if (h == 1L) {
        return h;
    }

    return calc(h / 2) * 2 + 1;
}

fun main(args: Array<String>) {
    readLong().let(::calc).let(::println)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 31532
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
--import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Fixed
import Data.Tuple
--import Data.Array
--import Data.Array.Unboxed
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
import System.IO
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete


main = do
    n <- getInt
    unless (n==0) $ do
        ds <- sortBy (comparing snd) . map (apply2 (,)) <$>  replicateM n getInts
        let folding = \(x,_) (y,c) -> (x+y,c)
        putStrLn $ cond "Yes" "No" $ all (uncurry (<=)) $ scanl folding (0,0) ds
        main


Measured memory_bytes: 4116
#include<bits/stdc++.h>
#define P pair
#define MP make_pair

typedef long long int llint ;

using namespace std;

int n;
bool parni=false;
string s;
int hi,lo,mi;

int main()
{
	cin>>n;
	hi=n;
	lo=0;
	int q=25;
	cout<<0<<endl;
	fflush(stdout);
	cin>>s;
	if(s=="Male")
	{
		parni=true;
	}
	else if(s=="Vacant")
	return 0;
	while(q)
	{
		q--;
		mi=(hi+lo)/2;
		cout<<mi<<endl;
		fflush(stdout);
		cin>>s;
		if(s=="Vacant")
		return 0;
		if(mi%2==0)
		{
			if(parni)
			{
				if(s=="Male")
				lo=mi+1;
				else
				hi=mi-1;
			}
			else
			{
				if(s=="Male")
				hi=mi-1;
				else
				lo=mi+1;
			}
		}
		else
		{
			if(parni)
			{
				if(s=="Male")
				hi=mi-1;
				else
				lo=mi+1;
			}
			else 
			{
				if(s=="Male")
				lo=mi+1;		
				else
				hi=mi-1;
			}
		}
	}
    return 0;
}


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

int main(){
  long N;
  int M;
  cin >> N >> M;

  int A[M];

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


  int sum = 0, result;
  for (int i=0; i<M; i++) {
    sum += A[i];
  }

  if (N -sum < 0) {
    result = -1;
  } else {
    result = N - sum;
  }

  cout << result << endl;

  return 0;
}

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

A = [0]*(n+1)

for i in range(n):
    A[i+1] = A[i] +a[i]

B = [0]*(m+1)
for j in range(m):
    B[j+1] = B[j] +b[j]

ans = 0
j = m
for i in range(n+1):
    if A[i] > k:
        break

    while B[j] > k-A[i]:
        j -= 1

    ans = max(ans, i+j)
print(ans)

Measured memory_bytes: 47372
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    vector<string>v(8);
    rep(i,8)cin>>v[i];
    cout<<90<<endl;
    rep(j,8){rep(i,8)cout<<v[7-i][j]; cout<<endl;}
    cout<<180<<endl;
    rep(i,8){rep(j,8)cout<<v[7-i][7-j]; cout<<endl;}
    cout<<270<<endl;
    rep(j,8){rep(i,8)cout<<v[i][7-j]; cout<<endl;}
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector< long long > a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    if (a[0] != 0) {
        cout << -1 << endl;
        return 0;
    }
    long long cnt = 0;
    for (int i = 1; i < n; i++) {
        long long d = a[i] - a[i - 1];
        if (d >= 2) {
            cout << -1 << endl;
            return 0;
        } else if (d == 1) {
            cnt++;
        } else if (d <= 0) {
            cnt += a[i];
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1792
package main

import (
	"fmt"
	"io"
	"os"
)

func fscanNums(r io.Reader, len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Fscan(r, &num)
		nums = append(nums, num)
	}
	return
}

func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}
func answer(r io.Reader, w io.Writer) {
	var numNumber int
	fmt.Fscan(r, &numNumber)
	nums := fscanNums(r, numNumber)

	ans := nums[0]
	for i := 1; i < numNumber; i++ {
		ans = gcd(ans, nums[i])
	}
	fmt.Fprintf(w, "%d", ans)
}

func main() {
	answer(os.Stdin, os.Stdout)
}


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

int main()
{
	std::vector<int> v;
	long int n, j=1, a;
	cin>>n;
	long int x=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>x;
		v.push_back(x);
	}
	std::vector<int>::iterator it;
	// for(it=v.begin();it<v.end();++it)
	// {
	// 	cout<<*it<<' ';
	// }
	for(it=v.begin();it<v.end();++it)
	{
		if(*it==j)
		{
			j++;
		}
	}
	j=j-1;
	if(j==0)
		a=-1;
	else
		a=n-j;
	cout<<a;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
using namespace std;

bool cheak(int a,int b,int c){
	if(a<b && b<c){
		return 1;
	}else if(a>b && b>c){
		return 1;
	}else{
		return 0;
	}
}

int main(){
	int p[20],num,ans;
	cin>>num;
	for(int i=0;i<num;i++){
		cin>>p[i];
	}
	for(int i=1;i<num-1;i++){
		if(cheak(p[i-1],p[i],p[i+1]))ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using static B2.MyLibrary;
namespace B2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nk = ToIntArray(Console.ReadLine().Split(' '));
            int[] As;
            int n = nk[0], k = nk[1];
            int d;
            int[] cnt = new int[n+1];
            for(int i = 0; i < k; i++)
            {
                d = int.Parse(Console.ReadLine());
                As = ToIntArray(Console.ReadLine().Split(' '));
                foreach(int a in As)
                {
                    cnt[a]++;
                }

            }
            int ans = Count(cnt,0)-1;
            Console.WriteLine(ans);
        }
    }
    class MyLibrary
    {
        public static int[] ToIntArray(string[] stringArray)
        {
            int length = stringArray.Length;
            int[] intArray = new int[length];
            for(int i = 0; i < length; i++)
            {
                intArray[i] = int.Parse(stringArray[i]);
            }
            return intArray;
        }
        public static int Count(int[] intArray, int i)
        {
            int count = 0;
            foreach(int j in intArray)
            {
                if(j == i)
                {
                    count++;
                }
            }
            return count;
        }
    }
}


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

using namespace std;

int main() {
  int tt;
  scanf("%d", &tt);
  while (tt--) {
    int n, d;
    scanf("%d %d", &n, &d);
    if ((n - 1) % 2 == 1) {
      for (int i = 0; i <= 6; ++i) {
        d ^= 1 << i;
      }
    }
    printf("%d\n", 127 * (n - 1) + d);
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename Container>
void print(const Container &c, char end = '\n', char sep = ' ')
{
    for (const auto &x : c)
        cout << x << sep;
    cout << end;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < n; i++)
    {
        cout << s[i] << t[i];
    }

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define F first
#define S second
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
int main()
{
  string s; cin >> s;
  ll cnt = 0;
  rep(i,(int)s.size()) {
    ll x = s[i] - '0';
    cnt += x;
  }
  if(cnt % 9 == 0) cout << "Yes" << "\n";
  else cout << "No" << "\n";
  return 0;
}


Measured memory_bytes: 3744
#include <iostream>
#include <stdio.h>
using namespace std;
//long long sum(long long n){return n*(n+1)/2;};
int main()  //R R G B
{
    string s; cin>>s;

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

}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
	int n,i,j,a=1;
	scanf("%d",&n);
	char w[99][11];
	for(i=0;i<n;i++){
		scanf("%s",w[i]);
		if(i>0&&a!=0){
			if(w[i][0]!=w[i-1][strlen(w[i-1])-1]){a=0;}
			for(j=0;j<i;j++){
				if(strcmp(w[j],w[i])==0){a=0;}
			}
		}
	}
	printf(a?"Yes":"No");
	return 0;
}

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

int main(void) {
    string str;
    cin >> str;

    int ans = 0;
    int cnt = 0;

    for(int i=0;i<str.size();i++) {
        if(str[i] == 'T') {
            ans++;
            if(cnt > 0) {
                ans-=2;
                cnt--;
            }
        }
        else {
            cnt++;
            ans++;
        }
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 640
while True:
  (H, W) = [int(i) for i in input().split()]
  if H == W == 0:
    break

  for hc in range(H):
    for wc in range(W):
      if (hc + wc) % 2 == 0:
        print('#', end='')
      else:
        print('.', end='')
    print()
  print()

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

int dp[110][110], n, m;
char arr[110][110];

int main()
{
    scanf("%d%d", &n, &m);
    for(int i=0; i<n; ++i) scanf("%s", arr[i]);
    dp[0][0] = arr[0][0]=='#'?1:0;
    for(int i=0; i<n; ++i){
        for(int j=0; j<m; ++j){
            if(i+j==0) continue;
            dp[i][j] = 999999;
            if(i>0) dp[i][j] = min(dp[i][j], dp[i-1][j]+((arr[i-1][j]=='.'&&arr[i][j]=='#')?1:0));
            if(j>0) dp[i][j] = min(dp[i][j], dp[i][j-1]+((arr[i][j-1]=='.'&&arr[i][j]=='#')?1:0));
        }
    }
    printf("%d\n", dp[n-1][m-1]);
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep (i, h) cin >> s[i];
	vector<vector<int> > hor(h, vector<int>(w, -1)), ver(h, vector<int>(w, -1));
	rep (i, h) {
	  int cnt = 0;
	  int start = -1, end = -1;
	  rep (j, w) {
		if (cnt == 0 && s[i][j] == '#') continue;
		if (cnt == 0 && s[i][j] == '.') start = j;
		if (s[i][j] == '#' || j == w - 1) {
		  if (s[i][j] == '#') {
			end = j;
		  } else {
			end = j + 1;
			cnt++;
		  }
		  FOR (k, start, end) ver[i][k] = cnt;
		  cnt = 0;
		  continue;
		}
		cnt++;
	  }
	}
	rep (j, w) {
	  int cnt = 0;
	  int start = -1, end = -1;
	  rep (i, h) {
		if (cnt == 0 && s[i][j] == '#') continue;
		if (cnt == 0 && s[i][j] == '.') start = i;
		if (s[i][j] == '#' || i == h - 1) {
		  if (s[i][j] == '#') {
			end = i;
		  } else {
			end = i + 1;
			cnt++;
		  }
		  FOR (k, start, end) hor[k][j] = cnt;
		  cnt = 0;
		  continue;
		}
		cnt++;
	  }
	}
	int res = 0;
	rep (i, h) {
	  rep (j, w) {
		if (s[i][j] == '#') continue;
		res = max(res, ver[i][j] + hor[i][j] - 1);
	  } 
	}
	cout << res << endl;
	
    return 0;
}



Measured memory_bytes: 38812
#include <bits/stdc++.h>
using namespace std;
 
int main(void) {
    int k, n;
    cin >> k >> n;

    int *A = new int[n];

    cin >> A[0];
    int max1 = A[0];
    for(int i=1; i<n; i++){
        cin >> A[i];
        max1 = max(max1, A[i]-A[i-1]);
    }
    
    max1 = max(max1, A[0] + k - A[n-1]);
    cout << k-max1;
 
    delete[] A;
    
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int ans = 0, m = 1e8;
    for (int i = 0; i < n; i++) {
        if (p[i] <= m) {
            ans++;
            m = p[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
def main():
    from sys import stdin
    n,k = map(int,stdin.readline().rstrip().split())
    Ds = set(map(int,stdin.readline().rstrip().split()))

    ans = n
    while True:
        num = ans
        numset = set()
        while num != 0:
            r = num%10
            num = num//10
            numset.add(r)
        if numset & Ds == set({}):
            break;
        else:
            ans+=1
    
    print(ans)
main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define inf (ll)1e9
#define d(x) cerr<<#x<<"="<<x<<endl;

map<int, pair<int,int>> mp;
int di[300];

int main(void){
    int h,w,d,tmp;
    cin>>h>>w>>d;
    rep(i,h)rep(j,w){
        cin>>tmp;
        mp[tmp]={i,j};
    }
    int q,l,r;
    cin>>q;
    int px,py,x,y,sum;
    vector<int> vec[d];
    for(int i = 0; i < d; i++){
        //d(i)
        int j=i;
        if(i==0)j=d;
        sum=0;
        vec[i].push_back(0);
        px=mp[j].first; py=mp[j].second;
        while(j<h*w){
            j+=d;
            x=mp[j].first; y=mp[j].second;
            sum+=abs(x-px)+abs(y-py);
            px=x; py=y;
            vec[i].push_back(sum);
        }
        //rep(j,vec[i].size())d(vec[i][j])
    }
    int tl,tr,ind;
    rep(i,q){
        cin>>l>>r;
        ind=l%d;
        tl=(l-l%d)/d;
        tr=(r-r%d)/d;
        if(ind==0){tl--; tr--;}
        cout<<vec[ind][tr]-vec[ind][tl]<<endl;
    }
}


Measured memory_bytes: 16640
# 入力
p,q,r = gets.chomp.split.map(&:to_i)

# これ絶対もっといいやり方ある
a = p + q
b = r + q
c = p + r
d = q + r
e = r + p
f = q + p

# こたえ
plan = [a,b,c,d,e,f]
puts plan.min

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

int dp[100][100][2];
char matrix[100][100];

int main(){
#ifdef LOCAL
	freopen("A_input.txt", "r", stdin);
	//freopen("A_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n, m;
	cin >> n >> m;

	for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> matrix[i][j];

	dp[0][0][0] = 0;
	dp[0][0][1] = 1e9;

	if (matrix[0][0] == '#') {
		dp[0][0][0] = 1e9;
		dp[0][0][1] = 1;
	}

	for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) for (int k = 0; k < 2; ++k) {
		if (i==0 && j==0) continue;
		dp[i][j][k] = 1e9;

		if (k == 0 && matrix[i][j] == '#') continue;
		if (k == 1 && matrix[i][j] == '.') continue;

		if (i > 0) {
			dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k]);
			if (k==0) dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][1-k]);
			else dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][1-k] + 1);
		}
		if (j > 0) {
			dp[i][j][k] = min(dp[i][j][k], dp[i][j-1][k]);
			if (k==0) dp[i][j][k] = min(dp[i][j][k], dp[i][j-1][1-k]);
			else dp[i][j][k] = min(dp[i][j][k], dp[i][j-1][1-k] + 1);
		}
	}

	//cout << dp[0][0][0] << endl;

	cout << min(dp[n-1][m-1][1], dp[n-1][m-1][0]);


}


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

int main(void) {
    string T;
    cin >> T;

    int size = T.size();

    long long cnt = 0;
    for (int i=0; i<size; i++) {
        if (T[i] == '?') T[i] = 'D';
        if (T[i] == 'D') cnt++;
    }
 //   for (int i=0; i<(size-1); i++) {
 //       if ((T[i] == 'P') && (T[i+1] == 'D')) cnt++;
//  }
//    cout << cnt << endl;
    cout << T << endl;

    return 0;
}


Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<int,int> Pi;
typedef pair<int,Pi> PP;

const int INF=1000000000;
const long long int INF_=1000000000000000000;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

inline bool IsIn(int y,int x,int h,int w){
	return 0<=y&&y<h&&0<=x&&x<w;
}

inline int f(int x){
	if(x==0) return 1;
	else if(x==1) return 0;
}

void Djikstra(vector<vector<int> > &f,vector<vector<int> > &l,int sy,int sx,int h,int w){
	priority_queue<PP,vector<PP>,greater<PP> > que;
	REP(y,0,h) fill(l[y].begin(),l[y].end(),INF);
	l[sy][sx]=1;
	que.push(PP(1,Pi(sy,sx)));
	while(!que.empty()){
		PP p=que.top(); que.pop();
		Pi v=p.S_;
		if(l[v.F_][v.S_]<p.F_) continue;
		REP(i,0,4){
			int ny=v.F_+dy[i],nx=v.S_+dx[i];
			if(!IsIn(ny,nx,h,w)) continue;
			if(l[ny][nx]>max(f[ny][nx],l[v.F_][v.S_])){
				l[ny][nx]=max(f[ny][nx],l[v.F_][v.S_]);
				que.push(PP(l[ny][nx],Pi(ny,nx)));
			}
		}
	}
}

void solve(){
	int R;
	while(cin >> R&&R){
		int W[2],H[2],X[2],Y[2];
		vector<vector<int> > field[2];
		vector<vector<int> > level[2];
		REP(i,0,2){
			cin >> W[i] >> H[i] >> X[i] >> Y[i];
			--X[i]; --Y[i];
			field[i].resize(H[i]);
			level[i].resize(H[i]);
			REP(j,0,H[i]){
				field[i][j].resize(W[i]);
				level[i][j].resize(W[i]);
			}
			REP(y,0,H[i]) REP(x,0,W[i]) cin >> field[i][y][x];
			Djikstra(field[i],level[i],Y[i],X[i],H[i],W[i]);
		}
		map<int,int> s[2];
		vector<int> idx[2],num[2];
		REP(i,0,2){
			REP(y,0,H[i]) REP(x,0,W[i]) ++s[i][level[i][y][x]];
			auto it=s[i].begin();
			idx[i].push_back(0);
			num[i].push_back(0);
			idx[i].push_back(it->F_);
			num[i].push_back(it->S_);
			auto prev=it;
			++it;
			for(; it!=s[i].end(); ++it,++prev){
				it->S_+=prev->S_;
				idx[i].push_back(it->F_);
				num[i].push_back(it->S_);
			}
		}
		int result=INF;
		REP(i,0,2) REP(j,0,idx[i].size()){
			int tmp=(int)(lower_bound(num[f(i)].begin(),num[f(i)].end(),R-num[i][j])-num[f(i)].begin());
			if(!(0<=tmp&&tmp<=idx[f(i)].size()-1)) continue;
			result=min(result,idx[i][j]+idx[f(i)][tmp]);
		}
		cout << result << endl;
	}
}

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

Measured memory_bytes: 17728
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

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

  sort(s.begin(),s.end());//昇順にソート
  sort(t.begin(),t.end(),greater<int>());//降順にソート

  


  int sum_s = 0;
  int sum_t = 0;

  for(int i = 0;i < t.size();i++){
    if(i < s.size())sum_s += s[i];
    sum_t += t[i];
    if(sum_s < sum_t){
      cout << "Yes" << endl;
      return 0;
    }
    else{//sum_s >= sum_tの時.
      if(sum_s == sum_t){
        continue;//sum_s==sum_tのままfor文を抜ける場合がある.
      }
      else{//sum_s > sum_tの時は辞書順でs > tになる.
        cout << "No" << endl;
        return 0;
      }
    }
  }

  if(sum_s == sum_t)cout << "No" << endl;






}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
using namespace std;
typedef long long LL;

const int maxn = 400005;
int last[2 * maxn],pre[2 * maxn],other[2 * maxn];
LL cost[2 * maxn],dis[maxn];
bool vis[maxn];
int que[maxn];
int all = -1;

void build(int x,int y,LL z){
	pre[++all] = last[x];
	last[x] = all;
	other[all] = y;
	cost[all] = z;
}

bool dfs(int x){
	vis[x] = 1;
	int dt = last[x];
	while(dt != -1){
		int dr = other[dt];
		if(vis[dr] == 0){
			dis[dr] = dis[x] + cost[dt];
			if(!dfs(dr)) return false;
		}
		if(vis[dr] == 1){
			if(dis[dr] != dis[x] + cost[dt]) return false;
		}
		dt = pre[dt];
	}
	return true;
}

int main(){
	int n,m;
	cin >> n >> m;
	memset(last,-1,sizeof(last));
	int cnt = 0;
	for(int i = 1;i <= m;i++){
		int x,y;
		LL z;
		cin >> x >> y >> z;
		if(vis[x] == 0) vis[x] = 1,que[++cnt] = x;
		if(vis[y] == 0) vis[y] = 1,que[++cnt] = y;
		build(x,y,z);
		build(y,x,-z);
	}
	memset(vis,0,sizeof(vis));
	for(int i = 1;i <= cnt;i++){
		if(vis[que[i]] == 0){
			dis[que[i]] = 0;
			if(dfs(que[i]) == false){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}


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

using namespace std;

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

    int c[3] = {};
    for (auto x:s) c[x - 'a']++;


    if (c[0] == 1 and c[1] == 1 and c[2] == 1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int max(int a,int b){return a>b?a:b;}
int n,a[105],ans[105];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	if(a[n]!=a[n-1]){printf("Impossible");return 0;}
	ans[1]=1;ans[1+a[n-1]]=1;
	for(int i=n-2;i>=1;i--)
	{
		if(a[i]<((a[n]+1)>>1)){printf("Impossible");return 0;}
		if(ans[a[i]+1]==1)
		{
			if(ans[1+a[n-1]-a[i]]==0) ans[1+a[n-1]-a[i]]=1;
			else if(a[i]-1<((a[n]+1)>>1)){printf("Impossible");return 0;}
		}
		else ans[a[i]+1]=1;
	}
	for(int i=1;i<=1+a[n-1];i++) if(ans[i]==0){printf("Impossible");return 0;}
	printf("Possible");
	return 0;
}

Measured memory_bytes: 128
# D

N, K = list(map(int, input().split()))
As = list(map(int, input().split()))

def compute(city, K):
    for i in range(K):
        # print('\t', city)
        city = As[city-1]
    print(city)

cities_visited = [False] * N
i = 0
city = 1
city_visited_time = {}

while not cities_visited[city - 1]:
    # print(city)
    cities_visited[city - 1] = True
    city_visited_time[city-1] = i
    city = As[city-1]
    i += 1

loop_start = city_visited_time[city-1]
loop_end = i


div = (K - loop_start) // (loop_end - loop_start)
if K - loop_start < 0 or div == 0:
    compute(1, K)
else:
    compute(city, K - loop_start - div * (loop_end - loop_start))

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

using namespace std;


int check[200005];
char s[200005];
int main() {
    scanf("%s", s);
    int ans = 0;
    int n = strlen(s);
    int letter = s[n - 1];
    for (int i = n - 1; i >= 0; --i) if (letter != s[i]) letter = s[i], ans++;

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
typedef long long ll;



int main(void){
    // Your code here!
    ll a, b, c;
    cin >> a >> b >> c;
    
    if(a >= c){
        cout << c + b << endl;
    } else {
        if(a + b < c){
            cout << a + 2*b + 1 << endl;
        } else{
            cout << b + c << endl;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    while(cin >> N){
        cin >> K;
        vector<int > h;
        int counter = 0;
        while(N--){
            int tmp;
            cin >> tmp;
            h.emplace_back(tmp);
        }
        
        for(auto x : h){
            if(x>=K){
                counter++;
            }
        }
        cout << counter << endl;
    }

}

Measured memory_bytes: 892
#include <stdio.h>

#define A 500
#define B 100
#define C 50

int main(void)
{
	int a, b, c, x;
	int num = 0;

	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	scanf("%d", &x);


	for(int i = 0; i <= a; i++)
	{
		for(int j = 0; j <= b; j++)
		{
			for(int k = 0; k <= c; k++)
			{
				int sum = i * A + j * B + k * C;
				if(sum == x)
					num++;
				else if(sum > x)
					break;
			}
		}
	}
				
	printf("%d\n", num);

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s, t;
	
	cin >> s >> t;
	
	if (s.size() > t.size()) {
		cout << "GREATER" << endl;
	}
	else if (s.size() < t.size()) {
		cout << "LESS" << endl;
	}
	else {
		for (int i = 0; i < (int)s.size(); i++) {
			if (s[i] > t[i]) {
				cout << "GREATER" << endl;
				break;
			}
			else if (s[i] < t[i]) {
				cout << "LESS" << endl;
				break;
			}
		}
	}
	
	if (s == t) {
		cout << "EQUAL" << endl;
	}
	
	return (0);
}

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

int main() {
  int K;
  string S;
  cin >> K;
  cin >> S;
  int cpi = S.size();
  if (K < cpi) {
    string ans;
    for(int i = 0;i < K;i++) {
    ans += S.at(i);
    }
  cout << ans + "..." << endl;
  }
  else {
    cout << S << endl;
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  int ans=0;
  cin >> N >> M;
  for (int i=N;i <= M;i++){
    int a[5];
    int i_copy=i;
    for(int j = 0;j<5;j++){
   		a[j] = (i_copy % 10);
    	i_copy/= 10;
    }
    if(a[0]==a[4]&&a[1]==a[3]){
      ans+=1;
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

using namespace std;

string s[100];

main()
{
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> a >> b;
    int n = 100, m = 100;
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) s[i].push_back('.');
    cout << n << ' ' << m << endl;
    int j;
    for(j = 0; j < m; j++){
        if(j & 1){
            for(int i = 0; i < n; i++) s[i][j] = '#';
            if(a == 1) break;
        }
        else{
            for(int i = 0; i < n; i++){
                if(i & 1) s[i][j] = '#';
                else{
                    if(a > 1){
                        a--;
                    }
                    else s[i][j] = '#';
                }
            }
        }
    }
    b--;
    j++;
    for(; ; j++){
        if(j & 1){
            for(int i = 0; i < n; i++){
                if(!(i & 1)){
                    if(b > 0){
                        b--;
                        s[i][j] = '#';
                    }
                }
            }
        }
        if(!b) break;
    }
    for(int i = 0; i < n; i++) cout << s[i] << endl;
}


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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(long long N) {
  cout << (N-2) * 180 << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


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

int main(){
    int a;
    cin >> a;
    vint A(a);
    rep(i,a) cin >> A[i];
    sort(A.begin(),A.end());
    double sum = A[0];
    for(int i = 1;i<a;i++){
        sum += A[i];
        sum /= 2;
    } 
  
    cout << sum << endl; 
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
//var input = require('fs').readFileSync('input.txt', 'utf8');
var Arr=(input.trim()).split("\n");	

Arr.forEach(function(v){
    var nums = v.split(" ").map(Number);
    var ans = "NO";
    var x1 = nums[2] - nums[0];
    var y1 = nums[3] - nums[1];
    var x2 = nums[6] - nums[4];
    var y2 = nums[7] - nums[5];
    var k1 = (nums[3] - nums[1]) / (nums[2] - nums[0]);
    var k2 = (nums[7] - nums[5]) / (nums[6] - nums[4]);
    if(x1 == 0){
        if(y2 == 0){
            ans = "YES";
        }
    }
    else if(x2 == 0){
        if(y1 == 0){
            ans = "YES"
        }
    }
    else if(Math.abs(k1 * k2 + 1) < 1e-10){
        ans = "YES";   
    }
    console.log(ans);
});


Measured memory_bytes: 16068
n=int(input())
a=list(map(int,input().split()))
d={}
for i in range(1,1+n):
    d[a[i-1]]=i
sortd=sorted(d.items(),key=lambda x:x[0])
sl=[0]*n
for i in range(n):
    sl[i]=sortd[i][1]
print(*sl)

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

static const int INF = 55;

int main(){
    int N;
    cin>>N;
    vector<string> S(N);
    for(int i=0; i<N; i++) cin>>S[i];

    vector<int> cnt(26,INF);

    for(int i=0; i<N; i++){
        vector<int> cp(26,0);
        for(int j=0; j<S[i].size(); j++){
            cp[(int)(S[i][j] - 'a')]++;
        }
        for(int j=0; j<26; j++){
            cnt[j] = min(cp[j],cnt[j]);
        }
    }

    string ans = "";
    int start = 0;

    for(int i=0; i<26; i++){
        if(cnt[i] == INF) cnt[i] == 0;
    }

    while(start < 26){
        if(cnt[start] == 0){
            start++;
            continue;
        }

        ans += char('a' + start);
        cnt[start]--;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n, h;
    int prevH = 0, maxH = 0;
    cin >> n;

    for(int i = 0; i < n; ++i) {
        cin >> h;

        if(prevH > h && maxH - 1 > h) {
            cout << "No" << '\n';
            return 0;
        } else
            maxH = max(maxH, h);

        prevH = h;
    }
    cout << "Yes" << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include <cstdio>
using namespace std;
 
const int m_MAX = 50;
const int f_MAX = 50;
const int r_MAX = 100;
int m[m_MAX], f[f_MAX], r[r_MAX];
 
char scorejudge(int x, int y, int z){
    char scoreX;
    if (x == -1 || y == -1)scoreX = 'F';
    else if (x + y >= 80)scoreX = 'A';
    else if (x + y >= 65)scoreX = 'B';
    else if (x + y >= 50)scoreX = 'C';
    else if (x + y >= 30 && z >= 50)scoreX = 'C';
    else if (x + y >= 30)scoreX = 'D';
    else scoreX = 'F';
    return scoreX;
}
 
int scoreinput(){
    int i = 0;
 
    for (;; i++){
        cin >> m[i] >> f[i] >> r[i];
        if (m[i] == -1 && f[i] == -1 && r[i] == -1)break;
    }
 
    return i;
}
 
int main(){
    int i=scoreinput();
 
    for (int j = 0; j < i; j++){
        cout << scorejudge(m[j], f[j], r[j]) << endl;
    }
 
    return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
struct edge{int to,cost;};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=MOD;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    int memo=modpow(a,b/2);
    return memo*memo%MOD;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
    x=modpow(x,MOD-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
double dist(double ax,double ay,double bx,double by){
    return sqrt((bx-ax)*(bx-ax)+(ay-by)*(ay-by));
}
string s;
int a[100010];
signed main(){
	cin>>s;
	int n=s.size();
	rep(i,n)a[i+1]=s[i]-'0';
	bool ok=true;
	if(a[1]==0||a[n]==1)ok=false;
	for(int i=1;i<=n;i++){
		if(a[i]!=a[n-i])ok=false;
	}
	if(ok==false){
		puts("-1");
		return 0;
	}
	int p=n;
	for(int i=n-1;i>=1;i--){
		cout<<p<<" "<<i<<endl;
		if(a[i]==1)p=i;
	}
    return 0;
}



Measured memory_bytes: 2432
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        x:i8,
        a: i8,
    }
    if x<a {
        println!("0");
    }else{
        println!("10");
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h> 
using namespace std; 
#define int long long
# define pii pair<int,int>
const int maxn=1e6+5;
signed main() { 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x,n;
    cin>>x>>n;
    if(n==0)
    {
    	cout<<x;
    	return 0;
    }
    unordered_set<int> s;
    for(int i=0;i<n;i++)
    {
    	int t;
    	cin>>t;
    	s.insert(t);
    }
    int ans1=1e6,ans2=1e6;
    for(int i=x;i>=0 ;i--)
    {
    	if(s.find(i)==s.end())
    	{
    		ans1=i;
    		break;
    	}
    }
    for(int i=x;i<150;i++)
    {
    	if(s.find(i)==s.end())
    	{
    		ans2=i;
    		break;
    	}
    }
    int ans=(abs(ans1-x)>abs(ans2-x))?ans2:ans1;
    cout<<ans;
}

Measured memory_bytes: 3664
N, u, v = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N)]
for Ai, Bi in AB:
    graph[Ai - 1].append(Bi - 1)
    graph[Bi - 1].append(Ai - 1)

import heapq

# tak table
d_tak = [10 ** 9 + 7] * N
p_tak = [None] * N
d_tak[u - 1] = 0
q = [(u - 1, 0)]
while len(q) > 0:
    src, pen = heapq.heappop(q)
    for dst in graph[src]:
        if d_tak[dst] > pen + 1:
            d_tak[dst] = pen + 1
            p_tak[dst] = src
            heapq.heappush(q, (dst, pen + 1))

# aok table
d_aok = [10 ** 9 + 7] * N
p_aok = [None] * N
d_aok[v - 1] = 0
q = [(v - 1, 0)]
while len(q) > 0:
    src, pen = heapq.heappop(q)
    for dst in graph[src]:
        if d_aok[dst] > pen + 1:
            d_aok[dst] = pen + 1
            p_aok[dst] = src
            heapq.heappush(q, (dst, pen + 1))

# where for tak to escape
i_ans = None
ans_tmp = 0
for i in range(N):
    if d_tak[i] < d_aok[i] and ans_tmp < d_aok[i]:
        ans_tmp = d_aok[i]
        i_ans = i

# where is aok when tak stops
pos_aok = i_ans
for j in range(d_aok[i_ans] - d_tak[i_ans]):
    pos_aok = p_aok[pos_aok]

# aok table 2
d_aok2 = [10 ** 9 + 7] * N
p_aok2 = [None] * N
d_aok2[v - 1] = 0
q = [(v - 1, 0)]
while len(q) > 0:
    src, pen = heapq.heappop(q)
    for dst in graph[src]:
        if d_aok2[dst] > pen + 1:
            d_aok2[dst] = pen + 1
            p_aok2[dst] = src
            heapq.heappush(q, (dst, pen + 1))

print(max(0, d_aok2[i_ans] - 1))

Measured memory_bytes: 55256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define MAX 1001
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int,int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int inf = 1e9;
const ll INF = 1e18;
const int size = 6002;
#define B 100

int n, dy[4] = {0, -1, 1, 0}, dx[4] = {-1, 0, 0, 1};
queue<P> q;
int X1[MAX], X2[MAX], Y1[MAX], Y2[MAX];
bool a[size][size];
int compress1(int w){
	vector<int> xs;
	for(int i = 0;i < n;i++){
		for(int j = -1;j <= 1;j++){
			int t1 = X1[i]+j, t2 = X2[i]+j;
			if(0 <= t1 && t1 <= w)xs.push_back(t1);
			if(0 <= t2 && t2 <= w)xs.push_back(t2);
		}
	}
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	for(int i = 0;i < n;i++){
		X1[i] = find(xs.begin(), xs.end(), X1[i])-xs.begin()+1;
		X2[i] = find(xs.begin(), xs.end(), X2[i])-xs.begin()+1;
	}
	return xs.size()-1;
}

int compress2(int h){
	vector<int> xs;
	for(int i = 0;i < n;i++){
		for(int j = -1;j <= 1;j++){
			int t1 = Y1[i]+j, t2 = Y2[i]+j;
			if(0 <= t1 && t1 <= h)xs.push_back(t1);
			if(0 <= t2 && t2 <= h)xs.push_back(t2);
		}
	}
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	for(int i = 0;i < n;i++){
		Y1[i] = find(xs.begin(), xs.end(), Y1[i])-xs.begin()+1;
		Y2[i] = find(xs.begin(), xs.end(), Y2[i])-xs.begin()+1;
	}
	return xs.size()-1;
}

void paint(){
	for(int i = 0;i < n;i++){
		for(int y = Y1[i];y < Y2[i];y++){
			for(int x = X1[i];x < X2[i];x++){
				a[y][x] = 1;
			}
		}
	}
}

int bfs(int w, int h){
	int ans = 0, tx, ty, yy, xx;
	for(int y = 1;y <= h;y++){
		for(int x = 1;x <= w;x++){
			if(a[y][x])continue;
			q.push(dmp(y, x));
			ans++;
			while(!q.empty()){
				P p = q.front();q.pop();
				yy = p.fi;xx = p.se;
				a[yy][xx] = true;
				for(int i = 0;i < 4;i++){
					ty = yy+dy[i];tx = xx+dx[i];
					if(!a[ty][tx]){
						a[ty][tx] = true;
						q.push(dmp(ty, tx));
					}
				}
			}
		}
	}
	return ans;
}

int main(){
	int w, h;
	/*queue<P> p;
	rep(i,10000)p.push(dmp(i, i+1));
	while(!p.empty()){
		P u = p.front();p.pop();
		printf("%d %d\n", u.fi, u.se);
	}*/
	while(1){
		scanf("%d%d", &w, &h);
		if(!w)break;
		scanf("%d", &n);
		fill((bool*)a, (bool*)(a+size), true);
		rep(i,n){
			scanf("%d%d%d%d", &X1[i], &Y1[i], &X2[i], &Y2[i]);
		}
		
		w = compress1(w);
		h = compress2(h);
		rrep(i,h)rrep(j,w)a[i][j] = false;
		paint();
		
		/*for(int y = 0;y <= h+1;y++){
			for(int x = 0;x <= w+1;x++){
				printf("%d ", a[y][x]);
			}
			printf("\n");
		}*/
		
		int ans = bfs(w, h);
		//int ans = 0;
		
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 38292
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;


int main (void) {
  ll N; std::cin >> N;
  if ( N == 0 ) {
    std::cout << 0 << std::endl;
    return 0;
  }

  std::vector<ll> K;
  while ( N != 0 ) {
    ll k = std::pow(2, K.size()+1);
    if ( N % k != 0 ) {
      N -= std::pow(-2, K.size());
      K.push_back(1);
    }
    else K.push_back(0);
  }
  for(int i=K.size()-1; i>=0; i--) std::cout << K[i];
  std::cout << std::endl;
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))

# num[i] = iを作るために必要なマッチの本数
# 1-indexになるよう、形式的にnum[0] = 0とした
num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

# dp[i] = i本のマッチで作れる最大の数
dp = [-1] * (N + 1)
dp[0] = 0

for i in range(N + 1):
    for a in A:
        # 遷移元がないならスキップ
        if dp[i] == -1:
            continue
        # 遷移先がないならスキップ
        elif i + num[a] > N:
            continue
        # 末尾にaをつける = 今の数字を10倍してaを足す
        else:
            dp[i + num[a]] = max(dp[i + num[a]], dp[i] * 10 + a)

# ちょうどN本使って作れる最大の数
print(dp[N])


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

int main(void){
    int a, b, c, k;

    cin >> a >> b >> c >> k;


    if(k <= a){
        cout << k << endl;
    }
    else if(k<=a+b){
        cout << a << endl;
    }
    else{
        cout << a-(k-a-b) << endl;
    }

}

Measured memory_bytes: 3636
import java.util.Scanner;

class Main {

	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		if(a<b && b<c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

		scan.close();
	}


}


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

using namespace std;

#define debug(x) cout << "\n" << __LINE__ << " " <<  (#x) << " is " << (x) << endl

map < multiset <char>, int> sol;

int main(){
	#ifdef EVAL	
		freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		multiset <char> tmp;
		char c;
		for(int j = 0; j < 10; j++){
			cin >> c;
			tmp.insert(c);
		}
		sol[tmp]++;
	}
	long long ans = 0;
	for(auto it : sol){
		long long cur = it.second;
		if(cur > 1){
			ans += (cur * (cur - 1)) / 2;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 56448